ethdev: remove legacy MACVLAN filter type support
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_NET_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_NET_IXGBE
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_NET_I40E
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_NET_BNXT
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related cmds.\n"
100                 "    help all                        : All of the above sections.\n\n"
101         );
102
103 }
104
105 cmdline_parse_token_string_t cmd_help_brief_help =
106         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107
108 cmdline_parse_inst_t cmd_help_brief = {
109         .f = cmd_help_brief_parsed,
110         .data = NULL,
111         .help_str = "help: Show help",
112         .tokens = {
113                 (void *)&cmd_help_brief_help,
114                 NULL,
115         },
116 };
117
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120         cmdline_fixed_string_t help;
121         cmdline_fixed_string_t section;
122 };
123
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port port_id (module_eeprom|eeprom)\n"
170                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port (port_id) rss-hash [key]\n"
178                         "    Display the RSS hash functions and RSS hash key of port\n\n"
179
180                         "clear port (info|stats|xstats|fdir|stat_qmap) (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) macs|mcast_macs"
250                         "       Display list of mac addresses added to port.\n\n"
251
252                         "show port (port_id) fec capabilities"
253                         "       Show fec capabilities of a port.\n\n"
254
255                         "show port (port_id) fec_mode"
256                         "       Show fec mode of a port.\n\n"
257                 );
258         }
259
260         if (show_all || !strcmp(res->section, "config")) {
261                 cmdline_printf(
262                         cl,
263                         "\n"
264                         "Configuration:\n"
265                         "--------------\n"
266                         "Configuration changes only become active when"
267                         " forwarding is started/restarted.\n\n"
268
269                         "set default\n"
270                         "    Reset forwarding to the default configuration.\n\n"
271
272                         "set verbose (level)\n"
273                         "    Set the debug verbosity level X.\n\n"
274
275                         "set log global|(type) (level)\n"
276                         "    Set the log level.\n\n"
277
278                         "set nbport (num)\n"
279                         "    Set number of ports.\n\n"
280
281                         "set nbcore (num)\n"
282                         "    Set number of cores.\n\n"
283
284                         "set coremask (mask)\n"
285                         "    Set the forwarding cores hexadecimal mask.\n\n"
286
287                         "set portmask (mask)\n"
288                         "    Set the forwarding ports hexadecimal mask.\n\n"
289
290                         "set burst (num)\n"
291                         "    Set number of packets per burst.\n\n"
292
293                         "set burst tx delay (microseconds) retry (num)\n"
294                         "    Set the transmit delay time and number of retries,"
295                         " effective when retry is enabled.\n\n"
296
297                         "set rxoffs (x[,y]*)\n"
298                         "    Set the offset of each packet segment on"
299                         " receiving if split feature is engaged."
300                         " Affects only the queues configured with split"
301                         " offloads.\n\n"
302
303                         "set rxpkts (x[,y]*)\n"
304                         "    Set the length of each segment to scatter"
305                         " packets on receiving if split feature is engaged."
306                         " Affects only the queues configured with split"
307                         " offloads.\n\n"
308
309                         "set txpkts (x[,y]*)\n"
310                         "    Set the length of each segment of TXONLY"
311                         " and optionally CSUM packets.\n\n"
312
313                         "set txsplit (off|on|rand)\n"
314                         "    Set the split policy for the TX packets."
315                         " Right now only applicable for CSUM and TXONLY"
316                         " modes\n\n"
317
318                         "set txtimes (x, y)\n"
319                         "    Set the scheduling on timestamps"
320                         " timings for the TXONLY mode\n\n"
321
322                         "set corelist (x[,y]*)\n"
323                         "    Set the list of forwarding cores.\n\n"
324
325                         "set portlist (x[,y]*)\n"
326                         "    Set the list of forwarding ports.\n\n"
327
328                         "set port setup on (iterator|event)\n"
329                         "    Select how attached port is retrieved for setup.\n\n"
330
331                         "set tx loopback (port_id) (on|off)\n"
332                         "    Enable or disable tx loopback.\n\n"
333
334                         "set all queues drop (port_id) (on|off)\n"
335                         "    Set drop enable bit for all queues.\n\n"
336
337                         "set vf split drop (port_id) (vf_id) (on|off)\n"
338                         "    Set split drop enable bit for a VF from the PF.\n\n"
339
340                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
341                         "    Set MAC antispoof for a VF from the PF.\n\n"
342
343                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
344                         "    Enable MACsec offload.\n\n"
345
346                         "set macsec offload (port_id) off\n"
347                         "    Disable MACsec offload.\n\n"
348
349                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
350                         "    Configure MACsec secure connection (SC).\n\n"
351
352                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
353                         "    Configure MACsec secure association (SA).\n\n"
354
355                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
356                         "    Set VF broadcast for a VF from the PF.\n\n"
357
358                         "vlan set stripq (on|off) (port_id,queue_id)\n"
359                         "    Set the VLAN strip for a queue on a port.\n\n"
360
361                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
362                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
363
364                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
365                         "    Set VLAN insert for a VF from the PF.\n\n"
366
367                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
368                         "    Set VLAN antispoof for a VF from the PF.\n\n"
369
370                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
371                         "    Set VLAN tag for a VF from the PF.\n\n"
372
373                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
374                         "    Set a VF's max bandwidth(Mbps).\n\n"
375
376                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
377                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
378
379                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
380                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
381
382                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
383                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
384
385                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
386                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
387
388                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
389                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
390
391                         "vlan set (inner|outer) tpid (value) (port_id)\n"
392                         "    Set the VLAN TPID for Packet Filtering on"
393                         " a port\n\n"
394
395                         "rx_vlan add (vlan_id|all) (port_id)\n"
396                         "    Add a vlan_id, or all identifiers, to the set"
397                         " of VLAN identifiers filtered by port_id.\n\n"
398
399                         "rx_vlan rm (vlan_id|all) (port_id)\n"
400                         "    Remove a vlan_id, or all identifiers, from the set"
401                         " of VLAN identifiers filtered by port_id.\n\n"
402
403                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
404                         "    Add a vlan_id, to the set of VLAN identifiers"
405                         "filtered for VF(s) from port_id.\n\n"
406
407                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
408                         "    Remove a vlan_id, to the set of VLAN identifiers"
409                         "filtered for VF(s) from port_id.\n\n"
410
411                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
412                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
413                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
414                         "   add a tunnel filter of a port.\n\n"
415
416                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
417                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
418                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
419                         "   remove a tunnel filter of a port.\n\n"
420
421                         "rx_vxlan_port add (udp_port) (port_id)\n"
422                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
423
424                         "rx_vxlan_port rm (udp_port) (port_id)\n"
425                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
426
427                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
428                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
429                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
430
431                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
432                         "    Set port based TX VLAN insertion.\n\n"
433
434                         "tx_vlan reset (port_id)\n"
435                         "    Disable hardware insertion of a VLAN header in"
436                         " packets sent on a port.\n\n"
437
438                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
439                         "    Select hardware or software calculation of the"
440                         " checksum when transmitting a packet using the"
441                         " csum forward engine.\n"
442                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
443                         "    outer-ip concerns the outer IP layer in"
444                         "    outer-udp concerns the outer UDP layer in"
445                         " case the packet is recognized as a tunnel packet by"
446                         " the forward engine (vxlan, gre and ipip are supported)\n"
447                         "    Please check the NIC datasheet for HW limits.\n\n"
448
449                         "csum parse-tunnel (on|off) (tx_port_id)\n"
450                         "    If disabled, treat tunnel packets as non-tunneled"
451                         " packets (treat inner headers as payload). The port\n"
452                         "    argument is the port used for TX in csum forward"
453                         " engine.\n\n"
454
455                         "csum show (port_id)\n"
456                         "    Display tx checksum offload configuration\n\n"
457
458                         "tso set (segsize) (portid)\n"
459                         "    Enable TCP Segmentation Offload in csum forward"
460                         " engine.\n"
461                         "    Please check the NIC datasheet for HW limits.\n\n"
462
463                         "tso show (portid)"
464                         "    Display the status of TCP Segmentation Offload.\n\n"
465
466                         "set port (port_id) gro on|off\n"
467                         "    Enable or disable Generic Receive Offload in"
468                         " csum forwarding engine.\n\n"
469
470                         "show port (port_id) gro\n"
471                         "    Display GRO configuration.\n\n"
472
473                         "set gro flush (cycles)\n"
474                         "    Set the cycle to flush GROed packets from"
475                         " reassembly tables.\n\n"
476
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
488                         "set fwd (%s)\n"
489                         "    Set packet forwarding mode.\n\n"
490
491                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
492                         "    Add a MAC address on port_id.\n\n"
493
494                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
495                         "    Remove a MAC address from port_id.\n\n"
496
497                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
498                         "    Set the default MAC address for port_id.\n\n"
499
500                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
501                         "    Add a MAC address for a VF on the port.\n\n"
502
503                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
504                         "    Set the MAC address for a VF from the PF.\n\n"
505
506                         "set eth-peer (port_id) (peer_addr)\n"
507                         "    set the peer address for certain port.\n\n"
508
509                         "set port (port_id) uta (mac_address|all) (on|off)\n"
510                         "    Add/Remove a or all unicast hash filter(s)"
511                         "from port X.\n\n"
512
513                         "set promisc (port_id|all) (on|off)\n"
514                         "    Set the promiscuous mode on port_id, or all.\n\n"
515
516                         "set allmulti (port_id|all) (on|off)\n"
517                         "    Set the allmulti mode on port_id, or all.\n\n"
518
519                         "set vf promisc (port_id) (vf_id) (on|off)\n"
520                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
521
522                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
523                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
524
525                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
526                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
527                         " (on|off) autoneg (on|off) (port_id)\n"
528                         "set flow_ctrl rx (on|off) (portid)\n"
529                         "set flow_ctrl tx (on|off) (portid)\n"
530                         "set flow_ctrl high_water (high_water) (portid)\n"
531                         "set flow_ctrl low_water (low_water) (portid)\n"
532                         "set flow_ctrl pause_time (pause_time) (portid)\n"
533                         "set flow_ctrl send_xon (send_xon) (portid)\n"
534                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
535                         "set flow_ctrl autoneg (on|off) (port_id)\n"
536                         "    Set the link flow control parameter on a port.\n\n"
537
538                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
539                         " (low_water) (pause_time) (priority) (port_id)\n"
540                         "    Set the priority flow control parameter on a"
541                         " port.\n\n"
542
543                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
544                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
545                         " queue on port.\n"
546                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
547                         " on port 0 to mapping 5.\n\n"
548
549                         "set xstats-hide-zero on|off\n"
550                         "    Set the option to hide the zero values"
551                         " for xstats display.\n"
552
553                         "set record-core-cycles on|off\n"
554                         "    Set the option to enable measurement of CPU cycles.\n"
555
556                         "set record-burst-stats on|off\n"
557                         "    Set the option to enable display of RX and TX bursts.\n"
558
559                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
560                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
561
562                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
563                         "|MPE) (on|off)\n"
564                         "    AUPE:accepts untagged VLAN;"
565                         "ROPE:accept unicast hash\n\n"
566                         "    BAM:accepts broadcast packets;"
567                         "MPE:accepts all multicast packets\n\n"
568                         "    Enable/Disable a VF receive mode of a port\n\n"
569
570                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
571                         "    Set rate limit for a queue of a port\n\n"
572
573                         "set port (port_id) vf (vf_id) rate (rate_num) "
574                         "queue_mask (queue_mask_value)\n"
575                         "    Set rate limit for queues in VF of a port\n\n"
576
577                         "set port (port_id) mirror-rule (rule_id)"
578                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
579                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
580                         "   Set pool or vlan type mirror rule on a port.\n"
581                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
582                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
583                         " to pool 0.\n\n"
584
585                         "set port (port_id) mirror-rule (rule_id)"
586                         " (uplink-mirror|downlink-mirror) dst-pool"
587                         " (pool_id) (on|off)\n"
588                         "   Set uplink or downlink type mirror rule on a port.\n"
589                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
590                         " 0 on' enable mirror income traffic to pool 0.\n\n"
591
592                         "reset port (port_id) mirror-rule (rule_id)\n"
593                         "   Reset a mirror rule.\n\n"
594
595                         "set flush_rx (on|off)\n"
596                         "   Flush (default) or don't flush RX streams before"
597                         " forwarding. Mainly used with PCAP drivers.\n\n"
598
599                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
600                         "   Set the bypass mode for the lowest port on bypass enabled"
601                         " NIC.\n\n"
602
603                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
604                         "mode (normal|bypass|isolate) (port_id)\n"
605                         "   Set the event required to initiate specified bypass mode for"
606                         " the lowest port on a bypass enabled NIC where:\n"
607                         "       timeout   = enable bypass after watchdog timeout.\n"
608                         "       os_on     = enable bypass when OS/board is powered on.\n"
609                         "       os_off    = enable bypass when OS/board is powered off.\n"
610                         "       power_on  = enable bypass when power supply is turned on.\n"
611                         "       power_off = enable bypass when power supply is turned off."
612                         "\n\n"
613
614                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
615                         "   Set the bypass watchdog timeout to 'n' seconds"
616                         " where 0 = instant.\n\n"
617
618                         "show bypass config (port_id)\n"
619                         "   Show the bypass configuration for a bypass enabled NIC"
620                         " using the lowest port on the NIC.\n\n"
621
622 #ifdef RTE_NET_BOND
623                         "create bonded device (mode) (socket)\n"
624                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
625
626                         "add bonding slave (slave_id) (port_id)\n"
627                         "       Add a slave device to a bonded device.\n\n"
628
629                         "remove bonding slave (slave_id) (port_id)\n"
630                         "       Remove a slave device from a bonded device.\n\n"
631
632                         "set bonding mode (value) (port_id)\n"
633                         "       Set the bonding mode on a bonded device.\n\n"
634
635                         "set bonding primary (slave_id) (port_id)\n"
636                         "       Set the primary slave for a bonded device.\n\n"
637
638                         "show bonding config (port_id)\n"
639                         "       Show the bonding config for port_id.\n\n"
640
641                         "set bonding mac_addr (port_id) (address)\n"
642                         "       Set the MAC address of a bonded device.\n\n"
643
644                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
645                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
646
647                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
648                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
649
650                         "set bonding mon_period (port_id) (value)\n"
651                         "       Set the bonding link status monitoring polling period in ms.\n\n"
652
653                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
654                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
655
656 #endif
657                         "set link-up port (port_id)\n"
658                         "       Set link up for a port.\n\n"
659
660                         "set link-down port (port_id)\n"
661                         "       Set link down for a port.\n\n"
662
663                         "E-tag set insertion on port-tag-id (value)"
664                         " port (port_id) vf (vf_id)\n"
665                         "    Enable E-tag insertion for a VF on a port\n\n"
666
667                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
668                         "    Disable E-tag insertion for a VF on a port\n\n"
669
670                         "E-tag set stripping (on|off) port (port_id)\n"
671                         "    Enable/disable E-tag stripping on a port\n\n"
672
673                         "E-tag set forwarding (on|off) port (port_id)\n"
674                         "    Enable/disable E-tag based forwarding"
675                         " on a port\n\n"
676
677                         "E-tag set filter add e-tag-id (value) dst-pool"
678                         " (pool_id) port (port_id)\n"
679                         "    Add an E-tag forwarding filter on a port\n\n"
680
681                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
682                         "    Delete an E-tag forwarding filter on a port\n\n"
683
684                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
685                         "    Load a profile package on a port\n\n"
686
687                         "ddp del (port_id) (backup_profile_path)\n"
688                         "    Delete a profile package from a port\n\n"
689
690                         "ptype mapping get (port_id) (valid_only)\n"
691                         "    Get ptype mapping on a port\n\n"
692
693                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
694                         "    Replace target with the pkt_type in ptype mapping\n\n"
695
696                         "ptype mapping reset (port_id)\n"
697                         "    Reset ptype mapping on a port\n\n"
698
699                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
700                         "    Update a ptype mapping item on a port\n\n"
701
702                         "set port (port_id) ptype_mask (ptype_mask)\n"
703                         "    set packet types classification for a specific port\n\n"
704
705                         "set port (port_id) queue-region region_id (value) "
706                         "queue_start_index (value) queue_num (value)\n"
707                         "    Set a queue region on a port\n\n"
708
709                         "set port (port_id) queue-region region_id (value) "
710                         "flowtype (value)\n"
711                         "    Set a flowtype region index on a port\n\n"
712
713                         "set port (port_id) queue-region UP (value) region_id (value)\n"
714                         "    Set the mapping of User Priority to "
715                         "queue region on a port\n\n"
716
717                         "set port (port_id) queue-region flush (on|off)\n"
718                         "    flush all queue region related configuration\n\n"
719
720                         "show port meter cap (port_id)\n"
721                         "    Show port meter capability information\n\n"
722
723                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
724                         "    meter profile add - srtcm rfc 2697\n\n"
725
726                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
727                         "    meter profile add - trtcm rfc 2698\n\n"
728
729                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
730                         "    meter profile add - trtcm rfc 4115\n\n"
731
732                         "del port meter profile (port_id) (profile_id)\n"
733                         "    meter profile delete\n\n"
734
735                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
736                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
737                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
738                         "(dscp_tbl_entry63)]\n"
739                         "    meter create\n\n"
740
741                         "enable port meter (port_id) (mtr_id)\n"
742                         "    meter enable\n\n"
743
744                         "disable port meter (port_id) (mtr_id)\n"
745                         "    meter disable\n\n"
746
747                         "del port meter (port_id) (mtr_id)\n"
748                         "    meter delete\n\n"
749
750                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
751                         "    meter update meter profile\n\n"
752
753                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
754                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
755                         "    update meter dscp table entries\n\n"
756
757                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
758                         "(action0) [(action1) (action2)]\n"
759                         "    meter update policer action\n\n"
760
761                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
762                         "    meter update stats\n\n"
763
764                         "show port (port_id) queue-region\n"
765                         "    show all queue region related configuration info\n\n"
766
767                         "set port (port_id) fec_mode auto|off|rs|baser\n"
768                         "    set fec mode for a specific port\n\n"
769
770                         , list_pkt_forwarding_modes()
771                 );
772         }
773
774         if (show_all || !strcmp(res->section, "ports")) {
775
776                 cmdline_printf(
777                         cl,
778                         "\n"
779                         "Port Operations:\n"
780                         "----------------\n\n"
781
782                         "port start (port_id|all)\n"
783                         "    Start all ports or port_id.\n\n"
784
785                         "port stop (port_id|all)\n"
786                         "    Stop all ports or port_id.\n\n"
787
788                         "port close (port_id|all)\n"
789                         "    Close all ports or port_id.\n\n"
790
791                         "port reset (port_id|all)\n"
792                         "    Reset all ports or port_id.\n\n"
793
794                         "port attach (ident)\n"
795                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
796
797                         "port detach (port_id)\n"
798                         "    Detach physical or virtual dev by port_id\n\n"
799
800                         "port config (port_id|all)"
801                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
802                         " duplex (half|full|auto)\n"
803                         "    Set speed and duplex for all ports or port_id\n\n"
804
805                         "port config (port_id|all) loopback (mode)\n"
806                         "    Set loopback mode for all ports or port_id\n\n"
807
808                         "port config all (rxq|txq|rxd|txd) (value)\n"
809                         "    Set number for rxq/txq/rxd/txd.\n\n"
810
811                         "port config all max-pkt-len (value)\n"
812                         "    Set the max packet length.\n\n"
813
814                         "port config all max-lro-pkt-size (value)\n"
815                         "    Set the max LRO aggregated packet size.\n\n"
816
817                         "port config all drop-en (on|off)\n"
818                         "    Enable or disable packet drop on all RX queues of all ports when no "
819                         "receive buffers available.\n\n"
820
821                         "port config all rss (all|default|ip|tcp|udp|sctp|"
822                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|level-default|"
823                         "level-outer|level-inner|<flowtype_id>)\n"
824                         "    Set the RSS mode.\n\n"
825
826                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
827                         "    Set the RSS redirection table.\n\n"
828
829                         "port config (port_id) dcb vt (on|off) (traffic_class)"
830                         " pfc (on|off)\n"
831                         "    Set the DCB mode.\n\n"
832
833                         "port config all burst (value)\n"
834                         "    Set the number of packets per burst.\n\n"
835
836                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
837                         " (value)\n"
838                         "    Set the ring prefetch/host/writeback threshold"
839                         " for tx/rx queue.\n\n"
840
841                         "port config all (txfreet|txrst|rxfreet) (value)\n"
842                         "    Set free threshold for rx/tx, or set"
843                         " tx rs bit threshold.\n\n"
844                         "port config mtu X value\n"
845                         "    Set the MTU of port X to a given value\n\n"
846
847                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
848                         "    Set a rx/tx queue's ring size configuration, the new"
849                         " value will take effect after command that (re-)start the port"
850                         " or command that setup the specific queue\n\n"
851
852                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
853                         "    Start/stop a rx/tx queue of port X. Only take effect"
854                         " when port X is started\n\n"
855
856                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
857                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
858                         " take effect when port X is stopped.\n\n"
859
860                         "port (port_id) (rxq|txq) (queue_id) setup\n"
861                         "    Setup a rx/tx queue of port X.\n\n"
862
863                         "port config (port_id|all) l2-tunnel E-tag ether-type"
864                         " (value)\n"
865                         "    Set the value of E-tag ether-type.\n\n"
866
867                         "port config (port_id|all) l2-tunnel E-tag"
868                         " (enable|disable)\n"
869                         "    Enable/disable the E-tag support.\n\n"
870
871                         "port config (port_id) pctype mapping reset\n"
872                         "    Reset flow type to pctype mapping on a port\n\n"
873
874                         "port config (port_id) pctype mapping update"
875                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
876                         "    Update a flow type to pctype mapping item on a port\n\n"
877
878                         "port config (port_id) pctype (pctype_id) hash_inset|"
879                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
880                         " (field_idx)\n"
881                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
882
883                         "port config (port_id) pctype (pctype_id) hash_inset|"
884                         "fdir_inset|fdir_flx_inset clear all"
885                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
886
887                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
888                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
889
890                         "port config <port_id> rx_offload vlan_strip|"
891                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
892                         "outer_ipv4_cksum|macsec_strip|header_split|"
893                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
894                         "buffer_split|timestamp|security|keep_crc on|off\n"
895                         "     Enable or disable a per port Rx offloading"
896                         " on all Rx queues of a port\n\n"
897
898                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
899                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
900                         "outer_ipv4_cksum|macsec_strip|header_split|"
901                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
902                         "buffer_split|timestamp|security|keep_crc on|off\n"
903                         "    Enable or disable a per queue Rx offloading"
904                         " only on a specific Rx queue\n\n"
905
906                         "port config (port_id) tx_offload vlan_insert|"
907                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
908                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
909                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
910                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
911                         "security on|off\n"
912                         "    Enable or disable a per port Tx offloading"
913                         " on all Tx queues of a port\n\n"
914
915                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
916                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
917                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
918                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
919                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
920                         " on|off\n"
921                         "    Enable or disable a per queue Tx offloading"
922                         " only on a specific Tx queue\n\n"
923
924                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
925                         "    Load an eBPF program as a callback"
926                         " for particular RX/TX queue\n\n"
927
928                         "bpf-unload rx|tx (port) (queue)\n"
929                         "    Unload previously loaded eBPF program"
930                         " for particular RX/TX queue\n\n"
931
932                         "port config (port_id) tx_metadata (value)\n"
933                         "    Set Tx metadata value per port. Testpmd will add this value"
934                         " to any Tx packet sent from this port\n\n"
935
936                         "port config (port_id) dynf (name) set|clear\n"
937                         "    Register a dynf and Set/clear this flag on Tx. "
938                         "Testpmd will set this value to any Tx packet "
939                         "sent from this port\n\n"
940                 );
941         }
942
943         if (show_all || !strcmp(res->section, "registers")) {
944
945                 cmdline_printf(
946                         cl,
947                         "\n"
948                         "Registers:\n"
949                         "----------\n\n"
950
951                         "read reg (port_id) (address)\n"
952                         "    Display value of a port register.\n\n"
953
954                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
955                         "    Display a port register bit field.\n\n"
956
957                         "read regbit (port_id) (address) (bit_x)\n"
958                         "    Display a single port register bit.\n\n"
959
960                         "write reg (port_id) (address) (value)\n"
961                         "    Set value of a port register.\n\n"
962
963                         "write regfield (port_id) (address) (bit_x) (bit_y)"
964                         " (value)\n"
965                         "    Set bit field of a port register.\n\n"
966
967                         "write regbit (port_id) (address) (bit_x) (value)\n"
968                         "    Set single bit value of a port register.\n\n"
969                 );
970         }
971         if (show_all || !strcmp(res->section, "filters")) {
972
973                 cmdline_printf(
974                         cl,
975                         "\n"
976                         "filters:\n"
977                         "--------\n\n"
978
979                         "ethertype_filter (port_id) (add|del)"
980                         " (mac_addr|mac_ignr) (mac_address) ethertype"
981                         " (ether_type) (drop|fwd) queue (queue_id)\n"
982                         "    Add/Del an ethertype filter.\n\n"
983
984                         "2tuple_filter (port_id) (add|del)"
985                         " dst_port (dst_port_value) protocol (protocol_value)"
986                         " mask (mask_value) tcp_flags (tcp_flags_value)"
987                         " priority (prio_value) queue (queue_id)\n"
988                         "    Add/Del a 2tuple filter.\n\n"
989
990                         "5tuple_filter (port_id) (add|del)"
991                         " dst_ip (dst_address) src_ip (src_address)"
992                         " dst_port (dst_port_value) src_port (src_port_value)"
993                         " protocol (protocol_value)"
994                         " mask (mask_value) tcp_flags (tcp_flags_value)"
995                         " priority (prio_value) queue (queue_id)\n"
996                         "    Add/Del a 5tuple filter.\n\n"
997
998                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
999                         "    Add/Del syn filter.\n\n"
1000
1001                         "flex_filter (port_id) (add|del) len (len_value)"
1002                         " bytes (bytes_value) mask (mask_value)"
1003                         " priority (prio_value) queue (queue_id)\n"
1004                         "    Add/Del a flex filter.\n\n"
1005
1006                         "flow_director_filter (port_id) mode IP (add|del|update)"
1007                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
1008                         " src (src_ip_address) dst (dst_ip_address)"
1009                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
1010                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1011                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1012                         " fd_id (fd_id_value)\n"
1013                         "    Add/Del an IP type flow director filter.\n\n"
1014
1015                         "flow_director_filter (port_id) mode IP (add|del|update)"
1016                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
1017                         " src (src_ip_address) (src_port)"
1018                         " dst (dst_ip_address) (dst_port)"
1019                         " tos (tos_value) ttl (ttl_value)"
1020                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1021                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1022                         " fd_id (fd_id_value)\n"
1023                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1024
1025                         "flow_director_filter (port_id) mode IP (add|del|update)"
1026                         " flow (ipv4-sctp|ipv6-sctp)"
1027                         " src (src_ip_address) (src_port)"
1028                         " dst (dst_ip_address) (dst_port)"
1029                         " tag (verification_tag) "
1030                         " tos (tos_value) ttl (ttl_value)"
1031                         " vlan (vlan_value)"
1032                         " flexbytes (flexbytes_value) (drop|fwd)"
1033                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1034                         "    Add/Del a SCTP type flow director filter.\n\n"
1035
1036                         "flow_director_filter (port_id) mode IP (add|del|update)"
1037                         " flow l2_payload ether (ethertype)"
1038                         " flexbytes (flexbytes_value) (drop|fwd)"
1039                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1040                         "    Add/Del a l2 payload type flow director filter.\n\n"
1041
1042                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1043                         " mac (mac_address) vlan (vlan_value)"
1044                         " flexbytes (flexbytes_value) (drop|fwd)"
1045                         " queue (queue_id) fd_id (fd_id_value)\n"
1046                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1047
1048                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1049                         " mac (mac_address) vlan (vlan_value)"
1050                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1051                         " flexbytes (flexbytes_value) (drop|fwd)"
1052                         " queue (queue_id) fd_id (fd_id_value)\n"
1053                         "    Add/Del a Tunnel flow director filter.\n\n"
1054
1055                         "flow_director_filter (port_id) mode raw (add|del|update)"
1056                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1057                         " fd_id (fd_id_value) packet (packet file name)\n"
1058                         "    Add/Del a raw type flow director filter.\n\n"
1059
1060                         "flush_flow_director (port_id)\n"
1061                         "    Flush all flow director entries of a device.\n\n"
1062
1063                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1064                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1065                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1066                         "    Set flow director IP mask.\n\n"
1067
1068                         "flow_director_mask (port_id) mode MAC-VLAN"
1069                         " vlan (vlan_value)\n"
1070                         "    Set flow director MAC-VLAN mask.\n\n"
1071
1072                         "flow_director_mask (port_id) mode Tunnel"
1073                         " vlan (vlan_value) mac (mac_value)"
1074                         " tunnel-type (tunnel_type_value)"
1075                         " tunnel-id (tunnel_id_value)\n"
1076                         "    Set flow director Tunnel mask.\n\n"
1077
1078                         "flow_director_flex_mask (port_id)"
1079                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1080                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1081                         " (mask)\n"
1082                         "    Configure mask of flex payload.\n\n"
1083
1084                         "flow_director_flex_payload (port_id)"
1085                         " (raw|l2|l3|l4) (config)\n"
1086                         "    Configure flex payload selection.\n\n"
1087
1088                         "get_sym_hash_ena_per_port (port_id)\n"
1089                         "    get symmetric hash enable configuration per port.\n\n"
1090
1091                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1092                         "    set symmetric hash enable configuration per port"
1093                         " to enable or disable.\n\n"
1094
1095                         "get_hash_global_config (port_id)\n"
1096                         "    Get the global configurations of hash filters.\n\n"
1097
1098                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1099                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1100                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1101                         " (enable|disable)\n"
1102                         "    Set the global configurations of hash filters.\n\n"
1103
1104                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1105                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1106                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1107                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1108                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1109                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1110                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1111                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1112                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1113                         "fld-8th|none) (select|add)\n"
1114                         "    Set the input set for hash.\n\n"
1115
1116                         "set_fdir_input_set (port_id) "
1117                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1118                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1119                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1120                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1121                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1122                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1123                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1124                         " (select|add)\n"
1125                         "    Set the input set for FDir.\n\n"
1126
1127                         "flow validate {port_id}"
1128                         " [group {group_id}] [priority {level}]"
1129                         " [ingress] [egress]"
1130                         " pattern {item} [/ {item} [...]] / end"
1131                         " actions {action} [/ {action} [...]] / end\n"
1132                         "    Check whether a flow rule can be created.\n\n"
1133
1134                         "flow create {port_id}"
1135                         " [group {group_id}] [priority {level}]"
1136                         " [ingress] [egress]"
1137                         " pattern {item} [/ {item} [...]] / end"
1138                         " actions {action} [/ {action} [...]] / end\n"
1139                         "    Create a flow rule.\n\n"
1140
1141                         "flow destroy {port_id} rule {rule_id} [...]\n"
1142                         "    Destroy specific flow rules.\n\n"
1143
1144                         "flow flush {port_id}\n"
1145                         "    Destroy all flow rules.\n\n"
1146
1147                         "flow query {port_id} {rule_id} {action}\n"
1148                         "    Query an existing flow rule.\n\n"
1149
1150                         "flow list {port_id} [group {group_id}] [...]\n"
1151                         "    List existing flow rules sorted by priority,"
1152                         " filtered by group identifiers.\n\n"
1153
1154                         "flow isolate {port_id} {boolean}\n"
1155                         "    Restrict ingress traffic to the defined"
1156                         " flow rules\n\n"
1157
1158                         "flow aged {port_id} [destroy]\n"
1159                         "    List and destroy aged flows"
1160                         " flow rules\n\n"
1161
1162                         "flow shared_action {port_id} create"
1163                         " [action_id {shared_action_id}]"
1164                         " [ingress] [egress]"
1165                         " action {action} / end\n"
1166                         "    Create shared action.\n\n"
1167
1168                         "flow shared_action {port_id} update"
1169                         " {shared_action_id} action {action} / end\n"
1170                         "    Update shared action.\n\n"
1171
1172                         "flow shared_action {port_id} destroy"
1173                         " action_id {shared_action_id} [...]\n"
1174                         "    Destroy specific shared actions.\n\n"
1175
1176                         "flow shared_action {port_id} query"
1177                         " {shared_action_id}\n"
1178                         "    Query an existing shared action.\n\n"
1179
1180                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1181                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1182                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1183                         "       Configure the VXLAN encapsulation for flows.\n\n"
1184
1185                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1186                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1187                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1188                         " eth-dst (eth-dst)\n"
1189                         "       Configure the VXLAN encapsulation for flows.\n\n"
1190
1191                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1192                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1193                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1194                         " eth-dst (eth-dst)\n"
1195                         "       Configure the VXLAN encapsulation for flows.\n\n"
1196
1197                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1198                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1199                         " (eth-dst)\n"
1200                         "       Configure the NVGRE encapsulation for flows.\n\n"
1201
1202                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1203                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1204                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1205                         "       Configure the NVGRE encapsulation for flows.\n\n"
1206
1207                         "set raw_encap {flow items}\n"
1208                         "       Configure the encapsulation with raw data.\n\n"
1209
1210                         "set raw_decap {flow items}\n"
1211                         "       Configure the decapsulation with raw data.\n\n"
1212
1213                 );
1214         }
1215
1216         if (show_all || !strcmp(res->section, "traffic_management")) {
1217                 cmdline_printf(
1218                         cl,
1219                         "\n"
1220                         "Traffic Management:\n"
1221                         "--------------\n"
1222                         "show port tm cap (port_id)\n"
1223                         "       Display the port TM capability.\n\n"
1224
1225                         "show port tm level cap (port_id) (level_id)\n"
1226                         "       Display the port TM hierarchical level capability.\n\n"
1227
1228                         "show port tm node cap (port_id) (node_id)\n"
1229                         "       Display the port TM node capability.\n\n"
1230
1231                         "show port tm node type (port_id) (node_id)\n"
1232                         "       Display the port TM node type.\n\n"
1233
1234                         "show port tm node stats (port_id) (node_id) (clear)\n"
1235                         "       Display the port TM node stats.\n\n"
1236
1237                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1238                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1239                         " (packet_length_adjust) (packet_mode)\n"
1240                         "       Add port tm node private shaper profile.\n\n"
1241
1242                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1243                         "       Delete port tm node private shaper profile.\n\n"
1244
1245                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1246                         " (shaper_profile_id)\n"
1247                         "       Add/update port tm node shared shaper.\n\n"
1248
1249                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1250                         "       Delete port tm node shared shaper.\n\n"
1251
1252                         "set port tm node shaper profile (port_id) (node_id)"
1253                         " (shaper_profile_id)\n"
1254                         "       Set port tm node shaper profile.\n\n"
1255
1256                         "add port tm node wred profile (port_id) (wred_profile_id)"
1257                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1258                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1259                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1260                         "       Add port tm node wred profile.\n\n"
1261
1262                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1263                         "       Delete port tm node wred profile.\n\n"
1264
1265                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1266                         " (priority) (weight) (level_id) (shaper_profile_id)"
1267                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1268                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1269                         "       Add port tm nonleaf node.\n\n"
1270
1271                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1272                         " (priority) (weight) (level_id) (shaper_profile_id)"
1273                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1274                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1275                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1276
1277                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1278                         " (priority) (weight) (level_id) (shaper_profile_id)"
1279                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1280                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1281                         "       Add port tm leaf node.\n\n"
1282
1283                         "del port tm node (port_id) (node_id)\n"
1284                         "       Delete port tm node.\n\n"
1285
1286                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1287                         " (priority) (weight)\n"
1288                         "       Set port tm node parent.\n\n"
1289
1290                         "suspend port tm node (port_id) (node_id)"
1291                         "       Suspend tm node.\n\n"
1292
1293                         "resume port tm node (port_id) (node_id)"
1294                         "       Resume tm node.\n\n"
1295
1296                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1297                         "       Commit tm hierarchy.\n\n"
1298
1299                         "set port tm mark ip_ecn (port) (green) (yellow)"
1300                         " (red)\n"
1301                         "    Enables/Disables the traffic management marking"
1302                         " for IP ECN (Explicit Congestion Notification)"
1303                         " packets on a given port\n\n"
1304
1305                         "set port tm mark ip_dscp (port) (green) (yellow)"
1306                         " (red)\n"
1307                         "    Enables/Disables the traffic management marking"
1308                         " on the port for IP dscp packets\n\n"
1309
1310                         "set port tm mark vlan_dei (port) (green) (yellow)"
1311                         " (red)\n"
1312                         "    Enables/Disables the traffic management marking"
1313                         " on the port for VLAN packets with DEI enabled\n\n"
1314                 );
1315         }
1316
1317         if (show_all || !strcmp(res->section, "devices")) {
1318                 cmdline_printf(
1319                         cl,
1320                         "\n"
1321                         "Device Operations:\n"
1322                         "--------------\n"
1323                         "device detach (identifier)\n"
1324                         "       Detach device by identifier.\n\n"
1325                 );
1326         }
1327
1328 }
1329
1330 cmdline_parse_token_string_t cmd_help_long_help =
1331         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1332
1333 cmdline_parse_token_string_t cmd_help_long_section =
1334         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1335                         "all#control#display#config#"
1336                         "ports#registers#filters#traffic_management#devices");
1337
1338 cmdline_parse_inst_t cmd_help_long = {
1339         .f = cmd_help_long_parsed,
1340         .data = NULL,
1341         .help_str = "help all|control|display|config|ports|register|"
1342                 "filters|traffic_management|devices: "
1343                 "Show help",
1344         .tokens = {
1345                 (void *)&cmd_help_long_help,
1346                 (void *)&cmd_help_long_section,
1347                 NULL,
1348         },
1349 };
1350
1351
1352 /* *** start/stop/close all ports *** */
1353 struct cmd_operate_port_result {
1354         cmdline_fixed_string_t keyword;
1355         cmdline_fixed_string_t name;
1356         cmdline_fixed_string_t value;
1357 };
1358
1359 static void cmd_operate_port_parsed(void *parsed_result,
1360                                 __rte_unused struct cmdline *cl,
1361                                 __rte_unused void *data)
1362 {
1363         struct cmd_operate_port_result *res = parsed_result;
1364
1365         if (!strcmp(res->name, "start"))
1366                 start_port(RTE_PORT_ALL);
1367         else if (!strcmp(res->name, "stop"))
1368                 stop_port(RTE_PORT_ALL);
1369         else if (!strcmp(res->name, "close"))
1370                 close_port(RTE_PORT_ALL);
1371         else if (!strcmp(res->name, "reset"))
1372                 reset_port(RTE_PORT_ALL);
1373         else
1374                 printf("Unknown parameter\n");
1375 }
1376
1377 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1378         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1379                                                                 "port");
1380 cmdline_parse_token_string_t cmd_operate_port_all_port =
1381         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1382                                                 "start#stop#close#reset");
1383 cmdline_parse_token_string_t cmd_operate_port_all_all =
1384         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1385
1386 cmdline_parse_inst_t cmd_operate_port = {
1387         .f = cmd_operate_port_parsed,
1388         .data = NULL,
1389         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1390         .tokens = {
1391                 (void *)&cmd_operate_port_all_cmd,
1392                 (void *)&cmd_operate_port_all_port,
1393                 (void *)&cmd_operate_port_all_all,
1394                 NULL,
1395         },
1396 };
1397
1398 /* *** start/stop/close specific port *** */
1399 struct cmd_operate_specific_port_result {
1400         cmdline_fixed_string_t keyword;
1401         cmdline_fixed_string_t name;
1402         uint8_t value;
1403 };
1404
1405 static void cmd_operate_specific_port_parsed(void *parsed_result,
1406                         __rte_unused struct cmdline *cl,
1407                                 __rte_unused void *data)
1408 {
1409         struct cmd_operate_specific_port_result *res = parsed_result;
1410
1411         if (!strcmp(res->name, "start"))
1412                 start_port(res->value);
1413         else if (!strcmp(res->name, "stop"))
1414                 stop_port(res->value);
1415         else if (!strcmp(res->name, "close"))
1416                 close_port(res->value);
1417         else if (!strcmp(res->name, "reset"))
1418                 reset_port(res->value);
1419         else
1420                 printf("Unknown parameter\n");
1421 }
1422
1423 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1424         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1425                                                         keyword, "port");
1426 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1427         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1428                                                 name, "start#stop#close#reset");
1429 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1430         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1431                                                         value, UINT8);
1432
1433 cmdline_parse_inst_t cmd_operate_specific_port = {
1434         .f = cmd_operate_specific_port_parsed,
1435         .data = NULL,
1436         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1437         .tokens = {
1438                 (void *)&cmd_operate_specific_port_cmd,
1439                 (void *)&cmd_operate_specific_port_port,
1440                 (void *)&cmd_operate_specific_port_id,
1441                 NULL,
1442         },
1443 };
1444
1445 /* *** enable port setup (after attach) via iterator or event *** */
1446 struct cmd_set_port_setup_on_result {
1447         cmdline_fixed_string_t set;
1448         cmdline_fixed_string_t port;
1449         cmdline_fixed_string_t setup;
1450         cmdline_fixed_string_t on;
1451         cmdline_fixed_string_t mode;
1452 };
1453
1454 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1455                                 __rte_unused struct cmdline *cl,
1456                                 __rte_unused void *data)
1457 {
1458         struct cmd_set_port_setup_on_result *res = parsed_result;
1459
1460         if (strcmp(res->mode, "event") == 0)
1461                 setup_on_probe_event = true;
1462         else if (strcmp(res->mode, "iterator") == 0)
1463                 setup_on_probe_event = false;
1464         else
1465                 printf("Unknown mode\n");
1466 }
1467
1468 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1469         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1470                         set, "set");
1471 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1472         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1473                         port, "port");
1474 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1475         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1476                         setup, "setup");
1477 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1478         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1479                         on, "on");
1480 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1481         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1482                         mode, "iterator#event");
1483
1484 cmdline_parse_inst_t cmd_set_port_setup_on = {
1485         .f = cmd_set_port_setup_on_parsed,
1486         .data = NULL,
1487         .help_str = "set port setup on iterator|event",
1488         .tokens = {
1489                 (void *)&cmd_set_port_setup_on_set,
1490                 (void *)&cmd_set_port_setup_on_port,
1491                 (void *)&cmd_set_port_setup_on_setup,
1492                 (void *)&cmd_set_port_setup_on_on,
1493                 (void *)&cmd_set_port_setup_on_mode,
1494                 NULL,
1495         },
1496 };
1497
1498 /* *** attach a specified port *** */
1499 struct cmd_operate_attach_port_result {
1500         cmdline_fixed_string_t port;
1501         cmdline_fixed_string_t keyword;
1502         cmdline_multi_string_t identifier;
1503 };
1504
1505 static void cmd_operate_attach_port_parsed(void *parsed_result,
1506                                 __rte_unused struct cmdline *cl,
1507                                 __rte_unused void *data)
1508 {
1509         struct cmd_operate_attach_port_result *res = parsed_result;
1510
1511         if (!strcmp(res->keyword, "attach"))
1512                 attach_port(res->identifier);
1513         else
1514                 printf("Unknown parameter\n");
1515 }
1516
1517 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1518         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1519                         port, "port");
1520 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1521         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1522                         keyword, "attach");
1523 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1524         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1525                         identifier, TOKEN_STRING_MULTI);
1526
1527 cmdline_parse_inst_t cmd_operate_attach_port = {
1528         .f = cmd_operate_attach_port_parsed,
1529         .data = NULL,
1530         .help_str = "port attach <identifier>: "
1531                 "(identifier: pci address or virtual dev name)",
1532         .tokens = {
1533                 (void *)&cmd_operate_attach_port_port,
1534                 (void *)&cmd_operate_attach_port_keyword,
1535                 (void *)&cmd_operate_attach_port_identifier,
1536                 NULL,
1537         },
1538 };
1539
1540 /* *** detach a specified port *** */
1541 struct cmd_operate_detach_port_result {
1542         cmdline_fixed_string_t port;
1543         cmdline_fixed_string_t keyword;
1544         portid_t port_id;
1545 };
1546
1547 static void cmd_operate_detach_port_parsed(void *parsed_result,
1548                                 __rte_unused struct cmdline *cl,
1549                                 __rte_unused void *data)
1550 {
1551         struct cmd_operate_detach_port_result *res = parsed_result;
1552
1553         if (!strcmp(res->keyword, "detach")) {
1554                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1555                 detach_port_device(res->port_id);
1556         } else {
1557                 printf("Unknown parameter\n");
1558         }
1559 }
1560
1561 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1562         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1563                         port, "port");
1564 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1565         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1566                         keyword, "detach");
1567 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1568         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1569                         port_id, UINT16);
1570
1571 cmdline_parse_inst_t cmd_operate_detach_port = {
1572         .f = cmd_operate_detach_port_parsed,
1573         .data = NULL,
1574         .help_str = "port detach <port_id>",
1575         .tokens = {
1576                 (void *)&cmd_operate_detach_port_port,
1577                 (void *)&cmd_operate_detach_port_keyword,
1578                 (void *)&cmd_operate_detach_port_port_id,
1579                 NULL,
1580         },
1581 };
1582
1583 /* *** detach device by identifier *** */
1584 struct cmd_operate_detach_device_result {
1585         cmdline_fixed_string_t device;
1586         cmdline_fixed_string_t keyword;
1587         cmdline_fixed_string_t identifier;
1588 };
1589
1590 static void cmd_operate_detach_device_parsed(void *parsed_result,
1591                                 __rte_unused struct cmdline *cl,
1592                                 __rte_unused void *data)
1593 {
1594         struct cmd_operate_detach_device_result *res = parsed_result;
1595
1596         if (!strcmp(res->keyword, "detach"))
1597                 detach_devargs(res->identifier);
1598         else
1599                 printf("Unknown parameter\n");
1600 }
1601
1602 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1603         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1604                         device, "device");
1605 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1606         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1607                         keyword, "detach");
1608 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1609         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1610                         identifier, NULL);
1611
1612 cmdline_parse_inst_t cmd_operate_detach_device = {
1613         .f = cmd_operate_detach_device_parsed,
1614         .data = NULL,
1615         .help_str = "device detach <identifier>:"
1616                 "(identifier: pci address or virtual dev name)",
1617         .tokens = {
1618                 (void *)&cmd_operate_detach_device_device,
1619                 (void *)&cmd_operate_detach_device_keyword,
1620                 (void *)&cmd_operate_detach_device_identifier,
1621                 NULL,
1622         },
1623 };
1624 /* *** configure speed for all ports *** */
1625 struct cmd_config_speed_all {
1626         cmdline_fixed_string_t port;
1627         cmdline_fixed_string_t keyword;
1628         cmdline_fixed_string_t all;
1629         cmdline_fixed_string_t item1;
1630         cmdline_fixed_string_t item2;
1631         cmdline_fixed_string_t value1;
1632         cmdline_fixed_string_t value2;
1633 };
1634
1635 static int
1636 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1637 {
1638
1639         int duplex;
1640
1641         if (!strcmp(duplexstr, "half")) {
1642                 duplex = ETH_LINK_HALF_DUPLEX;
1643         } else if (!strcmp(duplexstr, "full")) {
1644                 duplex = ETH_LINK_FULL_DUPLEX;
1645         } else if (!strcmp(duplexstr, "auto")) {
1646                 duplex = ETH_LINK_FULL_DUPLEX;
1647         } else {
1648                 printf("Unknown duplex parameter\n");
1649                 return -1;
1650         }
1651
1652         if (!strcmp(speedstr, "10")) {
1653                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1654                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1655         } else if (!strcmp(speedstr, "100")) {
1656                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1657                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1658         } else {
1659                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1660                         printf("Invalid speed/duplex parameters\n");
1661                         return -1;
1662                 }
1663                 if (!strcmp(speedstr, "1000")) {
1664                         *speed = ETH_LINK_SPEED_1G;
1665                 } else if (!strcmp(speedstr, "10000")) {
1666                         *speed = ETH_LINK_SPEED_10G;
1667                 } else if (!strcmp(speedstr, "25000")) {
1668                         *speed = ETH_LINK_SPEED_25G;
1669                 } else if (!strcmp(speedstr, "40000")) {
1670                         *speed = ETH_LINK_SPEED_40G;
1671                 } else if (!strcmp(speedstr, "50000")) {
1672                         *speed = ETH_LINK_SPEED_50G;
1673                 } else if (!strcmp(speedstr, "100000")) {
1674                         *speed = ETH_LINK_SPEED_100G;
1675                 } else if (!strcmp(speedstr, "200000")) {
1676                         *speed = ETH_LINK_SPEED_200G;
1677                 } else if (!strcmp(speedstr, "auto")) {
1678                         *speed = ETH_LINK_SPEED_AUTONEG;
1679                 } else {
1680                         printf("Unknown speed parameter\n");
1681                         return -1;
1682                 }
1683         }
1684
1685         return 0;
1686 }
1687
1688 static void
1689 cmd_config_speed_all_parsed(void *parsed_result,
1690                         __rte_unused struct cmdline *cl,
1691                         __rte_unused void *data)
1692 {
1693         struct cmd_config_speed_all *res = parsed_result;
1694         uint32_t link_speed;
1695         portid_t pid;
1696
1697         if (!all_ports_stopped()) {
1698                 printf("Please stop all ports first\n");
1699                 return;
1700         }
1701
1702         if (parse_and_check_speed_duplex(res->value1, res->value2,
1703                         &link_speed) < 0)
1704                 return;
1705
1706         RTE_ETH_FOREACH_DEV(pid) {
1707                 ports[pid].dev_conf.link_speeds = link_speed;
1708         }
1709
1710         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1711 }
1712
1713 cmdline_parse_token_string_t cmd_config_speed_all_port =
1714         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1715 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1716         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1717                                                         "config");
1718 cmdline_parse_token_string_t cmd_config_speed_all_all =
1719         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1720 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1721         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1722 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1723         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1724                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1725 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1726         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1727 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1728         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1729                                                 "half#full#auto");
1730
1731 cmdline_parse_inst_t cmd_config_speed_all = {
1732         .f = cmd_config_speed_all_parsed,
1733         .data = NULL,
1734         .help_str = "port config all speed "
1735                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1736                                                         "half|full|auto",
1737         .tokens = {
1738                 (void *)&cmd_config_speed_all_port,
1739                 (void *)&cmd_config_speed_all_keyword,
1740                 (void *)&cmd_config_speed_all_all,
1741                 (void *)&cmd_config_speed_all_item1,
1742                 (void *)&cmd_config_speed_all_value1,
1743                 (void *)&cmd_config_speed_all_item2,
1744                 (void *)&cmd_config_speed_all_value2,
1745                 NULL,
1746         },
1747 };
1748
1749 /* *** configure speed for specific port *** */
1750 struct cmd_config_speed_specific {
1751         cmdline_fixed_string_t port;
1752         cmdline_fixed_string_t keyword;
1753         portid_t id;
1754         cmdline_fixed_string_t item1;
1755         cmdline_fixed_string_t item2;
1756         cmdline_fixed_string_t value1;
1757         cmdline_fixed_string_t value2;
1758 };
1759
1760 static void
1761 cmd_config_speed_specific_parsed(void *parsed_result,
1762                                 __rte_unused struct cmdline *cl,
1763                                 __rte_unused void *data)
1764 {
1765         struct cmd_config_speed_specific *res = parsed_result;
1766         uint32_t link_speed;
1767
1768         if (!all_ports_stopped()) {
1769                 printf("Please stop all ports first\n");
1770                 return;
1771         }
1772
1773         if (port_id_is_invalid(res->id, ENABLED_WARN))
1774                 return;
1775
1776         if (parse_and_check_speed_duplex(res->value1, res->value2,
1777                         &link_speed) < 0)
1778                 return;
1779
1780         ports[res->id].dev_conf.link_speeds = link_speed;
1781
1782         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1783 }
1784
1785
1786 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1787         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1788                                                                 "port");
1789 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1790         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1791                                                                 "config");
1792 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1793         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1794 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1795         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1796                                                                 "speed");
1797 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1798         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1799                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1800 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1801         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1802                                                                 "duplex");
1803 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1804         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1805                                                         "half#full#auto");
1806
1807 cmdline_parse_inst_t cmd_config_speed_specific = {
1808         .f = cmd_config_speed_specific_parsed,
1809         .data = NULL,
1810         .help_str = "port config <port_id> speed "
1811                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1812                                                         "half|full|auto",
1813         .tokens = {
1814                 (void *)&cmd_config_speed_specific_port,
1815                 (void *)&cmd_config_speed_specific_keyword,
1816                 (void *)&cmd_config_speed_specific_id,
1817                 (void *)&cmd_config_speed_specific_item1,
1818                 (void *)&cmd_config_speed_specific_value1,
1819                 (void *)&cmd_config_speed_specific_item2,
1820                 (void *)&cmd_config_speed_specific_value2,
1821                 NULL,
1822         },
1823 };
1824
1825 /* *** configure loopback for all ports *** */
1826 struct cmd_config_loopback_all {
1827         cmdline_fixed_string_t port;
1828         cmdline_fixed_string_t keyword;
1829         cmdline_fixed_string_t all;
1830         cmdline_fixed_string_t item;
1831         uint32_t mode;
1832 };
1833
1834 static void
1835 cmd_config_loopback_all_parsed(void *parsed_result,
1836                         __rte_unused struct cmdline *cl,
1837                         __rte_unused void *data)
1838 {
1839         struct cmd_config_loopback_all *res = parsed_result;
1840         portid_t pid;
1841
1842         if (!all_ports_stopped()) {
1843                 printf("Please stop all ports first\n");
1844                 return;
1845         }
1846
1847         RTE_ETH_FOREACH_DEV(pid) {
1848                 ports[pid].dev_conf.lpbk_mode = res->mode;
1849         }
1850
1851         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1852 }
1853
1854 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1855         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1856 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1857         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1858                                                         "config");
1859 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1860         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1861 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1862         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1863                                                         "loopback");
1864 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1865         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1866
1867 cmdline_parse_inst_t cmd_config_loopback_all = {
1868         .f = cmd_config_loopback_all_parsed,
1869         .data = NULL,
1870         .help_str = "port config all loopback <mode>",
1871         .tokens = {
1872                 (void *)&cmd_config_loopback_all_port,
1873                 (void *)&cmd_config_loopback_all_keyword,
1874                 (void *)&cmd_config_loopback_all_all,
1875                 (void *)&cmd_config_loopback_all_item,
1876                 (void *)&cmd_config_loopback_all_mode,
1877                 NULL,
1878         },
1879 };
1880
1881 /* *** configure loopback for specific port *** */
1882 struct cmd_config_loopback_specific {
1883         cmdline_fixed_string_t port;
1884         cmdline_fixed_string_t keyword;
1885         uint16_t port_id;
1886         cmdline_fixed_string_t item;
1887         uint32_t mode;
1888 };
1889
1890 static void
1891 cmd_config_loopback_specific_parsed(void *parsed_result,
1892                                 __rte_unused struct cmdline *cl,
1893                                 __rte_unused void *data)
1894 {
1895         struct cmd_config_loopback_specific *res = parsed_result;
1896
1897         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1898                 return;
1899
1900         if (!port_is_stopped(res->port_id)) {
1901                 printf("Please stop port %u first\n", res->port_id);
1902                 return;
1903         }
1904
1905         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1906
1907         cmd_reconfig_device_queue(res->port_id, 1, 1);
1908 }
1909
1910
1911 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1912         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1913                                                                 "port");
1914 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1915         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1916                                                                 "config");
1917 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1918         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1919                                                                 UINT16);
1920 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1921         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1922                                                                 "loopback");
1923 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1924         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1925                               UINT32);
1926
1927 cmdline_parse_inst_t cmd_config_loopback_specific = {
1928         .f = cmd_config_loopback_specific_parsed,
1929         .data = NULL,
1930         .help_str = "port config <port_id> loopback <mode>",
1931         .tokens = {
1932                 (void *)&cmd_config_loopback_specific_port,
1933                 (void *)&cmd_config_loopback_specific_keyword,
1934                 (void *)&cmd_config_loopback_specific_id,
1935                 (void *)&cmd_config_loopback_specific_item,
1936                 (void *)&cmd_config_loopback_specific_mode,
1937                 NULL,
1938         },
1939 };
1940
1941 /* *** configure txq/rxq, txd/rxd *** */
1942 struct cmd_config_rx_tx {
1943         cmdline_fixed_string_t port;
1944         cmdline_fixed_string_t keyword;
1945         cmdline_fixed_string_t all;
1946         cmdline_fixed_string_t name;
1947         uint16_t value;
1948 };
1949
1950 static void
1951 cmd_config_rx_tx_parsed(void *parsed_result,
1952                         __rte_unused struct cmdline *cl,
1953                         __rte_unused void *data)
1954 {
1955         struct cmd_config_rx_tx *res = parsed_result;
1956
1957         if (!all_ports_stopped()) {
1958                 printf("Please stop all ports first\n");
1959                 return;
1960         }
1961         if (!strcmp(res->name, "rxq")) {
1962                 if (!res->value && !nb_txq) {
1963                         printf("Warning: Either rx or tx queues should be non zero\n");
1964                         return;
1965                 }
1966                 if (check_nb_rxq(res->value) != 0)
1967                         return;
1968                 nb_rxq = res->value;
1969         }
1970         else if (!strcmp(res->name, "txq")) {
1971                 if (!res->value && !nb_rxq) {
1972                         printf("Warning: Either rx or tx queues should be non zero\n");
1973                         return;
1974                 }
1975                 if (check_nb_txq(res->value) != 0)
1976                         return;
1977                 nb_txq = res->value;
1978         }
1979         else if (!strcmp(res->name, "rxd")) {
1980                 if (check_nb_rxd(res->value) != 0)
1981                         return;
1982                 nb_rxd = res->value;
1983         } else if (!strcmp(res->name, "txd")) {
1984                 if (check_nb_txd(res->value) != 0)
1985                         return;
1986
1987                 nb_txd = res->value;
1988         } else {
1989                 printf("Unknown parameter\n");
1990                 return;
1991         }
1992
1993         fwd_config_setup();
1994
1995         init_port_config();
1996
1997         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1998 }
1999
2000 cmdline_parse_token_string_t cmd_config_rx_tx_port =
2001         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
2002 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
2003         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
2004 cmdline_parse_token_string_t cmd_config_rx_tx_all =
2005         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
2006 cmdline_parse_token_string_t cmd_config_rx_tx_name =
2007         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
2008                                                 "rxq#txq#rxd#txd");
2009 cmdline_parse_token_num_t cmd_config_rx_tx_value =
2010         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
2011
2012 cmdline_parse_inst_t cmd_config_rx_tx = {
2013         .f = cmd_config_rx_tx_parsed,
2014         .data = NULL,
2015         .help_str = "port config all rxq|txq|rxd|txd <value>",
2016         .tokens = {
2017                 (void *)&cmd_config_rx_tx_port,
2018                 (void *)&cmd_config_rx_tx_keyword,
2019                 (void *)&cmd_config_rx_tx_all,
2020                 (void *)&cmd_config_rx_tx_name,
2021                 (void *)&cmd_config_rx_tx_value,
2022                 NULL,
2023         },
2024 };
2025
2026 /* *** config max packet length *** */
2027 struct cmd_config_max_pkt_len_result {
2028         cmdline_fixed_string_t port;
2029         cmdline_fixed_string_t keyword;
2030         cmdline_fixed_string_t all;
2031         cmdline_fixed_string_t name;
2032         uint32_t value;
2033 };
2034
2035 static void
2036 cmd_config_max_pkt_len_parsed(void *parsed_result,
2037                                 __rte_unused struct cmdline *cl,
2038                                 __rte_unused void *data)
2039 {
2040         struct cmd_config_max_pkt_len_result *res = parsed_result;
2041         portid_t pid;
2042
2043         if (!all_ports_stopped()) {
2044                 printf("Please stop all ports first\n");
2045                 return;
2046         }
2047
2048         RTE_ETH_FOREACH_DEV(pid) {
2049                 struct rte_port *port = &ports[pid];
2050                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2051
2052                 if (!strcmp(res->name, "max-pkt-len")) {
2053                         if (res->value < RTE_ETHER_MIN_LEN) {
2054                                 printf("max-pkt-len can not be less than %d\n",
2055                                                 RTE_ETHER_MIN_LEN);
2056                                 return;
2057                         }
2058                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2059                                 return;
2060
2061                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2062                         if (res->value > RTE_ETHER_MAX_LEN)
2063                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2064                         else
2065                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2066                         port->dev_conf.rxmode.offloads = rx_offloads;
2067                 } else {
2068                         printf("Unknown parameter\n");
2069                         return;
2070                 }
2071         }
2072
2073         init_port_config();
2074
2075         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2076 }
2077
2078 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2079         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2080                                                                 "port");
2081 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2082         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2083                                                                 "config");
2084 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2085         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2086                                                                 "all");
2087 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2088         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2089                                                                 "max-pkt-len");
2090 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2091         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2092                                                                 UINT32);
2093
2094 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2095         .f = cmd_config_max_pkt_len_parsed,
2096         .data = NULL,
2097         .help_str = "port config all max-pkt-len <value>",
2098         .tokens = {
2099                 (void *)&cmd_config_max_pkt_len_port,
2100                 (void *)&cmd_config_max_pkt_len_keyword,
2101                 (void *)&cmd_config_max_pkt_len_all,
2102                 (void *)&cmd_config_max_pkt_len_name,
2103                 (void *)&cmd_config_max_pkt_len_value,
2104                 NULL,
2105         },
2106 };
2107
2108 /* *** config max LRO aggregated packet size *** */
2109 struct cmd_config_max_lro_pkt_size_result {
2110         cmdline_fixed_string_t port;
2111         cmdline_fixed_string_t keyword;
2112         cmdline_fixed_string_t all;
2113         cmdline_fixed_string_t name;
2114         uint32_t value;
2115 };
2116
2117 static void
2118 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2119                                 __rte_unused struct cmdline *cl,
2120                                 __rte_unused void *data)
2121 {
2122         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2123         portid_t pid;
2124
2125         if (!all_ports_stopped()) {
2126                 printf("Please stop all ports first\n");
2127                 return;
2128         }
2129
2130         RTE_ETH_FOREACH_DEV(pid) {
2131                 struct rte_port *port = &ports[pid];
2132
2133                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2134                         if (res->value ==
2135                                         port->dev_conf.rxmode.max_lro_pkt_size)
2136                                 return;
2137
2138                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2139                 } else {
2140                         printf("Unknown parameter\n");
2141                         return;
2142                 }
2143         }
2144
2145         init_port_config();
2146
2147         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2148 }
2149
2150 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2151         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2152                                  port, "port");
2153 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2154         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2155                                  keyword, "config");
2156 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2157         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2158                                  all, "all");
2159 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2160         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2161                                  name, "max-lro-pkt-size");
2162 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2163         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2164                               value, UINT32);
2165
2166 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2167         .f = cmd_config_max_lro_pkt_size_parsed,
2168         .data = NULL,
2169         .help_str = "port config all max-lro-pkt-size <value>",
2170         .tokens = {
2171                 (void *)&cmd_config_max_lro_pkt_size_port,
2172                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2173                 (void *)&cmd_config_max_lro_pkt_size_all,
2174                 (void *)&cmd_config_max_lro_pkt_size_name,
2175                 (void *)&cmd_config_max_lro_pkt_size_value,
2176                 NULL,
2177         },
2178 };
2179
2180 /* *** configure port MTU *** */
2181 struct cmd_config_mtu_result {
2182         cmdline_fixed_string_t port;
2183         cmdline_fixed_string_t keyword;
2184         cmdline_fixed_string_t mtu;
2185         portid_t port_id;
2186         uint16_t value;
2187 };
2188
2189 static void
2190 cmd_config_mtu_parsed(void *parsed_result,
2191                       __rte_unused struct cmdline *cl,
2192                       __rte_unused void *data)
2193 {
2194         struct cmd_config_mtu_result *res = parsed_result;
2195
2196         if (res->value < RTE_ETHER_MIN_LEN) {
2197                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2198                 return;
2199         }
2200         port_mtu_set(res->port_id, res->value);
2201 }
2202
2203 cmdline_parse_token_string_t cmd_config_mtu_port =
2204         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2205                                  "port");
2206 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2207         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2208                                  "config");
2209 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2210         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2211                                  "mtu");
2212 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2213         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2214 cmdline_parse_token_num_t cmd_config_mtu_value =
2215         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2216
2217 cmdline_parse_inst_t cmd_config_mtu = {
2218         .f = cmd_config_mtu_parsed,
2219         .data = NULL,
2220         .help_str = "port config mtu <port_id> <value>",
2221         .tokens = {
2222                 (void *)&cmd_config_mtu_port,
2223                 (void *)&cmd_config_mtu_keyword,
2224                 (void *)&cmd_config_mtu_mtu,
2225                 (void *)&cmd_config_mtu_port_id,
2226                 (void *)&cmd_config_mtu_value,
2227                 NULL,
2228         },
2229 };
2230
2231 /* *** configure rx mode *** */
2232 struct cmd_config_rx_mode_flag {
2233         cmdline_fixed_string_t port;
2234         cmdline_fixed_string_t keyword;
2235         cmdline_fixed_string_t all;
2236         cmdline_fixed_string_t name;
2237         cmdline_fixed_string_t value;
2238 };
2239
2240 static void
2241 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2242                                 __rte_unused struct cmdline *cl,
2243                                 __rte_unused void *data)
2244 {
2245         struct cmd_config_rx_mode_flag *res = parsed_result;
2246
2247         if (!all_ports_stopped()) {
2248                 printf("Please stop all ports first\n");
2249                 return;
2250         }
2251
2252         if (!strcmp(res->name, "drop-en")) {
2253                 if (!strcmp(res->value, "on"))
2254                         rx_drop_en = 1;
2255                 else if (!strcmp(res->value, "off"))
2256                         rx_drop_en = 0;
2257                 else {
2258                         printf("Unknown parameter\n");
2259                         return;
2260                 }
2261         } else {
2262                 printf("Unknown parameter\n");
2263                 return;
2264         }
2265
2266         init_port_config();
2267
2268         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2269 }
2270
2271 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2272         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2273 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2274         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2275                                                                 "config");
2276 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2277         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2278 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2279         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2280                                         "drop-en");
2281 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2282         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2283                                                         "on#off");
2284
2285 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2286         .f = cmd_config_rx_mode_flag_parsed,
2287         .data = NULL,
2288         .help_str = "port config all drop-en on|off",
2289         .tokens = {
2290                 (void *)&cmd_config_rx_mode_flag_port,
2291                 (void *)&cmd_config_rx_mode_flag_keyword,
2292                 (void *)&cmd_config_rx_mode_flag_all,
2293                 (void *)&cmd_config_rx_mode_flag_name,
2294                 (void *)&cmd_config_rx_mode_flag_value,
2295                 NULL,
2296         },
2297 };
2298
2299 /* *** configure rss *** */
2300 struct cmd_config_rss {
2301         cmdline_fixed_string_t port;
2302         cmdline_fixed_string_t keyword;
2303         cmdline_fixed_string_t all;
2304         cmdline_fixed_string_t name;
2305         cmdline_fixed_string_t value;
2306 };
2307
2308 static void
2309 cmd_config_rss_parsed(void *parsed_result,
2310                         __rte_unused struct cmdline *cl,
2311                         __rte_unused void *data)
2312 {
2313         struct cmd_config_rss *res = parsed_result;
2314         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2315         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2316         int use_default = 0;
2317         int all_updated = 1;
2318         int diag;
2319         uint16_t i;
2320         int ret;
2321
2322         if (!strcmp(res->value, "all"))
2323                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2324                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2325                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2326                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2327         else if (!strcmp(res->value, "eth"))
2328                 rss_conf.rss_hf = ETH_RSS_ETH;
2329         else if (!strcmp(res->value, "vlan"))
2330                 rss_conf.rss_hf = ETH_RSS_VLAN;
2331         else if (!strcmp(res->value, "ip"))
2332                 rss_conf.rss_hf = ETH_RSS_IP;
2333         else if (!strcmp(res->value, "udp"))
2334                 rss_conf.rss_hf = ETH_RSS_UDP;
2335         else if (!strcmp(res->value, "tcp"))
2336                 rss_conf.rss_hf = ETH_RSS_TCP;
2337         else if (!strcmp(res->value, "sctp"))
2338                 rss_conf.rss_hf = ETH_RSS_SCTP;
2339         else if (!strcmp(res->value, "ether"))
2340                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2341         else if (!strcmp(res->value, "port"))
2342                 rss_conf.rss_hf = ETH_RSS_PORT;
2343         else if (!strcmp(res->value, "vxlan"))
2344                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2345         else if (!strcmp(res->value, "geneve"))
2346                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2347         else if (!strcmp(res->value, "nvgre"))
2348                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2349         else if (!strcmp(res->value, "l3-pre32"))
2350                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2351         else if (!strcmp(res->value, "l3-pre40"))
2352                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2353         else if (!strcmp(res->value, "l3-pre48"))
2354                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2355         else if (!strcmp(res->value, "l3-pre56"))
2356                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2357         else if (!strcmp(res->value, "l3-pre64"))
2358                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2359         else if (!strcmp(res->value, "l3-pre96"))
2360                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2361         else if (!strcmp(res->value, "l3-src-only"))
2362                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2363         else if (!strcmp(res->value, "l3-dst-only"))
2364                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2365         else if (!strcmp(res->value, "l4-src-only"))
2366                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2367         else if (!strcmp(res->value, "l4-dst-only"))
2368                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2369         else if (!strcmp(res->value, "l2-src-only"))
2370                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2371         else if (!strcmp(res->value, "l2-dst-only"))
2372                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2373         else if (!strcmp(res->value, "l2tpv3"))
2374                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2375         else if (!strcmp(res->value, "esp"))
2376                 rss_conf.rss_hf = ETH_RSS_ESP;
2377         else if (!strcmp(res->value, "ah"))
2378                 rss_conf.rss_hf = ETH_RSS_AH;
2379         else if (!strcmp(res->value, "pfcp"))
2380                 rss_conf.rss_hf = ETH_RSS_PFCP;
2381         else if (!strcmp(res->value, "pppoe"))
2382                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2383         else if (!strcmp(res->value, "gtpu"))
2384                 rss_conf.rss_hf = ETH_RSS_GTPU;
2385         else if (!strcmp(res->value, "none"))
2386                 rss_conf.rss_hf = 0;
2387         else if (!strcmp(res->value, "level-default")) {
2388                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2389                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2390         } else if (!strcmp(res->value, "level-outer")) {
2391                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2392                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2393         } else if (!strcmp(res->value, "level-inner")) {
2394                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2395                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2396         } else if (!strcmp(res->value, "default"))
2397                 use_default = 1;
2398         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2399                                                 atoi(res->value) < 64)
2400                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2401         else {
2402                 printf("Unknown parameter\n");
2403                 return;
2404         }
2405         rss_conf.rss_key = NULL;
2406         /* Update global configuration for RSS types. */
2407         RTE_ETH_FOREACH_DEV(i) {
2408                 struct rte_eth_rss_conf local_rss_conf;
2409
2410                 ret = eth_dev_info_get_print_err(i, &dev_info);
2411                 if (ret != 0)
2412                         return;
2413
2414                 if (use_default)
2415                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2416
2417                 local_rss_conf = rss_conf;
2418                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2419                         dev_info.flow_type_rss_offloads;
2420                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2421                         printf("Port %u modified RSS hash function based on hardware support,"
2422                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2423                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2424                 }
2425                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2426                 if (diag < 0) {
2427                         all_updated = 0;
2428                         printf("Configuration of RSS hash at ethernet port %d "
2429                                 "failed with error (%d): %s.\n",
2430                                 i, -diag, strerror(-diag));
2431                 }
2432         }
2433         if (all_updated && !use_default) {
2434                 rss_hf = rss_conf.rss_hf;
2435                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2436         }
2437 }
2438
2439 cmdline_parse_token_string_t cmd_config_rss_port =
2440         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2441 cmdline_parse_token_string_t cmd_config_rss_keyword =
2442         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2443 cmdline_parse_token_string_t cmd_config_rss_all =
2444         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2445 cmdline_parse_token_string_t cmd_config_rss_name =
2446         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2447 cmdline_parse_token_string_t cmd_config_rss_value =
2448         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2449
2450 cmdline_parse_inst_t cmd_config_rss = {
2451         .f = cmd_config_rss_parsed,
2452         .data = NULL,
2453         .help_str = "port config all rss "
2454                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2455                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2456                 "level-outer|level-inner|<flowtype_id>",
2457         .tokens = {
2458                 (void *)&cmd_config_rss_port,
2459                 (void *)&cmd_config_rss_keyword,
2460                 (void *)&cmd_config_rss_all,
2461                 (void *)&cmd_config_rss_name,
2462                 (void *)&cmd_config_rss_value,
2463                 NULL,
2464         },
2465 };
2466
2467 /* *** configure rss hash key *** */
2468 struct cmd_config_rss_hash_key {
2469         cmdline_fixed_string_t port;
2470         cmdline_fixed_string_t config;
2471         portid_t port_id;
2472         cmdline_fixed_string_t rss_hash_key;
2473         cmdline_fixed_string_t rss_type;
2474         cmdline_fixed_string_t key;
2475 };
2476
2477 static uint8_t
2478 hexa_digit_to_value(char hexa_digit)
2479 {
2480         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2481                 return (uint8_t) (hexa_digit - '0');
2482         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2483                 return (uint8_t) ((hexa_digit - 'a') + 10);
2484         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2485                 return (uint8_t) ((hexa_digit - 'A') + 10);
2486         /* Invalid hexa digit */
2487         return 0xFF;
2488 }
2489
2490 static uint8_t
2491 parse_and_check_key_hexa_digit(char *key, int idx)
2492 {
2493         uint8_t hexa_v;
2494
2495         hexa_v = hexa_digit_to_value(key[idx]);
2496         if (hexa_v == 0xFF)
2497                 printf("invalid key: character %c at position %d is not a "
2498                        "valid hexa digit\n", key[idx], idx);
2499         return hexa_v;
2500 }
2501
2502 static void
2503 cmd_config_rss_hash_key_parsed(void *parsed_result,
2504                                __rte_unused struct cmdline *cl,
2505                                __rte_unused void *data)
2506 {
2507         struct cmd_config_rss_hash_key *res = parsed_result;
2508         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2509         uint8_t xdgt0;
2510         uint8_t xdgt1;
2511         int i;
2512         struct rte_eth_dev_info dev_info;
2513         uint8_t hash_key_size;
2514         uint32_t key_len;
2515         int ret;
2516
2517         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2518         if (ret != 0)
2519                 return;
2520
2521         if (dev_info.hash_key_size > 0 &&
2522                         dev_info.hash_key_size <= sizeof(hash_key))
2523                 hash_key_size = dev_info.hash_key_size;
2524         else {
2525                 printf("dev_info did not provide a valid hash key size\n");
2526                 return;
2527         }
2528         /* Check the length of the RSS hash key */
2529         key_len = strlen(res->key);
2530         if (key_len != (hash_key_size * 2)) {
2531                 printf("key length: %d invalid - key must be a string of %d"
2532                            " hexa-decimal numbers\n",
2533                            (int) key_len, hash_key_size * 2);
2534                 return;
2535         }
2536         /* Translate RSS hash key into binary representation */
2537         for (i = 0; i < hash_key_size; i++) {
2538                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2539                 if (xdgt0 == 0xFF)
2540                         return;
2541                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2542                 if (xdgt1 == 0xFF)
2543                         return;
2544                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2545         }
2546         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2547                         hash_key_size);
2548 }
2549
2550 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2551         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2552 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2553         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2554                                  "config");
2555 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2556         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2557 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2558         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2559                                  rss_hash_key, "rss-hash-key");
2560 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2561         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2562                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2563                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2564                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2565                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2566                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2567                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2568                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2569 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2570         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2571
2572 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2573         .f = cmd_config_rss_hash_key_parsed,
2574         .data = NULL,
2575         .help_str = "port config <port_id> rss-hash-key "
2576                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2577                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2578                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2579                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2580                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2581                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2582                 "<string of hex digits (variable length, NIC dependent)>",
2583         .tokens = {
2584                 (void *)&cmd_config_rss_hash_key_port,
2585                 (void *)&cmd_config_rss_hash_key_config,
2586                 (void *)&cmd_config_rss_hash_key_port_id,
2587                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2588                 (void *)&cmd_config_rss_hash_key_rss_type,
2589                 (void *)&cmd_config_rss_hash_key_value,
2590                 NULL,
2591         },
2592 };
2593
2594 /* *** configure port rxq/txq ring size *** */
2595 struct cmd_config_rxtx_ring_size {
2596         cmdline_fixed_string_t port;
2597         cmdline_fixed_string_t config;
2598         portid_t portid;
2599         cmdline_fixed_string_t rxtxq;
2600         uint16_t qid;
2601         cmdline_fixed_string_t rsize;
2602         uint16_t size;
2603 };
2604
2605 static void
2606 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2607                                  __rte_unused struct cmdline *cl,
2608                                  __rte_unused void *data)
2609 {
2610         struct cmd_config_rxtx_ring_size *res = parsed_result;
2611         struct rte_port *port;
2612         uint8_t isrx;
2613
2614         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2615                 return;
2616
2617         if (res->portid == (portid_t)RTE_PORT_ALL) {
2618                 printf("Invalid port id\n");
2619                 return;
2620         }
2621
2622         port = &ports[res->portid];
2623
2624         if (!strcmp(res->rxtxq, "rxq"))
2625                 isrx = 1;
2626         else if (!strcmp(res->rxtxq, "txq"))
2627                 isrx = 0;
2628         else {
2629                 printf("Unknown parameter\n");
2630                 return;
2631         }
2632
2633         if (isrx && rx_queue_id_is_invalid(res->qid))
2634                 return;
2635         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2636                 return;
2637
2638         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2639                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2640                        rx_free_thresh);
2641                 return;
2642         }
2643
2644         if (isrx)
2645                 port->nb_rx_desc[res->qid] = res->size;
2646         else
2647                 port->nb_tx_desc[res->qid] = res->size;
2648
2649         cmd_reconfig_device_queue(res->portid, 0, 1);
2650 }
2651
2652 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2653         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2654                                  port, "port");
2655 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2656         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2657                                  config, "config");
2658 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2659         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2660                                  portid, UINT16);
2661 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2662         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2663                                  rxtxq, "rxq#txq");
2664 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2665         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2666                               qid, UINT16);
2667 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2668         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2669                                  rsize, "ring_size");
2670 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2671         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2672                               size, UINT16);
2673
2674 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2675         .f = cmd_config_rxtx_ring_size_parsed,
2676         .data = NULL,
2677         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2678         .tokens = {
2679                 (void *)&cmd_config_rxtx_ring_size_port,
2680                 (void *)&cmd_config_rxtx_ring_size_config,
2681                 (void *)&cmd_config_rxtx_ring_size_portid,
2682                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2683                 (void *)&cmd_config_rxtx_ring_size_qid,
2684                 (void *)&cmd_config_rxtx_ring_size_rsize,
2685                 (void *)&cmd_config_rxtx_ring_size_size,
2686                 NULL,
2687         },
2688 };
2689
2690 /* *** configure port rxq/txq start/stop *** */
2691 struct cmd_config_rxtx_queue {
2692         cmdline_fixed_string_t port;
2693         portid_t portid;
2694         cmdline_fixed_string_t rxtxq;
2695         uint16_t qid;
2696         cmdline_fixed_string_t opname;
2697 };
2698
2699 static void
2700 cmd_config_rxtx_queue_parsed(void *parsed_result,
2701                         __rte_unused struct cmdline *cl,
2702                         __rte_unused void *data)
2703 {
2704         struct cmd_config_rxtx_queue *res = parsed_result;
2705         uint8_t isrx;
2706         uint8_t isstart;
2707         int ret = 0;
2708
2709         if (test_done == 0) {
2710                 printf("Please stop forwarding first\n");
2711                 return;
2712         }
2713
2714         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2715                 return;
2716
2717         if (port_is_started(res->portid) != 1) {
2718                 printf("Please start port %u first\n", res->portid);
2719                 return;
2720         }
2721
2722         if (!strcmp(res->rxtxq, "rxq"))
2723                 isrx = 1;
2724         else if (!strcmp(res->rxtxq, "txq"))
2725                 isrx = 0;
2726         else {
2727                 printf("Unknown parameter\n");
2728                 return;
2729         }
2730
2731         if (isrx && rx_queue_id_is_invalid(res->qid))
2732                 return;
2733         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2734                 return;
2735
2736         if (!strcmp(res->opname, "start"))
2737                 isstart = 1;
2738         else if (!strcmp(res->opname, "stop"))
2739                 isstart = 0;
2740         else {
2741                 printf("Unknown parameter\n");
2742                 return;
2743         }
2744
2745         if (isstart && isrx)
2746                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2747         else if (!isstart && isrx)
2748                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2749         else if (isstart && !isrx)
2750                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2751         else
2752                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2753
2754         if (ret == -ENOTSUP)
2755                 printf("Function not supported in PMD driver\n");
2756 }
2757
2758 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2759         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2760 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2761         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2762 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2763         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2764 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2765         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2766 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2767         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2768                                                 "start#stop");
2769
2770 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2771         .f = cmd_config_rxtx_queue_parsed,
2772         .data = NULL,
2773         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2774         .tokens = {
2775                 (void *)&cmd_config_rxtx_queue_port,
2776                 (void *)&cmd_config_rxtx_queue_portid,
2777                 (void *)&cmd_config_rxtx_queue_rxtxq,
2778                 (void *)&cmd_config_rxtx_queue_qid,
2779                 (void *)&cmd_config_rxtx_queue_opname,
2780                 NULL,
2781         },
2782 };
2783
2784 /* *** configure port rxq/txq deferred start on/off *** */
2785 struct cmd_config_deferred_start_rxtx_queue {
2786         cmdline_fixed_string_t port;
2787         portid_t port_id;
2788         cmdline_fixed_string_t rxtxq;
2789         uint16_t qid;
2790         cmdline_fixed_string_t opname;
2791         cmdline_fixed_string_t state;
2792 };
2793
2794 static void
2795 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2796                         __rte_unused struct cmdline *cl,
2797                         __rte_unused void *data)
2798 {
2799         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2800         struct rte_port *port;
2801         uint8_t isrx;
2802         uint8_t ison;
2803         uint8_t needreconfig = 0;
2804
2805         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2806                 return;
2807
2808         if (port_is_started(res->port_id) != 0) {
2809                 printf("Please stop port %u first\n", res->port_id);
2810                 return;
2811         }
2812
2813         port = &ports[res->port_id];
2814
2815         isrx = !strcmp(res->rxtxq, "rxq");
2816
2817         if (isrx && rx_queue_id_is_invalid(res->qid))
2818                 return;
2819         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2820                 return;
2821
2822         ison = !strcmp(res->state, "on");
2823
2824         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2825                 port->rx_conf[res->qid].rx_deferred_start = ison;
2826                 needreconfig = 1;
2827         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2828                 port->tx_conf[res->qid].tx_deferred_start = ison;
2829                 needreconfig = 1;
2830         }
2831
2832         if (needreconfig)
2833                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2834 }
2835
2836 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2837         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2838                                                 port, "port");
2839 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2840         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2841                                                 port_id, UINT16);
2842 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2843         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2844                                                 rxtxq, "rxq#txq");
2845 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2846         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2847                                                 qid, UINT16);
2848 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2849         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2850                                                 opname, "deferred_start");
2851 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2852         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2853                                                 state, "on#off");
2854
2855 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2856         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2857         .data = NULL,
2858         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2859         .tokens = {
2860                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2861                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2862                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2863                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2864                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2865                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2866                 NULL,
2867         },
2868 };
2869
2870 /* *** configure port rxq/txq setup *** */
2871 struct cmd_setup_rxtx_queue {
2872         cmdline_fixed_string_t port;
2873         portid_t portid;
2874         cmdline_fixed_string_t rxtxq;
2875         uint16_t qid;
2876         cmdline_fixed_string_t setup;
2877 };
2878
2879 /* Common CLI fields for queue setup */
2880 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2881         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2882 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2883         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2884 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2885         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2886 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2887         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2888 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2889         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2890
2891 static void
2892 cmd_setup_rxtx_queue_parsed(
2893         void *parsed_result,
2894         __rte_unused struct cmdline *cl,
2895         __rte_unused void *data)
2896 {
2897         struct cmd_setup_rxtx_queue *res = parsed_result;
2898         struct rte_port *port;
2899         struct rte_mempool *mp;
2900         unsigned int socket_id;
2901         uint8_t isrx = 0;
2902         int ret;
2903
2904         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2905                 return;
2906
2907         if (res->portid == (portid_t)RTE_PORT_ALL) {
2908                 printf("Invalid port id\n");
2909                 return;
2910         }
2911
2912         if (!strcmp(res->rxtxq, "rxq"))
2913                 isrx = 1;
2914         else if (!strcmp(res->rxtxq, "txq"))
2915                 isrx = 0;
2916         else {
2917                 printf("Unknown parameter\n");
2918                 return;
2919         }
2920
2921         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2922                 printf("Invalid rx queue\n");
2923                 return;
2924         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2925                 printf("Invalid tx queue\n");
2926                 return;
2927         }
2928
2929         port = &ports[res->portid];
2930         if (isrx) {
2931                 socket_id = rxring_numa[res->portid];
2932                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2933                         socket_id = port->socket_id;
2934
2935                 mp = mbuf_pool_find(socket_id, 0);
2936                 if (mp == NULL) {
2937                         printf("Failed to setup RX queue: "
2938                                 "No mempool allocation"
2939                                 " on the socket %d\n",
2940                                 rxring_numa[res->portid]);
2941                         return;
2942                 }
2943                 ret = rx_queue_setup(res->portid,
2944                                      res->qid,
2945                                      port->nb_rx_desc[res->qid],
2946                                      socket_id,
2947                                      &port->rx_conf[res->qid],
2948                                      mp);
2949                 if (ret)
2950                         printf("Failed to setup RX queue\n");
2951         } else {
2952                 socket_id = txring_numa[res->portid];
2953                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2954                         socket_id = port->socket_id;
2955
2956                 ret = rte_eth_tx_queue_setup(res->portid,
2957                                              res->qid,
2958                                              port->nb_tx_desc[res->qid],
2959                                              socket_id,
2960                                              &port->tx_conf[res->qid]);
2961                 if (ret)
2962                         printf("Failed to setup TX queue\n");
2963         }
2964 }
2965
2966 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2967         .f = cmd_setup_rxtx_queue_parsed,
2968         .data = NULL,
2969         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2970         .tokens = {
2971                 (void *)&cmd_setup_rxtx_queue_port,
2972                 (void *)&cmd_setup_rxtx_queue_portid,
2973                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2974                 (void *)&cmd_setup_rxtx_queue_qid,
2975                 (void *)&cmd_setup_rxtx_queue_setup,
2976                 NULL,
2977         },
2978 };
2979
2980
2981 /* *** Configure RSS RETA *** */
2982 struct cmd_config_rss_reta {
2983         cmdline_fixed_string_t port;
2984         cmdline_fixed_string_t keyword;
2985         portid_t port_id;
2986         cmdline_fixed_string_t name;
2987         cmdline_fixed_string_t list_name;
2988         cmdline_fixed_string_t list_of_items;
2989 };
2990
2991 static int
2992 parse_reta_config(const char *str,
2993                   struct rte_eth_rss_reta_entry64 *reta_conf,
2994                   uint16_t nb_entries)
2995 {
2996         int i;
2997         unsigned size;
2998         uint16_t hash_index, idx, shift;
2999         uint16_t nb_queue;
3000         char s[256];
3001         const char *p, *p0 = str;
3002         char *end;
3003         enum fieldnames {
3004                 FLD_HASH_INDEX = 0,
3005                 FLD_QUEUE,
3006                 _NUM_FLD
3007         };
3008         unsigned long int_fld[_NUM_FLD];
3009         char *str_fld[_NUM_FLD];
3010
3011         while ((p = strchr(p0,'(')) != NULL) {
3012                 ++p;
3013                 if((p0 = strchr(p,')')) == NULL)
3014                         return -1;
3015
3016                 size = p0 - p;
3017                 if(size >= sizeof(s))
3018                         return -1;
3019
3020                 snprintf(s, sizeof(s), "%.*s", size, p);
3021                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
3022                         return -1;
3023                 for (i = 0; i < _NUM_FLD; i++) {
3024                         errno = 0;
3025                         int_fld[i] = strtoul(str_fld[i], &end, 0);
3026                         if (errno != 0 || end == str_fld[i] ||
3027                                         int_fld[i] > 65535)
3028                                 return -1;
3029                 }
3030
3031                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
3032                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
3033
3034                 if (hash_index >= nb_entries) {
3035                         printf("Invalid RETA hash index=%d\n", hash_index);
3036                         return -1;
3037                 }
3038
3039                 idx = hash_index / RTE_RETA_GROUP_SIZE;
3040                 shift = hash_index % RTE_RETA_GROUP_SIZE;
3041                 reta_conf[idx].mask |= (1ULL << shift);
3042                 reta_conf[idx].reta[shift] = nb_queue;
3043         }
3044
3045         return 0;
3046 }
3047
3048 static void
3049 cmd_set_rss_reta_parsed(void *parsed_result,
3050                         __rte_unused struct cmdline *cl,
3051                         __rte_unused void *data)
3052 {
3053         int ret;
3054         struct rte_eth_dev_info dev_info;
3055         struct rte_eth_rss_reta_entry64 reta_conf[8];
3056         struct cmd_config_rss_reta *res = parsed_result;
3057
3058         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3059         if (ret != 0)
3060                 return;
3061
3062         if (dev_info.reta_size == 0) {
3063                 printf("Redirection table size is 0 which is "
3064                                         "invalid for RSS\n");
3065                 return;
3066         } else
3067                 printf("The reta size of port %d is %u\n",
3068                         res->port_id, dev_info.reta_size);
3069         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3070                 printf("Currently do not support more than %u entries of "
3071                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3072                 return;
3073         }
3074
3075         memset(reta_conf, 0, sizeof(reta_conf));
3076         if (!strcmp(res->list_name, "reta")) {
3077                 if (parse_reta_config(res->list_of_items, reta_conf,
3078                                                 dev_info.reta_size)) {
3079                         printf("Invalid RSS Redirection Table "
3080                                         "config entered\n");
3081                         return;
3082                 }
3083                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3084                                 reta_conf, dev_info.reta_size);
3085                 if (ret != 0)
3086                         printf("Bad redirection table parameter, "
3087                                         "return code = %d \n", ret);
3088         }
3089 }
3090
3091 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3092         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3093 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3094         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3095 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3096         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3097 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3098         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3099 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3100         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3101 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3102         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3103                                  NULL);
3104 cmdline_parse_inst_t cmd_config_rss_reta = {
3105         .f = cmd_set_rss_reta_parsed,
3106         .data = NULL,
3107         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3108         .tokens = {
3109                 (void *)&cmd_config_rss_reta_port,
3110                 (void *)&cmd_config_rss_reta_keyword,
3111                 (void *)&cmd_config_rss_reta_port_id,
3112                 (void *)&cmd_config_rss_reta_name,
3113                 (void *)&cmd_config_rss_reta_list_name,
3114                 (void *)&cmd_config_rss_reta_list_of_items,
3115                 NULL,
3116         },
3117 };
3118
3119 /* *** SHOW PORT RETA INFO *** */
3120 struct cmd_showport_reta {
3121         cmdline_fixed_string_t show;
3122         cmdline_fixed_string_t port;
3123         portid_t port_id;
3124         cmdline_fixed_string_t rss;
3125         cmdline_fixed_string_t reta;
3126         uint16_t size;
3127         cmdline_fixed_string_t list_of_items;
3128 };
3129
3130 static int
3131 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3132                            uint16_t nb_entries,
3133                            char *str)
3134 {
3135         uint32_t size;
3136         const char *p, *p0 = str;
3137         char s[256];
3138         char *end;
3139         char *str_fld[8];
3140         uint16_t i;
3141         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3142                         RTE_RETA_GROUP_SIZE;
3143         int ret;
3144
3145         p = strchr(p0, '(');
3146         if (p == NULL)
3147                 return -1;
3148         p++;
3149         p0 = strchr(p, ')');
3150         if (p0 == NULL)
3151                 return -1;
3152         size = p0 - p;
3153         if (size >= sizeof(s)) {
3154                 printf("The string size exceeds the internal buffer size\n");
3155                 return -1;
3156         }
3157         snprintf(s, sizeof(s), "%.*s", size, p);
3158         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3159         if (ret <= 0 || ret != num) {
3160                 printf("The bits of masks do not match the number of "
3161                                         "reta entries: %u\n", num);
3162                 return -1;
3163         }
3164         for (i = 0; i < ret; i++)
3165                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3166
3167         return 0;
3168 }
3169
3170 static void
3171 cmd_showport_reta_parsed(void *parsed_result,
3172                          __rte_unused struct cmdline *cl,
3173                          __rte_unused void *data)
3174 {
3175         struct cmd_showport_reta *res = parsed_result;
3176         struct rte_eth_rss_reta_entry64 reta_conf[8];
3177         struct rte_eth_dev_info dev_info;
3178         uint16_t max_reta_size;
3179         int ret;
3180
3181         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3182         if (ret != 0)
3183                 return;
3184
3185         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3186         if (res->size == 0 || res->size > max_reta_size) {
3187                 printf("Invalid redirection table size: %u (1-%u)\n",
3188                         res->size, max_reta_size);
3189                 return;
3190         }
3191
3192         memset(reta_conf, 0, sizeof(reta_conf));
3193         if (showport_parse_reta_config(reta_conf, res->size,
3194                                 res->list_of_items) < 0) {
3195                 printf("Invalid string: %s for reta masks\n",
3196                                         res->list_of_items);
3197                 return;
3198         }
3199         port_rss_reta_info(res->port_id, reta_conf, res->size);
3200 }
3201
3202 cmdline_parse_token_string_t cmd_showport_reta_show =
3203         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3204 cmdline_parse_token_string_t cmd_showport_reta_port =
3205         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3206 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3207         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3208 cmdline_parse_token_string_t cmd_showport_reta_rss =
3209         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3210 cmdline_parse_token_string_t cmd_showport_reta_reta =
3211         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3212 cmdline_parse_token_num_t cmd_showport_reta_size =
3213         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3214 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3215         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3216                                         list_of_items, NULL);
3217
3218 cmdline_parse_inst_t cmd_showport_reta = {
3219         .f = cmd_showport_reta_parsed,
3220         .data = NULL,
3221         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3222         .tokens = {
3223                 (void *)&cmd_showport_reta_show,
3224                 (void *)&cmd_showport_reta_port,
3225                 (void *)&cmd_showport_reta_port_id,
3226                 (void *)&cmd_showport_reta_rss,
3227                 (void *)&cmd_showport_reta_reta,
3228                 (void *)&cmd_showport_reta_size,
3229                 (void *)&cmd_showport_reta_list_of_items,
3230                 NULL,
3231         },
3232 };
3233
3234 /* *** Show RSS hash configuration *** */
3235 struct cmd_showport_rss_hash {
3236         cmdline_fixed_string_t show;
3237         cmdline_fixed_string_t port;
3238         portid_t port_id;
3239         cmdline_fixed_string_t rss_hash;
3240         cmdline_fixed_string_t rss_type;
3241         cmdline_fixed_string_t key; /* optional argument */
3242 };
3243
3244 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3245                                 __rte_unused struct cmdline *cl,
3246                                 void *show_rss_key)
3247 {
3248         struct cmd_showport_rss_hash *res = parsed_result;
3249
3250         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3251 }
3252
3253 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3254         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3255 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3256         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3257 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3258         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3259 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3260         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3261                                  "rss-hash");
3262 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3263         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3264
3265 cmdline_parse_inst_t cmd_showport_rss_hash = {
3266         .f = cmd_showport_rss_hash_parsed,
3267         .data = NULL,
3268         .help_str = "show port <port_id> rss-hash",
3269         .tokens = {
3270                 (void *)&cmd_showport_rss_hash_show,
3271                 (void *)&cmd_showport_rss_hash_port,
3272                 (void *)&cmd_showport_rss_hash_port_id,
3273                 (void *)&cmd_showport_rss_hash_rss_hash,
3274                 NULL,
3275         },
3276 };
3277
3278 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3279         .f = cmd_showport_rss_hash_parsed,
3280         .data = (void *)1,
3281         .help_str = "show port <port_id> rss-hash key",
3282         .tokens = {
3283                 (void *)&cmd_showport_rss_hash_show,
3284                 (void *)&cmd_showport_rss_hash_port,
3285                 (void *)&cmd_showport_rss_hash_port_id,
3286                 (void *)&cmd_showport_rss_hash_rss_hash,
3287                 (void *)&cmd_showport_rss_hash_rss_key,
3288                 NULL,
3289         },
3290 };
3291
3292 /* *** Configure DCB *** */
3293 struct cmd_config_dcb {
3294         cmdline_fixed_string_t port;
3295         cmdline_fixed_string_t config;
3296         portid_t port_id;
3297         cmdline_fixed_string_t dcb;
3298         cmdline_fixed_string_t vt;
3299         cmdline_fixed_string_t vt_en;
3300         uint8_t num_tcs;
3301         cmdline_fixed_string_t pfc;
3302         cmdline_fixed_string_t pfc_en;
3303 };
3304
3305 static void
3306 cmd_config_dcb_parsed(void *parsed_result,
3307                         __rte_unused struct cmdline *cl,
3308                         __rte_unused void *data)
3309 {
3310         struct cmd_config_dcb *res = parsed_result;
3311         portid_t port_id = res->port_id;
3312         struct rte_port *port;
3313         uint8_t pfc_en;
3314         int ret;
3315
3316         port = &ports[port_id];
3317         /** Check if the port is not started **/
3318         if (port->port_status != RTE_PORT_STOPPED) {
3319                 printf("Please stop port %d first\n", port_id);
3320                 return;
3321         }
3322
3323         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3324                 printf("The invalid number of traffic class,"
3325                         " only 4 or 8 allowed.\n");
3326                 return;
3327         }
3328
3329         if (nb_fwd_lcores < res->num_tcs) {
3330                 printf("nb_cores shouldn't be less than number of TCs.\n");
3331                 return;
3332         }
3333         if (!strncmp(res->pfc_en, "on", 2))
3334                 pfc_en = 1;
3335         else
3336                 pfc_en = 0;
3337
3338         /* DCB in VT mode */
3339         if (!strncmp(res->vt_en, "on", 2))
3340                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3341                                 (enum rte_eth_nb_tcs)res->num_tcs,
3342                                 pfc_en);
3343         else
3344                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3345                                 (enum rte_eth_nb_tcs)res->num_tcs,
3346                                 pfc_en);
3347
3348
3349         if (ret != 0) {
3350                 printf("Cannot initialize network ports.\n");
3351                 return;
3352         }
3353
3354         cmd_reconfig_device_queue(port_id, 1, 1);
3355 }
3356
3357 cmdline_parse_token_string_t cmd_config_dcb_port =
3358         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3359 cmdline_parse_token_string_t cmd_config_dcb_config =
3360         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3361 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3362         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3363 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3364         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3365 cmdline_parse_token_string_t cmd_config_dcb_vt =
3366         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3367 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3368         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3369 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3370         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3371 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3372         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3373 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3374         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3375
3376 cmdline_parse_inst_t cmd_config_dcb = {
3377         .f = cmd_config_dcb_parsed,
3378         .data = NULL,
3379         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3380         .tokens = {
3381                 (void *)&cmd_config_dcb_port,
3382                 (void *)&cmd_config_dcb_config,
3383                 (void *)&cmd_config_dcb_port_id,
3384                 (void *)&cmd_config_dcb_dcb,
3385                 (void *)&cmd_config_dcb_vt,
3386                 (void *)&cmd_config_dcb_vt_en,
3387                 (void *)&cmd_config_dcb_num_tcs,
3388                 (void *)&cmd_config_dcb_pfc,
3389                 (void *)&cmd_config_dcb_pfc_en,
3390                 NULL,
3391         },
3392 };
3393
3394 /* *** configure number of packets per burst *** */
3395 struct cmd_config_burst {
3396         cmdline_fixed_string_t port;
3397         cmdline_fixed_string_t keyword;
3398         cmdline_fixed_string_t all;
3399         cmdline_fixed_string_t name;
3400         uint16_t value;
3401 };
3402
3403 static void
3404 cmd_config_burst_parsed(void *parsed_result,
3405                         __rte_unused struct cmdline *cl,
3406                         __rte_unused void *data)
3407 {
3408         struct cmd_config_burst *res = parsed_result;
3409         struct rte_eth_dev_info dev_info;
3410         uint16_t rec_nb_pkts;
3411         int ret;
3412
3413         if (!all_ports_stopped()) {
3414                 printf("Please stop all ports first\n");
3415                 return;
3416         }
3417
3418         if (!strcmp(res->name, "burst")) {
3419                 if (res->value == 0) {
3420                         /* If user gives a value of zero, query the PMD for
3421                          * its recommended Rx burst size. Testpmd uses a single
3422                          * size for all ports, so assume all ports are the same
3423                          * NIC model and use the values from Port 0.
3424                          */
3425                         ret = eth_dev_info_get_print_err(0, &dev_info);
3426                         if (ret != 0)
3427                                 return;
3428
3429                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3430
3431                         if (rec_nb_pkts == 0) {
3432                                 printf("PMD does not recommend a burst size.\n"
3433                                         "User provided value must be between"
3434                                         " 1 and %d\n", MAX_PKT_BURST);
3435                                 return;
3436                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3437                                 printf("PMD recommended burst size of %d"
3438                                         " exceeds maximum value of %d\n",
3439                                         rec_nb_pkts, MAX_PKT_BURST);
3440                                 return;
3441                         }
3442                         printf("Using PMD-provided burst value of %d\n",
3443                                 rec_nb_pkts);
3444                         nb_pkt_per_burst = rec_nb_pkts;
3445                 } else if (res->value > MAX_PKT_BURST) {
3446                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3447                         return;
3448                 } else
3449                         nb_pkt_per_burst = res->value;
3450         } else {
3451                 printf("Unknown parameter\n");
3452                 return;
3453         }
3454
3455         init_port_config();
3456
3457         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3458 }
3459
3460 cmdline_parse_token_string_t cmd_config_burst_port =
3461         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3462 cmdline_parse_token_string_t cmd_config_burst_keyword =
3463         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3464 cmdline_parse_token_string_t cmd_config_burst_all =
3465         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3466 cmdline_parse_token_string_t cmd_config_burst_name =
3467         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3468 cmdline_parse_token_num_t cmd_config_burst_value =
3469         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3470
3471 cmdline_parse_inst_t cmd_config_burst = {
3472         .f = cmd_config_burst_parsed,
3473         .data = NULL,
3474         .help_str = "port config all burst <value>",
3475         .tokens = {
3476                 (void *)&cmd_config_burst_port,
3477                 (void *)&cmd_config_burst_keyword,
3478                 (void *)&cmd_config_burst_all,
3479                 (void *)&cmd_config_burst_name,
3480                 (void *)&cmd_config_burst_value,
3481                 NULL,
3482         },
3483 };
3484
3485 /* *** configure rx/tx queues *** */
3486 struct cmd_config_thresh {
3487         cmdline_fixed_string_t port;
3488         cmdline_fixed_string_t keyword;
3489         cmdline_fixed_string_t all;
3490         cmdline_fixed_string_t name;
3491         uint8_t value;
3492 };
3493
3494 static void
3495 cmd_config_thresh_parsed(void *parsed_result,
3496                         __rte_unused struct cmdline *cl,
3497                         __rte_unused void *data)
3498 {
3499         struct cmd_config_thresh *res = parsed_result;
3500
3501         if (!all_ports_stopped()) {
3502                 printf("Please stop all ports first\n");
3503                 return;
3504         }
3505
3506         if (!strcmp(res->name, "txpt"))
3507                 tx_pthresh = res->value;
3508         else if(!strcmp(res->name, "txht"))
3509                 tx_hthresh = res->value;
3510         else if(!strcmp(res->name, "txwt"))
3511                 tx_wthresh = res->value;
3512         else if(!strcmp(res->name, "rxpt"))
3513                 rx_pthresh = res->value;
3514         else if(!strcmp(res->name, "rxht"))
3515                 rx_hthresh = res->value;
3516         else if(!strcmp(res->name, "rxwt"))
3517                 rx_wthresh = res->value;
3518         else {
3519                 printf("Unknown parameter\n");
3520                 return;
3521         }
3522
3523         init_port_config();
3524
3525         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3526 }
3527
3528 cmdline_parse_token_string_t cmd_config_thresh_port =
3529         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3530 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3531         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3532 cmdline_parse_token_string_t cmd_config_thresh_all =
3533         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3534 cmdline_parse_token_string_t cmd_config_thresh_name =
3535         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3536                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3537 cmdline_parse_token_num_t cmd_config_thresh_value =
3538         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3539
3540 cmdline_parse_inst_t cmd_config_thresh = {
3541         .f = cmd_config_thresh_parsed,
3542         .data = NULL,
3543         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3544         .tokens = {
3545                 (void *)&cmd_config_thresh_port,
3546                 (void *)&cmd_config_thresh_keyword,
3547                 (void *)&cmd_config_thresh_all,
3548                 (void *)&cmd_config_thresh_name,
3549                 (void *)&cmd_config_thresh_value,
3550                 NULL,
3551         },
3552 };
3553
3554 /* *** configure free/rs threshold *** */
3555 struct cmd_config_threshold {
3556         cmdline_fixed_string_t port;
3557         cmdline_fixed_string_t keyword;
3558         cmdline_fixed_string_t all;
3559         cmdline_fixed_string_t name;
3560         uint16_t value;
3561 };
3562
3563 static void
3564 cmd_config_threshold_parsed(void *parsed_result,
3565                         __rte_unused struct cmdline *cl,
3566                         __rte_unused void *data)
3567 {
3568         struct cmd_config_threshold *res = parsed_result;
3569
3570         if (!all_ports_stopped()) {
3571                 printf("Please stop all ports first\n");
3572                 return;
3573         }
3574
3575         if (!strcmp(res->name, "txfreet"))
3576                 tx_free_thresh = res->value;
3577         else if (!strcmp(res->name, "txrst"))
3578                 tx_rs_thresh = res->value;
3579         else if (!strcmp(res->name, "rxfreet"))
3580                 rx_free_thresh = res->value;
3581         else {
3582                 printf("Unknown parameter\n");
3583                 return;
3584         }
3585
3586         init_port_config();
3587
3588         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3589 }
3590
3591 cmdline_parse_token_string_t cmd_config_threshold_port =
3592         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3593 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3594         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3595                                                                 "config");
3596 cmdline_parse_token_string_t cmd_config_threshold_all =
3597         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3598 cmdline_parse_token_string_t cmd_config_threshold_name =
3599         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3600                                                 "txfreet#txrst#rxfreet");
3601 cmdline_parse_token_num_t cmd_config_threshold_value =
3602         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3603
3604 cmdline_parse_inst_t cmd_config_threshold = {
3605         .f = cmd_config_threshold_parsed,
3606         .data = NULL,
3607         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3608         .tokens = {
3609                 (void *)&cmd_config_threshold_port,
3610                 (void *)&cmd_config_threshold_keyword,
3611                 (void *)&cmd_config_threshold_all,
3612                 (void *)&cmd_config_threshold_name,
3613                 (void *)&cmd_config_threshold_value,
3614                 NULL,
3615         },
3616 };
3617
3618 /* *** stop *** */
3619 struct cmd_stop_result {
3620         cmdline_fixed_string_t stop;
3621 };
3622
3623 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3624                             __rte_unused struct cmdline *cl,
3625                             __rte_unused void *data)
3626 {
3627         stop_packet_forwarding();
3628 }
3629
3630 cmdline_parse_token_string_t cmd_stop_stop =
3631         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3632
3633 cmdline_parse_inst_t cmd_stop = {
3634         .f = cmd_stop_parsed,
3635         .data = NULL,
3636         .help_str = "stop: Stop packet forwarding",
3637         .tokens = {
3638                 (void *)&cmd_stop_stop,
3639                 NULL,
3640         },
3641 };
3642
3643 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3644
3645 unsigned int
3646 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3647                 unsigned int *parsed_items, int check_unique_values)
3648 {
3649         unsigned int nb_item;
3650         unsigned int value;
3651         unsigned int i;
3652         unsigned int j;
3653         int value_ok;
3654         char c;
3655
3656         /*
3657          * First parse all items in the list and store their value.
3658          */
3659         value = 0;
3660         nb_item = 0;
3661         value_ok = 0;
3662         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3663                 c = str[i];
3664                 if ((c >= '0') && (c <= '9')) {
3665                         value = (unsigned int) (value * 10 + (c - '0'));
3666                         value_ok = 1;
3667                         continue;
3668                 }
3669                 if (c != ',') {
3670                         printf("character %c is not a decimal digit\n", c);
3671                         return 0;
3672                 }
3673                 if (! value_ok) {
3674                         printf("No valid value before comma\n");
3675                         return 0;
3676                 }
3677                 if (nb_item < max_items) {
3678                         parsed_items[nb_item] = value;
3679                         value_ok = 0;
3680                         value = 0;
3681                 }
3682                 nb_item++;
3683         }
3684         if (nb_item >= max_items) {
3685                 printf("Number of %s = %u > %u (maximum items)\n",
3686                        item_name, nb_item + 1, max_items);
3687                 return 0;
3688         }
3689         parsed_items[nb_item++] = value;
3690         if (! check_unique_values)
3691                 return nb_item;
3692
3693         /*
3694          * Then, check that all values in the list are differents.
3695          * No optimization here...
3696          */
3697         for (i = 0; i < nb_item; i++) {
3698                 for (j = i + 1; j < nb_item; j++) {
3699                         if (parsed_items[j] == parsed_items[i]) {
3700                                 printf("duplicated %s %u at index %u and %u\n",
3701                                        item_name, parsed_items[i], i, j);
3702                                 return 0;
3703                         }
3704                 }
3705         }
3706         return nb_item;
3707 }
3708
3709 struct cmd_set_list_result {
3710         cmdline_fixed_string_t cmd_keyword;
3711         cmdline_fixed_string_t list_name;
3712         cmdline_fixed_string_t list_of_items;
3713 };
3714
3715 static void cmd_set_list_parsed(void *parsed_result,
3716                                 __rte_unused struct cmdline *cl,
3717                                 __rte_unused void *data)
3718 {
3719         struct cmd_set_list_result *res;
3720         union {
3721                 unsigned int lcorelist[RTE_MAX_LCORE];
3722                 unsigned int portlist[RTE_MAX_ETHPORTS];
3723         } parsed_items;
3724         unsigned int nb_item;
3725
3726         if (test_done == 0) {
3727                 printf("Please stop forwarding first\n");
3728                 return;
3729         }
3730
3731         res = parsed_result;
3732         if (!strcmp(res->list_name, "corelist")) {
3733                 nb_item = parse_item_list(res->list_of_items, "core",
3734                                           RTE_MAX_LCORE,
3735                                           parsed_items.lcorelist, 1);
3736                 if (nb_item > 0) {
3737                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3738                         fwd_config_setup();
3739                 }
3740                 return;
3741         }
3742         if (!strcmp(res->list_name, "portlist")) {
3743                 nb_item = parse_item_list(res->list_of_items, "port",
3744                                           RTE_MAX_ETHPORTS,
3745                                           parsed_items.portlist, 1);
3746                 if (nb_item > 0) {
3747                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3748                         fwd_config_setup();
3749                 }
3750         }
3751 }
3752
3753 cmdline_parse_token_string_t cmd_set_list_keyword =
3754         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3755                                  "set");
3756 cmdline_parse_token_string_t cmd_set_list_name =
3757         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3758                                  "corelist#portlist");
3759 cmdline_parse_token_string_t cmd_set_list_of_items =
3760         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3761                                  NULL);
3762
3763 cmdline_parse_inst_t cmd_set_fwd_list = {
3764         .f = cmd_set_list_parsed,
3765         .data = NULL,
3766         .help_str = "set corelist|portlist <list0[,list1]*>",
3767         .tokens = {
3768                 (void *)&cmd_set_list_keyword,
3769                 (void *)&cmd_set_list_name,
3770                 (void *)&cmd_set_list_of_items,
3771                 NULL,
3772         },
3773 };
3774
3775 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3776
3777 struct cmd_setmask_result {
3778         cmdline_fixed_string_t set;
3779         cmdline_fixed_string_t mask;
3780         uint64_t hexavalue;
3781 };
3782
3783 static void cmd_set_mask_parsed(void *parsed_result,
3784                                 __rte_unused struct cmdline *cl,
3785                                 __rte_unused void *data)
3786 {
3787         struct cmd_setmask_result *res = parsed_result;
3788
3789         if (test_done == 0) {
3790                 printf("Please stop forwarding first\n");
3791                 return;
3792         }
3793         if (!strcmp(res->mask, "coremask")) {
3794                 set_fwd_lcores_mask(res->hexavalue);
3795                 fwd_config_setup();
3796         } else if (!strcmp(res->mask, "portmask")) {
3797                 set_fwd_ports_mask(res->hexavalue);
3798                 fwd_config_setup();
3799         }
3800 }
3801
3802 cmdline_parse_token_string_t cmd_setmask_set =
3803         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3804 cmdline_parse_token_string_t cmd_setmask_mask =
3805         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3806                                  "coremask#portmask");
3807 cmdline_parse_token_num_t cmd_setmask_value =
3808         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3809
3810 cmdline_parse_inst_t cmd_set_fwd_mask = {
3811         .f = cmd_set_mask_parsed,
3812         .data = NULL,
3813         .help_str = "set coremask|portmask <hexadecimal value>",
3814         .tokens = {
3815                 (void *)&cmd_setmask_set,
3816                 (void *)&cmd_setmask_mask,
3817                 (void *)&cmd_setmask_value,
3818                 NULL,
3819         },
3820 };
3821
3822 /*
3823  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3824  */
3825 struct cmd_set_result {
3826         cmdline_fixed_string_t set;
3827         cmdline_fixed_string_t what;
3828         uint16_t value;
3829 };
3830
3831 static void cmd_set_parsed(void *parsed_result,
3832                            __rte_unused struct cmdline *cl,
3833                            __rte_unused void *data)
3834 {
3835         struct cmd_set_result *res = parsed_result;
3836         if (!strcmp(res->what, "nbport")) {
3837                 set_fwd_ports_number(res->value);
3838                 fwd_config_setup();
3839         } else if (!strcmp(res->what, "nbcore")) {
3840                 set_fwd_lcores_number(res->value);
3841                 fwd_config_setup();
3842         } else if (!strcmp(res->what, "burst"))
3843                 set_nb_pkt_per_burst(res->value);
3844         else if (!strcmp(res->what, "verbose"))
3845                 set_verbose_level(res->value);
3846 }
3847
3848 cmdline_parse_token_string_t cmd_set_set =
3849         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3850 cmdline_parse_token_string_t cmd_set_what =
3851         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3852                                  "nbport#nbcore#burst#verbose");
3853 cmdline_parse_token_num_t cmd_set_value =
3854         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3855
3856 cmdline_parse_inst_t cmd_set_numbers = {
3857         .f = cmd_set_parsed,
3858         .data = NULL,
3859         .help_str = "set nbport|nbcore|burst|verbose <value>",
3860         .tokens = {
3861                 (void *)&cmd_set_set,
3862                 (void *)&cmd_set_what,
3863                 (void *)&cmd_set_value,
3864                 NULL,
3865         },
3866 };
3867
3868 /* *** SET LOG LEVEL CONFIGURATION *** */
3869
3870 struct cmd_set_log_result {
3871         cmdline_fixed_string_t set;
3872         cmdline_fixed_string_t log;
3873         cmdline_fixed_string_t type;
3874         uint32_t level;
3875 };
3876
3877 static void
3878 cmd_set_log_parsed(void *parsed_result,
3879                    __rte_unused struct cmdline *cl,
3880                    __rte_unused void *data)
3881 {
3882         struct cmd_set_log_result *res;
3883         int ret;
3884
3885         res = parsed_result;
3886         if (!strcmp(res->type, "global"))
3887                 rte_log_set_global_level(res->level);
3888         else {
3889                 ret = rte_log_set_level_regexp(res->type, res->level);
3890                 if (ret < 0)
3891                         printf("Unable to set log level\n");
3892         }
3893 }
3894
3895 cmdline_parse_token_string_t cmd_set_log_set =
3896         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3897 cmdline_parse_token_string_t cmd_set_log_log =
3898         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3899 cmdline_parse_token_string_t cmd_set_log_type =
3900         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3901 cmdline_parse_token_num_t cmd_set_log_level =
3902         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3903
3904 cmdline_parse_inst_t cmd_set_log = {
3905         .f = cmd_set_log_parsed,
3906         .data = NULL,
3907         .help_str = "set log global|<type> <level>",
3908         .tokens = {
3909                 (void *)&cmd_set_log_set,
3910                 (void *)&cmd_set_log_log,
3911                 (void *)&cmd_set_log_type,
3912                 (void *)&cmd_set_log_level,
3913                 NULL,
3914         },
3915 };
3916
3917 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3918
3919 struct cmd_set_rxoffs_result {
3920         cmdline_fixed_string_t cmd_keyword;
3921         cmdline_fixed_string_t rxoffs;
3922         cmdline_fixed_string_t seg_offsets;
3923 };
3924
3925 static void
3926 cmd_set_rxoffs_parsed(void *parsed_result,
3927                       __rte_unused struct cmdline *cl,
3928                       __rte_unused void *data)
3929 {
3930         struct cmd_set_rxoffs_result *res;
3931         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3932         unsigned int nb_segs;
3933
3934         res = parsed_result;
3935         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3936                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3937         if (nb_segs > 0)
3938                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3939 }
3940
3941 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3942         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3943                                  cmd_keyword, "set");
3944 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3945         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3946                                  rxoffs, "rxoffs");
3947 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3948         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3949                                  seg_offsets, NULL);
3950
3951 cmdline_parse_inst_t cmd_set_rxoffs = {
3952         .f = cmd_set_rxoffs_parsed,
3953         .data = NULL,
3954         .help_str = "set rxoffs <len0[,len1]*>",
3955         .tokens = {
3956                 (void *)&cmd_set_rxoffs_keyword,
3957                 (void *)&cmd_set_rxoffs_name,
3958                 (void *)&cmd_set_rxoffs_offsets,
3959                 NULL,
3960         },
3961 };
3962
3963 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3964
3965 struct cmd_set_rxpkts_result {
3966         cmdline_fixed_string_t cmd_keyword;
3967         cmdline_fixed_string_t rxpkts;
3968         cmdline_fixed_string_t seg_lengths;
3969 };
3970
3971 static void
3972 cmd_set_rxpkts_parsed(void *parsed_result,
3973                       __rte_unused struct cmdline *cl,
3974                       __rte_unused void *data)
3975 {
3976         struct cmd_set_rxpkts_result *res;
3977         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3978         unsigned int nb_segs;
3979
3980         res = parsed_result;
3981         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3982                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3983         if (nb_segs > 0)
3984                 set_rx_pkt_segments(seg_lengths, nb_segs);
3985 }
3986
3987 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3988         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3989                                  cmd_keyword, "set");
3990 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3991         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3992                                  rxpkts, "rxpkts");
3993 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3994         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3995                                  seg_lengths, NULL);
3996
3997 cmdline_parse_inst_t cmd_set_rxpkts = {
3998         .f = cmd_set_rxpkts_parsed,
3999         .data = NULL,
4000         .help_str = "set rxpkts <len0[,len1]*>",
4001         .tokens = {
4002                 (void *)&cmd_set_rxpkts_keyword,
4003                 (void *)&cmd_set_rxpkts_name,
4004                 (void *)&cmd_set_rxpkts_lengths,
4005                 NULL,
4006         },
4007 };
4008
4009 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
4010
4011 struct cmd_set_txpkts_result {
4012         cmdline_fixed_string_t cmd_keyword;
4013         cmdline_fixed_string_t txpkts;
4014         cmdline_fixed_string_t seg_lengths;
4015 };
4016
4017 static void
4018 cmd_set_txpkts_parsed(void *parsed_result,
4019                       __rte_unused struct cmdline *cl,
4020                       __rte_unused void *data)
4021 {
4022         struct cmd_set_txpkts_result *res;
4023         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4024         unsigned int nb_segs;
4025
4026         res = parsed_result;
4027         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4028                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4029         if (nb_segs > 0)
4030                 set_tx_pkt_segments(seg_lengths, nb_segs);
4031 }
4032
4033 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4034         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4035                                  cmd_keyword, "set");
4036 cmdline_parse_token_string_t cmd_set_txpkts_name =
4037         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4038                                  txpkts, "txpkts");
4039 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4040         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4041                                  seg_lengths, NULL);
4042
4043 cmdline_parse_inst_t cmd_set_txpkts = {
4044         .f = cmd_set_txpkts_parsed,
4045         .data = NULL,
4046         .help_str = "set txpkts <len0[,len1]*>",
4047         .tokens = {
4048                 (void *)&cmd_set_txpkts_keyword,
4049                 (void *)&cmd_set_txpkts_name,
4050                 (void *)&cmd_set_txpkts_lengths,
4051                 NULL,
4052         },
4053 };
4054
4055 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4056
4057 struct cmd_set_txsplit_result {
4058         cmdline_fixed_string_t cmd_keyword;
4059         cmdline_fixed_string_t txsplit;
4060         cmdline_fixed_string_t mode;
4061 };
4062
4063 static void
4064 cmd_set_txsplit_parsed(void *parsed_result,
4065                       __rte_unused struct cmdline *cl,
4066                       __rte_unused void *data)
4067 {
4068         struct cmd_set_txsplit_result *res;
4069
4070         res = parsed_result;
4071         set_tx_pkt_split(res->mode);
4072 }
4073
4074 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4075         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4076                                  cmd_keyword, "set");
4077 cmdline_parse_token_string_t cmd_set_txsplit_name =
4078         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4079                                  txsplit, "txsplit");
4080 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4081         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4082                                  mode, NULL);
4083
4084 cmdline_parse_inst_t cmd_set_txsplit = {
4085         .f = cmd_set_txsplit_parsed,
4086         .data = NULL,
4087         .help_str = "set txsplit on|off|rand",
4088         .tokens = {
4089                 (void *)&cmd_set_txsplit_keyword,
4090                 (void *)&cmd_set_txsplit_name,
4091                 (void *)&cmd_set_txsplit_mode,
4092                 NULL,
4093         },
4094 };
4095
4096 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4097
4098 struct cmd_set_txtimes_result {
4099         cmdline_fixed_string_t cmd_keyword;
4100         cmdline_fixed_string_t txtimes;
4101         cmdline_fixed_string_t tx_times;
4102 };
4103
4104 static void
4105 cmd_set_txtimes_parsed(void *parsed_result,
4106                        __rte_unused struct cmdline *cl,
4107                        __rte_unused void *data)
4108 {
4109         struct cmd_set_txtimes_result *res;
4110         unsigned int tx_times[2] = {0, 0};
4111         unsigned int n_times;
4112
4113         res = parsed_result;
4114         n_times = parse_item_list(res->tx_times, "tx times",
4115                                   2, tx_times, 0);
4116         if (n_times == 2)
4117                 set_tx_pkt_times(tx_times);
4118 }
4119
4120 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4121         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4122                                  cmd_keyword, "set");
4123 cmdline_parse_token_string_t cmd_set_txtimes_name =
4124         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4125                                  txtimes, "txtimes");
4126 cmdline_parse_token_string_t cmd_set_txtimes_value =
4127         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4128                                  tx_times, NULL);
4129
4130 cmdline_parse_inst_t cmd_set_txtimes = {
4131         .f = cmd_set_txtimes_parsed,
4132         .data = NULL,
4133         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4134         .tokens = {
4135                 (void *)&cmd_set_txtimes_keyword,
4136                 (void *)&cmd_set_txtimes_name,
4137                 (void *)&cmd_set_txtimes_value,
4138                 NULL,
4139         },
4140 };
4141
4142 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4143 struct cmd_rx_vlan_filter_all_result {
4144         cmdline_fixed_string_t rx_vlan;
4145         cmdline_fixed_string_t what;
4146         cmdline_fixed_string_t all;
4147         portid_t port_id;
4148 };
4149
4150 static void
4151 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4152                               __rte_unused struct cmdline *cl,
4153                               __rte_unused void *data)
4154 {
4155         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4156
4157         if (!strcmp(res->what, "add"))
4158                 rx_vlan_all_filter_set(res->port_id, 1);
4159         else
4160                 rx_vlan_all_filter_set(res->port_id, 0);
4161 }
4162
4163 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4164         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4165                                  rx_vlan, "rx_vlan");
4166 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4167         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4168                                  what, "add#rm");
4169 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4170         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4171                                  all, "all");
4172 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4173         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4174                               port_id, UINT16);
4175
4176 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4177         .f = cmd_rx_vlan_filter_all_parsed,
4178         .data = NULL,
4179         .help_str = "rx_vlan add|rm all <port_id>: "
4180                 "Add/Remove all identifiers to/from the set of VLAN "
4181                 "identifiers filtered by a port",
4182         .tokens = {
4183                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4184                 (void *)&cmd_rx_vlan_filter_all_what,
4185                 (void *)&cmd_rx_vlan_filter_all_all,
4186                 (void *)&cmd_rx_vlan_filter_all_portid,
4187                 NULL,
4188         },
4189 };
4190
4191 /* *** VLAN OFFLOAD SET ON A PORT *** */
4192 struct cmd_vlan_offload_result {
4193         cmdline_fixed_string_t vlan;
4194         cmdline_fixed_string_t set;
4195         cmdline_fixed_string_t vlan_type;
4196         cmdline_fixed_string_t what;
4197         cmdline_fixed_string_t on;
4198         cmdline_fixed_string_t port_id;
4199 };
4200
4201 static void
4202 cmd_vlan_offload_parsed(void *parsed_result,
4203                           __rte_unused struct cmdline *cl,
4204                           __rte_unused void *data)
4205 {
4206         int on;
4207         struct cmd_vlan_offload_result *res = parsed_result;
4208         char *str;
4209         int i, len = 0;
4210         portid_t port_id = 0;
4211         unsigned int tmp;
4212
4213         str = res->port_id;
4214         len = strnlen(str, STR_TOKEN_SIZE);
4215         i = 0;
4216         /* Get port_id first */
4217         while(i < len){
4218                 if(str[i] == ',')
4219                         break;
4220
4221                 i++;
4222         }
4223         str[i]='\0';
4224         tmp = strtoul(str, NULL, 0);
4225         /* If port_id greater that what portid_t can represent, return */
4226         if(tmp >= RTE_MAX_ETHPORTS)
4227                 return;
4228         port_id = (portid_t)tmp;
4229
4230         if (!strcmp(res->on, "on"))
4231                 on = 1;
4232         else
4233                 on = 0;
4234
4235         if (!strcmp(res->what, "strip"))
4236                 rx_vlan_strip_set(port_id,  on);
4237         else if(!strcmp(res->what, "stripq")){
4238                 uint16_t queue_id = 0;
4239
4240                 /* No queue_id, return */
4241                 if(i + 1 >= len) {
4242                         printf("must specify (port,queue_id)\n");
4243                         return;
4244                 }
4245                 tmp = strtoul(str + i + 1, NULL, 0);
4246                 /* If queue_id greater that what 16-bits can represent, return */
4247                 if(tmp > 0xffff)
4248                         return;
4249
4250                 queue_id = (uint16_t)tmp;
4251                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4252         }
4253         else if (!strcmp(res->what, "filter"))
4254                 rx_vlan_filter_set(port_id, on);
4255         else if (!strcmp(res->what, "qinq_strip"))
4256                 rx_vlan_qinq_strip_set(port_id, on);
4257         else
4258                 vlan_extend_set(port_id, on);
4259
4260         return;
4261 }
4262
4263 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4264         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4265                                  vlan, "vlan");
4266 cmdline_parse_token_string_t cmd_vlan_offload_set =
4267         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4268                                  set, "set");
4269 cmdline_parse_token_string_t cmd_vlan_offload_what =
4270         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4271                                 what, "strip#filter#qinq_strip#extend#stripq");
4272 cmdline_parse_token_string_t cmd_vlan_offload_on =
4273         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4274                               on, "on#off");
4275 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4276         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4277                               port_id, NULL);
4278
4279 cmdline_parse_inst_t cmd_vlan_offload = {
4280         .f = cmd_vlan_offload_parsed,
4281         .data = NULL,
4282         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4283                 "<port_id[,queue_id]>: "
4284                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4285         .tokens = {
4286                 (void *)&cmd_vlan_offload_vlan,
4287                 (void *)&cmd_vlan_offload_set,
4288                 (void *)&cmd_vlan_offload_what,
4289                 (void *)&cmd_vlan_offload_on,
4290                 (void *)&cmd_vlan_offload_portid,
4291                 NULL,
4292         },
4293 };
4294
4295 /* *** VLAN TPID SET ON A PORT *** */
4296 struct cmd_vlan_tpid_result {
4297         cmdline_fixed_string_t vlan;
4298         cmdline_fixed_string_t set;
4299         cmdline_fixed_string_t vlan_type;
4300         cmdline_fixed_string_t what;
4301         uint16_t tp_id;
4302         portid_t port_id;
4303 };
4304
4305 static void
4306 cmd_vlan_tpid_parsed(void *parsed_result,
4307                           __rte_unused struct cmdline *cl,
4308                           __rte_unused void *data)
4309 {
4310         struct cmd_vlan_tpid_result *res = parsed_result;
4311         enum rte_vlan_type vlan_type;
4312
4313         if (!strcmp(res->vlan_type, "inner"))
4314                 vlan_type = ETH_VLAN_TYPE_INNER;
4315         else if (!strcmp(res->vlan_type, "outer"))
4316                 vlan_type = ETH_VLAN_TYPE_OUTER;
4317         else {
4318                 printf("Unknown vlan type\n");
4319                 return;
4320         }
4321         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4322 }
4323
4324 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4325         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4326                                  vlan, "vlan");
4327 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4328         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4329                                  set, "set");
4330 cmdline_parse_token_string_t cmd_vlan_type =
4331         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4332                                  vlan_type, "inner#outer");
4333 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4334         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4335                                  what, "tpid");
4336 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4337         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4338                               tp_id, UINT16);
4339 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4340         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4341                               port_id, UINT16);
4342
4343 cmdline_parse_inst_t cmd_vlan_tpid = {
4344         .f = cmd_vlan_tpid_parsed,
4345         .data = NULL,
4346         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4347                 "Set the VLAN Ether type",
4348         .tokens = {
4349                 (void *)&cmd_vlan_tpid_vlan,
4350                 (void *)&cmd_vlan_tpid_set,
4351                 (void *)&cmd_vlan_type,
4352                 (void *)&cmd_vlan_tpid_what,
4353                 (void *)&cmd_vlan_tpid_tpid,
4354                 (void *)&cmd_vlan_tpid_portid,
4355                 NULL,
4356         },
4357 };
4358
4359 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4360 struct cmd_rx_vlan_filter_result {
4361         cmdline_fixed_string_t rx_vlan;
4362         cmdline_fixed_string_t what;
4363         uint16_t vlan_id;
4364         portid_t port_id;
4365 };
4366
4367 static void
4368 cmd_rx_vlan_filter_parsed(void *parsed_result,
4369                           __rte_unused struct cmdline *cl,
4370                           __rte_unused void *data)
4371 {
4372         struct cmd_rx_vlan_filter_result *res = parsed_result;
4373
4374         if (!strcmp(res->what, "add"))
4375                 rx_vft_set(res->port_id, res->vlan_id, 1);
4376         else
4377                 rx_vft_set(res->port_id, res->vlan_id, 0);
4378 }
4379
4380 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4381         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4382                                  rx_vlan, "rx_vlan");
4383 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4384         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4385                                  what, "add#rm");
4386 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4387         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4388                               vlan_id, UINT16);
4389 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4390         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4391                               port_id, UINT16);
4392
4393 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4394         .f = cmd_rx_vlan_filter_parsed,
4395         .data = NULL,
4396         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4397                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4398                 "identifiers filtered by a port",
4399         .tokens = {
4400                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4401                 (void *)&cmd_rx_vlan_filter_what,
4402                 (void *)&cmd_rx_vlan_filter_vlanid,
4403                 (void *)&cmd_rx_vlan_filter_portid,
4404                 NULL,
4405         },
4406 };
4407
4408 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4409 struct cmd_tx_vlan_set_result {
4410         cmdline_fixed_string_t tx_vlan;
4411         cmdline_fixed_string_t set;
4412         portid_t port_id;
4413         uint16_t vlan_id;
4414 };
4415
4416 static void
4417 cmd_tx_vlan_set_parsed(void *parsed_result,
4418                        __rte_unused struct cmdline *cl,
4419                        __rte_unused void *data)
4420 {
4421         struct cmd_tx_vlan_set_result *res = parsed_result;
4422
4423         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4424                 return;
4425
4426         if (!port_is_stopped(res->port_id)) {
4427                 printf("Please stop port %d first\n", res->port_id);
4428                 return;
4429         }
4430
4431         tx_vlan_set(res->port_id, res->vlan_id);
4432
4433         cmd_reconfig_device_queue(res->port_id, 1, 1);
4434 }
4435
4436 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4437         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4438                                  tx_vlan, "tx_vlan");
4439 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4440         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4441                                  set, "set");
4442 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4443         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4444                               port_id, UINT16);
4445 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4446         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4447                               vlan_id, UINT16);
4448
4449 cmdline_parse_inst_t cmd_tx_vlan_set = {
4450         .f = cmd_tx_vlan_set_parsed,
4451         .data = NULL,
4452         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4453                 "Enable hardware insertion of a single VLAN header "
4454                 "with a given TAG Identifier in packets sent on a port",
4455         .tokens = {
4456                 (void *)&cmd_tx_vlan_set_tx_vlan,
4457                 (void *)&cmd_tx_vlan_set_set,
4458                 (void *)&cmd_tx_vlan_set_portid,
4459                 (void *)&cmd_tx_vlan_set_vlanid,
4460                 NULL,
4461         },
4462 };
4463
4464 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4465 struct cmd_tx_vlan_set_qinq_result {
4466         cmdline_fixed_string_t tx_vlan;
4467         cmdline_fixed_string_t set;
4468         portid_t port_id;
4469         uint16_t vlan_id;
4470         uint16_t vlan_id_outer;
4471 };
4472
4473 static void
4474 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4475                             __rte_unused struct cmdline *cl,
4476                             __rte_unused void *data)
4477 {
4478         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4479
4480         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4481                 return;
4482
4483         if (!port_is_stopped(res->port_id)) {
4484                 printf("Please stop port %d first\n", res->port_id);
4485                 return;
4486         }
4487
4488         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4489
4490         cmd_reconfig_device_queue(res->port_id, 1, 1);
4491 }
4492
4493 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4494         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4495                 tx_vlan, "tx_vlan");
4496 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4497         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4498                 set, "set");
4499 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4500         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4501                 port_id, UINT16);
4502 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4503         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4504                 vlan_id, UINT16);
4505 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4506         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4507                 vlan_id_outer, UINT16);
4508
4509 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4510         .f = cmd_tx_vlan_set_qinq_parsed,
4511         .data = NULL,
4512         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4513                 "Enable hardware insertion of double VLAN header "
4514                 "with given TAG Identifiers in packets sent on a port",
4515         .tokens = {
4516                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4517                 (void *)&cmd_tx_vlan_set_qinq_set,
4518                 (void *)&cmd_tx_vlan_set_qinq_portid,
4519                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4520                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4521                 NULL,
4522         },
4523 };
4524
4525 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4526 struct cmd_tx_vlan_set_pvid_result {
4527         cmdline_fixed_string_t tx_vlan;
4528         cmdline_fixed_string_t set;
4529         cmdline_fixed_string_t pvid;
4530         portid_t port_id;
4531         uint16_t vlan_id;
4532         cmdline_fixed_string_t mode;
4533 };
4534
4535 static void
4536 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4537                             __rte_unused struct cmdline *cl,
4538                             __rte_unused void *data)
4539 {
4540         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4541
4542         if (strcmp(res->mode, "on") == 0)
4543                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4544         else
4545                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4546 }
4547
4548 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4549         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4550                                  tx_vlan, "tx_vlan");
4551 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4552         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4553                                  set, "set");
4554 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4555         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4556                                  pvid, "pvid");
4557 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4558         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4559                              port_id, UINT16);
4560 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4561         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4562                               vlan_id, UINT16);
4563 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4564         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4565                                  mode, "on#off");
4566
4567 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4568         .f = cmd_tx_vlan_set_pvid_parsed,
4569         .data = NULL,
4570         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4571         .tokens = {
4572                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4573                 (void *)&cmd_tx_vlan_set_pvid_set,
4574                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4575                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4576                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4577                 (void *)&cmd_tx_vlan_set_pvid_mode,
4578                 NULL,
4579         },
4580 };
4581
4582 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4583 struct cmd_tx_vlan_reset_result {
4584         cmdline_fixed_string_t tx_vlan;
4585         cmdline_fixed_string_t reset;
4586         portid_t port_id;
4587 };
4588
4589 static void
4590 cmd_tx_vlan_reset_parsed(void *parsed_result,
4591                          __rte_unused struct cmdline *cl,
4592                          __rte_unused void *data)
4593 {
4594         struct cmd_tx_vlan_reset_result *res = parsed_result;
4595
4596         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4597                 return;
4598
4599         if (!port_is_stopped(res->port_id)) {
4600                 printf("Please stop port %d first\n", res->port_id);
4601                 return;
4602         }
4603
4604         tx_vlan_reset(res->port_id);
4605
4606         cmd_reconfig_device_queue(res->port_id, 1, 1);
4607 }
4608
4609 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4610         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4611                                  tx_vlan, "tx_vlan");
4612 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4613         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4614                                  reset, "reset");
4615 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4616         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4617                               port_id, UINT16);
4618
4619 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4620         .f = cmd_tx_vlan_reset_parsed,
4621         .data = NULL,
4622         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4623                 "VLAN header in packets sent on a port",
4624         .tokens = {
4625                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4626                 (void *)&cmd_tx_vlan_reset_reset,
4627                 (void *)&cmd_tx_vlan_reset_portid,
4628                 NULL,
4629         },
4630 };
4631
4632
4633 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4634 struct cmd_csum_result {
4635         cmdline_fixed_string_t csum;
4636         cmdline_fixed_string_t mode;
4637         cmdline_fixed_string_t proto;
4638         cmdline_fixed_string_t hwsw;
4639         portid_t port_id;
4640 };
4641
4642 static void
4643 csum_show(int port_id)
4644 {
4645         struct rte_eth_dev_info dev_info;
4646         uint64_t tx_offloads;
4647         int ret;
4648
4649         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4650         printf("Parse tunnel is %s\n",
4651                 (ports[port_id].parse_tunnel) ? "on" : "off");
4652         printf("IP checksum offload is %s\n",
4653                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4654         printf("UDP checksum offload is %s\n",
4655                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4656         printf("TCP checksum offload is %s\n",
4657                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4658         printf("SCTP checksum offload is %s\n",
4659                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4660         printf("Outer-Ip checksum offload is %s\n",
4661                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4662         printf("Outer-Udp checksum offload is %s\n",
4663                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4664
4665         /* display warnings if configuration is not supported by the NIC */
4666         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4667         if (ret != 0)
4668                 return;
4669
4670         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4671                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4672                 printf("Warning: hardware IP checksum enabled but not "
4673                         "supported by port %d\n", port_id);
4674         }
4675         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4676                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4677                 printf("Warning: hardware UDP checksum enabled but not "
4678                         "supported by port %d\n", port_id);
4679         }
4680         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4681                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4682                 printf("Warning: hardware TCP checksum enabled but not "
4683                         "supported by port %d\n", port_id);
4684         }
4685         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4686                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4687                 printf("Warning: hardware SCTP checksum enabled but not "
4688                         "supported by port %d\n", port_id);
4689         }
4690         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4691                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4692                 printf("Warning: hardware outer IP checksum enabled but not "
4693                         "supported by port %d\n", port_id);
4694         }
4695         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4696                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4697                         == 0) {
4698                 printf("Warning: hardware outer UDP checksum enabled but not "
4699                         "supported by port %d\n", port_id);
4700         }
4701 }
4702
4703 static void
4704 cmd_config_queue_tx_offloads(struct rte_port *port)
4705 {
4706         int k;
4707
4708         /* Apply queue tx offloads configuration */
4709         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4710                 port->tx_conf[k].offloads =
4711                         port->dev_conf.txmode.offloads;
4712 }
4713
4714 static void
4715 cmd_csum_parsed(void *parsed_result,
4716                        __rte_unused struct cmdline *cl,
4717                        __rte_unused void *data)
4718 {
4719         struct cmd_csum_result *res = parsed_result;
4720         int hw = 0;
4721         uint64_t csum_offloads = 0;
4722         struct rte_eth_dev_info dev_info;
4723         int ret;
4724
4725         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4726                 printf("invalid port %d\n", res->port_id);
4727                 return;
4728         }
4729         if (!port_is_stopped(res->port_id)) {
4730                 printf("Please stop port %d first\n", res->port_id);
4731                 return;
4732         }
4733
4734         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4735         if (ret != 0)
4736                 return;
4737
4738         if (!strcmp(res->mode, "set")) {
4739
4740                 if (!strcmp(res->hwsw, "hw"))
4741                         hw = 1;
4742
4743                 if (!strcmp(res->proto, "ip")) {
4744                         if (hw == 0 || (dev_info.tx_offload_capa &
4745                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4746                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4747                         } else {
4748                                 printf("IP checksum offload is not supported "
4749                                        "by port %u\n", res->port_id);
4750                         }
4751                 } else if (!strcmp(res->proto, "udp")) {
4752                         if (hw == 0 || (dev_info.tx_offload_capa &
4753                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4754                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4755                         } else {
4756                                 printf("UDP checksum offload is not supported "
4757                                        "by port %u\n", res->port_id);
4758                         }
4759                 } else if (!strcmp(res->proto, "tcp")) {
4760                         if (hw == 0 || (dev_info.tx_offload_capa &
4761                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4762                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4763                         } else {
4764                                 printf("TCP checksum offload is not supported "
4765                                        "by port %u\n", res->port_id);
4766                         }
4767                 } else if (!strcmp(res->proto, "sctp")) {
4768                         if (hw == 0 || (dev_info.tx_offload_capa &
4769                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4770                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4771                         } else {
4772                                 printf("SCTP checksum offload is not supported "
4773                                        "by port %u\n", res->port_id);
4774                         }
4775                 } else if (!strcmp(res->proto, "outer-ip")) {
4776                         if (hw == 0 || (dev_info.tx_offload_capa &
4777                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4778                                 csum_offloads |=
4779                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4780                         } else {
4781                                 printf("Outer IP checksum offload is not "
4782                                        "supported by port %u\n", res->port_id);
4783                         }
4784                 } else if (!strcmp(res->proto, "outer-udp")) {
4785                         if (hw == 0 || (dev_info.tx_offload_capa &
4786                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4787                                 csum_offloads |=
4788                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4789                         } else {
4790                                 printf("Outer UDP checksum offload is not "
4791                                        "supported by port %u\n", res->port_id);
4792                         }
4793                 }
4794
4795                 if (hw) {
4796                         ports[res->port_id].dev_conf.txmode.offloads |=
4797                                                         csum_offloads;
4798                 } else {
4799                         ports[res->port_id].dev_conf.txmode.offloads &=
4800                                                         (~csum_offloads);
4801                 }
4802                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4803         }
4804         csum_show(res->port_id);
4805
4806         cmd_reconfig_device_queue(res->port_id, 1, 1);
4807 }
4808
4809 cmdline_parse_token_string_t cmd_csum_csum =
4810         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4811                                 csum, "csum");
4812 cmdline_parse_token_string_t cmd_csum_mode =
4813         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4814                                 mode, "set");
4815 cmdline_parse_token_string_t cmd_csum_proto =
4816         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4817                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4818 cmdline_parse_token_string_t cmd_csum_hwsw =
4819         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4820                                 hwsw, "hw#sw");
4821 cmdline_parse_token_num_t cmd_csum_portid =
4822         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4823                                 port_id, UINT16);
4824
4825 cmdline_parse_inst_t cmd_csum_set = {
4826         .f = cmd_csum_parsed,
4827         .data = NULL,
4828         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4829                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4830                 "using csum forward engine",
4831         .tokens = {
4832                 (void *)&cmd_csum_csum,
4833                 (void *)&cmd_csum_mode,
4834                 (void *)&cmd_csum_proto,
4835                 (void *)&cmd_csum_hwsw,
4836                 (void *)&cmd_csum_portid,
4837                 NULL,
4838         },
4839 };
4840
4841 cmdline_parse_token_string_t cmd_csum_mode_show =
4842         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4843                                 mode, "show");
4844
4845 cmdline_parse_inst_t cmd_csum_show = {
4846         .f = cmd_csum_parsed,
4847         .data = NULL,
4848         .help_str = "csum show <port_id>: Show checksum offload configuration",
4849         .tokens = {
4850                 (void *)&cmd_csum_csum,
4851                 (void *)&cmd_csum_mode_show,
4852                 (void *)&cmd_csum_portid,
4853                 NULL,
4854         },
4855 };
4856
4857 /* Enable/disable tunnel parsing */
4858 struct cmd_csum_tunnel_result {
4859         cmdline_fixed_string_t csum;
4860         cmdline_fixed_string_t parse;
4861         cmdline_fixed_string_t onoff;
4862         portid_t port_id;
4863 };
4864
4865 static void
4866 cmd_csum_tunnel_parsed(void *parsed_result,
4867                        __rte_unused struct cmdline *cl,
4868                        __rte_unused void *data)
4869 {
4870         struct cmd_csum_tunnel_result *res = parsed_result;
4871
4872         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4873                 return;
4874
4875         if (!strcmp(res->onoff, "on"))
4876                 ports[res->port_id].parse_tunnel = 1;
4877         else
4878                 ports[res->port_id].parse_tunnel = 0;
4879
4880         csum_show(res->port_id);
4881 }
4882
4883 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4884         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4885                                 csum, "csum");
4886 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4887         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4888                                 parse, "parse-tunnel");
4889 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4890         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4891                                 onoff, "on#off");
4892 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4893         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4894                                 port_id, UINT16);
4895
4896 cmdline_parse_inst_t cmd_csum_tunnel = {
4897         .f = cmd_csum_tunnel_parsed,
4898         .data = NULL,
4899         .help_str = "csum parse-tunnel on|off <port_id>: "
4900                 "Enable/Disable parsing of tunnels for csum engine",
4901         .tokens = {
4902                 (void *)&cmd_csum_tunnel_csum,
4903                 (void *)&cmd_csum_tunnel_parse,
4904                 (void *)&cmd_csum_tunnel_onoff,
4905                 (void *)&cmd_csum_tunnel_portid,
4906                 NULL,
4907         },
4908 };
4909
4910 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4911 struct cmd_tso_set_result {
4912         cmdline_fixed_string_t tso;
4913         cmdline_fixed_string_t mode;
4914         uint16_t tso_segsz;
4915         portid_t port_id;
4916 };
4917
4918 static void
4919 cmd_tso_set_parsed(void *parsed_result,
4920                        __rte_unused struct cmdline *cl,
4921                        __rte_unused void *data)
4922 {
4923         struct cmd_tso_set_result *res = parsed_result;
4924         struct rte_eth_dev_info dev_info;
4925         int ret;
4926
4927         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4928                 return;
4929         if (!port_is_stopped(res->port_id)) {
4930                 printf("Please stop port %d first\n", res->port_id);
4931                 return;
4932         }
4933
4934         if (!strcmp(res->mode, "set"))
4935                 ports[res->port_id].tso_segsz = res->tso_segsz;
4936
4937         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4938         if (ret != 0)
4939                 return;
4940
4941         if ((ports[res->port_id].tso_segsz != 0) &&
4942                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4943                 printf("Error: TSO is not supported by port %d\n",
4944                        res->port_id);
4945                 return;
4946         }
4947
4948         if (ports[res->port_id].tso_segsz == 0) {
4949                 ports[res->port_id].dev_conf.txmode.offloads &=
4950                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4951                 printf("TSO for non-tunneled packets is disabled\n");
4952         } else {
4953                 ports[res->port_id].dev_conf.txmode.offloads |=
4954                                                 DEV_TX_OFFLOAD_TCP_TSO;
4955                 printf("TSO segment size for non-tunneled packets is %d\n",
4956                         ports[res->port_id].tso_segsz);
4957         }
4958         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4959
4960         /* display warnings if configuration is not supported by the NIC */
4961         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4962         if (ret != 0)
4963                 return;
4964
4965         if ((ports[res->port_id].tso_segsz != 0) &&
4966                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4967                 printf("Warning: TSO enabled but not "
4968                         "supported by port %d\n", res->port_id);
4969         }
4970
4971         cmd_reconfig_device_queue(res->port_id, 1, 1);
4972 }
4973
4974 cmdline_parse_token_string_t cmd_tso_set_tso =
4975         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4976                                 tso, "tso");
4977 cmdline_parse_token_string_t cmd_tso_set_mode =
4978         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4979                                 mode, "set");
4980 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4981         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4982                                 tso_segsz, UINT16);
4983 cmdline_parse_token_num_t cmd_tso_set_portid =
4984         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4985                                 port_id, UINT16);
4986
4987 cmdline_parse_inst_t cmd_tso_set = {
4988         .f = cmd_tso_set_parsed,
4989         .data = NULL,
4990         .help_str = "tso set <tso_segsz> <port_id>: "
4991                 "Set TSO segment size of non-tunneled packets for csum engine "
4992                 "(0 to disable)",
4993         .tokens = {
4994                 (void *)&cmd_tso_set_tso,
4995                 (void *)&cmd_tso_set_mode,
4996                 (void *)&cmd_tso_set_tso_segsz,
4997                 (void *)&cmd_tso_set_portid,
4998                 NULL,
4999         },
5000 };
5001
5002 cmdline_parse_token_string_t cmd_tso_show_mode =
5003         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
5004                                 mode, "show");
5005
5006
5007 cmdline_parse_inst_t cmd_tso_show = {
5008         .f = cmd_tso_set_parsed,
5009         .data = NULL,
5010         .help_str = "tso show <port_id>: "
5011                 "Show TSO segment size of non-tunneled packets for csum engine",
5012         .tokens = {
5013                 (void *)&cmd_tso_set_tso,
5014                 (void *)&cmd_tso_show_mode,
5015                 (void *)&cmd_tso_set_portid,
5016                 NULL,
5017         },
5018 };
5019
5020 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5021 struct cmd_tunnel_tso_set_result {
5022         cmdline_fixed_string_t tso;
5023         cmdline_fixed_string_t mode;
5024         uint16_t tso_segsz;
5025         portid_t port_id;
5026 };
5027
5028 static struct rte_eth_dev_info
5029 check_tunnel_tso_nic_support(portid_t port_id)
5030 {
5031         struct rte_eth_dev_info dev_info;
5032
5033         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5034                 return dev_info;
5035
5036         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
5037                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
5038                        "not enabled for port %d\n", port_id);
5039         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
5040                 printf("Warning: GRE TUNNEL TSO not supported therefore "
5041                        "not enabled for port %d\n", port_id);
5042         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
5043                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
5044                        "not enabled for port %d\n", port_id);
5045         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
5046                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
5047                        "not enabled for port %d\n", port_id);
5048         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
5049                 printf("Warning: IP TUNNEL TSO not supported therefore "
5050                        "not enabled for port %d\n", port_id);
5051         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
5052                 printf("Warning: UDP TUNNEL TSO not supported therefore "
5053                        "not enabled for port %d\n", port_id);
5054         return dev_info;
5055 }
5056
5057 static void
5058 cmd_tunnel_tso_set_parsed(void *parsed_result,
5059                           __rte_unused struct cmdline *cl,
5060                           __rte_unused void *data)
5061 {
5062         struct cmd_tunnel_tso_set_result *res = parsed_result;
5063         struct rte_eth_dev_info dev_info;
5064
5065         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5066                 return;
5067         if (!port_is_stopped(res->port_id)) {
5068                 printf("Please stop port %d first\n", res->port_id);
5069                 return;
5070         }
5071
5072         if (!strcmp(res->mode, "set"))
5073                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5074
5075         dev_info = check_tunnel_tso_nic_support(res->port_id);
5076         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5077                 ports[res->port_id].dev_conf.txmode.offloads &=
5078                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5079                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
5080                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5081                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5082                           DEV_TX_OFFLOAD_IP_TNL_TSO |
5083                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
5084                 printf("TSO for tunneled packets is disabled\n");
5085         } else {
5086                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5087                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
5088                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5089                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5090                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
5091                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
5092
5093                 ports[res->port_id].dev_conf.txmode.offloads |=
5094                         (tso_offloads & dev_info.tx_offload_capa);
5095                 printf("TSO segment size for tunneled packets is %d\n",
5096                         ports[res->port_id].tunnel_tso_segsz);
5097
5098                 /* Below conditions are needed to make it work:
5099                  * (1) tunnel TSO is supported by the NIC;
5100                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5101                  * are recognized;
5102                  * (3) for tunneled pkts with outer L3 of IPv4,
5103                  * "csum set outer-ip" must be set to hw, because after tso,
5104                  * total_len of outer IP header is changed, and the checksum
5105                  * of outer IP header calculated by sw should be wrong; that
5106                  * is not necessary for IPv6 tunneled pkts because there's no
5107                  * checksum in IP header anymore.
5108                  */
5109
5110                 if (!ports[res->port_id].parse_tunnel)
5111                         printf("Warning: csum parse_tunnel must be set "
5112                                 "so that tunneled packets are recognized\n");
5113                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5114                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5115                         printf("Warning: csum set outer-ip must be set to hw "
5116                                 "if outer L3 is IPv4; not necessary for IPv6\n");
5117         }
5118
5119         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5120         cmd_reconfig_device_queue(res->port_id, 1, 1);
5121 }
5122
5123 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5124         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5125                                 tso, "tunnel_tso");
5126 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5127         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5128                                 mode, "set");
5129 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5130         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5131                                 tso_segsz, UINT16);
5132 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5133         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5134                                 port_id, UINT16);
5135
5136 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5137         .f = cmd_tunnel_tso_set_parsed,
5138         .data = NULL,
5139         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5140                 "Set TSO segment size of tunneled packets for csum engine "
5141                 "(0 to disable)",
5142         .tokens = {
5143                 (void *)&cmd_tunnel_tso_set_tso,
5144                 (void *)&cmd_tunnel_tso_set_mode,
5145                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5146                 (void *)&cmd_tunnel_tso_set_portid,
5147                 NULL,
5148         },
5149 };
5150
5151 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5152         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5153                                 mode, "show");
5154
5155
5156 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5157         .f = cmd_tunnel_tso_set_parsed,
5158         .data = NULL,
5159         .help_str = "tunnel_tso show <port_id> "
5160                 "Show TSO segment size of tunneled packets for csum engine",
5161         .tokens = {
5162                 (void *)&cmd_tunnel_tso_set_tso,
5163                 (void *)&cmd_tunnel_tso_show_mode,
5164                 (void *)&cmd_tunnel_tso_set_portid,
5165                 NULL,
5166         },
5167 };
5168
5169 /* *** SET GRO FOR A PORT *** */
5170 struct cmd_gro_enable_result {
5171         cmdline_fixed_string_t cmd_set;
5172         cmdline_fixed_string_t cmd_port;
5173         cmdline_fixed_string_t cmd_keyword;
5174         cmdline_fixed_string_t cmd_onoff;
5175         portid_t cmd_pid;
5176 };
5177
5178 static void
5179 cmd_gro_enable_parsed(void *parsed_result,
5180                 __rte_unused struct cmdline *cl,
5181                 __rte_unused void *data)
5182 {
5183         struct cmd_gro_enable_result *res;
5184
5185         res = parsed_result;
5186         if (!strcmp(res->cmd_keyword, "gro"))
5187                 setup_gro(res->cmd_onoff, res->cmd_pid);
5188 }
5189
5190 cmdline_parse_token_string_t cmd_gro_enable_set =
5191         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5192                         cmd_set, "set");
5193 cmdline_parse_token_string_t cmd_gro_enable_port =
5194         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5195                         cmd_keyword, "port");
5196 cmdline_parse_token_num_t cmd_gro_enable_pid =
5197         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5198                         cmd_pid, UINT16);
5199 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5200         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5201                         cmd_keyword, "gro");
5202 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5203         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5204                         cmd_onoff, "on#off");
5205
5206 cmdline_parse_inst_t cmd_gro_enable = {
5207         .f = cmd_gro_enable_parsed,
5208         .data = NULL,
5209         .help_str = "set port <port_id> gro on|off",
5210         .tokens = {
5211                 (void *)&cmd_gro_enable_set,
5212                 (void *)&cmd_gro_enable_port,
5213                 (void *)&cmd_gro_enable_pid,
5214                 (void *)&cmd_gro_enable_keyword,
5215                 (void *)&cmd_gro_enable_onoff,
5216                 NULL,
5217         },
5218 };
5219
5220 /* *** DISPLAY GRO CONFIGURATION *** */
5221 struct cmd_gro_show_result {
5222         cmdline_fixed_string_t cmd_show;
5223         cmdline_fixed_string_t cmd_port;
5224         cmdline_fixed_string_t cmd_keyword;
5225         portid_t cmd_pid;
5226 };
5227
5228 static void
5229 cmd_gro_show_parsed(void *parsed_result,
5230                 __rte_unused struct cmdline *cl,
5231                 __rte_unused void *data)
5232 {
5233         struct cmd_gro_show_result *res;
5234
5235         res = parsed_result;
5236         if (!strcmp(res->cmd_keyword, "gro"))
5237                 show_gro(res->cmd_pid);
5238 }
5239
5240 cmdline_parse_token_string_t cmd_gro_show_show =
5241         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5242                         cmd_show, "show");
5243 cmdline_parse_token_string_t cmd_gro_show_port =
5244         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5245                         cmd_port, "port");
5246 cmdline_parse_token_num_t cmd_gro_show_pid =
5247         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5248                         cmd_pid, UINT16);
5249 cmdline_parse_token_string_t cmd_gro_show_keyword =
5250         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5251                         cmd_keyword, "gro");
5252
5253 cmdline_parse_inst_t cmd_gro_show = {
5254         .f = cmd_gro_show_parsed,
5255         .data = NULL,
5256         .help_str = "show port <port_id> gro",
5257         .tokens = {
5258                 (void *)&cmd_gro_show_show,
5259                 (void *)&cmd_gro_show_port,
5260                 (void *)&cmd_gro_show_pid,
5261                 (void *)&cmd_gro_show_keyword,
5262                 NULL,
5263         },
5264 };
5265
5266 /* *** SET FLUSH CYCLES FOR GRO *** */
5267 struct cmd_gro_flush_result {
5268         cmdline_fixed_string_t cmd_set;
5269         cmdline_fixed_string_t cmd_keyword;
5270         cmdline_fixed_string_t cmd_flush;
5271         uint8_t cmd_cycles;
5272 };
5273
5274 static void
5275 cmd_gro_flush_parsed(void *parsed_result,
5276                 __rte_unused struct cmdline *cl,
5277                 __rte_unused void *data)
5278 {
5279         struct cmd_gro_flush_result *res;
5280
5281         res = parsed_result;
5282         if ((!strcmp(res->cmd_keyword, "gro")) &&
5283                         (!strcmp(res->cmd_flush, "flush")))
5284                 setup_gro_flush_cycles(res->cmd_cycles);
5285 }
5286
5287 cmdline_parse_token_string_t cmd_gro_flush_set =
5288         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5289                         cmd_set, "set");
5290 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5291         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5292                         cmd_keyword, "gro");
5293 cmdline_parse_token_string_t cmd_gro_flush_flush =
5294         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5295                         cmd_flush, "flush");
5296 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5297         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5298                         cmd_cycles, UINT8);
5299
5300 cmdline_parse_inst_t cmd_gro_flush = {
5301         .f = cmd_gro_flush_parsed,
5302         .data = NULL,
5303         .help_str = "set gro flush <cycles>",
5304         .tokens = {
5305                 (void *)&cmd_gro_flush_set,
5306                 (void *)&cmd_gro_flush_keyword,
5307                 (void *)&cmd_gro_flush_flush,
5308                 (void *)&cmd_gro_flush_cycles,
5309                 NULL,
5310         },
5311 };
5312
5313 /* *** ENABLE/DISABLE GSO *** */
5314 struct cmd_gso_enable_result {
5315         cmdline_fixed_string_t cmd_set;
5316         cmdline_fixed_string_t cmd_port;
5317         cmdline_fixed_string_t cmd_keyword;
5318         cmdline_fixed_string_t cmd_mode;
5319         portid_t cmd_pid;
5320 };
5321
5322 static void
5323 cmd_gso_enable_parsed(void *parsed_result,
5324                 __rte_unused struct cmdline *cl,
5325                 __rte_unused void *data)
5326 {
5327         struct cmd_gso_enable_result *res;
5328
5329         res = parsed_result;
5330         if (!strcmp(res->cmd_keyword, "gso"))
5331                 setup_gso(res->cmd_mode, res->cmd_pid);
5332 }
5333
5334 cmdline_parse_token_string_t cmd_gso_enable_set =
5335         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5336                         cmd_set, "set");
5337 cmdline_parse_token_string_t cmd_gso_enable_port =
5338         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5339                         cmd_port, "port");
5340 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5341         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5342                         cmd_keyword, "gso");
5343 cmdline_parse_token_string_t cmd_gso_enable_mode =
5344         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5345                         cmd_mode, "on#off");
5346 cmdline_parse_token_num_t cmd_gso_enable_pid =
5347         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5348                         cmd_pid, UINT16);
5349
5350 cmdline_parse_inst_t cmd_gso_enable = {
5351         .f = cmd_gso_enable_parsed,
5352         .data = NULL,
5353         .help_str = "set port <port_id> gso on|off",
5354         .tokens = {
5355                 (void *)&cmd_gso_enable_set,
5356                 (void *)&cmd_gso_enable_port,
5357                 (void *)&cmd_gso_enable_pid,
5358                 (void *)&cmd_gso_enable_keyword,
5359                 (void *)&cmd_gso_enable_mode,
5360                 NULL,
5361         },
5362 };
5363
5364 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5365 struct cmd_gso_size_result {
5366         cmdline_fixed_string_t cmd_set;
5367         cmdline_fixed_string_t cmd_keyword;
5368         cmdline_fixed_string_t cmd_segsz;
5369         uint16_t cmd_size;
5370 };
5371
5372 static void
5373 cmd_gso_size_parsed(void *parsed_result,
5374                        __rte_unused struct cmdline *cl,
5375                        __rte_unused void *data)
5376 {
5377         struct cmd_gso_size_result *res = parsed_result;
5378
5379         if (test_done == 0) {
5380                 printf("Before setting GSO segsz, please first"
5381                                 " stop forwarding\n");
5382                 return;
5383         }
5384
5385         if (!strcmp(res->cmd_keyword, "gso") &&
5386                         !strcmp(res->cmd_segsz, "segsz")) {
5387                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5388                         printf("gso_size should be larger than %zu."
5389                                         " Please input a legal value\n",
5390                                         RTE_GSO_SEG_SIZE_MIN);
5391                 else
5392                         gso_max_segment_size = res->cmd_size;
5393         }
5394 }
5395
5396 cmdline_parse_token_string_t cmd_gso_size_set =
5397         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5398                                 cmd_set, "set");
5399 cmdline_parse_token_string_t cmd_gso_size_keyword =
5400         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5401                                 cmd_keyword, "gso");
5402 cmdline_parse_token_string_t cmd_gso_size_segsz =
5403         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5404                                 cmd_segsz, "segsz");
5405 cmdline_parse_token_num_t cmd_gso_size_size =
5406         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5407                                 cmd_size, UINT16);
5408
5409 cmdline_parse_inst_t cmd_gso_size = {
5410         .f = cmd_gso_size_parsed,
5411         .data = NULL,
5412         .help_str = "set gso segsz <length>",
5413         .tokens = {
5414                 (void *)&cmd_gso_size_set,
5415                 (void *)&cmd_gso_size_keyword,
5416                 (void *)&cmd_gso_size_segsz,
5417                 (void *)&cmd_gso_size_size,
5418                 NULL,
5419         },
5420 };
5421
5422 /* *** SHOW GSO CONFIGURATION *** */
5423 struct cmd_gso_show_result {
5424         cmdline_fixed_string_t cmd_show;
5425         cmdline_fixed_string_t cmd_port;
5426         cmdline_fixed_string_t cmd_keyword;
5427         portid_t cmd_pid;
5428 };
5429
5430 static void
5431 cmd_gso_show_parsed(void *parsed_result,
5432                        __rte_unused struct cmdline *cl,
5433                        __rte_unused void *data)
5434 {
5435         struct cmd_gso_show_result *res = parsed_result;
5436
5437         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5438                 printf("invalid port id %u\n", res->cmd_pid);
5439                 return;
5440         }
5441         if (!strcmp(res->cmd_keyword, "gso")) {
5442                 if (gso_ports[res->cmd_pid].enable) {
5443                         printf("Max GSO'd packet size: %uB\n"
5444                                         "Supported GSO types: TCP/IPv4, "
5445                                         "UDP/IPv4, VxLAN with inner "
5446                                         "TCP/IPv4 packet, GRE with inner "
5447                                         "TCP/IPv4 packet\n",
5448                                         gso_max_segment_size);
5449                 } else
5450                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5451         }
5452 }
5453
5454 cmdline_parse_token_string_t cmd_gso_show_show =
5455 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5456                 cmd_show, "show");
5457 cmdline_parse_token_string_t cmd_gso_show_port =
5458 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5459                 cmd_port, "port");
5460 cmdline_parse_token_string_t cmd_gso_show_keyword =
5461         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5462                                 cmd_keyword, "gso");
5463 cmdline_parse_token_num_t cmd_gso_show_pid =
5464         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5465                                 cmd_pid, UINT16);
5466
5467 cmdline_parse_inst_t cmd_gso_show = {
5468         .f = cmd_gso_show_parsed,
5469         .data = NULL,
5470         .help_str = "show port <port_id> gso",
5471         .tokens = {
5472                 (void *)&cmd_gso_show_show,
5473                 (void *)&cmd_gso_show_port,
5474                 (void *)&cmd_gso_show_pid,
5475                 (void *)&cmd_gso_show_keyword,
5476                 NULL,
5477         },
5478 };
5479
5480 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5481 struct cmd_set_flush_rx {
5482         cmdline_fixed_string_t set;
5483         cmdline_fixed_string_t flush_rx;
5484         cmdline_fixed_string_t mode;
5485 };
5486
5487 static void
5488 cmd_set_flush_rx_parsed(void *parsed_result,
5489                 __rte_unused struct cmdline *cl,
5490                 __rte_unused void *data)
5491 {
5492         struct cmd_set_flush_rx *res = parsed_result;
5493         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5494 }
5495
5496 cmdline_parse_token_string_t cmd_setflushrx_set =
5497         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5498                         set, "set");
5499 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5500         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5501                         flush_rx, "flush_rx");
5502 cmdline_parse_token_string_t cmd_setflushrx_mode =
5503         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5504                         mode, "on#off");
5505
5506
5507 cmdline_parse_inst_t cmd_set_flush_rx = {
5508         .f = cmd_set_flush_rx_parsed,
5509         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5510         .data = NULL,
5511         .tokens = {
5512                 (void *)&cmd_setflushrx_set,
5513                 (void *)&cmd_setflushrx_flush_rx,
5514                 (void *)&cmd_setflushrx_mode,
5515                 NULL,
5516         },
5517 };
5518
5519 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5520 struct cmd_set_link_check {
5521         cmdline_fixed_string_t set;
5522         cmdline_fixed_string_t link_check;
5523         cmdline_fixed_string_t mode;
5524 };
5525
5526 static void
5527 cmd_set_link_check_parsed(void *parsed_result,
5528                 __rte_unused struct cmdline *cl,
5529                 __rte_unused void *data)
5530 {
5531         struct cmd_set_link_check *res = parsed_result;
5532         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5533 }
5534
5535 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5536         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5537                         set, "set");
5538 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5539         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5540                         link_check, "link_check");
5541 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5542         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5543                         mode, "on#off");
5544
5545
5546 cmdline_parse_inst_t cmd_set_link_check = {
5547         .f = cmd_set_link_check_parsed,
5548         .help_str = "set link_check on|off: Enable/Disable link status check "
5549                     "when starting/stopping a port",
5550         .data = NULL,
5551         .tokens = {
5552                 (void *)&cmd_setlinkcheck_set,
5553                 (void *)&cmd_setlinkcheck_link_check,
5554                 (void *)&cmd_setlinkcheck_mode,
5555                 NULL,
5556         },
5557 };
5558
5559 /* *** SET NIC BYPASS MODE *** */
5560 struct cmd_set_bypass_mode_result {
5561         cmdline_fixed_string_t set;
5562         cmdline_fixed_string_t bypass;
5563         cmdline_fixed_string_t mode;
5564         cmdline_fixed_string_t value;
5565         portid_t port_id;
5566 };
5567
5568 static void
5569 cmd_set_bypass_mode_parsed(void *parsed_result,
5570                 __rte_unused struct cmdline *cl,
5571                 __rte_unused void *data)
5572 {
5573         struct cmd_set_bypass_mode_result *res = parsed_result;
5574         portid_t port_id = res->port_id;
5575         int32_t rc = -EINVAL;
5576
5577 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5578         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5579
5580         if (!strcmp(res->value, "bypass"))
5581                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5582         else if (!strcmp(res->value, "isolate"))
5583                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5584         else
5585                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5586
5587         /* Set the bypass mode for the relevant port. */
5588         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5589 #endif
5590         if (rc != 0)
5591                 printf("\t Failed to set bypass mode for port = %d.\n", 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, 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                         printf("Failed to set timeout value %u "
5679                         "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                 printf("\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, 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                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5834                 return;
5835         }
5836         else {
5837                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5838                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5839
5840                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5841         }
5842
5843         /* Display the bypass timeout.*/
5844         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5845                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5846
5847         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5848
5849         /* Display the bypass events and associated modes. */
5850         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5851
5852                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5853                         printf("\tFailed to get bypass mode for event = %s\n",
5854                                 events[i]);
5855                 } else {
5856                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5857                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5858
5859                         printf("\tbypass event: %-16s = %s\n", events[i],
5860                                 modes[event_mode]);
5861                 }
5862         }
5863 #endif
5864         if (rc != 0)
5865                 printf("\tFailed to get bypass configuration for port = %d\n",
5866                        port_id);
5867 }
5868
5869 cmdline_parse_token_string_t cmd_showbypass_config_show =
5870         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5871                         show, "show");
5872 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5873         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5874                         bypass, "bypass");
5875 cmdline_parse_token_string_t cmd_showbypass_config_config =
5876         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5877                         config, "config");
5878 cmdline_parse_token_num_t cmd_showbypass_config_port =
5879         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5880                                 port_id, UINT16);
5881
5882 cmdline_parse_inst_t cmd_show_bypass_config = {
5883         .f = cmd_show_bypass_config_parsed,
5884         .help_str = "show bypass config <port_id>: "
5885                     "Show the NIC bypass config for port_id",
5886         .data = NULL,
5887         .tokens = {
5888                 (void *)&cmd_showbypass_config_show,
5889                 (void *)&cmd_showbypass_config_bypass,
5890                 (void *)&cmd_showbypass_config_config,
5891                 (void *)&cmd_showbypass_config_port,
5892                 NULL,
5893         },
5894 };
5895
5896 #ifdef RTE_NET_BOND
5897 /* *** SET BONDING MODE *** */
5898 struct cmd_set_bonding_mode_result {
5899         cmdline_fixed_string_t set;
5900         cmdline_fixed_string_t bonding;
5901         cmdline_fixed_string_t mode;
5902         uint8_t value;
5903         portid_t port_id;
5904 };
5905
5906 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5907                 __rte_unused  struct cmdline *cl,
5908                 __rte_unused void *data)
5909 {
5910         struct cmd_set_bonding_mode_result *res = parsed_result;
5911         portid_t port_id = res->port_id;
5912
5913         /* Set the bonding mode for the relevant port. */
5914         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5915                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5916 }
5917
5918 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5919 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5920                 set, "set");
5921 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5922 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5923                 bonding, "bonding");
5924 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5925 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5926                 mode, "mode");
5927 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5928 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5929                 value, UINT8);
5930 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5931 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5932                 port_id, UINT16);
5933
5934 cmdline_parse_inst_t cmd_set_bonding_mode = {
5935                 .f = cmd_set_bonding_mode_parsed,
5936                 .help_str = "set bonding mode <mode_value> <port_id>: "
5937                         "Set the bonding mode for port_id",
5938                 .data = NULL,
5939                 .tokens = {
5940                                 (void *) &cmd_setbonding_mode_set,
5941                                 (void *) &cmd_setbonding_mode_bonding,
5942                                 (void *) &cmd_setbonding_mode_mode,
5943                                 (void *) &cmd_setbonding_mode_value,
5944                                 (void *) &cmd_setbonding_mode_port,
5945                                 NULL
5946                 }
5947 };
5948
5949 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5950 struct cmd_set_bonding_lacp_dedicated_queues_result {
5951         cmdline_fixed_string_t set;
5952         cmdline_fixed_string_t bonding;
5953         cmdline_fixed_string_t lacp;
5954         cmdline_fixed_string_t dedicated_queues;
5955         portid_t port_id;
5956         cmdline_fixed_string_t mode;
5957 };
5958
5959 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5960                 __rte_unused  struct cmdline *cl,
5961                 __rte_unused void *data)
5962 {
5963         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5964         portid_t port_id = res->port_id;
5965         struct rte_port *port;
5966
5967         port = &ports[port_id];
5968
5969         /** Check if the port is not started **/
5970         if (port->port_status != RTE_PORT_STOPPED) {
5971                 printf("Please stop port %d first\n", port_id);
5972                 return;
5973         }
5974
5975         if (!strcmp(res->mode, "enable")) {
5976                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5977                         printf("Dedicate queues for LACP control packets"
5978                                         " enabled\n");
5979                 else
5980                         printf("Enabling dedicate queues for LACP control "
5981                                         "packets on port %d failed\n", port_id);
5982         } else if (!strcmp(res->mode, "disable")) {
5983                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5984                         printf("Dedicated queues for LACP control packets "
5985                                         "disabled\n");
5986                 else
5987                         printf("Disabling dedicated queues for LACP control "
5988                                         "traffic on port %d failed\n", port_id);
5989         }
5990 }
5991
5992 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5993 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5994                 set, "set");
5995 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5996 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5997                 bonding, "bonding");
5998 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5999 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6000                 lacp, "lacp");
6001 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
6002 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6003                 dedicated_queues, "dedicated_queues");
6004 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6005 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6006                 port_id, UINT16);
6007 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6008 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6009                 mode, "enable#disable");
6010
6011 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6012                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6013                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6014                         "enable|disable: "
6015                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6016                 .data = NULL,
6017                 .tokens = {
6018                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6019                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6020                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6021                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6022                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6023                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6024                         NULL
6025                 }
6026 };
6027
6028 /* *** SET BALANCE XMIT POLICY *** */
6029 struct cmd_set_bonding_balance_xmit_policy_result {
6030         cmdline_fixed_string_t set;
6031         cmdline_fixed_string_t bonding;
6032         cmdline_fixed_string_t balance_xmit_policy;
6033         portid_t port_id;
6034         cmdline_fixed_string_t policy;
6035 };
6036
6037 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6038                 __rte_unused  struct cmdline *cl,
6039                 __rte_unused void *data)
6040 {
6041         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6042         portid_t port_id = res->port_id;
6043         uint8_t policy;
6044
6045         if (!strcmp(res->policy, "l2")) {
6046                 policy = BALANCE_XMIT_POLICY_LAYER2;
6047         } else if (!strcmp(res->policy, "l23")) {
6048                 policy = BALANCE_XMIT_POLICY_LAYER23;
6049         } else if (!strcmp(res->policy, "l34")) {
6050                 policy = BALANCE_XMIT_POLICY_LAYER34;
6051         } else {
6052                 printf("\t Invalid xmit policy selection");
6053                 return;
6054         }
6055
6056         /* Set the bonding mode for the relevant port. */
6057         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6058                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
6059                                 port_id);
6060         }
6061 }
6062
6063 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6064 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6065                 set, "set");
6066 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6067 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6068                 bonding, "bonding");
6069 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6070 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6071                 balance_xmit_policy, "balance_xmit_policy");
6072 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6073 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6074                 port_id, UINT16);
6075 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6076 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6077                 policy, "l2#l23#l34");
6078
6079 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6080                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6081                 .help_str = "set bonding balance_xmit_policy <port_id> "
6082                         "l2|l23|l34: "
6083                         "Set the bonding balance_xmit_policy for port_id",
6084                 .data = NULL,
6085                 .tokens = {
6086                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6087                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6088                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6089                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6090                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6091                                 NULL
6092                 }
6093 };
6094
6095 /* *** SHOW NIC BONDING CONFIGURATION *** */
6096 struct cmd_show_bonding_config_result {
6097         cmdline_fixed_string_t show;
6098         cmdline_fixed_string_t bonding;
6099         cmdline_fixed_string_t config;
6100         portid_t port_id;
6101 };
6102
6103 static void cmd_show_bonding_config_parsed(void *parsed_result,
6104                 __rte_unused  struct cmdline *cl,
6105                 __rte_unused void *data)
6106 {
6107         struct cmd_show_bonding_config_result *res = parsed_result;
6108         int bonding_mode, agg_mode;
6109         portid_t slaves[RTE_MAX_ETHPORTS];
6110         int num_slaves, num_active_slaves;
6111         int primary_id;
6112         int i;
6113         portid_t port_id = res->port_id;
6114
6115         /* Display the bonding mode.*/
6116         bonding_mode = rte_eth_bond_mode_get(port_id);
6117         if (bonding_mode < 0) {
6118                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
6119                 return;
6120         } else
6121                 printf("\tBonding mode: %d\n", bonding_mode);
6122
6123         if (bonding_mode == BONDING_MODE_BALANCE) {
6124                 int balance_xmit_policy;
6125
6126                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6127                 if (balance_xmit_policy < 0) {
6128                         printf("\tFailed to get balance xmit policy for port = %d\n",
6129                                         port_id);
6130                         return;
6131                 } else {
6132                         printf("\tBalance Xmit Policy: ");
6133
6134                         switch (balance_xmit_policy) {
6135                         case BALANCE_XMIT_POLICY_LAYER2:
6136                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6137                                 break;
6138                         case BALANCE_XMIT_POLICY_LAYER23:
6139                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6140                                 break;
6141                         case BALANCE_XMIT_POLICY_LAYER34:
6142                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6143                                 break;
6144                         }
6145                         printf("\n");
6146                 }
6147         }
6148
6149         if (bonding_mode == BONDING_MODE_8023AD) {
6150                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6151                 printf("\tIEEE802.3AD Aggregator Mode: ");
6152                 switch (agg_mode) {
6153                 case AGG_BANDWIDTH:
6154                         printf("bandwidth");
6155                         break;
6156                 case AGG_STABLE:
6157                         printf("stable");
6158                         break;
6159                 case AGG_COUNT:
6160                         printf("count");
6161                         break;
6162                 }
6163                 printf("\n");
6164         }
6165
6166         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6167
6168         if (num_slaves < 0) {
6169                 printf("\tFailed to get slave list for port = %d\n", port_id);
6170                 return;
6171         }
6172         if (num_slaves > 0) {
6173                 printf("\tSlaves (%d): [", num_slaves);
6174                 for (i = 0; i < num_slaves - 1; i++)
6175                         printf("%d ", slaves[i]);
6176
6177                 printf("%d]\n", slaves[num_slaves - 1]);
6178         } else {
6179                 printf("\tSlaves: []\n");
6180
6181         }
6182
6183         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6184                         RTE_MAX_ETHPORTS);
6185
6186         if (num_active_slaves < 0) {
6187                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6188                 return;
6189         }
6190         if (num_active_slaves > 0) {
6191                 printf("\tActive Slaves (%d): [", num_active_slaves);
6192                 for (i = 0; i < num_active_slaves - 1; i++)
6193                         printf("%d ", slaves[i]);
6194
6195                 printf("%d]\n", slaves[num_active_slaves - 1]);
6196
6197         } else {
6198                 printf("\tActive Slaves: []\n");
6199
6200         }
6201
6202         primary_id = rte_eth_bond_primary_get(port_id);
6203         if (primary_id < 0) {
6204                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6205                 return;
6206         } else
6207                 printf("\tPrimary: [%d]\n", primary_id);
6208
6209 }
6210
6211 cmdline_parse_token_string_t cmd_showbonding_config_show =
6212 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6213                 show, "show");
6214 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6215 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6216                 bonding, "bonding");
6217 cmdline_parse_token_string_t cmd_showbonding_config_config =
6218 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6219                 config, "config");
6220 cmdline_parse_token_num_t cmd_showbonding_config_port =
6221 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6222                 port_id, UINT16);
6223
6224 cmdline_parse_inst_t cmd_show_bonding_config = {
6225                 .f = cmd_show_bonding_config_parsed,
6226                 .help_str = "show bonding config <port_id>: "
6227                         "Show the bonding config for port_id",
6228                 .data = NULL,
6229                 .tokens = {
6230                                 (void *)&cmd_showbonding_config_show,
6231                                 (void *)&cmd_showbonding_config_bonding,
6232                                 (void *)&cmd_showbonding_config_config,
6233                                 (void *)&cmd_showbonding_config_port,
6234                                 NULL
6235                 }
6236 };
6237
6238 /* *** SET BONDING PRIMARY *** */
6239 struct cmd_set_bonding_primary_result {
6240         cmdline_fixed_string_t set;
6241         cmdline_fixed_string_t bonding;
6242         cmdline_fixed_string_t primary;
6243         portid_t slave_id;
6244         portid_t port_id;
6245 };
6246
6247 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6248                 __rte_unused  struct cmdline *cl,
6249                 __rte_unused void *data)
6250 {
6251         struct cmd_set_bonding_primary_result *res = parsed_result;
6252         portid_t master_port_id = res->port_id;
6253         portid_t slave_port_id = res->slave_id;
6254
6255         /* Set the primary slave for a bonded device. */
6256         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6257                 printf("\t Failed to set primary slave for port = %d.\n",
6258                                 master_port_id);
6259                 return;
6260         }
6261         init_port_config();
6262 }
6263
6264 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6265 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6266                 set, "set");
6267 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6268 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6269                 bonding, "bonding");
6270 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6271 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6272                 primary, "primary");
6273 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6274 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6275                 slave_id, UINT16);
6276 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6277 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6278                 port_id, UINT16);
6279
6280 cmdline_parse_inst_t cmd_set_bonding_primary = {
6281                 .f = cmd_set_bonding_primary_parsed,
6282                 .help_str = "set bonding primary <slave_id> <port_id>: "
6283                         "Set the primary slave for port_id",
6284                 .data = NULL,
6285                 .tokens = {
6286                                 (void *)&cmd_setbonding_primary_set,
6287                                 (void *)&cmd_setbonding_primary_bonding,
6288                                 (void *)&cmd_setbonding_primary_primary,
6289                                 (void *)&cmd_setbonding_primary_slave,
6290                                 (void *)&cmd_setbonding_primary_port,
6291                                 NULL
6292                 }
6293 };
6294
6295 /* *** ADD SLAVE *** */
6296 struct cmd_add_bonding_slave_result {
6297         cmdline_fixed_string_t add;
6298         cmdline_fixed_string_t bonding;
6299         cmdline_fixed_string_t slave;
6300         portid_t slave_id;
6301         portid_t port_id;
6302 };
6303
6304 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6305                 __rte_unused  struct cmdline *cl,
6306                 __rte_unused void *data)
6307 {
6308         struct cmd_add_bonding_slave_result *res = parsed_result;
6309         portid_t master_port_id = res->port_id;
6310         portid_t slave_port_id = res->slave_id;
6311
6312         /* add the slave for a bonded device. */
6313         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6314                 printf("\t Failed to add slave %d to master port = %d.\n",
6315                                 slave_port_id, master_port_id);
6316                 return;
6317         }
6318         init_port_config();
6319         set_port_slave_flag(slave_port_id);
6320 }
6321
6322 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6323 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6324                 add, "add");
6325 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6326 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6327                 bonding, "bonding");
6328 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6329 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6330                 slave, "slave");
6331 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6332 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6333                 slave_id, UINT16);
6334 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6335 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6336                 port_id, UINT16);
6337
6338 cmdline_parse_inst_t cmd_add_bonding_slave = {
6339                 .f = cmd_add_bonding_slave_parsed,
6340                 .help_str = "add bonding slave <slave_id> <port_id>: "
6341                         "Add a slave device to a bonded device",
6342                 .data = NULL,
6343                 .tokens = {
6344                                 (void *)&cmd_addbonding_slave_add,
6345                                 (void *)&cmd_addbonding_slave_bonding,
6346                                 (void *)&cmd_addbonding_slave_slave,
6347                                 (void *)&cmd_addbonding_slave_slaveid,
6348                                 (void *)&cmd_addbonding_slave_port,
6349                                 NULL
6350                 }
6351 };
6352
6353 /* *** REMOVE SLAVE *** */
6354 struct cmd_remove_bonding_slave_result {
6355         cmdline_fixed_string_t remove;
6356         cmdline_fixed_string_t bonding;
6357         cmdline_fixed_string_t slave;
6358         portid_t slave_id;
6359         portid_t port_id;
6360 };
6361
6362 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6363                 __rte_unused  struct cmdline *cl,
6364                 __rte_unused void *data)
6365 {
6366         struct cmd_remove_bonding_slave_result *res = parsed_result;
6367         portid_t master_port_id = res->port_id;
6368         portid_t slave_port_id = res->slave_id;
6369
6370         /* remove the slave from a bonded device. */
6371         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6372                 printf("\t Failed to remove slave %d from master port = %d.\n",
6373                                 slave_port_id, master_port_id);
6374                 return;
6375         }
6376         init_port_config();
6377         clear_port_slave_flag(slave_port_id);
6378 }
6379
6380 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6381                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6382                                 remove, "remove");
6383 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6384                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6385                                 bonding, "bonding");
6386 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6387                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6388                                 slave, "slave");
6389 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6390                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6391                                 slave_id, UINT16);
6392 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6393                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6394                                 port_id, UINT16);
6395
6396 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6397                 .f = cmd_remove_bonding_slave_parsed,
6398                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6399                         "Remove a slave device from a bonded device",
6400                 .data = NULL,
6401                 .tokens = {
6402                                 (void *)&cmd_removebonding_slave_remove,
6403                                 (void *)&cmd_removebonding_slave_bonding,
6404                                 (void *)&cmd_removebonding_slave_slave,
6405                                 (void *)&cmd_removebonding_slave_slaveid,
6406                                 (void *)&cmd_removebonding_slave_port,
6407                                 NULL
6408                 }
6409 };
6410
6411 /* *** CREATE BONDED DEVICE *** */
6412 struct cmd_create_bonded_device_result {
6413         cmdline_fixed_string_t create;
6414         cmdline_fixed_string_t bonded;
6415         cmdline_fixed_string_t device;
6416         uint8_t mode;
6417         uint8_t socket;
6418 };
6419
6420 static int bond_dev_num = 0;
6421
6422 static void cmd_create_bonded_device_parsed(void *parsed_result,
6423                 __rte_unused  struct cmdline *cl,
6424                 __rte_unused void *data)
6425 {
6426         struct cmd_create_bonded_device_result *res = parsed_result;
6427         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6428         int port_id;
6429         int ret;
6430
6431         if (test_done == 0) {
6432                 printf("Please stop forwarding first\n");
6433                 return;
6434         }
6435
6436         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6437                         bond_dev_num++);
6438
6439         /* Create a new bonded device. */
6440         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6441         if (port_id < 0) {
6442                 printf("\t Failed to create bonded device.\n");
6443                 return;
6444         } else {
6445                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6446                                 port_id);
6447
6448                 /* Update number of ports */
6449                 nb_ports = rte_eth_dev_count_avail();
6450                 reconfig(port_id, res->socket);
6451                 ret = rte_eth_promiscuous_enable(port_id);
6452                 if (ret != 0)
6453                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6454                                 port_id, rte_strerror(-ret));
6455
6456                 ports[port_id].need_setup = 0;
6457                 ports[port_id].port_status = RTE_PORT_STOPPED;
6458         }
6459
6460 }
6461
6462 cmdline_parse_token_string_t cmd_createbonded_device_create =
6463                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6464                                 create, "create");
6465 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6466                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6467                                 bonded, "bonded");
6468 cmdline_parse_token_string_t cmd_createbonded_device_device =
6469                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6470                                 device, "device");
6471 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6472                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6473                                 mode, UINT8);
6474 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6475                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6476                                 socket, UINT8);
6477
6478 cmdline_parse_inst_t cmd_create_bonded_device = {
6479                 .f = cmd_create_bonded_device_parsed,
6480                 .help_str = "create bonded device <mode> <socket>: "
6481                         "Create a new bonded device with specific bonding mode and socket",
6482                 .data = NULL,
6483                 .tokens = {
6484                                 (void *)&cmd_createbonded_device_create,
6485                                 (void *)&cmd_createbonded_device_bonded,
6486                                 (void *)&cmd_createbonded_device_device,
6487                                 (void *)&cmd_createbonded_device_mode,
6488                                 (void *)&cmd_createbonded_device_socket,
6489                                 NULL
6490                 }
6491 };
6492
6493 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6494 struct cmd_set_bond_mac_addr_result {
6495         cmdline_fixed_string_t set;
6496         cmdline_fixed_string_t bonding;
6497         cmdline_fixed_string_t mac_addr;
6498         uint16_t port_num;
6499         struct rte_ether_addr address;
6500 };
6501
6502 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6503                 __rte_unused  struct cmdline *cl,
6504                 __rte_unused void *data)
6505 {
6506         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6507         int ret;
6508
6509         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6510                 return;
6511
6512         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6513
6514         /* check the return value and print it if is < 0 */
6515         if (ret < 0)
6516                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6517 }
6518
6519 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6520                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6521 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6522                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6523                                 "bonding");
6524 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6525                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6526                                 "mac_addr");
6527 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6528                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6529                                 port_num, UINT16);
6530 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6531                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6532
6533 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6534                 .f = cmd_set_bond_mac_addr_parsed,
6535                 .data = (void *) 0,
6536                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6537                 .tokens = {
6538                                 (void *)&cmd_set_bond_mac_addr_set,
6539                                 (void *)&cmd_set_bond_mac_addr_bonding,
6540                                 (void *)&cmd_set_bond_mac_addr_mac,
6541                                 (void *)&cmd_set_bond_mac_addr_portnum,
6542                                 (void *)&cmd_set_bond_mac_addr_addr,
6543                                 NULL
6544                 }
6545 };
6546
6547
6548 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6549 struct cmd_set_bond_mon_period_result {
6550         cmdline_fixed_string_t set;
6551         cmdline_fixed_string_t bonding;
6552         cmdline_fixed_string_t mon_period;
6553         uint16_t port_num;
6554         uint32_t period_ms;
6555 };
6556
6557 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6558                 __rte_unused  struct cmdline *cl,
6559                 __rte_unused void *data)
6560 {
6561         struct cmd_set_bond_mon_period_result *res = parsed_result;
6562         int ret;
6563
6564         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6565
6566         /* check the return value and print it if is < 0 */
6567         if (ret < 0)
6568                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6569 }
6570
6571 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6572                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6573                                 set, "set");
6574 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6575                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6576                                 bonding, "bonding");
6577 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6578                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6579                                 mon_period,     "mon_period");
6580 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6581                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6582                                 port_num, UINT16);
6583 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6584                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6585                                 period_ms, UINT32);
6586
6587 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6588                 .f = cmd_set_bond_mon_period_parsed,
6589                 .data = (void *) 0,
6590                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6591                 .tokens = {
6592                                 (void *)&cmd_set_bond_mon_period_set,
6593                                 (void *)&cmd_set_bond_mon_period_bonding,
6594                                 (void *)&cmd_set_bond_mon_period_mon_period,
6595                                 (void *)&cmd_set_bond_mon_period_portnum,
6596                                 (void *)&cmd_set_bond_mon_period_period_ms,
6597                                 NULL
6598                 }
6599 };
6600
6601
6602
6603 struct cmd_set_bonding_agg_mode_policy_result {
6604         cmdline_fixed_string_t set;
6605         cmdline_fixed_string_t bonding;
6606         cmdline_fixed_string_t agg_mode;
6607         uint16_t port_num;
6608         cmdline_fixed_string_t policy;
6609 };
6610
6611
6612 static void
6613 cmd_set_bonding_agg_mode(void *parsed_result,
6614                 __rte_unused struct cmdline *cl,
6615                 __rte_unused void *data)
6616 {
6617         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6618         uint8_t policy = AGG_BANDWIDTH;
6619
6620         if (!strcmp(res->policy, "bandwidth"))
6621                 policy = AGG_BANDWIDTH;
6622         else if (!strcmp(res->policy, "stable"))
6623                 policy = AGG_STABLE;
6624         else if (!strcmp(res->policy, "count"))
6625                 policy = AGG_COUNT;
6626
6627         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6628 }
6629
6630
6631 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6632         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6633                                 set, "set");
6634 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6635         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6636                                 bonding, "bonding");
6637
6638 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6639         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6640                                 agg_mode, "agg_mode");
6641
6642 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6643         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6644                                 port_num, UINT16);
6645
6646 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6647         TOKEN_STRING_INITIALIZER(
6648                         struct cmd_set_bonding_balance_xmit_policy_result,
6649                 policy, "stable#bandwidth#count");
6650
6651 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6652         .f = cmd_set_bonding_agg_mode,
6653         .data = (void *) 0,
6654         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6655         .tokens = {
6656                         (void *)&cmd_set_bonding_agg_mode_set,
6657                         (void *)&cmd_set_bonding_agg_mode_bonding,
6658                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6659                         (void *)&cmd_set_bonding_agg_mode_portnum,
6660                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6661                         NULL
6662                 }
6663 };
6664
6665
6666 #endif /* RTE_NET_BOND */
6667
6668 /* *** SET FORWARDING MODE *** */
6669 struct cmd_set_fwd_mode_result {
6670         cmdline_fixed_string_t set;
6671         cmdline_fixed_string_t fwd;
6672         cmdline_fixed_string_t mode;
6673 };
6674
6675 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6676                                     __rte_unused struct cmdline *cl,
6677                                     __rte_unused void *data)
6678 {
6679         struct cmd_set_fwd_mode_result *res = parsed_result;
6680
6681         retry_enabled = 0;
6682         set_pkt_forwarding_mode(res->mode);
6683 }
6684
6685 cmdline_parse_token_string_t cmd_setfwd_set =
6686         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6687 cmdline_parse_token_string_t cmd_setfwd_fwd =
6688         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6689 cmdline_parse_token_string_t cmd_setfwd_mode =
6690         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6691                 "" /* defined at init */);
6692
6693 cmdline_parse_inst_t cmd_set_fwd_mode = {
6694         .f = cmd_set_fwd_mode_parsed,
6695         .data = NULL,
6696         .help_str = NULL, /* defined at init */
6697         .tokens = {
6698                 (void *)&cmd_setfwd_set,
6699                 (void *)&cmd_setfwd_fwd,
6700                 (void *)&cmd_setfwd_mode,
6701                 NULL,
6702         },
6703 };
6704
6705 static void cmd_set_fwd_mode_init(void)
6706 {
6707         char *modes, *c;
6708         static char token[128];
6709         static char help[256];
6710         cmdline_parse_token_string_t *token_struct;
6711
6712         modes = list_pkt_forwarding_modes();
6713         snprintf(help, sizeof(help), "set fwd %s: "
6714                 "Set packet forwarding mode", modes);
6715         cmd_set_fwd_mode.help_str = help;
6716
6717         /* string token separator is # */
6718         for (c = token; *modes != '\0'; modes++)
6719                 if (*modes == '|')
6720                         *c++ = '#';
6721                 else
6722                         *c++ = *modes;
6723         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6724         token_struct->string_data.str = token;
6725 }
6726
6727 /* *** SET RETRY FORWARDING MODE *** */
6728 struct cmd_set_fwd_retry_mode_result {
6729         cmdline_fixed_string_t set;
6730         cmdline_fixed_string_t fwd;
6731         cmdline_fixed_string_t mode;
6732         cmdline_fixed_string_t retry;
6733 };
6734
6735 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6736                             __rte_unused struct cmdline *cl,
6737                             __rte_unused void *data)
6738 {
6739         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6740
6741         retry_enabled = 1;
6742         set_pkt_forwarding_mode(res->mode);
6743 }
6744
6745 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6746         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6747                         set, "set");
6748 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6749         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6750                         fwd, "fwd");
6751 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6752         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6753                         mode,
6754                 "" /* defined at init */);
6755 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6756         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6757                         retry, "retry");
6758
6759 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6760         .f = cmd_set_fwd_retry_mode_parsed,
6761         .data = NULL,
6762         .help_str = NULL, /* defined at init */
6763         .tokens = {
6764                 (void *)&cmd_setfwd_retry_set,
6765                 (void *)&cmd_setfwd_retry_fwd,
6766                 (void *)&cmd_setfwd_retry_mode,
6767                 (void *)&cmd_setfwd_retry_retry,
6768                 NULL,
6769         },
6770 };
6771
6772 static void cmd_set_fwd_retry_mode_init(void)
6773 {
6774         char *modes, *c;
6775         static char token[128];
6776         static char help[256];
6777         cmdline_parse_token_string_t *token_struct;
6778
6779         modes = list_pkt_forwarding_retry_modes();
6780         snprintf(help, sizeof(help), "set fwd %s retry: "
6781                 "Set packet forwarding mode with retry", modes);
6782         cmd_set_fwd_retry_mode.help_str = help;
6783
6784         /* string token separator is # */
6785         for (c = token; *modes != '\0'; modes++)
6786                 if (*modes == '|')
6787                         *c++ = '#';
6788                 else
6789                         *c++ = *modes;
6790         token_struct = (cmdline_parse_token_string_t *)
6791                 cmd_set_fwd_retry_mode.tokens[2];
6792         token_struct->string_data.str = token;
6793 }
6794
6795 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6796 struct cmd_set_burst_tx_retry_result {
6797         cmdline_fixed_string_t set;
6798         cmdline_fixed_string_t burst;
6799         cmdline_fixed_string_t tx;
6800         cmdline_fixed_string_t delay;
6801         uint32_t time;
6802         cmdline_fixed_string_t retry;
6803         uint32_t retry_num;
6804 };
6805
6806 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6807                                         __rte_unused struct cmdline *cl,
6808                                         __rte_unused void *data)
6809 {
6810         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6811
6812         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6813                 && !strcmp(res->tx, "tx")) {
6814                 if (!strcmp(res->delay, "delay"))
6815                         burst_tx_delay_time = res->time;
6816                 if (!strcmp(res->retry, "retry"))
6817                         burst_tx_retry_num = res->retry_num;
6818         }
6819
6820 }
6821
6822 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6823         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6824 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6825         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6826                                  "burst");
6827 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6828         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6829 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6830         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6831 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6832         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6833 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6834         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6835 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6836         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6837
6838 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6839         .f = cmd_set_burst_tx_retry_parsed,
6840         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6841         .tokens = {
6842                 (void *)&cmd_set_burst_tx_retry_set,
6843                 (void *)&cmd_set_burst_tx_retry_burst,
6844                 (void *)&cmd_set_burst_tx_retry_tx,
6845                 (void *)&cmd_set_burst_tx_retry_delay,
6846                 (void *)&cmd_set_burst_tx_retry_time,
6847                 (void *)&cmd_set_burst_tx_retry_retry,
6848                 (void *)&cmd_set_burst_tx_retry_retry_num,
6849                 NULL,
6850         },
6851 };
6852
6853 /* *** SET PROMISC MODE *** */
6854 struct cmd_set_promisc_mode_result {
6855         cmdline_fixed_string_t set;
6856         cmdline_fixed_string_t promisc;
6857         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6858         uint16_t port_num;               /* valid if "allports" argument == 0 */
6859         cmdline_fixed_string_t mode;
6860 };
6861
6862 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6863                                         __rte_unused struct cmdline *cl,
6864                                         void *allports)
6865 {
6866         struct cmd_set_promisc_mode_result *res = parsed_result;
6867         int enable;
6868         portid_t i;
6869
6870         if (!strcmp(res->mode, "on"))
6871                 enable = 1;
6872         else
6873                 enable = 0;
6874
6875         /* all ports */
6876         if (allports) {
6877                 RTE_ETH_FOREACH_DEV(i)
6878                         eth_set_promisc_mode(i, enable);
6879         } else {
6880                 eth_set_promisc_mode(res->port_num, enable);
6881         }
6882 }
6883
6884 cmdline_parse_token_string_t cmd_setpromisc_set =
6885         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6886 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6887         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6888                                  "promisc");
6889 cmdline_parse_token_string_t cmd_setpromisc_portall =
6890         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6891                                  "all");
6892 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6893         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6894                               UINT16);
6895 cmdline_parse_token_string_t cmd_setpromisc_mode =
6896         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6897                                  "on#off");
6898
6899 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6900         .f = cmd_set_promisc_mode_parsed,
6901         .data = (void *)1,
6902         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6903         .tokens = {
6904                 (void *)&cmd_setpromisc_set,
6905                 (void *)&cmd_setpromisc_promisc,
6906                 (void *)&cmd_setpromisc_portall,
6907                 (void *)&cmd_setpromisc_mode,
6908                 NULL,
6909         },
6910 };
6911
6912 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6913         .f = cmd_set_promisc_mode_parsed,
6914         .data = (void *)0,
6915         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6916         .tokens = {
6917                 (void *)&cmd_setpromisc_set,
6918                 (void *)&cmd_setpromisc_promisc,
6919                 (void *)&cmd_setpromisc_portnum,
6920                 (void *)&cmd_setpromisc_mode,
6921                 NULL,
6922         },
6923 };
6924
6925 /* *** SET ALLMULTI MODE *** */
6926 struct cmd_set_allmulti_mode_result {
6927         cmdline_fixed_string_t set;
6928         cmdline_fixed_string_t allmulti;
6929         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6930         uint16_t port_num;               /* valid if "allports" argument == 0 */
6931         cmdline_fixed_string_t mode;
6932 };
6933
6934 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6935                                         __rte_unused struct cmdline *cl,
6936                                         void *allports)
6937 {
6938         struct cmd_set_allmulti_mode_result *res = parsed_result;
6939         int enable;
6940         portid_t i;
6941
6942         if (!strcmp(res->mode, "on"))
6943                 enable = 1;
6944         else
6945                 enable = 0;
6946
6947         /* all ports */
6948         if (allports) {
6949                 RTE_ETH_FOREACH_DEV(i) {
6950                         eth_set_allmulticast_mode(i, enable);
6951                 }
6952         }
6953         else {
6954                 eth_set_allmulticast_mode(res->port_num, enable);
6955         }
6956 }
6957
6958 cmdline_parse_token_string_t cmd_setallmulti_set =
6959         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6960 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6961         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6962                                  "allmulti");
6963 cmdline_parse_token_string_t cmd_setallmulti_portall =
6964         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6965                                  "all");
6966 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6967         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6968                               UINT16);
6969 cmdline_parse_token_string_t cmd_setallmulti_mode =
6970         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6971                                  "on#off");
6972
6973 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6974         .f = cmd_set_allmulti_mode_parsed,
6975         .data = (void *)1,
6976         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6977         .tokens = {
6978                 (void *)&cmd_setallmulti_set,
6979                 (void *)&cmd_setallmulti_allmulti,
6980                 (void *)&cmd_setallmulti_portall,
6981                 (void *)&cmd_setallmulti_mode,
6982                 NULL,
6983         },
6984 };
6985
6986 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6987         .f = cmd_set_allmulti_mode_parsed,
6988         .data = (void *)0,
6989         .help_str = "set allmulti <port_id> on|off: "
6990                 "Set allmulti mode on port_id",
6991         .tokens = {
6992                 (void *)&cmd_setallmulti_set,
6993                 (void *)&cmd_setallmulti_allmulti,
6994                 (void *)&cmd_setallmulti_portnum,
6995                 (void *)&cmd_setallmulti_mode,
6996                 NULL,
6997         },
6998 };
6999
7000 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7001 struct cmd_link_flow_ctrl_set_result {
7002         cmdline_fixed_string_t set;
7003         cmdline_fixed_string_t flow_ctrl;
7004         cmdline_fixed_string_t rx;
7005         cmdline_fixed_string_t rx_lfc_mode;
7006         cmdline_fixed_string_t tx;
7007         cmdline_fixed_string_t tx_lfc_mode;
7008         cmdline_fixed_string_t mac_ctrl_frame_fwd;
7009         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7010         cmdline_fixed_string_t autoneg_str;
7011         cmdline_fixed_string_t autoneg;
7012         cmdline_fixed_string_t hw_str;
7013         uint32_t high_water;
7014         cmdline_fixed_string_t lw_str;
7015         uint32_t low_water;
7016         cmdline_fixed_string_t pt_str;
7017         uint16_t pause_time;
7018         cmdline_fixed_string_t xon_str;
7019         uint16_t send_xon;
7020         portid_t port_id;
7021 };
7022
7023 cmdline_parse_token_string_t cmd_lfc_set_set =
7024         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7025                                 set, "set");
7026 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7027         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7028                                 flow_ctrl, "flow_ctrl");
7029 cmdline_parse_token_string_t cmd_lfc_set_rx =
7030         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7031                                 rx, "rx");
7032 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7033         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7034                                 rx_lfc_mode, "on#off");
7035 cmdline_parse_token_string_t cmd_lfc_set_tx =
7036         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7037                                 tx, "tx");
7038 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7039         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7040                                 tx_lfc_mode, "on#off");
7041 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7042         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7043                                 hw_str, "high_water");
7044 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7045         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7046                                 high_water, UINT32);
7047 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7048         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7049                                 lw_str, "low_water");
7050 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7051         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7052                                 low_water, UINT32);
7053 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7054         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7055                                 pt_str, "pause_time");
7056 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7057         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7058                                 pause_time, UINT16);
7059 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7060         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7061                                 xon_str, "send_xon");
7062 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7063         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7064                                 send_xon, UINT16);
7065 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7066         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7067                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7068 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7069         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7070                                 mac_ctrl_frame_fwd_mode, "on#off");
7071 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7072         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7073                                 autoneg_str, "autoneg");
7074 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7075         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7076                                 autoneg, "on#off");
7077 cmdline_parse_token_num_t cmd_lfc_set_portid =
7078         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7079                                 port_id, UINT16);
7080
7081 /* forward declaration */
7082 static void
7083 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7084                               void *data);
7085
7086 cmdline_parse_inst_t cmd_link_flow_control_set = {
7087         .f = cmd_link_flow_ctrl_set_parsed,
7088         .data = NULL,
7089         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7090                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7091                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7092         .tokens = {
7093                 (void *)&cmd_lfc_set_set,
7094                 (void *)&cmd_lfc_set_flow_ctrl,
7095                 (void *)&cmd_lfc_set_rx,
7096                 (void *)&cmd_lfc_set_rx_mode,
7097                 (void *)&cmd_lfc_set_tx,
7098                 (void *)&cmd_lfc_set_tx_mode,
7099                 (void *)&cmd_lfc_set_high_water,
7100                 (void *)&cmd_lfc_set_low_water,
7101                 (void *)&cmd_lfc_set_pause_time,
7102                 (void *)&cmd_lfc_set_send_xon,
7103                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7104                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7105                 (void *)&cmd_lfc_set_autoneg_str,
7106                 (void *)&cmd_lfc_set_autoneg,
7107                 (void *)&cmd_lfc_set_portid,
7108                 NULL,
7109         },
7110 };
7111
7112 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7113         .f = cmd_link_flow_ctrl_set_parsed,
7114         .data = (void *)&cmd_link_flow_control_set_rx,
7115         .help_str = "set flow_ctrl rx on|off <port_id>: "
7116                 "Change rx flow control parameter",
7117         .tokens = {
7118                 (void *)&cmd_lfc_set_set,
7119                 (void *)&cmd_lfc_set_flow_ctrl,
7120                 (void *)&cmd_lfc_set_rx,
7121                 (void *)&cmd_lfc_set_rx_mode,
7122                 (void *)&cmd_lfc_set_portid,
7123                 NULL,
7124         },
7125 };
7126
7127 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7128         .f = cmd_link_flow_ctrl_set_parsed,
7129         .data = (void *)&cmd_link_flow_control_set_tx,
7130         .help_str = "set flow_ctrl tx on|off <port_id>: "
7131                 "Change tx flow control parameter",
7132         .tokens = {
7133                 (void *)&cmd_lfc_set_set,
7134                 (void *)&cmd_lfc_set_flow_ctrl,
7135                 (void *)&cmd_lfc_set_tx,
7136                 (void *)&cmd_lfc_set_tx_mode,
7137                 (void *)&cmd_lfc_set_portid,
7138                 NULL,
7139         },
7140 };
7141
7142 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7143         .f = cmd_link_flow_ctrl_set_parsed,
7144         .data = (void *)&cmd_link_flow_control_set_hw,
7145         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7146                 "Change high water flow control parameter",
7147         .tokens = {
7148                 (void *)&cmd_lfc_set_set,
7149                 (void *)&cmd_lfc_set_flow_ctrl,
7150                 (void *)&cmd_lfc_set_high_water_str,
7151                 (void *)&cmd_lfc_set_high_water,
7152                 (void *)&cmd_lfc_set_portid,
7153                 NULL,
7154         },
7155 };
7156
7157 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7158         .f = cmd_link_flow_ctrl_set_parsed,
7159         .data = (void *)&cmd_link_flow_control_set_lw,
7160         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7161                 "Change low water flow control parameter",
7162         .tokens = {
7163                 (void *)&cmd_lfc_set_set,
7164                 (void *)&cmd_lfc_set_flow_ctrl,
7165                 (void *)&cmd_lfc_set_low_water_str,
7166                 (void *)&cmd_lfc_set_low_water,
7167                 (void *)&cmd_lfc_set_portid,
7168                 NULL,
7169         },
7170 };
7171
7172 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7173         .f = cmd_link_flow_ctrl_set_parsed,
7174         .data = (void *)&cmd_link_flow_control_set_pt,
7175         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7176                 "Change pause time flow control parameter",
7177         .tokens = {
7178                 (void *)&cmd_lfc_set_set,
7179                 (void *)&cmd_lfc_set_flow_ctrl,
7180                 (void *)&cmd_lfc_set_pause_time_str,
7181                 (void *)&cmd_lfc_set_pause_time,
7182                 (void *)&cmd_lfc_set_portid,
7183                 NULL,
7184         },
7185 };
7186
7187 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7188         .f = cmd_link_flow_ctrl_set_parsed,
7189         .data = (void *)&cmd_link_flow_control_set_xon,
7190         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7191                 "Change send_xon flow control parameter",
7192         .tokens = {
7193                 (void *)&cmd_lfc_set_set,
7194                 (void *)&cmd_lfc_set_flow_ctrl,
7195                 (void *)&cmd_lfc_set_send_xon_str,
7196                 (void *)&cmd_lfc_set_send_xon,
7197                 (void *)&cmd_lfc_set_portid,
7198                 NULL,
7199         },
7200 };
7201
7202 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7203         .f = cmd_link_flow_ctrl_set_parsed,
7204         .data = (void *)&cmd_link_flow_control_set_macfwd,
7205         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7206                 "Change mac ctrl fwd flow control parameter",
7207         .tokens = {
7208                 (void *)&cmd_lfc_set_set,
7209                 (void *)&cmd_lfc_set_flow_ctrl,
7210                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7211                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7212                 (void *)&cmd_lfc_set_portid,
7213                 NULL,
7214         },
7215 };
7216
7217 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7218         .f = cmd_link_flow_ctrl_set_parsed,
7219         .data = (void *)&cmd_link_flow_control_set_autoneg,
7220         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7221                 "Change autoneg flow control parameter",
7222         .tokens = {
7223                 (void *)&cmd_lfc_set_set,
7224                 (void *)&cmd_lfc_set_flow_ctrl,
7225                 (void *)&cmd_lfc_set_autoneg_str,
7226                 (void *)&cmd_lfc_set_autoneg,
7227                 (void *)&cmd_lfc_set_portid,
7228                 NULL,
7229         },
7230 };
7231
7232 static void
7233 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7234                               __rte_unused struct cmdline *cl,
7235                               void *data)
7236 {
7237         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7238         cmdline_parse_inst_t *cmd = data;
7239         struct rte_eth_fc_conf fc_conf;
7240         int rx_fc_en = 0;
7241         int tx_fc_en = 0;
7242         int ret;
7243
7244         /*
7245          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7246          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7247          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7248          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7249          */
7250         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7251                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7252         };
7253
7254         /* Partial command line, retrieve current configuration */
7255         if (cmd) {
7256                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7257                 if (ret != 0) {
7258                         printf("cannot get current flow ctrl parameters, return"
7259                                "code = %d\n", ret);
7260                         return;
7261                 }
7262
7263                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7264                     (fc_conf.mode == RTE_FC_FULL))
7265                         rx_fc_en = 1;
7266                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7267                     (fc_conf.mode == RTE_FC_FULL))
7268                         tx_fc_en = 1;
7269         }
7270
7271         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7272                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7273
7274         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7275                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7276
7277         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7278
7279         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7280                 fc_conf.high_water = res->high_water;
7281
7282         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7283                 fc_conf.low_water = res->low_water;
7284
7285         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7286                 fc_conf.pause_time = res->pause_time;
7287
7288         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7289                 fc_conf.send_xon = res->send_xon;
7290
7291         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7292                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7293                         fc_conf.mac_ctrl_frame_fwd = 1;
7294                 else
7295                         fc_conf.mac_ctrl_frame_fwd = 0;
7296         }
7297
7298         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7299                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7300
7301         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7302         if (ret != 0)
7303                 printf("bad flow contrl parameter, return code = %d \n", ret);
7304 }
7305
7306 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7307 struct cmd_priority_flow_ctrl_set_result {
7308         cmdline_fixed_string_t set;
7309         cmdline_fixed_string_t pfc_ctrl;
7310         cmdline_fixed_string_t rx;
7311         cmdline_fixed_string_t rx_pfc_mode;
7312         cmdline_fixed_string_t tx;
7313         cmdline_fixed_string_t tx_pfc_mode;
7314         uint32_t high_water;
7315         uint32_t low_water;
7316         uint16_t pause_time;
7317         uint8_t  priority;
7318         portid_t port_id;
7319 };
7320
7321 static void
7322 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7323                        __rte_unused struct cmdline *cl,
7324                        __rte_unused void *data)
7325 {
7326         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7327         struct rte_eth_pfc_conf pfc_conf;
7328         int rx_fc_enable, tx_fc_enable;
7329         int ret;
7330
7331         /*
7332          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7333          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7334          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7335          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7336          */
7337         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7338                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7339         };
7340
7341         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7342         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7343         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7344         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7345         pfc_conf.fc.high_water = res->high_water;
7346         pfc_conf.fc.low_water  = res->low_water;
7347         pfc_conf.fc.pause_time = res->pause_time;
7348         pfc_conf.priority      = res->priority;
7349
7350         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7351         if (ret != 0)
7352                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7353 }
7354
7355 cmdline_parse_token_string_t cmd_pfc_set_set =
7356         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7357                                 set, "set");
7358 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7359         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7360                                 pfc_ctrl, "pfc_ctrl");
7361 cmdline_parse_token_string_t cmd_pfc_set_rx =
7362         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7363                                 rx, "rx");
7364 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7365         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7366                                 rx_pfc_mode, "on#off");
7367 cmdline_parse_token_string_t cmd_pfc_set_tx =
7368         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7369                                 tx, "tx");
7370 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7371         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7372                                 tx_pfc_mode, "on#off");
7373 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7374         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7375                                 high_water, UINT32);
7376 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7377         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7378                                 low_water, UINT32);
7379 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7380         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7381                                 pause_time, UINT16);
7382 cmdline_parse_token_num_t cmd_pfc_set_priority =
7383         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7384                                 priority, UINT8);
7385 cmdline_parse_token_num_t cmd_pfc_set_portid =
7386         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7387                                 port_id, UINT16);
7388
7389 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7390         .f = cmd_priority_flow_ctrl_set_parsed,
7391         .data = NULL,
7392         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7393                 "<pause_time> <priority> <port_id>: "
7394                 "Configure the Ethernet priority flow control",
7395         .tokens = {
7396                 (void *)&cmd_pfc_set_set,
7397                 (void *)&cmd_pfc_set_flow_ctrl,
7398                 (void *)&cmd_pfc_set_rx,
7399                 (void *)&cmd_pfc_set_rx_mode,
7400                 (void *)&cmd_pfc_set_tx,
7401                 (void *)&cmd_pfc_set_tx_mode,
7402                 (void *)&cmd_pfc_set_high_water,
7403                 (void *)&cmd_pfc_set_low_water,
7404                 (void *)&cmd_pfc_set_pause_time,
7405                 (void *)&cmd_pfc_set_priority,
7406                 (void *)&cmd_pfc_set_portid,
7407                 NULL,
7408         },
7409 };
7410
7411 /* *** RESET CONFIGURATION *** */
7412 struct cmd_reset_result {
7413         cmdline_fixed_string_t reset;
7414         cmdline_fixed_string_t def;
7415 };
7416
7417 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7418                              struct cmdline *cl,
7419                              __rte_unused void *data)
7420 {
7421         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7422         set_def_fwd_config();
7423 }
7424
7425 cmdline_parse_token_string_t cmd_reset_set =
7426         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7427 cmdline_parse_token_string_t cmd_reset_def =
7428         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7429                                  "default");
7430
7431 cmdline_parse_inst_t cmd_reset = {
7432         .f = cmd_reset_parsed,
7433         .data = NULL,
7434         .help_str = "set default: Reset default forwarding configuration",
7435         .tokens = {
7436                 (void *)&cmd_reset_set,
7437                 (void *)&cmd_reset_def,
7438                 NULL,
7439         },
7440 };
7441
7442 /* *** START FORWARDING *** */
7443 struct cmd_start_result {
7444         cmdline_fixed_string_t start;
7445 };
7446
7447 cmdline_parse_token_string_t cmd_start_start =
7448         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7449
7450 static void cmd_start_parsed(__rte_unused void *parsed_result,
7451                              __rte_unused struct cmdline *cl,
7452                              __rte_unused void *data)
7453 {
7454         start_packet_forwarding(0);
7455 }
7456
7457 cmdline_parse_inst_t cmd_start = {
7458         .f = cmd_start_parsed,
7459         .data = NULL,
7460         .help_str = "start: Start packet forwarding",
7461         .tokens = {
7462                 (void *)&cmd_start_start,
7463                 NULL,
7464         },
7465 };
7466
7467 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7468 struct cmd_start_tx_first_result {
7469         cmdline_fixed_string_t start;
7470         cmdline_fixed_string_t tx_first;
7471 };
7472
7473 static void
7474 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7475                           __rte_unused struct cmdline *cl,
7476                           __rte_unused void *data)
7477 {
7478         start_packet_forwarding(1);
7479 }
7480
7481 cmdline_parse_token_string_t cmd_start_tx_first_start =
7482         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7483                                  "start");
7484 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7485         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7486                                  tx_first, "tx_first");
7487
7488 cmdline_parse_inst_t cmd_start_tx_first = {
7489         .f = cmd_start_tx_first_parsed,
7490         .data = NULL,
7491         .help_str = "start tx_first: Start packet forwarding, "
7492                 "after sending 1 burst of packets",
7493         .tokens = {
7494                 (void *)&cmd_start_tx_first_start,
7495                 (void *)&cmd_start_tx_first_tx_first,
7496                 NULL,
7497         },
7498 };
7499
7500 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7501 struct cmd_start_tx_first_n_result {
7502         cmdline_fixed_string_t start;
7503         cmdline_fixed_string_t tx_first;
7504         uint32_t tx_num;
7505 };
7506
7507 static void
7508 cmd_start_tx_first_n_parsed(void *parsed_result,
7509                           __rte_unused struct cmdline *cl,
7510                           __rte_unused void *data)
7511 {
7512         struct cmd_start_tx_first_n_result *res = parsed_result;
7513
7514         start_packet_forwarding(res->tx_num);
7515 }
7516
7517 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7518         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7519                         start, "start");
7520 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7521         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7522                         tx_first, "tx_first");
7523 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7524         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7525                         tx_num, UINT32);
7526
7527 cmdline_parse_inst_t cmd_start_tx_first_n = {
7528         .f = cmd_start_tx_first_n_parsed,
7529         .data = NULL,
7530         .help_str = "start tx_first <num>: "
7531                 "packet forwarding, after sending <num> bursts of packets",
7532         .tokens = {
7533                 (void *)&cmd_start_tx_first_n_start,
7534                 (void *)&cmd_start_tx_first_n_tx_first,
7535                 (void *)&cmd_start_tx_first_n_tx_num,
7536                 NULL,
7537         },
7538 };
7539
7540 /* *** SET LINK UP *** */
7541 struct cmd_set_link_up_result {
7542         cmdline_fixed_string_t set;
7543         cmdline_fixed_string_t link_up;
7544         cmdline_fixed_string_t port;
7545         portid_t port_id;
7546 };
7547
7548 cmdline_parse_token_string_t cmd_set_link_up_set =
7549         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7550 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7551         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7552                                 "link-up");
7553 cmdline_parse_token_string_t cmd_set_link_up_port =
7554         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7555 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7556         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7557
7558 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7559                              __rte_unused struct cmdline *cl,
7560                              __rte_unused void *data)
7561 {
7562         struct cmd_set_link_up_result *res = parsed_result;
7563         dev_set_link_up(res->port_id);
7564 }
7565
7566 cmdline_parse_inst_t cmd_set_link_up = {
7567         .f = cmd_set_link_up_parsed,
7568         .data = NULL,
7569         .help_str = "set link-up port <port id>",
7570         .tokens = {
7571                 (void *)&cmd_set_link_up_set,
7572                 (void *)&cmd_set_link_up_link_up,
7573                 (void *)&cmd_set_link_up_port,
7574                 (void *)&cmd_set_link_up_port_id,
7575                 NULL,
7576         },
7577 };
7578
7579 /* *** SET LINK DOWN *** */
7580 struct cmd_set_link_down_result {
7581         cmdline_fixed_string_t set;
7582         cmdline_fixed_string_t link_down;
7583         cmdline_fixed_string_t port;
7584         portid_t port_id;
7585 };
7586
7587 cmdline_parse_token_string_t cmd_set_link_down_set =
7588         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7589 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7590         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7591                                 "link-down");
7592 cmdline_parse_token_string_t cmd_set_link_down_port =
7593         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7594 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7595         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7596
7597 static void cmd_set_link_down_parsed(
7598                                 __rte_unused void *parsed_result,
7599                                 __rte_unused struct cmdline *cl,
7600                                 __rte_unused void *data)
7601 {
7602         struct cmd_set_link_down_result *res = parsed_result;
7603         dev_set_link_down(res->port_id);
7604 }
7605
7606 cmdline_parse_inst_t cmd_set_link_down = {
7607         .f = cmd_set_link_down_parsed,
7608         .data = NULL,
7609         .help_str = "set link-down port <port id>",
7610         .tokens = {
7611                 (void *)&cmd_set_link_down_set,
7612                 (void *)&cmd_set_link_down_link_down,
7613                 (void *)&cmd_set_link_down_port,
7614                 (void *)&cmd_set_link_down_port_id,
7615                 NULL,
7616         },
7617 };
7618
7619 /* *** SHOW CFG *** */
7620 struct cmd_showcfg_result {
7621         cmdline_fixed_string_t show;
7622         cmdline_fixed_string_t cfg;
7623         cmdline_fixed_string_t what;
7624 };
7625
7626 static void cmd_showcfg_parsed(void *parsed_result,
7627                                __rte_unused struct cmdline *cl,
7628                                __rte_unused void *data)
7629 {
7630         struct cmd_showcfg_result *res = parsed_result;
7631         if (!strcmp(res->what, "rxtx"))
7632                 rxtx_config_display();
7633         else if (!strcmp(res->what, "cores"))
7634                 fwd_lcores_config_display();
7635         else if (!strcmp(res->what, "fwd"))
7636                 pkt_fwd_config_display(&cur_fwd_config);
7637         else if (!strcmp(res->what, "rxoffs"))
7638                 show_rx_pkt_offsets();
7639         else if (!strcmp(res->what, "rxpkts"))
7640                 show_rx_pkt_segments();
7641         else if (!strcmp(res->what, "txpkts"))
7642                 show_tx_pkt_segments();
7643         else if (!strcmp(res->what, "txtimes"))
7644                 show_tx_pkt_times();
7645 }
7646
7647 cmdline_parse_token_string_t cmd_showcfg_show =
7648         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7649 cmdline_parse_token_string_t cmd_showcfg_port =
7650         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7651 cmdline_parse_token_string_t cmd_showcfg_what =
7652         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7653                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7654
7655 cmdline_parse_inst_t cmd_showcfg = {
7656         .f = cmd_showcfg_parsed,
7657         .data = NULL,
7658         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7659         .tokens = {
7660                 (void *)&cmd_showcfg_show,
7661                 (void *)&cmd_showcfg_port,
7662                 (void *)&cmd_showcfg_what,
7663                 NULL,
7664         },
7665 };
7666
7667 /* *** SHOW ALL PORT INFO *** */
7668 struct cmd_showportall_result {
7669         cmdline_fixed_string_t show;
7670         cmdline_fixed_string_t port;
7671         cmdline_fixed_string_t what;
7672         cmdline_fixed_string_t all;
7673 };
7674
7675 static void cmd_showportall_parsed(void *parsed_result,
7676                                 __rte_unused struct cmdline *cl,
7677                                 __rte_unused void *data)
7678 {
7679         portid_t i;
7680
7681         struct cmd_showportall_result *res = parsed_result;
7682         if (!strcmp(res->show, "clear")) {
7683                 if (!strcmp(res->what, "stats"))
7684                         RTE_ETH_FOREACH_DEV(i)
7685                                 nic_stats_clear(i);
7686                 else if (!strcmp(res->what, "xstats"))
7687                         RTE_ETH_FOREACH_DEV(i)
7688                                 nic_xstats_clear(i);
7689         } else if (!strcmp(res->what, "info"))
7690                 RTE_ETH_FOREACH_DEV(i)
7691                         port_infos_display(i);
7692         else if (!strcmp(res->what, "summary")) {
7693                 port_summary_header_display();
7694                 RTE_ETH_FOREACH_DEV(i)
7695                         port_summary_display(i);
7696         }
7697         else if (!strcmp(res->what, "stats"))
7698                 RTE_ETH_FOREACH_DEV(i)
7699                         nic_stats_display(i);
7700         else if (!strcmp(res->what, "xstats"))
7701                 RTE_ETH_FOREACH_DEV(i)
7702                         nic_xstats_display(i);
7703         else if (!strcmp(res->what, "fdir"))
7704                 RTE_ETH_FOREACH_DEV(i)
7705                         fdir_get_infos(i);
7706         else if (!strcmp(res->what, "stat_qmap"))
7707                 RTE_ETH_FOREACH_DEV(i)
7708                         nic_stats_mapping_display(i);
7709         else if (!strcmp(res->what, "dcb_tc"))
7710                 RTE_ETH_FOREACH_DEV(i)
7711                         port_dcb_info_display(i);
7712         else if (!strcmp(res->what, "cap"))
7713                 RTE_ETH_FOREACH_DEV(i)
7714                         port_offload_cap_display(i);
7715 }
7716
7717 cmdline_parse_token_string_t cmd_showportall_show =
7718         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7719                                  "show#clear");
7720 cmdline_parse_token_string_t cmd_showportall_port =
7721         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7722 cmdline_parse_token_string_t cmd_showportall_what =
7723         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7724                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7725 cmdline_parse_token_string_t cmd_showportall_all =
7726         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7727 cmdline_parse_inst_t cmd_showportall = {
7728         .f = cmd_showportall_parsed,
7729         .data = NULL,
7730         .help_str = "show|clear port "
7731                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7732         .tokens = {
7733                 (void *)&cmd_showportall_show,
7734                 (void *)&cmd_showportall_port,
7735                 (void *)&cmd_showportall_what,
7736                 (void *)&cmd_showportall_all,
7737                 NULL,
7738         },
7739 };
7740
7741 /* *** SHOW PORT INFO *** */
7742 struct cmd_showport_result {
7743         cmdline_fixed_string_t show;
7744         cmdline_fixed_string_t port;
7745         cmdline_fixed_string_t what;
7746         uint16_t portnum;
7747 };
7748
7749 static void cmd_showport_parsed(void *parsed_result,
7750                                 __rte_unused struct cmdline *cl,
7751                                 __rte_unused void *data)
7752 {
7753         struct cmd_showport_result *res = parsed_result;
7754         if (!strcmp(res->show, "clear")) {
7755                 if (!strcmp(res->what, "stats"))
7756                         nic_stats_clear(res->portnum);
7757                 else if (!strcmp(res->what, "xstats"))
7758                         nic_xstats_clear(res->portnum);
7759         } else if (!strcmp(res->what, "info"))
7760                 port_infos_display(res->portnum);
7761         else if (!strcmp(res->what, "summary")) {
7762                 port_summary_header_display();
7763                 port_summary_display(res->portnum);
7764         }
7765         else if (!strcmp(res->what, "stats"))
7766                 nic_stats_display(res->portnum);
7767         else if (!strcmp(res->what, "xstats"))
7768                 nic_xstats_display(res->portnum);
7769         else if (!strcmp(res->what, "fdir"))
7770                  fdir_get_infos(res->portnum);
7771         else if (!strcmp(res->what, "stat_qmap"))
7772                 nic_stats_mapping_display(res->portnum);
7773         else if (!strcmp(res->what, "dcb_tc"))
7774                 port_dcb_info_display(res->portnum);
7775         else if (!strcmp(res->what, "cap"))
7776                 port_offload_cap_display(res->portnum);
7777 }
7778
7779 cmdline_parse_token_string_t cmd_showport_show =
7780         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7781                                  "show#clear");
7782 cmdline_parse_token_string_t cmd_showport_port =
7783         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7784 cmdline_parse_token_string_t cmd_showport_what =
7785         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7786                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7787 cmdline_parse_token_num_t cmd_showport_portnum =
7788         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7789
7790 cmdline_parse_inst_t cmd_showport = {
7791         .f = cmd_showport_parsed,
7792         .data = NULL,
7793         .help_str = "show|clear port "
7794                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7795                 "<port_id>",
7796         .tokens = {
7797                 (void *)&cmd_showport_show,
7798                 (void *)&cmd_showport_port,
7799                 (void *)&cmd_showport_what,
7800                 (void *)&cmd_showport_portnum,
7801                 NULL,
7802         },
7803 };
7804
7805 /* *** SHOW DEVICE INFO *** */
7806 struct cmd_showdevice_result {
7807         cmdline_fixed_string_t show;
7808         cmdline_fixed_string_t device;
7809         cmdline_fixed_string_t what;
7810         cmdline_fixed_string_t identifier;
7811 };
7812
7813 static void cmd_showdevice_parsed(void *parsed_result,
7814                                 __rte_unused struct cmdline *cl,
7815                                 __rte_unused void *data)
7816 {
7817         struct cmd_showdevice_result *res = parsed_result;
7818         if (!strcmp(res->what, "info")) {
7819                 if (!strcmp(res->identifier, "all"))
7820                         device_infos_display(NULL);
7821                 else
7822                         device_infos_display(res->identifier);
7823         }
7824 }
7825
7826 cmdline_parse_token_string_t cmd_showdevice_show =
7827         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7828                                  "show");
7829 cmdline_parse_token_string_t cmd_showdevice_device =
7830         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7831 cmdline_parse_token_string_t cmd_showdevice_what =
7832         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7833                                  "info");
7834 cmdline_parse_token_string_t cmd_showdevice_identifier =
7835         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7836                         identifier, NULL);
7837
7838 cmdline_parse_inst_t cmd_showdevice = {
7839         .f = cmd_showdevice_parsed,
7840         .data = NULL,
7841         .help_str = "show device info <identifier>|all",
7842         .tokens = {
7843                 (void *)&cmd_showdevice_show,
7844                 (void *)&cmd_showdevice_device,
7845                 (void *)&cmd_showdevice_what,
7846                 (void *)&cmd_showdevice_identifier,
7847                 NULL,
7848         },
7849 };
7850
7851 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7852 struct cmd_showeeprom_result {
7853         cmdline_fixed_string_t show;
7854         cmdline_fixed_string_t port;
7855         uint16_t portnum;
7856         cmdline_fixed_string_t type;
7857 };
7858
7859 static void cmd_showeeprom_parsed(void *parsed_result,
7860                 __rte_unused struct cmdline *cl,
7861                 __rte_unused void *data)
7862 {
7863         struct cmd_showeeprom_result *res = parsed_result;
7864
7865         if (!strcmp(res->type, "eeprom"))
7866                 port_eeprom_display(res->portnum);
7867         else if (!strcmp(res->type, "module_eeprom"))
7868                 port_module_eeprom_display(res->portnum);
7869         else
7870                 printf("Unknown argument\n");
7871 }
7872
7873 cmdline_parse_token_string_t cmd_showeeprom_show =
7874         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7875 cmdline_parse_token_string_t cmd_showeeprom_port =
7876         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7877 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7878         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7879 cmdline_parse_token_string_t cmd_showeeprom_type =
7880         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7881
7882 cmdline_parse_inst_t cmd_showeeprom = {
7883         .f = cmd_showeeprom_parsed,
7884         .data = NULL,
7885         .help_str = "show port <port_id> module_eeprom|eeprom",
7886         .tokens = {
7887                 (void *)&cmd_showeeprom_show,
7888                 (void *)&cmd_showeeprom_port,
7889                 (void *)&cmd_showeeprom_portnum,
7890                 (void *)&cmd_showeeprom_type,
7891                 NULL,
7892         },
7893 };
7894
7895 /* *** SHOW QUEUE INFO *** */
7896 struct cmd_showqueue_result {
7897         cmdline_fixed_string_t show;
7898         cmdline_fixed_string_t type;
7899         cmdline_fixed_string_t what;
7900         uint16_t portnum;
7901         uint16_t queuenum;
7902 };
7903
7904 static void
7905 cmd_showqueue_parsed(void *parsed_result,
7906         __rte_unused struct cmdline *cl,
7907         __rte_unused void *data)
7908 {
7909         struct cmd_showqueue_result *res = parsed_result;
7910
7911         if (!strcmp(res->type, "rxq"))
7912                 rx_queue_infos_display(res->portnum, res->queuenum);
7913         else if (!strcmp(res->type, "txq"))
7914                 tx_queue_infos_display(res->portnum, res->queuenum);
7915 }
7916
7917 cmdline_parse_token_string_t cmd_showqueue_show =
7918         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7919 cmdline_parse_token_string_t cmd_showqueue_type =
7920         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7921 cmdline_parse_token_string_t cmd_showqueue_what =
7922         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7923 cmdline_parse_token_num_t cmd_showqueue_portnum =
7924         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7925 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7926         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7927
7928 cmdline_parse_inst_t cmd_showqueue = {
7929         .f = cmd_showqueue_parsed,
7930         .data = NULL,
7931         .help_str = "show rxq|txq info <port_id> <queue_id>",
7932         .tokens = {
7933                 (void *)&cmd_showqueue_show,
7934                 (void *)&cmd_showqueue_type,
7935                 (void *)&cmd_showqueue_what,
7936                 (void *)&cmd_showqueue_portnum,
7937                 (void *)&cmd_showqueue_queuenum,
7938                 NULL,
7939         },
7940 };
7941
7942 /* show/clear fwd engine statistics */
7943 struct fwd_result {
7944         cmdline_fixed_string_t action;
7945         cmdline_fixed_string_t fwd;
7946         cmdline_fixed_string_t stats;
7947         cmdline_fixed_string_t all;
7948 };
7949
7950 cmdline_parse_token_string_t cmd_fwd_action =
7951         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7952 cmdline_parse_token_string_t cmd_fwd_fwd =
7953         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7954 cmdline_parse_token_string_t cmd_fwd_stats =
7955         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7956 cmdline_parse_token_string_t cmd_fwd_all =
7957         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7958
7959 static void
7960 cmd_showfwdall_parsed(void *parsed_result,
7961                       __rte_unused struct cmdline *cl,
7962                       __rte_unused void *data)
7963 {
7964         struct fwd_result *res = parsed_result;
7965
7966         if (!strcmp(res->action, "show"))
7967                 fwd_stats_display();
7968         else
7969                 fwd_stats_reset();
7970 }
7971
7972 static cmdline_parse_inst_t cmd_showfwdall = {
7973         .f = cmd_showfwdall_parsed,
7974         .data = NULL,
7975         .help_str = "show|clear fwd stats all",
7976         .tokens = {
7977                 (void *)&cmd_fwd_action,
7978                 (void *)&cmd_fwd_fwd,
7979                 (void *)&cmd_fwd_stats,
7980                 (void *)&cmd_fwd_all,
7981                 NULL,
7982         },
7983 };
7984
7985 /* *** READ PORT REGISTER *** */
7986 struct cmd_read_reg_result {
7987         cmdline_fixed_string_t read;
7988         cmdline_fixed_string_t reg;
7989         portid_t port_id;
7990         uint32_t reg_off;
7991 };
7992
7993 static void
7994 cmd_read_reg_parsed(void *parsed_result,
7995                     __rte_unused struct cmdline *cl,
7996                     __rte_unused void *data)
7997 {
7998         struct cmd_read_reg_result *res = parsed_result;
7999         port_reg_display(res->port_id, res->reg_off);
8000 }
8001
8002 cmdline_parse_token_string_t cmd_read_reg_read =
8003         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8004 cmdline_parse_token_string_t cmd_read_reg_reg =
8005         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8006 cmdline_parse_token_num_t cmd_read_reg_port_id =
8007         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
8008 cmdline_parse_token_num_t cmd_read_reg_reg_off =
8009         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
8010
8011 cmdline_parse_inst_t cmd_read_reg = {
8012         .f = cmd_read_reg_parsed,
8013         .data = NULL,
8014         .help_str = "read reg <port_id> <reg_off>",
8015         .tokens = {
8016                 (void *)&cmd_read_reg_read,
8017                 (void *)&cmd_read_reg_reg,
8018                 (void *)&cmd_read_reg_port_id,
8019                 (void *)&cmd_read_reg_reg_off,
8020                 NULL,
8021         },
8022 };
8023
8024 /* *** READ PORT REGISTER BIT FIELD *** */
8025 struct cmd_read_reg_bit_field_result {
8026         cmdline_fixed_string_t read;
8027         cmdline_fixed_string_t regfield;
8028         portid_t port_id;
8029         uint32_t reg_off;
8030         uint8_t bit1_pos;
8031         uint8_t bit2_pos;
8032 };
8033
8034 static void
8035 cmd_read_reg_bit_field_parsed(void *parsed_result,
8036                               __rte_unused struct cmdline *cl,
8037                               __rte_unused void *data)
8038 {
8039         struct cmd_read_reg_bit_field_result *res = parsed_result;
8040         port_reg_bit_field_display(res->port_id, res->reg_off,
8041                                    res->bit1_pos, res->bit2_pos);
8042 }
8043
8044 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8045         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8046                                  "read");
8047 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8048         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8049                                  regfield, "regfield");
8050 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8051         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8052                               UINT16);
8053 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8054         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8055                               UINT32);
8056 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8057         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8058                               UINT8);
8059 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8060         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8061                               UINT8);
8062
8063 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8064         .f = cmd_read_reg_bit_field_parsed,
8065         .data = NULL,
8066         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8067         "Read register bit field between bit_x and bit_y included",
8068         .tokens = {
8069                 (void *)&cmd_read_reg_bit_field_read,
8070                 (void *)&cmd_read_reg_bit_field_regfield,
8071                 (void *)&cmd_read_reg_bit_field_port_id,
8072                 (void *)&cmd_read_reg_bit_field_reg_off,
8073                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8074                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8075                 NULL,
8076         },
8077 };
8078
8079 /* *** READ PORT REGISTER BIT *** */
8080 struct cmd_read_reg_bit_result {
8081         cmdline_fixed_string_t read;
8082         cmdline_fixed_string_t regbit;
8083         portid_t port_id;
8084         uint32_t reg_off;
8085         uint8_t bit_pos;
8086 };
8087
8088 static void
8089 cmd_read_reg_bit_parsed(void *parsed_result,
8090                         __rte_unused struct cmdline *cl,
8091                         __rte_unused void *data)
8092 {
8093         struct cmd_read_reg_bit_result *res = parsed_result;
8094         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8095 }
8096
8097 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8098         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8099 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8100         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8101                                  regbit, "regbit");
8102 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8103         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
8104 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8105         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
8106 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8107         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
8108
8109 cmdline_parse_inst_t cmd_read_reg_bit = {
8110         .f = cmd_read_reg_bit_parsed,
8111         .data = NULL,
8112         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8113         .tokens = {
8114                 (void *)&cmd_read_reg_bit_read,
8115                 (void *)&cmd_read_reg_bit_regbit,
8116                 (void *)&cmd_read_reg_bit_port_id,
8117                 (void *)&cmd_read_reg_bit_reg_off,
8118                 (void *)&cmd_read_reg_bit_bit_pos,
8119                 NULL,
8120         },
8121 };
8122
8123 /* *** WRITE PORT REGISTER *** */
8124 struct cmd_write_reg_result {
8125         cmdline_fixed_string_t write;
8126         cmdline_fixed_string_t reg;
8127         portid_t port_id;
8128         uint32_t reg_off;
8129         uint32_t value;
8130 };
8131
8132 static void
8133 cmd_write_reg_parsed(void *parsed_result,
8134                      __rte_unused struct cmdline *cl,
8135                      __rte_unused void *data)
8136 {
8137         struct cmd_write_reg_result *res = parsed_result;
8138         port_reg_set(res->port_id, res->reg_off, res->value);
8139 }
8140
8141 cmdline_parse_token_string_t cmd_write_reg_write =
8142         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8143 cmdline_parse_token_string_t cmd_write_reg_reg =
8144         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8145 cmdline_parse_token_num_t cmd_write_reg_port_id =
8146         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
8147 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8148         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
8149 cmdline_parse_token_num_t cmd_write_reg_value =
8150         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
8151
8152 cmdline_parse_inst_t cmd_write_reg = {
8153         .f = cmd_write_reg_parsed,
8154         .data = NULL,
8155         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8156         .tokens = {
8157                 (void *)&cmd_write_reg_write,
8158                 (void *)&cmd_write_reg_reg,
8159                 (void *)&cmd_write_reg_port_id,
8160                 (void *)&cmd_write_reg_reg_off,
8161                 (void *)&cmd_write_reg_value,
8162                 NULL,
8163         },
8164 };
8165
8166 /* *** WRITE PORT REGISTER BIT FIELD *** */
8167 struct cmd_write_reg_bit_field_result {
8168         cmdline_fixed_string_t write;
8169         cmdline_fixed_string_t regfield;
8170         portid_t port_id;
8171         uint32_t reg_off;
8172         uint8_t bit1_pos;
8173         uint8_t bit2_pos;
8174         uint32_t value;
8175 };
8176
8177 static void
8178 cmd_write_reg_bit_field_parsed(void *parsed_result,
8179                                __rte_unused struct cmdline *cl,
8180                                __rte_unused void *data)
8181 {
8182         struct cmd_write_reg_bit_field_result *res = parsed_result;
8183         port_reg_bit_field_set(res->port_id, res->reg_off,
8184                           res->bit1_pos, res->bit2_pos, res->value);
8185 }
8186
8187 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8188         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8189                                  "write");
8190 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8191         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8192                                  regfield, "regfield");
8193 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8194         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8195                               UINT16);
8196 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8197         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8198                               UINT32);
8199 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8200         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8201                               UINT8);
8202 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8203         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8204                               UINT8);
8205 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8206         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8207                               UINT32);
8208
8209 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8210         .f = cmd_write_reg_bit_field_parsed,
8211         .data = NULL,
8212         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8213                 "<reg_value>: "
8214                 "Set register bit field between bit_x and bit_y included",
8215         .tokens = {
8216                 (void *)&cmd_write_reg_bit_field_write,
8217                 (void *)&cmd_write_reg_bit_field_regfield,
8218                 (void *)&cmd_write_reg_bit_field_port_id,
8219                 (void *)&cmd_write_reg_bit_field_reg_off,
8220                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8221                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8222                 (void *)&cmd_write_reg_bit_field_value,
8223                 NULL,
8224         },
8225 };
8226
8227 /* *** WRITE PORT REGISTER BIT *** */
8228 struct cmd_write_reg_bit_result {
8229         cmdline_fixed_string_t write;
8230         cmdline_fixed_string_t regbit;
8231         portid_t port_id;
8232         uint32_t reg_off;
8233         uint8_t bit_pos;
8234         uint8_t value;
8235 };
8236
8237 static void
8238 cmd_write_reg_bit_parsed(void *parsed_result,
8239                          __rte_unused struct cmdline *cl,
8240                          __rte_unused void *data)
8241 {
8242         struct cmd_write_reg_bit_result *res = parsed_result;
8243         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8244 }
8245
8246 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8247         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8248                                  "write");
8249 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8250         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8251                                  regbit, "regbit");
8252 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8253         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8254 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8255         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8256 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8257         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8258 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8259         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8260
8261 cmdline_parse_inst_t cmd_write_reg_bit = {
8262         .f = cmd_write_reg_bit_parsed,
8263         .data = NULL,
8264         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8265                 "0 <= bit_x <= 31",
8266         .tokens = {
8267                 (void *)&cmd_write_reg_bit_write,
8268                 (void *)&cmd_write_reg_bit_regbit,
8269                 (void *)&cmd_write_reg_bit_port_id,
8270                 (void *)&cmd_write_reg_bit_reg_off,
8271                 (void *)&cmd_write_reg_bit_bit_pos,
8272                 (void *)&cmd_write_reg_bit_value,
8273                 NULL,
8274         },
8275 };
8276
8277 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8278 struct cmd_read_rxd_txd_result {
8279         cmdline_fixed_string_t read;
8280         cmdline_fixed_string_t rxd_txd;
8281         portid_t port_id;
8282         uint16_t queue_id;
8283         uint16_t desc_id;
8284 };
8285
8286 static void
8287 cmd_read_rxd_txd_parsed(void *parsed_result,
8288                         __rte_unused struct cmdline *cl,
8289                         __rte_unused void *data)
8290 {
8291         struct cmd_read_rxd_txd_result *res = parsed_result;
8292
8293         if (!strcmp(res->rxd_txd, "rxd"))
8294                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8295         else if (!strcmp(res->rxd_txd, "txd"))
8296                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8297 }
8298
8299 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8300         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8301 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8302         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8303                                  "rxd#txd");
8304 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8305         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8306 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8307         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8308 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8309         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8310
8311 cmdline_parse_inst_t cmd_read_rxd_txd = {
8312         .f = cmd_read_rxd_txd_parsed,
8313         .data = NULL,
8314         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8315         .tokens = {
8316                 (void *)&cmd_read_rxd_txd_read,
8317                 (void *)&cmd_read_rxd_txd_rxd_txd,
8318                 (void *)&cmd_read_rxd_txd_port_id,
8319                 (void *)&cmd_read_rxd_txd_queue_id,
8320                 (void *)&cmd_read_rxd_txd_desc_id,
8321                 NULL,
8322         },
8323 };
8324
8325 /* *** QUIT *** */
8326 struct cmd_quit_result {
8327         cmdline_fixed_string_t quit;
8328 };
8329
8330 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8331                             struct cmdline *cl,
8332                             __rte_unused void *data)
8333 {
8334         cmdline_quit(cl);
8335 }
8336
8337 cmdline_parse_token_string_t cmd_quit_quit =
8338         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8339
8340 cmdline_parse_inst_t cmd_quit = {
8341         .f = cmd_quit_parsed,
8342         .data = NULL,
8343         .help_str = "quit: Exit application",
8344         .tokens = {
8345                 (void *)&cmd_quit_quit,
8346                 NULL,
8347         },
8348 };
8349
8350 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8351 struct cmd_mac_addr_result {
8352         cmdline_fixed_string_t mac_addr_cmd;
8353         cmdline_fixed_string_t what;
8354         uint16_t port_num;
8355         struct rte_ether_addr address;
8356 };
8357
8358 static void cmd_mac_addr_parsed(void *parsed_result,
8359                 __rte_unused struct cmdline *cl,
8360                 __rte_unused void *data)
8361 {
8362         struct cmd_mac_addr_result *res = parsed_result;
8363         int ret;
8364
8365         if (strcmp(res->what, "add") == 0)
8366                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8367         else if (strcmp(res->what, "set") == 0)
8368                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8369                                                        &res->address);
8370         else
8371                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8372
8373         /* check the return value and print it if is < 0 */
8374         if(ret < 0)
8375                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8376
8377 }
8378
8379 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8380         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8381                                 "mac_addr");
8382 cmdline_parse_token_string_t cmd_mac_addr_what =
8383         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8384                                 "add#remove#set");
8385 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8386                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8387                                         UINT16);
8388 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8389                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8390
8391 cmdline_parse_inst_t cmd_mac_addr = {
8392         .f = cmd_mac_addr_parsed,
8393         .data = (void *)0,
8394         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8395                         "Add/Remove/Set MAC address on port_id",
8396         .tokens = {
8397                 (void *)&cmd_mac_addr_cmd,
8398                 (void *)&cmd_mac_addr_what,
8399                 (void *)&cmd_mac_addr_portnum,
8400                 (void *)&cmd_mac_addr_addr,
8401                 NULL,
8402         },
8403 };
8404
8405 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8406 struct cmd_eth_peer_result {
8407         cmdline_fixed_string_t set;
8408         cmdline_fixed_string_t eth_peer;
8409         portid_t port_id;
8410         cmdline_fixed_string_t peer_addr;
8411 };
8412
8413 static void cmd_set_eth_peer_parsed(void *parsed_result,
8414                         __rte_unused struct cmdline *cl,
8415                         __rte_unused void *data)
8416 {
8417                 struct cmd_eth_peer_result *res = parsed_result;
8418
8419                 if (test_done == 0) {
8420                         printf("Please stop forwarding first\n");
8421                         return;
8422                 }
8423                 if (!strcmp(res->eth_peer, "eth-peer")) {
8424                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8425                         fwd_config_setup();
8426                 }
8427 }
8428 cmdline_parse_token_string_t cmd_eth_peer_set =
8429         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8430 cmdline_parse_token_string_t cmd_eth_peer =
8431         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8432 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8433         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8434 cmdline_parse_token_string_t cmd_eth_peer_addr =
8435         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8436
8437 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8438         .f = cmd_set_eth_peer_parsed,
8439         .data = NULL,
8440         .help_str = "set eth-peer <port_id> <peer_mac>",
8441         .tokens = {
8442                 (void *)&cmd_eth_peer_set,
8443                 (void *)&cmd_eth_peer,
8444                 (void *)&cmd_eth_peer_port_id,
8445                 (void *)&cmd_eth_peer_addr,
8446                 NULL,
8447         },
8448 };
8449
8450 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8451 struct cmd_set_qmap_result {
8452         cmdline_fixed_string_t set;
8453         cmdline_fixed_string_t qmap;
8454         cmdline_fixed_string_t what;
8455         portid_t port_id;
8456         uint16_t queue_id;
8457         uint8_t map_value;
8458 };
8459
8460 static void
8461 cmd_set_qmap_parsed(void *parsed_result,
8462                        __rte_unused struct cmdline *cl,
8463                        __rte_unused void *data)
8464 {
8465         struct cmd_set_qmap_result *res = parsed_result;
8466         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8467
8468         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8469 }
8470
8471 cmdline_parse_token_string_t cmd_setqmap_set =
8472         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8473                                  set, "set");
8474 cmdline_parse_token_string_t cmd_setqmap_qmap =
8475         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8476                                  qmap, "stat_qmap");
8477 cmdline_parse_token_string_t cmd_setqmap_what =
8478         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8479                                  what, "tx#rx");
8480 cmdline_parse_token_num_t cmd_setqmap_portid =
8481         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8482                               port_id, UINT16);
8483 cmdline_parse_token_num_t cmd_setqmap_queueid =
8484         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8485                               queue_id, UINT16);
8486 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8487         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8488                               map_value, UINT8);
8489
8490 cmdline_parse_inst_t cmd_set_qmap = {
8491         .f = cmd_set_qmap_parsed,
8492         .data = NULL,
8493         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8494                 "Set statistics mapping value on tx|rx queue_id of port_id",
8495         .tokens = {
8496                 (void *)&cmd_setqmap_set,
8497                 (void *)&cmd_setqmap_qmap,
8498                 (void *)&cmd_setqmap_what,
8499                 (void *)&cmd_setqmap_portid,
8500                 (void *)&cmd_setqmap_queueid,
8501                 (void *)&cmd_setqmap_mapvalue,
8502                 NULL,
8503         },
8504 };
8505
8506 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8507 struct cmd_set_xstats_hide_zero_result {
8508         cmdline_fixed_string_t keyword;
8509         cmdline_fixed_string_t name;
8510         cmdline_fixed_string_t on_off;
8511 };
8512
8513 static void
8514 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8515                         __rte_unused struct cmdline *cl,
8516                         __rte_unused void *data)
8517 {
8518         struct cmd_set_xstats_hide_zero_result *res;
8519         uint16_t on_off = 0;
8520
8521         res = parsed_result;
8522         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8523         set_xstats_hide_zero(on_off);
8524 }
8525
8526 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8527         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8528                                  keyword, "set");
8529 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8530         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8531                                  name, "xstats-hide-zero");
8532 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8533         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8534                                  on_off, "on#off");
8535
8536 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8537         .f = cmd_set_xstats_hide_zero_parsed,
8538         .data = NULL,
8539         .help_str = "set xstats-hide-zero on|off",
8540         .tokens = {
8541                 (void *)&cmd_set_xstats_hide_zero_keyword,
8542                 (void *)&cmd_set_xstats_hide_zero_name,
8543                 (void *)&cmd_set_xstats_hide_zero_on_off,
8544                 NULL,
8545         },
8546 };
8547
8548 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8549 struct cmd_set_record_core_cycles_result {
8550         cmdline_fixed_string_t keyword;
8551         cmdline_fixed_string_t name;
8552         cmdline_fixed_string_t on_off;
8553 };
8554
8555 static void
8556 cmd_set_record_core_cycles_parsed(void *parsed_result,
8557                         __rte_unused struct cmdline *cl,
8558                         __rte_unused void *data)
8559 {
8560         struct cmd_set_record_core_cycles_result *res;
8561         uint16_t on_off = 0;
8562
8563         res = parsed_result;
8564         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8565         set_record_core_cycles(on_off);
8566 }
8567
8568 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8569         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8570                                  keyword, "set");
8571 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8572         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8573                                  name, "record-core-cycles");
8574 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8575         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8576                                  on_off, "on#off");
8577
8578 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8579         .f = cmd_set_record_core_cycles_parsed,
8580         .data = NULL,
8581         .help_str = "set record-core-cycles on|off",
8582         .tokens = {
8583                 (void *)&cmd_set_record_core_cycles_keyword,
8584                 (void *)&cmd_set_record_core_cycles_name,
8585                 (void *)&cmd_set_record_core_cycles_on_off,
8586                 NULL,
8587         },
8588 };
8589
8590 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8591 struct cmd_set_record_burst_stats_result {
8592         cmdline_fixed_string_t keyword;
8593         cmdline_fixed_string_t name;
8594         cmdline_fixed_string_t on_off;
8595 };
8596
8597 static void
8598 cmd_set_record_burst_stats_parsed(void *parsed_result,
8599                         __rte_unused struct cmdline *cl,
8600                         __rte_unused void *data)
8601 {
8602         struct cmd_set_record_burst_stats_result *res;
8603         uint16_t on_off = 0;
8604
8605         res = parsed_result;
8606         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8607         set_record_burst_stats(on_off);
8608 }
8609
8610 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8611         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8612                                  keyword, "set");
8613 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8614         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8615                                  name, "record-burst-stats");
8616 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8617         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8618                                  on_off, "on#off");
8619
8620 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8621         .f = cmd_set_record_burst_stats_parsed,
8622         .data = NULL,
8623         .help_str = "set record-burst-stats on|off",
8624         .tokens = {
8625                 (void *)&cmd_set_record_burst_stats_keyword,
8626                 (void *)&cmd_set_record_burst_stats_name,
8627                 (void *)&cmd_set_record_burst_stats_on_off,
8628                 NULL,
8629         },
8630 };
8631
8632 /* *** CONFIGURE UNICAST HASH TABLE *** */
8633 struct cmd_set_uc_hash_table {
8634         cmdline_fixed_string_t set;
8635         cmdline_fixed_string_t port;
8636         portid_t port_id;
8637         cmdline_fixed_string_t what;
8638         struct rte_ether_addr address;
8639         cmdline_fixed_string_t mode;
8640 };
8641
8642 static void
8643 cmd_set_uc_hash_parsed(void *parsed_result,
8644                        __rte_unused struct cmdline *cl,
8645                        __rte_unused void *data)
8646 {
8647         int ret=0;
8648         struct cmd_set_uc_hash_table *res = parsed_result;
8649
8650         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8651
8652         if (strcmp(res->what, "uta") == 0)
8653                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8654                                                 &res->address,(uint8_t)is_on);
8655         if (ret < 0)
8656                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8657
8658 }
8659
8660 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8661         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8662                                  set, "set");
8663 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8664         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8665                                  port, "port");
8666 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8667         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8668                               port_id, UINT16);
8669 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8670         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8671                                  what, "uta");
8672 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8673         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8674                                 address);
8675 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8676         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8677                                  mode, "on#off");
8678
8679 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8680         .f = cmd_set_uc_hash_parsed,
8681         .data = NULL,
8682         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8683         .tokens = {
8684                 (void *)&cmd_set_uc_hash_set,
8685                 (void *)&cmd_set_uc_hash_port,
8686                 (void *)&cmd_set_uc_hash_portid,
8687                 (void *)&cmd_set_uc_hash_what,
8688                 (void *)&cmd_set_uc_hash_mac,
8689                 (void *)&cmd_set_uc_hash_mode,
8690                 NULL,
8691         },
8692 };
8693
8694 struct cmd_set_uc_all_hash_table {
8695         cmdline_fixed_string_t set;
8696         cmdline_fixed_string_t port;
8697         portid_t port_id;
8698         cmdline_fixed_string_t what;
8699         cmdline_fixed_string_t value;
8700         cmdline_fixed_string_t mode;
8701 };
8702
8703 static void
8704 cmd_set_uc_all_hash_parsed(void *parsed_result,
8705                        __rte_unused struct cmdline *cl,
8706                        __rte_unused void *data)
8707 {
8708         int ret=0;
8709         struct cmd_set_uc_all_hash_table *res = parsed_result;
8710
8711         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8712
8713         if ((strcmp(res->what, "uta") == 0) &&
8714                 (strcmp(res->value, "all") == 0))
8715                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8716         if (ret < 0)
8717                 printf("bad unicast hash table parameter,"
8718                         "return code = %d \n", ret);
8719 }
8720
8721 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8722         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8723                                  set, "set");
8724 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8725         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8726                                  port, "port");
8727 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8728         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8729                               port_id, UINT16);
8730 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8731         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8732                                  what, "uta");
8733 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8734         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8735                                 value,"all");
8736 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8737         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8738                                  mode, "on#off");
8739
8740 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8741         .f = cmd_set_uc_all_hash_parsed,
8742         .data = NULL,
8743         .help_str = "set port <port_id> uta all on|off",
8744         .tokens = {
8745                 (void *)&cmd_set_uc_all_hash_set,
8746                 (void *)&cmd_set_uc_all_hash_port,
8747                 (void *)&cmd_set_uc_all_hash_portid,
8748                 (void *)&cmd_set_uc_all_hash_what,
8749                 (void *)&cmd_set_uc_all_hash_value,
8750                 (void *)&cmd_set_uc_all_hash_mode,
8751                 NULL,
8752         },
8753 };
8754
8755 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8756 struct cmd_set_vf_traffic {
8757         cmdline_fixed_string_t set;
8758         cmdline_fixed_string_t port;
8759         portid_t port_id;
8760         cmdline_fixed_string_t vf;
8761         uint8_t vf_id;
8762         cmdline_fixed_string_t what;
8763         cmdline_fixed_string_t mode;
8764 };
8765
8766 static void
8767 cmd_set_vf_traffic_parsed(void *parsed_result,
8768                        __rte_unused struct cmdline *cl,
8769                        __rte_unused void *data)
8770 {
8771         struct cmd_set_vf_traffic *res = parsed_result;
8772         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8773         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8774
8775         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8776 }
8777
8778 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8779         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8780                                  set, "set");
8781 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8782         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8783                                  port, "port");
8784 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8785         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8786                               port_id, UINT16);
8787 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8788         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8789                                  vf, "vf");
8790 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8791         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8792                               vf_id, UINT8);
8793 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8794         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8795                                  what, "tx#rx");
8796 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8797         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8798                                  mode, "on#off");
8799
8800 cmdline_parse_inst_t cmd_set_vf_traffic = {
8801         .f = cmd_set_vf_traffic_parsed,
8802         .data = NULL,
8803         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8804         .tokens = {
8805                 (void *)&cmd_setvf_traffic_set,
8806                 (void *)&cmd_setvf_traffic_port,
8807                 (void *)&cmd_setvf_traffic_portid,
8808                 (void *)&cmd_setvf_traffic_vf,
8809                 (void *)&cmd_setvf_traffic_vfid,
8810                 (void *)&cmd_setvf_traffic_what,
8811                 (void *)&cmd_setvf_traffic_mode,
8812                 NULL,
8813         },
8814 };
8815
8816 /* *** CONFIGURE VF RECEIVE MODE *** */
8817 struct cmd_set_vf_rxmode {
8818         cmdline_fixed_string_t set;
8819         cmdline_fixed_string_t port;
8820         portid_t port_id;
8821         cmdline_fixed_string_t vf;
8822         uint8_t vf_id;
8823         cmdline_fixed_string_t what;
8824         cmdline_fixed_string_t mode;
8825         cmdline_fixed_string_t on;
8826 };
8827
8828 static void
8829 cmd_set_vf_rxmode_parsed(void *parsed_result,
8830                        __rte_unused struct cmdline *cl,
8831                        __rte_unused void *data)
8832 {
8833         int ret = -ENOTSUP;
8834         uint16_t vf_rxmode = 0;
8835         struct cmd_set_vf_rxmode *res = parsed_result;
8836
8837         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8838         if (!strcmp(res->what,"rxmode")) {
8839                 if (!strcmp(res->mode, "AUPE"))
8840                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8841                 else if (!strcmp(res->mode, "ROPE"))
8842                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8843                 else if (!strcmp(res->mode, "BAM"))
8844                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8845                 else if (!strncmp(res->mode, "MPE",3))
8846                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8847         }
8848
8849         RTE_SET_USED(is_on);
8850
8851 #ifdef RTE_NET_IXGBE
8852         if (ret == -ENOTSUP)
8853                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8854                                                   vf_rxmode, (uint8_t)is_on);
8855 #endif
8856 #ifdef RTE_NET_BNXT
8857         if (ret == -ENOTSUP)
8858                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8859                                                  vf_rxmode, (uint8_t)is_on);
8860 #endif
8861         if (ret < 0)
8862                 printf("bad VF receive mode parameter, return code = %d \n",
8863                 ret);
8864 }
8865
8866 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8867         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8868                                  set, "set");
8869 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8870         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8871                                  port, "port");
8872 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8873         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8874                               port_id, UINT16);
8875 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8876         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8877                                  vf, "vf");
8878 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8879         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8880                               vf_id, UINT8);
8881 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8882         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8883                                  what, "rxmode");
8884 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8885         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8886                                  mode, "AUPE#ROPE#BAM#MPE");
8887 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8888         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8889                                  on, "on#off");
8890
8891 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8892         .f = cmd_set_vf_rxmode_parsed,
8893         .data = NULL,
8894         .help_str = "set port <port_id> vf <vf_id> rxmode "
8895                 "AUPE|ROPE|BAM|MPE on|off",
8896         .tokens = {
8897                 (void *)&cmd_set_vf_rxmode_set,
8898                 (void *)&cmd_set_vf_rxmode_port,
8899                 (void *)&cmd_set_vf_rxmode_portid,
8900                 (void *)&cmd_set_vf_rxmode_vf,
8901                 (void *)&cmd_set_vf_rxmode_vfid,
8902                 (void *)&cmd_set_vf_rxmode_what,
8903                 (void *)&cmd_set_vf_rxmode_mode,
8904                 (void *)&cmd_set_vf_rxmode_on,
8905                 NULL,
8906         },
8907 };
8908
8909 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8910 struct cmd_vf_mac_addr_result {
8911         cmdline_fixed_string_t mac_addr_cmd;
8912         cmdline_fixed_string_t what;
8913         cmdline_fixed_string_t port;
8914         uint16_t port_num;
8915         cmdline_fixed_string_t vf;
8916         uint8_t vf_num;
8917         struct rte_ether_addr address;
8918 };
8919
8920 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8921                 __rte_unused struct cmdline *cl,
8922                 __rte_unused void *data)
8923 {
8924         struct cmd_vf_mac_addr_result *res = parsed_result;
8925         int ret = -ENOTSUP;
8926
8927         if (strcmp(res->what, "add") != 0)
8928                 return;
8929
8930 #ifdef RTE_NET_I40E
8931         if (ret == -ENOTSUP)
8932                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8933                                                    &res->address);
8934 #endif
8935 #ifdef RTE_NET_BNXT
8936         if (ret == -ENOTSUP)
8937                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8938                                                 res->vf_num);
8939 #endif
8940
8941         if(ret < 0)
8942                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8943
8944 }
8945
8946 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8947         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8948                                 mac_addr_cmd,"mac_addr");
8949 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8950         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8951                                 what,"add");
8952 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8953         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8954                                 port,"port");
8955 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8956         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8957                                 port_num, UINT16);
8958 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8959         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8960                                 vf,"vf");
8961 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8962         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8963                                 vf_num, UINT8);
8964 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8965         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8966                                 address);
8967
8968 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8969         .f = cmd_vf_mac_addr_parsed,
8970         .data = (void *)0,
8971         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8972                 "Add MAC address filtering for a VF on port_id",
8973         .tokens = {
8974                 (void *)&cmd_vf_mac_addr_cmd,
8975                 (void *)&cmd_vf_mac_addr_what,
8976                 (void *)&cmd_vf_mac_addr_port,
8977                 (void *)&cmd_vf_mac_addr_portnum,
8978                 (void *)&cmd_vf_mac_addr_vf,
8979                 (void *)&cmd_vf_mac_addr_vfnum,
8980                 (void *)&cmd_vf_mac_addr_addr,
8981                 NULL,
8982         },
8983 };
8984
8985 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8986 struct cmd_vf_rx_vlan_filter {
8987         cmdline_fixed_string_t rx_vlan;
8988         cmdline_fixed_string_t what;
8989         uint16_t vlan_id;
8990         cmdline_fixed_string_t port;
8991         portid_t port_id;
8992         cmdline_fixed_string_t vf;
8993         uint64_t vf_mask;
8994 };
8995
8996 static void
8997 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8998                           __rte_unused struct cmdline *cl,
8999                           __rte_unused void *data)
9000 {
9001         struct cmd_vf_rx_vlan_filter *res = parsed_result;
9002         int ret = -ENOTSUP;
9003
9004         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9005
9006 #ifdef RTE_NET_IXGBE
9007         if (ret == -ENOTSUP)
9008                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9009                                 res->vlan_id, res->vf_mask, is_add);
9010 #endif
9011 #ifdef RTE_NET_I40E
9012         if (ret == -ENOTSUP)
9013                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9014                                 res->vlan_id, res->vf_mask, is_add);
9015 #endif
9016 #ifdef RTE_NET_BNXT
9017         if (ret == -ENOTSUP)
9018                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9019                                 res->vlan_id, res->vf_mask, is_add);
9020 #endif
9021
9022         switch (ret) {
9023         case 0:
9024                 break;
9025         case -EINVAL:
9026                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
9027                                 res->vlan_id, res->vf_mask);
9028                 break;
9029         case -ENODEV:
9030                 printf("invalid port_id %d\n", res->port_id);
9031                 break;
9032         case -ENOTSUP:
9033                 printf("function not implemented or supported\n");
9034                 break;
9035         default:
9036                 printf("programming error: (%s)\n", strerror(-ret));
9037         }
9038 }
9039
9040 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9041         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9042                                  rx_vlan, "rx_vlan");
9043 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9044         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9045                                  what, "add#rm");
9046 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9047         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9048                               vlan_id, UINT16);
9049 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9050         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9051                                  port, "port");
9052 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9053         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9054                               port_id, UINT16);
9055 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9056         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9057                                  vf, "vf");
9058 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9059         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9060                               vf_mask, UINT64);
9061
9062 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9063         .f = cmd_vf_rx_vlan_filter_parsed,
9064         .data = NULL,
9065         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9066                 "(vf_mask = hexadecimal VF mask)",
9067         .tokens = {
9068                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9069                 (void *)&cmd_vf_rx_vlan_filter_what,
9070                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9071                 (void *)&cmd_vf_rx_vlan_filter_port,
9072                 (void *)&cmd_vf_rx_vlan_filter_portid,
9073                 (void *)&cmd_vf_rx_vlan_filter_vf,
9074                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9075                 NULL,
9076         },
9077 };
9078
9079 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9080 struct cmd_queue_rate_limit_result {
9081         cmdline_fixed_string_t set;
9082         cmdline_fixed_string_t port;
9083         uint16_t port_num;
9084         cmdline_fixed_string_t queue;
9085         uint8_t queue_num;
9086         cmdline_fixed_string_t rate;
9087         uint16_t rate_num;
9088 };
9089
9090 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9091                 __rte_unused struct cmdline *cl,
9092                 __rte_unused void *data)
9093 {
9094         struct cmd_queue_rate_limit_result *res = parsed_result;
9095         int ret = 0;
9096
9097         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9098                 && (strcmp(res->queue, "queue") == 0)
9099                 && (strcmp(res->rate, "rate") == 0))
9100                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9101                                         res->rate_num);
9102         if (ret < 0)
9103                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9104
9105 }
9106
9107 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9108         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9109                                 set, "set");
9110 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9111         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9112                                 port, "port");
9113 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9114         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9115                                 port_num, UINT16);
9116 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9117         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9118                                 queue, "queue");
9119 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9120         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9121                                 queue_num, UINT8);
9122 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9123         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9124                                 rate, "rate");
9125 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9126         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9127                                 rate_num, UINT16);
9128
9129 cmdline_parse_inst_t cmd_queue_rate_limit = {
9130         .f = cmd_queue_rate_limit_parsed,
9131         .data = (void *)0,
9132         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9133                 "Set rate limit for a queue on port_id",
9134         .tokens = {
9135                 (void *)&cmd_queue_rate_limit_set,
9136                 (void *)&cmd_queue_rate_limit_port,
9137                 (void *)&cmd_queue_rate_limit_portnum,
9138                 (void *)&cmd_queue_rate_limit_queue,
9139                 (void *)&cmd_queue_rate_limit_queuenum,
9140                 (void *)&cmd_queue_rate_limit_rate,
9141                 (void *)&cmd_queue_rate_limit_ratenum,
9142                 NULL,
9143         },
9144 };
9145
9146 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9147 struct cmd_vf_rate_limit_result {
9148         cmdline_fixed_string_t set;
9149         cmdline_fixed_string_t port;
9150         uint16_t port_num;
9151         cmdline_fixed_string_t vf;
9152         uint8_t vf_num;
9153         cmdline_fixed_string_t rate;
9154         uint16_t rate_num;
9155         cmdline_fixed_string_t q_msk;
9156         uint64_t q_msk_val;
9157 };
9158
9159 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9160                 __rte_unused struct cmdline *cl,
9161                 __rte_unused void *data)
9162 {
9163         struct cmd_vf_rate_limit_result *res = parsed_result;
9164         int ret = 0;
9165
9166         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9167                 && (strcmp(res->vf, "vf") == 0)
9168                 && (strcmp(res->rate, "rate") == 0)
9169                 && (strcmp(res->q_msk, "queue_mask") == 0))
9170                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9171                                         res->rate_num, res->q_msk_val);
9172         if (ret < 0)
9173                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9174
9175 }
9176
9177 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9178         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9179                                 set, "set");
9180 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9181         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9182                                 port, "port");
9183 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9184         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9185                                 port_num, UINT16);
9186 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9187         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9188                                 vf, "vf");
9189 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9190         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9191                                 vf_num, UINT8);
9192 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9193         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9194                                 rate, "rate");
9195 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9196         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9197                                 rate_num, UINT16);
9198 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9199         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9200                                 q_msk, "queue_mask");
9201 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9202         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9203                                 q_msk_val, UINT64);
9204
9205 cmdline_parse_inst_t cmd_vf_rate_limit = {
9206         .f = cmd_vf_rate_limit_parsed,
9207         .data = (void *)0,
9208         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9209                 "queue_mask <queue_mask_value>: "
9210                 "Set rate limit for queues of VF on port_id",
9211         .tokens = {
9212                 (void *)&cmd_vf_rate_limit_set,
9213                 (void *)&cmd_vf_rate_limit_port,
9214                 (void *)&cmd_vf_rate_limit_portnum,
9215                 (void *)&cmd_vf_rate_limit_vf,
9216                 (void *)&cmd_vf_rate_limit_vfnum,
9217                 (void *)&cmd_vf_rate_limit_rate,
9218                 (void *)&cmd_vf_rate_limit_ratenum,
9219                 (void *)&cmd_vf_rate_limit_q_msk,
9220                 (void *)&cmd_vf_rate_limit_q_msk_val,
9221                 NULL,
9222         },
9223 };
9224
9225 /* *** ADD TUNNEL FILTER OF A PORT *** */
9226 struct cmd_tunnel_filter_result {
9227         cmdline_fixed_string_t cmd;
9228         cmdline_fixed_string_t what;
9229         portid_t port_id;
9230         struct rte_ether_addr outer_mac;
9231         struct rte_ether_addr inner_mac;
9232         cmdline_ipaddr_t ip_value;
9233         uint16_t inner_vlan;
9234         cmdline_fixed_string_t tunnel_type;
9235         cmdline_fixed_string_t filter_type;
9236         uint32_t tenant_id;
9237         uint16_t queue_num;
9238 };
9239
9240 static void
9241 cmd_tunnel_filter_parsed(void *parsed_result,
9242                           __rte_unused struct cmdline *cl,
9243                           __rte_unused void *data)
9244 {
9245         struct cmd_tunnel_filter_result *res = parsed_result;
9246         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9247         int ret = 0;
9248
9249         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9250
9251         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9252         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9253         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9254
9255         if (res->ip_value.family == AF_INET) {
9256                 tunnel_filter_conf.ip_addr.ipv4_addr =
9257                         res->ip_value.addr.ipv4.s_addr;
9258                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9259         } else {
9260                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9261                         &(res->ip_value.addr.ipv6),
9262                         sizeof(struct in6_addr));
9263                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9264         }
9265
9266         if (!strcmp(res->filter_type, "imac-ivlan"))
9267                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9268         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9269                 tunnel_filter_conf.filter_type =
9270                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9271         else if (!strcmp(res->filter_type, "imac-tenid"))
9272                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9273         else if (!strcmp(res->filter_type, "imac"))
9274                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9275         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9276                 tunnel_filter_conf.filter_type =
9277                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9278         else if (!strcmp(res->filter_type, "oip"))
9279                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9280         else if (!strcmp(res->filter_type, "iip"))
9281                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9282         else {
9283                 printf("The filter type is not supported");
9284                 return;
9285         }
9286
9287         if (!strcmp(res->tunnel_type, "vxlan"))
9288                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9289         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9290                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9291         else if (!strcmp(res->tunnel_type, "nvgre"))
9292                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9293         else if (!strcmp(res->tunnel_type, "ipingre"))
9294                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9295         else {
9296                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9297                 return;
9298         }
9299
9300         tunnel_filter_conf.tenant_id = res->tenant_id;
9301         tunnel_filter_conf.queue_id = res->queue_num;
9302         if (!strcmp(res->what, "add"))
9303                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9304                                         RTE_ETH_FILTER_TUNNEL,
9305                                         RTE_ETH_FILTER_ADD,
9306                                         &tunnel_filter_conf);
9307         else
9308                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9309                                         RTE_ETH_FILTER_TUNNEL,
9310                                         RTE_ETH_FILTER_DELETE,
9311                                         &tunnel_filter_conf);
9312         if (ret < 0)
9313                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9314                                 strerror(-ret));
9315
9316 }
9317 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9318         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9319         cmd, "tunnel_filter");
9320 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9321         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9322         what, "add#rm");
9323 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9324         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9325         port_id, UINT16);
9326 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9327         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9328         outer_mac);
9329 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9330         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9331         inner_mac);
9332 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9333         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9334         inner_vlan, UINT16);
9335 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9336         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9337         ip_value);
9338 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9339         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9340         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9341
9342 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9343         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9344         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9345                 "imac#omac-imac-tenid");
9346 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9347         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9348         tenant_id, UINT32);
9349 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9350         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9351         queue_num, UINT16);
9352
9353 cmdline_parse_inst_t cmd_tunnel_filter = {
9354         .f = cmd_tunnel_filter_parsed,
9355         .data = (void *)0,
9356         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9357                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9358                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9359                 "<queue_id>: Add/Rm tunnel filter of a port",
9360         .tokens = {
9361                 (void *)&cmd_tunnel_filter_cmd,
9362                 (void *)&cmd_tunnel_filter_what,
9363                 (void *)&cmd_tunnel_filter_port_id,
9364                 (void *)&cmd_tunnel_filter_outer_mac,
9365                 (void *)&cmd_tunnel_filter_inner_mac,
9366                 (void *)&cmd_tunnel_filter_ip_value,
9367                 (void *)&cmd_tunnel_filter_innner_vlan,
9368                 (void *)&cmd_tunnel_filter_tunnel_type,
9369                 (void *)&cmd_tunnel_filter_filter_type,
9370                 (void *)&cmd_tunnel_filter_tenant_id,
9371                 (void *)&cmd_tunnel_filter_queue_num,
9372                 NULL,
9373         },
9374 };
9375
9376 /* *** CONFIGURE TUNNEL UDP PORT *** */
9377 struct cmd_tunnel_udp_config {
9378         cmdline_fixed_string_t cmd;
9379         cmdline_fixed_string_t what;
9380         uint16_t udp_port;
9381         portid_t port_id;
9382 };
9383
9384 static void
9385 cmd_tunnel_udp_config_parsed(void *parsed_result,
9386                           __rte_unused struct cmdline *cl,
9387                           __rte_unused void *data)
9388 {
9389         struct cmd_tunnel_udp_config *res = parsed_result;
9390         struct rte_eth_udp_tunnel tunnel_udp;
9391         int ret;
9392
9393         tunnel_udp.udp_port = res->udp_port;
9394
9395         if (!strcmp(res->cmd, "rx_vxlan_port"))
9396                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9397
9398         if (!strcmp(res->what, "add"))
9399                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9400                                                       &tunnel_udp);
9401         else
9402                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9403                                                          &tunnel_udp);
9404
9405         if (ret < 0)
9406                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9407 }
9408
9409 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9410         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9411                                 cmd, "rx_vxlan_port");
9412 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9413         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9414                                 what, "add#rm");
9415 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9416         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9417                                 udp_port, UINT16);
9418 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9419         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9420                                 port_id, UINT16);
9421
9422 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9423         .f = cmd_tunnel_udp_config_parsed,
9424         .data = (void *)0,
9425         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9426                 "Add/Remove a tunneling UDP port filter",
9427         .tokens = {
9428                 (void *)&cmd_tunnel_udp_config_cmd,
9429                 (void *)&cmd_tunnel_udp_config_what,
9430                 (void *)&cmd_tunnel_udp_config_udp_port,
9431                 (void *)&cmd_tunnel_udp_config_port_id,
9432                 NULL,
9433         },
9434 };
9435
9436 struct cmd_config_tunnel_udp_port {
9437         cmdline_fixed_string_t port;
9438         cmdline_fixed_string_t config;
9439         portid_t port_id;
9440         cmdline_fixed_string_t udp_tunnel_port;
9441         cmdline_fixed_string_t action;
9442         cmdline_fixed_string_t tunnel_type;
9443         uint16_t udp_port;
9444 };
9445
9446 static void
9447 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9448                                __rte_unused struct cmdline *cl,
9449                                __rte_unused void *data)
9450 {
9451         struct cmd_config_tunnel_udp_port *res = parsed_result;
9452         struct rte_eth_udp_tunnel tunnel_udp;
9453         int ret = 0;
9454
9455         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9456                 return;
9457
9458         tunnel_udp.udp_port = res->udp_port;
9459
9460         if (!strcmp(res->tunnel_type, "vxlan")) {
9461                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9462         } else if (!strcmp(res->tunnel_type, "geneve")) {
9463                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9464         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9465                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9466         } else {
9467                 printf("Invalid tunnel type\n");
9468                 return;
9469         }
9470
9471         if (!strcmp(res->action, "add"))
9472                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9473                                                       &tunnel_udp);
9474         else
9475                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9476                                                          &tunnel_udp);
9477
9478         if (ret < 0)
9479                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9480 }
9481
9482 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9483         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9484                                  "port");
9485 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9486         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9487                                  "config");
9488 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9489         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9490                               UINT16);
9491 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9492         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9493                                  udp_tunnel_port,
9494                                  "udp_tunnel_port");
9495 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9496         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9497                                  "add#rm");
9498 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9499         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9500                                  "vxlan#geneve#vxlan-gpe");
9501 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9502         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9503                               UINT16);
9504
9505 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9506         .f = cmd_cfg_tunnel_udp_port_parsed,
9507         .data = NULL,
9508         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9509         .tokens = {
9510                 (void *)&cmd_config_tunnel_udp_port_port,
9511                 (void *)&cmd_config_tunnel_udp_port_config,
9512                 (void *)&cmd_config_tunnel_udp_port_port_id,
9513                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9514                 (void *)&cmd_config_tunnel_udp_port_action,
9515                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9516                 (void *)&cmd_config_tunnel_udp_port_value,
9517                 NULL,
9518         },
9519 };
9520
9521 /* *** GLOBAL CONFIG *** */
9522 struct cmd_global_config_result {
9523         cmdline_fixed_string_t cmd;
9524         portid_t port_id;
9525         cmdline_fixed_string_t cfg_type;
9526         uint8_t len;
9527 };
9528
9529 static void
9530 cmd_global_config_parsed(void *parsed_result,
9531                          __rte_unused struct cmdline *cl,
9532                          __rte_unused void *data)
9533 {
9534         struct cmd_global_config_result *res = parsed_result;
9535         struct rte_eth_global_cfg conf;
9536         int ret;
9537
9538         memset(&conf, 0, sizeof(conf));
9539         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9540         conf.cfg.gre_key_len = res->len;
9541         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9542                                       RTE_ETH_FILTER_SET, &conf);
9543 #ifdef RTE_NET_I40E
9544         if (ret == -ENOTSUP)
9545                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9546 #endif
9547         if (ret != 0)
9548                 printf("Global config error\n");
9549 }
9550
9551 cmdline_parse_token_string_t cmd_global_config_cmd =
9552         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9553                 "global_config");
9554 cmdline_parse_token_num_t cmd_global_config_port_id =
9555         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9556                                UINT16);
9557 cmdline_parse_token_string_t cmd_global_config_type =
9558         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9559                 cfg_type, "gre-key-len");
9560 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9561         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9562                 len, UINT8);
9563
9564 cmdline_parse_inst_t cmd_global_config = {
9565         .f = cmd_global_config_parsed,
9566         .data = (void *)NULL,
9567         .help_str = "global_config <port_id> gre-key-len <key_len>",
9568         .tokens = {
9569                 (void *)&cmd_global_config_cmd,
9570                 (void *)&cmd_global_config_port_id,
9571                 (void *)&cmd_global_config_type,
9572                 (void *)&cmd_global_config_gre_key_len,
9573                 NULL,
9574         },
9575 };
9576
9577 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9578 struct cmd_set_mirror_mask_result {
9579         cmdline_fixed_string_t set;
9580         cmdline_fixed_string_t port;
9581         portid_t port_id;
9582         cmdline_fixed_string_t mirror;
9583         uint8_t rule_id;
9584         cmdline_fixed_string_t what;
9585         cmdline_fixed_string_t value;
9586         cmdline_fixed_string_t dstpool;
9587         uint8_t dstpool_id;
9588         cmdline_fixed_string_t on;
9589 };
9590
9591 cmdline_parse_token_string_t cmd_mirror_mask_set =
9592         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9593                                 set, "set");
9594 cmdline_parse_token_string_t cmd_mirror_mask_port =
9595         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9596                                 port, "port");
9597 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9598         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9599                                 port_id, UINT16);
9600 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9601         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9602                                 mirror, "mirror-rule");
9603 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9604         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9605                                 rule_id, UINT8);
9606 cmdline_parse_token_string_t cmd_mirror_mask_what =
9607         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9608                                 what, "pool-mirror-up#pool-mirror-down"
9609                                       "#vlan-mirror");
9610 cmdline_parse_token_string_t cmd_mirror_mask_value =
9611         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9612                                 value, NULL);
9613 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9614         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9615                                 dstpool, "dst-pool");
9616 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9617         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9618                                 dstpool_id, UINT8);
9619 cmdline_parse_token_string_t cmd_mirror_mask_on =
9620         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9621                                 on, "on#off");
9622
9623 static void
9624 cmd_set_mirror_mask_parsed(void *parsed_result,
9625                        __rte_unused struct cmdline *cl,
9626                        __rte_unused void *data)
9627 {
9628         int ret,nb_item,i;
9629         struct cmd_set_mirror_mask_result *res = parsed_result;
9630         struct rte_eth_mirror_conf mr_conf;
9631
9632         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9633
9634         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9635
9636         mr_conf.dst_pool = res->dstpool_id;
9637
9638         if (!strcmp(res->what, "pool-mirror-up")) {
9639                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9640                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9641         } else if (!strcmp(res->what, "pool-mirror-down")) {
9642                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9643                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9644         } else if (!strcmp(res->what, "vlan-mirror")) {
9645                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9646                 nb_item = parse_item_list(res->value, "vlan",
9647                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9648                 if (nb_item <= 0)
9649                         return;
9650
9651                 for (i = 0; i < nb_item; i++) {
9652                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9653                                 printf("Invalid vlan_id: must be < 4096\n");
9654                                 return;
9655                         }
9656
9657                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9658                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9659                 }
9660         }
9661
9662         if (!strcmp(res->on, "on"))
9663                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9664                                                 res->rule_id, 1);
9665         else
9666                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9667                                                 res->rule_id, 0);
9668         if (ret < 0)
9669                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9670 }
9671
9672 cmdline_parse_inst_t cmd_set_mirror_mask = {
9673                 .f = cmd_set_mirror_mask_parsed,
9674                 .data = NULL,
9675                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9676                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9677                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9678                 .tokens = {
9679                         (void *)&cmd_mirror_mask_set,
9680                         (void *)&cmd_mirror_mask_port,
9681                         (void *)&cmd_mirror_mask_portid,
9682                         (void *)&cmd_mirror_mask_mirror,
9683                         (void *)&cmd_mirror_mask_ruleid,
9684                         (void *)&cmd_mirror_mask_what,
9685                         (void *)&cmd_mirror_mask_value,
9686                         (void *)&cmd_mirror_mask_dstpool,
9687                         (void *)&cmd_mirror_mask_poolid,
9688                         (void *)&cmd_mirror_mask_on,
9689                         NULL,
9690                 },
9691 };
9692
9693 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9694 struct cmd_set_mirror_link_result {
9695         cmdline_fixed_string_t set;
9696         cmdline_fixed_string_t port;
9697         portid_t port_id;
9698         cmdline_fixed_string_t mirror;
9699         uint8_t rule_id;
9700         cmdline_fixed_string_t what;
9701         cmdline_fixed_string_t dstpool;
9702         uint8_t dstpool_id;
9703         cmdline_fixed_string_t on;
9704 };
9705
9706 cmdline_parse_token_string_t cmd_mirror_link_set =
9707         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9708                                  set, "set");
9709 cmdline_parse_token_string_t cmd_mirror_link_port =
9710         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9711                                 port, "port");
9712 cmdline_parse_token_num_t cmd_mirror_link_portid =
9713         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9714                                 port_id, UINT16);
9715 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9716         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9717                                 mirror, "mirror-rule");
9718 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9719         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9720                             rule_id, UINT8);
9721 cmdline_parse_token_string_t cmd_mirror_link_what =
9722         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9723                                 what, "uplink-mirror#downlink-mirror");
9724 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9725         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9726                                 dstpool, "dst-pool");
9727 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9728         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9729                                 dstpool_id, UINT8);
9730 cmdline_parse_token_string_t cmd_mirror_link_on =
9731         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9732                                 on, "on#off");
9733
9734 static void
9735 cmd_set_mirror_link_parsed(void *parsed_result,
9736                        __rte_unused struct cmdline *cl,
9737                        __rte_unused void *data)
9738 {
9739         int ret;
9740         struct cmd_set_mirror_link_result *res = parsed_result;
9741         struct rte_eth_mirror_conf mr_conf;
9742
9743         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9744         if (!strcmp(res->what, "uplink-mirror"))
9745                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9746         else
9747                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9748
9749         mr_conf.dst_pool = res->dstpool_id;
9750
9751         if (!strcmp(res->on, "on"))
9752                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9753                                                 res->rule_id, 1);
9754         else
9755                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9756                                                 res->rule_id, 0);
9757
9758         /* check the return value and print it if is < 0 */
9759         if (ret < 0)
9760                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9761
9762 }
9763
9764 cmdline_parse_inst_t cmd_set_mirror_link = {
9765                 .f = cmd_set_mirror_link_parsed,
9766                 .data = NULL,
9767                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9768                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9769                 .tokens = {
9770                         (void *)&cmd_mirror_link_set,
9771                         (void *)&cmd_mirror_link_port,
9772                         (void *)&cmd_mirror_link_portid,
9773                         (void *)&cmd_mirror_link_mirror,
9774                         (void *)&cmd_mirror_link_ruleid,
9775                         (void *)&cmd_mirror_link_what,
9776                         (void *)&cmd_mirror_link_dstpool,
9777                         (void *)&cmd_mirror_link_poolid,
9778                         (void *)&cmd_mirror_link_on,
9779                         NULL,
9780                 },
9781 };
9782
9783 /* *** RESET VM MIRROR RULE *** */
9784 struct cmd_rm_mirror_rule_result {
9785         cmdline_fixed_string_t reset;
9786         cmdline_fixed_string_t port;
9787         portid_t port_id;
9788         cmdline_fixed_string_t mirror;
9789         uint8_t rule_id;
9790 };
9791
9792 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9793         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9794                                  reset, "reset");
9795 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9796         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9797                                 port, "port");
9798 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9799         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9800                                 port_id, UINT16);
9801 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9802         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9803                                 mirror, "mirror-rule");
9804 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9805         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9806                                 rule_id, UINT8);
9807
9808 static void
9809 cmd_reset_mirror_rule_parsed(void *parsed_result,
9810                        __rte_unused struct cmdline *cl,
9811                        __rte_unused void *data)
9812 {
9813         int ret;
9814         struct cmd_set_mirror_link_result *res = parsed_result;
9815         /* check rule_id */
9816         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9817         if(ret < 0)
9818                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9819 }
9820
9821 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9822                 .f = cmd_reset_mirror_rule_parsed,
9823                 .data = NULL,
9824                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9825                 .tokens = {
9826                         (void *)&cmd_rm_mirror_rule_reset,
9827                         (void *)&cmd_rm_mirror_rule_port,
9828                         (void *)&cmd_rm_mirror_rule_portid,
9829                         (void *)&cmd_rm_mirror_rule_mirror,
9830                         (void *)&cmd_rm_mirror_rule_ruleid,
9831                         NULL,
9832                 },
9833 };
9834
9835 /* ******************************************************************************** */
9836
9837 struct cmd_dump_result {
9838         cmdline_fixed_string_t dump;
9839 };
9840
9841 static void
9842 dump_struct_sizes(void)
9843 {
9844 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9845         DUMP_SIZE(struct rte_mbuf);
9846         DUMP_SIZE(struct rte_mempool);
9847         DUMP_SIZE(struct rte_ring);
9848 #undef DUMP_SIZE
9849 }
9850
9851
9852 /* Dump the socket memory statistics on console */
9853 static void
9854 dump_socket_mem(FILE *f)
9855 {
9856         struct rte_malloc_socket_stats socket_stats;
9857         unsigned int i;
9858         size_t total = 0;
9859         size_t alloc = 0;
9860         size_t free = 0;
9861         unsigned int n_alloc = 0;
9862         unsigned int n_free = 0;
9863         static size_t last_allocs;
9864         static size_t last_total;
9865
9866
9867         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9868                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9869                     !socket_stats.heap_totalsz_bytes)
9870                         continue;
9871                 total += socket_stats.heap_totalsz_bytes;
9872                 alloc += socket_stats.heap_allocsz_bytes;
9873                 free += socket_stats.heap_freesz_bytes;
9874                 n_alloc += socket_stats.alloc_count;
9875                 n_free += socket_stats.free_count;
9876                 fprintf(f,
9877                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9878                         i,
9879                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9880                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9881                         (double)socket_stats.heap_allocsz_bytes * 100 /
9882                         (double)socket_stats.heap_totalsz_bytes,
9883                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9884                         socket_stats.alloc_count,
9885                         socket_stats.free_count);
9886         }
9887         fprintf(f,
9888                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9889                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9890                 (double)alloc * 100 / (double)total,
9891                 (double)free / (1024 * 1024),
9892                 n_alloc, n_free);
9893         if (last_allocs)
9894                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9895                         ((double)total - (double)last_total) / (1024 * 1024),
9896                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9897         last_allocs = alloc;
9898         last_total = total;
9899 }
9900
9901 static void cmd_dump_parsed(void *parsed_result,
9902                             __rte_unused struct cmdline *cl,
9903                             __rte_unused void *data)
9904 {
9905         struct cmd_dump_result *res = parsed_result;
9906
9907         if (!strcmp(res->dump, "dump_physmem"))
9908                 rte_dump_physmem_layout(stdout);
9909         else if (!strcmp(res->dump, "dump_socket_mem"))
9910                 dump_socket_mem(stdout);
9911         else if (!strcmp(res->dump, "dump_memzone"))
9912                 rte_memzone_dump(stdout);
9913         else if (!strcmp(res->dump, "dump_struct_sizes"))
9914                 dump_struct_sizes();
9915         else if (!strcmp(res->dump, "dump_ring"))
9916                 rte_ring_list_dump(stdout);
9917         else if (!strcmp(res->dump, "dump_mempool"))
9918                 rte_mempool_list_dump(stdout);
9919         else if (!strcmp(res->dump, "dump_devargs"))
9920                 rte_devargs_dump(stdout);
9921         else if (!strcmp(res->dump, "dump_log_types"))
9922                 rte_log_dump(stdout);
9923 }
9924
9925 cmdline_parse_token_string_t cmd_dump_dump =
9926         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9927                 "dump_physmem#"
9928                 "dump_memzone#"
9929                 "dump_socket_mem#"
9930                 "dump_struct_sizes#"
9931                 "dump_ring#"
9932                 "dump_mempool#"
9933                 "dump_devargs#"
9934                 "dump_log_types");
9935
9936 cmdline_parse_inst_t cmd_dump = {
9937         .f = cmd_dump_parsed,  /* function to call */
9938         .data = NULL,      /* 2nd arg of func */
9939         .help_str = "Dump status",
9940         .tokens = {        /* token list, NULL terminated */
9941                 (void *)&cmd_dump_dump,
9942                 NULL,
9943         },
9944 };
9945
9946 /* ******************************************************************************** */
9947
9948 struct cmd_dump_one_result {
9949         cmdline_fixed_string_t dump;
9950         cmdline_fixed_string_t name;
9951 };
9952
9953 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9954                                 __rte_unused void *data)
9955 {
9956         struct cmd_dump_one_result *res = parsed_result;
9957
9958         if (!strcmp(res->dump, "dump_ring")) {
9959                 struct rte_ring *r;
9960                 r = rte_ring_lookup(res->name);
9961                 if (r == NULL) {
9962                         cmdline_printf(cl, "Cannot find ring\n");
9963                         return;
9964                 }
9965                 rte_ring_dump(stdout, r);
9966         } else if (!strcmp(res->dump, "dump_mempool")) {
9967                 struct rte_mempool *mp;
9968                 mp = rte_mempool_lookup(res->name);
9969                 if (mp == NULL) {
9970                         cmdline_printf(cl, "Cannot find mempool\n");
9971                         return;
9972                 }
9973                 rte_mempool_dump(stdout, mp);
9974         }
9975 }
9976
9977 cmdline_parse_token_string_t cmd_dump_one_dump =
9978         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9979                                  "dump_ring#dump_mempool");
9980
9981 cmdline_parse_token_string_t cmd_dump_one_name =
9982         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9983
9984 cmdline_parse_inst_t cmd_dump_one = {
9985         .f = cmd_dump_one_parsed,  /* function to call */
9986         .data = NULL,      /* 2nd arg of func */
9987         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9988         .tokens = {        /* token list, NULL terminated */
9989                 (void *)&cmd_dump_one_dump,
9990                 (void *)&cmd_dump_one_name,
9991                 NULL,
9992         },
9993 };
9994
9995 /* *** Add/Del syn filter *** */
9996 struct cmd_syn_filter_result {
9997         cmdline_fixed_string_t filter;
9998         portid_t port_id;
9999         cmdline_fixed_string_t ops;
10000         cmdline_fixed_string_t priority;
10001         cmdline_fixed_string_t high;
10002         cmdline_fixed_string_t queue;
10003         uint16_t queue_id;
10004 };
10005
10006 static void
10007 cmd_syn_filter_parsed(void *parsed_result,
10008                         __rte_unused struct cmdline *cl,
10009                         __rte_unused void *data)
10010 {
10011         struct cmd_syn_filter_result *res = parsed_result;
10012         struct rte_eth_syn_filter syn_filter;
10013         int ret = 0;
10014
10015         ret = rte_eth_dev_filter_supported(res->port_id,
10016                                         RTE_ETH_FILTER_SYN);
10017         if (ret < 0) {
10018                 printf("syn filter is not supported on port %u.\n",
10019                                 res->port_id);
10020                 return;
10021         }
10022
10023         memset(&syn_filter, 0, sizeof(syn_filter));
10024
10025         if (!strcmp(res->ops, "add")) {
10026                 if (!strcmp(res->high, "high"))
10027                         syn_filter.hig_pri = 1;
10028                 else
10029                         syn_filter.hig_pri = 0;
10030
10031                 syn_filter.queue = res->queue_id;
10032                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10033                                                 RTE_ETH_FILTER_SYN,
10034                                                 RTE_ETH_FILTER_ADD,
10035                                                 &syn_filter);
10036         } else
10037                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10038                                                 RTE_ETH_FILTER_SYN,
10039                                                 RTE_ETH_FILTER_DELETE,
10040                                                 &syn_filter);
10041
10042         if (ret < 0)
10043                 printf("syn filter programming error: (%s)\n",
10044                                 strerror(-ret));
10045 }
10046
10047 cmdline_parse_token_string_t cmd_syn_filter_filter =
10048         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10049         filter, "syn_filter");
10050 cmdline_parse_token_num_t cmd_syn_filter_port_id =
10051         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10052         port_id, UINT16);
10053 cmdline_parse_token_string_t cmd_syn_filter_ops =
10054         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10055         ops, "add#del");
10056 cmdline_parse_token_string_t cmd_syn_filter_priority =
10057         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10058                                 priority, "priority");
10059 cmdline_parse_token_string_t cmd_syn_filter_high =
10060         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10061                                 high, "high#low");
10062 cmdline_parse_token_string_t cmd_syn_filter_queue =
10063         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10064                                 queue, "queue");
10065 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
10066         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10067                                 queue_id, UINT16);
10068
10069 cmdline_parse_inst_t cmd_syn_filter = {
10070         .f = cmd_syn_filter_parsed,
10071         .data = NULL,
10072         .help_str = "syn_filter <port_id> add|del priority high|low queue "
10073                 "<queue_id>: Add/Delete syn filter",
10074         .tokens = {
10075                 (void *)&cmd_syn_filter_filter,
10076                 (void *)&cmd_syn_filter_port_id,
10077                 (void *)&cmd_syn_filter_ops,
10078                 (void *)&cmd_syn_filter_priority,
10079                 (void *)&cmd_syn_filter_high,
10080                 (void *)&cmd_syn_filter_queue,
10081                 (void *)&cmd_syn_filter_queue_id,
10082                 NULL,
10083         },
10084 };
10085
10086 /* *** queue region set *** */
10087 struct cmd_queue_region_result {
10088         cmdline_fixed_string_t set;
10089         cmdline_fixed_string_t port;
10090         portid_t port_id;
10091         cmdline_fixed_string_t cmd;
10092         cmdline_fixed_string_t region;
10093         uint8_t  region_id;
10094         cmdline_fixed_string_t queue_start_index;
10095         uint8_t  queue_id;
10096         cmdline_fixed_string_t queue_num;
10097         uint8_t  queue_num_value;
10098 };
10099
10100 static void
10101 cmd_queue_region_parsed(void *parsed_result,
10102                         __rte_unused struct cmdline *cl,
10103                         __rte_unused void *data)
10104 {
10105         struct cmd_queue_region_result *res = parsed_result;
10106         int ret = -ENOTSUP;
10107 #ifdef RTE_NET_I40E
10108         struct rte_pmd_i40e_queue_region_conf region_conf;
10109         enum rte_pmd_i40e_queue_region_op op_type;
10110 #endif
10111
10112         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10113                 return;
10114
10115 #ifdef RTE_NET_I40E
10116         memset(&region_conf, 0, sizeof(region_conf));
10117         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10118         region_conf.region_id = res->region_id;
10119         region_conf.queue_num = res->queue_num_value;
10120         region_conf.queue_start_index = res->queue_id;
10121
10122         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10123                                 op_type, &region_conf);
10124 #endif
10125
10126         switch (ret) {
10127         case 0:
10128                 break;
10129         case -ENOTSUP:
10130                 printf("function not implemented or supported\n");
10131                 break;
10132         default:
10133                 printf("queue region config error: (%s)\n", strerror(-ret));
10134         }
10135 }
10136
10137 cmdline_parse_token_string_t cmd_queue_region_set =
10138 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10139                 set, "set");
10140 cmdline_parse_token_string_t cmd_queue_region_port =
10141         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10142 cmdline_parse_token_num_t cmd_queue_region_port_id =
10143         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10144                                 port_id, UINT16);
10145 cmdline_parse_token_string_t cmd_queue_region_cmd =
10146         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10147                                  cmd, "queue-region");
10148 cmdline_parse_token_string_t cmd_queue_region_id =
10149         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10150                                 region, "region_id");
10151 cmdline_parse_token_num_t cmd_queue_region_index =
10152         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10153                                 region_id, UINT8);
10154 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10155         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10156                                 queue_start_index, "queue_start_index");
10157 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10158         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10159                                 queue_id, UINT8);
10160 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10161         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10162                                 queue_num, "queue_num");
10163 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10164         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10165                                 queue_num_value, UINT8);
10166
10167 cmdline_parse_inst_t cmd_queue_region = {
10168         .f = cmd_queue_region_parsed,
10169         .data = NULL,
10170         .help_str = "set port <port_id> queue-region region_id <value> "
10171                 "queue_start_index <value> queue_num <value>: Set a queue region",
10172         .tokens = {
10173                 (void *)&cmd_queue_region_set,
10174                 (void *)&cmd_queue_region_port,
10175                 (void *)&cmd_queue_region_port_id,
10176                 (void *)&cmd_queue_region_cmd,
10177                 (void *)&cmd_queue_region_id,
10178                 (void *)&cmd_queue_region_index,
10179                 (void *)&cmd_queue_region_queue_start_index,
10180                 (void *)&cmd_queue_region_queue_id,
10181                 (void *)&cmd_queue_region_queue_num,
10182                 (void *)&cmd_queue_region_queue_num_value,
10183                 NULL,
10184         },
10185 };
10186
10187 /* *** queue region and flowtype set *** */
10188 struct cmd_region_flowtype_result {
10189         cmdline_fixed_string_t set;
10190         cmdline_fixed_string_t port;
10191         portid_t port_id;
10192         cmdline_fixed_string_t cmd;
10193         cmdline_fixed_string_t region;
10194         uint8_t  region_id;
10195         cmdline_fixed_string_t flowtype;
10196         uint8_t  flowtype_id;
10197 };
10198
10199 static void
10200 cmd_region_flowtype_parsed(void *parsed_result,
10201                         __rte_unused struct cmdline *cl,
10202                         __rte_unused void *data)
10203 {
10204         struct cmd_region_flowtype_result *res = parsed_result;
10205         int ret = -ENOTSUP;
10206 #ifdef RTE_NET_I40E
10207         struct rte_pmd_i40e_queue_region_conf region_conf;
10208         enum rte_pmd_i40e_queue_region_op op_type;
10209 #endif
10210
10211         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10212                 return;
10213
10214 #ifdef RTE_NET_I40E
10215         memset(&region_conf, 0, sizeof(region_conf));
10216
10217         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10218         region_conf.region_id = res->region_id;
10219         region_conf.hw_flowtype = res->flowtype_id;
10220
10221         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10222                         op_type, &region_conf);
10223 #endif
10224
10225         switch (ret) {
10226         case 0:
10227                 break;
10228         case -ENOTSUP:
10229                 printf("function not implemented or supported\n");
10230                 break;
10231         default:
10232                 printf("region flowtype config error: (%s)\n", strerror(-ret));
10233         }
10234 }
10235
10236 cmdline_parse_token_string_t cmd_region_flowtype_set =
10237 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10238                                 set, "set");
10239 cmdline_parse_token_string_t cmd_region_flowtype_port =
10240         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10241                                 port, "port");
10242 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10243         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10244                                 port_id, UINT16);
10245 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10246         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10247                                 cmd, "queue-region");
10248 cmdline_parse_token_string_t cmd_region_flowtype_index =
10249         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10250                                 region, "region_id");
10251 cmdline_parse_token_num_t cmd_region_flowtype_id =
10252         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10253                                 region_id, UINT8);
10254 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10255         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10256                                 flowtype, "flowtype");
10257 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10258         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10259                                 flowtype_id, UINT8);
10260 cmdline_parse_inst_t cmd_region_flowtype = {
10261         .f = cmd_region_flowtype_parsed,
10262         .data = NULL,
10263         .help_str = "set port <port_id> queue-region region_id <value> "
10264                 "flowtype <value>: Set a flowtype region index",
10265         .tokens = {
10266                 (void *)&cmd_region_flowtype_set,
10267                 (void *)&cmd_region_flowtype_port,
10268                 (void *)&cmd_region_flowtype_port_index,
10269                 (void *)&cmd_region_flowtype_cmd,
10270                 (void *)&cmd_region_flowtype_index,
10271                 (void *)&cmd_region_flowtype_id,
10272                 (void *)&cmd_region_flowtype_flow_index,
10273                 (void *)&cmd_region_flowtype_flow_id,
10274                 NULL,
10275         },
10276 };
10277
10278 /* *** User Priority (UP) to queue region (region_id) set *** */
10279 struct cmd_user_priority_region_result {
10280         cmdline_fixed_string_t set;
10281         cmdline_fixed_string_t port;
10282         portid_t port_id;
10283         cmdline_fixed_string_t cmd;
10284         cmdline_fixed_string_t user_priority;
10285         uint8_t  user_priority_id;
10286         cmdline_fixed_string_t region;
10287         uint8_t  region_id;
10288 };
10289
10290 static void
10291 cmd_user_priority_region_parsed(void *parsed_result,
10292                         __rte_unused struct cmdline *cl,
10293                         __rte_unused void *data)
10294 {
10295         struct cmd_user_priority_region_result *res = parsed_result;
10296         int ret = -ENOTSUP;
10297 #ifdef RTE_NET_I40E
10298         struct rte_pmd_i40e_queue_region_conf region_conf;
10299         enum rte_pmd_i40e_queue_region_op op_type;
10300 #endif
10301
10302         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10303                 return;
10304
10305 #ifdef RTE_NET_I40E
10306         memset(&region_conf, 0, sizeof(region_conf));
10307         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10308         region_conf.user_priority = res->user_priority_id;
10309         region_conf.region_id = res->region_id;
10310
10311         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10312                                 op_type, &region_conf);
10313 #endif
10314
10315         switch (ret) {
10316         case 0:
10317                 break;
10318         case -ENOTSUP:
10319                 printf("function not implemented or supported\n");
10320                 break;
10321         default:
10322                 printf("user_priority region config error: (%s)\n",
10323                                 strerror(-ret));
10324         }
10325 }
10326
10327 cmdline_parse_token_string_t cmd_user_priority_region_set =
10328         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10329                                 set, "set");
10330 cmdline_parse_token_string_t cmd_user_priority_region_port =
10331         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10332                                 port, "port");
10333 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10334         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10335                                 port_id, UINT16);
10336 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10337         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10338                                 cmd, "queue-region");
10339 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10340         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10341                                 user_priority, "UP");
10342 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10343         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10344                                 user_priority_id, UINT8);
10345 cmdline_parse_token_string_t cmd_user_priority_region_region =
10346         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10347                                 region, "region_id");
10348 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10349         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10350                                 region_id, UINT8);
10351
10352 cmdline_parse_inst_t cmd_user_priority_region = {
10353         .f = cmd_user_priority_region_parsed,
10354         .data = NULL,
10355         .help_str = "set port <port_id> queue-region UP <value> "
10356                 "region_id <value>: Set the mapping of User Priority (UP) "
10357                 "to queue region (region_id) ",
10358         .tokens = {
10359                 (void *)&cmd_user_priority_region_set,
10360                 (void *)&cmd_user_priority_region_port,
10361                 (void *)&cmd_user_priority_region_port_index,
10362                 (void *)&cmd_user_priority_region_cmd,
10363                 (void *)&cmd_user_priority_region_UP,
10364                 (void *)&cmd_user_priority_region_UP_id,
10365                 (void *)&cmd_user_priority_region_region,
10366                 (void *)&cmd_user_priority_region_region_id,
10367                 NULL,
10368         },
10369 };
10370
10371 /* *** flush all queue region related configuration *** */
10372 struct cmd_flush_queue_region_result {
10373         cmdline_fixed_string_t set;
10374         cmdline_fixed_string_t port;
10375         portid_t port_id;
10376         cmdline_fixed_string_t cmd;
10377         cmdline_fixed_string_t flush;
10378         cmdline_fixed_string_t what;
10379 };
10380
10381 static void
10382 cmd_flush_queue_region_parsed(void *parsed_result,
10383                         __rte_unused struct cmdline *cl,
10384                         __rte_unused void *data)
10385 {
10386         struct cmd_flush_queue_region_result *res = parsed_result;
10387         int ret = -ENOTSUP;
10388 #ifdef RTE_NET_I40E
10389         struct rte_pmd_i40e_queue_region_conf region_conf;
10390         enum rte_pmd_i40e_queue_region_op op_type;
10391 #endif
10392
10393         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10394                 return;
10395
10396 #ifdef RTE_NET_I40E
10397         memset(&region_conf, 0, sizeof(region_conf));
10398
10399         if (strcmp(res->what, "on") == 0)
10400                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10401         else
10402                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10403
10404         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10405                                 op_type, &region_conf);
10406 #endif
10407
10408         switch (ret) {
10409         case 0:
10410                 break;
10411         case -ENOTSUP:
10412                 printf("function not implemented or supported\n");
10413                 break;
10414         default:
10415                 printf("queue region config flush error: (%s)\n",
10416                                 strerror(-ret));
10417         }
10418 }
10419
10420 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10421         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10422                                 set, "set");
10423 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10424         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10425                                 port, "port");
10426 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10427         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10428                                 port_id, UINT16);
10429 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10430         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10431                                 cmd, "queue-region");
10432 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10433         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10434                                 flush, "flush");
10435 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10436         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10437                                 what, "on#off");
10438
10439 cmdline_parse_inst_t cmd_flush_queue_region = {
10440         .f = cmd_flush_queue_region_parsed,
10441         .data = NULL,
10442         .help_str = "set port <port_id> queue-region flush on|off"
10443                 ": flush all queue region related configuration",
10444         .tokens = {
10445                 (void *)&cmd_flush_queue_region_set,
10446                 (void *)&cmd_flush_queue_region_port,
10447                 (void *)&cmd_flush_queue_region_port_index,
10448                 (void *)&cmd_flush_queue_region_cmd,
10449                 (void *)&cmd_flush_queue_region_flush,
10450                 (void *)&cmd_flush_queue_region_what,
10451                 NULL,
10452         },
10453 };
10454
10455 /* *** get all queue region related configuration info *** */
10456 struct cmd_show_queue_region_info {
10457         cmdline_fixed_string_t show;
10458         cmdline_fixed_string_t port;
10459         portid_t port_id;
10460         cmdline_fixed_string_t cmd;
10461 };
10462
10463 static void
10464 cmd_show_queue_region_info_parsed(void *parsed_result,
10465                         __rte_unused struct cmdline *cl,
10466                         __rte_unused void *data)
10467 {
10468         struct cmd_show_queue_region_info *res = parsed_result;
10469         int ret = -ENOTSUP;
10470 #ifdef RTE_NET_I40E
10471         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10472         enum rte_pmd_i40e_queue_region_op op_type;
10473 #endif
10474
10475         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10476                 return;
10477
10478 #ifdef RTE_NET_I40E
10479         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10480
10481         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10482
10483         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10484                                         op_type, &rte_pmd_regions);
10485
10486         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10487 #endif
10488
10489         switch (ret) {
10490         case 0:
10491                 break;
10492         case -ENOTSUP:
10493                 printf("function not implemented or supported\n");
10494                 break;
10495         default:
10496                 printf("queue region config info show error: (%s)\n",
10497                                 strerror(-ret));
10498         }
10499 }
10500
10501 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10502 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10503                                 show, "show");
10504 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10505         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10506                                 port, "port");
10507 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10508         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10509                                 port_id, UINT16);
10510 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10511         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10512                                 cmd, "queue-region");
10513
10514 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10515         .f = cmd_show_queue_region_info_parsed,
10516         .data = NULL,
10517         .help_str = "show port <port_id> queue-region"
10518                 ": show all queue region related configuration info",
10519         .tokens = {
10520                 (void *)&cmd_show_queue_region_info_get,
10521                 (void *)&cmd_show_queue_region_info_port,
10522                 (void *)&cmd_show_queue_region_info_port_index,
10523                 (void *)&cmd_show_queue_region_info_cmd,
10524                 NULL,
10525         },
10526 };
10527
10528 /* *** ADD/REMOVE A 2tuple FILTER *** */
10529 struct cmd_2tuple_filter_result {
10530         cmdline_fixed_string_t filter;
10531         portid_t port_id;
10532         cmdline_fixed_string_t ops;
10533         cmdline_fixed_string_t dst_port;
10534         uint16_t dst_port_value;
10535         cmdline_fixed_string_t protocol;
10536         uint8_t protocol_value;
10537         cmdline_fixed_string_t mask;
10538         uint8_t  mask_value;
10539         cmdline_fixed_string_t tcp_flags;
10540         uint8_t tcp_flags_value;
10541         cmdline_fixed_string_t priority;
10542         uint8_t  priority_value;
10543         cmdline_fixed_string_t queue;
10544         uint16_t  queue_id;
10545 };
10546
10547 static void
10548 cmd_2tuple_filter_parsed(void *parsed_result,
10549                         __rte_unused struct cmdline *cl,
10550                         __rte_unused void *data)
10551 {
10552         struct rte_eth_ntuple_filter filter;
10553         struct cmd_2tuple_filter_result *res = parsed_result;
10554         int ret = 0;
10555
10556         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10557         if (ret < 0) {
10558                 printf("ntuple filter is not supported on port %u.\n",
10559                         res->port_id);
10560                 return;
10561         }
10562
10563         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10564
10565         filter.flags = RTE_2TUPLE_FLAGS;
10566         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10567         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10568         filter.proto = res->protocol_value;
10569         filter.priority = res->priority_value;
10570         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10571                 printf("nonzero tcp_flags is only meaningful"
10572                         " when protocol is TCP.\n");
10573                 return;
10574         }
10575         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10576                 printf("invalid TCP flags.\n");
10577                 return;
10578         }
10579
10580         if (res->tcp_flags_value != 0) {
10581                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10582                 filter.tcp_flags = res->tcp_flags_value;
10583         }
10584
10585         /* need convert to big endian. */
10586         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10587         filter.queue = res->queue_id;
10588
10589         if (!strcmp(res->ops, "add"))
10590                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10591                                 RTE_ETH_FILTER_NTUPLE,
10592                                 RTE_ETH_FILTER_ADD,
10593                                 &filter);
10594         else
10595                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10596                                 RTE_ETH_FILTER_NTUPLE,
10597                                 RTE_ETH_FILTER_DELETE,
10598                                 &filter);
10599         if (ret < 0)
10600                 printf("2tuple filter programming error: (%s)\n",
10601                         strerror(-ret));
10602
10603 }
10604
10605 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10606         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10607                                  filter, "2tuple_filter");
10608 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10609         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10610                                 port_id, UINT16);
10611 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10612         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10613                                  ops, "add#del");
10614 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10615         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10616                                 dst_port, "dst_port");
10617 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10618         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10619                                 dst_port_value, UINT16);
10620 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10621         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10622                                 protocol, "protocol");
10623 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10624         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10625                                 protocol_value, UINT8);
10626 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10627         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10628                                 mask, "mask");
10629 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10630         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10631                                 mask_value, INT8);
10632 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10633         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10634                                 tcp_flags, "tcp_flags");
10635 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10636         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10637                                 tcp_flags_value, UINT8);
10638 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10639         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10640                                 priority, "priority");
10641 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10642         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10643                                 priority_value, UINT8);
10644 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10645         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10646                                 queue, "queue");
10647 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10648         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10649                                 queue_id, UINT16);
10650
10651 cmdline_parse_inst_t cmd_2tuple_filter = {
10652         .f = cmd_2tuple_filter_parsed,
10653         .data = NULL,
10654         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10655                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10656                 "<queue_id>: Add a 2tuple filter",
10657         .tokens = {
10658                 (void *)&cmd_2tuple_filter_filter,
10659                 (void *)&cmd_2tuple_filter_port_id,
10660                 (void *)&cmd_2tuple_filter_ops,
10661                 (void *)&cmd_2tuple_filter_dst_port,
10662                 (void *)&cmd_2tuple_filter_dst_port_value,
10663                 (void *)&cmd_2tuple_filter_protocol,
10664                 (void *)&cmd_2tuple_filter_protocol_value,
10665                 (void *)&cmd_2tuple_filter_mask,
10666                 (void *)&cmd_2tuple_filter_mask_value,
10667                 (void *)&cmd_2tuple_filter_tcp_flags,
10668                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10669                 (void *)&cmd_2tuple_filter_priority,
10670                 (void *)&cmd_2tuple_filter_priority_value,
10671                 (void *)&cmd_2tuple_filter_queue,
10672                 (void *)&cmd_2tuple_filter_queue_id,
10673                 NULL,
10674         },
10675 };
10676
10677 /* *** ADD/REMOVE A 5tuple FILTER *** */
10678 struct cmd_5tuple_filter_result {
10679         cmdline_fixed_string_t filter;
10680         portid_t port_id;
10681         cmdline_fixed_string_t ops;
10682         cmdline_fixed_string_t dst_ip;
10683         cmdline_ipaddr_t dst_ip_value;
10684         cmdline_fixed_string_t src_ip;
10685         cmdline_ipaddr_t src_ip_value;
10686         cmdline_fixed_string_t dst_port;
10687         uint16_t dst_port_value;
10688         cmdline_fixed_string_t src_port;
10689         uint16_t src_port_value;
10690         cmdline_fixed_string_t protocol;
10691         uint8_t protocol_value;
10692         cmdline_fixed_string_t mask;
10693         uint8_t  mask_value;
10694         cmdline_fixed_string_t tcp_flags;
10695         uint8_t tcp_flags_value;
10696         cmdline_fixed_string_t priority;
10697         uint8_t  priority_value;
10698         cmdline_fixed_string_t queue;
10699         uint16_t  queue_id;
10700 };
10701
10702 static void
10703 cmd_5tuple_filter_parsed(void *parsed_result,
10704                         __rte_unused struct cmdline *cl,
10705                         __rte_unused void *data)
10706 {
10707         struct rte_eth_ntuple_filter filter;
10708         struct cmd_5tuple_filter_result *res = parsed_result;
10709         int ret = 0;
10710
10711         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10712         if (ret < 0) {
10713                 printf("ntuple filter is not supported on port %u.\n",
10714                         res->port_id);
10715                 return;
10716         }
10717
10718         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10719
10720         filter.flags = RTE_5TUPLE_FLAGS;
10721         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10722         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10723         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10724         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10725         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10726         filter.proto = res->protocol_value;
10727         filter.priority = res->priority_value;
10728         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10729                 printf("nonzero tcp_flags is only meaningful"
10730                         " when protocol is TCP.\n");
10731                 return;
10732         }
10733         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10734                 printf("invalid TCP flags.\n");
10735                 return;
10736         }
10737
10738         if (res->tcp_flags_value != 0) {
10739                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10740                 filter.tcp_flags = res->tcp_flags_value;
10741         }
10742
10743         if (res->dst_ip_value.family == AF_INET)
10744                 /* no need to convert, already big endian. */
10745                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10746         else {
10747                 if (filter.dst_ip_mask == 0) {
10748                         printf("can not support ipv6 involved compare.\n");
10749                         return;
10750                 }
10751                 filter.dst_ip = 0;
10752         }
10753
10754         if (res->src_ip_value.family == AF_INET)
10755                 /* no need to convert, already big endian. */
10756                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10757         else {
10758                 if (filter.src_ip_mask == 0) {
10759                         printf("can not support ipv6 involved compare.\n");
10760                         return;
10761                 }
10762                 filter.src_ip = 0;
10763         }
10764         /* need convert to big endian. */
10765         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10766         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10767         filter.queue = res->queue_id;
10768
10769         if (!strcmp(res->ops, "add"))
10770                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10771                                 RTE_ETH_FILTER_NTUPLE,
10772                                 RTE_ETH_FILTER_ADD,
10773                                 &filter);
10774         else
10775                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10776                                 RTE_ETH_FILTER_NTUPLE,
10777                                 RTE_ETH_FILTER_DELETE,
10778                                 &filter);
10779         if (ret < 0)
10780                 printf("5tuple filter programming error: (%s)\n",
10781                         strerror(-ret));
10782 }
10783
10784 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10785         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10786                                  filter, "5tuple_filter");
10787 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10788         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10789                                 port_id, UINT16);
10790 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10791         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10792                                  ops, "add#del");
10793 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10794         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10795                                 dst_ip, "dst_ip");
10796 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10797         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10798                                 dst_ip_value);
10799 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10800         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10801                                 src_ip, "src_ip");
10802 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10803         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10804                                 src_ip_value);
10805 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10806         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10807                                 dst_port, "dst_port");
10808 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10809         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10810                                 dst_port_value, UINT16);
10811 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10812         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10813                                 src_port, "src_port");
10814 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10815         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10816                                 src_port_value, UINT16);
10817 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10818         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10819                                 protocol, "protocol");
10820 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10821         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10822                                 protocol_value, UINT8);
10823 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10824         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10825                                 mask, "mask");
10826 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10827         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10828                                 mask_value, INT8);
10829 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10830         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10831                                 tcp_flags, "tcp_flags");
10832 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10833         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10834                                 tcp_flags_value, UINT8);
10835 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10836         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10837                                 priority, "priority");
10838 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10839         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10840                                 priority_value, UINT8);
10841 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10842         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10843                                 queue, "queue");
10844 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10845         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10846                                 queue_id, UINT16);
10847
10848 cmdline_parse_inst_t cmd_5tuple_filter = {
10849         .f = cmd_5tuple_filter_parsed,
10850         .data = NULL,
10851         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10852                 "src_ip <value> dst_port <value> src_port <value> "
10853                 "protocol <value>  mask <value> tcp_flags <value> "
10854                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10855         .tokens = {
10856                 (void *)&cmd_5tuple_filter_filter,
10857                 (void *)&cmd_5tuple_filter_port_id,
10858                 (void *)&cmd_5tuple_filter_ops,
10859                 (void *)&cmd_5tuple_filter_dst_ip,
10860                 (void *)&cmd_5tuple_filter_dst_ip_value,
10861                 (void *)&cmd_5tuple_filter_src_ip,
10862                 (void *)&cmd_5tuple_filter_src_ip_value,
10863                 (void *)&cmd_5tuple_filter_dst_port,
10864                 (void *)&cmd_5tuple_filter_dst_port_value,
10865                 (void *)&cmd_5tuple_filter_src_port,
10866                 (void *)&cmd_5tuple_filter_src_port_value,
10867                 (void *)&cmd_5tuple_filter_protocol,
10868                 (void *)&cmd_5tuple_filter_protocol_value,
10869                 (void *)&cmd_5tuple_filter_mask,
10870                 (void *)&cmd_5tuple_filter_mask_value,
10871                 (void *)&cmd_5tuple_filter_tcp_flags,
10872                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10873                 (void *)&cmd_5tuple_filter_priority,
10874                 (void *)&cmd_5tuple_filter_priority_value,
10875                 (void *)&cmd_5tuple_filter_queue,
10876                 (void *)&cmd_5tuple_filter_queue_id,
10877                 NULL,
10878         },
10879 };
10880
10881 /* *** ADD/REMOVE A flex FILTER *** */
10882 struct cmd_flex_filter_result {
10883         cmdline_fixed_string_t filter;
10884         cmdline_fixed_string_t ops;
10885         portid_t port_id;
10886         cmdline_fixed_string_t len;
10887         uint8_t len_value;
10888         cmdline_fixed_string_t bytes;
10889         cmdline_fixed_string_t bytes_value;
10890         cmdline_fixed_string_t mask;
10891         cmdline_fixed_string_t mask_value;
10892         cmdline_fixed_string_t priority;
10893         uint8_t priority_value;
10894         cmdline_fixed_string_t queue;
10895         uint16_t queue_id;
10896 };
10897
10898 static int xdigit2val(unsigned char c)
10899 {
10900         int val;
10901         if (isdigit(c))
10902                 val = c - '0';
10903         else if (isupper(c))
10904                 val = c - 'A' + 10;
10905         else
10906                 val = c - 'a' + 10;
10907         return val;
10908 }
10909
10910 static void
10911 cmd_flex_filter_parsed(void *parsed_result,
10912                           __rte_unused struct cmdline *cl,
10913                           __rte_unused void *data)
10914 {
10915         int ret = 0;
10916         struct rte_eth_flex_filter filter;
10917         struct cmd_flex_filter_result *res = parsed_result;
10918         char *bytes_ptr, *mask_ptr;
10919         uint16_t len, i, j = 0;
10920         char c;
10921         int val;
10922         uint8_t byte = 0;
10923
10924         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10925                 printf("the len exceed the max length 128\n");
10926                 return;
10927         }
10928         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10929         filter.len = res->len_value;
10930         filter.priority = res->priority_value;
10931         filter.queue = res->queue_id;
10932         bytes_ptr = res->bytes_value;
10933         mask_ptr = res->mask_value;
10934
10935          /* translate bytes string to array. */
10936         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10937                 (bytes_ptr[1] == 'X')))
10938                 bytes_ptr += 2;
10939         len = strnlen(bytes_ptr, res->len_value * 2);
10940         if (len == 0 || (len % 8 != 0)) {
10941                 printf("please check len and bytes input\n");
10942                 return;
10943         }
10944         for (i = 0; i < len; i++) {
10945                 c = bytes_ptr[i];
10946                 if (isxdigit(c) == 0) {
10947                         /* invalid characters. */
10948                         printf("invalid input\n");
10949                         return;
10950                 }
10951                 val = xdigit2val(c);
10952                 if (i % 2) {
10953                         byte |= val;
10954                         filter.bytes[j] = byte;
10955                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10956                         j++;
10957                         byte = 0;
10958                 } else
10959                         byte |= val << 4;
10960         }
10961         printf("\n");
10962          /* translate mask string to uint8_t array. */
10963         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10964                 (mask_ptr[1] == 'X')))
10965                 mask_ptr += 2;
10966         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10967         if (len == 0) {
10968                 printf("invalid input\n");
10969                 return;
10970         }
10971         j = 0;
10972         byte = 0;
10973         for (i = 0; i < len; i++) {
10974                 c = mask_ptr[i];
10975                 if (isxdigit(c) == 0) {
10976                         /* invalid characters. */
10977                         printf("invalid input\n");
10978                         return;
10979                 }
10980                 val = xdigit2val(c);
10981                 if (i % 2) {
10982                         byte |= val;
10983                         filter.mask[j] = byte;
10984                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10985                         j++;
10986                         byte = 0;
10987                 } else
10988                         byte |= val << 4;
10989         }
10990         printf("\n");
10991
10992         if (!strcmp(res->ops, "add"))
10993                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10994                                 RTE_ETH_FILTER_FLEXIBLE,
10995                                 RTE_ETH_FILTER_ADD,
10996                                 &filter);
10997         else
10998                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10999                                 RTE_ETH_FILTER_FLEXIBLE,
11000                                 RTE_ETH_FILTER_DELETE,
11001                                 &filter);
11002
11003         if (ret < 0)
11004                 printf("flex filter setting error: (%s)\n", strerror(-ret));
11005 }
11006
11007 cmdline_parse_token_string_t cmd_flex_filter_filter =
11008         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11009                                 filter, "flex_filter");
11010 cmdline_parse_token_num_t cmd_flex_filter_port_id =
11011         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11012                                 port_id, UINT16);
11013 cmdline_parse_token_string_t cmd_flex_filter_ops =
11014         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11015                                 ops, "add#del");
11016 cmdline_parse_token_string_t cmd_flex_filter_len =
11017         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11018                                 len, "len");
11019 cmdline_parse_token_num_t cmd_flex_filter_len_value =
11020         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11021                                 len_value, UINT8);
11022 cmdline_parse_token_string_t cmd_flex_filter_bytes =
11023         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11024                                 bytes, "bytes");
11025 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
11026         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11027                                 bytes_value, NULL);
11028 cmdline_parse_token_string_t cmd_flex_filter_mask =
11029         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11030                                 mask, "mask");
11031 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
11032         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11033                                 mask_value, NULL);
11034 cmdline_parse_token_string_t cmd_flex_filter_priority =
11035         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11036                                 priority, "priority");
11037 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
11038         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11039                                 priority_value, UINT8);
11040 cmdline_parse_token_string_t cmd_flex_filter_queue =
11041         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11042                                 queue, "queue");
11043 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
11044         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11045                                 queue_id, UINT16);
11046 cmdline_parse_inst_t cmd_flex_filter = {
11047         .f = cmd_flex_filter_parsed,
11048         .data = NULL,
11049         .help_str = "flex_filter <port_id> add|del len <value> bytes "
11050                 "<value> mask <value> priority <value> queue <queue_id>: "
11051                 "Add/Del a flex filter",
11052         .tokens = {
11053                 (void *)&cmd_flex_filter_filter,
11054                 (void *)&cmd_flex_filter_port_id,
11055                 (void *)&cmd_flex_filter_ops,
11056                 (void *)&cmd_flex_filter_len,
11057                 (void *)&cmd_flex_filter_len_value,
11058                 (void *)&cmd_flex_filter_bytes,
11059                 (void *)&cmd_flex_filter_bytes_value,
11060                 (void *)&cmd_flex_filter_mask,
11061                 (void *)&cmd_flex_filter_mask_value,
11062                 (void *)&cmd_flex_filter_priority,
11063                 (void *)&cmd_flex_filter_priority_value,
11064                 (void *)&cmd_flex_filter_queue,
11065                 (void *)&cmd_flex_filter_queue_id,
11066                 NULL,
11067         },
11068 };
11069
11070 /* *** Filters Control *** */
11071
11072 /* *** deal with ethertype filter *** */
11073 struct cmd_ethertype_filter_result {
11074         cmdline_fixed_string_t filter;
11075         portid_t port_id;
11076         cmdline_fixed_string_t ops;
11077         cmdline_fixed_string_t mac;
11078         struct rte_ether_addr mac_addr;
11079         cmdline_fixed_string_t ethertype;
11080         uint16_t ethertype_value;
11081         cmdline_fixed_string_t drop;
11082         cmdline_fixed_string_t queue;
11083         uint16_t  queue_id;
11084 };
11085
11086 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
11087         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11088                                  filter, "ethertype_filter");
11089 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
11090         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11091                               port_id, UINT16);
11092 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
11093         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11094                                  ops, "add#del");
11095 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
11096         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11097                                  mac, "mac_addr#mac_ignr");
11098 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
11099         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
11100                                      mac_addr);
11101 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
11102         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11103                                  ethertype, "ethertype");
11104 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
11105         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11106                               ethertype_value, UINT16);
11107 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
11108         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11109                                  drop, "drop#fwd");
11110 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
11111         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11112                                  queue, "queue");
11113 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
11114         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11115                               queue_id, UINT16);
11116
11117 static void
11118 cmd_ethertype_filter_parsed(void *parsed_result,
11119                           __rte_unused struct cmdline *cl,
11120                           __rte_unused void *data)
11121 {
11122         struct cmd_ethertype_filter_result *res = parsed_result;
11123         struct rte_eth_ethertype_filter filter;
11124         int ret = 0;
11125
11126         ret = rte_eth_dev_filter_supported(res->port_id,
11127                         RTE_ETH_FILTER_ETHERTYPE);
11128         if (ret < 0) {
11129                 printf("ethertype filter is not supported on port %u.\n",
11130                         res->port_id);
11131                 return;
11132         }
11133
11134         memset(&filter, 0, sizeof(filter));
11135         if (!strcmp(res->mac, "mac_addr")) {
11136                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
11137                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
11138                         sizeof(struct rte_ether_addr));
11139         }
11140         if (!strcmp(res->drop, "drop"))
11141                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
11142         filter.ether_type = res->ethertype_value;
11143         filter.queue = res->queue_id;
11144
11145         if (!strcmp(res->ops, "add"))
11146                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11147                                 RTE_ETH_FILTER_ETHERTYPE,
11148                                 RTE_ETH_FILTER_ADD,
11149                                 &filter);
11150         else
11151                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11152                                 RTE_ETH_FILTER_ETHERTYPE,
11153                                 RTE_ETH_FILTER_DELETE,
11154                                 &filter);
11155         if (ret < 0)
11156                 printf("ethertype filter programming error: (%s)\n",
11157                         strerror(-ret));
11158 }
11159
11160 cmdline_parse_inst_t cmd_ethertype_filter = {
11161         .f = cmd_ethertype_filter_parsed,
11162         .data = NULL,
11163         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
11164                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
11165                 "Add or delete an ethertype filter entry",
11166         .tokens = {
11167                 (void *)&cmd_ethertype_filter_filter,
11168                 (void *)&cmd_ethertype_filter_port_id,
11169                 (void *)&cmd_ethertype_filter_ops,
11170                 (void *)&cmd_ethertype_filter_mac,
11171                 (void *)&cmd_ethertype_filter_mac_addr,
11172                 (void *)&cmd_ethertype_filter_ethertype,
11173                 (void *)&cmd_ethertype_filter_ethertype_value,
11174                 (void *)&cmd_ethertype_filter_drop,
11175                 (void *)&cmd_ethertype_filter_queue,
11176                 (void *)&cmd_ethertype_filter_queue_id,
11177                 NULL,
11178         },
11179 };
11180
11181 /* *** deal with flow director filter *** */
11182 struct cmd_flow_director_result {
11183         cmdline_fixed_string_t flow_director_filter;
11184         portid_t port_id;
11185         cmdline_fixed_string_t mode;
11186         cmdline_fixed_string_t mode_value;
11187         cmdline_fixed_string_t ops;
11188         cmdline_fixed_string_t flow;
11189         cmdline_fixed_string_t flow_type;
11190         cmdline_fixed_string_t ether;
11191         uint16_t ether_type;
11192         cmdline_fixed_string_t src;
11193         cmdline_ipaddr_t ip_src;
11194         uint16_t port_src;
11195         cmdline_fixed_string_t dst;
11196         cmdline_ipaddr_t ip_dst;
11197         uint16_t port_dst;
11198         cmdline_fixed_string_t verify_tag;
11199         uint32_t verify_tag_value;
11200         cmdline_fixed_string_t tos;
11201         uint8_t tos_value;
11202         cmdline_fixed_string_t proto;
11203         uint8_t proto_value;
11204         cmdline_fixed_string_t ttl;
11205         uint8_t ttl_value;
11206         cmdline_fixed_string_t vlan;
11207         uint16_t vlan_value;
11208         cmdline_fixed_string_t flexbytes;
11209         cmdline_fixed_string_t flexbytes_value;
11210         cmdline_fixed_string_t pf_vf;
11211         cmdline_fixed_string_t drop;
11212         cmdline_fixed_string_t queue;
11213         uint16_t  queue_id;
11214         cmdline_fixed_string_t fd_id;
11215         uint32_t  fd_id_value;
11216         cmdline_fixed_string_t mac;
11217         struct rte_ether_addr mac_addr;
11218         cmdline_fixed_string_t tunnel;
11219         cmdline_fixed_string_t tunnel_type;
11220         cmdline_fixed_string_t tunnel_id;
11221         uint32_t tunnel_id_value;
11222         cmdline_fixed_string_t packet;
11223         char filepath[];
11224 };
11225
11226 static inline int
11227 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
11228 {
11229         char s[256];
11230         const char *p, *p0 = q_arg;
11231         char *end;
11232         unsigned long int_fld;
11233         char *str_fld[max_num];
11234         int i;
11235         unsigned size;
11236         int ret = -1;
11237
11238         p = strchr(p0, '(');
11239         if (p == NULL)
11240                 return -1;
11241         ++p;
11242         p0 = strchr(p, ')');
11243         if (p0 == NULL)
11244                 return -1;
11245
11246         size = p0 - p;
11247         if (size >= sizeof(s))
11248                 return -1;
11249
11250         snprintf(s, sizeof(s), "%.*s", size, p);
11251         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11252         if (ret < 0 || ret > max_num)
11253                 return -1;
11254         for (i = 0; i < ret; i++) {
11255                 errno = 0;
11256                 int_fld = strtoul(str_fld[i], &end, 0);
11257                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11258                         return -1;
11259                 flexbytes[i] = (uint8_t)int_fld;
11260         }
11261         return ret;
11262 }
11263
11264 static uint16_t
11265 str2flowtype(char *string)
11266 {
11267         uint8_t i = 0;
11268         static const struct {
11269                 char str[32];
11270                 uint16_t type;
11271         } flowtype_str[] = {
11272                 {"raw", RTE_ETH_FLOW_RAW},
11273                 {"ipv4", RTE_ETH_FLOW_IPV4},
11274                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11275                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11276                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11277                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11278                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11279                 {"ipv6", RTE_ETH_FLOW_IPV6},
11280                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11281                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11282                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11283                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11284                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11285                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11286         };
11287
11288         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11289                 if (!strcmp(flowtype_str[i].str, string))
11290                         return flowtype_str[i].type;
11291         }
11292
11293         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11294                 return (uint16_t)atoi(string);
11295
11296         return RTE_ETH_FLOW_UNKNOWN;
11297 }
11298
11299 static enum rte_eth_fdir_tunnel_type
11300 str2fdir_tunneltype(char *string)
11301 {
11302         uint8_t i = 0;
11303
11304         static const struct {
11305                 char str[32];
11306                 enum rte_eth_fdir_tunnel_type type;
11307         } tunneltype_str[] = {
11308                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11309                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11310         };
11311
11312         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11313                 if (!strcmp(tunneltype_str[i].str, string))
11314                         return tunneltype_str[i].type;
11315         }
11316         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11317 }
11318
11319 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11320 do { \
11321         if ((ip_addr).family == AF_INET) \
11322                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11323         else { \
11324                 printf("invalid parameter.\n"); \
11325                 return; \
11326         } \
11327 } while (0)
11328
11329 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11330 do { \
11331         if ((ip_addr).family == AF_INET6) \
11332                 rte_memcpy(&(ip), \
11333                                  &((ip_addr).addr.ipv6), \
11334                                  sizeof(struct in6_addr)); \
11335         else { \
11336                 printf("invalid parameter.\n"); \
11337                 return; \
11338         } \
11339 } while (0)
11340
11341 static void
11342 cmd_flow_director_filter_parsed(void *parsed_result,
11343                           __rte_unused struct cmdline *cl,
11344                           __rte_unused void *data)
11345 {
11346         struct cmd_flow_director_result *res = parsed_result;
11347         struct rte_eth_fdir_filter entry;
11348         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11349         char *end;
11350         unsigned long vf_id;
11351         int ret = 0;
11352
11353         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11354         if (ret < 0) {
11355                 printf("flow director is not supported on port %u.\n",
11356                         res->port_id);
11357                 return;
11358         }
11359         memset(flexbytes, 0, sizeof(flexbytes));
11360         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11361
11362         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11363                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11364                         printf("Please set mode to MAC-VLAN.\n");
11365                         return;
11366                 }
11367         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11368                 if (strcmp(res->mode_value, "Tunnel")) {
11369                         printf("Please set mode to Tunnel.\n");
11370                         return;
11371                 }
11372         } else {
11373                 if (!strcmp(res->mode_value, "raw")) {
11374 #ifdef RTE_NET_I40E
11375                         struct rte_pmd_i40e_flow_type_mapping
11376                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11377                         struct rte_pmd_i40e_pkt_template_conf conf;
11378                         uint16_t flow_type = str2flowtype(res->flow_type);
11379                         uint16_t i, port = res->port_id;
11380                         uint8_t add;
11381
11382                         memset(&conf, 0, sizeof(conf));
11383
11384                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11385                                 printf("Invalid flow type specified.\n");
11386                                 return;
11387                         }
11388                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11389                                                                  mapping);
11390                         if (ret)
11391                                 return;
11392                         if (mapping[flow_type].pctype == 0ULL) {
11393                                 printf("Invalid flow type specified.\n");
11394                                 return;
11395                         }
11396                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11397                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11398                                         conf.input.pctype = i;
11399                                         break;
11400                                 }
11401                         }
11402
11403                         conf.input.packet = open_file(res->filepath,
11404                                                 &conf.input.length);
11405                         if (!conf.input.packet)
11406                                 return;
11407                         if (!strcmp(res->drop, "drop"))
11408                                 conf.action.behavior =
11409                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11410                         else
11411                                 conf.action.behavior =
11412                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11413                         conf.action.report_status =
11414                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11415                         conf.action.rx_queue = res->queue_id;
11416                         conf.soft_id = res->fd_id_value;
11417                         add  = strcmp(res->ops, "del") ? 1 : 0;
11418                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11419                                                                         &conf,
11420                                                                         add);
11421                         if (ret < 0)
11422                                 printf("flow director config error: (%s)\n",
11423                                        strerror(-ret));
11424                         close_file(conf.input.packet);
11425 #endif
11426                         return;
11427                 } else if (strcmp(res->mode_value, "IP")) {
11428                         printf("Please set mode to IP or raw.\n");
11429                         return;
11430                 }
11431                 entry.input.flow_type = str2flowtype(res->flow_type);
11432         }
11433
11434         ret = parse_flexbytes(res->flexbytes_value,
11435                                         flexbytes,
11436                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11437         if (ret < 0) {
11438                 printf("error: Cannot parse flexbytes input.\n");
11439                 return;
11440         }
11441
11442         switch (entry.input.flow_type) {
11443         case RTE_ETH_FLOW_FRAG_IPV4:
11444         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11445                 entry.input.flow.ip4_flow.proto = res->proto_value;
11446                 /* fall-through */
11447         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11448         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11449                 IPV4_ADDR_TO_UINT(res->ip_dst,
11450                         entry.input.flow.ip4_flow.dst_ip);
11451                 IPV4_ADDR_TO_UINT(res->ip_src,
11452                         entry.input.flow.ip4_flow.src_ip);
11453                 entry.input.flow.ip4_flow.tos = res->tos_value;
11454                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11455                 /* need convert to big endian. */
11456                 entry.input.flow.udp4_flow.dst_port =
11457                                 rte_cpu_to_be_16(res->port_dst);
11458                 entry.input.flow.udp4_flow.src_port =
11459                                 rte_cpu_to_be_16(res->port_src);
11460                 break;
11461         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11462                 IPV4_ADDR_TO_UINT(res->ip_dst,
11463                         entry.input.flow.sctp4_flow.ip.dst_ip);
11464                 IPV4_ADDR_TO_UINT(res->ip_src,
11465                         entry.input.flow.sctp4_flow.ip.src_ip);
11466                 entry.input.flow.ip4_flow.tos = res->tos_value;
11467                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11468                 /* need convert to big endian. */
11469                 entry.input.flow.sctp4_flow.dst_port =
11470                                 rte_cpu_to_be_16(res->port_dst);
11471                 entry.input.flow.sctp4_flow.src_port =
11472                                 rte_cpu_to_be_16(res->port_src);
11473                 entry.input.flow.sctp4_flow.verify_tag =
11474                                 rte_cpu_to_be_32(res->verify_tag_value);
11475                 break;
11476         case RTE_ETH_FLOW_FRAG_IPV6:
11477         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11478                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11479                 /* fall-through */
11480         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11481         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11482                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11483                         entry.input.flow.ipv6_flow.dst_ip);
11484                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11485                         entry.input.flow.ipv6_flow.src_ip);
11486                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11487                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11488                 /* need convert to big endian. */
11489                 entry.input.flow.udp6_flow.dst_port =
11490                                 rte_cpu_to_be_16(res->port_dst);
11491                 entry.input.flow.udp6_flow.src_port =
11492                                 rte_cpu_to_be_16(res->port_src);
11493                 break;
11494         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11495                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11496                         entry.input.flow.sctp6_flow.ip.dst_ip);
11497                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11498                         entry.input.flow.sctp6_flow.ip.src_ip);
11499                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11500                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11501                 /* need convert to big endian. */
11502                 entry.input.flow.sctp6_flow.dst_port =
11503                                 rte_cpu_to_be_16(res->port_dst);
11504                 entry.input.flow.sctp6_flow.src_port =
11505                                 rte_cpu_to_be_16(res->port_src);
11506                 entry.input.flow.sctp6_flow.verify_tag =
11507                                 rte_cpu_to_be_32(res->verify_tag_value);
11508                 break;
11509         case RTE_ETH_FLOW_L2_PAYLOAD:
11510                 entry.input.flow.l2_flow.ether_type =
11511                         rte_cpu_to_be_16(res->ether_type);
11512                 break;
11513         default:
11514                 break;
11515         }
11516
11517         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11518                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11519                                  &res->mac_addr,
11520                                  sizeof(struct rte_ether_addr));
11521
11522         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11523                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11524                                  &res->mac_addr,
11525                                  sizeof(struct rte_ether_addr));
11526                 entry.input.flow.tunnel_flow.tunnel_type =
11527                         str2fdir_tunneltype(res->tunnel_type);
11528                 entry.input.flow.tunnel_flow.tunnel_id =
11529                         rte_cpu_to_be_32(res->tunnel_id_value);
11530         }
11531
11532         rte_memcpy(entry.input.flow_ext.flexbytes,
11533                    flexbytes,
11534                    RTE_ETH_FDIR_MAX_FLEXLEN);
11535
11536         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11537
11538         entry.action.flex_off = 0;  /*use 0 by default */
11539         if (!strcmp(res->drop, "drop"))
11540                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11541         else
11542                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11543
11544         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11545             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11546                 if (!strcmp(res->pf_vf, "pf"))
11547                         entry.input.flow_ext.is_vf = 0;
11548                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11549                         struct rte_eth_dev_info dev_info;
11550
11551                         ret = eth_dev_info_get_print_err(res->port_id,
11552                                                 &dev_info);
11553                         if (ret != 0)
11554                                 return;
11555
11556                         errno = 0;
11557                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11558                         if (errno != 0 || *end != '\0' ||
11559                             vf_id >= dev_info.max_vfs) {
11560                                 printf("invalid parameter %s.\n", res->pf_vf);
11561                                 return;
11562                         }
11563                         entry.input.flow_ext.is_vf = 1;
11564                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11565                 } else {
11566                         printf("invalid parameter %s.\n", res->pf_vf);
11567                         return;
11568                 }
11569         }
11570
11571         /* set to report FD ID by default */
11572         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11573         entry.action.rx_queue = res->queue_id;
11574         entry.soft_id = res->fd_id_value;
11575         if (!strcmp(res->ops, "add"))
11576                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11577                                              RTE_ETH_FILTER_ADD, &entry);
11578         else if (!strcmp(res->ops, "del"))
11579                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11580                                              RTE_ETH_FILTER_DELETE, &entry);
11581         else
11582                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11583                                              RTE_ETH_FILTER_UPDATE, &entry);
11584         if (ret < 0)
11585                 printf("flow director programming error: (%s)\n",
11586                         strerror(-ret));
11587 }
11588
11589 cmdline_parse_token_string_t cmd_flow_director_filter =
11590         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11591                                  flow_director_filter, "flow_director_filter");
11592 cmdline_parse_token_num_t cmd_flow_director_port_id =
11593         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11594                               port_id, UINT16);
11595 cmdline_parse_token_string_t cmd_flow_director_ops =
11596         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11597                                  ops, "add#del#update");
11598 cmdline_parse_token_string_t cmd_flow_director_flow =
11599         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11600                                  flow, "flow");
11601 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11602         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11603                 flow_type, NULL);
11604 cmdline_parse_token_string_t cmd_flow_director_ether =
11605         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11606                                  ether, "ether");
11607 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11608         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11609                               ether_type, UINT16);
11610 cmdline_parse_token_string_t cmd_flow_director_src =
11611         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11612                                  src, "src");
11613 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11614         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11615                                  ip_src);
11616 cmdline_parse_token_num_t cmd_flow_director_port_src =
11617         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11618                               port_src, UINT16);
11619 cmdline_parse_token_string_t cmd_flow_director_dst =
11620         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11621                                  dst, "dst");
11622 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11623         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11624                                  ip_dst);
11625 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11626         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11627                               port_dst, UINT16);
11628 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11629         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11630                                   verify_tag, "verify_tag");
11631 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11632         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11633                               verify_tag_value, UINT32);
11634 cmdline_parse_token_string_t cmd_flow_director_tos =
11635         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11636                                  tos, "tos");
11637 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11638         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11639                               tos_value, UINT8);
11640 cmdline_parse_token_string_t cmd_flow_director_proto =
11641         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11642                                  proto, "proto");
11643 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11644         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11645                               proto_value, UINT8);
11646 cmdline_parse_token_string_t cmd_flow_director_ttl =
11647         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11648                                  ttl, "ttl");
11649 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11650         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11651                               ttl_value, UINT8);
11652 cmdline_parse_token_string_t cmd_flow_director_vlan =
11653         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11654                                  vlan, "vlan");
11655 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11656         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11657                               vlan_value, UINT16);
11658 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11659         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11660                                  flexbytes, "flexbytes");
11661 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11662         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11663                               flexbytes_value, NULL);
11664 cmdline_parse_token_string_t cmd_flow_director_drop =
11665         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11666                                  drop, "drop#fwd");
11667 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11668         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11669                               pf_vf, NULL);
11670 cmdline_parse_token_string_t cmd_flow_director_queue =
11671         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11672                                  queue, "queue");
11673 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11674         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11675                               queue_id, UINT16);
11676 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11677         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11678                                  fd_id, "fd_id");
11679 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11680         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11681                               fd_id_value, UINT32);
11682
11683 cmdline_parse_token_string_t cmd_flow_director_mode =
11684         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11685                                  mode, "mode");
11686 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11687         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11688                                  mode_value, "IP");
11689 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11690         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11691                                  mode_value, "MAC-VLAN");
11692 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11693         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11694                                  mode_value, "Tunnel");
11695 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11696         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11697                                  mode_value, "raw");
11698 cmdline_parse_token_string_t cmd_flow_director_mac =
11699         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11700                                  mac, "mac");
11701 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11702         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11703                                     mac_addr);
11704 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11705         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11706                                  tunnel, "tunnel");
11707 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11708         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11709                                  tunnel_type, "NVGRE#VxLAN");
11710 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11711         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11712                                  tunnel_id, "tunnel-id");
11713 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11714         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11715                               tunnel_id_value, UINT32);
11716 cmdline_parse_token_string_t cmd_flow_director_packet =
11717         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11718                                  packet, "packet");
11719 cmdline_parse_token_string_t cmd_flow_director_filepath =
11720         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11721                                  filepath, NULL);
11722
11723 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11724         .f = cmd_flow_director_filter_parsed,
11725         .data = NULL,
11726         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11727                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11728                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11729                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11730                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11731                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11732                 "fd_id <fd_id_value>: "
11733                 "Add or delete an ip flow director entry on NIC",
11734         .tokens = {
11735                 (void *)&cmd_flow_director_filter,
11736                 (void *)&cmd_flow_director_port_id,
11737                 (void *)&cmd_flow_director_mode,
11738                 (void *)&cmd_flow_director_mode_ip,
11739                 (void *)&cmd_flow_director_ops,
11740                 (void *)&cmd_flow_director_flow,
11741                 (void *)&cmd_flow_director_flow_type,
11742                 (void *)&cmd_flow_director_src,
11743                 (void *)&cmd_flow_director_ip_src,
11744                 (void *)&cmd_flow_director_dst,
11745                 (void *)&cmd_flow_director_ip_dst,
11746                 (void *)&cmd_flow_director_tos,
11747                 (void *)&cmd_flow_director_tos_value,
11748                 (void *)&cmd_flow_director_proto,
11749                 (void *)&cmd_flow_director_proto_value,
11750                 (void *)&cmd_flow_director_ttl,
11751                 (void *)&cmd_flow_director_ttl_value,
11752                 (void *)&cmd_flow_director_vlan,
11753                 (void *)&cmd_flow_director_vlan_value,
11754                 (void *)&cmd_flow_director_flexbytes,
11755                 (void *)&cmd_flow_director_flexbytes_value,
11756                 (void *)&cmd_flow_director_drop,
11757                 (void *)&cmd_flow_director_pf_vf,
11758                 (void *)&cmd_flow_director_queue,
11759                 (void *)&cmd_flow_director_queue_id,
11760                 (void *)&cmd_flow_director_fd_id,
11761                 (void *)&cmd_flow_director_fd_id_value,
11762                 NULL,
11763         },
11764 };
11765
11766 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11767         .f = cmd_flow_director_filter_parsed,
11768         .data = NULL,
11769         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11770                 "director entry on NIC",
11771         .tokens = {
11772                 (void *)&cmd_flow_director_filter,
11773                 (void *)&cmd_flow_director_port_id,
11774                 (void *)&cmd_flow_director_mode,
11775                 (void *)&cmd_flow_director_mode_ip,
11776                 (void *)&cmd_flow_director_ops,
11777                 (void *)&cmd_flow_director_flow,
11778                 (void *)&cmd_flow_director_flow_type,
11779                 (void *)&cmd_flow_director_src,
11780                 (void *)&cmd_flow_director_ip_src,
11781                 (void *)&cmd_flow_director_port_src,
11782                 (void *)&cmd_flow_director_dst,
11783                 (void *)&cmd_flow_director_ip_dst,
11784                 (void *)&cmd_flow_director_port_dst,
11785                 (void *)&cmd_flow_director_tos,
11786                 (void *)&cmd_flow_director_tos_value,
11787                 (void *)&cmd_flow_director_ttl,
11788                 (void *)&cmd_flow_director_ttl_value,
11789                 (void *)&cmd_flow_director_vlan,
11790                 (void *)&cmd_flow_director_vlan_value,
11791                 (void *)&cmd_flow_director_flexbytes,
11792                 (void *)&cmd_flow_director_flexbytes_value,
11793                 (void *)&cmd_flow_director_drop,
11794                 (void *)&cmd_flow_director_pf_vf,
11795                 (void *)&cmd_flow_director_queue,
11796                 (void *)&cmd_flow_director_queue_id,
11797                 (void *)&cmd_flow_director_fd_id,
11798                 (void *)&cmd_flow_director_fd_id_value,
11799                 NULL,
11800         },
11801 };
11802
11803 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11804         .f = cmd_flow_director_filter_parsed,
11805         .data = NULL,
11806         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11807                 "director entry on NIC",
11808         .tokens = {
11809                 (void *)&cmd_flow_director_filter,
11810                 (void *)&cmd_flow_director_port_id,
11811                 (void *)&cmd_flow_director_mode,
11812                 (void *)&cmd_flow_director_mode_ip,
11813                 (void *)&cmd_flow_director_ops,
11814                 (void *)&cmd_flow_director_flow,
11815                 (void *)&cmd_flow_director_flow_type,
11816                 (void *)&cmd_flow_director_src,
11817                 (void *)&cmd_flow_director_ip_src,
11818                 (void *)&cmd_flow_director_port_src,
11819                 (void *)&cmd_flow_director_dst,
11820                 (void *)&cmd_flow_director_ip_dst,
11821                 (void *)&cmd_flow_director_port_dst,
11822                 (void *)&cmd_flow_director_verify_tag,
11823                 (void *)&cmd_flow_director_verify_tag_value,
11824                 (void *)&cmd_flow_director_tos,
11825                 (void *)&cmd_flow_director_tos_value,
11826                 (void *)&cmd_flow_director_ttl,
11827                 (void *)&cmd_flow_director_ttl_value,
11828                 (void *)&cmd_flow_director_vlan,
11829                 (void *)&cmd_flow_director_vlan_value,
11830                 (void *)&cmd_flow_director_flexbytes,
11831                 (void *)&cmd_flow_director_flexbytes_value,
11832                 (void *)&cmd_flow_director_drop,
11833                 (void *)&cmd_flow_director_pf_vf,
11834                 (void *)&cmd_flow_director_queue,
11835                 (void *)&cmd_flow_director_queue_id,
11836                 (void *)&cmd_flow_director_fd_id,
11837                 (void *)&cmd_flow_director_fd_id_value,
11838                 NULL,
11839         },
11840 };
11841
11842 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11843         .f = cmd_flow_director_filter_parsed,
11844         .data = NULL,
11845         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11846                 "director entry on NIC",
11847         .tokens = {
11848                 (void *)&cmd_flow_director_filter,
11849                 (void *)&cmd_flow_director_port_id,
11850                 (void *)&cmd_flow_director_mode,
11851                 (void *)&cmd_flow_director_mode_ip,
11852                 (void *)&cmd_flow_director_ops,
11853                 (void *)&cmd_flow_director_flow,
11854                 (void *)&cmd_flow_director_flow_type,
11855                 (void *)&cmd_flow_director_ether,
11856                 (void *)&cmd_flow_director_ether_type,
11857                 (void *)&cmd_flow_director_flexbytes,
11858                 (void *)&cmd_flow_director_flexbytes_value,
11859                 (void *)&cmd_flow_director_drop,
11860                 (void *)&cmd_flow_director_pf_vf,
11861                 (void *)&cmd_flow_director_queue,
11862                 (void *)&cmd_flow_director_queue_id,
11863                 (void *)&cmd_flow_director_fd_id,
11864                 (void *)&cmd_flow_director_fd_id_value,
11865                 NULL,
11866         },
11867 };
11868
11869 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11870         .f = cmd_flow_director_filter_parsed,
11871         .data = NULL,
11872         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11873                 "director entry on NIC",
11874         .tokens = {
11875                 (void *)&cmd_flow_director_filter,
11876                 (void *)&cmd_flow_director_port_id,
11877                 (void *)&cmd_flow_director_mode,
11878                 (void *)&cmd_flow_director_mode_mac_vlan,
11879                 (void *)&cmd_flow_director_ops,
11880                 (void *)&cmd_flow_director_mac,
11881                 (void *)&cmd_flow_director_mac_addr,
11882                 (void *)&cmd_flow_director_vlan,
11883                 (void *)&cmd_flow_director_vlan_value,
11884                 (void *)&cmd_flow_director_flexbytes,
11885                 (void *)&cmd_flow_director_flexbytes_value,
11886                 (void *)&cmd_flow_director_drop,
11887                 (void *)&cmd_flow_director_queue,
11888                 (void *)&cmd_flow_director_queue_id,
11889                 (void *)&cmd_flow_director_fd_id,
11890                 (void *)&cmd_flow_director_fd_id_value,
11891                 NULL,
11892         },
11893 };
11894
11895 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11896         .f = cmd_flow_director_filter_parsed,
11897         .data = NULL,
11898         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11899                 "director entry on NIC",
11900         .tokens = {
11901                 (void *)&cmd_flow_director_filter,
11902                 (void *)&cmd_flow_director_port_id,
11903                 (void *)&cmd_flow_director_mode,
11904                 (void *)&cmd_flow_director_mode_tunnel,
11905                 (void *)&cmd_flow_director_ops,
11906                 (void *)&cmd_flow_director_mac,
11907                 (void *)&cmd_flow_director_mac_addr,
11908                 (void *)&cmd_flow_director_vlan,
11909                 (void *)&cmd_flow_director_vlan_value,
11910                 (void *)&cmd_flow_director_tunnel,
11911                 (void *)&cmd_flow_director_tunnel_type,
11912                 (void *)&cmd_flow_director_tunnel_id,
11913                 (void *)&cmd_flow_director_tunnel_id_value,
11914                 (void *)&cmd_flow_director_flexbytes,
11915                 (void *)&cmd_flow_director_flexbytes_value,
11916                 (void *)&cmd_flow_director_drop,
11917                 (void *)&cmd_flow_director_queue,
11918                 (void *)&cmd_flow_director_queue_id,
11919                 (void *)&cmd_flow_director_fd_id,
11920                 (void *)&cmd_flow_director_fd_id_value,
11921                 NULL,
11922         },
11923 };
11924
11925 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11926         .f = cmd_flow_director_filter_parsed,
11927         .data = NULL,
11928         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11929                 "director entry on NIC",
11930         .tokens = {
11931                 (void *)&cmd_flow_director_filter,
11932                 (void *)&cmd_flow_director_port_id,
11933                 (void *)&cmd_flow_director_mode,
11934                 (void *)&cmd_flow_director_mode_raw,
11935                 (void *)&cmd_flow_director_ops,
11936                 (void *)&cmd_flow_director_flow,
11937                 (void *)&cmd_flow_director_flow_type,
11938                 (void *)&cmd_flow_director_drop,
11939                 (void *)&cmd_flow_director_queue,
11940                 (void *)&cmd_flow_director_queue_id,
11941                 (void *)&cmd_flow_director_fd_id,
11942                 (void *)&cmd_flow_director_fd_id_value,
11943                 (void *)&cmd_flow_director_packet,
11944                 (void *)&cmd_flow_director_filepath,
11945                 NULL,
11946         },
11947 };
11948
11949 struct cmd_flush_flow_director_result {
11950         cmdline_fixed_string_t flush_flow_director;
11951         portid_t port_id;
11952 };
11953
11954 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11955         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11956                                  flush_flow_director, "flush_flow_director");
11957 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11958         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11959                               port_id, UINT16);
11960
11961 static void
11962 cmd_flush_flow_director_parsed(void *parsed_result,
11963                           __rte_unused struct cmdline *cl,
11964                           __rte_unused void *data)
11965 {
11966         struct cmd_flow_director_result *res = parsed_result;
11967         int ret = 0;
11968
11969         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11970         if (ret < 0) {
11971                 printf("flow director is not supported on port %u.\n",
11972                         res->port_id);
11973                 return;
11974         }
11975
11976         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11977                         RTE_ETH_FILTER_FLUSH, NULL);
11978         if (ret < 0)
11979                 printf("flow director table flushing error: (%s)\n",
11980                         strerror(-ret));
11981 }
11982
11983 cmdline_parse_inst_t cmd_flush_flow_director = {
11984         .f = cmd_flush_flow_director_parsed,
11985         .data = NULL,
11986         .help_str = "flush_flow_director <port_id>: "
11987                 "Flush all flow director entries of a device on NIC",
11988         .tokens = {
11989                 (void *)&cmd_flush_flow_director_flush,
11990                 (void *)&cmd_flush_flow_director_port_id,
11991                 NULL,
11992         },
11993 };
11994
11995 /* *** deal with flow director mask *** */
11996 struct cmd_flow_director_mask_result {
11997         cmdline_fixed_string_t flow_director_mask;
11998         portid_t port_id;
11999         cmdline_fixed_string_t mode;
12000         cmdline_fixed_string_t mode_value;
12001         cmdline_fixed_string_t vlan;
12002         uint16_t vlan_mask;
12003         cmdline_fixed_string_t src_mask;
12004         cmdline_ipaddr_t ipv4_src;
12005         cmdline_ipaddr_t ipv6_src;
12006         uint16_t port_src;
12007         cmdline_fixed_string_t dst_mask;
12008         cmdline_ipaddr_t ipv4_dst;
12009         cmdline_ipaddr_t ipv6_dst;
12010         uint16_t port_dst;
12011         cmdline_fixed_string_t mac;
12012         uint8_t mac_addr_byte_mask;
12013         cmdline_fixed_string_t tunnel_id;
12014         uint32_t tunnel_id_mask;
12015         cmdline_fixed_string_t tunnel_type;
12016         uint8_t tunnel_type_mask;
12017 };
12018
12019 static void
12020 cmd_flow_director_mask_parsed(void *parsed_result,
12021                           __rte_unused struct cmdline *cl,
12022                           __rte_unused void *data)
12023 {
12024         struct cmd_flow_director_mask_result *res = parsed_result;
12025         struct rte_eth_fdir_masks *mask;
12026         struct rte_port *port;
12027
12028         port = &ports[res->port_id];
12029         /** Check if the port is not started **/
12030         if (port->port_status != RTE_PORT_STOPPED) {
12031                 printf("Please stop port %d first\n", res->port_id);
12032                 return;
12033         }
12034
12035         mask = &port->dev_conf.fdir_conf.mask;
12036
12037         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
12038                 if (strcmp(res->mode_value, "MAC-VLAN")) {
12039                         printf("Please set mode to MAC-VLAN.\n");
12040                         return;
12041                 }
12042
12043                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12044         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
12045                 if (strcmp(res->mode_value, "Tunnel")) {
12046                         printf("Please set mode to Tunnel.\n");
12047                         return;
12048                 }
12049
12050                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12051                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
12052                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
12053                 mask->tunnel_type_mask = res->tunnel_type_mask;
12054         } else {
12055                 if (strcmp(res->mode_value, "IP")) {
12056                         printf("Please set mode to IP.\n");
12057                         return;
12058                 }
12059
12060                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12061                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
12062                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
12063                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
12064                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
12065                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
12066                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
12067         }
12068
12069         cmd_reconfig_device_queue(res->port_id, 1, 1);
12070 }
12071
12072 cmdline_parse_token_string_t cmd_flow_director_mask =
12073         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12074                                  flow_director_mask, "flow_director_mask");
12075 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
12076         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12077                               port_id, UINT16);
12078 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
12079         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12080                                  vlan, "vlan");
12081 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
12082         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12083                               vlan_mask, UINT16);
12084 cmdline_parse_token_string_t cmd_flow_director_mask_src =
12085         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12086                                  src_mask, "src_mask");
12087 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
12088         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12089                                  ipv4_src);
12090 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
12091         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12092                                  ipv6_src);
12093 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
12094         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12095                               port_src, UINT16);
12096 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
12097         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12098                                  dst_mask, "dst_mask");
12099 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
12100         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12101                                  ipv4_dst);
12102 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
12103         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12104                                  ipv6_dst);
12105 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
12106         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12107                               port_dst, UINT16);
12108
12109 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
12110         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12111                                  mode, "mode");
12112 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
12113         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12114                                  mode_value, "IP");
12115 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
12116         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12117                                  mode_value, "MAC-VLAN");
12118 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
12119         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12120                                  mode_value, "Tunnel");
12121 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
12122         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12123                                  mac, "mac");
12124 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
12125         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12126                               mac_addr_byte_mask, UINT8);
12127 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
12128         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12129                                  tunnel_type, "tunnel-type");
12130 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
12131         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12132                               tunnel_type_mask, UINT8);
12133 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
12134         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12135                                  tunnel_id, "tunnel-id");
12136 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
12137         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12138                               tunnel_id_mask, UINT32);
12139
12140 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
12141         .f = cmd_flow_director_mask_parsed,
12142         .data = NULL,
12143         .help_str = "flow_director_mask ... : "
12144                 "Set IP mode flow director's mask on NIC",
12145         .tokens = {
12146                 (void *)&cmd_flow_director_mask,
12147                 (void *)&cmd_flow_director_mask_port_id,
12148                 (void *)&cmd_flow_director_mask_mode,
12149                 (void *)&cmd_flow_director_mask_mode_ip,
12150                 (void *)&cmd_flow_director_mask_vlan,
12151                 (void *)&cmd_flow_director_mask_vlan_value,
12152                 (void *)&cmd_flow_director_mask_src,
12153                 (void *)&cmd_flow_director_mask_ipv4_src,
12154                 (void *)&cmd_flow_director_mask_ipv6_src,
12155                 (void *)&cmd_flow_director_mask_port_src,
12156                 (void *)&cmd_flow_director_mask_dst,
12157                 (void *)&cmd_flow_director_mask_ipv4_dst,
12158                 (void *)&cmd_flow_director_mask_ipv6_dst,
12159                 (void *)&cmd_flow_director_mask_port_dst,
12160                 NULL,
12161         },
12162 };
12163
12164 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
12165         .f = cmd_flow_director_mask_parsed,
12166         .data = NULL,
12167         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
12168                 "flow director's mask on NIC",
12169         .tokens = {
12170                 (void *)&cmd_flow_director_mask,
12171                 (void *)&cmd_flow_director_mask_port_id,
12172                 (void *)&cmd_flow_director_mask_mode,
12173                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
12174                 (void *)&cmd_flow_director_mask_vlan,
12175                 (void *)&cmd_flow_director_mask_vlan_value,
12176                 NULL,
12177         },
12178 };
12179
12180 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
12181         .f = cmd_flow_director_mask_parsed,
12182         .data = NULL,
12183         .help_str = "flow_director_mask ... : Set tunnel mode "
12184                 "flow director's mask on NIC",
12185         .tokens = {
12186                 (void *)&cmd_flow_director_mask,
12187                 (void *)&cmd_flow_director_mask_port_id,
12188                 (void *)&cmd_flow_director_mask_mode,
12189                 (void *)&cmd_flow_director_mask_mode_tunnel,
12190                 (void *)&cmd_flow_director_mask_vlan,
12191                 (void *)&cmd_flow_director_mask_vlan_value,
12192                 (void *)&cmd_flow_director_mask_mac,
12193                 (void *)&cmd_flow_director_mask_mac_value,
12194                 (void *)&cmd_flow_director_mask_tunnel_type,
12195                 (void *)&cmd_flow_director_mask_tunnel_type_value,
12196                 (void *)&cmd_flow_director_mask_tunnel_id,
12197                 (void *)&cmd_flow_director_mask_tunnel_id_value,
12198                 NULL,
12199         },
12200 };
12201
12202 /* *** deal with flow director mask on flexible payload *** */
12203 struct cmd_flow_director_flex_mask_result {
12204         cmdline_fixed_string_t flow_director_flexmask;
12205         portid_t port_id;
12206         cmdline_fixed_string_t flow;
12207         cmdline_fixed_string_t flow_type;
12208         cmdline_fixed_string_t mask;
12209 };
12210
12211 static void
12212 cmd_flow_director_flex_mask_parsed(void *parsed_result,
12213                           __rte_unused struct cmdline *cl,
12214                           __rte_unused void *data)
12215 {
12216         struct cmd_flow_director_flex_mask_result *res = parsed_result;
12217         struct rte_eth_fdir_info fdir_info;
12218         struct rte_eth_fdir_flex_mask flex_mask;
12219         struct rte_port *port;
12220         uint64_t flow_type_mask;
12221         uint16_t i;
12222         int ret;
12223
12224         port = &ports[res->port_id];
12225         /** Check if the port is not started **/
12226         if (port->port_status != RTE_PORT_STOPPED) {
12227                 printf("Please stop port %d first\n", res->port_id);
12228                 return;
12229         }
12230
12231         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
12232         ret = parse_flexbytes(res->mask,
12233                         flex_mask.mask,
12234                         RTE_ETH_FDIR_MAX_FLEXLEN);
12235         if (ret < 0) {
12236                 printf("error: Cannot parse mask input.\n");
12237                 return;
12238         }
12239
12240         memset(&fdir_info, 0, sizeof(fdir_info));
12241         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12242                                 RTE_ETH_FILTER_INFO, &fdir_info);
12243         if (ret < 0) {
12244                 printf("Cannot get FDir filter info\n");
12245                 return;
12246         }
12247
12248         if (!strcmp(res->flow_type, "none")) {
12249                 /* means don't specify the flow type */
12250                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
12251                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
12252                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12253                                0, sizeof(struct rte_eth_fdir_flex_mask));
12254                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12255                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12256                                  &flex_mask,
12257                                  sizeof(struct rte_eth_fdir_flex_mask));
12258                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12259                 return;
12260         }
12261         flow_type_mask = fdir_info.flow_types_mask[0];
12262         if (!strcmp(res->flow_type, "all")) {
12263                 if (!flow_type_mask) {
12264                         printf("No flow type supported\n");
12265                         return;
12266                 }
12267                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12268                         if (flow_type_mask & (1ULL << i)) {
12269                                 flex_mask.flow_type = i;
12270                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12271                         }
12272                 }
12273                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12274                 return;
12275         }
12276         flex_mask.flow_type = str2flowtype(res->flow_type);
12277         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12278                 printf("Flow type %s not supported on port %d\n",
12279                                 res->flow_type, res->port_id);
12280                 return;
12281         }
12282         fdir_set_flex_mask(res->port_id, &flex_mask);
12283         cmd_reconfig_device_queue(res->port_id, 1, 1);
12284 }
12285
12286 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12287         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12288                                  flow_director_flexmask,
12289                                  "flow_director_flex_mask");
12290 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12291         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12292                               port_id, UINT16);
12293 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12294         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12295                                  flow, "flow");
12296 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12297         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12298                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12299                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12300 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12301         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12302                                  mask, NULL);
12303
12304 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12305         .f = cmd_flow_director_flex_mask_parsed,
12306         .data = NULL,
12307         .help_str = "flow_director_flex_mask ... : "
12308                 "Set flow director's flex mask on NIC",
12309         .tokens = {
12310                 (void *)&cmd_flow_director_flexmask,
12311                 (void *)&cmd_flow_director_flexmask_port_id,
12312                 (void *)&cmd_flow_director_flexmask_flow,
12313                 (void *)&cmd_flow_director_flexmask_flow_type,
12314                 (void *)&cmd_flow_director_flexmask_mask,
12315                 NULL,
12316         },
12317 };
12318
12319 /* *** deal with flow director flexible payload configuration *** */
12320 struct cmd_flow_director_flexpayload_result {
12321         cmdline_fixed_string_t flow_director_flexpayload;
12322         portid_t port_id;
12323         cmdline_fixed_string_t payload_layer;
12324         cmdline_fixed_string_t payload_cfg;
12325 };
12326
12327 static inline int
12328 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12329 {
12330         char s[256];
12331         const char *p, *p0 = q_arg;
12332         char *end;
12333         unsigned long int_fld;
12334         char *str_fld[max_num];
12335         int i;
12336         unsigned size;
12337         int ret = -1;
12338
12339         p = strchr(p0, '(');
12340         if (p == NULL)
12341                 return -1;
12342         ++p;
12343         p0 = strchr(p, ')');
12344         if (p0 == NULL)
12345                 return -1;
12346
12347         size = p0 - p;
12348         if (size >= sizeof(s))
12349                 return -1;
12350
12351         snprintf(s, sizeof(s), "%.*s", size, p);
12352         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12353         if (ret < 0 || ret > max_num)
12354                 return -1;
12355         for (i = 0; i < ret; i++) {
12356                 errno = 0;
12357                 int_fld = strtoul(str_fld[i], &end, 0);
12358                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12359                         return -1;
12360                 offsets[i] = (uint16_t)int_fld;
12361         }
12362         return ret;
12363 }
12364
12365 static void
12366 cmd_flow_director_flxpld_parsed(void *parsed_result,
12367                           __rte_unused struct cmdline *cl,
12368                           __rte_unused void *data)
12369 {
12370         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12371         struct rte_eth_flex_payload_cfg flex_cfg;
12372         struct rte_port *port;
12373         int ret = 0;
12374
12375         port = &ports[res->port_id];
12376         /** Check if the port is not started **/
12377         if (port->port_status != RTE_PORT_STOPPED) {
12378                 printf("Please stop port %d first\n", res->port_id);
12379                 return;
12380         }
12381
12382         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12383
12384         if (!strcmp(res->payload_layer, "raw"))
12385                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12386         else if (!strcmp(res->payload_layer, "l2"))
12387                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12388         else if (!strcmp(res->payload_layer, "l3"))
12389                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12390         else if (!strcmp(res->payload_layer, "l4"))
12391                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12392
12393         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12394                             RTE_ETH_FDIR_MAX_FLEXLEN);
12395         if (ret < 0) {
12396                 printf("error: Cannot parse flex payload input.\n");
12397                 return;
12398         }
12399
12400         fdir_set_flex_payload(res->port_id, &flex_cfg);
12401         cmd_reconfig_device_queue(res->port_id, 1, 1);
12402 }
12403
12404 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12405         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12406                                  flow_director_flexpayload,
12407                                  "flow_director_flex_payload");
12408 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12409         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12410                               port_id, UINT16);
12411 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12412         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12413                                  payload_layer, "raw#l2#l3#l4");
12414 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12415         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12416                                  payload_cfg, NULL);
12417
12418 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12419         .f = cmd_flow_director_flxpld_parsed,
12420         .data = NULL,
12421         .help_str = "flow_director_flexpayload ... : "
12422                 "Set flow director's flex payload on NIC",
12423         .tokens = {
12424                 (void *)&cmd_flow_director_flexpayload,
12425                 (void *)&cmd_flow_director_flexpayload_port_id,
12426                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12427                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12428                 NULL,
12429         },
12430 };
12431
12432 /* Generic flow interface command. */
12433 extern cmdline_parse_inst_t cmd_flow;
12434
12435 /* *** Classification Filters Control *** */
12436 /* *** Get symmetric hash enable per port *** */
12437 struct cmd_get_sym_hash_ena_per_port_result {
12438         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12439         portid_t port_id;
12440 };
12441
12442 static void
12443 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12444                                  __rte_unused struct cmdline *cl,
12445                                  __rte_unused void *data)
12446 {
12447         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12448         struct rte_eth_hash_filter_info info;
12449         int ret;
12450
12451         if (rte_eth_dev_filter_supported(res->port_id,
12452                                 RTE_ETH_FILTER_HASH) < 0) {
12453                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12454                                                         res->port_id);
12455                 return;
12456         }
12457
12458         memset(&info, 0, sizeof(info));
12459         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12460         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12461                                                 RTE_ETH_FILTER_GET, &info);
12462
12463         if (ret < 0) {
12464                 printf("Cannot get symmetric hash enable per port "
12465                                         "on port %u\n", res->port_id);
12466                 return;
12467         }
12468
12469         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12470                                 "enabled" : "disabled", res->port_id);
12471 }
12472
12473 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12474         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12475                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12476 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12477         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12478                 port_id, UINT16);
12479
12480 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12481         .f = cmd_get_sym_hash_per_port_parsed,
12482         .data = NULL,
12483         .help_str = "get_sym_hash_ena_per_port <port_id>",
12484         .tokens = {
12485                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12486                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12487                 NULL,
12488         },
12489 };
12490
12491 /* *** Set symmetric hash enable per port *** */
12492 struct cmd_set_sym_hash_ena_per_port_result {
12493         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12494         cmdline_fixed_string_t enable;
12495         portid_t port_id;
12496 };
12497
12498 static void
12499 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12500                                  __rte_unused struct cmdline *cl,
12501                                  __rte_unused void *data)
12502 {
12503         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12504         struct rte_eth_hash_filter_info info;
12505         int ret;
12506
12507         if (rte_eth_dev_filter_supported(res->port_id,
12508                                 RTE_ETH_FILTER_HASH) < 0) {
12509                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12510                                                         res->port_id);
12511                 return;
12512         }
12513
12514         memset(&info, 0, sizeof(info));
12515         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12516         if (!strcmp(res->enable, "enable"))
12517                 info.info.enable = 1;
12518         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12519                                         RTE_ETH_FILTER_SET, &info);
12520         if (ret < 0) {
12521                 printf("Cannot set symmetric hash enable per port on "
12522                                         "port %u\n", res->port_id);
12523                 return;
12524         }
12525         printf("Symmetric hash has been set to %s on port %u\n",
12526                                         res->enable, res->port_id);
12527 }
12528
12529 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12530         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12531                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12532 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12533         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12534                 port_id, UINT16);
12535 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12536         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12537                 enable, "enable#disable");
12538
12539 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12540         .f = cmd_set_sym_hash_per_port_parsed,
12541         .data = NULL,
12542         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12543         .tokens = {
12544                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12545                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12546                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12547                 NULL,
12548         },
12549 };
12550
12551 /* Get global config of hash function */
12552 struct cmd_get_hash_global_config_result {
12553         cmdline_fixed_string_t get_hash_global_config;
12554         portid_t port_id;
12555 };
12556
12557 static char *
12558 flowtype_to_str(uint16_t ftype)
12559 {
12560         uint16_t i;
12561         static struct {
12562                 char str[16];
12563                 uint16_t ftype;
12564         } ftype_table[] = {
12565                 {"ipv4", RTE_ETH_FLOW_IPV4},
12566                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12567                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12568                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12569                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12570                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12571                 {"ipv6", RTE_ETH_FLOW_IPV6},
12572                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12573                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12574                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12575                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12576                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12577                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12578                 {"port", RTE_ETH_FLOW_PORT},
12579                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12580                 {"geneve", RTE_ETH_FLOW_GENEVE},
12581                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12582                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12583         };
12584
12585         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12586                 if (ftype_table[i].ftype == ftype)
12587                         return ftype_table[i].str;
12588         }
12589
12590         return NULL;
12591 }
12592
12593 static void
12594 cmd_get_hash_global_config_parsed(void *parsed_result,
12595                                   __rte_unused struct cmdline *cl,
12596                                   __rte_unused void *data)
12597 {
12598         struct cmd_get_hash_global_config_result *res = parsed_result;
12599         struct rte_eth_hash_filter_info info;
12600         uint32_t idx, offset;
12601         uint16_t i;
12602         char *str;
12603         int ret;
12604
12605         if (rte_eth_dev_filter_supported(res->port_id,
12606                         RTE_ETH_FILTER_HASH) < 0) {
12607                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12608                                                         res->port_id);
12609                 return;
12610         }
12611
12612         memset(&info, 0, sizeof(info));
12613         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12614         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12615                                         RTE_ETH_FILTER_GET, &info);
12616         if (ret < 0) {
12617                 printf("Cannot get hash global configurations by port %d\n",
12618                                                         res->port_id);
12619                 return;
12620         }
12621
12622         switch (info.info.global_conf.hash_func) {
12623         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12624                 printf("Hash function is Toeplitz\n");
12625                 break;
12626         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12627                 printf("Hash function is Simple XOR\n");
12628                 break;
12629         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12630                 printf("Hash function is Symmetric Toeplitz\n");
12631                 break;
12632         default:
12633                 printf("Unknown hash function\n");
12634                 break;
12635         }
12636
12637         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12638                 idx = i / UINT64_BIT;
12639                 offset = i % UINT64_BIT;
12640                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12641                                                 (1ULL << offset)))
12642                         continue;
12643                 str = flowtype_to_str(i);
12644                 if (!str)
12645                         continue;
12646                 printf("Symmetric hash is %s globally for flow type %s "
12647                                                         "by port %d\n",
12648                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12649                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12650                                                         res->port_id);
12651         }
12652 }
12653
12654 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12655         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12656                 get_hash_global_config, "get_hash_global_config");
12657 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12658         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12659                 port_id, UINT16);
12660
12661 cmdline_parse_inst_t cmd_get_hash_global_config = {
12662         .f = cmd_get_hash_global_config_parsed,
12663         .data = NULL,
12664         .help_str = "get_hash_global_config <port_id>",
12665         .tokens = {
12666                 (void *)&cmd_get_hash_global_config_all,
12667                 (void *)&cmd_get_hash_global_config_port_id,
12668                 NULL,
12669         },
12670 };
12671
12672 /* Set global config of hash function */
12673 struct cmd_set_hash_global_config_result {
12674         cmdline_fixed_string_t set_hash_global_config;
12675         portid_t port_id;
12676         cmdline_fixed_string_t hash_func;
12677         cmdline_fixed_string_t flow_type;
12678         cmdline_fixed_string_t enable;
12679 };
12680
12681 static void
12682 cmd_set_hash_global_config_parsed(void *parsed_result,
12683                                   __rte_unused struct cmdline *cl,
12684                                   __rte_unused void *data)
12685 {
12686         struct cmd_set_hash_global_config_result *res = parsed_result;
12687         struct rte_eth_hash_filter_info info;
12688         uint32_t ftype, idx, offset;
12689         int ret;
12690
12691         if (rte_eth_dev_filter_supported(res->port_id,
12692                                 RTE_ETH_FILTER_HASH) < 0) {
12693                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12694                                                         res->port_id);
12695                 return;
12696         }
12697         memset(&info, 0, sizeof(info));
12698         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12699         if (!strcmp(res->hash_func, "toeplitz"))
12700                 info.info.global_conf.hash_func =
12701                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12702         else if (!strcmp(res->hash_func, "simple_xor"))
12703                 info.info.global_conf.hash_func =
12704                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12705         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12706                 info.info.global_conf.hash_func =
12707                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12708         else if (!strcmp(res->hash_func, "default"))
12709                 info.info.global_conf.hash_func =
12710                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12711
12712         ftype = str2flowtype(res->flow_type);
12713         idx = ftype / UINT64_BIT;
12714         offset = ftype % UINT64_BIT;
12715         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12716         if (!strcmp(res->enable, "enable"))
12717                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12718                                                 (1ULL << offset);
12719         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12720                                         RTE_ETH_FILTER_SET, &info);
12721         if (ret < 0)
12722                 printf("Cannot set global hash configurations by port %d\n",
12723                                                         res->port_id);
12724         else
12725                 printf("Global hash configurations have been set "
12726                         "successfully by port %d\n", res->port_id);
12727 }
12728
12729 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12730         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12731                 set_hash_global_config, "set_hash_global_config");
12732 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12733         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12734                 port_id, UINT16);
12735 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12736         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12737                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12738 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12739         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12740                 flow_type,
12741                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12742                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12743 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12744         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12745                 enable, "enable#disable");
12746
12747 cmdline_parse_inst_t cmd_set_hash_global_config = {
12748         .f = cmd_set_hash_global_config_parsed,
12749         .data = NULL,
12750         .help_str = "set_hash_global_config <port_id> "
12751                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12752                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12753                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12754                 "l2_payload enable|disable",
12755         .tokens = {
12756                 (void *)&cmd_set_hash_global_config_all,
12757                 (void *)&cmd_set_hash_global_config_port_id,
12758                 (void *)&cmd_set_hash_global_config_hash_func,
12759                 (void *)&cmd_set_hash_global_config_flow_type,
12760                 (void *)&cmd_set_hash_global_config_enable,
12761                 NULL,
12762         },
12763 };
12764
12765 /* Set hash input set */
12766 struct cmd_set_hash_input_set_result {
12767         cmdline_fixed_string_t set_hash_input_set;
12768         portid_t port_id;
12769         cmdline_fixed_string_t flow_type;
12770         cmdline_fixed_string_t inset_field;
12771         cmdline_fixed_string_t select;
12772 };
12773
12774 static enum rte_eth_input_set_field
12775 str2inset(char *string)
12776 {
12777         uint16_t i;
12778
12779         static const struct {
12780                 char str[32];
12781                 enum rte_eth_input_set_field inset;
12782         } inset_table[] = {
12783                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12784                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12785                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12786                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12787                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12788                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12789                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12790                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12791                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12792                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12793                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12794                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12795                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12796                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12797                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12798                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12799                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12800                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12801                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12802                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12803                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12804                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12805                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12806                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12807                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12808                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12809                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12810                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12811                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12812                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12813                 {"none", RTE_ETH_INPUT_SET_NONE},
12814         };
12815
12816         for (i = 0; i < RTE_DIM(inset_table); i++) {
12817                 if (!strcmp(string, inset_table[i].str))
12818                         return inset_table[i].inset;
12819         }
12820
12821         return RTE_ETH_INPUT_SET_UNKNOWN;
12822 }
12823
12824 static void
12825 cmd_set_hash_input_set_parsed(void *parsed_result,
12826                               __rte_unused struct cmdline *cl,
12827                               __rte_unused void *data)
12828 {
12829         struct cmd_set_hash_input_set_result *res = parsed_result;
12830         struct rte_eth_hash_filter_info info;
12831
12832         memset(&info, 0, sizeof(info));
12833         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12834         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12835         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12836         info.info.input_set_conf.inset_size = 1;
12837         if (!strcmp(res->select, "select"))
12838                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12839         else if (!strcmp(res->select, "add"))
12840                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12841         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12842                                 RTE_ETH_FILTER_SET, &info);
12843 }
12844
12845 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12846         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12847                 set_hash_input_set, "set_hash_input_set");
12848 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12849         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12850                 port_id, UINT16);
12851 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12852         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12853                 flow_type, NULL);
12854 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12855         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12856                 inset_field,
12857                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12858                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12859                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12860                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12861                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12862                 "fld-8th#none");
12863 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12864         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12865                 select, "select#add");
12866
12867 cmdline_parse_inst_t cmd_set_hash_input_set = {
12868         .f = cmd_set_hash_input_set_parsed,
12869         .data = NULL,
12870         .help_str = "set_hash_input_set <port_id> "
12871         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12872         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12873         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12874         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12875         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12876         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12877         "fld-7th|fld-8th|none select|add",
12878         .tokens = {
12879                 (void *)&cmd_set_hash_input_set_cmd,
12880                 (void *)&cmd_set_hash_input_set_port_id,
12881                 (void *)&cmd_set_hash_input_set_flow_type,
12882                 (void *)&cmd_set_hash_input_set_field,
12883                 (void *)&cmd_set_hash_input_set_select,
12884                 NULL,
12885         },
12886 };
12887
12888 /* Set flow director input set */
12889 struct cmd_set_fdir_input_set_result {
12890         cmdline_fixed_string_t set_fdir_input_set;
12891         portid_t port_id;
12892         cmdline_fixed_string_t flow_type;
12893         cmdline_fixed_string_t inset_field;
12894         cmdline_fixed_string_t select;
12895 };
12896
12897 static void
12898 cmd_set_fdir_input_set_parsed(void *parsed_result,
12899         __rte_unused struct cmdline *cl,
12900         __rte_unused void *data)
12901 {
12902         struct cmd_set_fdir_input_set_result *res = parsed_result;
12903         struct rte_eth_fdir_filter_info info;
12904
12905         memset(&info, 0, sizeof(info));
12906         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12907         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12908         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12909         info.info.input_set_conf.inset_size = 1;
12910         if (!strcmp(res->select, "select"))
12911                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12912         else if (!strcmp(res->select, "add"))
12913                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12914         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12915                 RTE_ETH_FILTER_SET, &info);
12916 }
12917
12918 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12919         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12920         set_fdir_input_set, "set_fdir_input_set");
12921 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12922         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12923         port_id, UINT16);
12924 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12925         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12926         flow_type,
12927         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12928         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12929 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12930         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12931         inset_field,
12932         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12933         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12934         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12935         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12936         "sctp-veri-tag#none");
12937 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12938         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12939         select, "select#add");
12940
12941 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12942         .f = cmd_set_fdir_input_set_parsed,
12943         .data = NULL,
12944         .help_str = "set_fdir_input_set <port_id> "
12945         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12946         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12947         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12948         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12949         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12950         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12951         "sctp-veri-tag|none select|add",
12952         .tokens = {
12953                 (void *)&cmd_set_fdir_input_set_cmd,
12954                 (void *)&cmd_set_fdir_input_set_port_id,
12955                 (void *)&cmd_set_fdir_input_set_flow_type,
12956                 (void *)&cmd_set_fdir_input_set_field,
12957                 (void *)&cmd_set_fdir_input_set_select,
12958                 NULL,
12959         },
12960 };
12961
12962 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12963 struct cmd_mcast_addr_result {
12964         cmdline_fixed_string_t mcast_addr_cmd;
12965         cmdline_fixed_string_t what;
12966         uint16_t port_num;
12967         struct rte_ether_addr mc_addr;
12968 };
12969
12970 static void cmd_mcast_addr_parsed(void *parsed_result,
12971                 __rte_unused struct cmdline *cl,
12972                 __rte_unused void *data)
12973 {
12974         struct cmd_mcast_addr_result *res = parsed_result;
12975
12976         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12977                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12978                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12979                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12980                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12981                 return;
12982         }
12983         if (strcmp(res->what, "add") == 0)
12984                 mcast_addr_add(res->port_num, &res->mc_addr);
12985         else
12986                 mcast_addr_remove(res->port_num, &res->mc_addr);
12987 }
12988
12989 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12990         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12991                                  mcast_addr_cmd, "mcast_addr");
12992 cmdline_parse_token_string_t cmd_mcast_addr_what =
12993         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12994                                  "add#remove");
12995 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12996         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12997 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12998         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12999
13000 cmdline_parse_inst_t cmd_mcast_addr = {
13001         .f = cmd_mcast_addr_parsed,
13002         .data = (void *)0,
13003         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
13004                 "Add/Remove multicast MAC address on port_id",
13005         .tokens = {
13006                 (void *)&cmd_mcast_addr_cmd,
13007                 (void *)&cmd_mcast_addr_what,
13008                 (void *)&cmd_mcast_addr_portnum,
13009                 (void *)&cmd_mcast_addr_addr,
13010                 NULL,
13011         },
13012 };
13013
13014 /* l2 tunnel config
13015  * only support E-tag now.
13016  */
13017
13018 /* Ether type config */
13019 struct cmd_config_l2_tunnel_eth_type_result {
13020         cmdline_fixed_string_t port;
13021         cmdline_fixed_string_t config;
13022         cmdline_fixed_string_t all;
13023         portid_t id;
13024         cmdline_fixed_string_t l2_tunnel;
13025         cmdline_fixed_string_t l2_tunnel_type;
13026         cmdline_fixed_string_t eth_type;
13027         uint16_t eth_type_val;
13028 };
13029
13030 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
13031         TOKEN_STRING_INITIALIZER
13032                 (struct cmd_config_l2_tunnel_eth_type_result,
13033                  port, "port");
13034 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
13035         TOKEN_STRING_INITIALIZER
13036                 (struct cmd_config_l2_tunnel_eth_type_result,
13037                  config, "config");
13038 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
13039         TOKEN_STRING_INITIALIZER
13040                 (struct cmd_config_l2_tunnel_eth_type_result,
13041                  all, "all");
13042 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
13043         TOKEN_NUM_INITIALIZER
13044                 (struct cmd_config_l2_tunnel_eth_type_result,
13045                  id, UINT16);
13046 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
13047         TOKEN_STRING_INITIALIZER
13048                 (struct cmd_config_l2_tunnel_eth_type_result,
13049                  l2_tunnel, "l2-tunnel");
13050 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
13051         TOKEN_STRING_INITIALIZER
13052                 (struct cmd_config_l2_tunnel_eth_type_result,
13053                  l2_tunnel_type, "E-tag");
13054 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
13055         TOKEN_STRING_INITIALIZER
13056                 (struct cmd_config_l2_tunnel_eth_type_result,
13057                  eth_type, "ether-type");
13058 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
13059         TOKEN_NUM_INITIALIZER
13060                 (struct cmd_config_l2_tunnel_eth_type_result,
13061                  eth_type_val, UINT16);
13062
13063 static enum rte_eth_tunnel_type
13064 str2fdir_l2_tunnel_type(char *string)
13065 {
13066         uint32_t i = 0;
13067
13068         static const struct {
13069                 char str[32];
13070                 enum rte_eth_tunnel_type type;
13071         } l2_tunnel_type_str[] = {
13072                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
13073         };
13074
13075         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
13076                 if (!strcmp(l2_tunnel_type_str[i].str, string))
13077                         return l2_tunnel_type_str[i].type;
13078         }
13079         return RTE_TUNNEL_TYPE_NONE;
13080 }
13081
13082 /* ether type config for all ports */
13083 static void
13084 cmd_config_l2_tunnel_eth_type_all_parsed
13085         (void *parsed_result,
13086          __rte_unused struct cmdline *cl,
13087          __rte_unused void *data)
13088 {
13089         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
13090         struct rte_eth_l2_tunnel_conf entry;
13091         portid_t pid;
13092
13093         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13094         entry.ether_type = res->eth_type_val;
13095
13096         RTE_ETH_FOREACH_DEV(pid) {
13097                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
13098         }
13099 }
13100
13101 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
13102         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
13103         .data = NULL,
13104         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
13105         .tokens = {
13106                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13107                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13108                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
13109                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13110                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13111                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13112                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13113                 NULL,
13114         },
13115 };
13116
13117 /* ether type config for a specific port */
13118 static void
13119 cmd_config_l2_tunnel_eth_type_specific_parsed(
13120         void *parsed_result,
13121         __rte_unused struct cmdline *cl,
13122         __rte_unused void *data)
13123 {
13124         struct cmd_config_l2_tunnel_eth_type_result *res =
13125                  parsed_result;
13126         struct rte_eth_l2_tunnel_conf entry;
13127
13128         if (port_id_is_invalid(res->id, ENABLED_WARN))
13129                 return;
13130
13131         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13132         entry.ether_type = res->eth_type_val;
13133
13134         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
13135 }
13136
13137 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
13138         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
13139         .data = NULL,
13140         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
13141         .tokens = {
13142                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13143                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13144                 (void *)&cmd_config_l2_tunnel_eth_type_id,
13145                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13146                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13147                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13148                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13149                 NULL,
13150         },
13151 };
13152
13153 /* Enable/disable l2 tunnel */
13154 struct cmd_config_l2_tunnel_en_dis_result {
13155         cmdline_fixed_string_t port;
13156         cmdline_fixed_string_t config;
13157         cmdline_fixed_string_t all;
13158         portid_t id;
13159         cmdline_fixed_string_t l2_tunnel;
13160         cmdline_fixed_string_t l2_tunnel_type;
13161         cmdline_fixed_string_t en_dis;
13162 };
13163
13164 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
13165         TOKEN_STRING_INITIALIZER
13166                 (struct cmd_config_l2_tunnel_en_dis_result,
13167                  port, "port");
13168 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
13169         TOKEN_STRING_INITIALIZER
13170                 (struct cmd_config_l2_tunnel_en_dis_result,
13171                  config, "config");
13172 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
13173         TOKEN_STRING_INITIALIZER
13174                 (struct cmd_config_l2_tunnel_en_dis_result,
13175                  all, "all");
13176 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
13177         TOKEN_NUM_INITIALIZER
13178                 (struct cmd_config_l2_tunnel_en_dis_result,
13179                  id, UINT16);
13180 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
13181         TOKEN_STRING_INITIALIZER
13182                 (struct cmd_config_l2_tunnel_en_dis_result,
13183                  l2_tunnel, "l2-tunnel");
13184 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
13185         TOKEN_STRING_INITIALIZER
13186                 (struct cmd_config_l2_tunnel_en_dis_result,
13187                  l2_tunnel_type, "E-tag");
13188 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
13189         TOKEN_STRING_INITIALIZER
13190                 (struct cmd_config_l2_tunnel_en_dis_result,
13191                  en_dis, "enable#disable");
13192
13193 /* enable/disable l2 tunnel for all ports */
13194 static void
13195 cmd_config_l2_tunnel_en_dis_all_parsed(
13196         void *parsed_result,
13197         __rte_unused struct cmdline *cl,
13198         __rte_unused void *data)
13199 {
13200         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
13201         struct rte_eth_l2_tunnel_conf entry;
13202         portid_t pid;
13203         uint8_t en;
13204
13205         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13206
13207         if (!strcmp("enable", res->en_dis))
13208                 en = 1;
13209         else
13210                 en = 0;
13211
13212         RTE_ETH_FOREACH_DEV(pid) {
13213                 rte_eth_dev_l2_tunnel_offload_set(pid,
13214                                                   &entry,
13215                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13216                                                   en);
13217         }
13218 }
13219
13220 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
13221         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
13222         .data = NULL,
13223         .help_str = "port config all l2-tunnel E-tag enable|disable",
13224         .tokens = {
13225                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13226                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13227                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
13228                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13229                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13230                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13231                 NULL,
13232         },
13233 };
13234
13235 /* enable/disable l2 tunnel for a port */
13236 static void
13237 cmd_config_l2_tunnel_en_dis_specific_parsed(
13238         void *parsed_result,
13239         __rte_unused struct cmdline *cl,
13240         __rte_unused void *data)
13241 {
13242         struct cmd_config_l2_tunnel_en_dis_result *res =
13243                 parsed_result;
13244         struct rte_eth_l2_tunnel_conf entry;
13245
13246         if (port_id_is_invalid(res->id, ENABLED_WARN))
13247                 return;
13248
13249         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13250
13251         if (!strcmp("enable", res->en_dis))
13252                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13253                                                   &entry,
13254                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13255                                                   1);
13256         else
13257                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13258                                                   &entry,
13259                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13260                                                   0);
13261 }
13262
13263 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13264         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13265         .data = NULL,
13266         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13267         .tokens = {
13268                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13269                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13270                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13271                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13272                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13273                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13274                 NULL,
13275         },
13276 };
13277
13278 /* E-tag configuration */
13279
13280 /* Common result structure for all E-tag configuration */
13281 struct cmd_config_e_tag_result {
13282         cmdline_fixed_string_t e_tag;
13283         cmdline_fixed_string_t set;
13284         cmdline_fixed_string_t insertion;
13285         cmdline_fixed_string_t stripping;
13286         cmdline_fixed_string_t forwarding;
13287         cmdline_fixed_string_t filter;
13288         cmdline_fixed_string_t add;
13289         cmdline_fixed_string_t del;
13290         cmdline_fixed_string_t on;
13291         cmdline_fixed_string_t off;
13292         cmdline_fixed_string_t on_off;
13293         cmdline_fixed_string_t port_tag_id;
13294         uint32_t port_tag_id_val;
13295         cmdline_fixed_string_t e_tag_id;
13296         uint16_t e_tag_id_val;
13297         cmdline_fixed_string_t dst_pool;
13298         uint8_t dst_pool_val;
13299         cmdline_fixed_string_t port;
13300         portid_t port_id;
13301         cmdline_fixed_string_t vf;
13302         uint8_t vf_id;
13303 };
13304
13305 /* Common CLI fields for all E-tag configuration */
13306 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13307         TOKEN_STRING_INITIALIZER
13308                 (struct cmd_config_e_tag_result,
13309                  e_tag, "E-tag");
13310 cmdline_parse_token_string_t cmd_config_e_tag_set =
13311         TOKEN_STRING_INITIALIZER
13312                 (struct cmd_config_e_tag_result,
13313                  set, "set");
13314 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13315         TOKEN_STRING_INITIALIZER
13316                 (struct cmd_config_e_tag_result,
13317                  insertion, "insertion");
13318 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13319         TOKEN_STRING_INITIALIZER
13320                 (struct cmd_config_e_tag_result,
13321                  stripping, "stripping");
13322 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13323         TOKEN_STRING_INITIALIZER
13324                 (struct cmd_config_e_tag_result,
13325                  forwarding, "forwarding");
13326 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13327         TOKEN_STRING_INITIALIZER
13328                 (struct cmd_config_e_tag_result,
13329                  filter, "filter");
13330 cmdline_parse_token_string_t cmd_config_e_tag_add =
13331         TOKEN_STRING_INITIALIZER
13332                 (struct cmd_config_e_tag_result,
13333                  add, "add");
13334 cmdline_parse_token_string_t cmd_config_e_tag_del =
13335         TOKEN_STRING_INITIALIZER
13336                 (struct cmd_config_e_tag_result,
13337                  del, "del");
13338 cmdline_parse_token_string_t cmd_config_e_tag_on =
13339         TOKEN_STRING_INITIALIZER
13340                 (struct cmd_config_e_tag_result,
13341                  on, "on");
13342 cmdline_parse_token_string_t cmd_config_e_tag_off =
13343         TOKEN_STRING_INITIALIZER
13344                 (struct cmd_config_e_tag_result,
13345                  off, "off");
13346 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13347         TOKEN_STRING_INITIALIZER
13348                 (struct cmd_config_e_tag_result,
13349                  on_off, "on#off");
13350 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13351         TOKEN_STRING_INITIALIZER
13352                 (struct cmd_config_e_tag_result,
13353                  port_tag_id, "port-tag-id");
13354 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13355         TOKEN_NUM_INITIALIZER
13356                 (struct cmd_config_e_tag_result,
13357                  port_tag_id_val, UINT32);
13358 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13359         TOKEN_STRING_INITIALIZER
13360                 (struct cmd_config_e_tag_result,
13361                  e_tag_id, "e-tag-id");
13362 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13363         TOKEN_NUM_INITIALIZER
13364                 (struct cmd_config_e_tag_result,
13365                  e_tag_id_val, UINT16);
13366 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13367         TOKEN_STRING_INITIALIZER
13368                 (struct cmd_config_e_tag_result,
13369                  dst_pool, "dst-pool");
13370 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13371         TOKEN_NUM_INITIALIZER
13372                 (struct cmd_config_e_tag_result,
13373                  dst_pool_val, UINT8);
13374 cmdline_parse_token_string_t cmd_config_e_tag_port =
13375         TOKEN_STRING_INITIALIZER
13376                 (struct cmd_config_e_tag_result,
13377                  port, "port");
13378 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13379         TOKEN_NUM_INITIALIZER
13380                 (struct cmd_config_e_tag_result,
13381                  port_id, UINT16);
13382 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13383         TOKEN_STRING_INITIALIZER
13384                 (struct cmd_config_e_tag_result,
13385                  vf, "vf");
13386 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13387         TOKEN_NUM_INITIALIZER
13388                 (struct cmd_config_e_tag_result,
13389                  vf_id, UINT8);
13390
13391 /* E-tag insertion configuration */
13392 static void
13393 cmd_config_e_tag_insertion_en_parsed(
13394         void *parsed_result,
13395         __rte_unused struct cmdline *cl,
13396         __rte_unused void *data)
13397 {
13398         struct cmd_config_e_tag_result *res =
13399                 parsed_result;
13400         struct rte_eth_l2_tunnel_conf entry;
13401
13402         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13403                 return;
13404
13405         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13406         entry.tunnel_id = res->port_tag_id_val;
13407         entry.vf_id = res->vf_id;
13408         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13409                                           &entry,
13410                                           ETH_L2_TUNNEL_INSERTION_MASK,
13411                                           1);
13412 }
13413
13414 static void
13415 cmd_config_e_tag_insertion_dis_parsed(
13416         void *parsed_result,
13417         __rte_unused struct cmdline *cl,
13418         __rte_unused void *data)
13419 {
13420         struct cmd_config_e_tag_result *res =
13421                 parsed_result;
13422         struct rte_eth_l2_tunnel_conf entry;
13423
13424         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13425                 return;
13426
13427         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13428         entry.vf_id = res->vf_id;
13429
13430         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13431                                           &entry,
13432                                           ETH_L2_TUNNEL_INSERTION_MASK,
13433                                           0);
13434 }
13435
13436 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13437         .f = cmd_config_e_tag_insertion_en_parsed,
13438         .data = NULL,
13439         .help_str = "E-tag ... : E-tag insertion enable",
13440         .tokens = {
13441                 (void *)&cmd_config_e_tag_e_tag,
13442                 (void *)&cmd_config_e_tag_set,
13443                 (void *)&cmd_config_e_tag_insertion,
13444                 (void *)&cmd_config_e_tag_on,
13445                 (void *)&cmd_config_e_tag_port_tag_id,
13446                 (void *)&cmd_config_e_tag_port_tag_id_val,
13447                 (void *)&cmd_config_e_tag_port,
13448                 (void *)&cmd_config_e_tag_port_id,
13449                 (void *)&cmd_config_e_tag_vf,
13450                 (void *)&cmd_config_e_tag_vf_id,
13451                 NULL,
13452         },
13453 };
13454
13455 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13456         .f = cmd_config_e_tag_insertion_dis_parsed,
13457         .data = NULL,
13458         .help_str = "E-tag ... : E-tag insertion disable",
13459         .tokens = {
13460                 (void *)&cmd_config_e_tag_e_tag,
13461                 (void *)&cmd_config_e_tag_set,
13462                 (void *)&cmd_config_e_tag_insertion,
13463                 (void *)&cmd_config_e_tag_off,
13464                 (void *)&cmd_config_e_tag_port,
13465                 (void *)&cmd_config_e_tag_port_id,
13466                 (void *)&cmd_config_e_tag_vf,
13467                 (void *)&cmd_config_e_tag_vf_id,
13468                 NULL,
13469         },
13470 };
13471
13472 /* E-tag stripping configuration */
13473 static void
13474 cmd_config_e_tag_stripping_parsed(
13475         void *parsed_result,
13476         __rte_unused struct cmdline *cl,
13477         __rte_unused void *data)
13478 {
13479         struct cmd_config_e_tag_result *res =
13480                 parsed_result;
13481         struct rte_eth_l2_tunnel_conf entry;
13482
13483         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13484                 return;
13485
13486         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13487
13488         if (!strcmp(res->on_off, "on"))
13489                 rte_eth_dev_l2_tunnel_offload_set
13490                         (res->port_id,
13491                          &entry,
13492                          ETH_L2_TUNNEL_STRIPPING_MASK,
13493                          1);
13494         else
13495                 rte_eth_dev_l2_tunnel_offload_set
13496                         (res->port_id,
13497                          &entry,
13498                          ETH_L2_TUNNEL_STRIPPING_MASK,
13499                          0);
13500 }
13501
13502 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13503         .f = cmd_config_e_tag_stripping_parsed,
13504         .data = NULL,
13505         .help_str = "E-tag ... : E-tag stripping enable/disable",
13506         .tokens = {
13507                 (void *)&cmd_config_e_tag_e_tag,
13508                 (void *)&cmd_config_e_tag_set,
13509                 (void *)&cmd_config_e_tag_stripping,
13510                 (void *)&cmd_config_e_tag_on_off,
13511                 (void *)&cmd_config_e_tag_port,
13512                 (void *)&cmd_config_e_tag_port_id,
13513                 NULL,
13514         },
13515 };
13516
13517 /* E-tag forwarding configuration */
13518 static void
13519 cmd_config_e_tag_forwarding_parsed(
13520         void *parsed_result,
13521         __rte_unused struct cmdline *cl,
13522         __rte_unused void *data)
13523 {
13524         struct cmd_config_e_tag_result *res = parsed_result;
13525         struct rte_eth_l2_tunnel_conf entry;
13526
13527         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13528                 return;
13529
13530         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13531
13532         if (!strcmp(res->on_off, "on"))
13533                 rte_eth_dev_l2_tunnel_offload_set
13534                         (res->port_id,
13535                          &entry,
13536                          ETH_L2_TUNNEL_FORWARDING_MASK,
13537                          1);
13538         else
13539                 rte_eth_dev_l2_tunnel_offload_set
13540                         (res->port_id,
13541                          &entry,
13542                          ETH_L2_TUNNEL_FORWARDING_MASK,
13543                          0);
13544 }
13545
13546 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13547         .f = cmd_config_e_tag_forwarding_parsed,
13548         .data = NULL,
13549         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13550         .tokens = {
13551                 (void *)&cmd_config_e_tag_e_tag,
13552                 (void *)&cmd_config_e_tag_set,
13553                 (void *)&cmd_config_e_tag_forwarding,
13554                 (void *)&cmd_config_e_tag_on_off,
13555                 (void *)&cmd_config_e_tag_port,
13556                 (void *)&cmd_config_e_tag_port_id,
13557                 NULL,
13558         },
13559 };
13560
13561 /* E-tag filter configuration */
13562 static void
13563 cmd_config_e_tag_filter_add_parsed(
13564         void *parsed_result,
13565         __rte_unused struct cmdline *cl,
13566         __rte_unused void *data)
13567 {
13568         struct cmd_config_e_tag_result *res = parsed_result;
13569         struct rte_eth_l2_tunnel_conf entry;
13570         int ret = 0;
13571
13572         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13573                 return;
13574
13575         if (res->e_tag_id_val > 0x3fff) {
13576                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13577                 return;
13578         }
13579
13580         ret = rte_eth_dev_filter_supported(res->port_id,
13581                                            RTE_ETH_FILTER_L2_TUNNEL);
13582         if (ret < 0) {
13583                 printf("E-tag filter is not supported on port %u.\n",
13584                        res->port_id);
13585                 return;
13586         }
13587
13588         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13589         entry.tunnel_id = res->e_tag_id_val;
13590         entry.pool = res->dst_pool_val;
13591
13592         ret = rte_eth_dev_filter_ctrl(res->port_id,
13593                                       RTE_ETH_FILTER_L2_TUNNEL,
13594                                       RTE_ETH_FILTER_ADD,
13595                                       &entry);
13596         if (ret < 0)
13597                 printf("E-tag filter programming error: (%s)\n",
13598                        strerror(-ret));
13599 }
13600
13601 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13602         .f = cmd_config_e_tag_filter_add_parsed,
13603         .data = NULL,
13604         .help_str = "E-tag ... : E-tag filter add",
13605         .tokens = {
13606                 (void *)&cmd_config_e_tag_e_tag,
13607                 (void *)&cmd_config_e_tag_set,
13608                 (void *)&cmd_config_e_tag_filter,
13609                 (void *)&cmd_config_e_tag_add,
13610                 (void *)&cmd_config_e_tag_e_tag_id,
13611                 (void *)&cmd_config_e_tag_e_tag_id_val,
13612                 (void *)&cmd_config_e_tag_dst_pool,
13613                 (void *)&cmd_config_e_tag_dst_pool_val,
13614                 (void *)&cmd_config_e_tag_port,
13615                 (void *)&cmd_config_e_tag_port_id,
13616                 NULL,
13617         },
13618 };
13619
13620 static void
13621 cmd_config_e_tag_filter_del_parsed(
13622         void *parsed_result,
13623         __rte_unused struct cmdline *cl,
13624         __rte_unused void *data)
13625 {
13626         struct cmd_config_e_tag_result *res = parsed_result;
13627         struct rte_eth_l2_tunnel_conf entry;
13628         int ret = 0;
13629
13630         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13631                 return;
13632
13633         if (res->e_tag_id_val > 0x3fff) {
13634                 printf("e-tag-id must be less than 0x3fff.\n");
13635                 return;
13636         }
13637
13638         ret = rte_eth_dev_filter_supported(res->port_id,
13639                                            RTE_ETH_FILTER_L2_TUNNEL);
13640         if (ret < 0) {
13641                 printf("E-tag filter is not supported on port %u.\n",
13642                        res->port_id);
13643                 return;
13644         }
13645
13646         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13647         entry.tunnel_id = res->e_tag_id_val;
13648
13649         ret = rte_eth_dev_filter_ctrl(res->port_id,
13650                                       RTE_ETH_FILTER_L2_TUNNEL,
13651                                       RTE_ETH_FILTER_DELETE,
13652                                       &entry);
13653         if (ret < 0)
13654                 printf("E-tag filter programming error: (%s)\n",
13655                        strerror(-ret));
13656 }
13657
13658 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13659         .f = cmd_config_e_tag_filter_del_parsed,
13660         .data = NULL,
13661         .help_str = "E-tag ... : E-tag filter delete",
13662         .tokens = {
13663                 (void *)&cmd_config_e_tag_e_tag,
13664                 (void *)&cmd_config_e_tag_set,
13665                 (void *)&cmd_config_e_tag_filter,
13666                 (void *)&cmd_config_e_tag_del,
13667                 (void *)&cmd_config_e_tag_e_tag_id,
13668                 (void *)&cmd_config_e_tag_e_tag_id_val,
13669                 (void *)&cmd_config_e_tag_port,
13670                 (void *)&cmd_config_e_tag_port_id,
13671                 NULL,
13672         },
13673 };
13674
13675 /* vf vlan anti spoof configuration */
13676
13677 /* Common result structure for vf vlan anti spoof */
13678 struct cmd_vf_vlan_anti_spoof_result {
13679         cmdline_fixed_string_t set;
13680         cmdline_fixed_string_t vf;
13681         cmdline_fixed_string_t vlan;
13682         cmdline_fixed_string_t antispoof;
13683         portid_t port_id;
13684         uint32_t vf_id;
13685         cmdline_fixed_string_t on_off;
13686 };
13687
13688 /* Common CLI fields for vf vlan anti spoof enable disable */
13689 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13690         TOKEN_STRING_INITIALIZER
13691                 (struct cmd_vf_vlan_anti_spoof_result,
13692                  set, "set");
13693 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13694         TOKEN_STRING_INITIALIZER
13695                 (struct cmd_vf_vlan_anti_spoof_result,
13696                  vf, "vf");
13697 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13698         TOKEN_STRING_INITIALIZER
13699                 (struct cmd_vf_vlan_anti_spoof_result,
13700                  vlan, "vlan");
13701 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13702         TOKEN_STRING_INITIALIZER
13703                 (struct cmd_vf_vlan_anti_spoof_result,
13704                  antispoof, "antispoof");
13705 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13706         TOKEN_NUM_INITIALIZER
13707                 (struct cmd_vf_vlan_anti_spoof_result,
13708                  port_id, UINT16);
13709 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13710         TOKEN_NUM_INITIALIZER
13711                 (struct cmd_vf_vlan_anti_spoof_result,
13712                  vf_id, UINT32);
13713 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13714         TOKEN_STRING_INITIALIZER
13715                 (struct cmd_vf_vlan_anti_spoof_result,
13716                  on_off, "on#off");
13717
13718 static void
13719 cmd_set_vf_vlan_anti_spoof_parsed(
13720         void *parsed_result,
13721         __rte_unused struct cmdline *cl,
13722         __rte_unused void *data)
13723 {
13724         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13725         int ret = -ENOTSUP;
13726
13727         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13728
13729         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13730                 return;
13731
13732 #ifdef RTE_NET_IXGBE
13733         if (ret == -ENOTSUP)
13734                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13735                                 res->vf_id, is_on);
13736 #endif
13737 #ifdef RTE_NET_I40E
13738         if (ret == -ENOTSUP)
13739                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13740                                 res->vf_id, is_on);
13741 #endif
13742 #ifdef RTE_NET_BNXT
13743         if (ret == -ENOTSUP)
13744                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13745                                 res->vf_id, is_on);
13746 #endif
13747
13748         switch (ret) {
13749         case 0:
13750                 break;
13751         case -EINVAL:
13752                 printf("invalid vf_id %d\n", res->vf_id);
13753                 break;
13754         case -ENODEV:
13755                 printf("invalid port_id %d\n", res->port_id);
13756                 break;
13757         case -ENOTSUP:
13758                 printf("function not implemented\n");
13759                 break;
13760         default:
13761                 printf("programming error: (%s)\n", strerror(-ret));
13762         }
13763 }
13764
13765 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13766         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13767         .data = NULL,
13768         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13769         .tokens = {
13770                 (void *)&cmd_vf_vlan_anti_spoof_set,
13771                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13772                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13773                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13774                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13775                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13776                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13777                 NULL,
13778         },
13779 };
13780
13781 /* vf mac anti spoof configuration */
13782
13783 /* Common result structure for vf mac anti spoof */
13784 struct cmd_vf_mac_anti_spoof_result {
13785         cmdline_fixed_string_t set;
13786         cmdline_fixed_string_t vf;
13787         cmdline_fixed_string_t mac;
13788         cmdline_fixed_string_t antispoof;
13789         portid_t port_id;
13790         uint32_t vf_id;
13791         cmdline_fixed_string_t on_off;
13792 };
13793
13794 /* Common CLI fields for vf mac anti spoof enable disable */
13795 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13796         TOKEN_STRING_INITIALIZER
13797                 (struct cmd_vf_mac_anti_spoof_result,
13798                  set, "set");
13799 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13800         TOKEN_STRING_INITIALIZER
13801                 (struct cmd_vf_mac_anti_spoof_result,
13802                  vf, "vf");
13803 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13804         TOKEN_STRING_INITIALIZER
13805                 (struct cmd_vf_mac_anti_spoof_result,
13806                  mac, "mac");
13807 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13808         TOKEN_STRING_INITIALIZER
13809                 (struct cmd_vf_mac_anti_spoof_result,
13810                  antispoof, "antispoof");
13811 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13812         TOKEN_NUM_INITIALIZER
13813                 (struct cmd_vf_mac_anti_spoof_result,
13814                  port_id, UINT16);
13815 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13816         TOKEN_NUM_INITIALIZER
13817                 (struct cmd_vf_mac_anti_spoof_result,
13818                  vf_id, UINT32);
13819 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13820         TOKEN_STRING_INITIALIZER
13821                 (struct cmd_vf_mac_anti_spoof_result,
13822                  on_off, "on#off");
13823
13824 static void
13825 cmd_set_vf_mac_anti_spoof_parsed(
13826         void *parsed_result,
13827         __rte_unused struct cmdline *cl,
13828         __rte_unused void *data)
13829 {
13830         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13831         int ret = -ENOTSUP;
13832
13833         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13834
13835         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13836                 return;
13837
13838 #ifdef RTE_NET_IXGBE
13839         if (ret == -ENOTSUP)
13840                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13841                         res->vf_id, is_on);
13842 #endif
13843 #ifdef RTE_NET_I40E
13844         if (ret == -ENOTSUP)
13845                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13846                         res->vf_id, is_on);
13847 #endif
13848 #ifdef RTE_NET_BNXT
13849         if (ret == -ENOTSUP)
13850                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13851                         res->vf_id, is_on);
13852 #endif
13853
13854         switch (ret) {
13855         case 0:
13856                 break;
13857         case -EINVAL:
13858                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13859                 break;
13860         case -ENODEV:
13861                 printf("invalid port_id %d\n", res->port_id);
13862                 break;
13863         case -ENOTSUP:
13864                 printf("function not implemented\n");
13865                 break;
13866         default:
13867                 printf("programming error: (%s)\n", strerror(-ret));
13868         }
13869 }
13870
13871 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13872         .f = cmd_set_vf_mac_anti_spoof_parsed,
13873         .data = NULL,
13874         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13875         .tokens = {
13876                 (void *)&cmd_vf_mac_anti_spoof_set,
13877                 (void *)&cmd_vf_mac_anti_spoof_vf,
13878                 (void *)&cmd_vf_mac_anti_spoof_mac,
13879                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13880                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13881                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13882                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13883                 NULL,
13884         },
13885 };
13886
13887 /* vf vlan strip queue configuration */
13888
13889 /* Common result structure for vf mac anti spoof */
13890 struct cmd_vf_vlan_stripq_result {
13891         cmdline_fixed_string_t set;
13892         cmdline_fixed_string_t vf;
13893         cmdline_fixed_string_t vlan;
13894         cmdline_fixed_string_t stripq;
13895         portid_t port_id;
13896         uint16_t vf_id;
13897         cmdline_fixed_string_t on_off;
13898 };
13899
13900 /* Common CLI fields for vf vlan strip enable disable */
13901 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13902         TOKEN_STRING_INITIALIZER
13903                 (struct cmd_vf_vlan_stripq_result,
13904                  set, "set");
13905 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13906         TOKEN_STRING_INITIALIZER
13907                 (struct cmd_vf_vlan_stripq_result,
13908                  vf, "vf");
13909 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13910         TOKEN_STRING_INITIALIZER
13911                 (struct cmd_vf_vlan_stripq_result,
13912                  vlan, "vlan");
13913 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13914         TOKEN_STRING_INITIALIZER
13915                 (struct cmd_vf_vlan_stripq_result,
13916                  stripq, "stripq");
13917 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13918         TOKEN_NUM_INITIALIZER
13919                 (struct cmd_vf_vlan_stripq_result,
13920                  port_id, UINT16);
13921 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13922         TOKEN_NUM_INITIALIZER
13923                 (struct cmd_vf_vlan_stripq_result,
13924                  vf_id, UINT16);
13925 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13926         TOKEN_STRING_INITIALIZER
13927                 (struct cmd_vf_vlan_stripq_result,
13928                  on_off, "on#off");
13929
13930 static void
13931 cmd_set_vf_vlan_stripq_parsed(
13932         void *parsed_result,
13933         __rte_unused struct cmdline *cl,
13934         __rte_unused void *data)
13935 {
13936         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13937         int ret = -ENOTSUP;
13938
13939         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13940
13941         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13942                 return;
13943
13944 #ifdef RTE_NET_IXGBE
13945         if (ret == -ENOTSUP)
13946                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13947                         res->vf_id, is_on);
13948 #endif
13949 #ifdef RTE_NET_I40E
13950         if (ret == -ENOTSUP)
13951                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13952                         res->vf_id, is_on);
13953 #endif
13954 #ifdef RTE_NET_BNXT
13955         if (ret == -ENOTSUP)
13956                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13957                         res->vf_id, is_on);
13958 #endif
13959
13960         switch (ret) {
13961         case 0:
13962                 break;
13963         case -EINVAL:
13964                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13965                 break;
13966         case -ENODEV:
13967                 printf("invalid port_id %d\n", res->port_id);
13968                 break;
13969         case -ENOTSUP:
13970                 printf("function not implemented\n");
13971                 break;
13972         default:
13973                 printf("programming error: (%s)\n", strerror(-ret));
13974         }
13975 }
13976
13977 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13978         .f = cmd_set_vf_vlan_stripq_parsed,
13979         .data = NULL,
13980         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13981         .tokens = {
13982                 (void *)&cmd_vf_vlan_stripq_set,
13983                 (void *)&cmd_vf_vlan_stripq_vf,
13984                 (void *)&cmd_vf_vlan_stripq_vlan,
13985                 (void *)&cmd_vf_vlan_stripq_stripq,
13986                 (void *)&cmd_vf_vlan_stripq_port_id,
13987                 (void *)&cmd_vf_vlan_stripq_vf_id,
13988                 (void *)&cmd_vf_vlan_stripq_on_off,
13989                 NULL,
13990         },
13991 };
13992
13993 /* vf vlan insert configuration */
13994
13995 /* Common result structure for vf vlan insert */
13996 struct cmd_vf_vlan_insert_result {
13997         cmdline_fixed_string_t set;
13998         cmdline_fixed_string_t vf;
13999         cmdline_fixed_string_t vlan;
14000         cmdline_fixed_string_t insert;
14001         portid_t port_id;
14002         uint16_t vf_id;
14003         uint16_t vlan_id;
14004 };
14005
14006 /* Common CLI fields for vf vlan insert enable disable */
14007 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
14008         TOKEN_STRING_INITIALIZER
14009                 (struct cmd_vf_vlan_insert_result,
14010                  set, "set");
14011 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
14012         TOKEN_STRING_INITIALIZER
14013                 (struct cmd_vf_vlan_insert_result,
14014                  vf, "vf");
14015 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
14016         TOKEN_STRING_INITIALIZER
14017                 (struct cmd_vf_vlan_insert_result,
14018                  vlan, "vlan");
14019 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
14020         TOKEN_STRING_INITIALIZER
14021                 (struct cmd_vf_vlan_insert_result,
14022                  insert, "insert");
14023 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
14024         TOKEN_NUM_INITIALIZER
14025                 (struct cmd_vf_vlan_insert_result,
14026                  port_id, UINT16);
14027 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
14028         TOKEN_NUM_INITIALIZER
14029                 (struct cmd_vf_vlan_insert_result,
14030                  vf_id, UINT16);
14031 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
14032         TOKEN_NUM_INITIALIZER
14033                 (struct cmd_vf_vlan_insert_result,
14034                  vlan_id, UINT16);
14035
14036 static void
14037 cmd_set_vf_vlan_insert_parsed(
14038         void *parsed_result,
14039         __rte_unused struct cmdline *cl,
14040         __rte_unused void *data)
14041 {
14042         struct cmd_vf_vlan_insert_result *res = parsed_result;
14043         int ret = -ENOTSUP;
14044
14045         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14046                 return;
14047
14048 #ifdef RTE_NET_IXGBE
14049         if (ret == -ENOTSUP)
14050                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
14051                         res->vlan_id);
14052 #endif
14053 #ifdef RTE_NET_I40E
14054         if (ret == -ENOTSUP)
14055                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
14056                         res->vlan_id);
14057 #endif
14058 #ifdef RTE_NET_BNXT
14059         if (ret == -ENOTSUP)
14060                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
14061                         res->vlan_id);
14062 #endif
14063
14064         switch (ret) {
14065         case 0:
14066                 break;
14067         case -EINVAL:
14068                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
14069                 break;
14070         case -ENODEV:
14071                 printf("invalid port_id %d\n", res->port_id);
14072                 break;
14073         case -ENOTSUP:
14074                 printf("function not implemented\n");
14075                 break;
14076         default:
14077                 printf("programming error: (%s)\n", strerror(-ret));
14078         }
14079 }
14080
14081 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
14082         .f = cmd_set_vf_vlan_insert_parsed,
14083         .data = NULL,
14084         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
14085         .tokens = {
14086                 (void *)&cmd_vf_vlan_insert_set,
14087                 (void *)&cmd_vf_vlan_insert_vf,
14088                 (void *)&cmd_vf_vlan_insert_vlan,
14089                 (void *)&cmd_vf_vlan_insert_insert,
14090                 (void *)&cmd_vf_vlan_insert_port_id,
14091                 (void *)&cmd_vf_vlan_insert_vf_id,
14092                 (void *)&cmd_vf_vlan_insert_vlan_id,
14093                 NULL,
14094         },
14095 };
14096
14097 /* tx loopback configuration */
14098
14099 /* Common result structure for tx loopback */
14100 struct cmd_tx_loopback_result {
14101         cmdline_fixed_string_t set;
14102         cmdline_fixed_string_t tx;
14103         cmdline_fixed_string_t loopback;
14104         portid_t port_id;
14105         cmdline_fixed_string_t on_off;
14106 };
14107
14108 /* Common CLI fields for tx loopback enable disable */
14109 cmdline_parse_token_string_t cmd_tx_loopback_set =
14110         TOKEN_STRING_INITIALIZER
14111                 (struct cmd_tx_loopback_result,
14112                  set, "set");
14113 cmdline_parse_token_string_t cmd_tx_loopback_tx =
14114         TOKEN_STRING_INITIALIZER
14115                 (struct cmd_tx_loopback_result,
14116                  tx, "tx");
14117 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
14118         TOKEN_STRING_INITIALIZER
14119                 (struct cmd_tx_loopback_result,
14120                  loopback, "loopback");
14121 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
14122         TOKEN_NUM_INITIALIZER
14123                 (struct cmd_tx_loopback_result,
14124                  port_id, UINT16);
14125 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
14126         TOKEN_STRING_INITIALIZER
14127                 (struct cmd_tx_loopback_result,
14128                  on_off, "on#off");
14129
14130 static void
14131 cmd_set_tx_loopback_parsed(
14132         void *parsed_result,
14133         __rte_unused struct cmdline *cl,
14134         __rte_unused void *data)
14135 {
14136         struct cmd_tx_loopback_result *res = parsed_result;
14137         int ret = -ENOTSUP;
14138
14139         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14140
14141         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14142                 return;
14143
14144 #ifdef RTE_NET_IXGBE
14145         if (ret == -ENOTSUP)
14146                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
14147 #endif
14148 #ifdef RTE_NET_I40E
14149         if (ret == -ENOTSUP)
14150                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
14151 #endif
14152 #ifdef RTE_NET_BNXT
14153         if (ret == -ENOTSUP)
14154                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
14155 #endif
14156 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
14157         if (ret == -ENOTSUP)
14158                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
14159 #endif
14160
14161         switch (ret) {
14162         case 0:
14163                 break;
14164         case -EINVAL:
14165                 printf("invalid is_on %d\n", is_on);
14166                 break;
14167         case -ENODEV:
14168                 printf("invalid port_id %d\n", res->port_id);
14169                 break;
14170         case -ENOTSUP:
14171                 printf("function not implemented\n");
14172                 break;
14173         default:
14174                 printf("programming error: (%s)\n", strerror(-ret));
14175         }
14176 }
14177
14178 cmdline_parse_inst_t cmd_set_tx_loopback = {
14179         .f = cmd_set_tx_loopback_parsed,
14180         .data = NULL,
14181         .help_str = "set tx loopback <port_id> on|off",
14182         .tokens = {
14183                 (void *)&cmd_tx_loopback_set,
14184                 (void *)&cmd_tx_loopback_tx,
14185                 (void *)&cmd_tx_loopback_loopback,
14186                 (void *)&cmd_tx_loopback_port_id,
14187                 (void *)&cmd_tx_loopback_on_off,
14188                 NULL,
14189         },
14190 };
14191
14192 /* all queues drop enable configuration */
14193
14194 /* Common result structure for all queues drop enable */
14195 struct cmd_all_queues_drop_en_result {
14196         cmdline_fixed_string_t set;
14197         cmdline_fixed_string_t all;
14198         cmdline_fixed_string_t queues;
14199         cmdline_fixed_string_t drop;
14200         portid_t port_id;
14201         cmdline_fixed_string_t on_off;
14202 };
14203
14204 /* Common CLI fields for tx loopback enable disable */
14205 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
14206         TOKEN_STRING_INITIALIZER
14207                 (struct cmd_all_queues_drop_en_result,
14208                  set, "set");
14209 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
14210         TOKEN_STRING_INITIALIZER
14211                 (struct cmd_all_queues_drop_en_result,
14212                  all, "all");
14213 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
14214         TOKEN_STRING_INITIALIZER
14215                 (struct cmd_all_queues_drop_en_result,
14216                  queues, "queues");
14217 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
14218         TOKEN_STRING_INITIALIZER
14219                 (struct cmd_all_queues_drop_en_result,
14220                  drop, "drop");
14221 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
14222         TOKEN_NUM_INITIALIZER
14223                 (struct cmd_all_queues_drop_en_result,
14224                  port_id, UINT16);
14225 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
14226         TOKEN_STRING_INITIALIZER
14227                 (struct cmd_all_queues_drop_en_result,
14228                  on_off, "on#off");
14229
14230 static void
14231 cmd_set_all_queues_drop_en_parsed(
14232         void *parsed_result,
14233         __rte_unused struct cmdline *cl,
14234         __rte_unused void *data)
14235 {
14236         struct cmd_all_queues_drop_en_result *res = parsed_result;
14237         int ret = -ENOTSUP;
14238         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14239
14240         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14241                 return;
14242
14243 #ifdef RTE_NET_IXGBE
14244         if (ret == -ENOTSUP)
14245                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
14246 #endif
14247 #ifdef RTE_NET_BNXT
14248         if (ret == -ENOTSUP)
14249                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
14250 #endif
14251         switch (ret) {
14252         case 0:
14253                 break;
14254         case -EINVAL:
14255                 printf("invalid is_on %d\n", is_on);
14256                 break;
14257         case -ENODEV:
14258                 printf("invalid port_id %d\n", res->port_id);
14259                 break;
14260         case -ENOTSUP:
14261                 printf("function not implemented\n");
14262                 break;
14263         default:
14264                 printf("programming error: (%s)\n", strerror(-ret));
14265         }
14266 }
14267
14268 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14269         .f = cmd_set_all_queues_drop_en_parsed,
14270         .data = NULL,
14271         .help_str = "set all queues drop <port_id> on|off",
14272         .tokens = {
14273                 (void *)&cmd_all_queues_drop_en_set,
14274                 (void *)&cmd_all_queues_drop_en_all,
14275                 (void *)&cmd_all_queues_drop_en_queues,
14276                 (void *)&cmd_all_queues_drop_en_drop,
14277                 (void *)&cmd_all_queues_drop_en_port_id,
14278                 (void *)&cmd_all_queues_drop_en_on_off,
14279                 NULL,
14280         },
14281 };
14282
14283 /* vf split drop enable configuration */
14284
14285 /* Common result structure for vf split drop enable */
14286 struct cmd_vf_split_drop_en_result {
14287         cmdline_fixed_string_t set;
14288         cmdline_fixed_string_t vf;
14289         cmdline_fixed_string_t split;
14290         cmdline_fixed_string_t drop;
14291         portid_t port_id;
14292         uint16_t vf_id;
14293         cmdline_fixed_string_t on_off;
14294 };
14295
14296 /* Common CLI fields for vf split drop enable disable */
14297 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14298         TOKEN_STRING_INITIALIZER
14299                 (struct cmd_vf_split_drop_en_result,
14300                  set, "set");
14301 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14302         TOKEN_STRING_INITIALIZER
14303                 (struct cmd_vf_split_drop_en_result,
14304                  vf, "vf");
14305 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14306         TOKEN_STRING_INITIALIZER
14307                 (struct cmd_vf_split_drop_en_result,
14308                  split, "split");
14309 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14310         TOKEN_STRING_INITIALIZER
14311                 (struct cmd_vf_split_drop_en_result,
14312                  drop, "drop");
14313 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14314         TOKEN_NUM_INITIALIZER
14315                 (struct cmd_vf_split_drop_en_result,
14316                  port_id, UINT16);
14317 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14318         TOKEN_NUM_INITIALIZER
14319                 (struct cmd_vf_split_drop_en_result,
14320                  vf_id, UINT16);
14321 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14322         TOKEN_STRING_INITIALIZER
14323                 (struct cmd_vf_split_drop_en_result,
14324                  on_off, "on#off");
14325
14326 static void
14327 cmd_set_vf_split_drop_en_parsed(
14328         void *parsed_result,
14329         __rte_unused struct cmdline *cl,
14330         __rte_unused void *data)
14331 {
14332         struct cmd_vf_split_drop_en_result *res = parsed_result;
14333         int ret = -ENOTSUP;
14334         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14335
14336         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14337                 return;
14338
14339 #ifdef RTE_NET_IXGBE
14340         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14341                         is_on);
14342 #endif
14343         switch (ret) {
14344         case 0:
14345                 break;
14346         case -EINVAL:
14347                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14348                 break;
14349         case -ENODEV:
14350                 printf("invalid port_id %d\n", res->port_id);
14351                 break;
14352         case -ENOTSUP:
14353                 printf("not supported on port %d\n", res->port_id);
14354                 break;
14355         default:
14356                 printf("programming error: (%s)\n", strerror(-ret));
14357         }
14358 }
14359
14360 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14361         .f = cmd_set_vf_split_drop_en_parsed,
14362         .data = NULL,
14363         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14364         .tokens = {
14365                 (void *)&cmd_vf_split_drop_en_set,
14366                 (void *)&cmd_vf_split_drop_en_vf,
14367                 (void *)&cmd_vf_split_drop_en_split,
14368                 (void *)&cmd_vf_split_drop_en_drop,
14369                 (void *)&cmd_vf_split_drop_en_port_id,
14370                 (void *)&cmd_vf_split_drop_en_vf_id,
14371                 (void *)&cmd_vf_split_drop_en_on_off,
14372                 NULL,
14373         },
14374 };
14375
14376 /* vf mac address configuration */
14377
14378 /* Common result structure for vf mac address */
14379 struct cmd_set_vf_mac_addr_result {
14380         cmdline_fixed_string_t set;
14381         cmdline_fixed_string_t vf;
14382         cmdline_fixed_string_t mac;
14383         cmdline_fixed_string_t addr;
14384         portid_t port_id;
14385         uint16_t vf_id;
14386         struct rte_ether_addr mac_addr;
14387
14388 };
14389
14390 /* Common CLI fields for vf split drop enable disable */
14391 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14392         TOKEN_STRING_INITIALIZER
14393                 (struct cmd_set_vf_mac_addr_result,
14394                  set, "set");
14395 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14396         TOKEN_STRING_INITIALIZER
14397                 (struct cmd_set_vf_mac_addr_result,
14398                  vf, "vf");
14399 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14400         TOKEN_STRING_INITIALIZER
14401                 (struct cmd_set_vf_mac_addr_result,
14402                  mac, "mac");
14403 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14404         TOKEN_STRING_INITIALIZER
14405                 (struct cmd_set_vf_mac_addr_result,
14406                  addr, "addr");
14407 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14408         TOKEN_NUM_INITIALIZER
14409                 (struct cmd_set_vf_mac_addr_result,
14410                  port_id, UINT16);
14411 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14412         TOKEN_NUM_INITIALIZER
14413                 (struct cmd_set_vf_mac_addr_result,
14414                  vf_id, UINT16);
14415 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14416         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14417                  mac_addr);
14418
14419 static void
14420 cmd_set_vf_mac_addr_parsed(
14421         void *parsed_result,
14422         __rte_unused struct cmdline *cl,
14423         __rte_unused void *data)
14424 {
14425         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14426         int ret = -ENOTSUP;
14427
14428         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14429                 return;
14430
14431 #ifdef RTE_NET_IXGBE
14432         if (ret == -ENOTSUP)
14433                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14434                                 &res->mac_addr);
14435 #endif
14436 #ifdef RTE_NET_I40E
14437         if (ret == -ENOTSUP)
14438                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14439                                 &res->mac_addr);
14440 #endif
14441 #ifdef RTE_NET_BNXT
14442         if (ret == -ENOTSUP)
14443                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14444                                 &res->mac_addr);
14445 #endif
14446
14447         switch (ret) {
14448         case 0:
14449                 break;
14450         case -EINVAL:
14451                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14452                 break;
14453         case -ENODEV:
14454                 printf("invalid port_id %d\n", res->port_id);
14455                 break;
14456         case -ENOTSUP:
14457                 printf("function not implemented\n");
14458                 break;
14459         default:
14460                 printf("programming error: (%s)\n", strerror(-ret));
14461         }
14462 }
14463
14464 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14465         .f = cmd_set_vf_mac_addr_parsed,
14466         .data = NULL,
14467         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14468         .tokens = {
14469                 (void *)&cmd_set_vf_mac_addr_set,
14470                 (void *)&cmd_set_vf_mac_addr_vf,
14471                 (void *)&cmd_set_vf_mac_addr_mac,
14472                 (void *)&cmd_set_vf_mac_addr_addr,
14473                 (void *)&cmd_set_vf_mac_addr_port_id,
14474                 (void *)&cmd_set_vf_mac_addr_vf_id,
14475                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14476                 NULL,
14477         },
14478 };
14479
14480 /* MACsec configuration */
14481
14482 /* Common result structure for MACsec offload enable */
14483 struct cmd_macsec_offload_on_result {
14484         cmdline_fixed_string_t set;
14485         cmdline_fixed_string_t macsec;
14486         cmdline_fixed_string_t offload;
14487         portid_t port_id;
14488         cmdline_fixed_string_t on;
14489         cmdline_fixed_string_t encrypt;
14490         cmdline_fixed_string_t en_on_off;
14491         cmdline_fixed_string_t replay_protect;
14492         cmdline_fixed_string_t rp_on_off;
14493 };
14494
14495 /* Common CLI fields for MACsec offload disable */
14496 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14497         TOKEN_STRING_INITIALIZER
14498                 (struct cmd_macsec_offload_on_result,
14499                  set, "set");
14500 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14501         TOKEN_STRING_INITIALIZER
14502                 (struct cmd_macsec_offload_on_result,
14503                  macsec, "macsec");
14504 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14505         TOKEN_STRING_INITIALIZER
14506                 (struct cmd_macsec_offload_on_result,
14507                  offload, "offload");
14508 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14509         TOKEN_NUM_INITIALIZER
14510                 (struct cmd_macsec_offload_on_result,
14511                  port_id, UINT16);
14512 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14513         TOKEN_STRING_INITIALIZER
14514                 (struct cmd_macsec_offload_on_result,
14515                  on, "on");
14516 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14517         TOKEN_STRING_INITIALIZER
14518                 (struct cmd_macsec_offload_on_result,
14519                  encrypt, "encrypt");
14520 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14521         TOKEN_STRING_INITIALIZER
14522                 (struct cmd_macsec_offload_on_result,
14523                  en_on_off, "on#off");
14524 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14525         TOKEN_STRING_INITIALIZER
14526                 (struct cmd_macsec_offload_on_result,
14527                  replay_protect, "replay-protect");
14528 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14529         TOKEN_STRING_INITIALIZER
14530                 (struct cmd_macsec_offload_on_result,
14531                  rp_on_off, "on#off");
14532
14533 static void
14534 cmd_set_macsec_offload_on_parsed(
14535         void *parsed_result,
14536         __rte_unused struct cmdline *cl,
14537         __rte_unused void *data)
14538 {
14539         struct cmd_macsec_offload_on_result *res = parsed_result;
14540         int ret = -ENOTSUP;
14541         portid_t port_id = res->port_id;
14542         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14543         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14544         struct rte_eth_dev_info dev_info;
14545
14546         if (port_id_is_invalid(port_id, ENABLED_WARN))
14547                 return;
14548         if (!port_is_stopped(port_id)) {
14549                 printf("Please stop port %d first\n", port_id);
14550                 return;
14551         }
14552
14553         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14554         if (ret != 0)
14555                 return;
14556
14557         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14558 #ifdef RTE_NET_IXGBE
14559                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14560 #endif
14561         }
14562         RTE_SET_USED(en);
14563         RTE_SET_USED(rp);
14564
14565         switch (ret) {
14566         case 0:
14567                 ports[port_id].dev_conf.txmode.offloads |=
14568                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14569                 cmd_reconfig_device_queue(port_id, 1, 1);
14570                 break;
14571         case -ENODEV:
14572                 printf("invalid port_id %d\n", port_id);
14573                 break;
14574         case -ENOTSUP:
14575                 printf("not supported on port %d\n", port_id);
14576                 break;
14577         default:
14578                 printf("programming error: (%s)\n", strerror(-ret));
14579         }
14580 }
14581
14582 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14583         .f = cmd_set_macsec_offload_on_parsed,
14584         .data = NULL,
14585         .help_str = "set macsec offload <port_id> on "
14586                 "encrypt on|off replay-protect on|off",
14587         .tokens = {
14588                 (void *)&cmd_macsec_offload_on_set,
14589                 (void *)&cmd_macsec_offload_on_macsec,
14590                 (void *)&cmd_macsec_offload_on_offload,
14591                 (void *)&cmd_macsec_offload_on_port_id,
14592                 (void *)&cmd_macsec_offload_on_on,
14593                 (void *)&cmd_macsec_offload_on_encrypt,
14594                 (void *)&cmd_macsec_offload_on_en_on_off,
14595                 (void *)&cmd_macsec_offload_on_replay_protect,
14596                 (void *)&cmd_macsec_offload_on_rp_on_off,
14597                 NULL,
14598         },
14599 };
14600
14601 /* Common result structure for MACsec offload disable */
14602 struct cmd_macsec_offload_off_result {
14603         cmdline_fixed_string_t set;
14604         cmdline_fixed_string_t macsec;
14605         cmdline_fixed_string_t offload;
14606         portid_t port_id;
14607         cmdline_fixed_string_t off;
14608 };
14609
14610 /* Common CLI fields for MACsec offload disable */
14611 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14612         TOKEN_STRING_INITIALIZER
14613                 (struct cmd_macsec_offload_off_result,
14614                  set, "set");
14615 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14616         TOKEN_STRING_INITIALIZER
14617                 (struct cmd_macsec_offload_off_result,
14618                  macsec, "macsec");
14619 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14620         TOKEN_STRING_INITIALIZER
14621                 (struct cmd_macsec_offload_off_result,
14622                  offload, "offload");
14623 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14624         TOKEN_NUM_INITIALIZER
14625                 (struct cmd_macsec_offload_off_result,
14626                  port_id, UINT16);
14627 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14628         TOKEN_STRING_INITIALIZER
14629                 (struct cmd_macsec_offload_off_result,
14630                  off, "off");
14631
14632 static void
14633 cmd_set_macsec_offload_off_parsed(
14634         void *parsed_result,
14635         __rte_unused struct cmdline *cl,
14636         __rte_unused void *data)
14637 {
14638         struct cmd_macsec_offload_off_result *res = parsed_result;
14639         int ret = -ENOTSUP;
14640         struct rte_eth_dev_info dev_info;
14641         portid_t port_id = res->port_id;
14642
14643         if (port_id_is_invalid(port_id, ENABLED_WARN))
14644                 return;
14645         if (!port_is_stopped(port_id)) {
14646                 printf("Please stop port %d first\n", port_id);
14647                 return;
14648         }
14649
14650         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14651         if (ret != 0)
14652                 return;
14653
14654         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14655 #ifdef RTE_NET_IXGBE
14656                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14657 #endif
14658         }
14659         switch (ret) {
14660         case 0:
14661                 ports[port_id].dev_conf.txmode.offloads &=
14662                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14663                 cmd_reconfig_device_queue(port_id, 1, 1);
14664                 break;
14665         case -ENODEV:
14666                 printf("invalid port_id %d\n", port_id);
14667                 break;
14668         case -ENOTSUP:
14669                 printf("not supported on port %d\n", port_id);
14670                 break;
14671         default:
14672                 printf("programming error: (%s)\n", strerror(-ret));
14673         }
14674 }
14675
14676 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14677         .f = cmd_set_macsec_offload_off_parsed,
14678         .data = NULL,
14679         .help_str = "set macsec offload <port_id> off",
14680         .tokens = {
14681                 (void *)&cmd_macsec_offload_off_set,
14682                 (void *)&cmd_macsec_offload_off_macsec,
14683                 (void *)&cmd_macsec_offload_off_offload,
14684                 (void *)&cmd_macsec_offload_off_port_id,
14685                 (void *)&cmd_macsec_offload_off_off,
14686                 NULL,
14687         },
14688 };
14689
14690 /* Common result structure for MACsec secure connection configure */
14691 struct cmd_macsec_sc_result {
14692         cmdline_fixed_string_t set;
14693         cmdline_fixed_string_t macsec;
14694         cmdline_fixed_string_t sc;
14695         cmdline_fixed_string_t tx_rx;
14696         portid_t port_id;
14697         struct rte_ether_addr mac;
14698         uint16_t pi;
14699 };
14700
14701 /* Common CLI fields for MACsec secure connection configure */
14702 cmdline_parse_token_string_t cmd_macsec_sc_set =
14703         TOKEN_STRING_INITIALIZER
14704                 (struct cmd_macsec_sc_result,
14705                  set, "set");
14706 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14707         TOKEN_STRING_INITIALIZER
14708                 (struct cmd_macsec_sc_result,
14709                  macsec, "macsec");
14710 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14711         TOKEN_STRING_INITIALIZER
14712                 (struct cmd_macsec_sc_result,
14713                  sc, "sc");
14714 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14715         TOKEN_STRING_INITIALIZER
14716                 (struct cmd_macsec_sc_result,
14717                  tx_rx, "tx#rx");
14718 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14719         TOKEN_NUM_INITIALIZER
14720                 (struct cmd_macsec_sc_result,
14721                  port_id, UINT16);
14722 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14723         TOKEN_ETHERADDR_INITIALIZER
14724                 (struct cmd_macsec_sc_result,
14725                  mac);
14726 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14727         TOKEN_NUM_INITIALIZER
14728                 (struct cmd_macsec_sc_result,
14729                  pi, UINT16);
14730
14731 static void
14732 cmd_set_macsec_sc_parsed(
14733         void *parsed_result,
14734         __rte_unused struct cmdline *cl,
14735         __rte_unused void *data)
14736 {
14737         struct cmd_macsec_sc_result *res = parsed_result;
14738         int ret = -ENOTSUP;
14739         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14740
14741 #ifdef RTE_NET_IXGBE
14742         ret = is_tx ?
14743                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14744                                 res->mac.addr_bytes) :
14745                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14746                                 res->mac.addr_bytes, res->pi);
14747 #endif
14748         RTE_SET_USED(is_tx);
14749
14750         switch (ret) {
14751         case 0:
14752                 break;
14753         case -ENODEV:
14754                 printf("invalid port_id %d\n", res->port_id);
14755                 break;
14756         case -ENOTSUP:
14757                 printf("not supported on port %d\n", res->port_id);
14758                 break;
14759         default:
14760                 printf("programming error: (%s)\n", strerror(-ret));
14761         }
14762 }
14763
14764 cmdline_parse_inst_t cmd_set_macsec_sc = {
14765         .f = cmd_set_macsec_sc_parsed,
14766         .data = NULL,
14767         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14768         .tokens = {
14769                 (void *)&cmd_macsec_sc_set,
14770                 (void *)&cmd_macsec_sc_macsec,
14771                 (void *)&cmd_macsec_sc_sc,
14772                 (void *)&cmd_macsec_sc_tx_rx,
14773                 (void *)&cmd_macsec_sc_port_id,
14774                 (void *)&cmd_macsec_sc_mac,
14775                 (void *)&cmd_macsec_sc_pi,
14776                 NULL,
14777         },
14778 };
14779
14780 /* Common result structure for MACsec secure connection configure */
14781 struct cmd_macsec_sa_result {
14782         cmdline_fixed_string_t set;
14783         cmdline_fixed_string_t macsec;
14784         cmdline_fixed_string_t sa;
14785         cmdline_fixed_string_t tx_rx;
14786         portid_t port_id;
14787         uint8_t idx;
14788         uint8_t an;
14789         uint32_t pn;
14790         cmdline_fixed_string_t key;
14791 };
14792
14793 /* Common CLI fields for MACsec secure connection configure */
14794 cmdline_parse_token_string_t cmd_macsec_sa_set =
14795         TOKEN_STRING_INITIALIZER
14796                 (struct cmd_macsec_sa_result,
14797                  set, "set");
14798 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14799         TOKEN_STRING_INITIALIZER
14800                 (struct cmd_macsec_sa_result,
14801                  macsec, "macsec");
14802 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14803         TOKEN_STRING_INITIALIZER
14804                 (struct cmd_macsec_sa_result,
14805                  sa, "sa");
14806 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14807         TOKEN_STRING_INITIALIZER
14808                 (struct cmd_macsec_sa_result,
14809                  tx_rx, "tx#rx");
14810 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14811         TOKEN_NUM_INITIALIZER
14812                 (struct cmd_macsec_sa_result,
14813                  port_id, UINT16);
14814 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14815         TOKEN_NUM_INITIALIZER
14816                 (struct cmd_macsec_sa_result,
14817                  idx, UINT8);
14818 cmdline_parse_token_num_t cmd_macsec_sa_an =
14819         TOKEN_NUM_INITIALIZER
14820                 (struct cmd_macsec_sa_result,
14821                  an, UINT8);
14822 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14823         TOKEN_NUM_INITIALIZER
14824                 (struct cmd_macsec_sa_result,
14825                  pn, UINT32);
14826 cmdline_parse_token_string_t cmd_macsec_sa_key =
14827         TOKEN_STRING_INITIALIZER
14828                 (struct cmd_macsec_sa_result,
14829                  key, NULL);
14830
14831 static void
14832 cmd_set_macsec_sa_parsed(
14833         void *parsed_result,
14834         __rte_unused struct cmdline *cl,
14835         __rte_unused void *data)
14836 {
14837         struct cmd_macsec_sa_result *res = parsed_result;
14838         int ret = -ENOTSUP;
14839         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14840         uint8_t key[16] = { 0 };
14841         uint8_t xdgt0;
14842         uint8_t xdgt1;
14843         int key_len;
14844         int i;
14845
14846         key_len = strlen(res->key) / 2;
14847         if (key_len > 16)
14848                 key_len = 16;
14849
14850         for (i = 0; i < key_len; i++) {
14851                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14852                 if (xdgt0 == 0xFF)
14853                         return;
14854                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14855                 if (xdgt1 == 0xFF)
14856                         return;
14857                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14858         }
14859
14860 #ifdef RTE_NET_IXGBE
14861         ret = is_tx ?
14862                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14863                         res->idx, res->an, res->pn, key) :
14864                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14865                         res->idx, res->an, res->pn, key);
14866 #endif
14867         RTE_SET_USED(is_tx);
14868         RTE_SET_USED(key);
14869
14870         switch (ret) {
14871         case 0:
14872                 break;
14873         case -EINVAL:
14874                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14875                 break;
14876         case -ENODEV:
14877                 printf("invalid port_id %d\n", res->port_id);
14878                 break;
14879         case -ENOTSUP:
14880                 printf("not supported on port %d\n", res->port_id);
14881                 break;
14882         default:
14883                 printf("programming error: (%s)\n", strerror(-ret));
14884         }
14885 }
14886
14887 cmdline_parse_inst_t cmd_set_macsec_sa = {
14888         .f = cmd_set_macsec_sa_parsed,
14889         .data = NULL,
14890         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14891         .tokens = {
14892                 (void *)&cmd_macsec_sa_set,
14893                 (void *)&cmd_macsec_sa_macsec,
14894                 (void *)&cmd_macsec_sa_sa,
14895                 (void *)&cmd_macsec_sa_tx_rx,
14896                 (void *)&cmd_macsec_sa_port_id,
14897                 (void *)&cmd_macsec_sa_idx,
14898                 (void *)&cmd_macsec_sa_an,
14899                 (void *)&cmd_macsec_sa_pn,
14900                 (void *)&cmd_macsec_sa_key,
14901                 NULL,
14902         },
14903 };
14904
14905 /* VF unicast promiscuous mode configuration */
14906
14907 /* Common result structure for VF unicast promiscuous mode */
14908 struct cmd_vf_promisc_result {
14909         cmdline_fixed_string_t set;
14910         cmdline_fixed_string_t vf;
14911         cmdline_fixed_string_t promisc;
14912         portid_t port_id;
14913         uint32_t vf_id;
14914         cmdline_fixed_string_t on_off;
14915 };
14916
14917 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14918 cmdline_parse_token_string_t cmd_vf_promisc_set =
14919         TOKEN_STRING_INITIALIZER
14920                 (struct cmd_vf_promisc_result,
14921                  set, "set");
14922 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14923         TOKEN_STRING_INITIALIZER
14924                 (struct cmd_vf_promisc_result,
14925                  vf, "vf");
14926 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14927         TOKEN_STRING_INITIALIZER
14928                 (struct cmd_vf_promisc_result,
14929                  promisc, "promisc");
14930 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14931         TOKEN_NUM_INITIALIZER
14932                 (struct cmd_vf_promisc_result,
14933                  port_id, UINT16);
14934 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14935         TOKEN_NUM_INITIALIZER
14936                 (struct cmd_vf_promisc_result,
14937                  vf_id, UINT32);
14938 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14939         TOKEN_STRING_INITIALIZER
14940                 (struct cmd_vf_promisc_result,
14941                  on_off, "on#off");
14942
14943 static void
14944 cmd_set_vf_promisc_parsed(
14945         void *parsed_result,
14946         __rte_unused struct cmdline *cl,
14947         __rte_unused void *data)
14948 {
14949         struct cmd_vf_promisc_result *res = parsed_result;
14950         int ret = -ENOTSUP;
14951
14952         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14953
14954         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14955                 return;
14956
14957 #ifdef RTE_NET_I40E
14958         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14959                                                   res->vf_id, is_on);
14960 #endif
14961
14962         switch (ret) {
14963         case 0:
14964                 break;
14965         case -EINVAL:
14966                 printf("invalid vf_id %d\n", res->vf_id);
14967                 break;
14968         case -ENODEV:
14969                 printf("invalid port_id %d\n", res->port_id);
14970                 break;
14971         case -ENOTSUP:
14972                 printf("function not implemented\n");
14973                 break;
14974         default:
14975                 printf("programming error: (%s)\n", strerror(-ret));
14976         }
14977 }
14978
14979 cmdline_parse_inst_t cmd_set_vf_promisc = {
14980         .f = cmd_set_vf_promisc_parsed,
14981         .data = NULL,
14982         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14983                 "Set unicast promiscuous mode for a VF from the PF",
14984         .tokens = {
14985                 (void *)&cmd_vf_promisc_set,
14986                 (void *)&cmd_vf_promisc_vf,
14987                 (void *)&cmd_vf_promisc_promisc,
14988                 (void *)&cmd_vf_promisc_port_id,
14989                 (void *)&cmd_vf_promisc_vf_id,
14990                 (void *)&cmd_vf_promisc_on_off,
14991                 NULL,
14992         },
14993 };
14994
14995 /* VF multicast promiscuous mode configuration */
14996
14997 /* Common result structure for VF multicast promiscuous mode */
14998 struct cmd_vf_allmulti_result {
14999         cmdline_fixed_string_t set;
15000         cmdline_fixed_string_t vf;
15001         cmdline_fixed_string_t allmulti;
15002         portid_t port_id;
15003         uint32_t vf_id;
15004         cmdline_fixed_string_t on_off;
15005 };
15006
15007 /* Common CLI fields for VF multicast promiscuous mode enable disable */
15008 cmdline_parse_token_string_t cmd_vf_allmulti_set =
15009         TOKEN_STRING_INITIALIZER
15010                 (struct cmd_vf_allmulti_result,
15011                  set, "set");
15012 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
15013         TOKEN_STRING_INITIALIZER
15014                 (struct cmd_vf_allmulti_result,
15015                  vf, "vf");
15016 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
15017         TOKEN_STRING_INITIALIZER
15018                 (struct cmd_vf_allmulti_result,
15019                  allmulti, "allmulti");
15020 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
15021         TOKEN_NUM_INITIALIZER
15022                 (struct cmd_vf_allmulti_result,
15023                  port_id, UINT16);
15024 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
15025         TOKEN_NUM_INITIALIZER
15026                 (struct cmd_vf_allmulti_result,
15027                  vf_id, UINT32);
15028 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
15029         TOKEN_STRING_INITIALIZER
15030                 (struct cmd_vf_allmulti_result,
15031                  on_off, "on#off");
15032
15033 static void
15034 cmd_set_vf_allmulti_parsed(
15035         void *parsed_result,
15036         __rte_unused struct cmdline *cl,
15037         __rte_unused void *data)
15038 {
15039         struct cmd_vf_allmulti_result *res = parsed_result;
15040         int ret = -ENOTSUP;
15041
15042         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15043
15044         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15045                 return;
15046
15047 #ifdef RTE_NET_I40E
15048         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
15049                                                     res->vf_id, is_on);
15050 #endif
15051
15052         switch (ret) {
15053         case 0:
15054                 break;
15055         case -EINVAL:
15056                 printf("invalid vf_id %d\n", res->vf_id);
15057                 break;
15058         case -ENODEV:
15059                 printf("invalid port_id %d\n", res->port_id);
15060                 break;
15061         case -ENOTSUP:
15062                 printf("function not implemented\n");
15063                 break;
15064         default:
15065                 printf("programming error: (%s)\n", strerror(-ret));
15066         }
15067 }
15068
15069 cmdline_parse_inst_t cmd_set_vf_allmulti = {
15070         .f = cmd_set_vf_allmulti_parsed,
15071         .data = NULL,
15072         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
15073                 "Set multicast promiscuous mode for a VF from the PF",
15074         .tokens = {
15075                 (void *)&cmd_vf_allmulti_set,
15076                 (void *)&cmd_vf_allmulti_vf,
15077                 (void *)&cmd_vf_allmulti_allmulti,
15078                 (void *)&cmd_vf_allmulti_port_id,
15079                 (void *)&cmd_vf_allmulti_vf_id,
15080                 (void *)&cmd_vf_allmulti_on_off,
15081                 NULL,
15082         },
15083 };
15084
15085 /* vf broadcast mode configuration */
15086
15087 /* Common result structure for vf broadcast */
15088 struct cmd_set_vf_broadcast_result {
15089         cmdline_fixed_string_t set;
15090         cmdline_fixed_string_t vf;
15091         cmdline_fixed_string_t broadcast;
15092         portid_t port_id;
15093         uint16_t vf_id;
15094         cmdline_fixed_string_t on_off;
15095 };
15096
15097 /* Common CLI fields for vf broadcast enable disable */
15098 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
15099         TOKEN_STRING_INITIALIZER
15100                 (struct cmd_set_vf_broadcast_result,
15101                  set, "set");
15102 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
15103         TOKEN_STRING_INITIALIZER
15104                 (struct cmd_set_vf_broadcast_result,
15105                  vf, "vf");
15106 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
15107         TOKEN_STRING_INITIALIZER
15108                 (struct cmd_set_vf_broadcast_result,
15109                  broadcast, "broadcast");
15110 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
15111         TOKEN_NUM_INITIALIZER
15112                 (struct cmd_set_vf_broadcast_result,
15113                  port_id, UINT16);
15114 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
15115         TOKEN_NUM_INITIALIZER
15116                 (struct cmd_set_vf_broadcast_result,
15117                  vf_id, UINT16);
15118 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
15119         TOKEN_STRING_INITIALIZER
15120                 (struct cmd_set_vf_broadcast_result,
15121                  on_off, "on#off");
15122
15123 static void
15124 cmd_set_vf_broadcast_parsed(
15125         void *parsed_result,
15126         __rte_unused struct cmdline *cl,
15127         __rte_unused void *data)
15128 {
15129         struct cmd_set_vf_broadcast_result *res = parsed_result;
15130         int ret = -ENOTSUP;
15131
15132         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15133
15134         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15135                 return;
15136
15137 #ifdef RTE_NET_I40E
15138         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
15139                                             res->vf_id, is_on);
15140 #endif
15141
15142         switch (ret) {
15143         case 0:
15144                 break;
15145         case -EINVAL:
15146                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15147                 break;
15148         case -ENODEV:
15149                 printf("invalid port_id %d\n", res->port_id);
15150                 break;
15151         case -ENOTSUP:
15152                 printf("function not implemented\n");
15153                 break;
15154         default:
15155                 printf("programming error: (%s)\n", strerror(-ret));
15156         }
15157 }
15158
15159 cmdline_parse_inst_t cmd_set_vf_broadcast = {
15160         .f = cmd_set_vf_broadcast_parsed,
15161         .data = NULL,
15162         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
15163         .tokens = {
15164                 (void *)&cmd_set_vf_broadcast_set,
15165                 (void *)&cmd_set_vf_broadcast_vf,
15166                 (void *)&cmd_set_vf_broadcast_broadcast,
15167                 (void *)&cmd_set_vf_broadcast_port_id,
15168                 (void *)&cmd_set_vf_broadcast_vf_id,
15169                 (void *)&cmd_set_vf_broadcast_on_off,
15170                 NULL,
15171         },
15172 };
15173
15174 /* vf vlan tag configuration */
15175
15176 /* Common result structure for vf vlan tag */
15177 struct cmd_set_vf_vlan_tag_result {
15178         cmdline_fixed_string_t set;
15179         cmdline_fixed_string_t vf;
15180         cmdline_fixed_string_t vlan;
15181         cmdline_fixed_string_t tag;
15182         portid_t port_id;
15183         uint16_t vf_id;
15184         cmdline_fixed_string_t on_off;
15185 };
15186
15187 /* Common CLI fields for vf vlan tag enable disable */
15188 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
15189         TOKEN_STRING_INITIALIZER
15190                 (struct cmd_set_vf_vlan_tag_result,
15191                  set, "set");
15192 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
15193         TOKEN_STRING_INITIALIZER
15194                 (struct cmd_set_vf_vlan_tag_result,
15195                  vf, "vf");
15196 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
15197         TOKEN_STRING_INITIALIZER
15198                 (struct cmd_set_vf_vlan_tag_result,
15199                  vlan, "vlan");
15200 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
15201         TOKEN_STRING_INITIALIZER
15202                 (struct cmd_set_vf_vlan_tag_result,
15203                  tag, "tag");
15204 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
15205         TOKEN_NUM_INITIALIZER
15206                 (struct cmd_set_vf_vlan_tag_result,
15207                  port_id, UINT16);
15208 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
15209         TOKEN_NUM_INITIALIZER
15210                 (struct cmd_set_vf_vlan_tag_result,
15211                  vf_id, UINT16);
15212 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
15213         TOKEN_STRING_INITIALIZER
15214                 (struct cmd_set_vf_vlan_tag_result,
15215                  on_off, "on#off");
15216
15217 static void
15218 cmd_set_vf_vlan_tag_parsed(
15219         void *parsed_result,
15220         __rte_unused struct cmdline *cl,
15221         __rte_unused void *data)
15222 {
15223         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
15224         int ret = -ENOTSUP;
15225
15226         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15227
15228         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15229                 return;
15230
15231 #ifdef RTE_NET_I40E
15232         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
15233                                            res->vf_id, is_on);
15234 #endif
15235
15236         switch (ret) {
15237         case 0:
15238                 break;
15239         case -EINVAL:
15240                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15241                 break;
15242         case -ENODEV:
15243                 printf("invalid port_id %d\n", res->port_id);
15244                 break;
15245         case -ENOTSUP:
15246                 printf("function not implemented\n");
15247                 break;
15248         default:
15249                 printf("programming error: (%s)\n", strerror(-ret));
15250         }
15251 }
15252
15253 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15254         .f = cmd_set_vf_vlan_tag_parsed,
15255         .data = NULL,
15256         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15257         .tokens = {
15258                 (void *)&cmd_set_vf_vlan_tag_set,
15259                 (void *)&cmd_set_vf_vlan_tag_vf,
15260                 (void *)&cmd_set_vf_vlan_tag_vlan,
15261                 (void *)&cmd_set_vf_vlan_tag_tag,
15262                 (void *)&cmd_set_vf_vlan_tag_port_id,
15263                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15264                 (void *)&cmd_set_vf_vlan_tag_on_off,
15265                 NULL,
15266         },
15267 };
15268
15269 /* Common definition of VF and TC TX bandwidth configuration */
15270 struct cmd_vf_tc_bw_result {
15271         cmdline_fixed_string_t set;
15272         cmdline_fixed_string_t vf;
15273         cmdline_fixed_string_t tc;
15274         cmdline_fixed_string_t tx;
15275         cmdline_fixed_string_t min_bw;
15276         cmdline_fixed_string_t max_bw;
15277         cmdline_fixed_string_t strict_link_prio;
15278         portid_t port_id;
15279         uint16_t vf_id;
15280         uint8_t tc_no;
15281         uint32_t bw;
15282         cmdline_fixed_string_t bw_list;
15283         uint8_t tc_map;
15284 };
15285
15286 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15287         TOKEN_STRING_INITIALIZER
15288                 (struct cmd_vf_tc_bw_result,
15289                  set, "set");
15290 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15291         TOKEN_STRING_INITIALIZER
15292                 (struct cmd_vf_tc_bw_result,
15293                  vf, "vf");
15294 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15295         TOKEN_STRING_INITIALIZER
15296                 (struct cmd_vf_tc_bw_result,
15297                  tc, "tc");
15298 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15299         TOKEN_STRING_INITIALIZER
15300                 (struct cmd_vf_tc_bw_result,
15301                  tx, "tx");
15302 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15303         TOKEN_STRING_INITIALIZER
15304                 (struct cmd_vf_tc_bw_result,
15305                  strict_link_prio, "strict-link-priority");
15306 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15307         TOKEN_STRING_INITIALIZER
15308                 (struct cmd_vf_tc_bw_result,
15309                  min_bw, "min-bandwidth");
15310 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15311         TOKEN_STRING_INITIALIZER
15312                 (struct cmd_vf_tc_bw_result,
15313                  max_bw, "max-bandwidth");
15314 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15315         TOKEN_NUM_INITIALIZER
15316                 (struct cmd_vf_tc_bw_result,
15317                  port_id, UINT16);
15318 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15319         TOKEN_NUM_INITIALIZER
15320                 (struct cmd_vf_tc_bw_result,
15321                  vf_id, UINT16);
15322 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15323         TOKEN_NUM_INITIALIZER
15324                 (struct cmd_vf_tc_bw_result,
15325                  tc_no, UINT8);
15326 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15327         TOKEN_NUM_INITIALIZER
15328                 (struct cmd_vf_tc_bw_result,
15329                  bw, UINT32);
15330 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15331         TOKEN_STRING_INITIALIZER
15332                 (struct cmd_vf_tc_bw_result,
15333                  bw_list, NULL);
15334 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15335         TOKEN_NUM_INITIALIZER
15336                 (struct cmd_vf_tc_bw_result,
15337                  tc_map, UINT8);
15338
15339 /* VF max bandwidth setting */
15340 static void
15341 cmd_vf_max_bw_parsed(
15342         void *parsed_result,
15343         __rte_unused struct cmdline *cl,
15344         __rte_unused void *data)
15345 {
15346         struct cmd_vf_tc_bw_result *res = parsed_result;
15347         int ret = -ENOTSUP;
15348
15349         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15350                 return;
15351
15352 #ifdef RTE_NET_I40E
15353         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15354                                          res->vf_id, res->bw);
15355 #endif
15356
15357         switch (ret) {
15358         case 0:
15359                 break;
15360         case -EINVAL:
15361                 printf("invalid vf_id %d or bandwidth %d\n",
15362                        res->vf_id, res->bw);
15363                 break;
15364         case -ENODEV:
15365                 printf("invalid port_id %d\n", res->port_id);
15366                 break;
15367         case -ENOTSUP:
15368                 printf("function not implemented\n");
15369                 break;
15370         default:
15371                 printf("programming error: (%s)\n", strerror(-ret));
15372         }
15373 }
15374
15375 cmdline_parse_inst_t cmd_vf_max_bw = {
15376         .f = cmd_vf_max_bw_parsed,
15377         .data = NULL,
15378         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15379         .tokens = {
15380                 (void *)&cmd_vf_tc_bw_set,
15381                 (void *)&cmd_vf_tc_bw_vf,
15382                 (void *)&cmd_vf_tc_bw_tx,
15383                 (void *)&cmd_vf_tc_bw_max_bw,
15384                 (void *)&cmd_vf_tc_bw_port_id,
15385                 (void *)&cmd_vf_tc_bw_vf_id,
15386                 (void *)&cmd_vf_tc_bw_bw,
15387                 NULL,
15388         },
15389 };
15390
15391 static int
15392 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15393                            uint8_t *tc_num,
15394                            char *str)
15395 {
15396         uint32_t size;
15397         const char *p, *p0 = str;
15398         char s[256];
15399         char *end;
15400         char *str_fld[16];
15401         uint16_t i;
15402         int ret;
15403
15404         p = strchr(p0, '(');
15405         if (p == NULL) {
15406                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15407                 return -1;
15408         }
15409         p++;
15410         p0 = strchr(p, ')');
15411         if (p0 == NULL) {
15412                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15413                 return -1;
15414         }
15415         size = p0 - p;
15416         if (size >= sizeof(s)) {
15417                 printf("The string size exceeds the internal buffer size\n");
15418                 return -1;
15419         }
15420         snprintf(s, sizeof(s), "%.*s", size, p);
15421         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15422         if (ret <= 0) {
15423                 printf("Failed to get the bandwidth list. ");
15424                 return -1;
15425         }
15426         *tc_num = ret;
15427         for (i = 0; i < ret; i++)
15428                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15429
15430         return 0;
15431 }
15432
15433 /* TC min bandwidth setting */
15434 static void
15435 cmd_vf_tc_min_bw_parsed(
15436         void *parsed_result,
15437         __rte_unused struct cmdline *cl,
15438         __rte_unused void *data)
15439 {
15440         struct cmd_vf_tc_bw_result *res = parsed_result;
15441         uint8_t tc_num;
15442         uint8_t bw[16];
15443         int ret = -ENOTSUP;
15444
15445         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15446                 return;
15447
15448         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15449         if (ret)
15450                 return;
15451
15452 #ifdef RTE_NET_I40E
15453         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15454                                               tc_num, bw);
15455 #endif
15456
15457         switch (ret) {
15458         case 0:
15459                 break;
15460         case -EINVAL:
15461                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15462                 break;
15463         case -ENODEV:
15464                 printf("invalid port_id %d\n", res->port_id);
15465                 break;
15466         case -ENOTSUP:
15467                 printf("function not implemented\n");
15468                 break;
15469         default:
15470                 printf("programming error: (%s)\n", strerror(-ret));
15471         }
15472 }
15473
15474 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15475         .f = cmd_vf_tc_min_bw_parsed,
15476         .data = NULL,
15477         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15478                     " <bw1, bw2, ...>",
15479         .tokens = {
15480                 (void *)&cmd_vf_tc_bw_set,
15481                 (void *)&cmd_vf_tc_bw_vf,
15482                 (void *)&cmd_vf_tc_bw_tc,
15483                 (void *)&cmd_vf_tc_bw_tx,
15484                 (void *)&cmd_vf_tc_bw_min_bw,
15485                 (void *)&cmd_vf_tc_bw_port_id,
15486                 (void *)&cmd_vf_tc_bw_vf_id,
15487                 (void *)&cmd_vf_tc_bw_bw_list,
15488                 NULL,
15489         },
15490 };
15491
15492 static void
15493 cmd_tc_min_bw_parsed(
15494         void *parsed_result,
15495         __rte_unused struct cmdline *cl,
15496         __rte_unused void *data)
15497 {
15498         struct cmd_vf_tc_bw_result *res = parsed_result;
15499         struct rte_port *port;
15500         uint8_t tc_num;
15501         uint8_t bw[16];
15502         int ret = -ENOTSUP;
15503
15504         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15505                 return;
15506
15507         port = &ports[res->port_id];
15508         /** Check if the port is not started **/
15509         if (port->port_status != RTE_PORT_STOPPED) {
15510                 printf("Please stop port %d first\n", res->port_id);
15511                 return;
15512         }
15513
15514         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15515         if (ret)
15516                 return;
15517
15518 #ifdef RTE_NET_IXGBE
15519         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15520 #endif
15521
15522         switch (ret) {
15523         case 0:
15524                 break;
15525         case -EINVAL:
15526                 printf("invalid bandwidth\n");
15527                 break;
15528         case -ENODEV:
15529                 printf("invalid port_id %d\n", res->port_id);
15530                 break;
15531         case -ENOTSUP:
15532                 printf("function not implemented\n");
15533                 break;
15534         default:
15535                 printf("programming error: (%s)\n", strerror(-ret));
15536         }
15537 }
15538
15539 cmdline_parse_inst_t cmd_tc_min_bw = {
15540         .f = cmd_tc_min_bw_parsed,
15541         .data = NULL,
15542         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15543         .tokens = {
15544                 (void *)&cmd_vf_tc_bw_set,
15545                 (void *)&cmd_vf_tc_bw_tc,
15546                 (void *)&cmd_vf_tc_bw_tx,
15547                 (void *)&cmd_vf_tc_bw_min_bw,
15548                 (void *)&cmd_vf_tc_bw_port_id,
15549                 (void *)&cmd_vf_tc_bw_bw_list,
15550                 NULL,
15551         },
15552 };
15553
15554 /* TC max bandwidth setting */
15555 static void
15556 cmd_vf_tc_max_bw_parsed(
15557         void *parsed_result,
15558         __rte_unused struct cmdline *cl,
15559         __rte_unused void *data)
15560 {
15561         struct cmd_vf_tc_bw_result *res = parsed_result;
15562         int ret = -ENOTSUP;
15563
15564         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15565                 return;
15566
15567 #ifdef RTE_NET_I40E
15568         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15569                                             res->tc_no, res->bw);
15570 #endif
15571
15572         switch (ret) {
15573         case 0:
15574                 break;
15575         case -EINVAL:
15576                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15577                        res->vf_id, res->tc_no, res->bw);
15578                 break;
15579         case -ENODEV:
15580                 printf("invalid port_id %d\n", res->port_id);
15581                 break;
15582         case -ENOTSUP:
15583                 printf("function not implemented\n");
15584                 break;
15585         default:
15586                 printf("programming error: (%s)\n", strerror(-ret));
15587         }
15588 }
15589
15590 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15591         .f = cmd_vf_tc_max_bw_parsed,
15592         .data = NULL,
15593         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15594                     " <bandwidth>",
15595         .tokens = {
15596                 (void *)&cmd_vf_tc_bw_set,
15597                 (void *)&cmd_vf_tc_bw_vf,
15598                 (void *)&cmd_vf_tc_bw_tc,
15599                 (void *)&cmd_vf_tc_bw_tx,
15600                 (void *)&cmd_vf_tc_bw_max_bw,
15601                 (void *)&cmd_vf_tc_bw_port_id,
15602                 (void *)&cmd_vf_tc_bw_vf_id,
15603                 (void *)&cmd_vf_tc_bw_tc_no,
15604                 (void *)&cmd_vf_tc_bw_bw,
15605                 NULL,
15606         },
15607 };
15608
15609 /** Set VXLAN encapsulation details */
15610 struct cmd_set_vxlan_result {
15611         cmdline_fixed_string_t set;
15612         cmdline_fixed_string_t vxlan;
15613         cmdline_fixed_string_t pos_token;
15614         cmdline_fixed_string_t ip_version;
15615         uint32_t vlan_present:1;
15616         uint32_t vni;
15617         uint16_t udp_src;
15618         uint16_t udp_dst;
15619         cmdline_ipaddr_t ip_src;
15620         cmdline_ipaddr_t ip_dst;
15621         uint16_t tci;
15622         uint8_t tos;
15623         uint8_t ttl;
15624         struct rte_ether_addr eth_src;
15625         struct rte_ether_addr eth_dst;
15626 };
15627
15628 cmdline_parse_token_string_t cmd_set_vxlan_set =
15629         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15630 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15631         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15632 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15633         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15634                                  "vxlan-tos-ttl");
15635 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15636         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15637                                  "vxlan-with-vlan");
15638 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15639         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15640                                  "ip-version");
15641 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15642         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15643                                  "ipv4#ipv6");
15644 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15645         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15646                                  "vni");
15647 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15648         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15649 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15650         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15651                                  "udp-src");
15652 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15653         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15654 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15655         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15656                                  "udp-dst");
15657 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15658         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15659 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15660         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15661                                  "ip-tos");
15662 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15663         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15664 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15665         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15666                                  "ip-ttl");
15667 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15668         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15669 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15670         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15671                                  "ip-src");
15672 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15673         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15674 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15675         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15676                                  "ip-dst");
15677 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15678         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15679 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15680         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15681                                  "vlan-tci");
15682 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15683         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15684 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15685         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15686                                  "eth-src");
15687 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15688         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15689 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15690         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15691                                  "eth-dst");
15692 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15693         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15694
15695 static void cmd_set_vxlan_parsed(void *parsed_result,
15696         __rte_unused struct cmdline *cl,
15697         __rte_unused void *data)
15698 {
15699         struct cmd_set_vxlan_result *res = parsed_result;
15700         union {
15701                 uint32_t vxlan_id;
15702                 uint8_t vni[4];
15703         } id = {
15704                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15705         };
15706
15707         vxlan_encap_conf.select_tos_ttl = 0;
15708         if (strcmp(res->vxlan, "vxlan") == 0)
15709                 vxlan_encap_conf.select_vlan = 0;
15710         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15711                 vxlan_encap_conf.select_vlan = 1;
15712         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15713                 vxlan_encap_conf.select_vlan = 0;
15714                 vxlan_encap_conf.select_tos_ttl = 1;
15715         }
15716         if (strcmp(res->ip_version, "ipv4") == 0)
15717                 vxlan_encap_conf.select_ipv4 = 1;
15718         else if (strcmp(res->ip_version, "ipv6") == 0)
15719                 vxlan_encap_conf.select_ipv4 = 0;
15720         else
15721                 return;
15722         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15723         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15724         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15725         vxlan_encap_conf.ip_tos = res->tos;
15726         vxlan_encap_conf.ip_ttl = res->ttl;
15727         if (vxlan_encap_conf.select_ipv4) {
15728                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15729                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15730         } else {
15731                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15732                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15733         }
15734         if (vxlan_encap_conf.select_vlan)
15735                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15736         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15737                    RTE_ETHER_ADDR_LEN);
15738         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15739                    RTE_ETHER_ADDR_LEN);
15740 }
15741
15742 cmdline_parse_inst_t cmd_set_vxlan = {
15743         .f = cmd_set_vxlan_parsed,
15744         .data = NULL,
15745         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15746                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15747                 " eth-src <eth-src> eth-dst <eth-dst>",
15748         .tokens = {
15749                 (void *)&cmd_set_vxlan_set,
15750                 (void *)&cmd_set_vxlan_vxlan,
15751                 (void *)&cmd_set_vxlan_ip_version,
15752                 (void *)&cmd_set_vxlan_ip_version_value,
15753                 (void *)&cmd_set_vxlan_vni,
15754                 (void *)&cmd_set_vxlan_vni_value,
15755                 (void *)&cmd_set_vxlan_udp_src,
15756                 (void *)&cmd_set_vxlan_udp_src_value,
15757                 (void *)&cmd_set_vxlan_udp_dst,
15758                 (void *)&cmd_set_vxlan_udp_dst_value,
15759                 (void *)&cmd_set_vxlan_ip_src,
15760                 (void *)&cmd_set_vxlan_ip_src_value,
15761                 (void *)&cmd_set_vxlan_ip_dst,
15762                 (void *)&cmd_set_vxlan_ip_dst_value,
15763                 (void *)&cmd_set_vxlan_eth_src,
15764                 (void *)&cmd_set_vxlan_eth_src_value,
15765                 (void *)&cmd_set_vxlan_eth_dst,
15766                 (void *)&cmd_set_vxlan_eth_dst_value,
15767                 NULL,
15768         },
15769 };
15770
15771 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15772         .f = cmd_set_vxlan_parsed,
15773         .data = NULL,
15774         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15775                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15776                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15777                 " eth-dst <eth-dst>",
15778         .tokens = {
15779                 (void *)&cmd_set_vxlan_set,
15780                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15781                 (void *)&cmd_set_vxlan_ip_version,
15782                 (void *)&cmd_set_vxlan_ip_version_value,
15783                 (void *)&cmd_set_vxlan_vni,
15784                 (void *)&cmd_set_vxlan_vni_value,
15785                 (void *)&cmd_set_vxlan_udp_src,
15786                 (void *)&cmd_set_vxlan_udp_src_value,
15787                 (void *)&cmd_set_vxlan_udp_dst,
15788                 (void *)&cmd_set_vxlan_udp_dst_value,
15789                 (void *)&cmd_set_vxlan_ip_tos,
15790                 (void *)&cmd_set_vxlan_ip_tos_value,
15791                 (void *)&cmd_set_vxlan_ip_ttl,
15792                 (void *)&cmd_set_vxlan_ip_ttl_value,
15793                 (void *)&cmd_set_vxlan_ip_src,
15794                 (void *)&cmd_set_vxlan_ip_src_value,
15795                 (void *)&cmd_set_vxlan_ip_dst,
15796                 (void *)&cmd_set_vxlan_ip_dst_value,
15797                 (void *)&cmd_set_vxlan_eth_src,
15798                 (void *)&cmd_set_vxlan_eth_src_value,
15799                 (void *)&cmd_set_vxlan_eth_dst,
15800                 (void *)&cmd_set_vxlan_eth_dst_value,
15801                 NULL,
15802         },
15803 };
15804
15805 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15806         .f = cmd_set_vxlan_parsed,
15807         .data = NULL,
15808         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15809                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15810                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15811                 " <eth-dst>",
15812         .tokens = {
15813                 (void *)&cmd_set_vxlan_set,
15814                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15815                 (void *)&cmd_set_vxlan_ip_version,
15816                 (void *)&cmd_set_vxlan_ip_version_value,
15817                 (void *)&cmd_set_vxlan_vni,
15818                 (void *)&cmd_set_vxlan_vni_value,
15819                 (void *)&cmd_set_vxlan_udp_src,
15820                 (void *)&cmd_set_vxlan_udp_src_value,
15821                 (void *)&cmd_set_vxlan_udp_dst,
15822                 (void *)&cmd_set_vxlan_udp_dst_value,
15823                 (void *)&cmd_set_vxlan_ip_src,
15824                 (void *)&cmd_set_vxlan_ip_src_value,
15825                 (void *)&cmd_set_vxlan_ip_dst,
15826                 (void *)&cmd_set_vxlan_ip_dst_value,
15827                 (void *)&cmd_set_vxlan_vlan,
15828                 (void *)&cmd_set_vxlan_vlan_value,
15829                 (void *)&cmd_set_vxlan_eth_src,
15830                 (void *)&cmd_set_vxlan_eth_src_value,
15831                 (void *)&cmd_set_vxlan_eth_dst,
15832                 (void *)&cmd_set_vxlan_eth_dst_value,
15833                 NULL,
15834         },
15835 };
15836
15837 /** Set NVGRE encapsulation details */
15838 struct cmd_set_nvgre_result {
15839         cmdline_fixed_string_t set;
15840         cmdline_fixed_string_t nvgre;
15841         cmdline_fixed_string_t pos_token;
15842         cmdline_fixed_string_t ip_version;
15843         uint32_t tni;
15844         cmdline_ipaddr_t ip_src;
15845         cmdline_ipaddr_t ip_dst;
15846         uint16_t tci;
15847         struct rte_ether_addr eth_src;
15848         struct rte_ether_addr eth_dst;
15849 };
15850
15851 cmdline_parse_token_string_t cmd_set_nvgre_set =
15852         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15853 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15854         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15855 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15856         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15857                                  "nvgre-with-vlan");
15858 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15859         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15860                                  "ip-version");
15861 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15862         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15863                                  "ipv4#ipv6");
15864 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15865         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15866                                  "tni");
15867 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15868         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15869 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15870         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15871                                  "ip-src");
15872 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15873         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15874 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15875         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15876                                  "ip-dst");
15877 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15878         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15879 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15880         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15881                                  "vlan-tci");
15882 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15883         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15884 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15885         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15886                                  "eth-src");
15887 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15888         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15889 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15890         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15891                                  "eth-dst");
15892 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15893         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15894
15895 static void cmd_set_nvgre_parsed(void *parsed_result,
15896         __rte_unused struct cmdline *cl,
15897         __rte_unused void *data)
15898 {
15899         struct cmd_set_nvgre_result *res = parsed_result;
15900         union {
15901                 uint32_t nvgre_tni;
15902                 uint8_t tni[4];
15903         } id = {
15904                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15905         };
15906
15907         if (strcmp(res->nvgre, "nvgre") == 0)
15908                 nvgre_encap_conf.select_vlan = 0;
15909         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15910                 nvgre_encap_conf.select_vlan = 1;
15911         if (strcmp(res->ip_version, "ipv4") == 0)
15912                 nvgre_encap_conf.select_ipv4 = 1;
15913         else if (strcmp(res->ip_version, "ipv6") == 0)
15914                 nvgre_encap_conf.select_ipv4 = 0;
15915         else
15916                 return;
15917         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15918         if (nvgre_encap_conf.select_ipv4) {
15919                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15920                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15921         } else {
15922                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15923                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15924         }
15925         if (nvgre_encap_conf.select_vlan)
15926                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15927         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15928                    RTE_ETHER_ADDR_LEN);
15929         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15930                    RTE_ETHER_ADDR_LEN);
15931 }
15932
15933 cmdline_parse_inst_t cmd_set_nvgre = {
15934         .f = cmd_set_nvgre_parsed,
15935         .data = NULL,
15936         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15937                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15938                 " eth-dst <eth-dst>",
15939         .tokens = {
15940                 (void *)&cmd_set_nvgre_set,
15941                 (void *)&cmd_set_nvgre_nvgre,
15942                 (void *)&cmd_set_nvgre_ip_version,
15943                 (void *)&cmd_set_nvgre_ip_version_value,
15944                 (void *)&cmd_set_nvgre_tni,
15945                 (void *)&cmd_set_nvgre_tni_value,
15946                 (void *)&cmd_set_nvgre_ip_src,
15947                 (void *)&cmd_set_nvgre_ip_src_value,
15948                 (void *)&cmd_set_nvgre_ip_dst,
15949                 (void *)&cmd_set_nvgre_ip_dst_value,
15950                 (void *)&cmd_set_nvgre_eth_src,
15951                 (void *)&cmd_set_nvgre_eth_src_value,
15952                 (void *)&cmd_set_nvgre_eth_dst,
15953                 (void *)&cmd_set_nvgre_eth_dst_value,
15954                 NULL,
15955         },
15956 };
15957
15958 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15959         .f = cmd_set_nvgre_parsed,
15960         .data = NULL,
15961         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15962                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15963                 " eth-src <eth-src> eth-dst <eth-dst>",
15964         .tokens = {
15965                 (void *)&cmd_set_nvgre_set,
15966                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15967                 (void *)&cmd_set_nvgre_ip_version,
15968                 (void *)&cmd_set_nvgre_ip_version_value,
15969                 (void *)&cmd_set_nvgre_tni,
15970                 (void *)&cmd_set_nvgre_tni_value,
15971                 (void *)&cmd_set_nvgre_ip_src,
15972                 (void *)&cmd_set_nvgre_ip_src_value,
15973                 (void *)&cmd_set_nvgre_ip_dst,
15974                 (void *)&cmd_set_nvgre_ip_dst_value,
15975                 (void *)&cmd_set_nvgre_vlan,
15976                 (void *)&cmd_set_nvgre_vlan_value,
15977                 (void *)&cmd_set_nvgre_eth_src,
15978                 (void *)&cmd_set_nvgre_eth_src_value,
15979                 (void *)&cmd_set_nvgre_eth_dst,
15980                 (void *)&cmd_set_nvgre_eth_dst_value,
15981                 NULL,
15982         },
15983 };
15984
15985 /** Set L2 encapsulation details */
15986 struct cmd_set_l2_encap_result {
15987         cmdline_fixed_string_t set;
15988         cmdline_fixed_string_t l2_encap;
15989         cmdline_fixed_string_t pos_token;
15990         cmdline_fixed_string_t ip_version;
15991         uint32_t vlan_present:1;
15992         uint16_t tci;
15993         struct rte_ether_addr eth_src;
15994         struct rte_ether_addr eth_dst;
15995 };
15996
15997 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15998         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15999 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
16000         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
16001 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
16002         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
16003                                  "l2_encap-with-vlan");
16004 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
16005         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16006                                  "ip-version");
16007 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
16008         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
16009                                  "ipv4#ipv6");
16010 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
16011         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16012                                  "vlan-tci");
16013 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
16014         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
16015 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
16016         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16017                                  "eth-src");
16018 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
16019         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
16020 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
16021         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16022                                  "eth-dst");
16023 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
16024         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
16025
16026 static void cmd_set_l2_encap_parsed(void *parsed_result,
16027         __rte_unused struct cmdline *cl,
16028         __rte_unused void *data)
16029 {
16030         struct cmd_set_l2_encap_result *res = parsed_result;
16031
16032         if (strcmp(res->l2_encap, "l2_encap") == 0)
16033                 l2_encap_conf.select_vlan = 0;
16034         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
16035                 l2_encap_conf.select_vlan = 1;
16036         if (strcmp(res->ip_version, "ipv4") == 0)
16037                 l2_encap_conf.select_ipv4 = 1;
16038         else if (strcmp(res->ip_version, "ipv6") == 0)
16039                 l2_encap_conf.select_ipv4 = 0;
16040         else
16041                 return;
16042         if (l2_encap_conf.select_vlan)
16043                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16044         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
16045                    RTE_ETHER_ADDR_LEN);
16046         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16047                    RTE_ETHER_ADDR_LEN);
16048 }
16049
16050 cmdline_parse_inst_t cmd_set_l2_encap = {
16051         .f = cmd_set_l2_encap_parsed,
16052         .data = NULL,
16053         .help_str = "set l2_encap ip-version ipv4|ipv6"
16054                 " eth-src <eth-src> eth-dst <eth-dst>",
16055         .tokens = {
16056                 (void *)&cmd_set_l2_encap_set,
16057                 (void *)&cmd_set_l2_encap_l2_encap,
16058                 (void *)&cmd_set_l2_encap_ip_version,
16059                 (void *)&cmd_set_l2_encap_ip_version_value,
16060                 (void *)&cmd_set_l2_encap_eth_src,
16061                 (void *)&cmd_set_l2_encap_eth_src_value,
16062                 (void *)&cmd_set_l2_encap_eth_dst,
16063                 (void *)&cmd_set_l2_encap_eth_dst_value,
16064                 NULL,
16065         },
16066 };
16067
16068 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
16069         .f = cmd_set_l2_encap_parsed,
16070         .data = NULL,
16071         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
16072                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16073         .tokens = {
16074                 (void *)&cmd_set_l2_encap_set,
16075                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
16076                 (void *)&cmd_set_l2_encap_ip_version,
16077                 (void *)&cmd_set_l2_encap_ip_version_value,
16078                 (void *)&cmd_set_l2_encap_vlan,
16079                 (void *)&cmd_set_l2_encap_vlan_value,
16080                 (void *)&cmd_set_l2_encap_eth_src,
16081                 (void *)&cmd_set_l2_encap_eth_src_value,
16082                 (void *)&cmd_set_l2_encap_eth_dst,
16083                 (void *)&cmd_set_l2_encap_eth_dst_value,
16084                 NULL,
16085         },
16086 };
16087
16088 /** Set L2 decapsulation details */
16089 struct cmd_set_l2_decap_result {
16090         cmdline_fixed_string_t set;
16091         cmdline_fixed_string_t l2_decap;
16092         cmdline_fixed_string_t pos_token;
16093         uint32_t vlan_present:1;
16094 };
16095
16096 cmdline_parse_token_string_t cmd_set_l2_decap_set =
16097         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
16098 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
16099         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16100                                  "l2_decap");
16101 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
16102         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16103                                  "l2_decap-with-vlan");
16104
16105 static void cmd_set_l2_decap_parsed(void *parsed_result,
16106         __rte_unused struct cmdline *cl,
16107         __rte_unused void *data)
16108 {
16109         struct cmd_set_l2_decap_result *res = parsed_result;
16110
16111         if (strcmp(res->l2_decap, "l2_decap") == 0)
16112                 l2_decap_conf.select_vlan = 0;
16113         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
16114                 l2_decap_conf.select_vlan = 1;
16115 }
16116
16117 cmdline_parse_inst_t cmd_set_l2_decap = {
16118         .f = cmd_set_l2_decap_parsed,
16119         .data = NULL,
16120         .help_str = "set l2_decap",
16121         .tokens = {
16122                 (void *)&cmd_set_l2_decap_set,
16123                 (void *)&cmd_set_l2_decap_l2_decap,
16124                 NULL,
16125         },
16126 };
16127
16128 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
16129         .f = cmd_set_l2_decap_parsed,
16130         .data = NULL,
16131         .help_str = "set l2_decap-with-vlan",
16132         .tokens = {
16133                 (void *)&cmd_set_l2_decap_set,
16134                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
16135                 NULL,
16136         },
16137 };
16138
16139 /** Set MPLSoGRE encapsulation details */
16140 struct cmd_set_mplsogre_encap_result {
16141         cmdline_fixed_string_t set;
16142         cmdline_fixed_string_t mplsogre;
16143         cmdline_fixed_string_t pos_token;
16144         cmdline_fixed_string_t ip_version;
16145         uint32_t vlan_present:1;
16146         uint32_t label;
16147         cmdline_ipaddr_t ip_src;
16148         cmdline_ipaddr_t ip_dst;
16149         uint16_t tci;
16150         struct rte_ether_addr eth_src;
16151         struct rte_ether_addr eth_dst;
16152 };
16153
16154 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
16155         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
16156                                  "set");
16157 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
16158         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
16159                                  "mplsogre_encap");
16160 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
16161         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16162                                  mplsogre, "mplsogre_encap-with-vlan");
16163 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
16164         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16165                                  pos_token, "ip-version");
16166 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
16167         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16168                                  ip_version, "ipv4#ipv6");
16169 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
16170         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16171                                  pos_token, "label");
16172 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
16173         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
16174                               UINT32);
16175 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
16176         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16177                                  pos_token, "ip-src");
16178 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
16179         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
16180 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
16181         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16182                                  pos_token, "ip-dst");
16183 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16184         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16185 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16186         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16187                                  pos_token, "vlan-tci");
16188 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16189         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16190                               UINT16);
16191 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16192         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16193                                  pos_token, "eth-src");
16194 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16195         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16196                                     eth_src);
16197 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16198         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16199                                  pos_token, "eth-dst");
16200 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16201         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16202                                     eth_dst);
16203
16204 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16205         __rte_unused struct cmdline *cl,
16206         __rte_unused void *data)
16207 {
16208         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16209         union {
16210                 uint32_t mplsogre_label;
16211                 uint8_t label[4];
16212         } id = {
16213                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16214         };
16215
16216         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16217                 mplsogre_encap_conf.select_vlan = 0;
16218         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16219                 mplsogre_encap_conf.select_vlan = 1;
16220         if (strcmp(res->ip_version, "ipv4") == 0)
16221                 mplsogre_encap_conf.select_ipv4 = 1;
16222         else if (strcmp(res->ip_version, "ipv6") == 0)
16223                 mplsogre_encap_conf.select_ipv4 = 0;
16224         else
16225                 return;
16226         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16227         if (mplsogre_encap_conf.select_ipv4) {
16228                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16229                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16230         } else {
16231                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16232                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16233         }
16234         if (mplsogre_encap_conf.select_vlan)
16235                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16236         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16237                    RTE_ETHER_ADDR_LEN);
16238         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16239                    RTE_ETHER_ADDR_LEN);
16240 }
16241
16242 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16243         .f = cmd_set_mplsogre_encap_parsed,
16244         .data = NULL,
16245         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16246                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16247                 " eth-dst <eth-dst>",
16248         .tokens = {
16249                 (void *)&cmd_set_mplsogre_encap_set,
16250                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16251                 (void *)&cmd_set_mplsogre_encap_ip_version,
16252                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16253                 (void *)&cmd_set_mplsogre_encap_label,
16254                 (void *)&cmd_set_mplsogre_encap_label_value,
16255                 (void *)&cmd_set_mplsogre_encap_ip_src,
16256                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16257                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16258                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16259                 (void *)&cmd_set_mplsogre_encap_eth_src,
16260                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16261                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16262                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16263                 NULL,
16264         },
16265 };
16266
16267 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16268         .f = cmd_set_mplsogre_encap_parsed,
16269         .data = NULL,
16270         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16271                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16272                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16273         .tokens = {
16274                 (void *)&cmd_set_mplsogre_encap_set,
16275                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16276                 (void *)&cmd_set_mplsogre_encap_ip_version,
16277                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16278                 (void *)&cmd_set_mplsogre_encap_label,
16279                 (void *)&cmd_set_mplsogre_encap_label_value,
16280                 (void *)&cmd_set_mplsogre_encap_ip_src,
16281                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16282                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16283                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16284                 (void *)&cmd_set_mplsogre_encap_vlan,
16285                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16286                 (void *)&cmd_set_mplsogre_encap_eth_src,
16287                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16288                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16289                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16290                 NULL,
16291         },
16292 };
16293
16294 /** Set MPLSoGRE decapsulation details */
16295 struct cmd_set_mplsogre_decap_result {
16296         cmdline_fixed_string_t set;
16297         cmdline_fixed_string_t mplsogre;
16298         cmdline_fixed_string_t pos_token;
16299         cmdline_fixed_string_t ip_version;
16300         uint32_t vlan_present:1;
16301 };
16302
16303 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16304         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16305                                  "set");
16306 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16307         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16308                                  "mplsogre_decap");
16309 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16310         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16311                                  mplsogre, "mplsogre_decap-with-vlan");
16312 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16313         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16314                                  pos_token, "ip-version");
16315 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16316         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16317                                  ip_version, "ipv4#ipv6");
16318
16319 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16320         __rte_unused struct cmdline *cl,
16321         __rte_unused void *data)
16322 {
16323         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16324
16325         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16326                 mplsogre_decap_conf.select_vlan = 0;
16327         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16328                 mplsogre_decap_conf.select_vlan = 1;
16329         if (strcmp(res->ip_version, "ipv4") == 0)
16330                 mplsogre_decap_conf.select_ipv4 = 1;
16331         else if (strcmp(res->ip_version, "ipv6") == 0)
16332                 mplsogre_decap_conf.select_ipv4 = 0;
16333 }
16334
16335 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16336         .f = cmd_set_mplsogre_decap_parsed,
16337         .data = NULL,
16338         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16339         .tokens = {
16340                 (void *)&cmd_set_mplsogre_decap_set,
16341                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16342                 (void *)&cmd_set_mplsogre_decap_ip_version,
16343                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16344                 NULL,
16345         },
16346 };
16347
16348 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16349         .f = cmd_set_mplsogre_decap_parsed,
16350         .data = NULL,
16351         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16352         .tokens = {
16353                 (void *)&cmd_set_mplsogre_decap_set,
16354                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16355                 (void *)&cmd_set_mplsogre_decap_ip_version,
16356                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16357                 NULL,
16358         },
16359 };
16360
16361 /** Set MPLSoUDP encapsulation details */
16362 struct cmd_set_mplsoudp_encap_result {
16363         cmdline_fixed_string_t set;
16364         cmdline_fixed_string_t mplsoudp;
16365         cmdline_fixed_string_t pos_token;
16366         cmdline_fixed_string_t ip_version;
16367         uint32_t vlan_present:1;
16368         uint32_t label;
16369         uint16_t udp_src;
16370         uint16_t udp_dst;
16371         cmdline_ipaddr_t ip_src;
16372         cmdline_ipaddr_t ip_dst;
16373         uint16_t tci;
16374         struct rte_ether_addr eth_src;
16375         struct rte_ether_addr eth_dst;
16376 };
16377
16378 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16379         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16380                                  "set");
16381 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16382         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16383                                  "mplsoudp_encap");
16384 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16385         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16386                                  mplsoudp, "mplsoudp_encap-with-vlan");
16387 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16388         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16389                                  pos_token, "ip-version");
16390 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16391         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16392                                  ip_version, "ipv4#ipv6");
16393 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16394         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16395                                  pos_token, "label");
16396 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16397         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16398                               UINT32);
16399 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16400         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16401                                  pos_token, "udp-src");
16402 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16403         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16404                               UINT16);
16405 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16406         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16407                                  pos_token, "udp-dst");
16408 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16409         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16410                               UINT16);
16411 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16412         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16413                                  pos_token, "ip-src");
16414 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16415         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16416 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16417         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16418                                  pos_token, "ip-dst");
16419 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16420         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16421 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16422         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16423                                  pos_token, "vlan-tci");
16424 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16425         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16426                               UINT16);
16427 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16428         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16429                                  pos_token, "eth-src");
16430 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16431         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16432                                     eth_src);
16433 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16434         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16435                                  pos_token, "eth-dst");
16436 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16437         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16438                                     eth_dst);
16439
16440 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16441         __rte_unused struct cmdline *cl,
16442         __rte_unused void *data)
16443 {
16444         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16445         union {
16446                 uint32_t mplsoudp_label;
16447                 uint8_t label[4];
16448         } id = {
16449                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16450         };
16451
16452         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16453                 mplsoudp_encap_conf.select_vlan = 0;
16454         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16455                 mplsoudp_encap_conf.select_vlan = 1;
16456         if (strcmp(res->ip_version, "ipv4") == 0)
16457                 mplsoudp_encap_conf.select_ipv4 = 1;
16458         else if (strcmp(res->ip_version, "ipv6") == 0)
16459                 mplsoudp_encap_conf.select_ipv4 = 0;
16460         else
16461                 return;
16462         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16463         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16464         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16465         if (mplsoudp_encap_conf.select_ipv4) {
16466                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16467                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16468         } else {
16469                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16470                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16471         }
16472         if (mplsoudp_encap_conf.select_vlan)
16473                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16474         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16475                    RTE_ETHER_ADDR_LEN);
16476         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16477                    RTE_ETHER_ADDR_LEN);
16478 }
16479
16480 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16481         .f = cmd_set_mplsoudp_encap_parsed,
16482         .data = NULL,
16483         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16484                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16485                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16486         .tokens = {
16487                 (void *)&cmd_set_mplsoudp_encap_set,
16488                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16489                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16490                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16491                 (void *)&cmd_set_mplsoudp_encap_label,
16492                 (void *)&cmd_set_mplsoudp_encap_label_value,
16493                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16494                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16495                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16496                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16497                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16498                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16499                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16500                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16501                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16502                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16503                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16504                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16505                 NULL,
16506         },
16507 };
16508
16509 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16510         .f = cmd_set_mplsoudp_encap_parsed,
16511         .data = NULL,
16512         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16513                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16514                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16515                 " eth-src <eth-src> eth-dst <eth-dst>",
16516         .tokens = {
16517                 (void *)&cmd_set_mplsoudp_encap_set,
16518                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16519                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16520                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16521                 (void *)&cmd_set_mplsoudp_encap_label,
16522                 (void *)&cmd_set_mplsoudp_encap_label_value,
16523                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16524                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16525                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16526                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16527                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16528                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16529                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16530                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16531                 (void *)&cmd_set_mplsoudp_encap_vlan,
16532                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16533                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16534                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16535                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16536                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16537                 NULL,
16538         },
16539 };
16540
16541 /** Set MPLSoUDP decapsulation details */
16542 struct cmd_set_mplsoudp_decap_result {
16543         cmdline_fixed_string_t set;
16544         cmdline_fixed_string_t mplsoudp;
16545         cmdline_fixed_string_t pos_token;
16546         cmdline_fixed_string_t ip_version;
16547         uint32_t vlan_present:1;
16548 };
16549
16550 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16551         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16552                                  "set");
16553 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16554         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16555                                  "mplsoudp_decap");
16556 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16557         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16558                                  mplsoudp, "mplsoudp_decap-with-vlan");
16559 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16560         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16561                                  pos_token, "ip-version");
16562 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16563         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16564                                  ip_version, "ipv4#ipv6");
16565
16566 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16567         __rte_unused struct cmdline *cl,
16568         __rte_unused void *data)
16569 {
16570         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16571
16572         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16573                 mplsoudp_decap_conf.select_vlan = 0;
16574         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16575                 mplsoudp_decap_conf.select_vlan = 1;
16576         if (strcmp(res->ip_version, "ipv4") == 0)
16577                 mplsoudp_decap_conf.select_ipv4 = 1;
16578         else if (strcmp(res->ip_version, "ipv6") == 0)
16579                 mplsoudp_decap_conf.select_ipv4 = 0;
16580 }
16581
16582 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16583         .f = cmd_set_mplsoudp_decap_parsed,
16584         .data = NULL,
16585         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16586         .tokens = {
16587                 (void *)&cmd_set_mplsoudp_decap_set,
16588                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16589                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16590                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16591                 NULL,
16592         },
16593 };
16594
16595 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16596         .f = cmd_set_mplsoudp_decap_parsed,
16597         .data = NULL,
16598         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16599         .tokens = {
16600                 (void *)&cmd_set_mplsoudp_decap_set,
16601                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16602                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16603                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16604                 NULL,
16605         },
16606 };
16607
16608 /* Strict link priority scheduling mode setting */
16609 static void
16610 cmd_strict_link_prio_parsed(
16611         void *parsed_result,
16612         __rte_unused struct cmdline *cl,
16613         __rte_unused void *data)
16614 {
16615         struct cmd_vf_tc_bw_result *res = parsed_result;
16616         int ret = -ENOTSUP;
16617
16618         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16619                 return;
16620
16621 #ifdef RTE_NET_I40E
16622         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16623 #endif
16624
16625         switch (ret) {
16626         case 0:
16627                 break;
16628         case -EINVAL:
16629                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16630                 break;
16631         case -ENODEV:
16632                 printf("invalid port_id %d\n", res->port_id);
16633                 break;
16634         case -ENOTSUP:
16635                 printf("function not implemented\n");
16636                 break;
16637         default:
16638                 printf("programming error: (%s)\n", strerror(-ret));
16639         }
16640 }
16641
16642 cmdline_parse_inst_t cmd_strict_link_prio = {
16643         .f = cmd_strict_link_prio_parsed,
16644         .data = NULL,
16645         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16646         .tokens = {
16647                 (void *)&cmd_vf_tc_bw_set,
16648                 (void *)&cmd_vf_tc_bw_tx,
16649                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16650                 (void *)&cmd_vf_tc_bw_port_id,
16651                 (void *)&cmd_vf_tc_bw_tc_map,
16652                 NULL,
16653         },
16654 };
16655
16656 /* Load dynamic device personalization*/
16657 struct cmd_ddp_add_result {
16658         cmdline_fixed_string_t ddp;
16659         cmdline_fixed_string_t add;
16660         portid_t port_id;
16661         char filepath[];
16662 };
16663
16664 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16665         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16666 cmdline_parse_token_string_t cmd_ddp_add_add =
16667         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16668 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16669         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16670 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16671         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16672
16673 static void
16674 cmd_ddp_add_parsed(
16675         void *parsed_result,
16676         __rte_unused struct cmdline *cl,
16677         __rte_unused void *data)
16678 {
16679         struct cmd_ddp_add_result *res = parsed_result;
16680         uint8_t *buff;
16681         uint32_t size;
16682         char *filepath;
16683         char *file_fld[2];
16684         int file_num;
16685         int ret = -ENOTSUP;
16686
16687         if (!all_ports_stopped()) {
16688                 printf("Please stop all ports first\n");
16689                 return;
16690         }
16691
16692         filepath = strdup(res->filepath);
16693         if (filepath == NULL) {
16694                 printf("Failed to allocate memory\n");
16695                 return;
16696         }
16697         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16698
16699         buff = open_file(file_fld[0], &size);
16700         if (!buff) {
16701                 free((void *)filepath);
16702                 return;
16703         }
16704
16705 #ifdef RTE_NET_I40E
16706         if (ret == -ENOTSUP)
16707                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16708                                                buff, size,
16709                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16710 #endif
16711
16712         if (ret == -EEXIST)
16713                 printf("Profile has already existed.\n");
16714         else if (ret < 0)
16715                 printf("Failed to load profile.\n");
16716         else if (file_num == 2)
16717                 save_file(file_fld[1], buff, size);
16718
16719         close_file(buff);
16720         free((void *)filepath);
16721 }
16722
16723 cmdline_parse_inst_t cmd_ddp_add = {
16724         .f = cmd_ddp_add_parsed,
16725         .data = NULL,
16726         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16727         .tokens = {
16728                 (void *)&cmd_ddp_add_ddp,
16729                 (void *)&cmd_ddp_add_add,
16730                 (void *)&cmd_ddp_add_port_id,
16731                 (void *)&cmd_ddp_add_filepath,
16732                 NULL,
16733         },
16734 };
16735
16736 /* Delete dynamic device personalization*/
16737 struct cmd_ddp_del_result {
16738         cmdline_fixed_string_t ddp;
16739         cmdline_fixed_string_t del;
16740         portid_t port_id;
16741         char filepath[];
16742 };
16743
16744 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16745         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16746 cmdline_parse_token_string_t cmd_ddp_del_del =
16747         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16748 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16749         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16750 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16751         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16752
16753 static void
16754 cmd_ddp_del_parsed(
16755         void *parsed_result,
16756         __rte_unused struct cmdline *cl,
16757         __rte_unused void *data)
16758 {
16759         struct cmd_ddp_del_result *res = parsed_result;
16760         uint8_t *buff;
16761         uint32_t size;
16762         int ret = -ENOTSUP;
16763
16764         if (!all_ports_stopped()) {
16765                 printf("Please stop all ports first\n");
16766                 return;
16767         }
16768
16769         buff = open_file(res->filepath, &size);
16770         if (!buff)
16771                 return;
16772
16773 #ifdef RTE_NET_I40E
16774         if (ret == -ENOTSUP)
16775                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16776                                                buff, size,
16777                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16778 #endif
16779
16780         if (ret == -EACCES)
16781                 printf("Profile does not exist.\n");
16782         else if (ret < 0)
16783                 printf("Failed to delete profile.\n");
16784
16785         close_file(buff);
16786 }
16787
16788 cmdline_parse_inst_t cmd_ddp_del = {
16789         .f = cmd_ddp_del_parsed,
16790         .data = NULL,
16791         .help_str = "ddp del <port_id> <backup_profile_path>",
16792         .tokens = {
16793                 (void *)&cmd_ddp_del_ddp,
16794                 (void *)&cmd_ddp_del_del,
16795                 (void *)&cmd_ddp_del_port_id,
16796                 (void *)&cmd_ddp_del_filepath,
16797                 NULL,
16798         },
16799 };
16800
16801 /* Get dynamic device personalization profile info */
16802 struct cmd_ddp_info_result {
16803         cmdline_fixed_string_t ddp;
16804         cmdline_fixed_string_t get;
16805         cmdline_fixed_string_t info;
16806         char filepath[];
16807 };
16808
16809 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16810         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16811 cmdline_parse_token_string_t cmd_ddp_info_get =
16812         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16813 cmdline_parse_token_string_t cmd_ddp_info_info =
16814         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16815 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16816         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16817
16818 static void
16819 cmd_ddp_info_parsed(
16820         void *parsed_result,
16821         __rte_unused struct cmdline *cl,
16822         __rte_unused void *data)
16823 {
16824         struct cmd_ddp_info_result *res = parsed_result;
16825         uint8_t *pkg;
16826         uint32_t pkg_size;
16827         int ret = -ENOTSUP;
16828 #ifdef RTE_NET_I40E
16829         uint32_t i, j, n;
16830         uint8_t *buff;
16831         uint32_t buff_size = 0;
16832         struct rte_pmd_i40e_profile_info info;
16833         uint32_t dev_num = 0;
16834         struct rte_pmd_i40e_ddp_device_id *devs;
16835         uint32_t proto_num = 0;
16836         struct rte_pmd_i40e_proto_info *proto = NULL;
16837         uint32_t pctype_num = 0;
16838         struct rte_pmd_i40e_ptype_info *pctype;
16839         uint32_t ptype_num = 0;
16840         struct rte_pmd_i40e_ptype_info *ptype;
16841         uint8_t proto_id;
16842
16843 #endif
16844
16845         pkg = open_file(res->filepath, &pkg_size);
16846         if (!pkg)
16847                 return;
16848
16849 #ifdef RTE_NET_I40E
16850         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16851                                 (uint8_t *)&info, sizeof(info),
16852                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16853         if (!ret) {
16854                 printf("Global Track id:       0x%x\n", info.track_id);
16855                 printf("Global Version:        %d.%d.%d.%d\n",
16856                         info.version.major,
16857                         info.version.minor,
16858                         info.version.update,
16859                         info.version.draft);
16860                 printf("Global Package name:   %s\n\n", info.name);
16861         }
16862
16863         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16864                                 (uint8_t *)&info, sizeof(info),
16865                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16866         if (!ret) {
16867                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16868                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16869                         info.version.major,
16870                         info.version.minor,
16871                         info.version.update,
16872                         info.version.draft);
16873                 printf("i40e Profile name:     %s\n\n", info.name);
16874         }
16875
16876         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16877                                 (uint8_t *)&buff_size, sizeof(buff_size),
16878                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16879         if (!ret && buff_size) {
16880                 buff = (uint8_t *)malloc(buff_size);
16881                 if (buff) {
16882                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16883                                                 buff, buff_size,
16884                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16885                         if (!ret)
16886                                 printf("Package Notes:\n%s\n\n", buff);
16887                         free(buff);
16888                 }
16889         }
16890
16891         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16892                                 (uint8_t *)&dev_num, sizeof(dev_num),
16893                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16894         if (!ret && dev_num) {
16895                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16896                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16897                 if (devs) {
16898                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16899                                                 (uint8_t *)devs, buff_size,
16900                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16901                         if (!ret) {
16902                                 printf("List of supported devices:\n");
16903                                 for (i = 0; i < dev_num; i++) {
16904                                         printf("  %04X:%04X %04X:%04X\n",
16905                                                 devs[i].vendor_dev_id >> 16,
16906                                                 devs[i].vendor_dev_id & 0xFFFF,
16907                                                 devs[i].sub_vendor_dev_id >> 16,
16908                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16909                                 }
16910                                 printf("\n");
16911                         }
16912                         free(devs);
16913                 }
16914         }
16915
16916         /* get information about protocols and packet types */
16917         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16918                 (uint8_t *)&proto_num, sizeof(proto_num),
16919                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16920         if (ret || !proto_num)
16921                 goto no_print_return;
16922
16923         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16924         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16925         if (!proto)
16926                 goto no_print_return;
16927
16928         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16929                                         buff_size,
16930                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16931         if (!ret) {
16932                 printf("List of used protocols:\n");
16933                 for (i = 0; i < proto_num; i++)
16934                         printf("  %2u: %s\n", proto[i].proto_id,
16935                                proto[i].name);
16936                 printf("\n");
16937         }
16938         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16939                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16940                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16941         if (ret || !pctype_num)
16942                 goto no_print_pctypes;
16943
16944         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16945         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16946         if (!pctype)
16947                 goto no_print_pctypes;
16948
16949         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16950                                         buff_size,
16951                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16952         if (ret) {
16953                 free(pctype);
16954                 goto no_print_pctypes;
16955         }
16956
16957         printf("List of defined packet classification types:\n");
16958         for (i = 0; i < pctype_num; i++) {
16959                 printf("  %2u:", pctype[i].ptype_id);
16960                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16961                         proto_id = pctype[i].protocols[j];
16962                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16963                                 for (n = 0; n < proto_num; n++) {
16964                                         if (proto[n].proto_id == proto_id) {
16965                                                 printf(" %s", proto[n].name);
16966                                                 break;
16967                                         }
16968                                 }
16969                         }
16970                 }
16971                 printf("\n");
16972         }
16973         printf("\n");
16974         free(pctype);
16975
16976 no_print_pctypes:
16977
16978         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16979                                         sizeof(ptype_num),
16980                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16981         if (ret || !ptype_num)
16982                 goto no_print_return;
16983
16984         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16985         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16986         if (!ptype)
16987                 goto no_print_return;
16988
16989         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16990                                         buff_size,
16991                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16992         if (ret) {
16993                 free(ptype);
16994                 goto no_print_return;
16995         }
16996         printf("List of defined packet types:\n");
16997         for (i = 0; i < ptype_num; i++) {
16998                 printf("  %2u:", ptype[i].ptype_id);
16999                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
17000                         proto_id = ptype[i].protocols[j];
17001                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
17002                                 for (n = 0; n < proto_num; n++) {
17003                                         if (proto[n].proto_id == proto_id) {
17004                                                 printf(" %s", proto[n].name);
17005                                                 break;
17006                                         }
17007                                 }
17008                         }
17009                 }
17010                 printf("\n");
17011         }
17012         free(ptype);
17013         printf("\n");
17014
17015         ret = 0;
17016 no_print_return:
17017         if (proto)
17018                 free(proto);
17019 #endif
17020         if (ret == -ENOTSUP)
17021                 printf("Function not supported in PMD driver\n");
17022         close_file(pkg);
17023 }
17024
17025 cmdline_parse_inst_t cmd_ddp_get_info = {
17026         .f = cmd_ddp_info_parsed,
17027         .data = NULL,
17028         .help_str = "ddp get info <profile_path>",
17029         .tokens = {
17030                 (void *)&cmd_ddp_info_ddp,
17031                 (void *)&cmd_ddp_info_get,
17032                 (void *)&cmd_ddp_info_info,
17033                 (void *)&cmd_ddp_info_filepath,
17034                 NULL,
17035         },
17036 };
17037
17038 /* Get dynamic device personalization profile info list*/
17039 #define PROFILE_INFO_SIZE 48
17040 #define MAX_PROFILE_NUM 16
17041
17042 struct cmd_ddp_get_list_result {
17043         cmdline_fixed_string_t ddp;
17044         cmdline_fixed_string_t get;
17045         cmdline_fixed_string_t list;
17046         portid_t port_id;
17047 };
17048
17049 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
17050         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
17051 cmdline_parse_token_string_t cmd_ddp_get_list_get =
17052         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
17053 cmdline_parse_token_string_t cmd_ddp_get_list_list =
17054         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
17055 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
17056         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
17057
17058 static void
17059 cmd_ddp_get_list_parsed(
17060         __rte_unused void *parsed_result,
17061         __rte_unused struct cmdline *cl,
17062         __rte_unused void *data)
17063 {
17064 #ifdef RTE_NET_I40E
17065         struct cmd_ddp_get_list_result *res = parsed_result;
17066         struct rte_pmd_i40e_profile_list *p_list;
17067         struct rte_pmd_i40e_profile_info *p_info;
17068         uint32_t p_num;
17069         uint32_t size;
17070         uint32_t i;
17071 #endif
17072         int ret = -ENOTSUP;
17073
17074 #ifdef RTE_NET_I40E
17075         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
17076         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
17077         if (!p_list) {
17078                 printf("%s: Failed to malloc buffer\n", __func__);
17079                 return;
17080         }
17081
17082         if (ret == -ENOTSUP)
17083                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
17084                                                 (uint8_t *)p_list, size);
17085
17086         if (!ret) {
17087                 p_num = p_list->p_count;
17088                 printf("Profile number is: %d\n\n", p_num);
17089
17090                 for (i = 0; i < p_num; i++) {
17091                         p_info = &p_list->p_info[i];
17092                         printf("Profile %d:\n", i);
17093                         printf("Track id:     0x%x\n", p_info->track_id);
17094                         printf("Version:      %d.%d.%d.%d\n",
17095                                p_info->version.major,
17096                                p_info->version.minor,
17097                                p_info->version.update,
17098                                p_info->version.draft);
17099                         printf("Profile name: %s\n\n", p_info->name);
17100                 }
17101         }
17102
17103         free(p_list);
17104 #endif
17105
17106         if (ret < 0)
17107                 printf("Failed to get ddp list\n");
17108 }
17109
17110 cmdline_parse_inst_t cmd_ddp_get_list = {
17111         .f = cmd_ddp_get_list_parsed,
17112         .data = NULL,
17113         .help_str = "ddp get list <port_id>",
17114         .tokens = {
17115                 (void *)&cmd_ddp_get_list_ddp,
17116                 (void *)&cmd_ddp_get_list_get,
17117                 (void *)&cmd_ddp_get_list_list,
17118                 (void *)&cmd_ddp_get_list_port_id,
17119                 NULL,
17120         },
17121 };
17122
17123 /* Configure input set */
17124 struct cmd_cfg_input_set_result {
17125         cmdline_fixed_string_t port;
17126         cmdline_fixed_string_t cfg;
17127         portid_t port_id;
17128         cmdline_fixed_string_t pctype;
17129         uint8_t pctype_id;
17130         cmdline_fixed_string_t inset_type;
17131         cmdline_fixed_string_t opt;
17132         cmdline_fixed_string_t field;
17133         uint8_t field_idx;
17134 };
17135
17136 static void
17137 cmd_cfg_input_set_parsed(
17138         __rte_unused void *parsed_result,
17139         __rte_unused struct cmdline *cl,
17140         __rte_unused void *data)
17141 {
17142 #ifdef RTE_NET_I40E
17143         struct cmd_cfg_input_set_result *res = parsed_result;
17144         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17145         struct rte_pmd_i40e_inset inset;
17146 #endif
17147         int ret = -ENOTSUP;
17148
17149         if (!all_ports_stopped()) {
17150                 printf("Please stop all ports first\n");
17151                 return;
17152         }
17153
17154 #ifdef RTE_NET_I40E
17155         if (!strcmp(res->inset_type, "hash_inset"))
17156                 inset_type = INSET_HASH;
17157         else if (!strcmp(res->inset_type, "fdir_inset"))
17158                 inset_type = INSET_FDIR;
17159         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17160                 inset_type = INSET_FDIR_FLX;
17161         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
17162                                      &inset, inset_type);
17163         if (ret) {
17164                 printf("Failed to get input set.\n");
17165                 return;
17166         }
17167
17168         if (!strcmp(res->opt, "get")) {
17169                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
17170                                                    res->field_idx);
17171                 if (ret)
17172                         printf("Field index %d is enabled.\n", res->field_idx);
17173                 else
17174                         printf("Field index %d is disabled.\n", res->field_idx);
17175                 return;
17176         } else if (!strcmp(res->opt, "set"))
17177                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
17178                                                    res->field_idx);
17179         else if (!strcmp(res->opt, "clear"))
17180                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
17181                                                      res->field_idx);
17182         if (ret) {
17183                 printf("Failed to configure input set field.\n");
17184                 return;
17185         }
17186
17187         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17188                                      &inset, inset_type);
17189         if (ret) {
17190                 printf("Failed to set input set.\n");
17191                 return;
17192         }
17193 #endif
17194
17195         if (ret == -ENOTSUP)
17196                 printf("Function not supported\n");
17197 }
17198
17199 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17200         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17201                                  port, "port");
17202 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17203         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17204                                  cfg, "config");
17205 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17206         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17207                               port_id, UINT16);
17208 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17209         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17210                                  pctype, "pctype");
17211 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17212         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17213                               pctype_id, UINT8);
17214 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17215         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17216                                  inset_type,
17217                                  "hash_inset#fdir_inset#fdir_flx_inset");
17218 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17219         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17220                                  opt, "get#set#clear");
17221 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17222         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17223                                  field, "field");
17224 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17225         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17226                               field_idx, UINT8);
17227
17228 cmdline_parse_inst_t cmd_cfg_input_set = {
17229         .f = cmd_cfg_input_set_parsed,
17230         .data = NULL,
17231         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17232                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17233         .tokens = {
17234                 (void *)&cmd_cfg_input_set_port,
17235                 (void *)&cmd_cfg_input_set_cfg,
17236                 (void *)&cmd_cfg_input_set_port_id,
17237                 (void *)&cmd_cfg_input_set_pctype,
17238                 (void *)&cmd_cfg_input_set_pctype_id,
17239                 (void *)&cmd_cfg_input_set_inset_type,
17240                 (void *)&cmd_cfg_input_set_opt,
17241                 (void *)&cmd_cfg_input_set_field,
17242                 (void *)&cmd_cfg_input_set_field_idx,
17243                 NULL,
17244         },
17245 };
17246
17247 /* Clear input set */
17248 struct cmd_clear_input_set_result {
17249         cmdline_fixed_string_t port;
17250         cmdline_fixed_string_t cfg;
17251         portid_t port_id;
17252         cmdline_fixed_string_t pctype;
17253         uint8_t pctype_id;
17254         cmdline_fixed_string_t inset_type;
17255         cmdline_fixed_string_t clear;
17256         cmdline_fixed_string_t all;
17257 };
17258
17259 static void
17260 cmd_clear_input_set_parsed(
17261         __rte_unused void *parsed_result,
17262         __rte_unused struct cmdline *cl,
17263         __rte_unused void *data)
17264 {
17265 #ifdef RTE_NET_I40E
17266         struct cmd_clear_input_set_result *res = parsed_result;
17267         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17268         struct rte_pmd_i40e_inset inset;
17269 #endif
17270         int ret = -ENOTSUP;
17271
17272         if (!all_ports_stopped()) {
17273                 printf("Please stop all ports first\n");
17274                 return;
17275         }
17276
17277 #ifdef RTE_NET_I40E
17278         if (!strcmp(res->inset_type, "hash_inset"))
17279                 inset_type = INSET_HASH;
17280         else if (!strcmp(res->inset_type, "fdir_inset"))
17281                 inset_type = INSET_FDIR;
17282         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17283                 inset_type = INSET_FDIR_FLX;
17284
17285         memset(&inset, 0, sizeof(inset));
17286
17287         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17288                                      &inset, inset_type);
17289         if (ret) {
17290                 printf("Failed to clear input set.\n");
17291                 return;
17292         }
17293
17294 #endif
17295
17296         if (ret == -ENOTSUP)
17297                 printf("Function not supported\n");
17298 }
17299
17300 cmdline_parse_token_string_t cmd_clear_input_set_port =
17301         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17302                                  port, "port");
17303 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17304         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17305                                  cfg, "config");
17306 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17307         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17308                               port_id, UINT16);
17309 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17310         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17311                                  pctype, "pctype");
17312 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17313         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17314                               pctype_id, UINT8);
17315 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17316         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17317                                  inset_type,
17318                                  "hash_inset#fdir_inset#fdir_flx_inset");
17319 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17320         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17321                                  clear, "clear");
17322 cmdline_parse_token_string_t cmd_clear_input_set_all =
17323         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17324                                  all, "all");
17325
17326 cmdline_parse_inst_t cmd_clear_input_set = {
17327         .f = cmd_clear_input_set_parsed,
17328         .data = NULL,
17329         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17330                     "fdir_inset|fdir_flx_inset clear all",
17331         .tokens = {
17332                 (void *)&cmd_clear_input_set_port,
17333                 (void *)&cmd_clear_input_set_cfg,
17334                 (void *)&cmd_clear_input_set_port_id,
17335                 (void *)&cmd_clear_input_set_pctype,
17336                 (void *)&cmd_clear_input_set_pctype_id,
17337                 (void *)&cmd_clear_input_set_inset_type,
17338                 (void *)&cmd_clear_input_set_clear,
17339                 (void *)&cmd_clear_input_set_all,
17340                 NULL,
17341         },
17342 };
17343
17344 /* show vf stats */
17345
17346 /* Common result structure for show vf stats */
17347 struct cmd_show_vf_stats_result {
17348         cmdline_fixed_string_t show;
17349         cmdline_fixed_string_t vf;
17350         cmdline_fixed_string_t stats;
17351         portid_t port_id;
17352         uint16_t vf_id;
17353 };
17354
17355 /* Common CLI fields show vf stats*/
17356 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17357         TOKEN_STRING_INITIALIZER
17358                 (struct cmd_show_vf_stats_result,
17359                  show, "show");
17360 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17361         TOKEN_STRING_INITIALIZER
17362                 (struct cmd_show_vf_stats_result,
17363                  vf, "vf");
17364 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17365         TOKEN_STRING_INITIALIZER
17366                 (struct cmd_show_vf_stats_result,
17367                  stats, "stats");
17368 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17369         TOKEN_NUM_INITIALIZER
17370                 (struct cmd_show_vf_stats_result,
17371                  port_id, UINT16);
17372 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17373         TOKEN_NUM_INITIALIZER
17374                 (struct cmd_show_vf_stats_result,
17375                  vf_id, UINT16);
17376
17377 static void
17378 cmd_show_vf_stats_parsed(
17379         void *parsed_result,
17380         __rte_unused struct cmdline *cl,
17381         __rte_unused void *data)
17382 {
17383         struct cmd_show_vf_stats_result *res = parsed_result;
17384         struct rte_eth_stats stats;
17385         int ret = -ENOTSUP;
17386         static const char *nic_stats_border = "########################";
17387
17388         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17389                 return;
17390
17391         memset(&stats, 0, sizeof(stats));
17392
17393 #ifdef RTE_NET_I40E
17394         if (ret == -ENOTSUP)
17395                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17396                                                 res->vf_id,
17397                                                 &stats);
17398 #endif
17399 #ifdef RTE_NET_BNXT
17400         if (ret == -ENOTSUP)
17401                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17402                                                 res->vf_id,
17403                                                 &stats);
17404 #endif
17405
17406         switch (ret) {
17407         case 0:
17408                 break;
17409         case -EINVAL:
17410                 printf("invalid vf_id %d\n", res->vf_id);
17411                 break;
17412         case -ENODEV:
17413                 printf("invalid port_id %d\n", res->port_id);
17414                 break;
17415         case -ENOTSUP:
17416                 printf("function not implemented\n");
17417                 break;
17418         default:
17419                 printf("programming error: (%s)\n", strerror(-ret));
17420         }
17421
17422         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17423                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17424
17425         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17426                "%-"PRIu64"\n",
17427                stats.ipackets, stats.imissed, stats.ibytes);
17428         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17429         printf("  RX-nombuf:  %-10"PRIu64"\n",
17430                stats.rx_nombuf);
17431         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17432                "%-"PRIu64"\n",
17433                stats.opackets, stats.oerrors, stats.obytes);
17434
17435         printf("  %s############################%s\n",
17436                                nic_stats_border, nic_stats_border);
17437 }
17438
17439 cmdline_parse_inst_t cmd_show_vf_stats = {
17440         .f = cmd_show_vf_stats_parsed,
17441         .data = NULL,
17442         .help_str = "show vf stats <port_id> <vf_id>",
17443         .tokens = {
17444                 (void *)&cmd_show_vf_stats_show,
17445                 (void *)&cmd_show_vf_stats_vf,
17446                 (void *)&cmd_show_vf_stats_stats,
17447                 (void *)&cmd_show_vf_stats_port_id,
17448                 (void *)&cmd_show_vf_stats_vf_id,
17449                 NULL,
17450         },
17451 };
17452
17453 /* clear vf stats */
17454
17455 /* Common result structure for clear vf stats */
17456 struct cmd_clear_vf_stats_result {
17457         cmdline_fixed_string_t clear;
17458         cmdline_fixed_string_t vf;
17459         cmdline_fixed_string_t stats;
17460         portid_t port_id;
17461         uint16_t vf_id;
17462 };
17463
17464 /* Common CLI fields clear vf stats*/
17465 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17466         TOKEN_STRING_INITIALIZER
17467                 (struct cmd_clear_vf_stats_result,
17468                  clear, "clear");
17469 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17470         TOKEN_STRING_INITIALIZER
17471                 (struct cmd_clear_vf_stats_result,
17472                  vf, "vf");
17473 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17474         TOKEN_STRING_INITIALIZER
17475                 (struct cmd_clear_vf_stats_result,
17476                  stats, "stats");
17477 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17478         TOKEN_NUM_INITIALIZER
17479                 (struct cmd_clear_vf_stats_result,
17480                  port_id, UINT16);
17481 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17482         TOKEN_NUM_INITIALIZER
17483                 (struct cmd_clear_vf_stats_result,
17484                  vf_id, UINT16);
17485
17486 static void
17487 cmd_clear_vf_stats_parsed(
17488         void *parsed_result,
17489         __rte_unused struct cmdline *cl,
17490         __rte_unused void *data)
17491 {
17492         struct cmd_clear_vf_stats_result *res = parsed_result;
17493         int ret = -ENOTSUP;
17494
17495         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17496                 return;
17497
17498 #ifdef RTE_NET_I40E
17499         if (ret == -ENOTSUP)
17500                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17501                                                   res->vf_id);
17502 #endif
17503 #ifdef RTE_NET_BNXT
17504         if (ret == -ENOTSUP)
17505                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17506                                                   res->vf_id);
17507 #endif
17508
17509         switch (ret) {
17510         case 0:
17511                 break;
17512         case -EINVAL:
17513                 printf("invalid vf_id %d\n", res->vf_id);
17514                 break;
17515         case -ENODEV:
17516                 printf("invalid port_id %d\n", res->port_id);
17517                 break;
17518         case -ENOTSUP:
17519                 printf("function not implemented\n");
17520                 break;
17521         default:
17522                 printf("programming error: (%s)\n", strerror(-ret));
17523         }
17524 }
17525
17526 cmdline_parse_inst_t cmd_clear_vf_stats = {
17527         .f = cmd_clear_vf_stats_parsed,
17528         .data = NULL,
17529         .help_str = "clear vf stats <port_id> <vf_id>",
17530         .tokens = {
17531                 (void *)&cmd_clear_vf_stats_clear,
17532                 (void *)&cmd_clear_vf_stats_vf,
17533                 (void *)&cmd_clear_vf_stats_stats,
17534                 (void *)&cmd_clear_vf_stats_port_id,
17535                 (void *)&cmd_clear_vf_stats_vf_id,
17536                 NULL,
17537         },
17538 };
17539
17540 /* port config pctype mapping reset */
17541
17542 /* Common result structure for port config pctype mapping reset */
17543 struct cmd_pctype_mapping_reset_result {
17544         cmdline_fixed_string_t port;
17545         cmdline_fixed_string_t config;
17546         portid_t port_id;
17547         cmdline_fixed_string_t pctype;
17548         cmdline_fixed_string_t mapping;
17549         cmdline_fixed_string_t reset;
17550 };
17551
17552 /* Common CLI fields for port config pctype mapping reset*/
17553 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17554         TOKEN_STRING_INITIALIZER
17555                 (struct cmd_pctype_mapping_reset_result,
17556                  port, "port");
17557 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17558         TOKEN_STRING_INITIALIZER
17559                 (struct cmd_pctype_mapping_reset_result,
17560                  config, "config");
17561 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17562         TOKEN_NUM_INITIALIZER
17563                 (struct cmd_pctype_mapping_reset_result,
17564                  port_id, UINT16);
17565 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17566         TOKEN_STRING_INITIALIZER
17567                 (struct cmd_pctype_mapping_reset_result,
17568                  pctype, "pctype");
17569 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17570         TOKEN_STRING_INITIALIZER
17571                 (struct cmd_pctype_mapping_reset_result,
17572                  mapping, "mapping");
17573 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17574         TOKEN_STRING_INITIALIZER
17575                 (struct cmd_pctype_mapping_reset_result,
17576                  reset, "reset");
17577
17578 static void
17579 cmd_pctype_mapping_reset_parsed(
17580         void *parsed_result,
17581         __rte_unused struct cmdline *cl,
17582         __rte_unused void *data)
17583 {
17584         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17585         int ret = -ENOTSUP;
17586
17587         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17588                 return;
17589
17590 #ifdef RTE_NET_I40E
17591         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17592 #endif
17593
17594         switch (ret) {
17595         case 0:
17596                 break;
17597         case -ENODEV:
17598                 printf("invalid port_id %d\n", res->port_id);
17599                 break;
17600         case -ENOTSUP:
17601                 printf("function not implemented\n");
17602                 break;
17603         default:
17604                 printf("programming error: (%s)\n", strerror(-ret));
17605         }
17606 }
17607
17608 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17609         .f = cmd_pctype_mapping_reset_parsed,
17610         .data = NULL,
17611         .help_str = "port config <port_id> pctype mapping reset",
17612         .tokens = {
17613                 (void *)&cmd_pctype_mapping_reset_port,
17614                 (void *)&cmd_pctype_mapping_reset_config,
17615                 (void *)&cmd_pctype_mapping_reset_port_id,
17616                 (void *)&cmd_pctype_mapping_reset_pctype,
17617                 (void *)&cmd_pctype_mapping_reset_mapping,
17618                 (void *)&cmd_pctype_mapping_reset_reset,
17619                 NULL,
17620         },
17621 };
17622
17623 /* show port pctype mapping */
17624
17625 /* Common result structure for show port pctype mapping */
17626 struct cmd_pctype_mapping_get_result {
17627         cmdline_fixed_string_t show;
17628         cmdline_fixed_string_t port;
17629         portid_t port_id;
17630         cmdline_fixed_string_t pctype;
17631         cmdline_fixed_string_t mapping;
17632 };
17633
17634 /* Common CLI fields for pctype mapping get */
17635 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17636         TOKEN_STRING_INITIALIZER
17637                 (struct cmd_pctype_mapping_get_result,
17638                  show, "show");
17639 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17640         TOKEN_STRING_INITIALIZER
17641                 (struct cmd_pctype_mapping_get_result,
17642                  port, "port");
17643 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17644         TOKEN_NUM_INITIALIZER
17645                 (struct cmd_pctype_mapping_get_result,
17646                  port_id, UINT16);
17647 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17648         TOKEN_STRING_INITIALIZER
17649                 (struct cmd_pctype_mapping_get_result,
17650                  pctype, "pctype");
17651 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17652         TOKEN_STRING_INITIALIZER
17653                 (struct cmd_pctype_mapping_get_result,
17654                  mapping, "mapping");
17655
17656 static void
17657 cmd_pctype_mapping_get_parsed(
17658         void *parsed_result,
17659         __rte_unused struct cmdline *cl,
17660         __rte_unused void *data)
17661 {
17662         struct cmd_pctype_mapping_get_result *res = parsed_result;
17663         int ret = -ENOTSUP;
17664 #ifdef RTE_NET_I40E
17665         struct rte_pmd_i40e_flow_type_mapping
17666                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17667         int i, j, first_pctype;
17668 #endif
17669
17670         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17671                 return;
17672
17673 #ifdef RTE_NET_I40E
17674         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17675 #endif
17676
17677         switch (ret) {
17678         case 0:
17679                 break;
17680         case -ENODEV:
17681                 printf("invalid port_id %d\n", res->port_id);
17682                 return;
17683         case -ENOTSUP:
17684                 printf("function not implemented\n");
17685                 return;
17686         default:
17687                 printf("programming error: (%s)\n", strerror(-ret));
17688                 return;
17689         }
17690
17691 #ifdef RTE_NET_I40E
17692         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17693                 if (mapping[i].pctype != 0ULL) {
17694                         first_pctype = 1;
17695
17696                         printf("pctype: ");
17697                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17698                                 if (mapping[i].pctype & (1ULL << j)) {
17699                                         printf(first_pctype ?
17700                                                "%02d" : ",%02d", j);
17701                                         first_pctype = 0;
17702                                 }
17703                         }
17704                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17705                 }
17706         }
17707 #endif
17708 }
17709
17710 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17711         .f = cmd_pctype_mapping_get_parsed,
17712         .data = NULL,
17713         .help_str = "show port <port_id> pctype mapping",
17714         .tokens = {
17715                 (void *)&cmd_pctype_mapping_get_show,
17716                 (void *)&cmd_pctype_mapping_get_port,
17717                 (void *)&cmd_pctype_mapping_get_port_id,
17718                 (void *)&cmd_pctype_mapping_get_pctype,
17719                 (void *)&cmd_pctype_mapping_get_mapping,
17720                 NULL,
17721         },
17722 };
17723
17724 /* port config pctype mapping update */
17725
17726 /* Common result structure for port config pctype mapping update */
17727 struct cmd_pctype_mapping_update_result {
17728         cmdline_fixed_string_t port;
17729         cmdline_fixed_string_t config;
17730         portid_t port_id;
17731         cmdline_fixed_string_t pctype;
17732         cmdline_fixed_string_t mapping;
17733         cmdline_fixed_string_t update;
17734         cmdline_fixed_string_t pctype_list;
17735         uint16_t flow_type;
17736 };
17737
17738 /* Common CLI fields for pctype mapping update*/
17739 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17740         TOKEN_STRING_INITIALIZER
17741                 (struct cmd_pctype_mapping_update_result,
17742                  port, "port");
17743 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17744         TOKEN_STRING_INITIALIZER
17745                 (struct cmd_pctype_mapping_update_result,
17746                  config, "config");
17747 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17748         TOKEN_NUM_INITIALIZER
17749                 (struct cmd_pctype_mapping_update_result,
17750                  port_id, UINT16);
17751 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17752         TOKEN_STRING_INITIALIZER
17753                 (struct cmd_pctype_mapping_update_result,
17754                  pctype, "pctype");
17755 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17756         TOKEN_STRING_INITIALIZER
17757                 (struct cmd_pctype_mapping_update_result,
17758                  mapping, "mapping");
17759 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17760         TOKEN_STRING_INITIALIZER
17761                 (struct cmd_pctype_mapping_update_result,
17762                  update, "update");
17763 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17764         TOKEN_STRING_INITIALIZER
17765                 (struct cmd_pctype_mapping_update_result,
17766                  pctype_list, NULL);
17767 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17768         TOKEN_NUM_INITIALIZER
17769                 (struct cmd_pctype_mapping_update_result,
17770                  flow_type, UINT16);
17771
17772 static void
17773 cmd_pctype_mapping_update_parsed(
17774         void *parsed_result,
17775         __rte_unused struct cmdline *cl,
17776         __rte_unused void *data)
17777 {
17778         struct cmd_pctype_mapping_update_result *res = parsed_result;
17779         int ret = -ENOTSUP;
17780 #ifdef RTE_NET_I40E
17781         struct rte_pmd_i40e_flow_type_mapping mapping;
17782         unsigned int i;
17783         unsigned int nb_item;
17784         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17785 #endif
17786
17787         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17788                 return;
17789
17790 #ifdef RTE_NET_I40E
17791         nb_item = parse_item_list(res->pctype_list, "pctypes",
17792                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17793         mapping.flow_type = res->flow_type;
17794         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17795                 mapping.pctype |= (1ULL << pctype_list[i]);
17796         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17797                                                 &mapping,
17798                                                 1,
17799                                                 0);
17800 #endif
17801
17802         switch (ret) {
17803         case 0:
17804                 break;
17805         case -EINVAL:
17806                 printf("invalid pctype or flow type\n");
17807                 break;
17808         case -ENODEV:
17809                 printf("invalid port_id %d\n", res->port_id);
17810                 break;
17811         case -ENOTSUP:
17812                 printf("function not implemented\n");
17813                 break;
17814         default:
17815                 printf("programming error: (%s)\n", strerror(-ret));
17816         }
17817 }
17818
17819 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17820         .f = cmd_pctype_mapping_update_parsed,
17821         .data = NULL,
17822         .help_str = "port config <port_id> pctype mapping update"
17823         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17824         .tokens = {
17825                 (void *)&cmd_pctype_mapping_update_port,
17826                 (void *)&cmd_pctype_mapping_update_config,
17827                 (void *)&cmd_pctype_mapping_update_port_id,
17828                 (void *)&cmd_pctype_mapping_update_pctype,
17829                 (void *)&cmd_pctype_mapping_update_mapping,
17830                 (void *)&cmd_pctype_mapping_update_update,
17831                 (void *)&cmd_pctype_mapping_update_pc_type,
17832                 (void *)&cmd_pctype_mapping_update_flow_type,
17833                 NULL,
17834         },
17835 };
17836
17837 /* ptype mapping get */
17838
17839 /* Common result structure for ptype mapping get */
17840 struct cmd_ptype_mapping_get_result {
17841         cmdline_fixed_string_t ptype;
17842         cmdline_fixed_string_t mapping;
17843         cmdline_fixed_string_t get;
17844         portid_t port_id;
17845         uint8_t valid_only;
17846 };
17847
17848 /* Common CLI fields for ptype mapping get */
17849 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17850         TOKEN_STRING_INITIALIZER
17851                 (struct cmd_ptype_mapping_get_result,
17852                  ptype, "ptype");
17853 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17854         TOKEN_STRING_INITIALIZER
17855                 (struct cmd_ptype_mapping_get_result,
17856                  mapping, "mapping");
17857 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17858         TOKEN_STRING_INITIALIZER
17859                 (struct cmd_ptype_mapping_get_result,
17860                  get, "get");
17861 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17862         TOKEN_NUM_INITIALIZER
17863                 (struct cmd_ptype_mapping_get_result,
17864                  port_id, UINT16);
17865 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17866         TOKEN_NUM_INITIALIZER
17867                 (struct cmd_ptype_mapping_get_result,
17868                  valid_only, UINT8);
17869
17870 static void
17871 cmd_ptype_mapping_get_parsed(
17872         void *parsed_result,
17873         __rte_unused struct cmdline *cl,
17874         __rte_unused void *data)
17875 {
17876         struct cmd_ptype_mapping_get_result *res = parsed_result;
17877         int ret = -ENOTSUP;
17878 #ifdef RTE_NET_I40E
17879         int max_ptype_num = 256;
17880         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17881         uint16_t count;
17882         int i;
17883 #endif
17884
17885         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17886                 return;
17887
17888 #ifdef RTE_NET_I40E
17889         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17890                                         mapping,
17891                                         max_ptype_num,
17892                                         &count,
17893                                         res->valid_only);
17894 #endif
17895
17896         switch (ret) {
17897         case 0:
17898                 break;
17899         case -ENODEV:
17900                 printf("invalid port_id %d\n", res->port_id);
17901                 break;
17902         case -ENOTSUP:
17903                 printf("function not implemented\n");
17904                 break;
17905         default:
17906                 printf("programming error: (%s)\n", strerror(-ret));
17907         }
17908
17909 #ifdef RTE_NET_I40E
17910         if (!ret) {
17911                 for (i = 0; i < count; i++)
17912                         printf("%3d\t0x%08x\n",
17913                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17914         }
17915 #endif
17916 }
17917
17918 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17919         .f = cmd_ptype_mapping_get_parsed,
17920         .data = NULL,
17921         .help_str = "ptype mapping get <port_id> <valid_only>",
17922         .tokens = {
17923                 (void *)&cmd_ptype_mapping_get_ptype,
17924                 (void *)&cmd_ptype_mapping_get_mapping,
17925                 (void *)&cmd_ptype_mapping_get_get,
17926                 (void *)&cmd_ptype_mapping_get_port_id,
17927                 (void *)&cmd_ptype_mapping_get_valid_only,
17928                 NULL,
17929         },
17930 };
17931
17932 /* ptype mapping replace */
17933
17934 /* Common result structure for ptype mapping replace */
17935 struct cmd_ptype_mapping_replace_result {
17936         cmdline_fixed_string_t ptype;
17937         cmdline_fixed_string_t mapping;
17938         cmdline_fixed_string_t replace;
17939         portid_t port_id;
17940         uint32_t target;
17941         uint8_t mask;
17942         uint32_t pkt_type;
17943 };
17944
17945 /* Common CLI fields for ptype mapping replace */
17946 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17947         TOKEN_STRING_INITIALIZER
17948                 (struct cmd_ptype_mapping_replace_result,
17949                  ptype, "ptype");
17950 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17951         TOKEN_STRING_INITIALIZER
17952                 (struct cmd_ptype_mapping_replace_result,
17953                  mapping, "mapping");
17954 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17955         TOKEN_STRING_INITIALIZER
17956                 (struct cmd_ptype_mapping_replace_result,
17957                  replace, "replace");
17958 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17959         TOKEN_NUM_INITIALIZER
17960                 (struct cmd_ptype_mapping_replace_result,
17961                  port_id, UINT16);
17962 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17963         TOKEN_NUM_INITIALIZER
17964                 (struct cmd_ptype_mapping_replace_result,
17965                  target, UINT32);
17966 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17967         TOKEN_NUM_INITIALIZER
17968                 (struct cmd_ptype_mapping_replace_result,
17969                  mask, UINT8);
17970 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17971         TOKEN_NUM_INITIALIZER
17972                 (struct cmd_ptype_mapping_replace_result,
17973                  pkt_type, UINT32);
17974
17975 static void
17976 cmd_ptype_mapping_replace_parsed(
17977         void *parsed_result,
17978         __rte_unused struct cmdline *cl,
17979         __rte_unused void *data)
17980 {
17981         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17982         int ret = -ENOTSUP;
17983
17984         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17985                 return;
17986
17987 #ifdef RTE_NET_I40E
17988         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17989                                         res->target,
17990                                         res->mask,
17991                                         res->pkt_type);
17992 #endif
17993
17994         switch (ret) {
17995         case 0:
17996                 break;
17997         case -EINVAL:
17998                 printf("invalid ptype 0x%8x or 0x%8x\n",
17999                                 res->target, res->pkt_type);
18000                 break;
18001         case -ENODEV:
18002                 printf("invalid port_id %d\n", res->port_id);
18003                 break;
18004         case -ENOTSUP:
18005                 printf("function not implemented\n");
18006                 break;
18007         default:
18008                 printf("programming error: (%s)\n", strerror(-ret));
18009         }
18010 }
18011
18012 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
18013         .f = cmd_ptype_mapping_replace_parsed,
18014         .data = NULL,
18015         .help_str =
18016                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
18017         .tokens = {
18018                 (void *)&cmd_ptype_mapping_replace_ptype,
18019                 (void *)&cmd_ptype_mapping_replace_mapping,
18020                 (void *)&cmd_ptype_mapping_replace_replace,
18021                 (void *)&cmd_ptype_mapping_replace_port_id,
18022                 (void *)&cmd_ptype_mapping_replace_target,
18023                 (void *)&cmd_ptype_mapping_replace_mask,
18024                 (void *)&cmd_ptype_mapping_replace_pkt_type,
18025                 NULL,
18026         },
18027 };
18028
18029 /* ptype mapping reset */
18030
18031 /* Common result structure for ptype mapping reset */
18032 struct cmd_ptype_mapping_reset_result {
18033         cmdline_fixed_string_t ptype;
18034         cmdline_fixed_string_t mapping;
18035         cmdline_fixed_string_t reset;
18036         portid_t port_id;
18037 };
18038
18039 /* Common CLI fields for ptype mapping reset*/
18040 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
18041         TOKEN_STRING_INITIALIZER
18042                 (struct cmd_ptype_mapping_reset_result,
18043                  ptype, "ptype");
18044 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
18045         TOKEN_STRING_INITIALIZER
18046                 (struct cmd_ptype_mapping_reset_result,
18047                  mapping, "mapping");
18048 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
18049         TOKEN_STRING_INITIALIZER
18050                 (struct cmd_ptype_mapping_reset_result,
18051                  reset, "reset");
18052 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
18053         TOKEN_NUM_INITIALIZER
18054                 (struct cmd_ptype_mapping_reset_result,
18055                  port_id, UINT16);
18056
18057 static void
18058 cmd_ptype_mapping_reset_parsed(
18059         void *parsed_result,
18060         __rte_unused struct cmdline *cl,
18061         __rte_unused void *data)
18062 {
18063         struct cmd_ptype_mapping_reset_result *res = parsed_result;
18064         int ret = -ENOTSUP;
18065
18066         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18067                 return;
18068
18069 #ifdef RTE_NET_I40E
18070         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
18071 #endif
18072
18073         switch (ret) {
18074         case 0:
18075                 break;
18076         case -ENODEV:
18077                 printf("invalid port_id %d\n", res->port_id);
18078                 break;
18079         case -ENOTSUP:
18080                 printf("function not implemented\n");
18081                 break;
18082         default:
18083                 printf("programming error: (%s)\n", strerror(-ret));
18084         }
18085 }
18086
18087 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
18088         .f = cmd_ptype_mapping_reset_parsed,
18089         .data = NULL,
18090         .help_str = "ptype mapping reset <port_id>",
18091         .tokens = {
18092                 (void *)&cmd_ptype_mapping_reset_ptype,
18093                 (void *)&cmd_ptype_mapping_reset_mapping,
18094                 (void *)&cmd_ptype_mapping_reset_reset,
18095                 (void *)&cmd_ptype_mapping_reset_port_id,
18096                 NULL,
18097         },
18098 };
18099
18100 /* ptype mapping update */
18101
18102 /* Common result structure for ptype mapping update */
18103 struct cmd_ptype_mapping_update_result {
18104         cmdline_fixed_string_t ptype;
18105         cmdline_fixed_string_t mapping;
18106         cmdline_fixed_string_t reset;
18107         portid_t port_id;
18108         uint8_t hw_ptype;
18109         uint32_t sw_ptype;
18110 };
18111
18112 /* Common CLI fields for ptype mapping update*/
18113 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
18114         TOKEN_STRING_INITIALIZER
18115                 (struct cmd_ptype_mapping_update_result,
18116                  ptype, "ptype");
18117 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
18118         TOKEN_STRING_INITIALIZER
18119                 (struct cmd_ptype_mapping_update_result,
18120                  mapping, "mapping");
18121 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
18122         TOKEN_STRING_INITIALIZER
18123                 (struct cmd_ptype_mapping_update_result,
18124                  reset, "update");
18125 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
18126         TOKEN_NUM_INITIALIZER
18127                 (struct cmd_ptype_mapping_update_result,
18128                  port_id, UINT16);
18129 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
18130         TOKEN_NUM_INITIALIZER
18131                 (struct cmd_ptype_mapping_update_result,
18132                  hw_ptype, UINT8);
18133 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
18134         TOKEN_NUM_INITIALIZER
18135                 (struct cmd_ptype_mapping_update_result,
18136                  sw_ptype, UINT32);
18137
18138 static void
18139 cmd_ptype_mapping_update_parsed(
18140         void *parsed_result,
18141         __rte_unused struct cmdline *cl,
18142         __rte_unused void *data)
18143 {
18144         struct cmd_ptype_mapping_update_result *res = parsed_result;
18145         int ret = -ENOTSUP;
18146 #ifdef RTE_NET_I40E
18147         struct rte_pmd_i40e_ptype_mapping mapping;
18148 #endif
18149         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18150                 return;
18151
18152 #ifdef RTE_NET_I40E
18153         mapping.hw_ptype = res->hw_ptype;
18154         mapping.sw_ptype = res->sw_ptype;
18155         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
18156                                                 &mapping,
18157                                                 1,
18158                                                 0);
18159 #endif
18160
18161         switch (ret) {
18162         case 0:
18163                 break;
18164         case -EINVAL:
18165                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
18166                 break;
18167         case -ENODEV:
18168                 printf("invalid port_id %d\n", res->port_id);
18169                 break;
18170         case -ENOTSUP:
18171                 printf("function not implemented\n");
18172                 break;
18173         default:
18174                 printf("programming error: (%s)\n", strerror(-ret));
18175         }
18176 }
18177
18178 cmdline_parse_inst_t cmd_ptype_mapping_update = {
18179         .f = cmd_ptype_mapping_update_parsed,
18180         .data = NULL,
18181         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
18182         .tokens = {
18183                 (void *)&cmd_ptype_mapping_update_ptype,
18184                 (void *)&cmd_ptype_mapping_update_mapping,
18185                 (void *)&cmd_ptype_mapping_update_update,
18186                 (void *)&cmd_ptype_mapping_update_port_id,
18187                 (void *)&cmd_ptype_mapping_update_hw_ptype,
18188                 (void *)&cmd_ptype_mapping_update_sw_ptype,
18189                 NULL,
18190         },
18191 };
18192
18193 /* Common result structure for file commands */
18194 struct cmd_cmdfile_result {
18195         cmdline_fixed_string_t load;
18196         cmdline_fixed_string_t filename;
18197 };
18198
18199 /* Common CLI fields for file commands */
18200 cmdline_parse_token_string_t cmd_load_cmdfile =
18201         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18202 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18203         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18204
18205 static void
18206 cmd_load_from_file_parsed(
18207         void *parsed_result,
18208         __rte_unused struct cmdline *cl,
18209         __rte_unused void *data)
18210 {
18211         struct cmd_cmdfile_result *res = parsed_result;
18212
18213         cmdline_read_from_file(res->filename);
18214 }
18215
18216 cmdline_parse_inst_t cmd_load_from_file = {
18217         .f = cmd_load_from_file_parsed,
18218         .data = NULL,
18219         .help_str = "load <filename>",
18220         .tokens = {
18221                 (void *)&cmd_load_cmdfile,
18222                 (void *)&cmd_load_cmdfile_filename,
18223                 NULL,
18224         },
18225 };
18226
18227 /* Get Rx offloads capabilities */
18228 struct cmd_rx_offload_get_capa_result {
18229         cmdline_fixed_string_t show;
18230         cmdline_fixed_string_t port;
18231         portid_t port_id;
18232         cmdline_fixed_string_t rx_offload;
18233         cmdline_fixed_string_t capabilities;
18234 };
18235
18236 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18237         TOKEN_STRING_INITIALIZER
18238                 (struct cmd_rx_offload_get_capa_result,
18239                  show, "show");
18240 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18241         TOKEN_STRING_INITIALIZER
18242                 (struct cmd_rx_offload_get_capa_result,
18243                  port, "port");
18244 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18245         TOKEN_NUM_INITIALIZER
18246                 (struct cmd_rx_offload_get_capa_result,
18247                  port_id, UINT16);
18248 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18249         TOKEN_STRING_INITIALIZER
18250                 (struct cmd_rx_offload_get_capa_result,
18251                  rx_offload, "rx_offload");
18252 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18253         TOKEN_STRING_INITIALIZER
18254                 (struct cmd_rx_offload_get_capa_result,
18255                  capabilities, "capabilities");
18256
18257 static void
18258 print_rx_offloads(uint64_t offloads)
18259 {
18260         uint64_t single_offload;
18261         int begin;
18262         int end;
18263         int bit;
18264
18265         if (offloads == 0)
18266                 return;
18267
18268         begin = __builtin_ctzll(offloads);
18269         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18270
18271         single_offload = 1ULL << begin;
18272         for (bit = begin; bit < end; bit++) {
18273                 if (offloads & single_offload)
18274                         printf(" %s",
18275                                rte_eth_dev_rx_offload_name(single_offload));
18276                 single_offload <<= 1;
18277         }
18278 }
18279
18280 static void
18281 cmd_rx_offload_get_capa_parsed(
18282         void *parsed_result,
18283         __rte_unused struct cmdline *cl,
18284         __rte_unused void *data)
18285 {
18286         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18287         struct rte_eth_dev_info dev_info;
18288         portid_t port_id = res->port_id;
18289         uint64_t queue_offloads;
18290         uint64_t port_offloads;
18291         int ret;
18292
18293         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18294         if (ret != 0)
18295                 return;
18296
18297         queue_offloads = dev_info.rx_queue_offload_capa;
18298         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18299
18300         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18301         printf("  Per Queue :");
18302         print_rx_offloads(queue_offloads);
18303
18304         printf("\n");
18305         printf("  Per Port  :");
18306         print_rx_offloads(port_offloads);
18307         printf("\n\n");
18308 }
18309
18310 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18311         .f = cmd_rx_offload_get_capa_parsed,
18312         .data = NULL,
18313         .help_str = "show port <port_id> rx_offload capabilities",
18314         .tokens = {
18315                 (void *)&cmd_rx_offload_get_capa_show,
18316                 (void *)&cmd_rx_offload_get_capa_port,
18317                 (void *)&cmd_rx_offload_get_capa_port_id,
18318                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18319                 (void *)&cmd_rx_offload_get_capa_capabilities,
18320                 NULL,
18321         }
18322 };
18323
18324 /* Get Rx offloads configuration */
18325 struct cmd_rx_offload_get_configuration_result {
18326         cmdline_fixed_string_t show;
18327         cmdline_fixed_string_t port;
18328         portid_t port_id;
18329         cmdline_fixed_string_t rx_offload;
18330         cmdline_fixed_string_t configuration;
18331 };
18332
18333 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18334         TOKEN_STRING_INITIALIZER
18335                 (struct cmd_rx_offload_get_configuration_result,
18336                  show, "show");
18337 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18338         TOKEN_STRING_INITIALIZER
18339                 (struct cmd_rx_offload_get_configuration_result,
18340                  port, "port");
18341 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18342         TOKEN_NUM_INITIALIZER
18343                 (struct cmd_rx_offload_get_configuration_result,
18344                  port_id, UINT16);
18345 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18346         TOKEN_STRING_INITIALIZER
18347                 (struct cmd_rx_offload_get_configuration_result,
18348                  rx_offload, "rx_offload");
18349 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18350         TOKEN_STRING_INITIALIZER
18351                 (struct cmd_rx_offload_get_configuration_result,
18352                  configuration, "configuration");
18353
18354 static void
18355 cmd_rx_offload_get_configuration_parsed(
18356         void *parsed_result,
18357         __rte_unused struct cmdline *cl,
18358         __rte_unused void *data)
18359 {
18360         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18361         struct rte_eth_dev_info dev_info;
18362         portid_t port_id = res->port_id;
18363         struct rte_port *port = &ports[port_id];
18364         uint64_t port_offloads;
18365         uint64_t queue_offloads;
18366         uint16_t nb_rx_queues;
18367         int q;
18368         int ret;
18369
18370         printf("Rx Offloading Configuration of port %d :\n", port_id);
18371
18372         port_offloads = port->dev_conf.rxmode.offloads;
18373         printf("  Port :");
18374         print_rx_offloads(port_offloads);
18375         printf("\n");
18376
18377         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18378         if (ret != 0)
18379                 return;
18380
18381         nb_rx_queues = dev_info.nb_rx_queues;
18382         for (q = 0; q < nb_rx_queues; q++) {
18383                 queue_offloads = port->rx_conf[q].offloads;
18384                 printf("  Queue[%2d] :", q);
18385                 print_rx_offloads(queue_offloads);
18386                 printf("\n");
18387         }
18388         printf("\n");
18389 }
18390
18391 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18392         .f = cmd_rx_offload_get_configuration_parsed,
18393         .data = NULL,
18394         .help_str = "show port <port_id> rx_offload configuration",
18395         .tokens = {
18396                 (void *)&cmd_rx_offload_get_configuration_show,
18397                 (void *)&cmd_rx_offload_get_configuration_port,
18398                 (void *)&cmd_rx_offload_get_configuration_port_id,
18399                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18400                 (void *)&cmd_rx_offload_get_configuration_configuration,
18401                 NULL,
18402         }
18403 };
18404
18405 /* Enable/Disable a per port offloading */
18406 struct cmd_config_per_port_rx_offload_result {
18407         cmdline_fixed_string_t port;
18408         cmdline_fixed_string_t config;
18409         portid_t port_id;
18410         cmdline_fixed_string_t rx_offload;
18411         cmdline_fixed_string_t offload;
18412         cmdline_fixed_string_t on_off;
18413 };
18414
18415 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18416         TOKEN_STRING_INITIALIZER
18417                 (struct cmd_config_per_port_rx_offload_result,
18418                  port, "port");
18419 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18420         TOKEN_STRING_INITIALIZER
18421                 (struct cmd_config_per_port_rx_offload_result,
18422                  config, "config");
18423 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18424         TOKEN_NUM_INITIALIZER
18425                 (struct cmd_config_per_port_rx_offload_result,
18426                  port_id, UINT16);
18427 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18428         TOKEN_STRING_INITIALIZER
18429                 (struct cmd_config_per_port_rx_offload_result,
18430                  rx_offload, "rx_offload");
18431 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18432         TOKEN_STRING_INITIALIZER
18433                 (struct cmd_config_per_port_rx_offload_result,
18434                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18435                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18436                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18437                            "scatter#buffer_split#timestamp#security#"
18438                            "keep_crc#rss_hash");
18439 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18440         TOKEN_STRING_INITIALIZER
18441                 (struct cmd_config_per_port_rx_offload_result,
18442                  on_off, "on#off");
18443
18444 static uint64_t
18445 search_rx_offload(const char *name)
18446 {
18447         uint64_t single_offload;
18448         const char *single_name;
18449         int found = 0;
18450         unsigned int bit;
18451
18452         single_offload = 1;
18453         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18454                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18455                 if (!strcasecmp(single_name, name)) {
18456                         found = 1;
18457                         break;
18458                 }
18459                 single_offload <<= 1;
18460         }
18461
18462         if (found)
18463                 return single_offload;
18464
18465         return 0;
18466 }
18467
18468 static void
18469 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18470                                 __rte_unused struct cmdline *cl,
18471                                 __rte_unused void *data)
18472 {
18473         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18474         portid_t port_id = res->port_id;
18475         struct rte_eth_dev_info dev_info;
18476         struct rte_port *port = &ports[port_id];
18477         uint64_t single_offload;
18478         uint16_t nb_rx_queues;
18479         int q;
18480         int ret;
18481
18482         if (port->port_status != RTE_PORT_STOPPED) {
18483                 printf("Error: Can't config offload when Port %d "
18484                        "is not stopped\n", port_id);
18485                 return;
18486         }
18487
18488         single_offload = search_rx_offload(res->offload);
18489         if (single_offload == 0) {
18490                 printf("Unknown offload name: %s\n", res->offload);
18491                 return;
18492         }
18493
18494         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18495         if (ret != 0)
18496                 return;
18497
18498         nb_rx_queues = dev_info.nb_rx_queues;
18499         if (!strcmp(res->on_off, "on")) {
18500                 port->dev_conf.rxmode.offloads |= single_offload;
18501                 for (q = 0; q < nb_rx_queues; q++)
18502                         port->rx_conf[q].offloads |= single_offload;
18503         } else {
18504                 port->dev_conf.rxmode.offloads &= ~single_offload;
18505                 for (q = 0; q < nb_rx_queues; q++)
18506                         port->rx_conf[q].offloads &= ~single_offload;
18507         }
18508
18509         cmd_reconfig_device_queue(port_id, 1, 1);
18510 }
18511
18512 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18513         .f = cmd_config_per_port_rx_offload_parsed,
18514         .data = NULL,
18515         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18516                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18517                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18518                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
18519                     "keep_crc|rss_hash on|off",
18520         .tokens = {
18521                 (void *)&cmd_config_per_port_rx_offload_result_port,
18522                 (void *)&cmd_config_per_port_rx_offload_result_config,
18523                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18524                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18525                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18526                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18527                 NULL,
18528         }
18529 };
18530
18531 /* Enable/Disable a per queue offloading */
18532 struct cmd_config_per_queue_rx_offload_result {
18533         cmdline_fixed_string_t port;
18534         portid_t port_id;
18535         cmdline_fixed_string_t rxq;
18536         uint16_t queue_id;
18537         cmdline_fixed_string_t rx_offload;
18538         cmdline_fixed_string_t offload;
18539         cmdline_fixed_string_t on_off;
18540 };
18541
18542 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18543         TOKEN_STRING_INITIALIZER
18544                 (struct cmd_config_per_queue_rx_offload_result,
18545                  port, "port");
18546 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18547         TOKEN_NUM_INITIALIZER
18548                 (struct cmd_config_per_queue_rx_offload_result,
18549                  port_id, UINT16);
18550 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18551         TOKEN_STRING_INITIALIZER
18552                 (struct cmd_config_per_queue_rx_offload_result,
18553                  rxq, "rxq");
18554 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18555         TOKEN_NUM_INITIALIZER
18556                 (struct cmd_config_per_queue_rx_offload_result,
18557                  queue_id, UINT16);
18558 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18559         TOKEN_STRING_INITIALIZER
18560                 (struct cmd_config_per_queue_rx_offload_result,
18561                  rx_offload, "rx_offload");
18562 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18563         TOKEN_STRING_INITIALIZER
18564                 (struct cmd_config_per_queue_rx_offload_result,
18565                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18566                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18567                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18568                            "scatter#buffer_split#timestamp#security#keep_crc");
18569 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18570         TOKEN_STRING_INITIALIZER
18571                 (struct cmd_config_per_queue_rx_offload_result,
18572                  on_off, "on#off");
18573
18574 static void
18575 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18576                                 __rte_unused struct cmdline *cl,
18577                                 __rte_unused void *data)
18578 {
18579         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18580         struct rte_eth_dev_info dev_info;
18581         portid_t port_id = res->port_id;
18582         uint16_t queue_id = res->queue_id;
18583         struct rte_port *port = &ports[port_id];
18584         uint64_t single_offload;
18585         int ret;
18586
18587         if (port->port_status != RTE_PORT_STOPPED) {
18588                 printf("Error: Can't config offload when Port %d "
18589                        "is not stopped\n", port_id);
18590                 return;
18591         }
18592
18593         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18594         if (ret != 0)
18595                 return;
18596
18597         if (queue_id >= dev_info.nb_rx_queues) {
18598                 printf("Error: input queue_id should be 0 ... "
18599                        "%d\n", dev_info.nb_rx_queues - 1);
18600                 return;
18601         }
18602
18603         single_offload = search_rx_offload(res->offload);
18604         if (single_offload == 0) {
18605                 printf("Unknown offload name: %s\n", res->offload);
18606                 return;
18607         }
18608
18609         if (!strcmp(res->on_off, "on"))
18610                 port->rx_conf[queue_id].offloads |= single_offload;
18611         else
18612                 port->rx_conf[queue_id].offloads &= ~single_offload;
18613
18614         cmd_reconfig_device_queue(port_id, 1, 1);
18615 }
18616
18617 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18618         .f = cmd_config_per_queue_rx_offload_parsed,
18619         .data = NULL,
18620         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18621                     "vlan_strip|ipv4_cksum|"
18622                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18623                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18624                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
18625                     "keep_crc on|off",
18626         .tokens = {
18627                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18628                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18629                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18630                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18631                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18632                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18633                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18634                 NULL,
18635         }
18636 };
18637
18638 /* Get Tx offloads capabilities */
18639 struct cmd_tx_offload_get_capa_result {
18640         cmdline_fixed_string_t show;
18641         cmdline_fixed_string_t port;
18642         portid_t port_id;
18643         cmdline_fixed_string_t tx_offload;
18644         cmdline_fixed_string_t capabilities;
18645 };
18646
18647 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18648         TOKEN_STRING_INITIALIZER
18649                 (struct cmd_tx_offload_get_capa_result,
18650                  show, "show");
18651 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18652         TOKEN_STRING_INITIALIZER
18653                 (struct cmd_tx_offload_get_capa_result,
18654                  port, "port");
18655 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18656         TOKEN_NUM_INITIALIZER
18657                 (struct cmd_tx_offload_get_capa_result,
18658                  port_id, UINT16);
18659 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18660         TOKEN_STRING_INITIALIZER
18661                 (struct cmd_tx_offload_get_capa_result,
18662                  tx_offload, "tx_offload");
18663 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18664         TOKEN_STRING_INITIALIZER
18665                 (struct cmd_tx_offload_get_capa_result,
18666                  capabilities, "capabilities");
18667
18668 static void
18669 print_tx_offloads(uint64_t offloads)
18670 {
18671         uint64_t single_offload;
18672         int begin;
18673         int end;
18674         int bit;
18675
18676         if (offloads == 0)
18677                 return;
18678
18679         begin = __builtin_ctzll(offloads);
18680         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18681
18682         single_offload = 1ULL << begin;
18683         for (bit = begin; bit < end; bit++) {
18684                 if (offloads & single_offload)
18685                         printf(" %s",
18686                                rte_eth_dev_tx_offload_name(single_offload));
18687                 single_offload <<= 1;
18688         }
18689 }
18690
18691 static void
18692 cmd_tx_offload_get_capa_parsed(
18693         void *parsed_result,
18694         __rte_unused struct cmdline *cl,
18695         __rte_unused void *data)
18696 {
18697         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18698         struct rte_eth_dev_info dev_info;
18699         portid_t port_id = res->port_id;
18700         uint64_t queue_offloads;
18701         uint64_t port_offloads;
18702         int ret;
18703
18704         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18705         if (ret != 0)
18706                 return;
18707
18708         queue_offloads = dev_info.tx_queue_offload_capa;
18709         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18710
18711         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18712         printf("  Per Queue :");
18713         print_tx_offloads(queue_offloads);
18714
18715         printf("\n");
18716         printf("  Per Port  :");
18717         print_tx_offloads(port_offloads);
18718         printf("\n\n");
18719 }
18720
18721 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18722         .f = cmd_tx_offload_get_capa_parsed,
18723         .data = NULL,
18724         .help_str = "show port <port_id> tx_offload capabilities",
18725         .tokens = {
18726                 (void *)&cmd_tx_offload_get_capa_show,
18727                 (void *)&cmd_tx_offload_get_capa_port,
18728                 (void *)&cmd_tx_offload_get_capa_port_id,
18729                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18730                 (void *)&cmd_tx_offload_get_capa_capabilities,
18731                 NULL,
18732         }
18733 };
18734
18735 /* Get Tx offloads configuration */
18736 struct cmd_tx_offload_get_configuration_result {
18737         cmdline_fixed_string_t show;
18738         cmdline_fixed_string_t port;
18739         portid_t port_id;
18740         cmdline_fixed_string_t tx_offload;
18741         cmdline_fixed_string_t configuration;
18742 };
18743
18744 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18745         TOKEN_STRING_INITIALIZER
18746                 (struct cmd_tx_offload_get_configuration_result,
18747                  show, "show");
18748 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18749         TOKEN_STRING_INITIALIZER
18750                 (struct cmd_tx_offload_get_configuration_result,
18751                  port, "port");
18752 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18753         TOKEN_NUM_INITIALIZER
18754                 (struct cmd_tx_offload_get_configuration_result,
18755                  port_id, UINT16);
18756 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18757         TOKEN_STRING_INITIALIZER
18758                 (struct cmd_tx_offload_get_configuration_result,
18759                  tx_offload, "tx_offload");
18760 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18761         TOKEN_STRING_INITIALIZER
18762                 (struct cmd_tx_offload_get_configuration_result,
18763                  configuration, "configuration");
18764
18765 static void
18766 cmd_tx_offload_get_configuration_parsed(
18767         void *parsed_result,
18768         __rte_unused struct cmdline *cl,
18769         __rte_unused void *data)
18770 {
18771         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18772         struct rte_eth_dev_info dev_info;
18773         portid_t port_id = res->port_id;
18774         struct rte_port *port = &ports[port_id];
18775         uint64_t port_offloads;
18776         uint64_t queue_offloads;
18777         uint16_t nb_tx_queues;
18778         int q;
18779         int ret;
18780
18781         printf("Tx Offloading Configuration of port %d :\n", port_id);
18782
18783         port_offloads = port->dev_conf.txmode.offloads;
18784         printf("  Port :");
18785         print_tx_offloads(port_offloads);
18786         printf("\n");
18787
18788         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18789         if (ret != 0)
18790                 return;
18791
18792         nb_tx_queues = dev_info.nb_tx_queues;
18793         for (q = 0; q < nb_tx_queues; q++) {
18794                 queue_offloads = port->tx_conf[q].offloads;
18795                 printf("  Queue[%2d] :", q);
18796                 print_tx_offloads(queue_offloads);
18797                 printf("\n");
18798         }
18799         printf("\n");
18800 }
18801
18802 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18803         .f = cmd_tx_offload_get_configuration_parsed,
18804         .data = NULL,
18805         .help_str = "show port <port_id> tx_offload configuration",
18806         .tokens = {
18807                 (void *)&cmd_tx_offload_get_configuration_show,
18808                 (void *)&cmd_tx_offload_get_configuration_port,
18809                 (void *)&cmd_tx_offload_get_configuration_port_id,
18810                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18811                 (void *)&cmd_tx_offload_get_configuration_configuration,
18812                 NULL,
18813         }
18814 };
18815
18816 /* Enable/Disable a per port offloading */
18817 struct cmd_config_per_port_tx_offload_result {
18818         cmdline_fixed_string_t port;
18819         cmdline_fixed_string_t config;
18820         portid_t port_id;
18821         cmdline_fixed_string_t tx_offload;
18822         cmdline_fixed_string_t offload;
18823         cmdline_fixed_string_t on_off;
18824 };
18825
18826 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18827         TOKEN_STRING_INITIALIZER
18828                 (struct cmd_config_per_port_tx_offload_result,
18829                  port, "port");
18830 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18831         TOKEN_STRING_INITIALIZER
18832                 (struct cmd_config_per_port_tx_offload_result,
18833                  config, "config");
18834 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18835         TOKEN_NUM_INITIALIZER
18836                 (struct cmd_config_per_port_tx_offload_result,
18837                  port_id, UINT16);
18838 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18839         TOKEN_STRING_INITIALIZER
18840                 (struct cmd_config_per_port_tx_offload_result,
18841                  tx_offload, "tx_offload");
18842 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18843         TOKEN_STRING_INITIALIZER
18844                 (struct cmd_config_per_port_tx_offload_result,
18845                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18846                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18847                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18848                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18849                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18850                           "send_on_timestamp");
18851 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18852         TOKEN_STRING_INITIALIZER
18853                 (struct cmd_config_per_port_tx_offload_result,
18854                  on_off, "on#off");
18855
18856 static uint64_t
18857 search_tx_offload(const char *name)
18858 {
18859         uint64_t single_offload;
18860         const char *single_name;
18861         int found = 0;
18862         unsigned int bit;
18863
18864         single_offload = 1;
18865         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18866                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18867                 if (single_name == NULL)
18868                         break;
18869                 if (!strcasecmp(single_name, name)) {
18870                         found = 1;
18871                         break;
18872                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18873                         break;
18874                 single_offload <<= 1;
18875         }
18876
18877         if (found)
18878                 return single_offload;
18879
18880         return 0;
18881 }
18882
18883 static void
18884 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18885                                 __rte_unused struct cmdline *cl,
18886                                 __rte_unused void *data)
18887 {
18888         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18889         portid_t port_id = res->port_id;
18890         struct rte_eth_dev_info dev_info;
18891         struct rte_port *port = &ports[port_id];
18892         uint64_t single_offload;
18893         uint16_t nb_tx_queues;
18894         int q;
18895         int ret;
18896
18897         if (port->port_status != RTE_PORT_STOPPED) {
18898                 printf("Error: Can't config offload when Port %d "
18899                        "is not stopped\n", port_id);
18900                 return;
18901         }
18902
18903         single_offload = search_tx_offload(res->offload);
18904         if (single_offload == 0) {
18905                 printf("Unknown offload name: %s\n", res->offload);
18906                 return;
18907         }
18908
18909         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18910         if (ret != 0)
18911                 return;
18912
18913         nb_tx_queues = dev_info.nb_tx_queues;
18914         if (!strcmp(res->on_off, "on")) {
18915                 port->dev_conf.txmode.offloads |= single_offload;
18916                 for (q = 0; q < nb_tx_queues; q++)
18917                         port->tx_conf[q].offloads |= single_offload;
18918         } else {
18919                 port->dev_conf.txmode.offloads &= ~single_offload;
18920                 for (q = 0; q < nb_tx_queues; q++)
18921                         port->tx_conf[q].offloads &= ~single_offload;
18922         }
18923
18924         cmd_reconfig_device_queue(port_id, 1, 1);
18925 }
18926
18927 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18928         .f = cmd_config_per_port_tx_offload_parsed,
18929         .data = NULL,
18930         .help_str = "port config <port_id> tx_offload "
18931                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18932                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18933                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18934                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18935                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18936                     "send_on_timestamp on|off",
18937         .tokens = {
18938                 (void *)&cmd_config_per_port_tx_offload_result_port,
18939                 (void *)&cmd_config_per_port_tx_offload_result_config,
18940                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18941                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18942                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18943                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18944                 NULL,
18945         }
18946 };
18947
18948 /* Enable/Disable a per queue offloading */
18949 struct cmd_config_per_queue_tx_offload_result {
18950         cmdline_fixed_string_t port;
18951         portid_t port_id;
18952         cmdline_fixed_string_t txq;
18953         uint16_t queue_id;
18954         cmdline_fixed_string_t tx_offload;
18955         cmdline_fixed_string_t offload;
18956         cmdline_fixed_string_t on_off;
18957 };
18958
18959 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18960         TOKEN_STRING_INITIALIZER
18961                 (struct cmd_config_per_queue_tx_offload_result,
18962                  port, "port");
18963 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18964         TOKEN_NUM_INITIALIZER
18965                 (struct cmd_config_per_queue_tx_offload_result,
18966                  port_id, UINT16);
18967 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18968         TOKEN_STRING_INITIALIZER
18969                 (struct cmd_config_per_queue_tx_offload_result,
18970                  txq, "txq");
18971 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18972         TOKEN_NUM_INITIALIZER
18973                 (struct cmd_config_per_queue_tx_offload_result,
18974                  queue_id, UINT16);
18975 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18976         TOKEN_STRING_INITIALIZER
18977                 (struct cmd_config_per_queue_tx_offload_result,
18978                  tx_offload, "tx_offload");
18979 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18980         TOKEN_STRING_INITIALIZER
18981                 (struct cmd_config_per_queue_tx_offload_result,
18982                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18983                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18984                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18985                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18986                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18987 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18988         TOKEN_STRING_INITIALIZER
18989                 (struct cmd_config_per_queue_tx_offload_result,
18990                  on_off, "on#off");
18991
18992 static void
18993 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18994                                 __rte_unused struct cmdline *cl,
18995                                 __rte_unused void *data)
18996 {
18997         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18998         struct rte_eth_dev_info dev_info;
18999         portid_t port_id = res->port_id;
19000         uint16_t queue_id = res->queue_id;
19001         struct rte_port *port = &ports[port_id];
19002         uint64_t single_offload;
19003         int ret;
19004
19005         if (port->port_status != RTE_PORT_STOPPED) {
19006                 printf("Error: Can't config offload when Port %d "
19007                        "is not stopped\n", port_id);
19008                 return;
19009         }
19010
19011         ret = eth_dev_info_get_print_err(port_id, &dev_info);
19012         if (ret != 0)
19013                 return;
19014
19015         if (queue_id >= dev_info.nb_tx_queues) {
19016                 printf("Error: input queue_id should be 0 ... "
19017                        "%d\n", dev_info.nb_tx_queues - 1);
19018                 return;
19019         }
19020
19021         single_offload = search_tx_offload(res->offload);
19022         if (single_offload == 0) {
19023                 printf("Unknown offload name: %s\n", res->offload);
19024                 return;
19025         }
19026
19027         if (!strcmp(res->on_off, "on"))
19028                 port->tx_conf[queue_id].offloads |= single_offload;
19029         else
19030                 port->tx_conf[queue_id].offloads &= ~single_offload;
19031
19032         cmd_reconfig_device_queue(port_id, 1, 1);
19033 }
19034
19035 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
19036         .f = cmd_config_per_queue_tx_offload_parsed,
19037         .data = NULL,
19038         .help_str = "port <port_id> txq <queue_id> tx_offload "
19039                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
19040                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
19041                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
19042                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
19043                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
19044                     "on|off",
19045         .tokens = {
19046                 (void *)&cmd_config_per_queue_tx_offload_result_port,
19047                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
19048                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
19049                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
19050                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
19051                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
19052                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
19053                 NULL,
19054         }
19055 };
19056
19057 /* *** configure tx_metadata for specific port *** */
19058 struct cmd_config_tx_metadata_specific_result {
19059         cmdline_fixed_string_t port;
19060         cmdline_fixed_string_t keyword;
19061         uint16_t port_id;
19062         cmdline_fixed_string_t item;
19063         uint32_t value;
19064 };
19065
19066 static void
19067 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
19068                                 __rte_unused struct cmdline *cl,
19069                                 __rte_unused void *data)
19070 {
19071         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
19072
19073         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19074                 return;
19075         ports[res->port_id].tx_metadata = res->value;
19076         /* Add/remove callback to insert valid metadata in every Tx packet. */
19077         if (ports[res->port_id].tx_metadata)
19078                 add_tx_md_callback(res->port_id);
19079         else
19080                 remove_tx_md_callback(res->port_id);
19081         rte_flow_dynf_metadata_register();
19082 }
19083
19084 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
19085         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19086                         port, "port");
19087 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
19088         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19089                         keyword, "config");
19090 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
19091         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19092                         port_id, UINT16);
19093 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
19094         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19095                         item, "tx_metadata");
19096 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
19097         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19098                         value, UINT32);
19099
19100 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
19101         .f = cmd_config_tx_metadata_specific_parsed,
19102         .data = NULL,
19103         .help_str = "port config <port_id> tx_metadata <value>",
19104         .tokens = {
19105                 (void *)&cmd_config_tx_metadata_specific_port,
19106                 (void *)&cmd_config_tx_metadata_specific_keyword,
19107                 (void *)&cmd_config_tx_metadata_specific_id,
19108                 (void *)&cmd_config_tx_metadata_specific_item,
19109                 (void *)&cmd_config_tx_metadata_specific_value,
19110                 NULL,
19111         },
19112 };
19113
19114 /* *** set dynf *** */
19115 struct cmd_config_tx_dynf_specific_result {
19116         cmdline_fixed_string_t port;
19117         cmdline_fixed_string_t keyword;
19118         uint16_t port_id;
19119         cmdline_fixed_string_t item;
19120         cmdline_fixed_string_t name;
19121         cmdline_fixed_string_t value;
19122 };
19123
19124 static void
19125 cmd_config_dynf_specific_parsed(void *parsed_result,
19126                                 __rte_unused struct cmdline *cl,
19127                                 __rte_unused void *data)
19128 {
19129         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
19130         struct rte_mbuf_dynflag desc_flag;
19131         int flag;
19132         uint64_t old_port_flags;
19133
19134         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19135                 return;
19136         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
19137         if (flag <= 0) {
19138                 if (strlcpy(desc_flag.name, res->name,
19139                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
19140                         printf("Flag name too long\n");
19141                         return;
19142                 }
19143                 desc_flag.flags = 0;
19144                 flag = rte_mbuf_dynflag_register(&desc_flag);
19145                 if (flag < 0) {
19146                         printf("Can't register flag\n");
19147                         return;
19148                 }
19149                 strcpy(dynf_names[flag], desc_flag.name);
19150         }
19151         old_port_flags = ports[res->port_id].mbuf_dynf;
19152         if (!strcmp(res->value, "set")) {
19153                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
19154                 if (old_port_flags == 0)
19155                         add_tx_dynf_callback(res->port_id);
19156         } else {
19157                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
19158                 if (ports[res->port_id].mbuf_dynf == 0)
19159                         remove_tx_dynf_callback(res->port_id);
19160         }
19161 }
19162
19163 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
19164         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19165                         keyword, "port");
19166 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
19167         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19168                         keyword, "config");
19169 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
19170         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19171                         port_id, UINT16);
19172 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
19173         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19174                         item, "dynf");
19175 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
19176         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19177                         name, NULL);
19178 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
19179         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19180                         value, "set#clear");
19181
19182 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
19183         .f = cmd_config_dynf_specific_parsed,
19184         .data = NULL,
19185         .help_str = "port config <port id> dynf <name> set|clear",
19186         .tokens = {
19187                 (void *)&cmd_config_tx_dynf_specific_port,
19188                 (void *)&cmd_config_tx_dynf_specific_keyword,
19189                 (void *)&cmd_config_tx_dynf_specific_port_id,
19190                 (void *)&cmd_config_tx_dynf_specific_item,
19191                 (void *)&cmd_config_tx_dynf_specific_name,
19192                 (void *)&cmd_config_tx_dynf_specific_value,
19193                 NULL,
19194         },
19195 };
19196
19197 /* *** display tx_metadata per port configuration *** */
19198 struct cmd_show_tx_metadata_result {
19199         cmdline_fixed_string_t cmd_show;
19200         cmdline_fixed_string_t cmd_port;
19201         cmdline_fixed_string_t cmd_keyword;
19202         portid_t cmd_pid;
19203 };
19204
19205 static void
19206 cmd_show_tx_metadata_parsed(void *parsed_result,
19207                 __rte_unused struct cmdline *cl,
19208                 __rte_unused void *data)
19209 {
19210         struct cmd_show_tx_metadata_result *res = parsed_result;
19211
19212         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19213                 printf("invalid port id %u\n", res->cmd_pid);
19214                 return;
19215         }
19216         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19217                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19218                        ports[res->cmd_pid].tx_metadata);
19219         }
19220 }
19221
19222 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19223         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19224                         cmd_show, "show");
19225 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19226         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19227                         cmd_port, "port");
19228 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19229         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19230                         cmd_pid, UINT16);
19231 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19232         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19233                         cmd_keyword, "tx_metadata");
19234
19235 cmdline_parse_inst_t cmd_show_tx_metadata = {
19236         .f = cmd_show_tx_metadata_parsed,
19237         .data = NULL,
19238         .help_str = "show port <port_id> tx_metadata",
19239         .tokens = {
19240                 (void *)&cmd_show_tx_metadata_show,
19241                 (void *)&cmd_show_tx_metadata_port,
19242                 (void *)&cmd_show_tx_metadata_pid,
19243                 (void *)&cmd_show_tx_metadata_keyword,
19244                 NULL,
19245         },
19246 };
19247
19248 /* *** show fec capability per port configuration *** */
19249 struct cmd_show_fec_capability_result {
19250         cmdline_fixed_string_t cmd_show;
19251         cmdline_fixed_string_t cmd_port;
19252         cmdline_fixed_string_t cmd_fec;
19253         cmdline_fixed_string_t cmd_keyword;
19254         portid_t cmd_pid;
19255 };
19256
19257 static void
19258 cmd_show_fec_capability_parsed(void *parsed_result,
19259                 __rte_unused struct cmdline *cl,
19260                 __rte_unused void *data)
19261 {
19262 #define FEC_CAP_NUM 2
19263         struct cmd_show_fec_capability_result *res = parsed_result;
19264         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
19265         unsigned int num = FEC_CAP_NUM;
19266         unsigned int ret_num;
19267         int ret;
19268
19269         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19270                 printf("Invalid port id %u\n", res->cmd_pid);
19271                 return;
19272         }
19273
19274         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
19275         if (ret == -ENOTSUP) {
19276                 printf("Function not implemented\n");
19277                 return;
19278         } else if (ret < 0) {
19279                 printf("Get FEC capability failed\n");
19280                 return;
19281         }
19282
19283         ret_num = (unsigned int)ret;
19284         show_fec_capability(ret_num, speed_fec_capa);
19285 }
19286
19287 cmdline_parse_token_string_t cmd_show_fec_capability_show =
19288         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19289                         cmd_show, "show");
19290 cmdline_parse_token_string_t cmd_show_fec_capability_port =
19291         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19292                         cmd_port, "port");
19293 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
19294         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
19295                         cmd_pid, UINT16);
19296 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
19297         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19298                         cmd_fec, "fec");
19299 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
19300         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19301                         cmd_keyword, "capabilities");
19302
19303 cmdline_parse_inst_t cmd_show_capability = {
19304         .f = cmd_show_fec_capability_parsed,
19305         .data = NULL,
19306         .help_str = "show port <port_id> fec capabilities",
19307         .tokens = {
19308                 (void *)&cmd_show_fec_capability_show,
19309                 (void *)&cmd_show_fec_capability_port,
19310                 (void *)&cmd_show_fec_capability_pid,
19311                 (void *)&cmd_show_fec_capability_fec,
19312                 (void *)&cmd_show_fec_capability_keyword,
19313                 NULL,
19314         },
19315 };
19316
19317 /* *** show fec mode per port configuration *** */
19318 struct cmd_show_fec_metadata_result {
19319         cmdline_fixed_string_t cmd_show;
19320         cmdline_fixed_string_t cmd_port;
19321         cmdline_fixed_string_t cmd_keyword;
19322         portid_t cmd_pid;
19323 };
19324
19325 static void
19326 cmd_show_fec_mode_parsed(void *parsed_result,
19327                 __rte_unused struct cmdline *cl,
19328                 __rte_unused void *data)
19329 {
19330 #define FEC_NAME_SIZE 16
19331         struct cmd_show_fec_metadata_result *res = parsed_result;
19332         uint32_t mode;
19333         char buf[FEC_NAME_SIZE];
19334         int ret;
19335
19336         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19337                 printf("Invalid port id %u\n", res->cmd_pid);
19338                 return;
19339         }
19340         ret = rte_eth_fec_get(res->cmd_pid, &mode);
19341         if (ret == -ENOTSUP) {
19342                 printf("Function not implemented\n");
19343                 return;
19344         } else if (ret < 0) {
19345                 printf("Get FEC mode failed\n");
19346                 return;
19347         }
19348
19349         switch (mode) {
19350         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
19351                 strlcpy(buf, "off", sizeof(buf));
19352                 break;
19353         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
19354                 strlcpy(buf, "auto", sizeof(buf));
19355                 break;
19356         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
19357                 strlcpy(buf, "baser", sizeof(buf));
19358                 break;
19359         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
19360                 strlcpy(buf, "rs", sizeof(buf));
19361                 break;
19362         default:
19363                 return;
19364         }
19365
19366         printf("%s\n", buf);
19367 }
19368
19369 cmdline_parse_token_string_t cmd_show_fec_mode_show =
19370         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19371                         cmd_show, "show");
19372 cmdline_parse_token_string_t cmd_show_fec_mode_port =
19373         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19374                         cmd_port, "port");
19375 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
19376         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
19377                         cmd_pid, UINT16);
19378 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
19379         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19380                         cmd_keyword, "fec_mode");
19381
19382 cmdline_parse_inst_t cmd_show_fec_mode = {
19383         .f = cmd_show_fec_mode_parsed,
19384         .data = NULL,
19385         .help_str = "show port <port_id> fec_mode",
19386         .tokens = {
19387                 (void *)&cmd_show_fec_mode_show,
19388                 (void *)&cmd_show_fec_mode_port,
19389                 (void *)&cmd_show_fec_mode_pid,
19390                 (void *)&cmd_show_fec_mode_keyword,
19391                 NULL,
19392         },
19393 };
19394
19395 /* *** set fec mode per port configuration *** */
19396 struct cmd_set_port_fec_mode {
19397         cmdline_fixed_string_t set;
19398         cmdline_fixed_string_t port;
19399         portid_t port_id;
19400         cmdline_fixed_string_t fec_mode;
19401         cmdline_fixed_string_t fec_value;
19402 };
19403
19404 /* Common CLI fields for set fec mode */
19405 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
19406         TOKEN_STRING_INITIALIZER
19407                 (struct cmd_set_port_fec_mode,
19408                  set, "set");
19409 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
19410         TOKEN_STRING_INITIALIZER
19411                 (struct cmd_set_port_fec_mode,
19412                  port, "port");
19413 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
19414         TOKEN_NUM_INITIALIZER
19415                 (struct cmd_set_port_fec_mode,
19416                  port_id, UINT16);
19417 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
19418         TOKEN_STRING_INITIALIZER
19419                 (struct cmd_set_port_fec_mode,
19420                  fec_mode, "fec_mode");
19421 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
19422         TOKEN_STRING_INITIALIZER
19423                 (struct cmd_set_port_fec_mode,
19424                  fec_value, NULL);
19425
19426 static void
19427 cmd_set_port_fec_mode_parsed(
19428         void *parsed_result,
19429         __rte_unused struct cmdline *cl,
19430         __rte_unused void *data)
19431 {
19432         struct cmd_set_port_fec_mode *res = parsed_result;
19433         uint16_t port_id = res->port_id;
19434         uint32_t mode;
19435         int ret;
19436
19437         ret = parse_fec_mode(res->fec_value, &mode);
19438         if (ret < 0) {
19439                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
19440                         port_id);
19441                 return;
19442         }
19443
19444         ret = rte_eth_fec_set(port_id, mode);
19445         if (ret == -ENOTSUP) {
19446                 printf("Function not implemented\n");
19447                 return;
19448         } else if (ret < 0) {
19449                 printf("Set FEC mode failed\n");
19450                 return;
19451         }
19452 }
19453
19454 cmdline_parse_inst_t cmd_set_fec_mode = {
19455         .f = cmd_set_port_fec_mode_parsed,
19456         .data = NULL,
19457         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
19458         .tokens = {
19459                 (void *)&cmd_set_port_fec_mode_set,
19460                 (void *)&cmd_set_port_fec_mode_port,
19461                 (void *)&cmd_set_port_fec_mode_port_id,
19462                 (void *)&cmd_set_port_fec_mode_str,
19463                 (void *)&cmd_set_port_fec_mode_value,
19464                 NULL,
19465         },
19466 };
19467
19468 /* show port supported ptypes */
19469
19470 /* Common result structure for show port ptypes */
19471 struct cmd_show_port_supported_ptypes_result {
19472         cmdline_fixed_string_t show;
19473         cmdline_fixed_string_t port;
19474         portid_t port_id;
19475         cmdline_fixed_string_t ptypes;
19476 };
19477
19478 /* Common CLI fields for show port ptypes */
19479 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19480         TOKEN_STRING_INITIALIZER
19481                 (struct cmd_show_port_supported_ptypes_result,
19482                  show, "show");
19483 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19484         TOKEN_STRING_INITIALIZER
19485                 (struct cmd_show_port_supported_ptypes_result,
19486                  port, "port");
19487 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19488         TOKEN_NUM_INITIALIZER
19489                 (struct cmd_show_port_supported_ptypes_result,
19490                  port_id, UINT16);
19491 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19492         TOKEN_STRING_INITIALIZER
19493                 (struct cmd_show_port_supported_ptypes_result,
19494                  ptypes, "ptypes");
19495
19496 static void
19497 cmd_show_port_supported_ptypes_parsed(
19498         void *parsed_result,
19499         __rte_unused struct cmdline *cl,
19500         __rte_unused void *data)
19501 {
19502 #define RSVD_PTYPE_MASK       0xf0000000
19503 #define MAX_PTYPES_PER_LAYER  16
19504 #define LTYPE_NAMESIZE        32
19505 #define PTYPE_NAMESIZE        256
19506         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19507         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19508         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19509         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19510         uint16_t port_id = res->port_id;
19511         int ret, i;
19512
19513         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19514         if (ret < 0)
19515                 return;
19516
19517         while (ptype_mask != RSVD_PTYPE_MASK) {
19518
19519                 switch (ptype_mask) {
19520                 case RTE_PTYPE_L2_MASK:
19521                         strlcpy(ltype, "L2", sizeof(ltype));
19522                         break;
19523                 case RTE_PTYPE_L3_MASK:
19524                         strlcpy(ltype, "L3", sizeof(ltype));
19525                         break;
19526                 case RTE_PTYPE_L4_MASK:
19527                         strlcpy(ltype, "L4", sizeof(ltype));
19528                         break;
19529                 case RTE_PTYPE_TUNNEL_MASK:
19530                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19531                         break;
19532                 case RTE_PTYPE_INNER_L2_MASK:
19533                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19534                         break;
19535                 case RTE_PTYPE_INNER_L3_MASK:
19536                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19537                         break;
19538                 case RTE_PTYPE_INNER_L4_MASK:
19539                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19540                         break;
19541                 default:
19542                         return;
19543                 }
19544
19545                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19546                                                        ptype_mask, ptypes,
19547                                                        MAX_PTYPES_PER_LAYER);
19548
19549                 if (ret > 0)
19550                         printf("Supported %s ptypes:\n", ltype);
19551                 else
19552                         printf("%s ptypes unsupported\n", ltype);
19553
19554                 for (i = 0; i < ret; ++i) {
19555                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19556                         printf("%s\n", buf);
19557                 }
19558
19559                 ptype_mask <<= 4;
19560         }
19561 }
19562
19563 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19564         .f = cmd_show_port_supported_ptypes_parsed,
19565         .data = NULL,
19566         .help_str = "show port <port_id> ptypes",
19567         .tokens = {
19568                 (void *)&cmd_show_port_supported_ptypes_show,
19569                 (void *)&cmd_show_port_supported_ptypes_port,
19570                 (void *)&cmd_show_port_supported_ptypes_port_id,
19571                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19572                 NULL,
19573         },
19574 };
19575
19576 /* *** display rx/tx descriptor status *** */
19577 struct cmd_show_rx_tx_desc_status_result {
19578         cmdline_fixed_string_t cmd_show;
19579         cmdline_fixed_string_t cmd_port;
19580         cmdline_fixed_string_t cmd_keyword;
19581         cmdline_fixed_string_t cmd_desc;
19582         cmdline_fixed_string_t cmd_status;
19583         portid_t cmd_pid;
19584         portid_t cmd_qid;
19585         portid_t cmd_did;
19586 };
19587
19588 static void
19589 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19590                 __rte_unused struct cmdline *cl,
19591                 __rte_unused void *data)
19592 {
19593         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19594         int rc;
19595
19596         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19597                 printf("invalid port id %u\n", res->cmd_pid);
19598                 return;
19599         }
19600
19601         if (!strcmp(res->cmd_keyword, "rxq")) {
19602                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19603                                              res->cmd_did);
19604                 if (rc < 0) {
19605                         printf("Invalid queueid = %d\n", res->cmd_qid);
19606                         return;
19607                 }
19608                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19609                         printf("Desc status = AVAILABLE\n");
19610                 else if (rc == RTE_ETH_RX_DESC_DONE)
19611                         printf("Desc status = DONE\n");
19612                 else
19613                         printf("Desc status = UNAVAILABLE\n");
19614         } else if (!strcmp(res->cmd_keyword, "txq")) {
19615                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19616                                              res->cmd_did);
19617                 if (rc < 0) {
19618                         printf("Invalid queueid = %d\n", res->cmd_qid);
19619                         return;
19620                 }
19621                 if (rc == RTE_ETH_TX_DESC_FULL)
19622                         printf("Desc status = FULL\n");
19623                 else if (rc == RTE_ETH_TX_DESC_DONE)
19624                         printf("Desc status = DONE\n");
19625                 else
19626                         printf("Desc status = UNAVAILABLE\n");
19627         }
19628 }
19629
19630 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19631         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19632                         cmd_show, "show");
19633 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19634         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19635                         cmd_port, "port");
19636 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19637         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19638                         cmd_pid, UINT16);
19639 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19640         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19641                         cmd_keyword, "rxq#txq");
19642 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19643         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19644                         cmd_qid, UINT16);
19645 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19646         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19647                         cmd_desc, "desc");
19648 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19649         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19650                         cmd_did, UINT16);
19651 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19652         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19653                         cmd_status, "status");
19654 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19655         .f = cmd_show_rx_tx_desc_status_parsed,
19656         .data = NULL,
19657         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19658                 "status",
19659         .tokens = {
19660                 (void *)&cmd_show_rx_tx_desc_status_show,
19661                 (void *)&cmd_show_rx_tx_desc_status_port,
19662                 (void *)&cmd_show_rx_tx_desc_status_pid,
19663                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19664                 (void *)&cmd_show_rx_tx_desc_status_qid,
19665                 (void *)&cmd_show_rx_tx_desc_status_desc,
19666                 (void *)&cmd_show_rx_tx_desc_status_did,
19667                 (void *)&cmd_show_rx_tx_desc_status_status,
19668                 NULL,
19669         },
19670 };
19671
19672 /* Common result structure for set port ptypes */
19673 struct cmd_set_port_ptypes_result {
19674         cmdline_fixed_string_t set;
19675         cmdline_fixed_string_t port;
19676         portid_t port_id;
19677         cmdline_fixed_string_t ptype_mask;
19678         uint32_t mask;
19679 };
19680
19681 /* Common CLI fields for set port ptypes */
19682 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19683         TOKEN_STRING_INITIALIZER
19684                 (struct cmd_set_port_ptypes_result,
19685                  set, "set");
19686 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19687         TOKEN_STRING_INITIALIZER
19688                 (struct cmd_set_port_ptypes_result,
19689                  port, "port");
19690 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19691         TOKEN_NUM_INITIALIZER
19692                 (struct cmd_set_port_ptypes_result,
19693                  port_id, UINT16);
19694 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19695         TOKEN_STRING_INITIALIZER
19696                 (struct cmd_set_port_ptypes_result,
19697                  ptype_mask, "ptype_mask");
19698 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19699         TOKEN_NUM_INITIALIZER
19700                 (struct cmd_set_port_ptypes_result,
19701                  mask, UINT32);
19702
19703 static void
19704 cmd_set_port_ptypes_parsed(
19705         void *parsed_result,
19706         __rte_unused struct cmdline *cl,
19707         __rte_unused void *data)
19708 {
19709         struct cmd_set_port_ptypes_result *res = parsed_result;
19710 #define PTYPE_NAMESIZE        256
19711         char ptype_name[PTYPE_NAMESIZE];
19712         uint16_t port_id = res->port_id;
19713         uint32_t ptype_mask = res->mask;
19714         int ret, i;
19715
19716         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19717                                                NULL, 0);
19718         if (ret <= 0) {
19719                 printf("Port %d doesn't support any ptypes.\n", port_id);
19720                 return;
19721         }
19722
19723         uint32_t ptypes[ret];
19724
19725         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19726         if (ret < 0) {
19727                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19728                 return;
19729         }
19730
19731         printf("Successfully set following ptypes for Port %d\n", port_id);
19732         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19733                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19734                 printf("%s\n", ptype_name);
19735         }
19736
19737         clear_ptypes = false;
19738 }
19739
19740 cmdline_parse_inst_t cmd_set_port_ptypes = {
19741         .f = cmd_set_port_ptypes_parsed,
19742         .data = NULL,
19743         .help_str = "set port <port_id> ptype_mask <mask>",
19744         .tokens = {
19745                 (void *)&cmd_set_port_ptypes_set,
19746                 (void *)&cmd_set_port_ptypes_port,
19747                 (void *)&cmd_set_port_ptypes_port_id,
19748                 (void *)&cmd_set_port_ptypes_mask_str,
19749                 (void *)&cmd_set_port_ptypes_mask_u32,
19750                 NULL,
19751         },
19752 };
19753
19754 /* *** display mac addresses added to a port *** */
19755 struct cmd_showport_macs_result {
19756         cmdline_fixed_string_t cmd_show;
19757         cmdline_fixed_string_t cmd_port;
19758         cmdline_fixed_string_t cmd_keyword;
19759         portid_t cmd_pid;
19760 };
19761
19762 static void
19763 cmd_showport_macs_parsed(void *parsed_result,
19764                 __rte_unused struct cmdline *cl,
19765                 __rte_unused void *data)
19766 {
19767         struct cmd_showport_macs_result *res = parsed_result;
19768
19769         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19770                 return;
19771
19772         if (!strcmp(res->cmd_keyword, "macs"))
19773                 show_macs(res->cmd_pid);
19774         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19775                 show_mcast_macs(res->cmd_pid);
19776 }
19777
19778 cmdline_parse_token_string_t cmd_showport_macs_show =
19779         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19780                         cmd_show, "show");
19781 cmdline_parse_token_string_t cmd_showport_macs_port =
19782         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19783                         cmd_port, "port");
19784 cmdline_parse_token_num_t cmd_showport_macs_pid =
19785         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19786                         cmd_pid, UINT16);
19787 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19788         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19789                         cmd_keyword, "macs#mcast_macs");
19790
19791 cmdline_parse_inst_t cmd_showport_macs = {
19792         .f = cmd_showport_macs_parsed,
19793         .data = NULL,
19794         .help_str = "show port <port_id> macs|mcast_macs",
19795         .tokens = {
19796                 (void *)&cmd_showport_macs_show,
19797                 (void *)&cmd_showport_macs_port,
19798                 (void *)&cmd_showport_macs_pid,
19799                 (void *)&cmd_showport_macs_keyword,
19800                 NULL,
19801         },
19802 };
19803
19804 /* ******************************************************************************** */
19805
19806 /* list of instructions */
19807 cmdline_parse_ctx_t main_ctx[] = {
19808         (cmdline_parse_inst_t *)&cmd_help_brief,
19809         (cmdline_parse_inst_t *)&cmd_help_long,
19810         (cmdline_parse_inst_t *)&cmd_quit,
19811         (cmdline_parse_inst_t *)&cmd_load_from_file,
19812         (cmdline_parse_inst_t *)&cmd_showport,
19813         (cmdline_parse_inst_t *)&cmd_showqueue,
19814         (cmdline_parse_inst_t *)&cmd_showeeprom,
19815         (cmdline_parse_inst_t *)&cmd_showportall,
19816         (cmdline_parse_inst_t *)&cmd_showdevice,
19817         (cmdline_parse_inst_t *)&cmd_showcfg,
19818         (cmdline_parse_inst_t *)&cmd_showfwdall,
19819         (cmdline_parse_inst_t *)&cmd_start,
19820         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19821         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19822         (cmdline_parse_inst_t *)&cmd_set_link_up,
19823         (cmdline_parse_inst_t *)&cmd_set_link_down,
19824         (cmdline_parse_inst_t *)&cmd_reset,
19825         (cmdline_parse_inst_t *)&cmd_set_numbers,
19826         (cmdline_parse_inst_t *)&cmd_set_log,
19827         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
19828         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
19829         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19830         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19831         (cmdline_parse_inst_t *)&cmd_set_txtimes,
19832         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19833         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19834         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19835         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19836         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19837         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19838         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19839         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19840         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19841         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19842         (cmdline_parse_inst_t *)&cmd_set_link_check,
19843         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19844         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19845         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19846         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19847 #ifdef RTE_NET_BOND
19848         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19849         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19850         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19851         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19852         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19853         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19854         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19855         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19856         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19857         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19858         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19859 #endif
19860         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19861         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19862         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19863         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19864         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19865         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19866         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19867         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19868         (cmdline_parse_inst_t *)&cmd_csum_set,
19869         (cmdline_parse_inst_t *)&cmd_csum_show,
19870         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19871         (cmdline_parse_inst_t *)&cmd_tso_set,
19872         (cmdline_parse_inst_t *)&cmd_tso_show,
19873         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19874         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19875         (cmdline_parse_inst_t *)&cmd_gro_enable,
19876         (cmdline_parse_inst_t *)&cmd_gro_flush,
19877         (cmdline_parse_inst_t *)&cmd_gro_show,
19878         (cmdline_parse_inst_t *)&cmd_gso_enable,
19879         (cmdline_parse_inst_t *)&cmd_gso_size,
19880         (cmdline_parse_inst_t *)&cmd_gso_show,
19881         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19882         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19883         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19884         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19885         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19886         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19887         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19888         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19889         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19890         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19891         (cmdline_parse_inst_t *)&cmd_config_dcb,
19892         (cmdline_parse_inst_t *)&cmd_read_reg,
19893         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19894         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19895         (cmdline_parse_inst_t *)&cmd_write_reg,
19896         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19897         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19898         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19899         (cmdline_parse_inst_t *)&cmd_stop,
19900         (cmdline_parse_inst_t *)&cmd_mac_addr,
19901         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19902         (cmdline_parse_inst_t *)&cmd_set_qmap,
19903         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19904         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
19905         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
19906         (cmdline_parse_inst_t *)&cmd_operate_port,
19907         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19908         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19909         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19910         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19911         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19912         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19913         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19914         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19915         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19916         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19917         (cmdline_parse_inst_t *)&cmd_config_mtu,
19918         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19919         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19920         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19921         (cmdline_parse_inst_t *)&cmd_config_rss,
19922         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19923         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19924         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19925         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19926         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19927         (cmdline_parse_inst_t *)&cmd_showport_reta,
19928         (cmdline_parse_inst_t *)&cmd_showport_macs,
19929         (cmdline_parse_inst_t *)&cmd_config_burst,
19930         (cmdline_parse_inst_t *)&cmd_config_thresh,
19931         (cmdline_parse_inst_t *)&cmd_config_threshold,
19932         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19933         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19934         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19935         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19936         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19937         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19938         (cmdline_parse_inst_t *)&cmd_global_config,
19939         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19940         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19941         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19942         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19943         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19944         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19945         (cmdline_parse_inst_t *)&cmd_dump,
19946         (cmdline_parse_inst_t *)&cmd_dump_one,
19947         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19948         (cmdline_parse_inst_t *)&cmd_syn_filter,
19949         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19950         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19951         (cmdline_parse_inst_t *)&cmd_flex_filter,
19952         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19953         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19954         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19955         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19956         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19957         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19958         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19959         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19960         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19961         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19962         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19963         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19964         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19965         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19966         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19967         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19968         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19969         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19970         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19971         (cmdline_parse_inst_t *)&cmd_flow,
19972         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19973         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19974         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19975         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19976         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19977         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19978         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19979         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19980         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19981         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19982         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19983         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19984         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19985         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19986         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19987         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19988         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19989         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19990         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19991         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19992         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19993         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19994         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19995         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19996         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19997         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19998         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19999         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
20000         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
20001         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
20002         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
20003         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
20004         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
20005         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
20006         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
20007         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
20008         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
20009         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
20010         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
20011         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
20012         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
20013         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
20014         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
20015         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
20016         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
20017         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
20018         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
20019         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
20020         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
20021         (cmdline_parse_inst_t *)&cmd_set_vxlan,
20022         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
20023         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
20024         (cmdline_parse_inst_t *)&cmd_set_nvgre,
20025         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
20026         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
20027         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
20028         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
20029         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
20030         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
20031         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
20032         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
20033         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
20034         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
20035         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
20036         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
20037         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
20038         (cmdline_parse_inst_t *)&cmd_ddp_add,
20039         (cmdline_parse_inst_t *)&cmd_ddp_del,
20040         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
20041         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
20042         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
20043         (cmdline_parse_inst_t *)&cmd_clear_input_set,
20044         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
20045         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
20046         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
20047         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
20048         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
20049         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
20050         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
20051         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
20052
20053         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
20054         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
20055         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
20056         (cmdline_parse_inst_t *)&cmd_queue_region,
20057         (cmdline_parse_inst_t *)&cmd_region_flowtype,
20058         (cmdline_parse_inst_t *)&cmd_user_priority_region,
20059         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
20060         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
20061         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
20062         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
20063         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
20064         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
20065         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
20066         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
20067         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
20068         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
20069         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
20070         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
20071         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
20072         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
20073         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
20074         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
20075         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
20076         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
20077         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
20078         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
20079         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
20080         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
20081         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
20082         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
20083         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
20084         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
20085         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
20086         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
20087         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
20088         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
20089         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
20090         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
20091         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
20092         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
20093 #ifdef RTE_LIB_BPF
20094         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
20095         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
20096 #endif
20097         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
20098         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
20099         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
20100         (cmdline_parse_inst_t *)&cmd_set_raw,
20101         (cmdline_parse_inst_t *)&cmd_show_set_raw,
20102         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
20103         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
20104         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
20105         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
20106         (cmdline_parse_inst_t *)&cmd_show_capability,
20107         NULL,
20108 };
20109
20110 /* read cmdline commands from file */
20111 void
20112 cmdline_read_from_file(const char *filename)
20113 {
20114         struct cmdline *cl;
20115
20116         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
20117         if (cl == NULL) {
20118                 printf("Failed to create file based cmdline context: %s\n",
20119                        filename);
20120                 return;
20121         }
20122
20123         cmdline_interact(cl);
20124         cmdline_quit(cl);
20125
20126         cmdline_free(cl);
20127
20128         printf("Read CLI commands from %s\n", filename);
20129 }
20130
20131 /* prompt function, called from main on MAIN lcore */
20132 void
20133 prompt(void)
20134 {
20135         /* initialize non-constant commands */
20136         cmd_set_fwd_mode_init();
20137         cmd_set_fwd_retry_mode_init();
20138
20139         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
20140         if (testpmd_cl == NULL)
20141                 return;
20142         cmdline_interact(testpmd_cl);
20143         cmdline_stdin_exit(testpmd_cl);
20144 }
20145
20146 void
20147 prompt_exit(void)
20148 {
20149         if (testpmd_cl != NULL)
20150                 cmdline_quit(testpmd_cl);
20151 }
20152
20153 static void
20154 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
20155 {
20156         if (id == (portid_t)RTE_PORT_ALL) {
20157                 portid_t pid;
20158
20159                 RTE_ETH_FOREACH_DEV(pid) {
20160                         /* check if need_reconfig has been set to 1 */
20161                         if (ports[pid].need_reconfig == 0)
20162                                 ports[pid].need_reconfig = dev;
20163                         /* check if need_reconfig_queues has been set to 1 */
20164                         if (ports[pid].need_reconfig_queues == 0)
20165                                 ports[pid].need_reconfig_queues = queue;
20166                 }
20167         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
20168                 /* check if need_reconfig has been set to 1 */
20169                 if (ports[id].need_reconfig == 0)
20170                         ports[id].need_reconfig = dev;
20171                 /* check if need_reconfig_queues has been set to 1 */
20172                 if (ports[id].need_reconfig_queues == 0)
20173                         ports[id].need_reconfig_queues = queue;
20174         }
20175 }