ethdev: remove legacy SYN 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                         "2tuple_filter (port_id) (add|del)"
980                         " dst_port (dst_port_value) protocol (protocol_value)"
981                         " mask (mask_value) tcp_flags (tcp_flags_value)"
982                         " priority (prio_value) queue (queue_id)\n"
983                         "    Add/Del a 2tuple filter.\n\n"
984
985                         "5tuple_filter (port_id) (add|del)"
986                         " dst_ip (dst_address) src_ip (src_address)"
987                         " dst_port (dst_port_value) src_port (src_port_value)"
988                         " protocol (protocol_value)"
989                         " mask (mask_value) tcp_flags (tcp_flags_value)"
990                         " priority (prio_value) queue (queue_id)\n"
991                         "    Add/Del a 5tuple filter.\n\n"
992
993                         "flow_director_filter (port_id) mode IP (add|del|update)"
994                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
995                         " src (src_ip_address) dst (dst_ip_address)"
996                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
997                         " vlan (vlan_value) flexbytes (flexbytes_value)"
998                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
999                         " fd_id (fd_id_value)\n"
1000                         "    Add/Del an IP type flow director filter.\n\n"
1001
1002                         "flow_director_filter (port_id) mode IP (add|del|update)"
1003                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
1004                         " src (src_ip_address) (src_port)"
1005                         " dst (dst_ip_address) (dst_port)"
1006                         " tos (tos_value) ttl (ttl_value)"
1007                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1008                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1009                         " fd_id (fd_id_value)\n"
1010                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1011
1012                         "flow_director_filter (port_id) mode IP (add|del|update)"
1013                         " flow (ipv4-sctp|ipv6-sctp)"
1014                         " src (src_ip_address) (src_port)"
1015                         " dst (dst_ip_address) (dst_port)"
1016                         " tag (verification_tag) "
1017                         " tos (tos_value) ttl (ttl_value)"
1018                         " vlan (vlan_value)"
1019                         " flexbytes (flexbytes_value) (drop|fwd)"
1020                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1021                         "    Add/Del a SCTP type flow director filter.\n\n"
1022
1023                         "flow_director_filter (port_id) mode IP (add|del|update)"
1024                         " flow l2_payload ether (ethertype)"
1025                         " flexbytes (flexbytes_value) (drop|fwd)"
1026                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1027                         "    Add/Del a l2 payload type flow director filter.\n\n"
1028
1029                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1030                         " mac (mac_address) vlan (vlan_value)"
1031                         " flexbytes (flexbytes_value) (drop|fwd)"
1032                         " queue (queue_id) fd_id (fd_id_value)\n"
1033                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1034
1035                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1036                         " mac (mac_address) vlan (vlan_value)"
1037                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1038                         " flexbytes (flexbytes_value) (drop|fwd)"
1039                         " queue (queue_id) fd_id (fd_id_value)\n"
1040                         "    Add/Del a Tunnel flow director filter.\n\n"
1041
1042                         "flow_director_filter (port_id) mode raw (add|del|update)"
1043                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1044                         " fd_id (fd_id_value) packet (packet file name)\n"
1045                         "    Add/Del a raw type flow director filter.\n\n"
1046
1047                         "flush_flow_director (port_id)\n"
1048                         "    Flush all flow director entries of a device.\n\n"
1049
1050                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1051                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1052                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1053                         "    Set flow director IP mask.\n\n"
1054
1055                         "flow_director_mask (port_id) mode MAC-VLAN"
1056                         " vlan (vlan_value)\n"
1057                         "    Set flow director MAC-VLAN mask.\n\n"
1058
1059                         "flow_director_mask (port_id) mode Tunnel"
1060                         " vlan (vlan_value) mac (mac_value)"
1061                         " tunnel-type (tunnel_type_value)"
1062                         " tunnel-id (tunnel_id_value)\n"
1063                         "    Set flow director Tunnel mask.\n\n"
1064
1065                         "flow_director_flex_mask (port_id)"
1066                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1067                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1068                         " (mask)\n"
1069                         "    Configure mask of flex payload.\n\n"
1070
1071                         "flow_director_flex_payload (port_id)"
1072                         " (raw|l2|l3|l4) (config)\n"
1073                         "    Configure flex payload selection.\n\n"
1074
1075                         "get_sym_hash_ena_per_port (port_id)\n"
1076                         "    get symmetric hash enable configuration per port.\n\n"
1077
1078                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1079                         "    set symmetric hash enable configuration per port"
1080                         " to enable or disable.\n\n"
1081
1082                         "get_hash_global_config (port_id)\n"
1083                         "    Get the global configurations of hash filters.\n\n"
1084
1085                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1086                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1087                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1088                         " (enable|disable)\n"
1089                         "    Set the global configurations of hash filters.\n\n"
1090
1091                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1092                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1093                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1094                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1095                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1096                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1097                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1098                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1099                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1100                         "fld-8th|none) (select|add)\n"
1101                         "    Set the input set for hash.\n\n"
1102
1103                         "set_fdir_input_set (port_id) "
1104                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1105                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1106                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1107                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1108                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1109                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1110                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1111                         " (select|add)\n"
1112                         "    Set the input set for FDir.\n\n"
1113
1114                         "flow validate {port_id}"
1115                         " [group {group_id}] [priority {level}]"
1116                         " [ingress] [egress]"
1117                         " pattern {item} [/ {item} [...]] / end"
1118                         " actions {action} [/ {action} [...]] / end\n"
1119                         "    Check whether a flow rule can be created.\n\n"
1120
1121                         "flow create {port_id}"
1122                         " [group {group_id}] [priority {level}]"
1123                         " [ingress] [egress]"
1124                         " pattern {item} [/ {item} [...]] / end"
1125                         " actions {action} [/ {action} [...]] / end\n"
1126                         "    Create a flow rule.\n\n"
1127
1128                         "flow destroy {port_id} rule {rule_id} [...]\n"
1129                         "    Destroy specific flow rules.\n\n"
1130
1131                         "flow flush {port_id}\n"
1132                         "    Destroy all flow rules.\n\n"
1133
1134                         "flow query {port_id} {rule_id} {action}\n"
1135                         "    Query an existing flow rule.\n\n"
1136
1137                         "flow list {port_id} [group {group_id}] [...]\n"
1138                         "    List existing flow rules sorted by priority,"
1139                         " filtered by group identifiers.\n\n"
1140
1141                         "flow isolate {port_id} {boolean}\n"
1142                         "    Restrict ingress traffic to the defined"
1143                         " flow rules\n\n"
1144
1145                         "flow aged {port_id} [destroy]\n"
1146                         "    List and destroy aged flows"
1147                         " flow rules\n\n"
1148
1149                         "flow shared_action {port_id} create"
1150                         " [action_id {shared_action_id}]"
1151                         " [ingress] [egress]"
1152                         " action {action} / end\n"
1153                         "    Create shared action.\n\n"
1154
1155                         "flow shared_action {port_id} update"
1156                         " {shared_action_id} action {action} / end\n"
1157                         "    Update shared action.\n\n"
1158
1159                         "flow shared_action {port_id} destroy"
1160                         " action_id {shared_action_id} [...]\n"
1161                         "    Destroy specific shared actions.\n\n"
1162
1163                         "flow shared_action {port_id} query"
1164                         " {shared_action_id}\n"
1165                         "    Query an existing shared action.\n\n"
1166
1167                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1168                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1169                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1170                         "       Configure the VXLAN encapsulation for flows.\n\n"
1171
1172                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1173                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1174                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1175                         " eth-dst (eth-dst)\n"
1176                         "       Configure the VXLAN encapsulation for flows.\n\n"
1177
1178                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1179                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1180                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1181                         " eth-dst (eth-dst)\n"
1182                         "       Configure the VXLAN encapsulation for flows.\n\n"
1183
1184                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1185                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1186                         " (eth-dst)\n"
1187                         "       Configure the NVGRE encapsulation for flows.\n\n"
1188
1189                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1190                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1191                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1192                         "       Configure the NVGRE encapsulation for flows.\n\n"
1193
1194                         "set raw_encap {flow items}\n"
1195                         "       Configure the encapsulation with raw data.\n\n"
1196
1197                         "set raw_decap {flow items}\n"
1198                         "       Configure the decapsulation with raw data.\n\n"
1199
1200                 );
1201         }
1202
1203         if (show_all || !strcmp(res->section, "traffic_management")) {
1204                 cmdline_printf(
1205                         cl,
1206                         "\n"
1207                         "Traffic Management:\n"
1208                         "--------------\n"
1209                         "show port tm cap (port_id)\n"
1210                         "       Display the port TM capability.\n\n"
1211
1212                         "show port tm level cap (port_id) (level_id)\n"
1213                         "       Display the port TM hierarchical level capability.\n\n"
1214
1215                         "show port tm node cap (port_id) (node_id)\n"
1216                         "       Display the port TM node capability.\n\n"
1217
1218                         "show port tm node type (port_id) (node_id)\n"
1219                         "       Display the port TM node type.\n\n"
1220
1221                         "show port tm node stats (port_id) (node_id) (clear)\n"
1222                         "       Display the port TM node stats.\n\n"
1223
1224                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1225                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1226                         " (packet_length_adjust) (packet_mode)\n"
1227                         "       Add port tm node private shaper profile.\n\n"
1228
1229                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1230                         "       Delete port tm node private shaper profile.\n\n"
1231
1232                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1233                         " (shaper_profile_id)\n"
1234                         "       Add/update port tm node shared shaper.\n\n"
1235
1236                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1237                         "       Delete port tm node shared shaper.\n\n"
1238
1239                         "set port tm node shaper profile (port_id) (node_id)"
1240                         " (shaper_profile_id)\n"
1241                         "       Set port tm node shaper profile.\n\n"
1242
1243                         "add port tm node wred profile (port_id) (wred_profile_id)"
1244                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1245                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1246                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1247                         "       Add port tm node wred profile.\n\n"
1248
1249                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1250                         "       Delete port tm node wred profile.\n\n"
1251
1252                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1253                         " (priority) (weight) (level_id) (shaper_profile_id)"
1254                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1255                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1256                         "       Add port tm nonleaf node.\n\n"
1257
1258                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1259                         " (priority) (weight) (level_id) (shaper_profile_id)"
1260                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1261                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1262                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1263
1264                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1265                         " (priority) (weight) (level_id) (shaper_profile_id)"
1266                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1267                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1268                         "       Add port tm leaf node.\n\n"
1269
1270                         "del port tm node (port_id) (node_id)\n"
1271                         "       Delete port tm node.\n\n"
1272
1273                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1274                         " (priority) (weight)\n"
1275                         "       Set port tm node parent.\n\n"
1276
1277                         "suspend port tm node (port_id) (node_id)"
1278                         "       Suspend tm node.\n\n"
1279
1280                         "resume port tm node (port_id) (node_id)"
1281                         "       Resume tm node.\n\n"
1282
1283                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1284                         "       Commit tm hierarchy.\n\n"
1285
1286                         "set port tm mark ip_ecn (port) (green) (yellow)"
1287                         " (red)\n"
1288                         "    Enables/Disables the traffic management marking"
1289                         " for IP ECN (Explicit Congestion Notification)"
1290                         " packets on a given port\n\n"
1291
1292                         "set port tm mark ip_dscp (port) (green) (yellow)"
1293                         " (red)\n"
1294                         "    Enables/Disables the traffic management marking"
1295                         " on the port for IP dscp packets\n\n"
1296
1297                         "set port tm mark vlan_dei (port) (green) (yellow)"
1298                         " (red)\n"
1299                         "    Enables/Disables the traffic management marking"
1300                         " on the port for VLAN packets with DEI enabled\n\n"
1301                 );
1302         }
1303
1304         if (show_all || !strcmp(res->section, "devices")) {
1305                 cmdline_printf(
1306                         cl,
1307                         "\n"
1308                         "Device Operations:\n"
1309                         "--------------\n"
1310                         "device detach (identifier)\n"
1311                         "       Detach device by identifier.\n\n"
1312                 );
1313         }
1314
1315 }
1316
1317 cmdline_parse_token_string_t cmd_help_long_help =
1318         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1319
1320 cmdline_parse_token_string_t cmd_help_long_section =
1321         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1322                         "all#control#display#config#"
1323                         "ports#registers#filters#traffic_management#devices");
1324
1325 cmdline_parse_inst_t cmd_help_long = {
1326         .f = cmd_help_long_parsed,
1327         .data = NULL,
1328         .help_str = "help all|control|display|config|ports|register|"
1329                 "filters|traffic_management|devices: "
1330                 "Show help",
1331         .tokens = {
1332                 (void *)&cmd_help_long_help,
1333                 (void *)&cmd_help_long_section,
1334                 NULL,
1335         },
1336 };
1337
1338
1339 /* *** start/stop/close all ports *** */
1340 struct cmd_operate_port_result {
1341         cmdline_fixed_string_t keyword;
1342         cmdline_fixed_string_t name;
1343         cmdline_fixed_string_t value;
1344 };
1345
1346 static void cmd_operate_port_parsed(void *parsed_result,
1347                                 __rte_unused struct cmdline *cl,
1348                                 __rte_unused void *data)
1349 {
1350         struct cmd_operate_port_result *res = parsed_result;
1351
1352         if (!strcmp(res->name, "start"))
1353                 start_port(RTE_PORT_ALL);
1354         else if (!strcmp(res->name, "stop"))
1355                 stop_port(RTE_PORT_ALL);
1356         else if (!strcmp(res->name, "close"))
1357                 close_port(RTE_PORT_ALL);
1358         else if (!strcmp(res->name, "reset"))
1359                 reset_port(RTE_PORT_ALL);
1360         else
1361                 printf("Unknown parameter\n");
1362 }
1363
1364 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1365         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1366                                                                 "port");
1367 cmdline_parse_token_string_t cmd_operate_port_all_port =
1368         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1369                                                 "start#stop#close#reset");
1370 cmdline_parse_token_string_t cmd_operate_port_all_all =
1371         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1372
1373 cmdline_parse_inst_t cmd_operate_port = {
1374         .f = cmd_operate_port_parsed,
1375         .data = NULL,
1376         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1377         .tokens = {
1378                 (void *)&cmd_operate_port_all_cmd,
1379                 (void *)&cmd_operate_port_all_port,
1380                 (void *)&cmd_operate_port_all_all,
1381                 NULL,
1382         },
1383 };
1384
1385 /* *** start/stop/close specific port *** */
1386 struct cmd_operate_specific_port_result {
1387         cmdline_fixed_string_t keyword;
1388         cmdline_fixed_string_t name;
1389         uint8_t value;
1390 };
1391
1392 static void cmd_operate_specific_port_parsed(void *parsed_result,
1393                         __rte_unused struct cmdline *cl,
1394                                 __rte_unused void *data)
1395 {
1396         struct cmd_operate_specific_port_result *res = parsed_result;
1397
1398         if (!strcmp(res->name, "start"))
1399                 start_port(res->value);
1400         else if (!strcmp(res->name, "stop"))
1401                 stop_port(res->value);
1402         else if (!strcmp(res->name, "close"))
1403                 close_port(res->value);
1404         else if (!strcmp(res->name, "reset"))
1405                 reset_port(res->value);
1406         else
1407                 printf("Unknown parameter\n");
1408 }
1409
1410 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1411         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1412                                                         keyword, "port");
1413 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1414         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1415                                                 name, "start#stop#close#reset");
1416 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1417         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1418                                                         value, UINT8);
1419
1420 cmdline_parse_inst_t cmd_operate_specific_port = {
1421         .f = cmd_operate_specific_port_parsed,
1422         .data = NULL,
1423         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1424         .tokens = {
1425                 (void *)&cmd_operate_specific_port_cmd,
1426                 (void *)&cmd_operate_specific_port_port,
1427                 (void *)&cmd_operate_specific_port_id,
1428                 NULL,
1429         },
1430 };
1431
1432 /* *** enable port setup (after attach) via iterator or event *** */
1433 struct cmd_set_port_setup_on_result {
1434         cmdline_fixed_string_t set;
1435         cmdline_fixed_string_t port;
1436         cmdline_fixed_string_t setup;
1437         cmdline_fixed_string_t on;
1438         cmdline_fixed_string_t mode;
1439 };
1440
1441 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1442                                 __rte_unused struct cmdline *cl,
1443                                 __rte_unused void *data)
1444 {
1445         struct cmd_set_port_setup_on_result *res = parsed_result;
1446
1447         if (strcmp(res->mode, "event") == 0)
1448                 setup_on_probe_event = true;
1449         else if (strcmp(res->mode, "iterator") == 0)
1450                 setup_on_probe_event = false;
1451         else
1452                 printf("Unknown mode\n");
1453 }
1454
1455 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1456         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1457                         set, "set");
1458 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1459         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1460                         port, "port");
1461 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1462         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1463                         setup, "setup");
1464 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1465         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1466                         on, "on");
1467 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1468         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1469                         mode, "iterator#event");
1470
1471 cmdline_parse_inst_t cmd_set_port_setup_on = {
1472         .f = cmd_set_port_setup_on_parsed,
1473         .data = NULL,
1474         .help_str = "set port setup on iterator|event",
1475         .tokens = {
1476                 (void *)&cmd_set_port_setup_on_set,
1477                 (void *)&cmd_set_port_setup_on_port,
1478                 (void *)&cmd_set_port_setup_on_setup,
1479                 (void *)&cmd_set_port_setup_on_on,
1480                 (void *)&cmd_set_port_setup_on_mode,
1481                 NULL,
1482         },
1483 };
1484
1485 /* *** attach a specified port *** */
1486 struct cmd_operate_attach_port_result {
1487         cmdline_fixed_string_t port;
1488         cmdline_fixed_string_t keyword;
1489         cmdline_multi_string_t identifier;
1490 };
1491
1492 static void cmd_operate_attach_port_parsed(void *parsed_result,
1493                                 __rte_unused struct cmdline *cl,
1494                                 __rte_unused void *data)
1495 {
1496         struct cmd_operate_attach_port_result *res = parsed_result;
1497
1498         if (!strcmp(res->keyword, "attach"))
1499                 attach_port(res->identifier);
1500         else
1501                 printf("Unknown parameter\n");
1502 }
1503
1504 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1505         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1506                         port, "port");
1507 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1508         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1509                         keyword, "attach");
1510 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1511         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1512                         identifier, TOKEN_STRING_MULTI);
1513
1514 cmdline_parse_inst_t cmd_operate_attach_port = {
1515         .f = cmd_operate_attach_port_parsed,
1516         .data = NULL,
1517         .help_str = "port attach <identifier>: "
1518                 "(identifier: pci address or virtual dev name)",
1519         .tokens = {
1520                 (void *)&cmd_operate_attach_port_port,
1521                 (void *)&cmd_operate_attach_port_keyword,
1522                 (void *)&cmd_operate_attach_port_identifier,
1523                 NULL,
1524         },
1525 };
1526
1527 /* *** detach a specified port *** */
1528 struct cmd_operate_detach_port_result {
1529         cmdline_fixed_string_t port;
1530         cmdline_fixed_string_t keyword;
1531         portid_t port_id;
1532 };
1533
1534 static void cmd_operate_detach_port_parsed(void *parsed_result,
1535                                 __rte_unused struct cmdline *cl,
1536                                 __rte_unused void *data)
1537 {
1538         struct cmd_operate_detach_port_result *res = parsed_result;
1539
1540         if (!strcmp(res->keyword, "detach")) {
1541                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1542                 detach_port_device(res->port_id);
1543         } else {
1544                 printf("Unknown parameter\n");
1545         }
1546 }
1547
1548 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1549         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1550                         port, "port");
1551 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1552         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1553                         keyword, "detach");
1554 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1555         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1556                         port_id, UINT16);
1557
1558 cmdline_parse_inst_t cmd_operate_detach_port = {
1559         .f = cmd_operate_detach_port_parsed,
1560         .data = NULL,
1561         .help_str = "port detach <port_id>",
1562         .tokens = {
1563                 (void *)&cmd_operate_detach_port_port,
1564                 (void *)&cmd_operate_detach_port_keyword,
1565                 (void *)&cmd_operate_detach_port_port_id,
1566                 NULL,
1567         },
1568 };
1569
1570 /* *** detach device by identifier *** */
1571 struct cmd_operate_detach_device_result {
1572         cmdline_fixed_string_t device;
1573         cmdline_fixed_string_t keyword;
1574         cmdline_fixed_string_t identifier;
1575 };
1576
1577 static void cmd_operate_detach_device_parsed(void *parsed_result,
1578                                 __rte_unused struct cmdline *cl,
1579                                 __rte_unused void *data)
1580 {
1581         struct cmd_operate_detach_device_result *res = parsed_result;
1582
1583         if (!strcmp(res->keyword, "detach"))
1584                 detach_devargs(res->identifier);
1585         else
1586                 printf("Unknown parameter\n");
1587 }
1588
1589 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1590         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1591                         device, "device");
1592 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1593         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1594                         keyword, "detach");
1595 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1596         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1597                         identifier, NULL);
1598
1599 cmdline_parse_inst_t cmd_operate_detach_device = {
1600         .f = cmd_operate_detach_device_parsed,
1601         .data = NULL,
1602         .help_str = "device detach <identifier>:"
1603                 "(identifier: pci address or virtual dev name)",
1604         .tokens = {
1605                 (void *)&cmd_operate_detach_device_device,
1606                 (void *)&cmd_operate_detach_device_keyword,
1607                 (void *)&cmd_operate_detach_device_identifier,
1608                 NULL,
1609         },
1610 };
1611 /* *** configure speed for all ports *** */
1612 struct cmd_config_speed_all {
1613         cmdline_fixed_string_t port;
1614         cmdline_fixed_string_t keyword;
1615         cmdline_fixed_string_t all;
1616         cmdline_fixed_string_t item1;
1617         cmdline_fixed_string_t item2;
1618         cmdline_fixed_string_t value1;
1619         cmdline_fixed_string_t value2;
1620 };
1621
1622 static int
1623 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1624 {
1625
1626         int duplex;
1627
1628         if (!strcmp(duplexstr, "half")) {
1629                 duplex = ETH_LINK_HALF_DUPLEX;
1630         } else if (!strcmp(duplexstr, "full")) {
1631                 duplex = ETH_LINK_FULL_DUPLEX;
1632         } else if (!strcmp(duplexstr, "auto")) {
1633                 duplex = ETH_LINK_FULL_DUPLEX;
1634         } else {
1635                 printf("Unknown duplex parameter\n");
1636                 return -1;
1637         }
1638
1639         if (!strcmp(speedstr, "10")) {
1640                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1641                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1642         } else if (!strcmp(speedstr, "100")) {
1643                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1644                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1645         } else {
1646                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1647                         printf("Invalid speed/duplex parameters\n");
1648                         return -1;
1649                 }
1650                 if (!strcmp(speedstr, "1000")) {
1651                         *speed = ETH_LINK_SPEED_1G;
1652                 } else if (!strcmp(speedstr, "10000")) {
1653                         *speed = ETH_LINK_SPEED_10G;
1654                 } else if (!strcmp(speedstr, "25000")) {
1655                         *speed = ETH_LINK_SPEED_25G;
1656                 } else if (!strcmp(speedstr, "40000")) {
1657                         *speed = ETH_LINK_SPEED_40G;
1658                 } else if (!strcmp(speedstr, "50000")) {
1659                         *speed = ETH_LINK_SPEED_50G;
1660                 } else if (!strcmp(speedstr, "100000")) {
1661                         *speed = ETH_LINK_SPEED_100G;
1662                 } else if (!strcmp(speedstr, "200000")) {
1663                         *speed = ETH_LINK_SPEED_200G;
1664                 } else if (!strcmp(speedstr, "auto")) {
1665                         *speed = ETH_LINK_SPEED_AUTONEG;
1666                 } else {
1667                         printf("Unknown speed parameter\n");
1668                         return -1;
1669                 }
1670         }
1671
1672         return 0;
1673 }
1674
1675 static void
1676 cmd_config_speed_all_parsed(void *parsed_result,
1677                         __rte_unused struct cmdline *cl,
1678                         __rte_unused void *data)
1679 {
1680         struct cmd_config_speed_all *res = parsed_result;
1681         uint32_t link_speed;
1682         portid_t pid;
1683
1684         if (!all_ports_stopped()) {
1685                 printf("Please stop all ports first\n");
1686                 return;
1687         }
1688
1689         if (parse_and_check_speed_duplex(res->value1, res->value2,
1690                         &link_speed) < 0)
1691                 return;
1692
1693         RTE_ETH_FOREACH_DEV(pid) {
1694                 ports[pid].dev_conf.link_speeds = link_speed;
1695         }
1696
1697         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1698 }
1699
1700 cmdline_parse_token_string_t cmd_config_speed_all_port =
1701         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1702 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1703         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1704                                                         "config");
1705 cmdline_parse_token_string_t cmd_config_speed_all_all =
1706         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1707 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1708         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1709 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1710         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1711                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1712 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1713         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1714 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1715         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1716                                                 "half#full#auto");
1717
1718 cmdline_parse_inst_t cmd_config_speed_all = {
1719         .f = cmd_config_speed_all_parsed,
1720         .data = NULL,
1721         .help_str = "port config all speed "
1722                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1723                                                         "half|full|auto",
1724         .tokens = {
1725                 (void *)&cmd_config_speed_all_port,
1726                 (void *)&cmd_config_speed_all_keyword,
1727                 (void *)&cmd_config_speed_all_all,
1728                 (void *)&cmd_config_speed_all_item1,
1729                 (void *)&cmd_config_speed_all_value1,
1730                 (void *)&cmd_config_speed_all_item2,
1731                 (void *)&cmd_config_speed_all_value2,
1732                 NULL,
1733         },
1734 };
1735
1736 /* *** configure speed for specific port *** */
1737 struct cmd_config_speed_specific {
1738         cmdline_fixed_string_t port;
1739         cmdline_fixed_string_t keyword;
1740         portid_t id;
1741         cmdline_fixed_string_t item1;
1742         cmdline_fixed_string_t item2;
1743         cmdline_fixed_string_t value1;
1744         cmdline_fixed_string_t value2;
1745 };
1746
1747 static void
1748 cmd_config_speed_specific_parsed(void *parsed_result,
1749                                 __rte_unused struct cmdline *cl,
1750                                 __rte_unused void *data)
1751 {
1752         struct cmd_config_speed_specific *res = parsed_result;
1753         uint32_t link_speed;
1754
1755         if (!all_ports_stopped()) {
1756                 printf("Please stop all ports first\n");
1757                 return;
1758         }
1759
1760         if (port_id_is_invalid(res->id, ENABLED_WARN))
1761                 return;
1762
1763         if (parse_and_check_speed_duplex(res->value1, res->value2,
1764                         &link_speed) < 0)
1765                 return;
1766
1767         ports[res->id].dev_conf.link_speeds = link_speed;
1768
1769         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1770 }
1771
1772
1773 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1774         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1775                                                                 "port");
1776 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1777         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1778                                                                 "config");
1779 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1780         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1781 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1782         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1783                                                                 "speed");
1784 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1785         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1786                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1787 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1788         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1789                                                                 "duplex");
1790 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1791         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1792                                                         "half#full#auto");
1793
1794 cmdline_parse_inst_t cmd_config_speed_specific = {
1795         .f = cmd_config_speed_specific_parsed,
1796         .data = NULL,
1797         .help_str = "port config <port_id> speed "
1798                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1799                                                         "half|full|auto",
1800         .tokens = {
1801                 (void *)&cmd_config_speed_specific_port,
1802                 (void *)&cmd_config_speed_specific_keyword,
1803                 (void *)&cmd_config_speed_specific_id,
1804                 (void *)&cmd_config_speed_specific_item1,
1805                 (void *)&cmd_config_speed_specific_value1,
1806                 (void *)&cmd_config_speed_specific_item2,
1807                 (void *)&cmd_config_speed_specific_value2,
1808                 NULL,
1809         },
1810 };
1811
1812 /* *** configure loopback for all ports *** */
1813 struct cmd_config_loopback_all {
1814         cmdline_fixed_string_t port;
1815         cmdline_fixed_string_t keyword;
1816         cmdline_fixed_string_t all;
1817         cmdline_fixed_string_t item;
1818         uint32_t mode;
1819 };
1820
1821 static void
1822 cmd_config_loopback_all_parsed(void *parsed_result,
1823                         __rte_unused struct cmdline *cl,
1824                         __rte_unused void *data)
1825 {
1826         struct cmd_config_loopback_all *res = parsed_result;
1827         portid_t pid;
1828
1829         if (!all_ports_stopped()) {
1830                 printf("Please stop all ports first\n");
1831                 return;
1832         }
1833
1834         RTE_ETH_FOREACH_DEV(pid) {
1835                 ports[pid].dev_conf.lpbk_mode = res->mode;
1836         }
1837
1838         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1839 }
1840
1841 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1842         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1843 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1844         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1845                                                         "config");
1846 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1847         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1848 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1849         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1850                                                         "loopback");
1851 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1852         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1853
1854 cmdline_parse_inst_t cmd_config_loopback_all = {
1855         .f = cmd_config_loopback_all_parsed,
1856         .data = NULL,
1857         .help_str = "port config all loopback <mode>",
1858         .tokens = {
1859                 (void *)&cmd_config_loopback_all_port,
1860                 (void *)&cmd_config_loopback_all_keyword,
1861                 (void *)&cmd_config_loopback_all_all,
1862                 (void *)&cmd_config_loopback_all_item,
1863                 (void *)&cmd_config_loopback_all_mode,
1864                 NULL,
1865         },
1866 };
1867
1868 /* *** configure loopback for specific port *** */
1869 struct cmd_config_loopback_specific {
1870         cmdline_fixed_string_t port;
1871         cmdline_fixed_string_t keyword;
1872         uint16_t port_id;
1873         cmdline_fixed_string_t item;
1874         uint32_t mode;
1875 };
1876
1877 static void
1878 cmd_config_loopback_specific_parsed(void *parsed_result,
1879                                 __rte_unused struct cmdline *cl,
1880                                 __rte_unused void *data)
1881 {
1882         struct cmd_config_loopback_specific *res = parsed_result;
1883
1884         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1885                 return;
1886
1887         if (!port_is_stopped(res->port_id)) {
1888                 printf("Please stop port %u first\n", res->port_id);
1889                 return;
1890         }
1891
1892         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1893
1894         cmd_reconfig_device_queue(res->port_id, 1, 1);
1895 }
1896
1897
1898 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1899         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1900                                                                 "port");
1901 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1902         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1903                                                                 "config");
1904 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1905         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1906                                                                 UINT16);
1907 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1908         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1909                                                                 "loopback");
1910 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1911         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1912                               UINT32);
1913
1914 cmdline_parse_inst_t cmd_config_loopback_specific = {
1915         .f = cmd_config_loopback_specific_parsed,
1916         .data = NULL,
1917         .help_str = "port config <port_id> loopback <mode>",
1918         .tokens = {
1919                 (void *)&cmd_config_loopback_specific_port,
1920                 (void *)&cmd_config_loopback_specific_keyword,
1921                 (void *)&cmd_config_loopback_specific_id,
1922                 (void *)&cmd_config_loopback_specific_item,
1923                 (void *)&cmd_config_loopback_specific_mode,
1924                 NULL,
1925         },
1926 };
1927
1928 /* *** configure txq/rxq, txd/rxd *** */
1929 struct cmd_config_rx_tx {
1930         cmdline_fixed_string_t port;
1931         cmdline_fixed_string_t keyword;
1932         cmdline_fixed_string_t all;
1933         cmdline_fixed_string_t name;
1934         uint16_t value;
1935 };
1936
1937 static void
1938 cmd_config_rx_tx_parsed(void *parsed_result,
1939                         __rte_unused struct cmdline *cl,
1940                         __rte_unused void *data)
1941 {
1942         struct cmd_config_rx_tx *res = parsed_result;
1943
1944         if (!all_ports_stopped()) {
1945                 printf("Please stop all ports first\n");
1946                 return;
1947         }
1948         if (!strcmp(res->name, "rxq")) {
1949                 if (!res->value && !nb_txq) {
1950                         printf("Warning: Either rx or tx queues should be non zero\n");
1951                         return;
1952                 }
1953                 if (check_nb_rxq(res->value) != 0)
1954                         return;
1955                 nb_rxq = res->value;
1956         }
1957         else if (!strcmp(res->name, "txq")) {
1958                 if (!res->value && !nb_rxq) {
1959                         printf("Warning: Either rx or tx queues should be non zero\n");
1960                         return;
1961                 }
1962                 if (check_nb_txq(res->value) != 0)
1963                         return;
1964                 nb_txq = res->value;
1965         }
1966         else if (!strcmp(res->name, "rxd")) {
1967                 if (check_nb_rxd(res->value) != 0)
1968                         return;
1969                 nb_rxd = res->value;
1970         } else if (!strcmp(res->name, "txd")) {
1971                 if (check_nb_txd(res->value) != 0)
1972                         return;
1973
1974                 nb_txd = res->value;
1975         } else {
1976                 printf("Unknown parameter\n");
1977                 return;
1978         }
1979
1980         fwd_config_setup();
1981
1982         init_port_config();
1983
1984         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1985 }
1986
1987 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1988         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1989 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1990         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1991 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1992         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1993 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1994         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1995                                                 "rxq#txq#rxd#txd");
1996 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1997         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1998
1999 cmdline_parse_inst_t cmd_config_rx_tx = {
2000         .f = cmd_config_rx_tx_parsed,
2001         .data = NULL,
2002         .help_str = "port config all rxq|txq|rxd|txd <value>",
2003         .tokens = {
2004                 (void *)&cmd_config_rx_tx_port,
2005                 (void *)&cmd_config_rx_tx_keyword,
2006                 (void *)&cmd_config_rx_tx_all,
2007                 (void *)&cmd_config_rx_tx_name,
2008                 (void *)&cmd_config_rx_tx_value,
2009                 NULL,
2010         },
2011 };
2012
2013 /* *** config max packet length *** */
2014 struct cmd_config_max_pkt_len_result {
2015         cmdline_fixed_string_t port;
2016         cmdline_fixed_string_t keyword;
2017         cmdline_fixed_string_t all;
2018         cmdline_fixed_string_t name;
2019         uint32_t value;
2020 };
2021
2022 static void
2023 cmd_config_max_pkt_len_parsed(void *parsed_result,
2024                                 __rte_unused struct cmdline *cl,
2025                                 __rte_unused void *data)
2026 {
2027         struct cmd_config_max_pkt_len_result *res = parsed_result;
2028         portid_t pid;
2029
2030         if (!all_ports_stopped()) {
2031                 printf("Please stop all ports first\n");
2032                 return;
2033         }
2034
2035         RTE_ETH_FOREACH_DEV(pid) {
2036                 struct rte_port *port = &ports[pid];
2037                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2038
2039                 if (!strcmp(res->name, "max-pkt-len")) {
2040                         if (res->value < RTE_ETHER_MIN_LEN) {
2041                                 printf("max-pkt-len can not be less than %d\n",
2042                                                 RTE_ETHER_MIN_LEN);
2043                                 return;
2044                         }
2045                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2046                                 return;
2047
2048                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2049                         if (res->value > RTE_ETHER_MAX_LEN)
2050                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2051                         else
2052                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2053                         port->dev_conf.rxmode.offloads = rx_offloads;
2054                 } else {
2055                         printf("Unknown parameter\n");
2056                         return;
2057                 }
2058         }
2059
2060         init_port_config();
2061
2062         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2063 }
2064
2065 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2066         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2067                                                                 "port");
2068 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2069         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2070                                                                 "config");
2071 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2072         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2073                                                                 "all");
2074 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2075         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2076                                                                 "max-pkt-len");
2077 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2078         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2079                                                                 UINT32);
2080
2081 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2082         .f = cmd_config_max_pkt_len_parsed,
2083         .data = NULL,
2084         .help_str = "port config all max-pkt-len <value>",
2085         .tokens = {
2086                 (void *)&cmd_config_max_pkt_len_port,
2087                 (void *)&cmd_config_max_pkt_len_keyword,
2088                 (void *)&cmd_config_max_pkt_len_all,
2089                 (void *)&cmd_config_max_pkt_len_name,
2090                 (void *)&cmd_config_max_pkt_len_value,
2091                 NULL,
2092         },
2093 };
2094
2095 /* *** config max LRO aggregated packet size *** */
2096 struct cmd_config_max_lro_pkt_size_result {
2097         cmdline_fixed_string_t port;
2098         cmdline_fixed_string_t keyword;
2099         cmdline_fixed_string_t all;
2100         cmdline_fixed_string_t name;
2101         uint32_t value;
2102 };
2103
2104 static void
2105 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2106                                 __rte_unused struct cmdline *cl,
2107                                 __rte_unused void *data)
2108 {
2109         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2110         portid_t pid;
2111
2112         if (!all_ports_stopped()) {
2113                 printf("Please stop all ports first\n");
2114                 return;
2115         }
2116
2117         RTE_ETH_FOREACH_DEV(pid) {
2118                 struct rte_port *port = &ports[pid];
2119
2120                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2121                         if (res->value ==
2122                                         port->dev_conf.rxmode.max_lro_pkt_size)
2123                                 return;
2124
2125                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2126                 } else {
2127                         printf("Unknown parameter\n");
2128                         return;
2129                 }
2130         }
2131
2132         init_port_config();
2133
2134         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2135 }
2136
2137 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2138         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2139                                  port, "port");
2140 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2141         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2142                                  keyword, "config");
2143 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2144         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2145                                  all, "all");
2146 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2147         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2148                                  name, "max-lro-pkt-size");
2149 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2150         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2151                               value, UINT32);
2152
2153 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2154         .f = cmd_config_max_lro_pkt_size_parsed,
2155         .data = NULL,
2156         .help_str = "port config all max-lro-pkt-size <value>",
2157         .tokens = {
2158                 (void *)&cmd_config_max_lro_pkt_size_port,
2159                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2160                 (void *)&cmd_config_max_lro_pkt_size_all,
2161                 (void *)&cmd_config_max_lro_pkt_size_name,
2162                 (void *)&cmd_config_max_lro_pkt_size_value,
2163                 NULL,
2164         },
2165 };
2166
2167 /* *** configure port MTU *** */
2168 struct cmd_config_mtu_result {
2169         cmdline_fixed_string_t port;
2170         cmdline_fixed_string_t keyword;
2171         cmdline_fixed_string_t mtu;
2172         portid_t port_id;
2173         uint16_t value;
2174 };
2175
2176 static void
2177 cmd_config_mtu_parsed(void *parsed_result,
2178                       __rte_unused struct cmdline *cl,
2179                       __rte_unused void *data)
2180 {
2181         struct cmd_config_mtu_result *res = parsed_result;
2182
2183         if (res->value < RTE_ETHER_MIN_LEN) {
2184                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2185                 return;
2186         }
2187         port_mtu_set(res->port_id, res->value);
2188 }
2189
2190 cmdline_parse_token_string_t cmd_config_mtu_port =
2191         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2192                                  "port");
2193 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2194         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2195                                  "config");
2196 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2197         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2198                                  "mtu");
2199 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2200         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2201 cmdline_parse_token_num_t cmd_config_mtu_value =
2202         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2203
2204 cmdline_parse_inst_t cmd_config_mtu = {
2205         .f = cmd_config_mtu_parsed,
2206         .data = NULL,
2207         .help_str = "port config mtu <port_id> <value>",
2208         .tokens = {
2209                 (void *)&cmd_config_mtu_port,
2210                 (void *)&cmd_config_mtu_keyword,
2211                 (void *)&cmd_config_mtu_mtu,
2212                 (void *)&cmd_config_mtu_port_id,
2213                 (void *)&cmd_config_mtu_value,
2214                 NULL,
2215         },
2216 };
2217
2218 /* *** configure rx mode *** */
2219 struct cmd_config_rx_mode_flag {
2220         cmdline_fixed_string_t port;
2221         cmdline_fixed_string_t keyword;
2222         cmdline_fixed_string_t all;
2223         cmdline_fixed_string_t name;
2224         cmdline_fixed_string_t value;
2225 };
2226
2227 static void
2228 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2229                                 __rte_unused struct cmdline *cl,
2230                                 __rte_unused void *data)
2231 {
2232         struct cmd_config_rx_mode_flag *res = parsed_result;
2233
2234         if (!all_ports_stopped()) {
2235                 printf("Please stop all ports first\n");
2236                 return;
2237         }
2238
2239         if (!strcmp(res->name, "drop-en")) {
2240                 if (!strcmp(res->value, "on"))
2241                         rx_drop_en = 1;
2242                 else if (!strcmp(res->value, "off"))
2243                         rx_drop_en = 0;
2244                 else {
2245                         printf("Unknown parameter\n");
2246                         return;
2247                 }
2248         } else {
2249                 printf("Unknown parameter\n");
2250                 return;
2251         }
2252
2253         init_port_config();
2254
2255         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2256 }
2257
2258 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2259         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2260 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2261         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2262                                                                 "config");
2263 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2264         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2265 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2266         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2267                                         "drop-en");
2268 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2269         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2270                                                         "on#off");
2271
2272 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2273         .f = cmd_config_rx_mode_flag_parsed,
2274         .data = NULL,
2275         .help_str = "port config all drop-en on|off",
2276         .tokens = {
2277                 (void *)&cmd_config_rx_mode_flag_port,
2278                 (void *)&cmd_config_rx_mode_flag_keyword,
2279                 (void *)&cmd_config_rx_mode_flag_all,
2280                 (void *)&cmd_config_rx_mode_flag_name,
2281                 (void *)&cmd_config_rx_mode_flag_value,
2282                 NULL,
2283         },
2284 };
2285
2286 /* *** configure rss *** */
2287 struct cmd_config_rss {
2288         cmdline_fixed_string_t port;
2289         cmdline_fixed_string_t keyword;
2290         cmdline_fixed_string_t all;
2291         cmdline_fixed_string_t name;
2292         cmdline_fixed_string_t value;
2293 };
2294
2295 static void
2296 cmd_config_rss_parsed(void *parsed_result,
2297                         __rte_unused struct cmdline *cl,
2298                         __rte_unused void *data)
2299 {
2300         struct cmd_config_rss *res = parsed_result;
2301         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2302         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2303         int use_default = 0;
2304         int all_updated = 1;
2305         int diag;
2306         uint16_t i;
2307         int ret;
2308
2309         if (!strcmp(res->value, "all"))
2310                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2311                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2312                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2313                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2314         else if (!strcmp(res->value, "eth"))
2315                 rss_conf.rss_hf = ETH_RSS_ETH;
2316         else if (!strcmp(res->value, "vlan"))
2317                 rss_conf.rss_hf = ETH_RSS_VLAN;
2318         else if (!strcmp(res->value, "ip"))
2319                 rss_conf.rss_hf = ETH_RSS_IP;
2320         else if (!strcmp(res->value, "udp"))
2321                 rss_conf.rss_hf = ETH_RSS_UDP;
2322         else if (!strcmp(res->value, "tcp"))
2323                 rss_conf.rss_hf = ETH_RSS_TCP;
2324         else if (!strcmp(res->value, "sctp"))
2325                 rss_conf.rss_hf = ETH_RSS_SCTP;
2326         else if (!strcmp(res->value, "ether"))
2327                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2328         else if (!strcmp(res->value, "port"))
2329                 rss_conf.rss_hf = ETH_RSS_PORT;
2330         else if (!strcmp(res->value, "vxlan"))
2331                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2332         else if (!strcmp(res->value, "geneve"))
2333                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2334         else if (!strcmp(res->value, "nvgre"))
2335                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2336         else if (!strcmp(res->value, "l3-pre32"))
2337                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2338         else if (!strcmp(res->value, "l3-pre40"))
2339                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2340         else if (!strcmp(res->value, "l3-pre48"))
2341                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2342         else if (!strcmp(res->value, "l3-pre56"))
2343                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2344         else if (!strcmp(res->value, "l3-pre64"))
2345                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2346         else if (!strcmp(res->value, "l3-pre96"))
2347                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2348         else if (!strcmp(res->value, "l3-src-only"))
2349                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2350         else if (!strcmp(res->value, "l3-dst-only"))
2351                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2352         else if (!strcmp(res->value, "l4-src-only"))
2353                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2354         else if (!strcmp(res->value, "l4-dst-only"))
2355                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2356         else if (!strcmp(res->value, "l2-src-only"))
2357                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2358         else if (!strcmp(res->value, "l2-dst-only"))
2359                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2360         else if (!strcmp(res->value, "l2tpv3"))
2361                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2362         else if (!strcmp(res->value, "esp"))
2363                 rss_conf.rss_hf = ETH_RSS_ESP;
2364         else if (!strcmp(res->value, "ah"))
2365                 rss_conf.rss_hf = ETH_RSS_AH;
2366         else if (!strcmp(res->value, "pfcp"))
2367                 rss_conf.rss_hf = ETH_RSS_PFCP;
2368         else if (!strcmp(res->value, "pppoe"))
2369                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2370         else if (!strcmp(res->value, "gtpu"))
2371                 rss_conf.rss_hf = ETH_RSS_GTPU;
2372         else if (!strcmp(res->value, "none"))
2373                 rss_conf.rss_hf = 0;
2374         else if (!strcmp(res->value, "level-default")) {
2375                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2376                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2377         } else if (!strcmp(res->value, "level-outer")) {
2378                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2379                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2380         } else if (!strcmp(res->value, "level-inner")) {
2381                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2382                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2383         } else if (!strcmp(res->value, "default"))
2384                 use_default = 1;
2385         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2386                                                 atoi(res->value) < 64)
2387                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2388         else {
2389                 printf("Unknown parameter\n");
2390                 return;
2391         }
2392         rss_conf.rss_key = NULL;
2393         /* Update global configuration for RSS types. */
2394         RTE_ETH_FOREACH_DEV(i) {
2395                 struct rte_eth_rss_conf local_rss_conf;
2396
2397                 ret = eth_dev_info_get_print_err(i, &dev_info);
2398                 if (ret != 0)
2399                         return;
2400
2401                 if (use_default)
2402                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2403
2404                 local_rss_conf = rss_conf;
2405                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2406                         dev_info.flow_type_rss_offloads;
2407                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2408                         printf("Port %u modified RSS hash function based on hardware support,"
2409                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2410                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2411                 }
2412                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2413                 if (diag < 0) {
2414                         all_updated = 0;
2415                         printf("Configuration of RSS hash at ethernet port %d "
2416                                 "failed with error (%d): %s.\n",
2417                                 i, -diag, strerror(-diag));
2418                 }
2419         }
2420         if (all_updated && !use_default) {
2421                 rss_hf = rss_conf.rss_hf;
2422                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2423         }
2424 }
2425
2426 cmdline_parse_token_string_t cmd_config_rss_port =
2427         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2428 cmdline_parse_token_string_t cmd_config_rss_keyword =
2429         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2430 cmdline_parse_token_string_t cmd_config_rss_all =
2431         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2432 cmdline_parse_token_string_t cmd_config_rss_name =
2433         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2434 cmdline_parse_token_string_t cmd_config_rss_value =
2435         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2436
2437 cmdline_parse_inst_t cmd_config_rss = {
2438         .f = cmd_config_rss_parsed,
2439         .data = NULL,
2440         .help_str = "port config all rss "
2441                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2442                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2443                 "level-outer|level-inner|<flowtype_id>",
2444         .tokens = {
2445                 (void *)&cmd_config_rss_port,
2446                 (void *)&cmd_config_rss_keyword,
2447                 (void *)&cmd_config_rss_all,
2448                 (void *)&cmd_config_rss_name,
2449                 (void *)&cmd_config_rss_value,
2450                 NULL,
2451         },
2452 };
2453
2454 /* *** configure rss hash key *** */
2455 struct cmd_config_rss_hash_key {
2456         cmdline_fixed_string_t port;
2457         cmdline_fixed_string_t config;
2458         portid_t port_id;
2459         cmdline_fixed_string_t rss_hash_key;
2460         cmdline_fixed_string_t rss_type;
2461         cmdline_fixed_string_t key;
2462 };
2463
2464 static uint8_t
2465 hexa_digit_to_value(char hexa_digit)
2466 {
2467         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2468                 return (uint8_t) (hexa_digit - '0');
2469         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2470                 return (uint8_t) ((hexa_digit - 'a') + 10);
2471         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2472                 return (uint8_t) ((hexa_digit - 'A') + 10);
2473         /* Invalid hexa digit */
2474         return 0xFF;
2475 }
2476
2477 static uint8_t
2478 parse_and_check_key_hexa_digit(char *key, int idx)
2479 {
2480         uint8_t hexa_v;
2481
2482         hexa_v = hexa_digit_to_value(key[idx]);
2483         if (hexa_v == 0xFF)
2484                 printf("invalid key: character %c at position %d is not a "
2485                        "valid hexa digit\n", key[idx], idx);
2486         return hexa_v;
2487 }
2488
2489 static void
2490 cmd_config_rss_hash_key_parsed(void *parsed_result,
2491                                __rte_unused struct cmdline *cl,
2492                                __rte_unused void *data)
2493 {
2494         struct cmd_config_rss_hash_key *res = parsed_result;
2495         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2496         uint8_t xdgt0;
2497         uint8_t xdgt1;
2498         int i;
2499         struct rte_eth_dev_info dev_info;
2500         uint8_t hash_key_size;
2501         uint32_t key_len;
2502         int ret;
2503
2504         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2505         if (ret != 0)
2506                 return;
2507
2508         if (dev_info.hash_key_size > 0 &&
2509                         dev_info.hash_key_size <= sizeof(hash_key))
2510                 hash_key_size = dev_info.hash_key_size;
2511         else {
2512                 printf("dev_info did not provide a valid hash key size\n");
2513                 return;
2514         }
2515         /* Check the length of the RSS hash key */
2516         key_len = strlen(res->key);
2517         if (key_len != (hash_key_size * 2)) {
2518                 printf("key length: %d invalid - key must be a string of %d"
2519                            " hexa-decimal numbers\n",
2520                            (int) key_len, hash_key_size * 2);
2521                 return;
2522         }
2523         /* Translate RSS hash key into binary representation */
2524         for (i = 0; i < hash_key_size; i++) {
2525                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2526                 if (xdgt0 == 0xFF)
2527                         return;
2528                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2529                 if (xdgt1 == 0xFF)
2530                         return;
2531                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2532         }
2533         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2534                         hash_key_size);
2535 }
2536
2537 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2538         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2539 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2540         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2541                                  "config");
2542 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2543         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2544 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2545         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2546                                  rss_hash_key, "rss-hash-key");
2547 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2548         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2549                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2550                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2551                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2552                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2553                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2554                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2555                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2556 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2557         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2558
2559 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2560         .f = cmd_config_rss_hash_key_parsed,
2561         .data = NULL,
2562         .help_str = "port config <port_id> rss-hash-key "
2563                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2564                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2565                 "l2-payload|ipv6-ex|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                 "<string of hex digits (variable length, NIC dependent)>",
2570         .tokens = {
2571                 (void *)&cmd_config_rss_hash_key_port,
2572                 (void *)&cmd_config_rss_hash_key_config,
2573                 (void *)&cmd_config_rss_hash_key_port_id,
2574                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2575                 (void *)&cmd_config_rss_hash_key_rss_type,
2576                 (void *)&cmd_config_rss_hash_key_value,
2577                 NULL,
2578         },
2579 };
2580
2581 /* *** configure port rxq/txq ring size *** */
2582 struct cmd_config_rxtx_ring_size {
2583         cmdline_fixed_string_t port;
2584         cmdline_fixed_string_t config;
2585         portid_t portid;
2586         cmdline_fixed_string_t rxtxq;
2587         uint16_t qid;
2588         cmdline_fixed_string_t rsize;
2589         uint16_t size;
2590 };
2591
2592 static void
2593 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2594                                  __rte_unused struct cmdline *cl,
2595                                  __rte_unused void *data)
2596 {
2597         struct cmd_config_rxtx_ring_size *res = parsed_result;
2598         struct rte_port *port;
2599         uint8_t isrx;
2600
2601         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2602                 return;
2603
2604         if (res->portid == (portid_t)RTE_PORT_ALL) {
2605                 printf("Invalid port id\n");
2606                 return;
2607         }
2608
2609         port = &ports[res->portid];
2610
2611         if (!strcmp(res->rxtxq, "rxq"))
2612                 isrx = 1;
2613         else if (!strcmp(res->rxtxq, "txq"))
2614                 isrx = 0;
2615         else {
2616                 printf("Unknown parameter\n");
2617                 return;
2618         }
2619
2620         if (isrx && rx_queue_id_is_invalid(res->qid))
2621                 return;
2622         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2623                 return;
2624
2625         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2626                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2627                        rx_free_thresh);
2628                 return;
2629         }
2630
2631         if (isrx)
2632                 port->nb_rx_desc[res->qid] = res->size;
2633         else
2634                 port->nb_tx_desc[res->qid] = res->size;
2635
2636         cmd_reconfig_device_queue(res->portid, 0, 1);
2637 }
2638
2639 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2640         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2641                                  port, "port");
2642 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2643         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2644                                  config, "config");
2645 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2646         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2647                                  portid, UINT16);
2648 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2649         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2650                                  rxtxq, "rxq#txq");
2651 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2652         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2653                               qid, UINT16);
2654 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2655         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2656                                  rsize, "ring_size");
2657 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2658         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2659                               size, UINT16);
2660
2661 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2662         .f = cmd_config_rxtx_ring_size_parsed,
2663         .data = NULL,
2664         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2665         .tokens = {
2666                 (void *)&cmd_config_rxtx_ring_size_port,
2667                 (void *)&cmd_config_rxtx_ring_size_config,
2668                 (void *)&cmd_config_rxtx_ring_size_portid,
2669                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2670                 (void *)&cmd_config_rxtx_ring_size_qid,
2671                 (void *)&cmd_config_rxtx_ring_size_rsize,
2672                 (void *)&cmd_config_rxtx_ring_size_size,
2673                 NULL,
2674         },
2675 };
2676
2677 /* *** configure port rxq/txq start/stop *** */
2678 struct cmd_config_rxtx_queue {
2679         cmdline_fixed_string_t port;
2680         portid_t portid;
2681         cmdline_fixed_string_t rxtxq;
2682         uint16_t qid;
2683         cmdline_fixed_string_t opname;
2684 };
2685
2686 static void
2687 cmd_config_rxtx_queue_parsed(void *parsed_result,
2688                         __rte_unused struct cmdline *cl,
2689                         __rte_unused void *data)
2690 {
2691         struct cmd_config_rxtx_queue *res = parsed_result;
2692         uint8_t isrx;
2693         uint8_t isstart;
2694         int ret = 0;
2695
2696         if (test_done == 0) {
2697                 printf("Please stop forwarding first\n");
2698                 return;
2699         }
2700
2701         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2702                 return;
2703
2704         if (port_is_started(res->portid) != 1) {
2705                 printf("Please start port %u first\n", res->portid);
2706                 return;
2707         }
2708
2709         if (!strcmp(res->rxtxq, "rxq"))
2710                 isrx = 1;
2711         else if (!strcmp(res->rxtxq, "txq"))
2712                 isrx = 0;
2713         else {
2714                 printf("Unknown parameter\n");
2715                 return;
2716         }
2717
2718         if (isrx && rx_queue_id_is_invalid(res->qid))
2719                 return;
2720         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2721                 return;
2722
2723         if (!strcmp(res->opname, "start"))
2724                 isstart = 1;
2725         else if (!strcmp(res->opname, "stop"))
2726                 isstart = 0;
2727         else {
2728                 printf("Unknown parameter\n");
2729                 return;
2730         }
2731
2732         if (isstart && isrx)
2733                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2734         else if (!isstart && isrx)
2735                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2736         else if (isstart && !isrx)
2737                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2738         else
2739                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2740
2741         if (ret == -ENOTSUP)
2742                 printf("Function not supported in PMD driver\n");
2743 }
2744
2745 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2746         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2747 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2748         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2749 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2750         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2751 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2752         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2753 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2754         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2755                                                 "start#stop");
2756
2757 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2758         .f = cmd_config_rxtx_queue_parsed,
2759         .data = NULL,
2760         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2761         .tokens = {
2762                 (void *)&cmd_config_rxtx_queue_port,
2763                 (void *)&cmd_config_rxtx_queue_portid,
2764                 (void *)&cmd_config_rxtx_queue_rxtxq,
2765                 (void *)&cmd_config_rxtx_queue_qid,
2766                 (void *)&cmd_config_rxtx_queue_opname,
2767                 NULL,
2768         },
2769 };
2770
2771 /* *** configure port rxq/txq deferred start on/off *** */
2772 struct cmd_config_deferred_start_rxtx_queue {
2773         cmdline_fixed_string_t port;
2774         portid_t port_id;
2775         cmdline_fixed_string_t rxtxq;
2776         uint16_t qid;
2777         cmdline_fixed_string_t opname;
2778         cmdline_fixed_string_t state;
2779 };
2780
2781 static void
2782 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2783                         __rte_unused struct cmdline *cl,
2784                         __rte_unused void *data)
2785 {
2786         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2787         struct rte_port *port;
2788         uint8_t isrx;
2789         uint8_t ison;
2790         uint8_t needreconfig = 0;
2791
2792         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2793                 return;
2794
2795         if (port_is_started(res->port_id) != 0) {
2796                 printf("Please stop port %u first\n", res->port_id);
2797                 return;
2798         }
2799
2800         port = &ports[res->port_id];
2801
2802         isrx = !strcmp(res->rxtxq, "rxq");
2803
2804         if (isrx && rx_queue_id_is_invalid(res->qid))
2805                 return;
2806         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2807                 return;
2808
2809         ison = !strcmp(res->state, "on");
2810
2811         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2812                 port->rx_conf[res->qid].rx_deferred_start = ison;
2813                 needreconfig = 1;
2814         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2815                 port->tx_conf[res->qid].tx_deferred_start = ison;
2816                 needreconfig = 1;
2817         }
2818
2819         if (needreconfig)
2820                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2821 }
2822
2823 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2824         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2825                                                 port, "port");
2826 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2827         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2828                                                 port_id, UINT16);
2829 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2830         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2831                                                 rxtxq, "rxq#txq");
2832 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2833         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2834                                                 qid, UINT16);
2835 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2836         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2837                                                 opname, "deferred_start");
2838 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2839         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2840                                                 state, "on#off");
2841
2842 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2843         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2844         .data = NULL,
2845         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2846         .tokens = {
2847                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2848                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2849                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2850                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2851                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2852                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2853                 NULL,
2854         },
2855 };
2856
2857 /* *** configure port rxq/txq setup *** */
2858 struct cmd_setup_rxtx_queue {
2859         cmdline_fixed_string_t port;
2860         portid_t portid;
2861         cmdline_fixed_string_t rxtxq;
2862         uint16_t qid;
2863         cmdline_fixed_string_t setup;
2864 };
2865
2866 /* Common CLI fields for queue setup */
2867 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2868         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2869 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2870         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2871 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2872         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2873 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2874         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2875 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2876         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2877
2878 static void
2879 cmd_setup_rxtx_queue_parsed(
2880         void *parsed_result,
2881         __rte_unused struct cmdline *cl,
2882         __rte_unused void *data)
2883 {
2884         struct cmd_setup_rxtx_queue *res = parsed_result;
2885         struct rte_port *port;
2886         struct rte_mempool *mp;
2887         unsigned int socket_id;
2888         uint8_t isrx = 0;
2889         int ret;
2890
2891         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2892                 return;
2893
2894         if (res->portid == (portid_t)RTE_PORT_ALL) {
2895                 printf("Invalid port id\n");
2896                 return;
2897         }
2898
2899         if (!strcmp(res->rxtxq, "rxq"))
2900                 isrx = 1;
2901         else if (!strcmp(res->rxtxq, "txq"))
2902                 isrx = 0;
2903         else {
2904                 printf("Unknown parameter\n");
2905                 return;
2906         }
2907
2908         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2909                 printf("Invalid rx queue\n");
2910                 return;
2911         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2912                 printf("Invalid tx queue\n");
2913                 return;
2914         }
2915
2916         port = &ports[res->portid];
2917         if (isrx) {
2918                 socket_id = rxring_numa[res->portid];
2919                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2920                         socket_id = port->socket_id;
2921
2922                 mp = mbuf_pool_find(socket_id, 0);
2923                 if (mp == NULL) {
2924                         printf("Failed to setup RX queue: "
2925                                 "No mempool allocation"
2926                                 " on the socket %d\n",
2927                                 rxring_numa[res->portid]);
2928                         return;
2929                 }
2930                 ret = rx_queue_setup(res->portid,
2931                                      res->qid,
2932                                      port->nb_rx_desc[res->qid],
2933                                      socket_id,
2934                                      &port->rx_conf[res->qid],
2935                                      mp);
2936                 if (ret)
2937                         printf("Failed to setup RX queue\n");
2938         } else {
2939                 socket_id = txring_numa[res->portid];
2940                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2941                         socket_id = port->socket_id;
2942
2943                 ret = rte_eth_tx_queue_setup(res->portid,
2944                                              res->qid,
2945                                              port->nb_tx_desc[res->qid],
2946                                              socket_id,
2947                                              &port->tx_conf[res->qid]);
2948                 if (ret)
2949                         printf("Failed to setup TX queue\n");
2950         }
2951 }
2952
2953 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2954         .f = cmd_setup_rxtx_queue_parsed,
2955         .data = NULL,
2956         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2957         .tokens = {
2958                 (void *)&cmd_setup_rxtx_queue_port,
2959                 (void *)&cmd_setup_rxtx_queue_portid,
2960                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2961                 (void *)&cmd_setup_rxtx_queue_qid,
2962                 (void *)&cmd_setup_rxtx_queue_setup,
2963                 NULL,
2964         },
2965 };
2966
2967
2968 /* *** Configure RSS RETA *** */
2969 struct cmd_config_rss_reta {
2970         cmdline_fixed_string_t port;
2971         cmdline_fixed_string_t keyword;
2972         portid_t port_id;
2973         cmdline_fixed_string_t name;
2974         cmdline_fixed_string_t list_name;
2975         cmdline_fixed_string_t list_of_items;
2976 };
2977
2978 static int
2979 parse_reta_config(const char *str,
2980                   struct rte_eth_rss_reta_entry64 *reta_conf,
2981                   uint16_t nb_entries)
2982 {
2983         int i;
2984         unsigned size;
2985         uint16_t hash_index, idx, shift;
2986         uint16_t nb_queue;
2987         char s[256];
2988         const char *p, *p0 = str;
2989         char *end;
2990         enum fieldnames {
2991                 FLD_HASH_INDEX = 0,
2992                 FLD_QUEUE,
2993                 _NUM_FLD
2994         };
2995         unsigned long int_fld[_NUM_FLD];
2996         char *str_fld[_NUM_FLD];
2997
2998         while ((p = strchr(p0,'(')) != NULL) {
2999                 ++p;
3000                 if((p0 = strchr(p,')')) == NULL)
3001                         return -1;
3002
3003                 size = p0 - p;
3004                 if(size >= sizeof(s))
3005                         return -1;
3006
3007                 snprintf(s, sizeof(s), "%.*s", size, p);
3008                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
3009                         return -1;
3010                 for (i = 0; i < _NUM_FLD; i++) {
3011                         errno = 0;
3012                         int_fld[i] = strtoul(str_fld[i], &end, 0);
3013                         if (errno != 0 || end == str_fld[i] ||
3014                                         int_fld[i] > 65535)
3015                                 return -1;
3016                 }
3017
3018                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
3019                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
3020
3021                 if (hash_index >= nb_entries) {
3022                         printf("Invalid RETA hash index=%d\n", hash_index);
3023                         return -1;
3024                 }
3025
3026                 idx = hash_index / RTE_RETA_GROUP_SIZE;
3027                 shift = hash_index % RTE_RETA_GROUP_SIZE;
3028                 reta_conf[idx].mask |= (1ULL << shift);
3029                 reta_conf[idx].reta[shift] = nb_queue;
3030         }
3031
3032         return 0;
3033 }
3034
3035 static void
3036 cmd_set_rss_reta_parsed(void *parsed_result,
3037                         __rte_unused struct cmdline *cl,
3038                         __rte_unused void *data)
3039 {
3040         int ret;
3041         struct rte_eth_dev_info dev_info;
3042         struct rte_eth_rss_reta_entry64 reta_conf[8];
3043         struct cmd_config_rss_reta *res = parsed_result;
3044
3045         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3046         if (ret != 0)
3047                 return;
3048
3049         if (dev_info.reta_size == 0) {
3050                 printf("Redirection table size is 0 which is "
3051                                         "invalid for RSS\n");
3052                 return;
3053         } else
3054                 printf("The reta size of port %d is %u\n",
3055                         res->port_id, dev_info.reta_size);
3056         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3057                 printf("Currently do not support more than %u entries of "
3058                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3059                 return;
3060         }
3061
3062         memset(reta_conf, 0, sizeof(reta_conf));
3063         if (!strcmp(res->list_name, "reta")) {
3064                 if (parse_reta_config(res->list_of_items, reta_conf,
3065                                                 dev_info.reta_size)) {
3066                         printf("Invalid RSS Redirection Table "
3067                                         "config entered\n");
3068                         return;
3069                 }
3070                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3071                                 reta_conf, dev_info.reta_size);
3072                 if (ret != 0)
3073                         printf("Bad redirection table parameter, "
3074                                         "return code = %d \n", ret);
3075         }
3076 }
3077
3078 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3079         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3080 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3081         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3082 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3083         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3084 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3085         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3086 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3087         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3088 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3089         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3090                                  NULL);
3091 cmdline_parse_inst_t cmd_config_rss_reta = {
3092         .f = cmd_set_rss_reta_parsed,
3093         .data = NULL,
3094         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3095         .tokens = {
3096                 (void *)&cmd_config_rss_reta_port,
3097                 (void *)&cmd_config_rss_reta_keyword,
3098                 (void *)&cmd_config_rss_reta_port_id,
3099                 (void *)&cmd_config_rss_reta_name,
3100                 (void *)&cmd_config_rss_reta_list_name,
3101                 (void *)&cmd_config_rss_reta_list_of_items,
3102                 NULL,
3103         },
3104 };
3105
3106 /* *** SHOW PORT RETA INFO *** */
3107 struct cmd_showport_reta {
3108         cmdline_fixed_string_t show;
3109         cmdline_fixed_string_t port;
3110         portid_t port_id;
3111         cmdline_fixed_string_t rss;
3112         cmdline_fixed_string_t reta;
3113         uint16_t size;
3114         cmdline_fixed_string_t list_of_items;
3115 };
3116
3117 static int
3118 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3119                            uint16_t nb_entries,
3120                            char *str)
3121 {
3122         uint32_t size;
3123         const char *p, *p0 = str;
3124         char s[256];
3125         char *end;
3126         char *str_fld[8];
3127         uint16_t i;
3128         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3129                         RTE_RETA_GROUP_SIZE;
3130         int ret;
3131
3132         p = strchr(p0, '(');
3133         if (p == NULL)
3134                 return -1;
3135         p++;
3136         p0 = strchr(p, ')');
3137         if (p0 == NULL)
3138                 return -1;
3139         size = p0 - p;
3140         if (size >= sizeof(s)) {
3141                 printf("The string size exceeds the internal buffer size\n");
3142                 return -1;
3143         }
3144         snprintf(s, sizeof(s), "%.*s", size, p);
3145         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3146         if (ret <= 0 || ret != num) {
3147                 printf("The bits of masks do not match the number of "
3148                                         "reta entries: %u\n", num);
3149                 return -1;
3150         }
3151         for (i = 0; i < ret; i++)
3152                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3153
3154         return 0;
3155 }
3156
3157 static void
3158 cmd_showport_reta_parsed(void *parsed_result,
3159                          __rte_unused struct cmdline *cl,
3160                          __rte_unused void *data)
3161 {
3162         struct cmd_showport_reta *res = parsed_result;
3163         struct rte_eth_rss_reta_entry64 reta_conf[8];
3164         struct rte_eth_dev_info dev_info;
3165         uint16_t max_reta_size;
3166         int ret;
3167
3168         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3169         if (ret != 0)
3170                 return;
3171
3172         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3173         if (res->size == 0 || res->size > max_reta_size) {
3174                 printf("Invalid redirection table size: %u (1-%u)\n",
3175                         res->size, max_reta_size);
3176                 return;
3177         }
3178
3179         memset(reta_conf, 0, sizeof(reta_conf));
3180         if (showport_parse_reta_config(reta_conf, res->size,
3181                                 res->list_of_items) < 0) {
3182                 printf("Invalid string: %s for reta masks\n",
3183                                         res->list_of_items);
3184                 return;
3185         }
3186         port_rss_reta_info(res->port_id, reta_conf, res->size);
3187 }
3188
3189 cmdline_parse_token_string_t cmd_showport_reta_show =
3190         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3191 cmdline_parse_token_string_t cmd_showport_reta_port =
3192         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3193 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3194         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3195 cmdline_parse_token_string_t cmd_showport_reta_rss =
3196         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3197 cmdline_parse_token_string_t cmd_showport_reta_reta =
3198         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3199 cmdline_parse_token_num_t cmd_showport_reta_size =
3200         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3201 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3202         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3203                                         list_of_items, NULL);
3204
3205 cmdline_parse_inst_t cmd_showport_reta = {
3206         .f = cmd_showport_reta_parsed,
3207         .data = NULL,
3208         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3209         .tokens = {
3210                 (void *)&cmd_showport_reta_show,
3211                 (void *)&cmd_showport_reta_port,
3212                 (void *)&cmd_showport_reta_port_id,
3213                 (void *)&cmd_showport_reta_rss,
3214                 (void *)&cmd_showport_reta_reta,
3215                 (void *)&cmd_showport_reta_size,
3216                 (void *)&cmd_showport_reta_list_of_items,
3217                 NULL,
3218         },
3219 };
3220
3221 /* *** Show RSS hash configuration *** */
3222 struct cmd_showport_rss_hash {
3223         cmdline_fixed_string_t show;
3224         cmdline_fixed_string_t port;
3225         portid_t port_id;
3226         cmdline_fixed_string_t rss_hash;
3227         cmdline_fixed_string_t rss_type;
3228         cmdline_fixed_string_t key; /* optional argument */
3229 };
3230
3231 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3232                                 __rte_unused struct cmdline *cl,
3233                                 void *show_rss_key)
3234 {
3235         struct cmd_showport_rss_hash *res = parsed_result;
3236
3237         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3238 }
3239
3240 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3241         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3242 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3243         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3244 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3245         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3246 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3247         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3248                                  "rss-hash");
3249 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3250         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3251
3252 cmdline_parse_inst_t cmd_showport_rss_hash = {
3253         .f = cmd_showport_rss_hash_parsed,
3254         .data = NULL,
3255         .help_str = "show port <port_id> rss-hash",
3256         .tokens = {
3257                 (void *)&cmd_showport_rss_hash_show,
3258                 (void *)&cmd_showport_rss_hash_port,
3259                 (void *)&cmd_showport_rss_hash_port_id,
3260                 (void *)&cmd_showport_rss_hash_rss_hash,
3261                 NULL,
3262         },
3263 };
3264
3265 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3266         .f = cmd_showport_rss_hash_parsed,
3267         .data = (void *)1,
3268         .help_str = "show port <port_id> rss-hash key",
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                 (void *)&cmd_showport_rss_hash_rss_key,
3275                 NULL,
3276         },
3277 };
3278
3279 /* *** Configure DCB *** */
3280 struct cmd_config_dcb {
3281         cmdline_fixed_string_t port;
3282         cmdline_fixed_string_t config;
3283         portid_t port_id;
3284         cmdline_fixed_string_t dcb;
3285         cmdline_fixed_string_t vt;
3286         cmdline_fixed_string_t vt_en;
3287         uint8_t num_tcs;
3288         cmdline_fixed_string_t pfc;
3289         cmdline_fixed_string_t pfc_en;
3290 };
3291
3292 static void
3293 cmd_config_dcb_parsed(void *parsed_result,
3294                         __rte_unused struct cmdline *cl,
3295                         __rte_unused void *data)
3296 {
3297         struct cmd_config_dcb *res = parsed_result;
3298         portid_t port_id = res->port_id;
3299         struct rte_port *port;
3300         uint8_t pfc_en;
3301         int ret;
3302
3303         port = &ports[port_id];
3304         /** Check if the port is not started **/
3305         if (port->port_status != RTE_PORT_STOPPED) {
3306                 printf("Please stop port %d first\n", port_id);
3307                 return;
3308         }
3309
3310         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3311                 printf("The invalid number of traffic class,"
3312                         " only 4 or 8 allowed.\n");
3313                 return;
3314         }
3315
3316         if (nb_fwd_lcores < res->num_tcs) {
3317                 printf("nb_cores shouldn't be less than number of TCs.\n");
3318                 return;
3319         }
3320         if (!strncmp(res->pfc_en, "on", 2))
3321                 pfc_en = 1;
3322         else
3323                 pfc_en = 0;
3324
3325         /* DCB in VT mode */
3326         if (!strncmp(res->vt_en, "on", 2))
3327                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3328                                 (enum rte_eth_nb_tcs)res->num_tcs,
3329                                 pfc_en);
3330         else
3331                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3332                                 (enum rte_eth_nb_tcs)res->num_tcs,
3333                                 pfc_en);
3334
3335
3336         if (ret != 0) {
3337                 printf("Cannot initialize network ports.\n");
3338                 return;
3339         }
3340
3341         cmd_reconfig_device_queue(port_id, 1, 1);
3342 }
3343
3344 cmdline_parse_token_string_t cmd_config_dcb_port =
3345         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3346 cmdline_parse_token_string_t cmd_config_dcb_config =
3347         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3348 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3349         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3350 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3351         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3352 cmdline_parse_token_string_t cmd_config_dcb_vt =
3353         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3354 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3355         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3356 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3357         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3358 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3359         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3360 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3361         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3362
3363 cmdline_parse_inst_t cmd_config_dcb = {
3364         .f = cmd_config_dcb_parsed,
3365         .data = NULL,
3366         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3367         .tokens = {
3368                 (void *)&cmd_config_dcb_port,
3369                 (void *)&cmd_config_dcb_config,
3370                 (void *)&cmd_config_dcb_port_id,
3371                 (void *)&cmd_config_dcb_dcb,
3372                 (void *)&cmd_config_dcb_vt,
3373                 (void *)&cmd_config_dcb_vt_en,
3374                 (void *)&cmd_config_dcb_num_tcs,
3375                 (void *)&cmd_config_dcb_pfc,
3376                 (void *)&cmd_config_dcb_pfc_en,
3377                 NULL,
3378         },
3379 };
3380
3381 /* *** configure number of packets per burst *** */
3382 struct cmd_config_burst {
3383         cmdline_fixed_string_t port;
3384         cmdline_fixed_string_t keyword;
3385         cmdline_fixed_string_t all;
3386         cmdline_fixed_string_t name;
3387         uint16_t value;
3388 };
3389
3390 static void
3391 cmd_config_burst_parsed(void *parsed_result,
3392                         __rte_unused struct cmdline *cl,
3393                         __rte_unused void *data)
3394 {
3395         struct cmd_config_burst *res = parsed_result;
3396         struct rte_eth_dev_info dev_info;
3397         uint16_t rec_nb_pkts;
3398         int ret;
3399
3400         if (!all_ports_stopped()) {
3401                 printf("Please stop all ports first\n");
3402                 return;
3403         }
3404
3405         if (!strcmp(res->name, "burst")) {
3406                 if (res->value == 0) {
3407                         /* If user gives a value of zero, query the PMD for
3408                          * its recommended Rx burst size. Testpmd uses a single
3409                          * size for all ports, so assume all ports are the same
3410                          * NIC model and use the values from Port 0.
3411                          */
3412                         ret = eth_dev_info_get_print_err(0, &dev_info);
3413                         if (ret != 0)
3414                                 return;
3415
3416                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3417
3418                         if (rec_nb_pkts == 0) {
3419                                 printf("PMD does not recommend a burst size.\n"
3420                                         "User provided value must be between"
3421                                         " 1 and %d\n", MAX_PKT_BURST);
3422                                 return;
3423                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3424                                 printf("PMD recommended burst size of %d"
3425                                         " exceeds maximum value of %d\n",
3426                                         rec_nb_pkts, MAX_PKT_BURST);
3427                                 return;
3428                         }
3429                         printf("Using PMD-provided burst value of %d\n",
3430                                 rec_nb_pkts);
3431                         nb_pkt_per_burst = rec_nb_pkts;
3432                 } else if (res->value > MAX_PKT_BURST) {
3433                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3434                         return;
3435                 } else
3436                         nb_pkt_per_burst = res->value;
3437         } else {
3438                 printf("Unknown parameter\n");
3439                 return;
3440         }
3441
3442         init_port_config();
3443
3444         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3445 }
3446
3447 cmdline_parse_token_string_t cmd_config_burst_port =
3448         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3449 cmdline_parse_token_string_t cmd_config_burst_keyword =
3450         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3451 cmdline_parse_token_string_t cmd_config_burst_all =
3452         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3453 cmdline_parse_token_string_t cmd_config_burst_name =
3454         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3455 cmdline_parse_token_num_t cmd_config_burst_value =
3456         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3457
3458 cmdline_parse_inst_t cmd_config_burst = {
3459         .f = cmd_config_burst_parsed,
3460         .data = NULL,
3461         .help_str = "port config all burst <value>",
3462         .tokens = {
3463                 (void *)&cmd_config_burst_port,
3464                 (void *)&cmd_config_burst_keyword,
3465                 (void *)&cmd_config_burst_all,
3466                 (void *)&cmd_config_burst_name,
3467                 (void *)&cmd_config_burst_value,
3468                 NULL,
3469         },
3470 };
3471
3472 /* *** configure rx/tx queues *** */
3473 struct cmd_config_thresh {
3474         cmdline_fixed_string_t port;
3475         cmdline_fixed_string_t keyword;
3476         cmdline_fixed_string_t all;
3477         cmdline_fixed_string_t name;
3478         uint8_t value;
3479 };
3480
3481 static void
3482 cmd_config_thresh_parsed(void *parsed_result,
3483                         __rte_unused struct cmdline *cl,
3484                         __rte_unused void *data)
3485 {
3486         struct cmd_config_thresh *res = parsed_result;
3487
3488         if (!all_ports_stopped()) {
3489                 printf("Please stop all ports first\n");
3490                 return;
3491         }
3492
3493         if (!strcmp(res->name, "txpt"))
3494                 tx_pthresh = res->value;
3495         else if(!strcmp(res->name, "txht"))
3496                 tx_hthresh = res->value;
3497         else if(!strcmp(res->name, "txwt"))
3498                 tx_wthresh = res->value;
3499         else if(!strcmp(res->name, "rxpt"))
3500                 rx_pthresh = res->value;
3501         else if(!strcmp(res->name, "rxht"))
3502                 rx_hthresh = res->value;
3503         else if(!strcmp(res->name, "rxwt"))
3504                 rx_wthresh = res->value;
3505         else {
3506                 printf("Unknown parameter\n");
3507                 return;
3508         }
3509
3510         init_port_config();
3511
3512         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3513 }
3514
3515 cmdline_parse_token_string_t cmd_config_thresh_port =
3516         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3517 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3518         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3519 cmdline_parse_token_string_t cmd_config_thresh_all =
3520         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3521 cmdline_parse_token_string_t cmd_config_thresh_name =
3522         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3523                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3524 cmdline_parse_token_num_t cmd_config_thresh_value =
3525         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3526
3527 cmdline_parse_inst_t cmd_config_thresh = {
3528         .f = cmd_config_thresh_parsed,
3529         .data = NULL,
3530         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3531         .tokens = {
3532                 (void *)&cmd_config_thresh_port,
3533                 (void *)&cmd_config_thresh_keyword,
3534                 (void *)&cmd_config_thresh_all,
3535                 (void *)&cmd_config_thresh_name,
3536                 (void *)&cmd_config_thresh_value,
3537                 NULL,
3538         },
3539 };
3540
3541 /* *** configure free/rs threshold *** */
3542 struct cmd_config_threshold {
3543         cmdline_fixed_string_t port;
3544         cmdline_fixed_string_t keyword;
3545         cmdline_fixed_string_t all;
3546         cmdline_fixed_string_t name;
3547         uint16_t value;
3548 };
3549
3550 static void
3551 cmd_config_threshold_parsed(void *parsed_result,
3552                         __rte_unused struct cmdline *cl,
3553                         __rte_unused void *data)
3554 {
3555         struct cmd_config_threshold *res = parsed_result;
3556
3557         if (!all_ports_stopped()) {
3558                 printf("Please stop all ports first\n");
3559                 return;
3560         }
3561
3562         if (!strcmp(res->name, "txfreet"))
3563                 tx_free_thresh = res->value;
3564         else if (!strcmp(res->name, "txrst"))
3565                 tx_rs_thresh = res->value;
3566         else if (!strcmp(res->name, "rxfreet"))
3567                 rx_free_thresh = res->value;
3568         else {
3569                 printf("Unknown parameter\n");
3570                 return;
3571         }
3572
3573         init_port_config();
3574
3575         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3576 }
3577
3578 cmdline_parse_token_string_t cmd_config_threshold_port =
3579         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3580 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3581         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3582                                                                 "config");
3583 cmdline_parse_token_string_t cmd_config_threshold_all =
3584         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3585 cmdline_parse_token_string_t cmd_config_threshold_name =
3586         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3587                                                 "txfreet#txrst#rxfreet");
3588 cmdline_parse_token_num_t cmd_config_threshold_value =
3589         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3590
3591 cmdline_parse_inst_t cmd_config_threshold = {
3592         .f = cmd_config_threshold_parsed,
3593         .data = NULL,
3594         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3595         .tokens = {
3596                 (void *)&cmd_config_threshold_port,
3597                 (void *)&cmd_config_threshold_keyword,
3598                 (void *)&cmd_config_threshold_all,
3599                 (void *)&cmd_config_threshold_name,
3600                 (void *)&cmd_config_threshold_value,
3601                 NULL,
3602         },
3603 };
3604
3605 /* *** stop *** */
3606 struct cmd_stop_result {
3607         cmdline_fixed_string_t stop;
3608 };
3609
3610 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3611                             __rte_unused struct cmdline *cl,
3612                             __rte_unused void *data)
3613 {
3614         stop_packet_forwarding();
3615 }
3616
3617 cmdline_parse_token_string_t cmd_stop_stop =
3618         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3619
3620 cmdline_parse_inst_t cmd_stop = {
3621         .f = cmd_stop_parsed,
3622         .data = NULL,
3623         .help_str = "stop: Stop packet forwarding",
3624         .tokens = {
3625                 (void *)&cmd_stop_stop,
3626                 NULL,
3627         },
3628 };
3629
3630 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3631
3632 unsigned int
3633 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3634                 unsigned int *parsed_items, int check_unique_values)
3635 {
3636         unsigned int nb_item;
3637         unsigned int value;
3638         unsigned int i;
3639         unsigned int j;
3640         int value_ok;
3641         char c;
3642
3643         /*
3644          * First parse all items in the list and store their value.
3645          */
3646         value = 0;
3647         nb_item = 0;
3648         value_ok = 0;
3649         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3650                 c = str[i];
3651                 if ((c >= '0') && (c <= '9')) {
3652                         value = (unsigned int) (value * 10 + (c - '0'));
3653                         value_ok = 1;
3654                         continue;
3655                 }
3656                 if (c != ',') {
3657                         printf("character %c is not a decimal digit\n", c);
3658                         return 0;
3659                 }
3660                 if (! value_ok) {
3661                         printf("No valid value before comma\n");
3662                         return 0;
3663                 }
3664                 if (nb_item < max_items) {
3665                         parsed_items[nb_item] = value;
3666                         value_ok = 0;
3667                         value = 0;
3668                 }
3669                 nb_item++;
3670         }
3671         if (nb_item >= max_items) {
3672                 printf("Number of %s = %u > %u (maximum items)\n",
3673                        item_name, nb_item + 1, max_items);
3674                 return 0;
3675         }
3676         parsed_items[nb_item++] = value;
3677         if (! check_unique_values)
3678                 return nb_item;
3679
3680         /*
3681          * Then, check that all values in the list are differents.
3682          * No optimization here...
3683          */
3684         for (i = 0; i < nb_item; i++) {
3685                 for (j = i + 1; j < nb_item; j++) {
3686                         if (parsed_items[j] == parsed_items[i]) {
3687                                 printf("duplicated %s %u at index %u and %u\n",
3688                                        item_name, parsed_items[i], i, j);
3689                                 return 0;
3690                         }
3691                 }
3692         }
3693         return nb_item;
3694 }
3695
3696 struct cmd_set_list_result {
3697         cmdline_fixed_string_t cmd_keyword;
3698         cmdline_fixed_string_t list_name;
3699         cmdline_fixed_string_t list_of_items;
3700 };
3701
3702 static void cmd_set_list_parsed(void *parsed_result,
3703                                 __rte_unused struct cmdline *cl,
3704                                 __rte_unused void *data)
3705 {
3706         struct cmd_set_list_result *res;
3707         union {
3708                 unsigned int lcorelist[RTE_MAX_LCORE];
3709                 unsigned int portlist[RTE_MAX_ETHPORTS];
3710         } parsed_items;
3711         unsigned int nb_item;
3712
3713         if (test_done == 0) {
3714                 printf("Please stop forwarding first\n");
3715                 return;
3716         }
3717
3718         res = parsed_result;
3719         if (!strcmp(res->list_name, "corelist")) {
3720                 nb_item = parse_item_list(res->list_of_items, "core",
3721                                           RTE_MAX_LCORE,
3722                                           parsed_items.lcorelist, 1);
3723                 if (nb_item > 0) {
3724                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3725                         fwd_config_setup();
3726                 }
3727                 return;
3728         }
3729         if (!strcmp(res->list_name, "portlist")) {
3730                 nb_item = parse_item_list(res->list_of_items, "port",
3731                                           RTE_MAX_ETHPORTS,
3732                                           parsed_items.portlist, 1);
3733                 if (nb_item > 0) {
3734                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3735                         fwd_config_setup();
3736                 }
3737         }
3738 }
3739
3740 cmdline_parse_token_string_t cmd_set_list_keyword =
3741         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3742                                  "set");
3743 cmdline_parse_token_string_t cmd_set_list_name =
3744         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3745                                  "corelist#portlist");
3746 cmdline_parse_token_string_t cmd_set_list_of_items =
3747         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3748                                  NULL);
3749
3750 cmdline_parse_inst_t cmd_set_fwd_list = {
3751         .f = cmd_set_list_parsed,
3752         .data = NULL,
3753         .help_str = "set corelist|portlist <list0[,list1]*>",
3754         .tokens = {
3755                 (void *)&cmd_set_list_keyword,
3756                 (void *)&cmd_set_list_name,
3757                 (void *)&cmd_set_list_of_items,
3758                 NULL,
3759         },
3760 };
3761
3762 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3763
3764 struct cmd_setmask_result {
3765         cmdline_fixed_string_t set;
3766         cmdline_fixed_string_t mask;
3767         uint64_t hexavalue;
3768 };
3769
3770 static void cmd_set_mask_parsed(void *parsed_result,
3771                                 __rte_unused struct cmdline *cl,
3772                                 __rte_unused void *data)
3773 {
3774         struct cmd_setmask_result *res = parsed_result;
3775
3776         if (test_done == 0) {
3777                 printf("Please stop forwarding first\n");
3778                 return;
3779         }
3780         if (!strcmp(res->mask, "coremask")) {
3781                 set_fwd_lcores_mask(res->hexavalue);
3782                 fwd_config_setup();
3783         } else if (!strcmp(res->mask, "portmask")) {
3784                 set_fwd_ports_mask(res->hexavalue);
3785                 fwd_config_setup();
3786         }
3787 }
3788
3789 cmdline_parse_token_string_t cmd_setmask_set =
3790         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3791 cmdline_parse_token_string_t cmd_setmask_mask =
3792         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3793                                  "coremask#portmask");
3794 cmdline_parse_token_num_t cmd_setmask_value =
3795         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3796
3797 cmdline_parse_inst_t cmd_set_fwd_mask = {
3798         .f = cmd_set_mask_parsed,
3799         .data = NULL,
3800         .help_str = "set coremask|portmask <hexadecimal value>",
3801         .tokens = {
3802                 (void *)&cmd_setmask_set,
3803                 (void *)&cmd_setmask_mask,
3804                 (void *)&cmd_setmask_value,
3805                 NULL,
3806         },
3807 };
3808
3809 /*
3810  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3811  */
3812 struct cmd_set_result {
3813         cmdline_fixed_string_t set;
3814         cmdline_fixed_string_t what;
3815         uint16_t value;
3816 };
3817
3818 static void cmd_set_parsed(void *parsed_result,
3819                            __rte_unused struct cmdline *cl,
3820                            __rte_unused void *data)
3821 {
3822         struct cmd_set_result *res = parsed_result;
3823         if (!strcmp(res->what, "nbport")) {
3824                 set_fwd_ports_number(res->value);
3825                 fwd_config_setup();
3826         } else if (!strcmp(res->what, "nbcore")) {
3827                 set_fwd_lcores_number(res->value);
3828                 fwd_config_setup();
3829         } else if (!strcmp(res->what, "burst"))
3830                 set_nb_pkt_per_burst(res->value);
3831         else if (!strcmp(res->what, "verbose"))
3832                 set_verbose_level(res->value);
3833 }
3834
3835 cmdline_parse_token_string_t cmd_set_set =
3836         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3837 cmdline_parse_token_string_t cmd_set_what =
3838         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3839                                  "nbport#nbcore#burst#verbose");
3840 cmdline_parse_token_num_t cmd_set_value =
3841         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3842
3843 cmdline_parse_inst_t cmd_set_numbers = {
3844         .f = cmd_set_parsed,
3845         .data = NULL,
3846         .help_str = "set nbport|nbcore|burst|verbose <value>",
3847         .tokens = {
3848                 (void *)&cmd_set_set,
3849                 (void *)&cmd_set_what,
3850                 (void *)&cmd_set_value,
3851                 NULL,
3852         },
3853 };
3854
3855 /* *** SET LOG LEVEL CONFIGURATION *** */
3856
3857 struct cmd_set_log_result {
3858         cmdline_fixed_string_t set;
3859         cmdline_fixed_string_t log;
3860         cmdline_fixed_string_t type;
3861         uint32_t level;
3862 };
3863
3864 static void
3865 cmd_set_log_parsed(void *parsed_result,
3866                    __rte_unused struct cmdline *cl,
3867                    __rte_unused void *data)
3868 {
3869         struct cmd_set_log_result *res;
3870         int ret;
3871
3872         res = parsed_result;
3873         if (!strcmp(res->type, "global"))
3874                 rte_log_set_global_level(res->level);
3875         else {
3876                 ret = rte_log_set_level_regexp(res->type, res->level);
3877                 if (ret < 0)
3878                         printf("Unable to set log level\n");
3879         }
3880 }
3881
3882 cmdline_parse_token_string_t cmd_set_log_set =
3883         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3884 cmdline_parse_token_string_t cmd_set_log_log =
3885         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3886 cmdline_parse_token_string_t cmd_set_log_type =
3887         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3888 cmdline_parse_token_num_t cmd_set_log_level =
3889         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3890
3891 cmdline_parse_inst_t cmd_set_log = {
3892         .f = cmd_set_log_parsed,
3893         .data = NULL,
3894         .help_str = "set log global|<type> <level>",
3895         .tokens = {
3896                 (void *)&cmd_set_log_set,
3897                 (void *)&cmd_set_log_log,
3898                 (void *)&cmd_set_log_type,
3899                 (void *)&cmd_set_log_level,
3900                 NULL,
3901         },
3902 };
3903
3904 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3905
3906 struct cmd_set_rxoffs_result {
3907         cmdline_fixed_string_t cmd_keyword;
3908         cmdline_fixed_string_t rxoffs;
3909         cmdline_fixed_string_t seg_offsets;
3910 };
3911
3912 static void
3913 cmd_set_rxoffs_parsed(void *parsed_result,
3914                       __rte_unused struct cmdline *cl,
3915                       __rte_unused void *data)
3916 {
3917         struct cmd_set_rxoffs_result *res;
3918         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3919         unsigned int nb_segs;
3920
3921         res = parsed_result;
3922         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3923                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3924         if (nb_segs > 0)
3925                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3926 }
3927
3928 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3929         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3930                                  cmd_keyword, "set");
3931 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3932         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3933                                  rxoffs, "rxoffs");
3934 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3935         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3936                                  seg_offsets, NULL);
3937
3938 cmdline_parse_inst_t cmd_set_rxoffs = {
3939         .f = cmd_set_rxoffs_parsed,
3940         .data = NULL,
3941         .help_str = "set rxoffs <len0[,len1]*>",
3942         .tokens = {
3943                 (void *)&cmd_set_rxoffs_keyword,
3944                 (void *)&cmd_set_rxoffs_name,
3945                 (void *)&cmd_set_rxoffs_offsets,
3946                 NULL,
3947         },
3948 };
3949
3950 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3951
3952 struct cmd_set_rxpkts_result {
3953         cmdline_fixed_string_t cmd_keyword;
3954         cmdline_fixed_string_t rxpkts;
3955         cmdline_fixed_string_t seg_lengths;
3956 };
3957
3958 static void
3959 cmd_set_rxpkts_parsed(void *parsed_result,
3960                       __rte_unused struct cmdline *cl,
3961                       __rte_unused void *data)
3962 {
3963         struct cmd_set_rxpkts_result *res;
3964         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3965         unsigned int nb_segs;
3966
3967         res = parsed_result;
3968         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3969                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3970         if (nb_segs > 0)
3971                 set_rx_pkt_segments(seg_lengths, nb_segs);
3972 }
3973
3974 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3975         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3976                                  cmd_keyword, "set");
3977 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3978         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3979                                  rxpkts, "rxpkts");
3980 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3981         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3982                                  seg_lengths, NULL);
3983
3984 cmdline_parse_inst_t cmd_set_rxpkts = {
3985         .f = cmd_set_rxpkts_parsed,
3986         .data = NULL,
3987         .help_str = "set rxpkts <len0[,len1]*>",
3988         .tokens = {
3989                 (void *)&cmd_set_rxpkts_keyword,
3990                 (void *)&cmd_set_rxpkts_name,
3991                 (void *)&cmd_set_rxpkts_lengths,
3992                 NULL,
3993         },
3994 };
3995
3996 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3997
3998 struct cmd_set_txpkts_result {
3999         cmdline_fixed_string_t cmd_keyword;
4000         cmdline_fixed_string_t txpkts;
4001         cmdline_fixed_string_t seg_lengths;
4002 };
4003
4004 static void
4005 cmd_set_txpkts_parsed(void *parsed_result,
4006                       __rte_unused struct cmdline *cl,
4007                       __rte_unused void *data)
4008 {
4009         struct cmd_set_txpkts_result *res;
4010         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4011         unsigned int nb_segs;
4012
4013         res = parsed_result;
4014         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4015                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4016         if (nb_segs > 0)
4017                 set_tx_pkt_segments(seg_lengths, nb_segs);
4018 }
4019
4020 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4021         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4022                                  cmd_keyword, "set");
4023 cmdline_parse_token_string_t cmd_set_txpkts_name =
4024         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4025                                  txpkts, "txpkts");
4026 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4027         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4028                                  seg_lengths, NULL);
4029
4030 cmdline_parse_inst_t cmd_set_txpkts = {
4031         .f = cmd_set_txpkts_parsed,
4032         .data = NULL,
4033         .help_str = "set txpkts <len0[,len1]*>",
4034         .tokens = {
4035                 (void *)&cmd_set_txpkts_keyword,
4036                 (void *)&cmd_set_txpkts_name,
4037                 (void *)&cmd_set_txpkts_lengths,
4038                 NULL,
4039         },
4040 };
4041
4042 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4043
4044 struct cmd_set_txsplit_result {
4045         cmdline_fixed_string_t cmd_keyword;
4046         cmdline_fixed_string_t txsplit;
4047         cmdline_fixed_string_t mode;
4048 };
4049
4050 static void
4051 cmd_set_txsplit_parsed(void *parsed_result,
4052                       __rte_unused struct cmdline *cl,
4053                       __rte_unused void *data)
4054 {
4055         struct cmd_set_txsplit_result *res;
4056
4057         res = parsed_result;
4058         set_tx_pkt_split(res->mode);
4059 }
4060
4061 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4062         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4063                                  cmd_keyword, "set");
4064 cmdline_parse_token_string_t cmd_set_txsplit_name =
4065         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4066                                  txsplit, "txsplit");
4067 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4068         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4069                                  mode, NULL);
4070
4071 cmdline_parse_inst_t cmd_set_txsplit = {
4072         .f = cmd_set_txsplit_parsed,
4073         .data = NULL,
4074         .help_str = "set txsplit on|off|rand",
4075         .tokens = {
4076                 (void *)&cmd_set_txsplit_keyword,
4077                 (void *)&cmd_set_txsplit_name,
4078                 (void *)&cmd_set_txsplit_mode,
4079                 NULL,
4080         },
4081 };
4082
4083 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4084
4085 struct cmd_set_txtimes_result {
4086         cmdline_fixed_string_t cmd_keyword;
4087         cmdline_fixed_string_t txtimes;
4088         cmdline_fixed_string_t tx_times;
4089 };
4090
4091 static void
4092 cmd_set_txtimes_parsed(void *parsed_result,
4093                        __rte_unused struct cmdline *cl,
4094                        __rte_unused void *data)
4095 {
4096         struct cmd_set_txtimes_result *res;
4097         unsigned int tx_times[2] = {0, 0};
4098         unsigned int n_times;
4099
4100         res = parsed_result;
4101         n_times = parse_item_list(res->tx_times, "tx times",
4102                                   2, tx_times, 0);
4103         if (n_times == 2)
4104                 set_tx_pkt_times(tx_times);
4105 }
4106
4107 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4108         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4109                                  cmd_keyword, "set");
4110 cmdline_parse_token_string_t cmd_set_txtimes_name =
4111         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4112                                  txtimes, "txtimes");
4113 cmdline_parse_token_string_t cmd_set_txtimes_value =
4114         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4115                                  tx_times, NULL);
4116
4117 cmdline_parse_inst_t cmd_set_txtimes = {
4118         .f = cmd_set_txtimes_parsed,
4119         .data = NULL,
4120         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4121         .tokens = {
4122                 (void *)&cmd_set_txtimes_keyword,
4123                 (void *)&cmd_set_txtimes_name,
4124                 (void *)&cmd_set_txtimes_value,
4125                 NULL,
4126         },
4127 };
4128
4129 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4130 struct cmd_rx_vlan_filter_all_result {
4131         cmdline_fixed_string_t rx_vlan;
4132         cmdline_fixed_string_t what;
4133         cmdline_fixed_string_t all;
4134         portid_t port_id;
4135 };
4136
4137 static void
4138 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4139                               __rte_unused struct cmdline *cl,
4140                               __rte_unused void *data)
4141 {
4142         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4143
4144         if (!strcmp(res->what, "add"))
4145                 rx_vlan_all_filter_set(res->port_id, 1);
4146         else
4147                 rx_vlan_all_filter_set(res->port_id, 0);
4148 }
4149
4150 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4151         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4152                                  rx_vlan, "rx_vlan");
4153 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4154         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4155                                  what, "add#rm");
4156 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4157         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4158                                  all, "all");
4159 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4160         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4161                               port_id, UINT16);
4162
4163 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4164         .f = cmd_rx_vlan_filter_all_parsed,
4165         .data = NULL,
4166         .help_str = "rx_vlan add|rm all <port_id>: "
4167                 "Add/Remove all identifiers to/from the set of VLAN "
4168                 "identifiers filtered by a port",
4169         .tokens = {
4170                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4171                 (void *)&cmd_rx_vlan_filter_all_what,
4172                 (void *)&cmd_rx_vlan_filter_all_all,
4173                 (void *)&cmd_rx_vlan_filter_all_portid,
4174                 NULL,
4175         },
4176 };
4177
4178 /* *** VLAN OFFLOAD SET ON A PORT *** */
4179 struct cmd_vlan_offload_result {
4180         cmdline_fixed_string_t vlan;
4181         cmdline_fixed_string_t set;
4182         cmdline_fixed_string_t vlan_type;
4183         cmdline_fixed_string_t what;
4184         cmdline_fixed_string_t on;
4185         cmdline_fixed_string_t port_id;
4186 };
4187
4188 static void
4189 cmd_vlan_offload_parsed(void *parsed_result,
4190                           __rte_unused struct cmdline *cl,
4191                           __rte_unused void *data)
4192 {
4193         int on;
4194         struct cmd_vlan_offload_result *res = parsed_result;
4195         char *str;
4196         int i, len = 0;
4197         portid_t port_id = 0;
4198         unsigned int tmp;
4199
4200         str = res->port_id;
4201         len = strnlen(str, STR_TOKEN_SIZE);
4202         i = 0;
4203         /* Get port_id first */
4204         while(i < len){
4205                 if(str[i] == ',')
4206                         break;
4207
4208                 i++;
4209         }
4210         str[i]='\0';
4211         tmp = strtoul(str, NULL, 0);
4212         /* If port_id greater that what portid_t can represent, return */
4213         if(tmp >= RTE_MAX_ETHPORTS)
4214                 return;
4215         port_id = (portid_t)tmp;
4216
4217         if (!strcmp(res->on, "on"))
4218                 on = 1;
4219         else
4220                 on = 0;
4221
4222         if (!strcmp(res->what, "strip"))
4223                 rx_vlan_strip_set(port_id,  on);
4224         else if(!strcmp(res->what, "stripq")){
4225                 uint16_t queue_id = 0;
4226
4227                 /* No queue_id, return */
4228                 if(i + 1 >= len) {
4229                         printf("must specify (port,queue_id)\n");
4230                         return;
4231                 }
4232                 tmp = strtoul(str + i + 1, NULL, 0);
4233                 /* If queue_id greater that what 16-bits can represent, return */
4234                 if(tmp > 0xffff)
4235                         return;
4236
4237                 queue_id = (uint16_t)tmp;
4238                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4239         }
4240         else if (!strcmp(res->what, "filter"))
4241                 rx_vlan_filter_set(port_id, on);
4242         else if (!strcmp(res->what, "qinq_strip"))
4243                 rx_vlan_qinq_strip_set(port_id, on);
4244         else
4245                 vlan_extend_set(port_id, on);
4246
4247         return;
4248 }
4249
4250 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4251         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4252                                  vlan, "vlan");
4253 cmdline_parse_token_string_t cmd_vlan_offload_set =
4254         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4255                                  set, "set");
4256 cmdline_parse_token_string_t cmd_vlan_offload_what =
4257         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4258                                 what, "strip#filter#qinq_strip#extend#stripq");
4259 cmdline_parse_token_string_t cmd_vlan_offload_on =
4260         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4261                               on, "on#off");
4262 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4263         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4264                               port_id, NULL);
4265
4266 cmdline_parse_inst_t cmd_vlan_offload = {
4267         .f = cmd_vlan_offload_parsed,
4268         .data = NULL,
4269         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4270                 "<port_id[,queue_id]>: "
4271                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4272         .tokens = {
4273                 (void *)&cmd_vlan_offload_vlan,
4274                 (void *)&cmd_vlan_offload_set,
4275                 (void *)&cmd_vlan_offload_what,
4276                 (void *)&cmd_vlan_offload_on,
4277                 (void *)&cmd_vlan_offload_portid,
4278                 NULL,
4279         },
4280 };
4281
4282 /* *** VLAN TPID SET ON A PORT *** */
4283 struct cmd_vlan_tpid_result {
4284         cmdline_fixed_string_t vlan;
4285         cmdline_fixed_string_t set;
4286         cmdline_fixed_string_t vlan_type;
4287         cmdline_fixed_string_t what;
4288         uint16_t tp_id;
4289         portid_t port_id;
4290 };
4291
4292 static void
4293 cmd_vlan_tpid_parsed(void *parsed_result,
4294                           __rte_unused struct cmdline *cl,
4295                           __rte_unused void *data)
4296 {
4297         struct cmd_vlan_tpid_result *res = parsed_result;
4298         enum rte_vlan_type vlan_type;
4299
4300         if (!strcmp(res->vlan_type, "inner"))
4301                 vlan_type = ETH_VLAN_TYPE_INNER;
4302         else if (!strcmp(res->vlan_type, "outer"))
4303                 vlan_type = ETH_VLAN_TYPE_OUTER;
4304         else {
4305                 printf("Unknown vlan type\n");
4306                 return;
4307         }
4308         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4309 }
4310
4311 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4312         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4313                                  vlan, "vlan");
4314 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4315         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4316                                  set, "set");
4317 cmdline_parse_token_string_t cmd_vlan_type =
4318         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4319                                  vlan_type, "inner#outer");
4320 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4321         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4322                                  what, "tpid");
4323 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4324         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4325                               tp_id, UINT16);
4326 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4327         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4328                               port_id, UINT16);
4329
4330 cmdline_parse_inst_t cmd_vlan_tpid = {
4331         .f = cmd_vlan_tpid_parsed,
4332         .data = NULL,
4333         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4334                 "Set the VLAN Ether type",
4335         .tokens = {
4336                 (void *)&cmd_vlan_tpid_vlan,
4337                 (void *)&cmd_vlan_tpid_set,
4338                 (void *)&cmd_vlan_type,
4339                 (void *)&cmd_vlan_tpid_what,
4340                 (void *)&cmd_vlan_tpid_tpid,
4341                 (void *)&cmd_vlan_tpid_portid,
4342                 NULL,
4343         },
4344 };
4345
4346 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4347 struct cmd_rx_vlan_filter_result {
4348         cmdline_fixed_string_t rx_vlan;
4349         cmdline_fixed_string_t what;
4350         uint16_t vlan_id;
4351         portid_t port_id;
4352 };
4353
4354 static void
4355 cmd_rx_vlan_filter_parsed(void *parsed_result,
4356                           __rte_unused struct cmdline *cl,
4357                           __rte_unused void *data)
4358 {
4359         struct cmd_rx_vlan_filter_result *res = parsed_result;
4360
4361         if (!strcmp(res->what, "add"))
4362                 rx_vft_set(res->port_id, res->vlan_id, 1);
4363         else
4364                 rx_vft_set(res->port_id, res->vlan_id, 0);
4365 }
4366
4367 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4368         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4369                                  rx_vlan, "rx_vlan");
4370 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4371         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4372                                  what, "add#rm");
4373 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4374         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4375                               vlan_id, UINT16);
4376 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4377         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4378                               port_id, UINT16);
4379
4380 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4381         .f = cmd_rx_vlan_filter_parsed,
4382         .data = NULL,
4383         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4384                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4385                 "identifiers filtered by a port",
4386         .tokens = {
4387                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4388                 (void *)&cmd_rx_vlan_filter_what,
4389                 (void *)&cmd_rx_vlan_filter_vlanid,
4390                 (void *)&cmd_rx_vlan_filter_portid,
4391                 NULL,
4392         },
4393 };
4394
4395 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4396 struct cmd_tx_vlan_set_result {
4397         cmdline_fixed_string_t tx_vlan;
4398         cmdline_fixed_string_t set;
4399         portid_t port_id;
4400         uint16_t vlan_id;
4401 };
4402
4403 static void
4404 cmd_tx_vlan_set_parsed(void *parsed_result,
4405                        __rte_unused struct cmdline *cl,
4406                        __rte_unused void *data)
4407 {
4408         struct cmd_tx_vlan_set_result *res = parsed_result;
4409
4410         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4411                 return;
4412
4413         if (!port_is_stopped(res->port_id)) {
4414                 printf("Please stop port %d first\n", res->port_id);
4415                 return;
4416         }
4417
4418         tx_vlan_set(res->port_id, res->vlan_id);
4419
4420         cmd_reconfig_device_queue(res->port_id, 1, 1);
4421 }
4422
4423 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4424         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4425                                  tx_vlan, "tx_vlan");
4426 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4427         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4428                                  set, "set");
4429 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4430         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4431                               port_id, UINT16);
4432 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4433         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4434                               vlan_id, UINT16);
4435
4436 cmdline_parse_inst_t cmd_tx_vlan_set = {
4437         .f = cmd_tx_vlan_set_parsed,
4438         .data = NULL,
4439         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4440                 "Enable hardware insertion of a single VLAN header "
4441                 "with a given TAG Identifier in packets sent on a port",
4442         .tokens = {
4443                 (void *)&cmd_tx_vlan_set_tx_vlan,
4444                 (void *)&cmd_tx_vlan_set_set,
4445                 (void *)&cmd_tx_vlan_set_portid,
4446                 (void *)&cmd_tx_vlan_set_vlanid,
4447                 NULL,
4448         },
4449 };
4450
4451 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4452 struct cmd_tx_vlan_set_qinq_result {
4453         cmdline_fixed_string_t tx_vlan;
4454         cmdline_fixed_string_t set;
4455         portid_t port_id;
4456         uint16_t vlan_id;
4457         uint16_t vlan_id_outer;
4458 };
4459
4460 static void
4461 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4462                             __rte_unused struct cmdline *cl,
4463                             __rte_unused void *data)
4464 {
4465         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4466
4467         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4468                 return;
4469
4470         if (!port_is_stopped(res->port_id)) {
4471                 printf("Please stop port %d first\n", res->port_id);
4472                 return;
4473         }
4474
4475         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4476
4477         cmd_reconfig_device_queue(res->port_id, 1, 1);
4478 }
4479
4480 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4481         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4482                 tx_vlan, "tx_vlan");
4483 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4484         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4485                 set, "set");
4486 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4487         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4488                 port_id, UINT16);
4489 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4490         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4491                 vlan_id, UINT16);
4492 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4493         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4494                 vlan_id_outer, UINT16);
4495
4496 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4497         .f = cmd_tx_vlan_set_qinq_parsed,
4498         .data = NULL,
4499         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4500                 "Enable hardware insertion of double VLAN header "
4501                 "with given TAG Identifiers in packets sent on a port",
4502         .tokens = {
4503                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4504                 (void *)&cmd_tx_vlan_set_qinq_set,
4505                 (void *)&cmd_tx_vlan_set_qinq_portid,
4506                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4507                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4508                 NULL,
4509         },
4510 };
4511
4512 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4513 struct cmd_tx_vlan_set_pvid_result {
4514         cmdline_fixed_string_t tx_vlan;
4515         cmdline_fixed_string_t set;
4516         cmdline_fixed_string_t pvid;
4517         portid_t port_id;
4518         uint16_t vlan_id;
4519         cmdline_fixed_string_t mode;
4520 };
4521
4522 static void
4523 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4524                             __rte_unused struct cmdline *cl,
4525                             __rte_unused void *data)
4526 {
4527         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4528
4529         if (strcmp(res->mode, "on") == 0)
4530                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4531         else
4532                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4533 }
4534
4535 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4536         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4537                                  tx_vlan, "tx_vlan");
4538 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4539         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4540                                  set, "set");
4541 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4542         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4543                                  pvid, "pvid");
4544 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4545         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4546                              port_id, UINT16);
4547 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4548         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4549                               vlan_id, UINT16);
4550 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4551         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4552                                  mode, "on#off");
4553
4554 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4555         .f = cmd_tx_vlan_set_pvid_parsed,
4556         .data = NULL,
4557         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4558         .tokens = {
4559                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4560                 (void *)&cmd_tx_vlan_set_pvid_set,
4561                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4562                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4563                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4564                 (void *)&cmd_tx_vlan_set_pvid_mode,
4565                 NULL,
4566         },
4567 };
4568
4569 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4570 struct cmd_tx_vlan_reset_result {
4571         cmdline_fixed_string_t tx_vlan;
4572         cmdline_fixed_string_t reset;
4573         portid_t port_id;
4574 };
4575
4576 static void
4577 cmd_tx_vlan_reset_parsed(void *parsed_result,
4578                          __rte_unused struct cmdline *cl,
4579                          __rte_unused void *data)
4580 {
4581         struct cmd_tx_vlan_reset_result *res = parsed_result;
4582
4583         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4584                 return;
4585
4586         if (!port_is_stopped(res->port_id)) {
4587                 printf("Please stop port %d first\n", res->port_id);
4588                 return;
4589         }
4590
4591         tx_vlan_reset(res->port_id);
4592
4593         cmd_reconfig_device_queue(res->port_id, 1, 1);
4594 }
4595
4596 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4597         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4598                                  tx_vlan, "tx_vlan");
4599 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4600         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4601                                  reset, "reset");
4602 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4603         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4604                               port_id, UINT16);
4605
4606 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4607         .f = cmd_tx_vlan_reset_parsed,
4608         .data = NULL,
4609         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4610                 "VLAN header in packets sent on a port",
4611         .tokens = {
4612                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4613                 (void *)&cmd_tx_vlan_reset_reset,
4614                 (void *)&cmd_tx_vlan_reset_portid,
4615                 NULL,
4616         },
4617 };
4618
4619
4620 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4621 struct cmd_csum_result {
4622         cmdline_fixed_string_t csum;
4623         cmdline_fixed_string_t mode;
4624         cmdline_fixed_string_t proto;
4625         cmdline_fixed_string_t hwsw;
4626         portid_t port_id;
4627 };
4628
4629 static void
4630 csum_show(int port_id)
4631 {
4632         struct rte_eth_dev_info dev_info;
4633         uint64_t tx_offloads;
4634         int ret;
4635
4636         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4637         printf("Parse tunnel is %s\n",
4638                 (ports[port_id].parse_tunnel) ? "on" : "off");
4639         printf("IP checksum offload is %s\n",
4640                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4641         printf("UDP checksum offload is %s\n",
4642                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4643         printf("TCP checksum offload is %s\n",
4644                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4645         printf("SCTP checksum offload is %s\n",
4646                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4647         printf("Outer-Ip checksum offload is %s\n",
4648                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4649         printf("Outer-Udp checksum offload is %s\n",
4650                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4651
4652         /* display warnings if configuration is not supported by the NIC */
4653         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4654         if (ret != 0)
4655                 return;
4656
4657         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4658                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4659                 printf("Warning: hardware IP checksum enabled but not "
4660                         "supported by port %d\n", port_id);
4661         }
4662         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4663                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4664                 printf("Warning: hardware UDP checksum enabled but not "
4665                         "supported by port %d\n", port_id);
4666         }
4667         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4668                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4669                 printf("Warning: hardware TCP checksum enabled but not "
4670                         "supported by port %d\n", port_id);
4671         }
4672         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4673                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4674                 printf("Warning: hardware SCTP checksum enabled but not "
4675                         "supported by port %d\n", port_id);
4676         }
4677         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4678                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4679                 printf("Warning: hardware outer IP checksum enabled but not "
4680                         "supported by port %d\n", port_id);
4681         }
4682         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4683                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4684                         == 0) {
4685                 printf("Warning: hardware outer UDP checksum enabled but not "
4686                         "supported by port %d\n", port_id);
4687         }
4688 }
4689
4690 static void
4691 cmd_config_queue_tx_offloads(struct rte_port *port)
4692 {
4693         int k;
4694
4695         /* Apply queue tx offloads configuration */
4696         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4697                 port->tx_conf[k].offloads =
4698                         port->dev_conf.txmode.offloads;
4699 }
4700
4701 static void
4702 cmd_csum_parsed(void *parsed_result,
4703                        __rte_unused struct cmdline *cl,
4704                        __rte_unused void *data)
4705 {
4706         struct cmd_csum_result *res = parsed_result;
4707         int hw = 0;
4708         uint64_t csum_offloads = 0;
4709         struct rte_eth_dev_info dev_info;
4710         int ret;
4711
4712         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4713                 printf("invalid port %d\n", res->port_id);
4714                 return;
4715         }
4716         if (!port_is_stopped(res->port_id)) {
4717                 printf("Please stop port %d first\n", res->port_id);
4718                 return;
4719         }
4720
4721         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4722         if (ret != 0)
4723                 return;
4724
4725         if (!strcmp(res->mode, "set")) {
4726
4727                 if (!strcmp(res->hwsw, "hw"))
4728                         hw = 1;
4729
4730                 if (!strcmp(res->proto, "ip")) {
4731                         if (hw == 0 || (dev_info.tx_offload_capa &
4732                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4733                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4734                         } else {
4735                                 printf("IP checksum offload is not supported "
4736                                        "by port %u\n", res->port_id);
4737                         }
4738                 } else if (!strcmp(res->proto, "udp")) {
4739                         if (hw == 0 || (dev_info.tx_offload_capa &
4740                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4741                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4742                         } else {
4743                                 printf("UDP checksum offload is not supported "
4744                                        "by port %u\n", res->port_id);
4745                         }
4746                 } else if (!strcmp(res->proto, "tcp")) {
4747                         if (hw == 0 || (dev_info.tx_offload_capa &
4748                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4749                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4750                         } else {
4751                                 printf("TCP checksum offload is not supported "
4752                                        "by port %u\n", res->port_id);
4753                         }
4754                 } else if (!strcmp(res->proto, "sctp")) {
4755                         if (hw == 0 || (dev_info.tx_offload_capa &
4756                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4757                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4758                         } else {
4759                                 printf("SCTP checksum offload is not supported "
4760                                        "by port %u\n", res->port_id);
4761                         }
4762                 } else if (!strcmp(res->proto, "outer-ip")) {
4763                         if (hw == 0 || (dev_info.tx_offload_capa &
4764                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4765                                 csum_offloads |=
4766                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4767                         } else {
4768                                 printf("Outer IP checksum offload is not "
4769                                        "supported by port %u\n", res->port_id);
4770                         }
4771                 } else if (!strcmp(res->proto, "outer-udp")) {
4772                         if (hw == 0 || (dev_info.tx_offload_capa &
4773                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4774                                 csum_offloads |=
4775                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4776                         } else {
4777                                 printf("Outer UDP checksum offload is not "
4778                                        "supported by port %u\n", res->port_id);
4779                         }
4780                 }
4781
4782                 if (hw) {
4783                         ports[res->port_id].dev_conf.txmode.offloads |=
4784                                                         csum_offloads;
4785                 } else {
4786                         ports[res->port_id].dev_conf.txmode.offloads &=
4787                                                         (~csum_offloads);
4788                 }
4789                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4790         }
4791         csum_show(res->port_id);
4792
4793         cmd_reconfig_device_queue(res->port_id, 1, 1);
4794 }
4795
4796 cmdline_parse_token_string_t cmd_csum_csum =
4797         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4798                                 csum, "csum");
4799 cmdline_parse_token_string_t cmd_csum_mode =
4800         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4801                                 mode, "set");
4802 cmdline_parse_token_string_t cmd_csum_proto =
4803         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4804                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4805 cmdline_parse_token_string_t cmd_csum_hwsw =
4806         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4807                                 hwsw, "hw#sw");
4808 cmdline_parse_token_num_t cmd_csum_portid =
4809         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4810                                 port_id, UINT16);
4811
4812 cmdline_parse_inst_t cmd_csum_set = {
4813         .f = cmd_csum_parsed,
4814         .data = NULL,
4815         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4816                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4817                 "using csum forward engine",
4818         .tokens = {
4819                 (void *)&cmd_csum_csum,
4820                 (void *)&cmd_csum_mode,
4821                 (void *)&cmd_csum_proto,
4822                 (void *)&cmd_csum_hwsw,
4823                 (void *)&cmd_csum_portid,
4824                 NULL,
4825         },
4826 };
4827
4828 cmdline_parse_token_string_t cmd_csum_mode_show =
4829         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4830                                 mode, "show");
4831
4832 cmdline_parse_inst_t cmd_csum_show = {
4833         .f = cmd_csum_parsed,
4834         .data = NULL,
4835         .help_str = "csum show <port_id>: Show checksum offload configuration",
4836         .tokens = {
4837                 (void *)&cmd_csum_csum,
4838                 (void *)&cmd_csum_mode_show,
4839                 (void *)&cmd_csum_portid,
4840                 NULL,
4841         },
4842 };
4843
4844 /* Enable/disable tunnel parsing */
4845 struct cmd_csum_tunnel_result {
4846         cmdline_fixed_string_t csum;
4847         cmdline_fixed_string_t parse;
4848         cmdline_fixed_string_t onoff;
4849         portid_t port_id;
4850 };
4851
4852 static void
4853 cmd_csum_tunnel_parsed(void *parsed_result,
4854                        __rte_unused struct cmdline *cl,
4855                        __rte_unused void *data)
4856 {
4857         struct cmd_csum_tunnel_result *res = parsed_result;
4858
4859         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4860                 return;
4861
4862         if (!strcmp(res->onoff, "on"))
4863                 ports[res->port_id].parse_tunnel = 1;
4864         else
4865                 ports[res->port_id].parse_tunnel = 0;
4866
4867         csum_show(res->port_id);
4868 }
4869
4870 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4871         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4872                                 csum, "csum");
4873 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4874         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4875                                 parse, "parse-tunnel");
4876 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4877         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4878                                 onoff, "on#off");
4879 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4880         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4881                                 port_id, UINT16);
4882
4883 cmdline_parse_inst_t cmd_csum_tunnel = {
4884         .f = cmd_csum_tunnel_parsed,
4885         .data = NULL,
4886         .help_str = "csum parse-tunnel on|off <port_id>: "
4887                 "Enable/Disable parsing of tunnels for csum engine",
4888         .tokens = {
4889                 (void *)&cmd_csum_tunnel_csum,
4890                 (void *)&cmd_csum_tunnel_parse,
4891                 (void *)&cmd_csum_tunnel_onoff,
4892                 (void *)&cmd_csum_tunnel_portid,
4893                 NULL,
4894         },
4895 };
4896
4897 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4898 struct cmd_tso_set_result {
4899         cmdline_fixed_string_t tso;
4900         cmdline_fixed_string_t mode;
4901         uint16_t tso_segsz;
4902         portid_t port_id;
4903 };
4904
4905 static void
4906 cmd_tso_set_parsed(void *parsed_result,
4907                        __rte_unused struct cmdline *cl,
4908                        __rte_unused void *data)
4909 {
4910         struct cmd_tso_set_result *res = parsed_result;
4911         struct rte_eth_dev_info dev_info;
4912         int ret;
4913
4914         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4915                 return;
4916         if (!port_is_stopped(res->port_id)) {
4917                 printf("Please stop port %d first\n", res->port_id);
4918                 return;
4919         }
4920
4921         if (!strcmp(res->mode, "set"))
4922                 ports[res->port_id].tso_segsz = res->tso_segsz;
4923
4924         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4925         if (ret != 0)
4926                 return;
4927
4928         if ((ports[res->port_id].tso_segsz != 0) &&
4929                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4930                 printf("Error: TSO is not supported by port %d\n",
4931                        res->port_id);
4932                 return;
4933         }
4934
4935         if (ports[res->port_id].tso_segsz == 0) {
4936                 ports[res->port_id].dev_conf.txmode.offloads &=
4937                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4938                 printf("TSO for non-tunneled packets is disabled\n");
4939         } else {
4940                 ports[res->port_id].dev_conf.txmode.offloads |=
4941                                                 DEV_TX_OFFLOAD_TCP_TSO;
4942                 printf("TSO segment size for non-tunneled packets is %d\n",
4943                         ports[res->port_id].tso_segsz);
4944         }
4945         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4946
4947         /* display warnings if configuration is not supported by the NIC */
4948         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4949         if (ret != 0)
4950                 return;
4951
4952         if ((ports[res->port_id].tso_segsz != 0) &&
4953                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4954                 printf("Warning: TSO enabled but not "
4955                         "supported by port %d\n", res->port_id);
4956         }
4957
4958         cmd_reconfig_device_queue(res->port_id, 1, 1);
4959 }
4960
4961 cmdline_parse_token_string_t cmd_tso_set_tso =
4962         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4963                                 tso, "tso");
4964 cmdline_parse_token_string_t cmd_tso_set_mode =
4965         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4966                                 mode, "set");
4967 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4968         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4969                                 tso_segsz, UINT16);
4970 cmdline_parse_token_num_t cmd_tso_set_portid =
4971         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4972                                 port_id, UINT16);
4973
4974 cmdline_parse_inst_t cmd_tso_set = {
4975         .f = cmd_tso_set_parsed,
4976         .data = NULL,
4977         .help_str = "tso set <tso_segsz> <port_id>: "
4978                 "Set TSO segment size of non-tunneled packets for csum engine "
4979                 "(0 to disable)",
4980         .tokens = {
4981                 (void *)&cmd_tso_set_tso,
4982                 (void *)&cmd_tso_set_mode,
4983                 (void *)&cmd_tso_set_tso_segsz,
4984                 (void *)&cmd_tso_set_portid,
4985                 NULL,
4986         },
4987 };
4988
4989 cmdline_parse_token_string_t cmd_tso_show_mode =
4990         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4991                                 mode, "show");
4992
4993
4994 cmdline_parse_inst_t cmd_tso_show = {
4995         .f = cmd_tso_set_parsed,
4996         .data = NULL,
4997         .help_str = "tso show <port_id>: "
4998                 "Show TSO segment size of non-tunneled packets for csum engine",
4999         .tokens = {
5000                 (void *)&cmd_tso_set_tso,
5001                 (void *)&cmd_tso_show_mode,
5002                 (void *)&cmd_tso_set_portid,
5003                 NULL,
5004         },
5005 };
5006
5007 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5008 struct cmd_tunnel_tso_set_result {
5009         cmdline_fixed_string_t tso;
5010         cmdline_fixed_string_t mode;
5011         uint16_t tso_segsz;
5012         portid_t port_id;
5013 };
5014
5015 static struct rte_eth_dev_info
5016 check_tunnel_tso_nic_support(portid_t port_id)
5017 {
5018         struct rte_eth_dev_info dev_info;
5019
5020         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5021                 return dev_info;
5022
5023         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
5024                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
5025                        "not enabled for port %d\n", port_id);
5026         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
5027                 printf("Warning: GRE TUNNEL TSO not supported therefore "
5028                        "not enabled for port %d\n", port_id);
5029         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
5030                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
5031                        "not enabled for port %d\n", port_id);
5032         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
5033                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
5034                        "not enabled for port %d\n", port_id);
5035         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
5036                 printf("Warning: IP TUNNEL TSO not supported therefore "
5037                        "not enabled for port %d\n", port_id);
5038         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
5039                 printf("Warning: UDP TUNNEL TSO not supported therefore "
5040                        "not enabled for port %d\n", port_id);
5041         return dev_info;
5042 }
5043
5044 static void
5045 cmd_tunnel_tso_set_parsed(void *parsed_result,
5046                           __rte_unused struct cmdline *cl,
5047                           __rte_unused void *data)
5048 {
5049         struct cmd_tunnel_tso_set_result *res = parsed_result;
5050         struct rte_eth_dev_info dev_info;
5051
5052         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5053                 return;
5054         if (!port_is_stopped(res->port_id)) {
5055                 printf("Please stop port %d first\n", res->port_id);
5056                 return;
5057         }
5058
5059         if (!strcmp(res->mode, "set"))
5060                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5061
5062         dev_info = check_tunnel_tso_nic_support(res->port_id);
5063         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5064                 ports[res->port_id].dev_conf.txmode.offloads &=
5065                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5066                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
5067                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5068                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5069                           DEV_TX_OFFLOAD_IP_TNL_TSO |
5070                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
5071                 printf("TSO for tunneled packets is disabled\n");
5072         } else {
5073                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5074                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
5075                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5076                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5077                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
5078                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
5079
5080                 ports[res->port_id].dev_conf.txmode.offloads |=
5081                         (tso_offloads & dev_info.tx_offload_capa);
5082                 printf("TSO segment size for tunneled packets is %d\n",
5083                         ports[res->port_id].tunnel_tso_segsz);
5084
5085                 /* Below conditions are needed to make it work:
5086                  * (1) tunnel TSO is supported by the NIC;
5087                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5088                  * are recognized;
5089                  * (3) for tunneled pkts with outer L3 of IPv4,
5090                  * "csum set outer-ip" must be set to hw, because after tso,
5091                  * total_len of outer IP header is changed, and the checksum
5092                  * of outer IP header calculated by sw should be wrong; that
5093                  * is not necessary for IPv6 tunneled pkts because there's no
5094                  * checksum in IP header anymore.
5095                  */
5096
5097                 if (!ports[res->port_id].parse_tunnel)
5098                         printf("Warning: csum parse_tunnel must be set "
5099                                 "so that tunneled packets are recognized\n");
5100                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5101                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5102                         printf("Warning: csum set outer-ip must be set to hw "
5103                                 "if outer L3 is IPv4; not necessary for IPv6\n");
5104         }
5105
5106         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5107         cmd_reconfig_device_queue(res->port_id, 1, 1);
5108 }
5109
5110 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5111         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5112                                 tso, "tunnel_tso");
5113 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5114         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5115                                 mode, "set");
5116 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5117         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5118                                 tso_segsz, UINT16);
5119 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5120         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5121                                 port_id, UINT16);
5122
5123 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5124         .f = cmd_tunnel_tso_set_parsed,
5125         .data = NULL,
5126         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5127                 "Set TSO segment size of tunneled packets for csum engine "
5128                 "(0 to disable)",
5129         .tokens = {
5130                 (void *)&cmd_tunnel_tso_set_tso,
5131                 (void *)&cmd_tunnel_tso_set_mode,
5132                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5133                 (void *)&cmd_tunnel_tso_set_portid,
5134                 NULL,
5135         },
5136 };
5137
5138 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5139         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5140                                 mode, "show");
5141
5142
5143 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5144         .f = cmd_tunnel_tso_set_parsed,
5145         .data = NULL,
5146         .help_str = "tunnel_tso show <port_id> "
5147                 "Show TSO segment size of tunneled packets for csum engine",
5148         .tokens = {
5149                 (void *)&cmd_tunnel_tso_set_tso,
5150                 (void *)&cmd_tunnel_tso_show_mode,
5151                 (void *)&cmd_tunnel_tso_set_portid,
5152                 NULL,
5153         },
5154 };
5155
5156 /* *** SET GRO FOR A PORT *** */
5157 struct cmd_gro_enable_result {
5158         cmdline_fixed_string_t cmd_set;
5159         cmdline_fixed_string_t cmd_port;
5160         cmdline_fixed_string_t cmd_keyword;
5161         cmdline_fixed_string_t cmd_onoff;
5162         portid_t cmd_pid;
5163 };
5164
5165 static void
5166 cmd_gro_enable_parsed(void *parsed_result,
5167                 __rte_unused struct cmdline *cl,
5168                 __rte_unused void *data)
5169 {
5170         struct cmd_gro_enable_result *res;
5171
5172         res = parsed_result;
5173         if (!strcmp(res->cmd_keyword, "gro"))
5174                 setup_gro(res->cmd_onoff, res->cmd_pid);
5175 }
5176
5177 cmdline_parse_token_string_t cmd_gro_enable_set =
5178         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5179                         cmd_set, "set");
5180 cmdline_parse_token_string_t cmd_gro_enable_port =
5181         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5182                         cmd_keyword, "port");
5183 cmdline_parse_token_num_t cmd_gro_enable_pid =
5184         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5185                         cmd_pid, UINT16);
5186 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5187         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5188                         cmd_keyword, "gro");
5189 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5190         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5191                         cmd_onoff, "on#off");
5192
5193 cmdline_parse_inst_t cmd_gro_enable = {
5194         .f = cmd_gro_enable_parsed,
5195         .data = NULL,
5196         .help_str = "set port <port_id> gro on|off",
5197         .tokens = {
5198                 (void *)&cmd_gro_enable_set,
5199                 (void *)&cmd_gro_enable_port,
5200                 (void *)&cmd_gro_enable_pid,
5201                 (void *)&cmd_gro_enable_keyword,
5202                 (void *)&cmd_gro_enable_onoff,
5203                 NULL,
5204         },
5205 };
5206
5207 /* *** DISPLAY GRO CONFIGURATION *** */
5208 struct cmd_gro_show_result {
5209         cmdline_fixed_string_t cmd_show;
5210         cmdline_fixed_string_t cmd_port;
5211         cmdline_fixed_string_t cmd_keyword;
5212         portid_t cmd_pid;
5213 };
5214
5215 static void
5216 cmd_gro_show_parsed(void *parsed_result,
5217                 __rte_unused struct cmdline *cl,
5218                 __rte_unused void *data)
5219 {
5220         struct cmd_gro_show_result *res;
5221
5222         res = parsed_result;
5223         if (!strcmp(res->cmd_keyword, "gro"))
5224                 show_gro(res->cmd_pid);
5225 }
5226
5227 cmdline_parse_token_string_t cmd_gro_show_show =
5228         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5229                         cmd_show, "show");
5230 cmdline_parse_token_string_t cmd_gro_show_port =
5231         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5232                         cmd_port, "port");
5233 cmdline_parse_token_num_t cmd_gro_show_pid =
5234         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5235                         cmd_pid, UINT16);
5236 cmdline_parse_token_string_t cmd_gro_show_keyword =
5237         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5238                         cmd_keyword, "gro");
5239
5240 cmdline_parse_inst_t cmd_gro_show = {
5241         .f = cmd_gro_show_parsed,
5242         .data = NULL,
5243         .help_str = "show port <port_id> gro",
5244         .tokens = {
5245                 (void *)&cmd_gro_show_show,
5246                 (void *)&cmd_gro_show_port,
5247                 (void *)&cmd_gro_show_pid,
5248                 (void *)&cmd_gro_show_keyword,
5249                 NULL,
5250         },
5251 };
5252
5253 /* *** SET FLUSH CYCLES FOR GRO *** */
5254 struct cmd_gro_flush_result {
5255         cmdline_fixed_string_t cmd_set;
5256         cmdline_fixed_string_t cmd_keyword;
5257         cmdline_fixed_string_t cmd_flush;
5258         uint8_t cmd_cycles;
5259 };
5260
5261 static void
5262 cmd_gro_flush_parsed(void *parsed_result,
5263                 __rte_unused struct cmdline *cl,
5264                 __rte_unused void *data)
5265 {
5266         struct cmd_gro_flush_result *res;
5267
5268         res = parsed_result;
5269         if ((!strcmp(res->cmd_keyword, "gro")) &&
5270                         (!strcmp(res->cmd_flush, "flush")))
5271                 setup_gro_flush_cycles(res->cmd_cycles);
5272 }
5273
5274 cmdline_parse_token_string_t cmd_gro_flush_set =
5275         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5276                         cmd_set, "set");
5277 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5278         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5279                         cmd_keyword, "gro");
5280 cmdline_parse_token_string_t cmd_gro_flush_flush =
5281         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5282                         cmd_flush, "flush");
5283 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5284         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5285                         cmd_cycles, UINT8);
5286
5287 cmdline_parse_inst_t cmd_gro_flush = {
5288         .f = cmd_gro_flush_parsed,
5289         .data = NULL,
5290         .help_str = "set gro flush <cycles>",
5291         .tokens = {
5292                 (void *)&cmd_gro_flush_set,
5293                 (void *)&cmd_gro_flush_keyword,
5294                 (void *)&cmd_gro_flush_flush,
5295                 (void *)&cmd_gro_flush_cycles,
5296                 NULL,
5297         },
5298 };
5299
5300 /* *** ENABLE/DISABLE GSO *** */
5301 struct cmd_gso_enable_result {
5302         cmdline_fixed_string_t cmd_set;
5303         cmdline_fixed_string_t cmd_port;
5304         cmdline_fixed_string_t cmd_keyword;
5305         cmdline_fixed_string_t cmd_mode;
5306         portid_t cmd_pid;
5307 };
5308
5309 static void
5310 cmd_gso_enable_parsed(void *parsed_result,
5311                 __rte_unused struct cmdline *cl,
5312                 __rte_unused void *data)
5313 {
5314         struct cmd_gso_enable_result *res;
5315
5316         res = parsed_result;
5317         if (!strcmp(res->cmd_keyword, "gso"))
5318                 setup_gso(res->cmd_mode, res->cmd_pid);
5319 }
5320
5321 cmdline_parse_token_string_t cmd_gso_enable_set =
5322         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5323                         cmd_set, "set");
5324 cmdline_parse_token_string_t cmd_gso_enable_port =
5325         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5326                         cmd_port, "port");
5327 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5328         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5329                         cmd_keyword, "gso");
5330 cmdline_parse_token_string_t cmd_gso_enable_mode =
5331         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5332                         cmd_mode, "on#off");
5333 cmdline_parse_token_num_t cmd_gso_enable_pid =
5334         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5335                         cmd_pid, UINT16);
5336
5337 cmdline_parse_inst_t cmd_gso_enable = {
5338         .f = cmd_gso_enable_parsed,
5339         .data = NULL,
5340         .help_str = "set port <port_id> gso on|off",
5341         .tokens = {
5342                 (void *)&cmd_gso_enable_set,
5343                 (void *)&cmd_gso_enable_port,
5344                 (void *)&cmd_gso_enable_pid,
5345                 (void *)&cmd_gso_enable_keyword,
5346                 (void *)&cmd_gso_enable_mode,
5347                 NULL,
5348         },
5349 };
5350
5351 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5352 struct cmd_gso_size_result {
5353         cmdline_fixed_string_t cmd_set;
5354         cmdline_fixed_string_t cmd_keyword;
5355         cmdline_fixed_string_t cmd_segsz;
5356         uint16_t cmd_size;
5357 };
5358
5359 static void
5360 cmd_gso_size_parsed(void *parsed_result,
5361                        __rte_unused struct cmdline *cl,
5362                        __rte_unused void *data)
5363 {
5364         struct cmd_gso_size_result *res = parsed_result;
5365
5366         if (test_done == 0) {
5367                 printf("Before setting GSO segsz, please first"
5368                                 " stop forwarding\n");
5369                 return;
5370         }
5371
5372         if (!strcmp(res->cmd_keyword, "gso") &&
5373                         !strcmp(res->cmd_segsz, "segsz")) {
5374                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5375                         printf("gso_size should be larger than %zu."
5376                                         " Please input a legal value\n",
5377                                         RTE_GSO_SEG_SIZE_MIN);
5378                 else
5379                         gso_max_segment_size = res->cmd_size;
5380         }
5381 }
5382
5383 cmdline_parse_token_string_t cmd_gso_size_set =
5384         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5385                                 cmd_set, "set");
5386 cmdline_parse_token_string_t cmd_gso_size_keyword =
5387         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5388                                 cmd_keyword, "gso");
5389 cmdline_parse_token_string_t cmd_gso_size_segsz =
5390         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5391                                 cmd_segsz, "segsz");
5392 cmdline_parse_token_num_t cmd_gso_size_size =
5393         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5394                                 cmd_size, UINT16);
5395
5396 cmdline_parse_inst_t cmd_gso_size = {
5397         .f = cmd_gso_size_parsed,
5398         .data = NULL,
5399         .help_str = "set gso segsz <length>",
5400         .tokens = {
5401                 (void *)&cmd_gso_size_set,
5402                 (void *)&cmd_gso_size_keyword,
5403                 (void *)&cmd_gso_size_segsz,
5404                 (void *)&cmd_gso_size_size,
5405                 NULL,
5406         },
5407 };
5408
5409 /* *** SHOW GSO CONFIGURATION *** */
5410 struct cmd_gso_show_result {
5411         cmdline_fixed_string_t cmd_show;
5412         cmdline_fixed_string_t cmd_port;
5413         cmdline_fixed_string_t cmd_keyword;
5414         portid_t cmd_pid;
5415 };
5416
5417 static void
5418 cmd_gso_show_parsed(void *parsed_result,
5419                        __rte_unused struct cmdline *cl,
5420                        __rte_unused void *data)
5421 {
5422         struct cmd_gso_show_result *res = parsed_result;
5423
5424         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5425                 printf("invalid port id %u\n", res->cmd_pid);
5426                 return;
5427         }
5428         if (!strcmp(res->cmd_keyword, "gso")) {
5429                 if (gso_ports[res->cmd_pid].enable) {
5430                         printf("Max GSO'd packet size: %uB\n"
5431                                         "Supported GSO types: TCP/IPv4, "
5432                                         "UDP/IPv4, VxLAN with inner "
5433                                         "TCP/IPv4 packet, GRE with inner "
5434                                         "TCP/IPv4 packet\n",
5435                                         gso_max_segment_size);
5436                 } else
5437                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5438         }
5439 }
5440
5441 cmdline_parse_token_string_t cmd_gso_show_show =
5442 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5443                 cmd_show, "show");
5444 cmdline_parse_token_string_t cmd_gso_show_port =
5445 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5446                 cmd_port, "port");
5447 cmdline_parse_token_string_t cmd_gso_show_keyword =
5448         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5449                                 cmd_keyword, "gso");
5450 cmdline_parse_token_num_t cmd_gso_show_pid =
5451         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5452                                 cmd_pid, UINT16);
5453
5454 cmdline_parse_inst_t cmd_gso_show = {
5455         .f = cmd_gso_show_parsed,
5456         .data = NULL,
5457         .help_str = "show port <port_id> gso",
5458         .tokens = {
5459                 (void *)&cmd_gso_show_show,
5460                 (void *)&cmd_gso_show_port,
5461                 (void *)&cmd_gso_show_pid,
5462                 (void *)&cmd_gso_show_keyword,
5463                 NULL,
5464         },
5465 };
5466
5467 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5468 struct cmd_set_flush_rx {
5469         cmdline_fixed_string_t set;
5470         cmdline_fixed_string_t flush_rx;
5471         cmdline_fixed_string_t mode;
5472 };
5473
5474 static void
5475 cmd_set_flush_rx_parsed(void *parsed_result,
5476                 __rte_unused struct cmdline *cl,
5477                 __rte_unused void *data)
5478 {
5479         struct cmd_set_flush_rx *res = parsed_result;
5480         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5481 }
5482
5483 cmdline_parse_token_string_t cmd_setflushrx_set =
5484         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5485                         set, "set");
5486 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5487         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5488                         flush_rx, "flush_rx");
5489 cmdline_parse_token_string_t cmd_setflushrx_mode =
5490         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5491                         mode, "on#off");
5492
5493
5494 cmdline_parse_inst_t cmd_set_flush_rx = {
5495         .f = cmd_set_flush_rx_parsed,
5496         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5497         .data = NULL,
5498         .tokens = {
5499                 (void *)&cmd_setflushrx_set,
5500                 (void *)&cmd_setflushrx_flush_rx,
5501                 (void *)&cmd_setflushrx_mode,
5502                 NULL,
5503         },
5504 };
5505
5506 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5507 struct cmd_set_link_check {
5508         cmdline_fixed_string_t set;
5509         cmdline_fixed_string_t link_check;
5510         cmdline_fixed_string_t mode;
5511 };
5512
5513 static void
5514 cmd_set_link_check_parsed(void *parsed_result,
5515                 __rte_unused struct cmdline *cl,
5516                 __rte_unused void *data)
5517 {
5518         struct cmd_set_link_check *res = parsed_result;
5519         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5520 }
5521
5522 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5523         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5524                         set, "set");
5525 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5526         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5527                         link_check, "link_check");
5528 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5529         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5530                         mode, "on#off");
5531
5532
5533 cmdline_parse_inst_t cmd_set_link_check = {
5534         .f = cmd_set_link_check_parsed,
5535         .help_str = "set link_check on|off: Enable/Disable link status check "
5536                     "when starting/stopping a port",
5537         .data = NULL,
5538         .tokens = {
5539                 (void *)&cmd_setlinkcheck_set,
5540                 (void *)&cmd_setlinkcheck_link_check,
5541                 (void *)&cmd_setlinkcheck_mode,
5542                 NULL,
5543         },
5544 };
5545
5546 /* *** SET NIC BYPASS MODE *** */
5547 struct cmd_set_bypass_mode_result {
5548         cmdline_fixed_string_t set;
5549         cmdline_fixed_string_t bypass;
5550         cmdline_fixed_string_t mode;
5551         cmdline_fixed_string_t value;
5552         portid_t port_id;
5553 };
5554
5555 static void
5556 cmd_set_bypass_mode_parsed(void *parsed_result,
5557                 __rte_unused struct cmdline *cl,
5558                 __rte_unused void *data)
5559 {
5560         struct cmd_set_bypass_mode_result *res = parsed_result;
5561         portid_t port_id = res->port_id;
5562         int32_t rc = -EINVAL;
5563
5564 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5565         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5566
5567         if (!strcmp(res->value, "bypass"))
5568                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5569         else if (!strcmp(res->value, "isolate"))
5570                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5571         else
5572                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5573
5574         /* Set the bypass mode for the relevant port. */
5575         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5576 #endif
5577         if (rc != 0)
5578                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5579 }
5580
5581 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5582         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5583                         set, "set");
5584 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5585         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5586                         bypass, "bypass");
5587 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5588         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5589                         mode, "mode");
5590 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5591         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5592                         value, "normal#bypass#isolate");
5593 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5594         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5595                                 port_id, UINT16);
5596
5597 cmdline_parse_inst_t cmd_set_bypass_mode = {
5598         .f = cmd_set_bypass_mode_parsed,
5599         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5600                     "Set the NIC bypass mode for port_id",
5601         .data = NULL,
5602         .tokens = {
5603                 (void *)&cmd_setbypass_mode_set,
5604                 (void *)&cmd_setbypass_mode_bypass,
5605                 (void *)&cmd_setbypass_mode_mode,
5606                 (void *)&cmd_setbypass_mode_value,
5607                 (void *)&cmd_setbypass_mode_port,
5608                 NULL,
5609         },
5610 };
5611
5612 /* *** SET NIC BYPASS EVENT *** */
5613 struct cmd_set_bypass_event_result {
5614         cmdline_fixed_string_t set;
5615         cmdline_fixed_string_t bypass;
5616         cmdline_fixed_string_t event;
5617         cmdline_fixed_string_t event_value;
5618         cmdline_fixed_string_t mode;
5619         cmdline_fixed_string_t mode_value;
5620         portid_t port_id;
5621 };
5622
5623 static void
5624 cmd_set_bypass_event_parsed(void *parsed_result,
5625                 __rte_unused struct cmdline *cl,
5626                 __rte_unused void *data)
5627 {
5628         int32_t rc = -EINVAL;
5629         struct cmd_set_bypass_event_result *res = parsed_result;
5630         portid_t port_id = res->port_id;
5631
5632 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5633         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5634         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5635
5636         if (!strcmp(res->event_value, "timeout"))
5637                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5638         else if (!strcmp(res->event_value, "os_on"))
5639                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5640         else if (!strcmp(res->event_value, "os_off"))
5641                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5642         else if (!strcmp(res->event_value, "power_on"))
5643                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5644         else if (!strcmp(res->event_value, "power_off"))
5645                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5646         else
5647                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5648
5649         if (!strcmp(res->mode_value, "bypass"))
5650                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5651         else if (!strcmp(res->mode_value, "isolate"))
5652                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5653         else
5654                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5655
5656         /* Set the watchdog timeout. */
5657         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5658
5659                 rc = -EINVAL;
5660                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5661                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5662                                                            bypass_timeout);
5663                 }
5664                 if (rc != 0) {
5665                         printf("Failed to set timeout value %u "
5666                         "for port %d, errto code: %d.\n",
5667                         bypass_timeout, port_id, rc);
5668                 }
5669         }
5670
5671         /* Set the bypass event to transition to bypass mode. */
5672         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5673                                               bypass_mode);
5674 #endif
5675
5676         if (rc != 0)
5677                 printf("\t Failed to set bypass event for port = %d.\n",
5678                        port_id);
5679 }
5680
5681 cmdline_parse_token_string_t cmd_setbypass_event_set =
5682         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5683                         set, "set");
5684 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5685         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5686                         bypass, "bypass");
5687 cmdline_parse_token_string_t cmd_setbypass_event_event =
5688         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5689                         event, "event");
5690 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5691         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5692                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5693 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5694         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5695                         mode, "mode");
5696 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5697         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5698                         mode_value, "normal#bypass#isolate");
5699 cmdline_parse_token_num_t cmd_setbypass_event_port =
5700         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5701                                 port_id, UINT16);
5702
5703 cmdline_parse_inst_t cmd_set_bypass_event = {
5704         .f = cmd_set_bypass_event_parsed,
5705         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5706                 "power_off mode normal|bypass|isolate <port_id>: "
5707                 "Set the NIC bypass event mode for port_id",
5708         .data = NULL,
5709         .tokens = {
5710                 (void *)&cmd_setbypass_event_set,
5711                 (void *)&cmd_setbypass_event_bypass,
5712                 (void *)&cmd_setbypass_event_event,
5713                 (void *)&cmd_setbypass_event_event_value,
5714                 (void *)&cmd_setbypass_event_mode,
5715                 (void *)&cmd_setbypass_event_mode_value,
5716                 (void *)&cmd_setbypass_event_port,
5717                 NULL,
5718         },
5719 };
5720
5721
5722 /* *** SET NIC BYPASS TIMEOUT *** */
5723 struct cmd_set_bypass_timeout_result {
5724         cmdline_fixed_string_t set;
5725         cmdline_fixed_string_t bypass;
5726         cmdline_fixed_string_t timeout;
5727         cmdline_fixed_string_t value;
5728 };
5729
5730 static void
5731 cmd_set_bypass_timeout_parsed(void *parsed_result,
5732                 __rte_unused struct cmdline *cl,
5733                 __rte_unused void *data)
5734 {
5735         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5736
5737 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5738         if (!strcmp(res->value, "1.5"))
5739                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5740         else if (!strcmp(res->value, "2"))
5741                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5742         else if (!strcmp(res->value, "3"))
5743                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5744         else if (!strcmp(res->value, "4"))
5745                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5746         else if (!strcmp(res->value, "8"))
5747                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5748         else if (!strcmp(res->value, "16"))
5749                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5750         else if (!strcmp(res->value, "32"))
5751                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5752         else
5753                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5754 #endif
5755 }
5756
5757 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5758         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5759                         set, "set");
5760 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5761         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5762                         bypass, "bypass");
5763 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5764         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5765                         timeout, "timeout");
5766 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5767         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5768                         value, "0#1.5#2#3#4#8#16#32");
5769
5770 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5771         .f = cmd_set_bypass_timeout_parsed,
5772         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5773                 "Set the NIC bypass watchdog timeout in seconds",
5774         .data = NULL,
5775         .tokens = {
5776                 (void *)&cmd_setbypass_timeout_set,
5777                 (void *)&cmd_setbypass_timeout_bypass,
5778                 (void *)&cmd_setbypass_timeout_timeout,
5779                 (void *)&cmd_setbypass_timeout_value,
5780                 NULL,
5781         },
5782 };
5783
5784 /* *** SHOW NIC BYPASS MODE *** */
5785 struct cmd_show_bypass_config_result {
5786         cmdline_fixed_string_t show;
5787         cmdline_fixed_string_t bypass;
5788         cmdline_fixed_string_t config;
5789         portid_t port_id;
5790 };
5791
5792 static void
5793 cmd_show_bypass_config_parsed(void *parsed_result,
5794                 __rte_unused struct cmdline *cl,
5795                 __rte_unused void *data)
5796 {
5797         struct cmd_show_bypass_config_result *res = parsed_result;
5798         portid_t port_id = res->port_id;
5799         int rc = -EINVAL;
5800 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5801         uint32_t event_mode;
5802         uint32_t bypass_mode;
5803         uint32_t timeout = bypass_timeout;
5804         unsigned int i;
5805
5806         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5807                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5808         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5809                 {"UNKNOWN", "normal", "bypass", "isolate"};
5810         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5811                 "NONE",
5812                 "OS/board on",
5813                 "power supply on",
5814                 "OS/board off",
5815                 "power supply off",
5816                 "timeout"};
5817
5818         /* Display the bypass mode.*/
5819         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5820                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5821                 return;
5822         }
5823         else {
5824                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5825                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5826
5827                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5828         }
5829
5830         /* Display the bypass timeout.*/
5831         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5832                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5833
5834         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5835
5836         /* Display the bypass events and associated modes. */
5837         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5838
5839                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5840                         printf("\tFailed to get bypass mode for event = %s\n",
5841                                 events[i]);
5842                 } else {
5843                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5844                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5845
5846                         printf("\tbypass event: %-16s = %s\n", events[i],
5847                                 modes[event_mode]);
5848                 }
5849         }
5850 #endif
5851         if (rc != 0)
5852                 printf("\tFailed to get bypass configuration for port = %d\n",
5853                        port_id);
5854 }
5855
5856 cmdline_parse_token_string_t cmd_showbypass_config_show =
5857         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5858                         show, "show");
5859 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5860         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5861                         bypass, "bypass");
5862 cmdline_parse_token_string_t cmd_showbypass_config_config =
5863         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5864                         config, "config");
5865 cmdline_parse_token_num_t cmd_showbypass_config_port =
5866         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5867                                 port_id, UINT16);
5868
5869 cmdline_parse_inst_t cmd_show_bypass_config = {
5870         .f = cmd_show_bypass_config_parsed,
5871         .help_str = "show bypass config <port_id>: "
5872                     "Show the NIC bypass config for port_id",
5873         .data = NULL,
5874         .tokens = {
5875                 (void *)&cmd_showbypass_config_show,
5876                 (void *)&cmd_showbypass_config_bypass,
5877                 (void *)&cmd_showbypass_config_config,
5878                 (void *)&cmd_showbypass_config_port,
5879                 NULL,
5880         },
5881 };
5882
5883 #ifdef RTE_NET_BOND
5884 /* *** SET BONDING MODE *** */
5885 struct cmd_set_bonding_mode_result {
5886         cmdline_fixed_string_t set;
5887         cmdline_fixed_string_t bonding;
5888         cmdline_fixed_string_t mode;
5889         uint8_t value;
5890         portid_t port_id;
5891 };
5892
5893 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5894                 __rte_unused  struct cmdline *cl,
5895                 __rte_unused void *data)
5896 {
5897         struct cmd_set_bonding_mode_result *res = parsed_result;
5898         portid_t port_id = res->port_id;
5899
5900         /* Set the bonding mode for the relevant port. */
5901         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5902                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5903 }
5904
5905 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5906 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5907                 set, "set");
5908 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5909 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5910                 bonding, "bonding");
5911 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5912 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5913                 mode, "mode");
5914 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5915 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5916                 value, UINT8);
5917 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5918 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5919                 port_id, UINT16);
5920
5921 cmdline_parse_inst_t cmd_set_bonding_mode = {
5922                 .f = cmd_set_bonding_mode_parsed,
5923                 .help_str = "set bonding mode <mode_value> <port_id>: "
5924                         "Set the bonding mode for port_id",
5925                 .data = NULL,
5926                 .tokens = {
5927                                 (void *) &cmd_setbonding_mode_set,
5928                                 (void *) &cmd_setbonding_mode_bonding,
5929                                 (void *) &cmd_setbonding_mode_mode,
5930                                 (void *) &cmd_setbonding_mode_value,
5931                                 (void *) &cmd_setbonding_mode_port,
5932                                 NULL
5933                 }
5934 };
5935
5936 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5937 struct cmd_set_bonding_lacp_dedicated_queues_result {
5938         cmdline_fixed_string_t set;
5939         cmdline_fixed_string_t bonding;
5940         cmdline_fixed_string_t lacp;
5941         cmdline_fixed_string_t dedicated_queues;
5942         portid_t port_id;
5943         cmdline_fixed_string_t mode;
5944 };
5945
5946 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5947                 __rte_unused  struct cmdline *cl,
5948                 __rte_unused void *data)
5949 {
5950         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5951         portid_t port_id = res->port_id;
5952         struct rte_port *port;
5953
5954         port = &ports[port_id];
5955
5956         /** Check if the port is not started **/
5957         if (port->port_status != RTE_PORT_STOPPED) {
5958                 printf("Please stop port %d first\n", port_id);
5959                 return;
5960         }
5961
5962         if (!strcmp(res->mode, "enable")) {
5963                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5964                         printf("Dedicate queues for LACP control packets"
5965                                         " enabled\n");
5966                 else
5967                         printf("Enabling dedicate queues for LACP control "
5968                                         "packets on port %d failed\n", port_id);
5969         } else if (!strcmp(res->mode, "disable")) {
5970                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5971                         printf("Dedicated queues for LACP control packets "
5972                                         "disabled\n");
5973                 else
5974                         printf("Disabling dedicated queues for LACP control "
5975                                         "traffic on port %d failed\n", port_id);
5976         }
5977 }
5978
5979 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5980 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5981                 set, "set");
5982 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5983 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5984                 bonding, "bonding");
5985 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5986 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5987                 lacp, "lacp");
5988 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5989 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5990                 dedicated_queues, "dedicated_queues");
5991 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5992 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5993                 port_id, UINT16);
5994 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5995 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5996                 mode, "enable#disable");
5997
5998 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5999                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6000                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6001                         "enable|disable: "
6002                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6003                 .data = NULL,
6004                 .tokens = {
6005                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6006                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6007                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6008                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6009                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6010                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6011                         NULL
6012                 }
6013 };
6014
6015 /* *** SET BALANCE XMIT POLICY *** */
6016 struct cmd_set_bonding_balance_xmit_policy_result {
6017         cmdline_fixed_string_t set;
6018         cmdline_fixed_string_t bonding;
6019         cmdline_fixed_string_t balance_xmit_policy;
6020         portid_t port_id;
6021         cmdline_fixed_string_t policy;
6022 };
6023
6024 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6025                 __rte_unused  struct cmdline *cl,
6026                 __rte_unused void *data)
6027 {
6028         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6029         portid_t port_id = res->port_id;
6030         uint8_t policy;
6031
6032         if (!strcmp(res->policy, "l2")) {
6033                 policy = BALANCE_XMIT_POLICY_LAYER2;
6034         } else if (!strcmp(res->policy, "l23")) {
6035                 policy = BALANCE_XMIT_POLICY_LAYER23;
6036         } else if (!strcmp(res->policy, "l34")) {
6037                 policy = BALANCE_XMIT_POLICY_LAYER34;
6038         } else {
6039                 printf("\t Invalid xmit policy selection");
6040                 return;
6041         }
6042
6043         /* Set the bonding mode for the relevant port. */
6044         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6045                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
6046                                 port_id);
6047         }
6048 }
6049
6050 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6051 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6052                 set, "set");
6053 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6054 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6055                 bonding, "bonding");
6056 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6057 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6058                 balance_xmit_policy, "balance_xmit_policy");
6059 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6060 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6061                 port_id, UINT16);
6062 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6063 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6064                 policy, "l2#l23#l34");
6065
6066 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6067                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6068                 .help_str = "set bonding balance_xmit_policy <port_id> "
6069                         "l2|l23|l34: "
6070                         "Set the bonding balance_xmit_policy for port_id",
6071                 .data = NULL,
6072                 .tokens = {
6073                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6074                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6075                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6076                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6077                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6078                                 NULL
6079                 }
6080 };
6081
6082 /* *** SHOW NIC BONDING CONFIGURATION *** */
6083 struct cmd_show_bonding_config_result {
6084         cmdline_fixed_string_t show;
6085         cmdline_fixed_string_t bonding;
6086         cmdline_fixed_string_t config;
6087         portid_t port_id;
6088 };
6089
6090 static void cmd_show_bonding_config_parsed(void *parsed_result,
6091                 __rte_unused  struct cmdline *cl,
6092                 __rte_unused void *data)
6093 {
6094         struct cmd_show_bonding_config_result *res = parsed_result;
6095         int bonding_mode, agg_mode;
6096         portid_t slaves[RTE_MAX_ETHPORTS];
6097         int num_slaves, num_active_slaves;
6098         int primary_id;
6099         int i;
6100         portid_t port_id = res->port_id;
6101
6102         /* Display the bonding mode.*/
6103         bonding_mode = rte_eth_bond_mode_get(port_id);
6104         if (bonding_mode < 0) {
6105                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
6106                 return;
6107         } else
6108                 printf("\tBonding mode: %d\n", bonding_mode);
6109
6110         if (bonding_mode == BONDING_MODE_BALANCE) {
6111                 int balance_xmit_policy;
6112
6113                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6114                 if (balance_xmit_policy < 0) {
6115                         printf("\tFailed to get balance xmit policy for port = %d\n",
6116                                         port_id);
6117                         return;
6118                 } else {
6119                         printf("\tBalance Xmit Policy: ");
6120
6121                         switch (balance_xmit_policy) {
6122                         case BALANCE_XMIT_POLICY_LAYER2:
6123                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6124                                 break;
6125                         case BALANCE_XMIT_POLICY_LAYER23:
6126                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6127                                 break;
6128                         case BALANCE_XMIT_POLICY_LAYER34:
6129                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6130                                 break;
6131                         }
6132                         printf("\n");
6133                 }
6134         }
6135
6136         if (bonding_mode == BONDING_MODE_8023AD) {
6137                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6138                 printf("\tIEEE802.3AD Aggregator Mode: ");
6139                 switch (agg_mode) {
6140                 case AGG_BANDWIDTH:
6141                         printf("bandwidth");
6142                         break;
6143                 case AGG_STABLE:
6144                         printf("stable");
6145                         break;
6146                 case AGG_COUNT:
6147                         printf("count");
6148                         break;
6149                 }
6150                 printf("\n");
6151         }
6152
6153         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6154
6155         if (num_slaves < 0) {
6156                 printf("\tFailed to get slave list for port = %d\n", port_id);
6157                 return;
6158         }
6159         if (num_slaves > 0) {
6160                 printf("\tSlaves (%d): [", num_slaves);
6161                 for (i = 0; i < num_slaves - 1; i++)
6162                         printf("%d ", slaves[i]);
6163
6164                 printf("%d]\n", slaves[num_slaves - 1]);
6165         } else {
6166                 printf("\tSlaves: []\n");
6167
6168         }
6169
6170         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6171                         RTE_MAX_ETHPORTS);
6172
6173         if (num_active_slaves < 0) {
6174                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6175                 return;
6176         }
6177         if (num_active_slaves > 0) {
6178                 printf("\tActive Slaves (%d): [", num_active_slaves);
6179                 for (i = 0; i < num_active_slaves - 1; i++)
6180                         printf("%d ", slaves[i]);
6181
6182                 printf("%d]\n", slaves[num_active_slaves - 1]);
6183
6184         } else {
6185                 printf("\tActive Slaves: []\n");
6186
6187         }
6188
6189         primary_id = rte_eth_bond_primary_get(port_id);
6190         if (primary_id < 0) {
6191                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6192                 return;
6193         } else
6194                 printf("\tPrimary: [%d]\n", primary_id);
6195
6196 }
6197
6198 cmdline_parse_token_string_t cmd_showbonding_config_show =
6199 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6200                 show, "show");
6201 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6202 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6203                 bonding, "bonding");
6204 cmdline_parse_token_string_t cmd_showbonding_config_config =
6205 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6206                 config, "config");
6207 cmdline_parse_token_num_t cmd_showbonding_config_port =
6208 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6209                 port_id, UINT16);
6210
6211 cmdline_parse_inst_t cmd_show_bonding_config = {
6212                 .f = cmd_show_bonding_config_parsed,
6213                 .help_str = "show bonding config <port_id>: "
6214                         "Show the bonding config for port_id",
6215                 .data = NULL,
6216                 .tokens = {
6217                                 (void *)&cmd_showbonding_config_show,
6218                                 (void *)&cmd_showbonding_config_bonding,
6219                                 (void *)&cmd_showbonding_config_config,
6220                                 (void *)&cmd_showbonding_config_port,
6221                                 NULL
6222                 }
6223 };
6224
6225 /* *** SET BONDING PRIMARY *** */
6226 struct cmd_set_bonding_primary_result {
6227         cmdline_fixed_string_t set;
6228         cmdline_fixed_string_t bonding;
6229         cmdline_fixed_string_t primary;
6230         portid_t slave_id;
6231         portid_t port_id;
6232 };
6233
6234 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6235                 __rte_unused  struct cmdline *cl,
6236                 __rte_unused void *data)
6237 {
6238         struct cmd_set_bonding_primary_result *res = parsed_result;
6239         portid_t master_port_id = res->port_id;
6240         portid_t slave_port_id = res->slave_id;
6241
6242         /* Set the primary slave for a bonded device. */
6243         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6244                 printf("\t Failed to set primary slave for port = %d.\n",
6245                                 master_port_id);
6246                 return;
6247         }
6248         init_port_config();
6249 }
6250
6251 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6252 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6253                 set, "set");
6254 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6255 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6256                 bonding, "bonding");
6257 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6258 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6259                 primary, "primary");
6260 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6261 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6262                 slave_id, UINT16);
6263 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6264 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6265                 port_id, UINT16);
6266
6267 cmdline_parse_inst_t cmd_set_bonding_primary = {
6268                 .f = cmd_set_bonding_primary_parsed,
6269                 .help_str = "set bonding primary <slave_id> <port_id>: "
6270                         "Set the primary slave for port_id",
6271                 .data = NULL,
6272                 .tokens = {
6273                                 (void *)&cmd_setbonding_primary_set,
6274                                 (void *)&cmd_setbonding_primary_bonding,
6275                                 (void *)&cmd_setbonding_primary_primary,
6276                                 (void *)&cmd_setbonding_primary_slave,
6277                                 (void *)&cmd_setbonding_primary_port,
6278                                 NULL
6279                 }
6280 };
6281
6282 /* *** ADD SLAVE *** */
6283 struct cmd_add_bonding_slave_result {
6284         cmdline_fixed_string_t add;
6285         cmdline_fixed_string_t bonding;
6286         cmdline_fixed_string_t slave;
6287         portid_t slave_id;
6288         portid_t port_id;
6289 };
6290
6291 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6292                 __rte_unused  struct cmdline *cl,
6293                 __rte_unused void *data)
6294 {
6295         struct cmd_add_bonding_slave_result *res = parsed_result;
6296         portid_t master_port_id = res->port_id;
6297         portid_t slave_port_id = res->slave_id;
6298
6299         /* add the slave for a bonded device. */
6300         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6301                 printf("\t Failed to add slave %d to master port = %d.\n",
6302                                 slave_port_id, master_port_id);
6303                 return;
6304         }
6305         init_port_config();
6306         set_port_slave_flag(slave_port_id);
6307 }
6308
6309 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6310 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6311                 add, "add");
6312 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6313 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6314                 bonding, "bonding");
6315 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6316 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6317                 slave, "slave");
6318 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6319 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6320                 slave_id, UINT16);
6321 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6322 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6323                 port_id, UINT16);
6324
6325 cmdline_parse_inst_t cmd_add_bonding_slave = {
6326                 .f = cmd_add_bonding_slave_parsed,
6327                 .help_str = "add bonding slave <slave_id> <port_id>: "
6328                         "Add a slave device to a bonded device",
6329                 .data = NULL,
6330                 .tokens = {
6331                                 (void *)&cmd_addbonding_slave_add,
6332                                 (void *)&cmd_addbonding_slave_bonding,
6333                                 (void *)&cmd_addbonding_slave_slave,
6334                                 (void *)&cmd_addbonding_slave_slaveid,
6335                                 (void *)&cmd_addbonding_slave_port,
6336                                 NULL
6337                 }
6338 };
6339
6340 /* *** REMOVE SLAVE *** */
6341 struct cmd_remove_bonding_slave_result {
6342         cmdline_fixed_string_t remove;
6343         cmdline_fixed_string_t bonding;
6344         cmdline_fixed_string_t slave;
6345         portid_t slave_id;
6346         portid_t port_id;
6347 };
6348
6349 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6350                 __rte_unused  struct cmdline *cl,
6351                 __rte_unused void *data)
6352 {
6353         struct cmd_remove_bonding_slave_result *res = parsed_result;
6354         portid_t master_port_id = res->port_id;
6355         portid_t slave_port_id = res->slave_id;
6356
6357         /* remove the slave from a bonded device. */
6358         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6359                 printf("\t Failed to remove slave %d from master port = %d.\n",
6360                                 slave_port_id, master_port_id);
6361                 return;
6362         }
6363         init_port_config();
6364         clear_port_slave_flag(slave_port_id);
6365 }
6366
6367 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6368                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6369                                 remove, "remove");
6370 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6371                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6372                                 bonding, "bonding");
6373 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6374                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6375                                 slave, "slave");
6376 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6377                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6378                                 slave_id, UINT16);
6379 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6380                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6381                                 port_id, UINT16);
6382
6383 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6384                 .f = cmd_remove_bonding_slave_parsed,
6385                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6386                         "Remove a slave device from a bonded device",
6387                 .data = NULL,
6388                 .tokens = {
6389                                 (void *)&cmd_removebonding_slave_remove,
6390                                 (void *)&cmd_removebonding_slave_bonding,
6391                                 (void *)&cmd_removebonding_slave_slave,
6392                                 (void *)&cmd_removebonding_slave_slaveid,
6393                                 (void *)&cmd_removebonding_slave_port,
6394                                 NULL
6395                 }
6396 };
6397
6398 /* *** CREATE BONDED DEVICE *** */
6399 struct cmd_create_bonded_device_result {
6400         cmdline_fixed_string_t create;
6401         cmdline_fixed_string_t bonded;
6402         cmdline_fixed_string_t device;
6403         uint8_t mode;
6404         uint8_t socket;
6405 };
6406
6407 static int bond_dev_num = 0;
6408
6409 static void cmd_create_bonded_device_parsed(void *parsed_result,
6410                 __rte_unused  struct cmdline *cl,
6411                 __rte_unused void *data)
6412 {
6413         struct cmd_create_bonded_device_result *res = parsed_result;
6414         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6415         int port_id;
6416         int ret;
6417
6418         if (test_done == 0) {
6419                 printf("Please stop forwarding first\n");
6420                 return;
6421         }
6422
6423         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6424                         bond_dev_num++);
6425
6426         /* Create a new bonded device. */
6427         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6428         if (port_id < 0) {
6429                 printf("\t Failed to create bonded device.\n");
6430                 return;
6431         } else {
6432                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6433                                 port_id);
6434
6435                 /* Update number of ports */
6436                 nb_ports = rte_eth_dev_count_avail();
6437                 reconfig(port_id, res->socket);
6438                 ret = rte_eth_promiscuous_enable(port_id);
6439                 if (ret != 0)
6440                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6441                                 port_id, rte_strerror(-ret));
6442
6443                 ports[port_id].need_setup = 0;
6444                 ports[port_id].port_status = RTE_PORT_STOPPED;
6445         }
6446
6447 }
6448
6449 cmdline_parse_token_string_t cmd_createbonded_device_create =
6450                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6451                                 create, "create");
6452 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6453                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6454                                 bonded, "bonded");
6455 cmdline_parse_token_string_t cmd_createbonded_device_device =
6456                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6457                                 device, "device");
6458 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6459                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6460                                 mode, UINT8);
6461 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6462                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6463                                 socket, UINT8);
6464
6465 cmdline_parse_inst_t cmd_create_bonded_device = {
6466                 .f = cmd_create_bonded_device_parsed,
6467                 .help_str = "create bonded device <mode> <socket>: "
6468                         "Create a new bonded device with specific bonding mode and socket",
6469                 .data = NULL,
6470                 .tokens = {
6471                                 (void *)&cmd_createbonded_device_create,
6472                                 (void *)&cmd_createbonded_device_bonded,
6473                                 (void *)&cmd_createbonded_device_device,
6474                                 (void *)&cmd_createbonded_device_mode,
6475                                 (void *)&cmd_createbonded_device_socket,
6476                                 NULL
6477                 }
6478 };
6479
6480 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6481 struct cmd_set_bond_mac_addr_result {
6482         cmdline_fixed_string_t set;
6483         cmdline_fixed_string_t bonding;
6484         cmdline_fixed_string_t mac_addr;
6485         uint16_t port_num;
6486         struct rte_ether_addr address;
6487 };
6488
6489 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6490                 __rte_unused  struct cmdline *cl,
6491                 __rte_unused void *data)
6492 {
6493         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6494         int ret;
6495
6496         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6497                 return;
6498
6499         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6500
6501         /* check the return value and print it if is < 0 */
6502         if (ret < 0)
6503                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6504 }
6505
6506 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6507                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6508 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6509                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6510                                 "bonding");
6511 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6512                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6513                                 "mac_addr");
6514 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6515                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6516                                 port_num, UINT16);
6517 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6518                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6519
6520 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6521                 .f = cmd_set_bond_mac_addr_parsed,
6522                 .data = (void *) 0,
6523                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6524                 .tokens = {
6525                                 (void *)&cmd_set_bond_mac_addr_set,
6526                                 (void *)&cmd_set_bond_mac_addr_bonding,
6527                                 (void *)&cmd_set_bond_mac_addr_mac,
6528                                 (void *)&cmd_set_bond_mac_addr_portnum,
6529                                 (void *)&cmd_set_bond_mac_addr_addr,
6530                                 NULL
6531                 }
6532 };
6533
6534
6535 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6536 struct cmd_set_bond_mon_period_result {
6537         cmdline_fixed_string_t set;
6538         cmdline_fixed_string_t bonding;
6539         cmdline_fixed_string_t mon_period;
6540         uint16_t port_num;
6541         uint32_t period_ms;
6542 };
6543
6544 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6545                 __rte_unused  struct cmdline *cl,
6546                 __rte_unused void *data)
6547 {
6548         struct cmd_set_bond_mon_period_result *res = parsed_result;
6549         int ret;
6550
6551         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6552
6553         /* check the return value and print it if is < 0 */
6554         if (ret < 0)
6555                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6556 }
6557
6558 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6559                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6560                                 set, "set");
6561 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6562                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6563                                 bonding, "bonding");
6564 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6565                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6566                                 mon_period,     "mon_period");
6567 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6568                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6569                                 port_num, UINT16);
6570 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6571                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6572                                 period_ms, UINT32);
6573
6574 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6575                 .f = cmd_set_bond_mon_period_parsed,
6576                 .data = (void *) 0,
6577                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6578                 .tokens = {
6579                                 (void *)&cmd_set_bond_mon_period_set,
6580                                 (void *)&cmd_set_bond_mon_period_bonding,
6581                                 (void *)&cmd_set_bond_mon_period_mon_period,
6582                                 (void *)&cmd_set_bond_mon_period_portnum,
6583                                 (void *)&cmd_set_bond_mon_period_period_ms,
6584                                 NULL
6585                 }
6586 };
6587
6588
6589
6590 struct cmd_set_bonding_agg_mode_policy_result {
6591         cmdline_fixed_string_t set;
6592         cmdline_fixed_string_t bonding;
6593         cmdline_fixed_string_t agg_mode;
6594         uint16_t port_num;
6595         cmdline_fixed_string_t policy;
6596 };
6597
6598
6599 static void
6600 cmd_set_bonding_agg_mode(void *parsed_result,
6601                 __rte_unused struct cmdline *cl,
6602                 __rte_unused void *data)
6603 {
6604         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6605         uint8_t policy = AGG_BANDWIDTH;
6606
6607         if (!strcmp(res->policy, "bandwidth"))
6608                 policy = AGG_BANDWIDTH;
6609         else if (!strcmp(res->policy, "stable"))
6610                 policy = AGG_STABLE;
6611         else if (!strcmp(res->policy, "count"))
6612                 policy = AGG_COUNT;
6613
6614         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6615 }
6616
6617
6618 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6619         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6620                                 set, "set");
6621 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6622         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6623                                 bonding, "bonding");
6624
6625 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6626         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6627                                 agg_mode, "agg_mode");
6628
6629 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6630         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6631                                 port_num, UINT16);
6632
6633 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6634         TOKEN_STRING_INITIALIZER(
6635                         struct cmd_set_bonding_balance_xmit_policy_result,
6636                 policy, "stable#bandwidth#count");
6637
6638 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6639         .f = cmd_set_bonding_agg_mode,
6640         .data = (void *) 0,
6641         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6642         .tokens = {
6643                         (void *)&cmd_set_bonding_agg_mode_set,
6644                         (void *)&cmd_set_bonding_agg_mode_bonding,
6645                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6646                         (void *)&cmd_set_bonding_agg_mode_portnum,
6647                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6648                         NULL
6649                 }
6650 };
6651
6652
6653 #endif /* RTE_NET_BOND */
6654
6655 /* *** SET FORWARDING MODE *** */
6656 struct cmd_set_fwd_mode_result {
6657         cmdline_fixed_string_t set;
6658         cmdline_fixed_string_t fwd;
6659         cmdline_fixed_string_t mode;
6660 };
6661
6662 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6663                                     __rte_unused struct cmdline *cl,
6664                                     __rte_unused void *data)
6665 {
6666         struct cmd_set_fwd_mode_result *res = parsed_result;
6667
6668         retry_enabled = 0;
6669         set_pkt_forwarding_mode(res->mode);
6670 }
6671
6672 cmdline_parse_token_string_t cmd_setfwd_set =
6673         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6674 cmdline_parse_token_string_t cmd_setfwd_fwd =
6675         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6676 cmdline_parse_token_string_t cmd_setfwd_mode =
6677         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6678                 "" /* defined at init */);
6679
6680 cmdline_parse_inst_t cmd_set_fwd_mode = {
6681         .f = cmd_set_fwd_mode_parsed,
6682         .data = NULL,
6683         .help_str = NULL, /* defined at init */
6684         .tokens = {
6685                 (void *)&cmd_setfwd_set,
6686                 (void *)&cmd_setfwd_fwd,
6687                 (void *)&cmd_setfwd_mode,
6688                 NULL,
6689         },
6690 };
6691
6692 static void cmd_set_fwd_mode_init(void)
6693 {
6694         char *modes, *c;
6695         static char token[128];
6696         static char help[256];
6697         cmdline_parse_token_string_t *token_struct;
6698
6699         modes = list_pkt_forwarding_modes();
6700         snprintf(help, sizeof(help), "set fwd %s: "
6701                 "Set packet forwarding mode", modes);
6702         cmd_set_fwd_mode.help_str = help;
6703
6704         /* string token separator is # */
6705         for (c = token; *modes != '\0'; modes++)
6706                 if (*modes == '|')
6707                         *c++ = '#';
6708                 else
6709                         *c++ = *modes;
6710         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6711         token_struct->string_data.str = token;
6712 }
6713
6714 /* *** SET RETRY FORWARDING MODE *** */
6715 struct cmd_set_fwd_retry_mode_result {
6716         cmdline_fixed_string_t set;
6717         cmdline_fixed_string_t fwd;
6718         cmdline_fixed_string_t mode;
6719         cmdline_fixed_string_t retry;
6720 };
6721
6722 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6723                             __rte_unused struct cmdline *cl,
6724                             __rte_unused void *data)
6725 {
6726         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6727
6728         retry_enabled = 1;
6729         set_pkt_forwarding_mode(res->mode);
6730 }
6731
6732 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6733         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6734                         set, "set");
6735 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6736         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6737                         fwd, "fwd");
6738 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6739         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6740                         mode,
6741                 "" /* defined at init */);
6742 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6743         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6744                         retry, "retry");
6745
6746 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6747         .f = cmd_set_fwd_retry_mode_parsed,
6748         .data = NULL,
6749         .help_str = NULL, /* defined at init */
6750         .tokens = {
6751                 (void *)&cmd_setfwd_retry_set,
6752                 (void *)&cmd_setfwd_retry_fwd,
6753                 (void *)&cmd_setfwd_retry_mode,
6754                 (void *)&cmd_setfwd_retry_retry,
6755                 NULL,
6756         },
6757 };
6758
6759 static void cmd_set_fwd_retry_mode_init(void)
6760 {
6761         char *modes, *c;
6762         static char token[128];
6763         static char help[256];
6764         cmdline_parse_token_string_t *token_struct;
6765
6766         modes = list_pkt_forwarding_retry_modes();
6767         snprintf(help, sizeof(help), "set fwd %s retry: "
6768                 "Set packet forwarding mode with retry", modes);
6769         cmd_set_fwd_retry_mode.help_str = help;
6770
6771         /* string token separator is # */
6772         for (c = token; *modes != '\0'; modes++)
6773                 if (*modes == '|')
6774                         *c++ = '#';
6775                 else
6776                         *c++ = *modes;
6777         token_struct = (cmdline_parse_token_string_t *)
6778                 cmd_set_fwd_retry_mode.tokens[2];
6779         token_struct->string_data.str = token;
6780 }
6781
6782 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6783 struct cmd_set_burst_tx_retry_result {
6784         cmdline_fixed_string_t set;
6785         cmdline_fixed_string_t burst;
6786         cmdline_fixed_string_t tx;
6787         cmdline_fixed_string_t delay;
6788         uint32_t time;
6789         cmdline_fixed_string_t retry;
6790         uint32_t retry_num;
6791 };
6792
6793 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6794                                         __rte_unused struct cmdline *cl,
6795                                         __rte_unused void *data)
6796 {
6797         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6798
6799         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6800                 && !strcmp(res->tx, "tx")) {
6801                 if (!strcmp(res->delay, "delay"))
6802                         burst_tx_delay_time = res->time;
6803                 if (!strcmp(res->retry, "retry"))
6804                         burst_tx_retry_num = res->retry_num;
6805         }
6806
6807 }
6808
6809 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6810         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6811 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6812         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6813                                  "burst");
6814 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6815         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6816 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6817         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6818 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6819         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6820 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6821         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6822 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6823         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6824
6825 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6826         .f = cmd_set_burst_tx_retry_parsed,
6827         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6828         .tokens = {
6829                 (void *)&cmd_set_burst_tx_retry_set,
6830                 (void *)&cmd_set_burst_tx_retry_burst,
6831                 (void *)&cmd_set_burst_tx_retry_tx,
6832                 (void *)&cmd_set_burst_tx_retry_delay,
6833                 (void *)&cmd_set_burst_tx_retry_time,
6834                 (void *)&cmd_set_burst_tx_retry_retry,
6835                 (void *)&cmd_set_burst_tx_retry_retry_num,
6836                 NULL,
6837         },
6838 };
6839
6840 /* *** SET PROMISC MODE *** */
6841 struct cmd_set_promisc_mode_result {
6842         cmdline_fixed_string_t set;
6843         cmdline_fixed_string_t promisc;
6844         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6845         uint16_t port_num;               /* valid if "allports" argument == 0 */
6846         cmdline_fixed_string_t mode;
6847 };
6848
6849 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6850                                         __rte_unused struct cmdline *cl,
6851                                         void *allports)
6852 {
6853         struct cmd_set_promisc_mode_result *res = parsed_result;
6854         int enable;
6855         portid_t i;
6856
6857         if (!strcmp(res->mode, "on"))
6858                 enable = 1;
6859         else
6860                 enable = 0;
6861
6862         /* all ports */
6863         if (allports) {
6864                 RTE_ETH_FOREACH_DEV(i)
6865                         eth_set_promisc_mode(i, enable);
6866         } else {
6867                 eth_set_promisc_mode(res->port_num, enable);
6868         }
6869 }
6870
6871 cmdline_parse_token_string_t cmd_setpromisc_set =
6872         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6873 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6874         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6875                                  "promisc");
6876 cmdline_parse_token_string_t cmd_setpromisc_portall =
6877         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6878                                  "all");
6879 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6880         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6881                               UINT16);
6882 cmdline_parse_token_string_t cmd_setpromisc_mode =
6883         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6884                                  "on#off");
6885
6886 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6887         .f = cmd_set_promisc_mode_parsed,
6888         .data = (void *)1,
6889         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6890         .tokens = {
6891                 (void *)&cmd_setpromisc_set,
6892                 (void *)&cmd_setpromisc_promisc,
6893                 (void *)&cmd_setpromisc_portall,
6894                 (void *)&cmd_setpromisc_mode,
6895                 NULL,
6896         },
6897 };
6898
6899 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6900         .f = cmd_set_promisc_mode_parsed,
6901         .data = (void *)0,
6902         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6903         .tokens = {
6904                 (void *)&cmd_setpromisc_set,
6905                 (void *)&cmd_setpromisc_promisc,
6906                 (void *)&cmd_setpromisc_portnum,
6907                 (void *)&cmd_setpromisc_mode,
6908                 NULL,
6909         },
6910 };
6911
6912 /* *** SET ALLMULTI MODE *** */
6913 struct cmd_set_allmulti_mode_result {
6914         cmdline_fixed_string_t set;
6915         cmdline_fixed_string_t allmulti;
6916         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6917         uint16_t port_num;               /* valid if "allports" argument == 0 */
6918         cmdline_fixed_string_t mode;
6919 };
6920
6921 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6922                                         __rte_unused struct cmdline *cl,
6923                                         void *allports)
6924 {
6925         struct cmd_set_allmulti_mode_result *res = parsed_result;
6926         int enable;
6927         portid_t i;
6928
6929         if (!strcmp(res->mode, "on"))
6930                 enable = 1;
6931         else
6932                 enable = 0;
6933
6934         /* all ports */
6935         if (allports) {
6936                 RTE_ETH_FOREACH_DEV(i) {
6937                         eth_set_allmulticast_mode(i, enable);
6938                 }
6939         }
6940         else {
6941                 eth_set_allmulticast_mode(res->port_num, enable);
6942         }
6943 }
6944
6945 cmdline_parse_token_string_t cmd_setallmulti_set =
6946         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6947 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6948         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6949                                  "allmulti");
6950 cmdline_parse_token_string_t cmd_setallmulti_portall =
6951         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6952                                  "all");
6953 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6954         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6955                               UINT16);
6956 cmdline_parse_token_string_t cmd_setallmulti_mode =
6957         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6958                                  "on#off");
6959
6960 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6961         .f = cmd_set_allmulti_mode_parsed,
6962         .data = (void *)1,
6963         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6964         .tokens = {
6965                 (void *)&cmd_setallmulti_set,
6966                 (void *)&cmd_setallmulti_allmulti,
6967                 (void *)&cmd_setallmulti_portall,
6968                 (void *)&cmd_setallmulti_mode,
6969                 NULL,
6970         },
6971 };
6972
6973 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6974         .f = cmd_set_allmulti_mode_parsed,
6975         .data = (void *)0,
6976         .help_str = "set allmulti <port_id> on|off: "
6977                 "Set allmulti mode on port_id",
6978         .tokens = {
6979                 (void *)&cmd_setallmulti_set,
6980                 (void *)&cmd_setallmulti_allmulti,
6981                 (void *)&cmd_setallmulti_portnum,
6982                 (void *)&cmd_setallmulti_mode,
6983                 NULL,
6984         },
6985 };
6986
6987 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6988 struct cmd_link_flow_ctrl_set_result {
6989         cmdline_fixed_string_t set;
6990         cmdline_fixed_string_t flow_ctrl;
6991         cmdline_fixed_string_t rx;
6992         cmdline_fixed_string_t rx_lfc_mode;
6993         cmdline_fixed_string_t tx;
6994         cmdline_fixed_string_t tx_lfc_mode;
6995         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6996         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6997         cmdline_fixed_string_t autoneg_str;
6998         cmdline_fixed_string_t autoneg;
6999         cmdline_fixed_string_t hw_str;
7000         uint32_t high_water;
7001         cmdline_fixed_string_t lw_str;
7002         uint32_t low_water;
7003         cmdline_fixed_string_t pt_str;
7004         uint16_t pause_time;
7005         cmdline_fixed_string_t xon_str;
7006         uint16_t send_xon;
7007         portid_t port_id;
7008 };
7009
7010 cmdline_parse_token_string_t cmd_lfc_set_set =
7011         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7012                                 set, "set");
7013 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7014         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7015                                 flow_ctrl, "flow_ctrl");
7016 cmdline_parse_token_string_t cmd_lfc_set_rx =
7017         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7018                                 rx, "rx");
7019 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7020         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7021                                 rx_lfc_mode, "on#off");
7022 cmdline_parse_token_string_t cmd_lfc_set_tx =
7023         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7024                                 tx, "tx");
7025 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7026         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7027                                 tx_lfc_mode, "on#off");
7028 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7029         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7030                                 hw_str, "high_water");
7031 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7032         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7033                                 high_water, UINT32);
7034 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7035         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7036                                 lw_str, "low_water");
7037 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7038         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7039                                 low_water, UINT32);
7040 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7041         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7042                                 pt_str, "pause_time");
7043 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7044         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7045                                 pause_time, UINT16);
7046 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7047         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7048                                 xon_str, "send_xon");
7049 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7050         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7051                                 send_xon, UINT16);
7052 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7053         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7054                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7055 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7056         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7057                                 mac_ctrl_frame_fwd_mode, "on#off");
7058 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7059         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7060                                 autoneg_str, "autoneg");
7061 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7062         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7063                                 autoneg, "on#off");
7064 cmdline_parse_token_num_t cmd_lfc_set_portid =
7065         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7066                                 port_id, UINT16);
7067
7068 /* forward declaration */
7069 static void
7070 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7071                               void *data);
7072
7073 cmdline_parse_inst_t cmd_link_flow_control_set = {
7074         .f = cmd_link_flow_ctrl_set_parsed,
7075         .data = NULL,
7076         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7077                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7078                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7079         .tokens = {
7080                 (void *)&cmd_lfc_set_set,
7081                 (void *)&cmd_lfc_set_flow_ctrl,
7082                 (void *)&cmd_lfc_set_rx,
7083                 (void *)&cmd_lfc_set_rx_mode,
7084                 (void *)&cmd_lfc_set_tx,
7085                 (void *)&cmd_lfc_set_tx_mode,
7086                 (void *)&cmd_lfc_set_high_water,
7087                 (void *)&cmd_lfc_set_low_water,
7088                 (void *)&cmd_lfc_set_pause_time,
7089                 (void *)&cmd_lfc_set_send_xon,
7090                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7091                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7092                 (void *)&cmd_lfc_set_autoneg_str,
7093                 (void *)&cmd_lfc_set_autoneg,
7094                 (void *)&cmd_lfc_set_portid,
7095                 NULL,
7096         },
7097 };
7098
7099 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7100         .f = cmd_link_flow_ctrl_set_parsed,
7101         .data = (void *)&cmd_link_flow_control_set_rx,
7102         .help_str = "set flow_ctrl rx on|off <port_id>: "
7103                 "Change rx flow control parameter",
7104         .tokens = {
7105                 (void *)&cmd_lfc_set_set,
7106                 (void *)&cmd_lfc_set_flow_ctrl,
7107                 (void *)&cmd_lfc_set_rx,
7108                 (void *)&cmd_lfc_set_rx_mode,
7109                 (void *)&cmd_lfc_set_portid,
7110                 NULL,
7111         },
7112 };
7113
7114 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7115         .f = cmd_link_flow_ctrl_set_parsed,
7116         .data = (void *)&cmd_link_flow_control_set_tx,
7117         .help_str = "set flow_ctrl tx on|off <port_id>: "
7118                 "Change tx flow control parameter",
7119         .tokens = {
7120                 (void *)&cmd_lfc_set_set,
7121                 (void *)&cmd_lfc_set_flow_ctrl,
7122                 (void *)&cmd_lfc_set_tx,
7123                 (void *)&cmd_lfc_set_tx_mode,
7124                 (void *)&cmd_lfc_set_portid,
7125                 NULL,
7126         },
7127 };
7128
7129 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7130         .f = cmd_link_flow_ctrl_set_parsed,
7131         .data = (void *)&cmd_link_flow_control_set_hw,
7132         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7133                 "Change high water flow control parameter",
7134         .tokens = {
7135                 (void *)&cmd_lfc_set_set,
7136                 (void *)&cmd_lfc_set_flow_ctrl,
7137                 (void *)&cmd_lfc_set_high_water_str,
7138                 (void *)&cmd_lfc_set_high_water,
7139                 (void *)&cmd_lfc_set_portid,
7140                 NULL,
7141         },
7142 };
7143
7144 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7145         .f = cmd_link_flow_ctrl_set_parsed,
7146         .data = (void *)&cmd_link_flow_control_set_lw,
7147         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7148                 "Change low water flow control parameter",
7149         .tokens = {
7150                 (void *)&cmd_lfc_set_set,
7151                 (void *)&cmd_lfc_set_flow_ctrl,
7152                 (void *)&cmd_lfc_set_low_water_str,
7153                 (void *)&cmd_lfc_set_low_water,
7154                 (void *)&cmd_lfc_set_portid,
7155                 NULL,
7156         },
7157 };
7158
7159 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7160         .f = cmd_link_flow_ctrl_set_parsed,
7161         .data = (void *)&cmd_link_flow_control_set_pt,
7162         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7163                 "Change pause time flow control parameter",
7164         .tokens = {
7165                 (void *)&cmd_lfc_set_set,
7166                 (void *)&cmd_lfc_set_flow_ctrl,
7167                 (void *)&cmd_lfc_set_pause_time_str,
7168                 (void *)&cmd_lfc_set_pause_time,
7169                 (void *)&cmd_lfc_set_portid,
7170                 NULL,
7171         },
7172 };
7173
7174 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7175         .f = cmd_link_flow_ctrl_set_parsed,
7176         .data = (void *)&cmd_link_flow_control_set_xon,
7177         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7178                 "Change send_xon flow control parameter",
7179         .tokens = {
7180                 (void *)&cmd_lfc_set_set,
7181                 (void *)&cmd_lfc_set_flow_ctrl,
7182                 (void *)&cmd_lfc_set_send_xon_str,
7183                 (void *)&cmd_lfc_set_send_xon,
7184                 (void *)&cmd_lfc_set_portid,
7185                 NULL,
7186         },
7187 };
7188
7189 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7190         .f = cmd_link_flow_ctrl_set_parsed,
7191         .data = (void *)&cmd_link_flow_control_set_macfwd,
7192         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7193                 "Change mac ctrl fwd flow control parameter",
7194         .tokens = {
7195                 (void *)&cmd_lfc_set_set,
7196                 (void *)&cmd_lfc_set_flow_ctrl,
7197                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7198                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7199                 (void *)&cmd_lfc_set_portid,
7200                 NULL,
7201         },
7202 };
7203
7204 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7205         .f = cmd_link_flow_ctrl_set_parsed,
7206         .data = (void *)&cmd_link_flow_control_set_autoneg,
7207         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7208                 "Change autoneg flow control parameter",
7209         .tokens = {
7210                 (void *)&cmd_lfc_set_set,
7211                 (void *)&cmd_lfc_set_flow_ctrl,
7212                 (void *)&cmd_lfc_set_autoneg_str,
7213                 (void *)&cmd_lfc_set_autoneg,
7214                 (void *)&cmd_lfc_set_portid,
7215                 NULL,
7216         },
7217 };
7218
7219 static void
7220 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7221                               __rte_unused struct cmdline *cl,
7222                               void *data)
7223 {
7224         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7225         cmdline_parse_inst_t *cmd = data;
7226         struct rte_eth_fc_conf fc_conf;
7227         int rx_fc_en = 0;
7228         int tx_fc_en = 0;
7229         int ret;
7230
7231         /*
7232          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7233          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7234          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7235          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7236          */
7237         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7238                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7239         };
7240
7241         /* Partial command line, retrieve current configuration */
7242         if (cmd) {
7243                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7244                 if (ret != 0) {
7245                         printf("cannot get current flow ctrl parameters, return"
7246                                "code = %d\n", ret);
7247                         return;
7248                 }
7249
7250                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7251                     (fc_conf.mode == RTE_FC_FULL))
7252                         rx_fc_en = 1;
7253                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7254                     (fc_conf.mode == RTE_FC_FULL))
7255                         tx_fc_en = 1;
7256         }
7257
7258         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7259                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7260
7261         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7262                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7263
7264         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7265
7266         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7267                 fc_conf.high_water = res->high_water;
7268
7269         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7270                 fc_conf.low_water = res->low_water;
7271
7272         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7273                 fc_conf.pause_time = res->pause_time;
7274
7275         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7276                 fc_conf.send_xon = res->send_xon;
7277
7278         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7279                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7280                         fc_conf.mac_ctrl_frame_fwd = 1;
7281                 else
7282                         fc_conf.mac_ctrl_frame_fwd = 0;
7283         }
7284
7285         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7286                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7287
7288         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7289         if (ret != 0)
7290                 printf("bad flow contrl parameter, return code = %d \n", ret);
7291 }
7292
7293 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7294 struct cmd_priority_flow_ctrl_set_result {
7295         cmdline_fixed_string_t set;
7296         cmdline_fixed_string_t pfc_ctrl;
7297         cmdline_fixed_string_t rx;
7298         cmdline_fixed_string_t rx_pfc_mode;
7299         cmdline_fixed_string_t tx;
7300         cmdline_fixed_string_t tx_pfc_mode;
7301         uint32_t high_water;
7302         uint32_t low_water;
7303         uint16_t pause_time;
7304         uint8_t  priority;
7305         portid_t port_id;
7306 };
7307
7308 static void
7309 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7310                        __rte_unused struct cmdline *cl,
7311                        __rte_unused void *data)
7312 {
7313         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7314         struct rte_eth_pfc_conf pfc_conf;
7315         int rx_fc_enable, tx_fc_enable;
7316         int ret;
7317
7318         /*
7319          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7320          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7321          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7322          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7323          */
7324         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7325                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7326         };
7327
7328         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7329         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7330         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7331         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7332         pfc_conf.fc.high_water = res->high_water;
7333         pfc_conf.fc.low_water  = res->low_water;
7334         pfc_conf.fc.pause_time = res->pause_time;
7335         pfc_conf.priority      = res->priority;
7336
7337         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7338         if (ret != 0)
7339                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7340 }
7341
7342 cmdline_parse_token_string_t cmd_pfc_set_set =
7343         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7344                                 set, "set");
7345 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7346         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7347                                 pfc_ctrl, "pfc_ctrl");
7348 cmdline_parse_token_string_t cmd_pfc_set_rx =
7349         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7350                                 rx, "rx");
7351 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7352         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7353                                 rx_pfc_mode, "on#off");
7354 cmdline_parse_token_string_t cmd_pfc_set_tx =
7355         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7356                                 tx, "tx");
7357 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7358         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7359                                 tx_pfc_mode, "on#off");
7360 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7361         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7362                                 high_water, UINT32);
7363 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7364         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7365                                 low_water, UINT32);
7366 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7367         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7368                                 pause_time, UINT16);
7369 cmdline_parse_token_num_t cmd_pfc_set_priority =
7370         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7371                                 priority, UINT8);
7372 cmdline_parse_token_num_t cmd_pfc_set_portid =
7373         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7374                                 port_id, UINT16);
7375
7376 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7377         .f = cmd_priority_flow_ctrl_set_parsed,
7378         .data = NULL,
7379         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7380                 "<pause_time> <priority> <port_id>: "
7381                 "Configure the Ethernet priority flow control",
7382         .tokens = {
7383                 (void *)&cmd_pfc_set_set,
7384                 (void *)&cmd_pfc_set_flow_ctrl,
7385                 (void *)&cmd_pfc_set_rx,
7386                 (void *)&cmd_pfc_set_rx_mode,
7387                 (void *)&cmd_pfc_set_tx,
7388                 (void *)&cmd_pfc_set_tx_mode,
7389                 (void *)&cmd_pfc_set_high_water,
7390                 (void *)&cmd_pfc_set_low_water,
7391                 (void *)&cmd_pfc_set_pause_time,
7392                 (void *)&cmd_pfc_set_priority,
7393                 (void *)&cmd_pfc_set_portid,
7394                 NULL,
7395         },
7396 };
7397
7398 /* *** RESET CONFIGURATION *** */
7399 struct cmd_reset_result {
7400         cmdline_fixed_string_t reset;
7401         cmdline_fixed_string_t def;
7402 };
7403
7404 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7405                              struct cmdline *cl,
7406                              __rte_unused void *data)
7407 {
7408         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7409         set_def_fwd_config();
7410 }
7411
7412 cmdline_parse_token_string_t cmd_reset_set =
7413         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7414 cmdline_parse_token_string_t cmd_reset_def =
7415         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7416                                  "default");
7417
7418 cmdline_parse_inst_t cmd_reset = {
7419         .f = cmd_reset_parsed,
7420         .data = NULL,
7421         .help_str = "set default: Reset default forwarding configuration",
7422         .tokens = {
7423                 (void *)&cmd_reset_set,
7424                 (void *)&cmd_reset_def,
7425                 NULL,
7426         },
7427 };
7428
7429 /* *** START FORWARDING *** */
7430 struct cmd_start_result {
7431         cmdline_fixed_string_t start;
7432 };
7433
7434 cmdline_parse_token_string_t cmd_start_start =
7435         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7436
7437 static void cmd_start_parsed(__rte_unused void *parsed_result,
7438                              __rte_unused struct cmdline *cl,
7439                              __rte_unused void *data)
7440 {
7441         start_packet_forwarding(0);
7442 }
7443
7444 cmdline_parse_inst_t cmd_start = {
7445         .f = cmd_start_parsed,
7446         .data = NULL,
7447         .help_str = "start: Start packet forwarding",
7448         .tokens = {
7449                 (void *)&cmd_start_start,
7450                 NULL,
7451         },
7452 };
7453
7454 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7455 struct cmd_start_tx_first_result {
7456         cmdline_fixed_string_t start;
7457         cmdline_fixed_string_t tx_first;
7458 };
7459
7460 static void
7461 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7462                           __rte_unused struct cmdline *cl,
7463                           __rte_unused void *data)
7464 {
7465         start_packet_forwarding(1);
7466 }
7467
7468 cmdline_parse_token_string_t cmd_start_tx_first_start =
7469         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7470                                  "start");
7471 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7472         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7473                                  tx_first, "tx_first");
7474
7475 cmdline_parse_inst_t cmd_start_tx_first = {
7476         .f = cmd_start_tx_first_parsed,
7477         .data = NULL,
7478         .help_str = "start tx_first: Start packet forwarding, "
7479                 "after sending 1 burst of packets",
7480         .tokens = {
7481                 (void *)&cmd_start_tx_first_start,
7482                 (void *)&cmd_start_tx_first_tx_first,
7483                 NULL,
7484         },
7485 };
7486
7487 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7488 struct cmd_start_tx_first_n_result {
7489         cmdline_fixed_string_t start;
7490         cmdline_fixed_string_t tx_first;
7491         uint32_t tx_num;
7492 };
7493
7494 static void
7495 cmd_start_tx_first_n_parsed(void *parsed_result,
7496                           __rte_unused struct cmdline *cl,
7497                           __rte_unused void *data)
7498 {
7499         struct cmd_start_tx_first_n_result *res = parsed_result;
7500
7501         start_packet_forwarding(res->tx_num);
7502 }
7503
7504 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7505         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7506                         start, "start");
7507 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7508         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7509                         tx_first, "tx_first");
7510 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7511         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7512                         tx_num, UINT32);
7513
7514 cmdline_parse_inst_t cmd_start_tx_first_n = {
7515         .f = cmd_start_tx_first_n_parsed,
7516         .data = NULL,
7517         .help_str = "start tx_first <num>: "
7518                 "packet forwarding, after sending <num> bursts of packets",
7519         .tokens = {
7520                 (void *)&cmd_start_tx_first_n_start,
7521                 (void *)&cmd_start_tx_first_n_tx_first,
7522                 (void *)&cmd_start_tx_first_n_tx_num,
7523                 NULL,
7524         },
7525 };
7526
7527 /* *** SET LINK UP *** */
7528 struct cmd_set_link_up_result {
7529         cmdline_fixed_string_t set;
7530         cmdline_fixed_string_t link_up;
7531         cmdline_fixed_string_t port;
7532         portid_t port_id;
7533 };
7534
7535 cmdline_parse_token_string_t cmd_set_link_up_set =
7536         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7537 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7538         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7539                                 "link-up");
7540 cmdline_parse_token_string_t cmd_set_link_up_port =
7541         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7542 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7543         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7544
7545 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7546                              __rte_unused struct cmdline *cl,
7547                              __rte_unused void *data)
7548 {
7549         struct cmd_set_link_up_result *res = parsed_result;
7550         dev_set_link_up(res->port_id);
7551 }
7552
7553 cmdline_parse_inst_t cmd_set_link_up = {
7554         .f = cmd_set_link_up_parsed,
7555         .data = NULL,
7556         .help_str = "set link-up port <port id>",
7557         .tokens = {
7558                 (void *)&cmd_set_link_up_set,
7559                 (void *)&cmd_set_link_up_link_up,
7560                 (void *)&cmd_set_link_up_port,
7561                 (void *)&cmd_set_link_up_port_id,
7562                 NULL,
7563         },
7564 };
7565
7566 /* *** SET LINK DOWN *** */
7567 struct cmd_set_link_down_result {
7568         cmdline_fixed_string_t set;
7569         cmdline_fixed_string_t link_down;
7570         cmdline_fixed_string_t port;
7571         portid_t port_id;
7572 };
7573
7574 cmdline_parse_token_string_t cmd_set_link_down_set =
7575         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7576 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7577         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7578                                 "link-down");
7579 cmdline_parse_token_string_t cmd_set_link_down_port =
7580         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7581 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7582         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7583
7584 static void cmd_set_link_down_parsed(
7585                                 __rte_unused void *parsed_result,
7586                                 __rte_unused struct cmdline *cl,
7587                                 __rte_unused void *data)
7588 {
7589         struct cmd_set_link_down_result *res = parsed_result;
7590         dev_set_link_down(res->port_id);
7591 }
7592
7593 cmdline_parse_inst_t cmd_set_link_down = {
7594         .f = cmd_set_link_down_parsed,
7595         .data = NULL,
7596         .help_str = "set link-down port <port id>",
7597         .tokens = {
7598                 (void *)&cmd_set_link_down_set,
7599                 (void *)&cmd_set_link_down_link_down,
7600                 (void *)&cmd_set_link_down_port,
7601                 (void *)&cmd_set_link_down_port_id,
7602                 NULL,
7603         },
7604 };
7605
7606 /* *** SHOW CFG *** */
7607 struct cmd_showcfg_result {
7608         cmdline_fixed_string_t show;
7609         cmdline_fixed_string_t cfg;
7610         cmdline_fixed_string_t what;
7611 };
7612
7613 static void cmd_showcfg_parsed(void *parsed_result,
7614                                __rte_unused struct cmdline *cl,
7615                                __rte_unused void *data)
7616 {
7617         struct cmd_showcfg_result *res = parsed_result;
7618         if (!strcmp(res->what, "rxtx"))
7619                 rxtx_config_display();
7620         else if (!strcmp(res->what, "cores"))
7621                 fwd_lcores_config_display();
7622         else if (!strcmp(res->what, "fwd"))
7623                 pkt_fwd_config_display(&cur_fwd_config);
7624         else if (!strcmp(res->what, "rxoffs"))
7625                 show_rx_pkt_offsets();
7626         else if (!strcmp(res->what, "rxpkts"))
7627                 show_rx_pkt_segments();
7628         else if (!strcmp(res->what, "txpkts"))
7629                 show_tx_pkt_segments();
7630         else if (!strcmp(res->what, "txtimes"))
7631                 show_tx_pkt_times();
7632 }
7633
7634 cmdline_parse_token_string_t cmd_showcfg_show =
7635         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7636 cmdline_parse_token_string_t cmd_showcfg_port =
7637         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7638 cmdline_parse_token_string_t cmd_showcfg_what =
7639         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7640                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7641
7642 cmdline_parse_inst_t cmd_showcfg = {
7643         .f = cmd_showcfg_parsed,
7644         .data = NULL,
7645         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7646         .tokens = {
7647                 (void *)&cmd_showcfg_show,
7648                 (void *)&cmd_showcfg_port,
7649                 (void *)&cmd_showcfg_what,
7650                 NULL,
7651         },
7652 };
7653
7654 /* *** SHOW ALL PORT INFO *** */
7655 struct cmd_showportall_result {
7656         cmdline_fixed_string_t show;
7657         cmdline_fixed_string_t port;
7658         cmdline_fixed_string_t what;
7659         cmdline_fixed_string_t all;
7660 };
7661
7662 static void cmd_showportall_parsed(void *parsed_result,
7663                                 __rte_unused struct cmdline *cl,
7664                                 __rte_unused void *data)
7665 {
7666         portid_t i;
7667
7668         struct cmd_showportall_result *res = parsed_result;
7669         if (!strcmp(res->show, "clear")) {
7670                 if (!strcmp(res->what, "stats"))
7671                         RTE_ETH_FOREACH_DEV(i)
7672                                 nic_stats_clear(i);
7673                 else if (!strcmp(res->what, "xstats"))
7674                         RTE_ETH_FOREACH_DEV(i)
7675                                 nic_xstats_clear(i);
7676         } else if (!strcmp(res->what, "info"))
7677                 RTE_ETH_FOREACH_DEV(i)
7678                         port_infos_display(i);
7679         else if (!strcmp(res->what, "summary")) {
7680                 port_summary_header_display();
7681                 RTE_ETH_FOREACH_DEV(i)
7682                         port_summary_display(i);
7683         }
7684         else if (!strcmp(res->what, "stats"))
7685                 RTE_ETH_FOREACH_DEV(i)
7686                         nic_stats_display(i);
7687         else if (!strcmp(res->what, "xstats"))
7688                 RTE_ETH_FOREACH_DEV(i)
7689                         nic_xstats_display(i);
7690         else if (!strcmp(res->what, "fdir"))
7691                 RTE_ETH_FOREACH_DEV(i)
7692                         fdir_get_infos(i);
7693         else if (!strcmp(res->what, "stat_qmap"))
7694                 RTE_ETH_FOREACH_DEV(i)
7695                         nic_stats_mapping_display(i);
7696         else if (!strcmp(res->what, "dcb_tc"))
7697                 RTE_ETH_FOREACH_DEV(i)
7698                         port_dcb_info_display(i);
7699         else if (!strcmp(res->what, "cap"))
7700                 RTE_ETH_FOREACH_DEV(i)
7701                         port_offload_cap_display(i);
7702 }
7703
7704 cmdline_parse_token_string_t cmd_showportall_show =
7705         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7706                                  "show#clear");
7707 cmdline_parse_token_string_t cmd_showportall_port =
7708         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7709 cmdline_parse_token_string_t cmd_showportall_what =
7710         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7711                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7712 cmdline_parse_token_string_t cmd_showportall_all =
7713         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7714 cmdline_parse_inst_t cmd_showportall = {
7715         .f = cmd_showportall_parsed,
7716         .data = NULL,
7717         .help_str = "show|clear port "
7718                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7719         .tokens = {
7720                 (void *)&cmd_showportall_show,
7721                 (void *)&cmd_showportall_port,
7722                 (void *)&cmd_showportall_what,
7723                 (void *)&cmd_showportall_all,
7724                 NULL,
7725         },
7726 };
7727
7728 /* *** SHOW PORT INFO *** */
7729 struct cmd_showport_result {
7730         cmdline_fixed_string_t show;
7731         cmdline_fixed_string_t port;
7732         cmdline_fixed_string_t what;
7733         uint16_t portnum;
7734 };
7735
7736 static void cmd_showport_parsed(void *parsed_result,
7737                                 __rte_unused struct cmdline *cl,
7738                                 __rte_unused void *data)
7739 {
7740         struct cmd_showport_result *res = parsed_result;
7741         if (!strcmp(res->show, "clear")) {
7742                 if (!strcmp(res->what, "stats"))
7743                         nic_stats_clear(res->portnum);
7744                 else if (!strcmp(res->what, "xstats"))
7745                         nic_xstats_clear(res->portnum);
7746         } else if (!strcmp(res->what, "info"))
7747                 port_infos_display(res->portnum);
7748         else if (!strcmp(res->what, "summary")) {
7749                 port_summary_header_display();
7750                 port_summary_display(res->portnum);
7751         }
7752         else if (!strcmp(res->what, "stats"))
7753                 nic_stats_display(res->portnum);
7754         else if (!strcmp(res->what, "xstats"))
7755                 nic_xstats_display(res->portnum);
7756         else if (!strcmp(res->what, "fdir"))
7757                  fdir_get_infos(res->portnum);
7758         else if (!strcmp(res->what, "stat_qmap"))
7759                 nic_stats_mapping_display(res->portnum);
7760         else if (!strcmp(res->what, "dcb_tc"))
7761                 port_dcb_info_display(res->portnum);
7762         else if (!strcmp(res->what, "cap"))
7763                 port_offload_cap_display(res->portnum);
7764 }
7765
7766 cmdline_parse_token_string_t cmd_showport_show =
7767         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7768                                  "show#clear");
7769 cmdline_parse_token_string_t cmd_showport_port =
7770         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7771 cmdline_parse_token_string_t cmd_showport_what =
7772         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7773                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7774 cmdline_parse_token_num_t cmd_showport_portnum =
7775         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7776
7777 cmdline_parse_inst_t cmd_showport = {
7778         .f = cmd_showport_parsed,
7779         .data = NULL,
7780         .help_str = "show|clear port "
7781                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7782                 "<port_id>",
7783         .tokens = {
7784                 (void *)&cmd_showport_show,
7785                 (void *)&cmd_showport_port,
7786                 (void *)&cmd_showport_what,
7787                 (void *)&cmd_showport_portnum,
7788                 NULL,
7789         },
7790 };
7791
7792 /* *** SHOW DEVICE INFO *** */
7793 struct cmd_showdevice_result {
7794         cmdline_fixed_string_t show;
7795         cmdline_fixed_string_t device;
7796         cmdline_fixed_string_t what;
7797         cmdline_fixed_string_t identifier;
7798 };
7799
7800 static void cmd_showdevice_parsed(void *parsed_result,
7801                                 __rte_unused struct cmdline *cl,
7802                                 __rte_unused void *data)
7803 {
7804         struct cmd_showdevice_result *res = parsed_result;
7805         if (!strcmp(res->what, "info")) {
7806                 if (!strcmp(res->identifier, "all"))
7807                         device_infos_display(NULL);
7808                 else
7809                         device_infos_display(res->identifier);
7810         }
7811 }
7812
7813 cmdline_parse_token_string_t cmd_showdevice_show =
7814         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7815                                  "show");
7816 cmdline_parse_token_string_t cmd_showdevice_device =
7817         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7818 cmdline_parse_token_string_t cmd_showdevice_what =
7819         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7820                                  "info");
7821 cmdline_parse_token_string_t cmd_showdevice_identifier =
7822         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7823                         identifier, NULL);
7824
7825 cmdline_parse_inst_t cmd_showdevice = {
7826         .f = cmd_showdevice_parsed,
7827         .data = NULL,
7828         .help_str = "show device info <identifier>|all",
7829         .tokens = {
7830                 (void *)&cmd_showdevice_show,
7831                 (void *)&cmd_showdevice_device,
7832                 (void *)&cmd_showdevice_what,
7833                 (void *)&cmd_showdevice_identifier,
7834                 NULL,
7835         },
7836 };
7837
7838 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7839 struct cmd_showeeprom_result {
7840         cmdline_fixed_string_t show;
7841         cmdline_fixed_string_t port;
7842         uint16_t portnum;
7843         cmdline_fixed_string_t type;
7844 };
7845
7846 static void cmd_showeeprom_parsed(void *parsed_result,
7847                 __rte_unused struct cmdline *cl,
7848                 __rte_unused void *data)
7849 {
7850         struct cmd_showeeprom_result *res = parsed_result;
7851
7852         if (!strcmp(res->type, "eeprom"))
7853                 port_eeprom_display(res->portnum);
7854         else if (!strcmp(res->type, "module_eeprom"))
7855                 port_module_eeprom_display(res->portnum);
7856         else
7857                 printf("Unknown argument\n");
7858 }
7859
7860 cmdline_parse_token_string_t cmd_showeeprom_show =
7861         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7862 cmdline_parse_token_string_t cmd_showeeprom_port =
7863         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7864 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7865         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7866 cmdline_parse_token_string_t cmd_showeeprom_type =
7867         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7868
7869 cmdline_parse_inst_t cmd_showeeprom = {
7870         .f = cmd_showeeprom_parsed,
7871         .data = NULL,
7872         .help_str = "show port <port_id> module_eeprom|eeprom",
7873         .tokens = {
7874                 (void *)&cmd_showeeprom_show,
7875                 (void *)&cmd_showeeprom_port,
7876                 (void *)&cmd_showeeprom_portnum,
7877                 (void *)&cmd_showeeprom_type,
7878                 NULL,
7879         },
7880 };
7881
7882 /* *** SHOW QUEUE INFO *** */
7883 struct cmd_showqueue_result {
7884         cmdline_fixed_string_t show;
7885         cmdline_fixed_string_t type;
7886         cmdline_fixed_string_t what;
7887         uint16_t portnum;
7888         uint16_t queuenum;
7889 };
7890
7891 static void
7892 cmd_showqueue_parsed(void *parsed_result,
7893         __rte_unused struct cmdline *cl,
7894         __rte_unused void *data)
7895 {
7896         struct cmd_showqueue_result *res = parsed_result;
7897
7898         if (!strcmp(res->type, "rxq"))
7899                 rx_queue_infos_display(res->portnum, res->queuenum);
7900         else if (!strcmp(res->type, "txq"))
7901                 tx_queue_infos_display(res->portnum, res->queuenum);
7902 }
7903
7904 cmdline_parse_token_string_t cmd_showqueue_show =
7905         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7906 cmdline_parse_token_string_t cmd_showqueue_type =
7907         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7908 cmdline_parse_token_string_t cmd_showqueue_what =
7909         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7910 cmdline_parse_token_num_t cmd_showqueue_portnum =
7911         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7912 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7913         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7914
7915 cmdline_parse_inst_t cmd_showqueue = {
7916         .f = cmd_showqueue_parsed,
7917         .data = NULL,
7918         .help_str = "show rxq|txq info <port_id> <queue_id>",
7919         .tokens = {
7920                 (void *)&cmd_showqueue_show,
7921                 (void *)&cmd_showqueue_type,
7922                 (void *)&cmd_showqueue_what,
7923                 (void *)&cmd_showqueue_portnum,
7924                 (void *)&cmd_showqueue_queuenum,
7925                 NULL,
7926         },
7927 };
7928
7929 /* show/clear fwd engine statistics */
7930 struct fwd_result {
7931         cmdline_fixed_string_t action;
7932         cmdline_fixed_string_t fwd;
7933         cmdline_fixed_string_t stats;
7934         cmdline_fixed_string_t all;
7935 };
7936
7937 cmdline_parse_token_string_t cmd_fwd_action =
7938         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7939 cmdline_parse_token_string_t cmd_fwd_fwd =
7940         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7941 cmdline_parse_token_string_t cmd_fwd_stats =
7942         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7943 cmdline_parse_token_string_t cmd_fwd_all =
7944         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7945
7946 static void
7947 cmd_showfwdall_parsed(void *parsed_result,
7948                       __rte_unused struct cmdline *cl,
7949                       __rte_unused void *data)
7950 {
7951         struct fwd_result *res = parsed_result;
7952
7953         if (!strcmp(res->action, "show"))
7954                 fwd_stats_display();
7955         else
7956                 fwd_stats_reset();
7957 }
7958
7959 static cmdline_parse_inst_t cmd_showfwdall = {
7960         .f = cmd_showfwdall_parsed,
7961         .data = NULL,
7962         .help_str = "show|clear fwd stats all",
7963         .tokens = {
7964                 (void *)&cmd_fwd_action,
7965                 (void *)&cmd_fwd_fwd,
7966                 (void *)&cmd_fwd_stats,
7967                 (void *)&cmd_fwd_all,
7968                 NULL,
7969         },
7970 };
7971
7972 /* *** READ PORT REGISTER *** */
7973 struct cmd_read_reg_result {
7974         cmdline_fixed_string_t read;
7975         cmdline_fixed_string_t reg;
7976         portid_t port_id;
7977         uint32_t reg_off;
7978 };
7979
7980 static void
7981 cmd_read_reg_parsed(void *parsed_result,
7982                     __rte_unused struct cmdline *cl,
7983                     __rte_unused void *data)
7984 {
7985         struct cmd_read_reg_result *res = parsed_result;
7986         port_reg_display(res->port_id, res->reg_off);
7987 }
7988
7989 cmdline_parse_token_string_t cmd_read_reg_read =
7990         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7991 cmdline_parse_token_string_t cmd_read_reg_reg =
7992         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7993 cmdline_parse_token_num_t cmd_read_reg_port_id =
7994         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7995 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7996         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7997
7998 cmdline_parse_inst_t cmd_read_reg = {
7999         .f = cmd_read_reg_parsed,
8000         .data = NULL,
8001         .help_str = "read reg <port_id> <reg_off>",
8002         .tokens = {
8003                 (void *)&cmd_read_reg_read,
8004                 (void *)&cmd_read_reg_reg,
8005                 (void *)&cmd_read_reg_port_id,
8006                 (void *)&cmd_read_reg_reg_off,
8007                 NULL,
8008         },
8009 };
8010
8011 /* *** READ PORT REGISTER BIT FIELD *** */
8012 struct cmd_read_reg_bit_field_result {
8013         cmdline_fixed_string_t read;
8014         cmdline_fixed_string_t regfield;
8015         portid_t port_id;
8016         uint32_t reg_off;
8017         uint8_t bit1_pos;
8018         uint8_t bit2_pos;
8019 };
8020
8021 static void
8022 cmd_read_reg_bit_field_parsed(void *parsed_result,
8023                               __rte_unused struct cmdline *cl,
8024                               __rte_unused void *data)
8025 {
8026         struct cmd_read_reg_bit_field_result *res = parsed_result;
8027         port_reg_bit_field_display(res->port_id, res->reg_off,
8028                                    res->bit1_pos, res->bit2_pos);
8029 }
8030
8031 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8032         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8033                                  "read");
8034 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8035         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8036                                  regfield, "regfield");
8037 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8038         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8039                               UINT16);
8040 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8041         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8042                               UINT32);
8043 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8044         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8045                               UINT8);
8046 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8047         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8048                               UINT8);
8049
8050 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8051         .f = cmd_read_reg_bit_field_parsed,
8052         .data = NULL,
8053         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8054         "Read register bit field between bit_x and bit_y included",
8055         .tokens = {
8056                 (void *)&cmd_read_reg_bit_field_read,
8057                 (void *)&cmd_read_reg_bit_field_regfield,
8058                 (void *)&cmd_read_reg_bit_field_port_id,
8059                 (void *)&cmd_read_reg_bit_field_reg_off,
8060                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8061                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8062                 NULL,
8063         },
8064 };
8065
8066 /* *** READ PORT REGISTER BIT *** */
8067 struct cmd_read_reg_bit_result {
8068         cmdline_fixed_string_t read;
8069         cmdline_fixed_string_t regbit;
8070         portid_t port_id;
8071         uint32_t reg_off;
8072         uint8_t bit_pos;
8073 };
8074
8075 static void
8076 cmd_read_reg_bit_parsed(void *parsed_result,
8077                         __rte_unused struct cmdline *cl,
8078                         __rte_unused void *data)
8079 {
8080         struct cmd_read_reg_bit_result *res = parsed_result;
8081         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8082 }
8083
8084 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8085         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8086 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8087         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8088                                  regbit, "regbit");
8089 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8090         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
8091 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8092         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
8093 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8094         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
8095
8096 cmdline_parse_inst_t cmd_read_reg_bit = {
8097         .f = cmd_read_reg_bit_parsed,
8098         .data = NULL,
8099         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8100         .tokens = {
8101                 (void *)&cmd_read_reg_bit_read,
8102                 (void *)&cmd_read_reg_bit_regbit,
8103                 (void *)&cmd_read_reg_bit_port_id,
8104                 (void *)&cmd_read_reg_bit_reg_off,
8105                 (void *)&cmd_read_reg_bit_bit_pos,
8106                 NULL,
8107         },
8108 };
8109
8110 /* *** WRITE PORT REGISTER *** */
8111 struct cmd_write_reg_result {
8112         cmdline_fixed_string_t write;
8113         cmdline_fixed_string_t reg;
8114         portid_t port_id;
8115         uint32_t reg_off;
8116         uint32_t value;
8117 };
8118
8119 static void
8120 cmd_write_reg_parsed(void *parsed_result,
8121                      __rte_unused struct cmdline *cl,
8122                      __rte_unused void *data)
8123 {
8124         struct cmd_write_reg_result *res = parsed_result;
8125         port_reg_set(res->port_id, res->reg_off, res->value);
8126 }
8127
8128 cmdline_parse_token_string_t cmd_write_reg_write =
8129         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8130 cmdline_parse_token_string_t cmd_write_reg_reg =
8131         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8132 cmdline_parse_token_num_t cmd_write_reg_port_id =
8133         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
8134 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8135         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
8136 cmdline_parse_token_num_t cmd_write_reg_value =
8137         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
8138
8139 cmdline_parse_inst_t cmd_write_reg = {
8140         .f = cmd_write_reg_parsed,
8141         .data = NULL,
8142         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8143         .tokens = {
8144                 (void *)&cmd_write_reg_write,
8145                 (void *)&cmd_write_reg_reg,
8146                 (void *)&cmd_write_reg_port_id,
8147                 (void *)&cmd_write_reg_reg_off,
8148                 (void *)&cmd_write_reg_value,
8149                 NULL,
8150         },
8151 };
8152
8153 /* *** WRITE PORT REGISTER BIT FIELD *** */
8154 struct cmd_write_reg_bit_field_result {
8155         cmdline_fixed_string_t write;
8156         cmdline_fixed_string_t regfield;
8157         portid_t port_id;
8158         uint32_t reg_off;
8159         uint8_t bit1_pos;
8160         uint8_t bit2_pos;
8161         uint32_t value;
8162 };
8163
8164 static void
8165 cmd_write_reg_bit_field_parsed(void *parsed_result,
8166                                __rte_unused struct cmdline *cl,
8167                                __rte_unused void *data)
8168 {
8169         struct cmd_write_reg_bit_field_result *res = parsed_result;
8170         port_reg_bit_field_set(res->port_id, res->reg_off,
8171                           res->bit1_pos, res->bit2_pos, res->value);
8172 }
8173
8174 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8175         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8176                                  "write");
8177 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8178         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8179                                  regfield, "regfield");
8180 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8181         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8182                               UINT16);
8183 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8184         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8185                               UINT32);
8186 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8187         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8188                               UINT8);
8189 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8190         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8191                               UINT8);
8192 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8193         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8194                               UINT32);
8195
8196 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8197         .f = cmd_write_reg_bit_field_parsed,
8198         .data = NULL,
8199         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8200                 "<reg_value>: "
8201                 "Set register bit field between bit_x and bit_y included",
8202         .tokens = {
8203                 (void *)&cmd_write_reg_bit_field_write,
8204                 (void *)&cmd_write_reg_bit_field_regfield,
8205                 (void *)&cmd_write_reg_bit_field_port_id,
8206                 (void *)&cmd_write_reg_bit_field_reg_off,
8207                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8208                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8209                 (void *)&cmd_write_reg_bit_field_value,
8210                 NULL,
8211         },
8212 };
8213
8214 /* *** WRITE PORT REGISTER BIT *** */
8215 struct cmd_write_reg_bit_result {
8216         cmdline_fixed_string_t write;
8217         cmdline_fixed_string_t regbit;
8218         portid_t port_id;
8219         uint32_t reg_off;
8220         uint8_t bit_pos;
8221         uint8_t value;
8222 };
8223
8224 static void
8225 cmd_write_reg_bit_parsed(void *parsed_result,
8226                          __rte_unused struct cmdline *cl,
8227                          __rte_unused void *data)
8228 {
8229         struct cmd_write_reg_bit_result *res = parsed_result;
8230         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8231 }
8232
8233 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8234         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8235                                  "write");
8236 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8237         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8238                                  regbit, "regbit");
8239 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8240         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8241 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8242         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8243 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8244         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8245 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8246         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8247
8248 cmdline_parse_inst_t cmd_write_reg_bit = {
8249         .f = cmd_write_reg_bit_parsed,
8250         .data = NULL,
8251         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8252                 "0 <= bit_x <= 31",
8253         .tokens = {
8254                 (void *)&cmd_write_reg_bit_write,
8255                 (void *)&cmd_write_reg_bit_regbit,
8256                 (void *)&cmd_write_reg_bit_port_id,
8257                 (void *)&cmd_write_reg_bit_reg_off,
8258                 (void *)&cmd_write_reg_bit_bit_pos,
8259                 (void *)&cmd_write_reg_bit_value,
8260                 NULL,
8261         },
8262 };
8263
8264 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8265 struct cmd_read_rxd_txd_result {
8266         cmdline_fixed_string_t read;
8267         cmdline_fixed_string_t rxd_txd;
8268         portid_t port_id;
8269         uint16_t queue_id;
8270         uint16_t desc_id;
8271 };
8272
8273 static void
8274 cmd_read_rxd_txd_parsed(void *parsed_result,
8275                         __rte_unused struct cmdline *cl,
8276                         __rte_unused void *data)
8277 {
8278         struct cmd_read_rxd_txd_result *res = parsed_result;
8279
8280         if (!strcmp(res->rxd_txd, "rxd"))
8281                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8282         else if (!strcmp(res->rxd_txd, "txd"))
8283                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8284 }
8285
8286 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8287         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8288 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8289         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8290                                  "rxd#txd");
8291 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8292         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8293 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8294         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8295 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8296         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8297
8298 cmdline_parse_inst_t cmd_read_rxd_txd = {
8299         .f = cmd_read_rxd_txd_parsed,
8300         .data = NULL,
8301         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8302         .tokens = {
8303                 (void *)&cmd_read_rxd_txd_read,
8304                 (void *)&cmd_read_rxd_txd_rxd_txd,
8305                 (void *)&cmd_read_rxd_txd_port_id,
8306                 (void *)&cmd_read_rxd_txd_queue_id,
8307                 (void *)&cmd_read_rxd_txd_desc_id,
8308                 NULL,
8309         },
8310 };
8311
8312 /* *** QUIT *** */
8313 struct cmd_quit_result {
8314         cmdline_fixed_string_t quit;
8315 };
8316
8317 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8318                             struct cmdline *cl,
8319                             __rte_unused void *data)
8320 {
8321         cmdline_quit(cl);
8322 }
8323
8324 cmdline_parse_token_string_t cmd_quit_quit =
8325         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8326
8327 cmdline_parse_inst_t cmd_quit = {
8328         .f = cmd_quit_parsed,
8329         .data = NULL,
8330         .help_str = "quit: Exit application",
8331         .tokens = {
8332                 (void *)&cmd_quit_quit,
8333                 NULL,
8334         },
8335 };
8336
8337 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8338 struct cmd_mac_addr_result {
8339         cmdline_fixed_string_t mac_addr_cmd;
8340         cmdline_fixed_string_t what;
8341         uint16_t port_num;
8342         struct rte_ether_addr address;
8343 };
8344
8345 static void cmd_mac_addr_parsed(void *parsed_result,
8346                 __rte_unused struct cmdline *cl,
8347                 __rte_unused void *data)
8348 {
8349         struct cmd_mac_addr_result *res = parsed_result;
8350         int ret;
8351
8352         if (strcmp(res->what, "add") == 0)
8353                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8354         else if (strcmp(res->what, "set") == 0)
8355                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8356                                                        &res->address);
8357         else
8358                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8359
8360         /* check the return value and print it if is < 0 */
8361         if(ret < 0)
8362                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8363
8364 }
8365
8366 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8367         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8368                                 "mac_addr");
8369 cmdline_parse_token_string_t cmd_mac_addr_what =
8370         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8371                                 "add#remove#set");
8372 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8373                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8374                                         UINT16);
8375 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8376                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8377
8378 cmdline_parse_inst_t cmd_mac_addr = {
8379         .f = cmd_mac_addr_parsed,
8380         .data = (void *)0,
8381         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8382                         "Add/Remove/Set MAC address on port_id",
8383         .tokens = {
8384                 (void *)&cmd_mac_addr_cmd,
8385                 (void *)&cmd_mac_addr_what,
8386                 (void *)&cmd_mac_addr_portnum,
8387                 (void *)&cmd_mac_addr_addr,
8388                 NULL,
8389         },
8390 };
8391
8392 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8393 struct cmd_eth_peer_result {
8394         cmdline_fixed_string_t set;
8395         cmdline_fixed_string_t eth_peer;
8396         portid_t port_id;
8397         cmdline_fixed_string_t peer_addr;
8398 };
8399
8400 static void cmd_set_eth_peer_parsed(void *parsed_result,
8401                         __rte_unused struct cmdline *cl,
8402                         __rte_unused void *data)
8403 {
8404                 struct cmd_eth_peer_result *res = parsed_result;
8405
8406                 if (test_done == 0) {
8407                         printf("Please stop forwarding first\n");
8408                         return;
8409                 }
8410                 if (!strcmp(res->eth_peer, "eth-peer")) {
8411                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8412                         fwd_config_setup();
8413                 }
8414 }
8415 cmdline_parse_token_string_t cmd_eth_peer_set =
8416         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8417 cmdline_parse_token_string_t cmd_eth_peer =
8418         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8419 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8420         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8421 cmdline_parse_token_string_t cmd_eth_peer_addr =
8422         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8423
8424 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8425         .f = cmd_set_eth_peer_parsed,
8426         .data = NULL,
8427         .help_str = "set eth-peer <port_id> <peer_mac>",
8428         .tokens = {
8429                 (void *)&cmd_eth_peer_set,
8430                 (void *)&cmd_eth_peer,
8431                 (void *)&cmd_eth_peer_port_id,
8432                 (void *)&cmd_eth_peer_addr,
8433                 NULL,
8434         },
8435 };
8436
8437 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8438 struct cmd_set_qmap_result {
8439         cmdline_fixed_string_t set;
8440         cmdline_fixed_string_t qmap;
8441         cmdline_fixed_string_t what;
8442         portid_t port_id;
8443         uint16_t queue_id;
8444         uint8_t map_value;
8445 };
8446
8447 static void
8448 cmd_set_qmap_parsed(void *parsed_result,
8449                        __rte_unused struct cmdline *cl,
8450                        __rte_unused void *data)
8451 {
8452         struct cmd_set_qmap_result *res = parsed_result;
8453         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8454
8455         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8456 }
8457
8458 cmdline_parse_token_string_t cmd_setqmap_set =
8459         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8460                                  set, "set");
8461 cmdline_parse_token_string_t cmd_setqmap_qmap =
8462         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8463                                  qmap, "stat_qmap");
8464 cmdline_parse_token_string_t cmd_setqmap_what =
8465         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8466                                  what, "tx#rx");
8467 cmdline_parse_token_num_t cmd_setqmap_portid =
8468         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8469                               port_id, UINT16);
8470 cmdline_parse_token_num_t cmd_setqmap_queueid =
8471         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8472                               queue_id, UINT16);
8473 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8474         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8475                               map_value, UINT8);
8476
8477 cmdline_parse_inst_t cmd_set_qmap = {
8478         .f = cmd_set_qmap_parsed,
8479         .data = NULL,
8480         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8481                 "Set statistics mapping value on tx|rx queue_id of port_id",
8482         .tokens = {
8483                 (void *)&cmd_setqmap_set,
8484                 (void *)&cmd_setqmap_qmap,
8485                 (void *)&cmd_setqmap_what,
8486                 (void *)&cmd_setqmap_portid,
8487                 (void *)&cmd_setqmap_queueid,
8488                 (void *)&cmd_setqmap_mapvalue,
8489                 NULL,
8490         },
8491 };
8492
8493 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8494 struct cmd_set_xstats_hide_zero_result {
8495         cmdline_fixed_string_t keyword;
8496         cmdline_fixed_string_t name;
8497         cmdline_fixed_string_t on_off;
8498 };
8499
8500 static void
8501 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8502                         __rte_unused struct cmdline *cl,
8503                         __rte_unused void *data)
8504 {
8505         struct cmd_set_xstats_hide_zero_result *res;
8506         uint16_t on_off = 0;
8507
8508         res = parsed_result;
8509         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8510         set_xstats_hide_zero(on_off);
8511 }
8512
8513 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8514         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8515                                  keyword, "set");
8516 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8517         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8518                                  name, "xstats-hide-zero");
8519 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8520         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8521                                  on_off, "on#off");
8522
8523 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8524         .f = cmd_set_xstats_hide_zero_parsed,
8525         .data = NULL,
8526         .help_str = "set xstats-hide-zero on|off",
8527         .tokens = {
8528                 (void *)&cmd_set_xstats_hide_zero_keyword,
8529                 (void *)&cmd_set_xstats_hide_zero_name,
8530                 (void *)&cmd_set_xstats_hide_zero_on_off,
8531                 NULL,
8532         },
8533 };
8534
8535 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8536 struct cmd_set_record_core_cycles_result {
8537         cmdline_fixed_string_t keyword;
8538         cmdline_fixed_string_t name;
8539         cmdline_fixed_string_t on_off;
8540 };
8541
8542 static void
8543 cmd_set_record_core_cycles_parsed(void *parsed_result,
8544                         __rte_unused struct cmdline *cl,
8545                         __rte_unused void *data)
8546 {
8547         struct cmd_set_record_core_cycles_result *res;
8548         uint16_t on_off = 0;
8549
8550         res = parsed_result;
8551         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8552         set_record_core_cycles(on_off);
8553 }
8554
8555 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8556         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8557                                  keyword, "set");
8558 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8559         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8560                                  name, "record-core-cycles");
8561 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8562         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8563                                  on_off, "on#off");
8564
8565 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8566         .f = cmd_set_record_core_cycles_parsed,
8567         .data = NULL,
8568         .help_str = "set record-core-cycles on|off",
8569         .tokens = {
8570                 (void *)&cmd_set_record_core_cycles_keyword,
8571                 (void *)&cmd_set_record_core_cycles_name,
8572                 (void *)&cmd_set_record_core_cycles_on_off,
8573                 NULL,
8574         },
8575 };
8576
8577 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8578 struct cmd_set_record_burst_stats_result {
8579         cmdline_fixed_string_t keyword;
8580         cmdline_fixed_string_t name;
8581         cmdline_fixed_string_t on_off;
8582 };
8583
8584 static void
8585 cmd_set_record_burst_stats_parsed(void *parsed_result,
8586                         __rte_unused struct cmdline *cl,
8587                         __rte_unused void *data)
8588 {
8589         struct cmd_set_record_burst_stats_result *res;
8590         uint16_t on_off = 0;
8591
8592         res = parsed_result;
8593         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8594         set_record_burst_stats(on_off);
8595 }
8596
8597 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8598         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8599                                  keyword, "set");
8600 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8601         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8602                                  name, "record-burst-stats");
8603 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8604         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8605                                  on_off, "on#off");
8606
8607 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8608         .f = cmd_set_record_burst_stats_parsed,
8609         .data = NULL,
8610         .help_str = "set record-burst-stats on|off",
8611         .tokens = {
8612                 (void *)&cmd_set_record_burst_stats_keyword,
8613                 (void *)&cmd_set_record_burst_stats_name,
8614                 (void *)&cmd_set_record_burst_stats_on_off,
8615                 NULL,
8616         },
8617 };
8618
8619 /* *** CONFIGURE UNICAST HASH TABLE *** */
8620 struct cmd_set_uc_hash_table {
8621         cmdline_fixed_string_t set;
8622         cmdline_fixed_string_t port;
8623         portid_t port_id;
8624         cmdline_fixed_string_t what;
8625         struct rte_ether_addr address;
8626         cmdline_fixed_string_t mode;
8627 };
8628
8629 static void
8630 cmd_set_uc_hash_parsed(void *parsed_result,
8631                        __rte_unused struct cmdline *cl,
8632                        __rte_unused void *data)
8633 {
8634         int ret=0;
8635         struct cmd_set_uc_hash_table *res = parsed_result;
8636
8637         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8638
8639         if (strcmp(res->what, "uta") == 0)
8640                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8641                                                 &res->address,(uint8_t)is_on);
8642         if (ret < 0)
8643                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8644
8645 }
8646
8647 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8648         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8649                                  set, "set");
8650 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8651         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8652                                  port, "port");
8653 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8654         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8655                               port_id, UINT16);
8656 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8657         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8658                                  what, "uta");
8659 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8660         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8661                                 address);
8662 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8663         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8664                                  mode, "on#off");
8665
8666 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8667         .f = cmd_set_uc_hash_parsed,
8668         .data = NULL,
8669         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8670         .tokens = {
8671                 (void *)&cmd_set_uc_hash_set,
8672                 (void *)&cmd_set_uc_hash_port,
8673                 (void *)&cmd_set_uc_hash_portid,
8674                 (void *)&cmd_set_uc_hash_what,
8675                 (void *)&cmd_set_uc_hash_mac,
8676                 (void *)&cmd_set_uc_hash_mode,
8677                 NULL,
8678         },
8679 };
8680
8681 struct cmd_set_uc_all_hash_table {
8682         cmdline_fixed_string_t set;
8683         cmdline_fixed_string_t port;
8684         portid_t port_id;
8685         cmdline_fixed_string_t what;
8686         cmdline_fixed_string_t value;
8687         cmdline_fixed_string_t mode;
8688 };
8689
8690 static void
8691 cmd_set_uc_all_hash_parsed(void *parsed_result,
8692                        __rte_unused struct cmdline *cl,
8693                        __rte_unused void *data)
8694 {
8695         int ret=0;
8696         struct cmd_set_uc_all_hash_table *res = parsed_result;
8697
8698         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8699
8700         if ((strcmp(res->what, "uta") == 0) &&
8701                 (strcmp(res->value, "all") == 0))
8702                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8703         if (ret < 0)
8704                 printf("bad unicast hash table parameter,"
8705                         "return code = %d \n", ret);
8706 }
8707
8708 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8709         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8710                                  set, "set");
8711 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8712         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8713                                  port, "port");
8714 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8715         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8716                               port_id, UINT16);
8717 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8718         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8719                                  what, "uta");
8720 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8721         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8722                                 value,"all");
8723 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8724         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8725                                  mode, "on#off");
8726
8727 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8728         .f = cmd_set_uc_all_hash_parsed,
8729         .data = NULL,
8730         .help_str = "set port <port_id> uta all on|off",
8731         .tokens = {
8732                 (void *)&cmd_set_uc_all_hash_set,
8733                 (void *)&cmd_set_uc_all_hash_port,
8734                 (void *)&cmd_set_uc_all_hash_portid,
8735                 (void *)&cmd_set_uc_all_hash_what,
8736                 (void *)&cmd_set_uc_all_hash_value,
8737                 (void *)&cmd_set_uc_all_hash_mode,
8738                 NULL,
8739         },
8740 };
8741
8742 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8743 struct cmd_set_vf_traffic {
8744         cmdline_fixed_string_t set;
8745         cmdline_fixed_string_t port;
8746         portid_t port_id;
8747         cmdline_fixed_string_t vf;
8748         uint8_t vf_id;
8749         cmdline_fixed_string_t what;
8750         cmdline_fixed_string_t mode;
8751 };
8752
8753 static void
8754 cmd_set_vf_traffic_parsed(void *parsed_result,
8755                        __rte_unused struct cmdline *cl,
8756                        __rte_unused void *data)
8757 {
8758         struct cmd_set_vf_traffic *res = parsed_result;
8759         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8760         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8761
8762         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8763 }
8764
8765 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8766         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8767                                  set, "set");
8768 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8769         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8770                                  port, "port");
8771 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8772         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8773                               port_id, UINT16);
8774 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8775         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8776                                  vf, "vf");
8777 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8778         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8779                               vf_id, UINT8);
8780 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8781         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8782                                  what, "tx#rx");
8783 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8784         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8785                                  mode, "on#off");
8786
8787 cmdline_parse_inst_t cmd_set_vf_traffic = {
8788         .f = cmd_set_vf_traffic_parsed,
8789         .data = NULL,
8790         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8791         .tokens = {
8792                 (void *)&cmd_setvf_traffic_set,
8793                 (void *)&cmd_setvf_traffic_port,
8794                 (void *)&cmd_setvf_traffic_portid,
8795                 (void *)&cmd_setvf_traffic_vf,
8796                 (void *)&cmd_setvf_traffic_vfid,
8797                 (void *)&cmd_setvf_traffic_what,
8798                 (void *)&cmd_setvf_traffic_mode,
8799                 NULL,
8800         },
8801 };
8802
8803 /* *** CONFIGURE VF RECEIVE MODE *** */
8804 struct cmd_set_vf_rxmode {
8805         cmdline_fixed_string_t set;
8806         cmdline_fixed_string_t port;
8807         portid_t port_id;
8808         cmdline_fixed_string_t vf;
8809         uint8_t vf_id;
8810         cmdline_fixed_string_t what;
8811         cmdline_fixed_string_t mode;
8812         cmdline_fixed_string_t on;
8813 };
8814
8815 static void
8816 cmd_set_vf_rxmode_parsed(void *parsed_result,
8817                        __rte_unused struct cmdline *cl,
8818                        __rte_unused void *data)
8819 {
8820         int ret = -ENOTSUP;
8821         uint16_t vf_rxmode = 0;
8822         struct cmd_set_vf_rxmode *res = parsed_result;
8823
8824         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8825         if (!strcmp(res->what,"rxmode")) {
8826                 if (!strcmp(res->mode, "AUPE"))
8827                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8828                 else if (!strcmp(res->mode, "ROPE"))
8829                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8830                 else if (!strcmp(res->mode, "BAM"))
8831                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8832                 else if (!strncmp(res->mode, "MPE",3))
8833                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8834         }
8835
8836         RTE_SET_USED(is_on);
8837
8838 #ifdef RTE_NET_IXGBE
8839         if (ret == -ENOTSUP)
8840                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8841                                                   vf_rxmode, (uint8_t)is_on);
8842 #endif
8843 #ifdef RTE_NET_BNXT
8844         if (ret == -ENOTSUP)
8845                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8846                                                  vf_rxmode, (uint8_t)is_on);
8847 #endif
8848         if (ret < 0)
8849                 printf("bad VF receive mode parameter, return code = %d \n",
8850                 ret);
8851 }
8852
8853 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8854         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8855                                  set, "set");
8856 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8857         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8858                                  port, "port");
8859 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8860         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8861                               port_id, UINT16);
8862 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8863         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8864                                  vf, "vf");
8865 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8866         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8867                               vf_id, UINT8);
8868 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8869         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8870                                  what, "rxmode");
8871 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8872         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8873                                  mode, "AUPE#ROPE#BAM#MPE");
8874 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8875         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8876                                  on, "on#off");
8877
8878 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8879         .f = cmd_set_vf_rxmode_parsed,
8880         .data = NULL,
8881         .help_str = "set port <port_id> vf <vf_id> rxmode "
8882                 "AUPE|ROPE|BAM|MPE on|off",
8883         .tokens = {
8884                 (void *)&cmd_set_vf_rxmode_set,
8885                 (void *)&cmd_set_vf_rxmode_port,
8886                 (void *)&cmd_set_vf_rxmode_portid,
8887                 (void *)&cmd_set_vf_rxmode_vf,
8888                 (void *)&cmd_set_vf_rxmode_vfid,
8889                 (void *)&cmd_set_vf_rxmode_what,
8890                 (void *)&cmd_set_vf_rxmode_mode,
8891                 (void *)&cmd_set_vf_rxmode_on,
8892                 NULL,
8893         },
8894 };
8895
8896 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8897 struct cmd_vf_mac_addr_result {
8898         cmdline_fixed_string_t mac_addr_cmd;
8899         cmdline_fixed_string_t what;
8900         cmdline_fixed_string_t port;
8901         uint16_t port_num;
8902         cmdline_fixed_string_t vf;
8903         uint8_t vf_num;
8904         struct rte_ether_addr address;
8905 };
8906
8907 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8908                 __rte_unused struct cmdline *cl,
8909                 __rte_unused void *data)
8910 {
8911         struct cmd_vf_mac_addr_result *res = parsed_result;
8912         int ret = -ENOTSUP;
8913
8914         if (strcmp(res->what, "add") != 0)
8915                 return;
8916
8917 #ifdef RTE_NET_I40E
8918         if (ret == -ENOTSUP)
8919                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8920                                                    &res->address);
8921 #endif
8922 #ifdef RTE_NET_BNXT
8923         if (ret == -ENOTSUP)
8924                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8925                                                 res->vf_num);
8926 #endif
8927
8928         if(ret < 0)
8929                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8930
8931 }
8932
8933 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8934         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8935                                 mac_addr_cmd,"mac_addr");
8936 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8937         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8938                                 what,"add");
8939 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8940         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8941                                 port,"port");
8942 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8943         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8944                                 port_num, UINT16);
8945 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8946         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8947                                 vf,"vf");
8948 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8949         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8950                                 vf_num, UINT8);
8951 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8952         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8953                                 address);
8954
8955 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8956         .f = cmd_vf_mac_addr_parsed,
8957         .data = (void *)0,
8958         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8959                 "Add MAC address filtering for a VF on port_id",
8960         .tokens = {
8961                 (void *)&cmd_vf_mac_addr_cmd,
8962                 (void *)&cmd_vf_mac_addr_what,
8963                 (void *)&cmd_vf_mac_addr_port,
8964                 (void *)&cmd_vf_mac_addr_portnum,
8965                 (void *)&cmd_vf_mac_addr_vf,
8966                 (void *)&cmd_vf_mac_addr_vfnum,
8967                 (void *)&cmd_vf_mac_addr_addr,
8968                 NULL,
8969         },
8970 };
8971
8972 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8973 struct cmd_vf_rx_vlan_filter {
8974         cmdline_fixed_string_t rx_vlan;
8975         cmdline_fixed_string_t what;
8976         uint16_t vlan_id;
8977         cmdline_fixed_string_t port;
8978         portid_t port_id;
8979         cmdline_fixed_string_t vf;
8980         uint64_t vf_mask;
8981 };
8982
8983 static void
8984 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8985                           __rte_unused struct cmdline *cl,
8986                           __rte_unused void *data)
8987 {
8988         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8989         int ret = -ENOTSUP;
8990
8991         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8992
8993 #ifdef RTE_NET_IXGBE
8994         if (ret == -ENOTSUP)
8995                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8996                                 res->vlan_id, res->vf_mask, is_add);
8997 #endif
8998 #ifdef RTE_NET_I40E
8999         if (ret == -ENOTSUP)
9000                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9001                                 res->vlan_id, res->vf_mask, is_add);
9002 #endif
9003 #ifdef RTE_NET_BNXT
9004         if (ret == -ENOTSUP)
9005                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9006                                 res->vlan_id, res->vf_mask, is_add);
9007 #endif
9008
9009         switch (ret) {
9010         case 0:
9011                 break;
9012         case -EINVAL:
9013                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
9014                                 res->vlan_id, res->vf_mask);
9015                 break;
9016         case -ENODEV:
9017                 printf("invalid port_id %d\n", res->port_id);
9018                 break;
9019         case -ENOTSUP:
9020                 printf("function not implemented or supported\n");
9021                 break;
9022         default:
9023                 printf("programming error: (%s)\n", strerror(-ret));
9024         }
9025 }
9026
9027 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9028         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9029                                  rx_vlan, "rx_vlan");
9030 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9031         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9032                                  what, "add#rm");
9033 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9034         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9035                               vlan_id, UINT16);
9036 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9037         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9038                                  port, "port");
9039 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9040         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9041                               port_id, UINT16);
9042 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9043         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9044                                  vf, "vf");
9045 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9046         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9047                               vf_mask, UINT64);
9048
9049 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9050         .f = cmd_vf_rx_vlan_filter_parsed,
9051         .data = NULL,
9052         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9053                 "(vf_mask = hexadecimal VF mask)",
9054         .tokens = {
9055                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9056                 (void *)&cmd_vf_rx_vlan_filter_what,
9057                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9058                 (void *)&cmd_vf_rx_vlan_filter_port,
9059                 (void *)&cmd_vf_rx_vlan_filter_portid,
9060                 (void *)&cmd_vf_rx_vlan_filter_vf,
9061                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9062                 NULL,
9063         },
9064 };
9065
9066 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9067 struct cmd_queue_rate_limit_result {
9068         cmdline_fixed_string_t set;
9069         cmdline_fixed_string_t port;
9070         uint16_t port_num;
9071         cmdline_fixed_string_t queue;
9072         uint8_t queue_num;
9073         cmdline_fixed_string_t rate;
9074         uint16_t rate_num;
9075 };
9076
9077 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9078                 __rte_unused struct cmdline *cl,
9079                 __rte_unused void *data)
9080 {
9081         struct cmd_queue_rate_limit_result *res = parsed_result;
9082         int ret = 0;
9083
9084         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9085                 && (strcmp(res->queue, "queue") == 0)
9086                 && (strcmp(res->rate, "rate") == 0))
9087                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9088                                         res->rate_num);
9089         if (ret < 0)
9090                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9091
9092 }
9093
9094 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9095         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9096                                 set, "set");
9097 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9098         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9099                                 port, "port");
9100 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9101         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9102                                 port_num, UINT16);
9103 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9104         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9105                                 queue, "queue");
9106 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9107         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9108                                 queue_num, UINT8);
9109 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9110         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9111                                 rate, "rate");
9112 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9113         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9114                                 rate_num, UINT16);
9115
9116 cmdline_parse_inst_t cmd_queue_rate_limit = {
9117         .f = cmd_queue_rate_limit_parsed,
9118         .data = (void *)0,
9119         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9120                 "Set rate limit for a queue on port_id",
9121         .tokens = {
9122                 (void *)&cmd_queue_rate_limit_set,
9123                 (void *)&cmd_queue_rate_limit_port,
9124                 (void *)&cmd_queue_rate_limit_portnum,
9125                 (void *)&cmd_queue_rate_limit_queue,
9126                 (void *)&cmd_queue_rate_limit_queuenum,
9127                 (void *)&cmd_queue_rate_limit_rate,
9128                 (void *)&cmd_queue_rate_limit_ratenum,
9129                 NULL,
9130         },
9131 };
9132
9133 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9134 struct cmd_vf_rate_limit_result {
9135         cmdline_fixed_string_t set;
9136         cmdline_fixed_string_t port;
9137         uint16_t port_num;
9138         cmdline_fixed_string_t vf;
9139         uint8_t vf_num;
9140         cmdline_fixed_string_t rate;
9141         uint16_t rate_num;
9142         cmdline_fixed_string_t q_msk;
9143         uint64_t q_msk_val;
9144 };
9145
9146 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9147                 __rte_unused struct cmdline *cl,
9148                 __rte_unused void *data)
9149 {
9150         struct cmd_vf_rate_limit_result *res = parsed_result;
9151         int ret = 0;
9152
9153         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9154                 && (strcmp(res->vf, "vf") == 0)
9155                 && (strcmp(res->rate, "rate") == 0)
9156                 && (strcmp(res->q_msk, "queue_mask") == 0))
9157                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9158                                         res->rate_num, res->q_msk_val);
9159         if (ret < 0)
9160                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9161
9162 }
9163
9164 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9165         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9166                                 set, "set");
9167 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9168         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9169                                 port, "port");
9170 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9171         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9172                                 port_num, UINT16);
9173 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9174         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9175                                 vf, "vf");
9176 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9177         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9178                                 vf_num, UINT8);
9179 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9180         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9181                                 rate, "rate");
9182 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9183         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9184                                 rate_num, UINT16);
9185 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9186         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9187                                 q_msk, "queue_mask");
9188 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9189         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9190                                 q_msk_val, UINT64);
9191
9192 cmdline_parse_inst_t cmd_vf_rate_limit = {
9193         .f = cmd_vf_rate_limit_parsed,
9194         .data = (void *)0,
9195         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9196                 "queue_mask <queue_mask_value>: "
9197                 "Set rate limit for queues of VF on port_id",
9198         .tokens = {
9199                 (void *)&cmd_vf_rate_limit_set,
9200                 (void *)&cmd_vf_rate_limit_port,
9201                 (void *)&cmd_vf_rate_limit_portnum,
9202                 (void *)&cmd_vf_rate_limit_vf,
9203                 (void *)&cmd_vf_rate_limit_vfnum,
9204                 (void *)&cmd_vf_rate_limit_rate,
9205                 (void *)&cmd_vf_rate_limit_ratenum,
9206                 (void *)&cmd_vf_rate_limit_q_msk,
9207                 (void *)&cmd_vf_rate_limit_q_msk_val,
9208                 NULL,
9209         },
9210 };
9211
9212 /* *** ADD TUNNEL FILTER OF A PORT *** */
9213 struct cmd_tunnel_filter_result {
9214         cmdline_fixed_string_t cmd;
9215         cmdline_fixed_string_t what;
9216         portid_t port_id;
9217         struct rte_ether_addr outer_mac;
9218         struct rte_ether_addr inner_mac;
9219         cmdline_ipaddr_t ip_value;
9220         uint16_t inner_vlan;
9221         cmdline_fixed_string_t tunnel_type;
9222         cmdline_fixed_string_t filter_type;
9223         uint32_t tenant_id;
9224         uint16_t queue_num;
9225 };
9226
9227 static void
9228 cmd_tunnel_filter_parsed(void *parsed_result,
9229                           __rte_unused struct cmdline *cl,
9230                           __rte_unused void *data)
9231 {
9232         struct cmd_tunnel_filter_result *res = parsed_result;
9233         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9234         int ret = 0;
9235
9236         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9237
9238         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9239         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9240         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9241
9242         if (res->ip_value.family == AF_INET) {
9243                 tunnel_filter_conf.ip_addr.ipv4_addr =
9244                         res->ip_value.addr.ipv4.s_addr;
9245                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9246         } else {
9247                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9248                         &(res->ip_value.addr.ipv6),
9249                         sizeof(struct in6_addr));
9250                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9251         }
9252
9253         if (!strcmp(res->filter_type, "imac-ivlan"))
9254                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9255         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9256                 tunnel_filter_conf.filter_type =
9257                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9258         else if (!strcmp(res->filter_type, "imac-tenid"))
9259                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9260         else if (!strcmp(res->filter_type, "imac"))
9261                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9262         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9263                 tunnel_filter_conf.filter_type =
9264                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9265         else if (!strcmp(res->filter_type, "oip"))
9266                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9267         else if (!strcmp(res->filter_type, "iip"))
9268                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9269         else {
9270                 printf("The filter type is not supported");
9271                 return;
9272         }
9273
9274         if (!strcmp(res->tunnel_type, "vxlan"))
9275                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9276         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9277                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9278         else if (!strcmp(res->tunnel_type, "nvgre"))
9279                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9280         else if (!strcmp(res->tunnel_type, "ipingre"))
9281                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9282         else {
9283                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9284                 return;
9285         }
9286
9287         tunnel_filter_conf.tenant_id = res->tenant_id;
9288         tunnel_filter_conf.queue_id = res->queue_num;
9289         if (!strcmp(res->what, "add"))
9290                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9291                                         RTE_ETH_FILTER_TUNNEL,
9292                                         RTE_ETH_FILTER_ADD,
9293                                         &tunnel_filter_conf);
9294         else
9295                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9296                                         RTE_ETH_FILTER_TUNNEL,
9297                                         RTE_ETH_FILTER_DELETE,
9298                                         &tunnel_filter_conf);
9299         if (ret < 0)
9300                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9301                                 strerror(-ret));
9302
9303 }
9304 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9305         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9306         cmd, "tunnel_filter");
9307 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9308         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9309         what, "add#rm");
9310 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9311         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9312         port_id, UINT16);
9313 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9314         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9315         outer_mac);
9316 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9317         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9318         inner_mac);
9319 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9320         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9321         inner_vlan, UINT16);
9322 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9323         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9324         ip_value);
9325 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9326         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9327         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9328
9329 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9330         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9331         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9332                 "imac#omac-imac-tenid");
9333 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9334         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9335         tenant_id, UINT32);
9336 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9337         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9338         queue_num, UINT16);
9339
9340 cmdline_parse_inst_t cmd_tunnel_filter = {
9341         .f = cmd_tunnel_filter_parsed,
9342         .data = (void *)0,
9343         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9344                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9345                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9346                 "<queue_id>: Add/Rm tunnel filter of a port",
9347         .tokens = {
9348                 (void *)&cmd_tunnel_filter_cmd,
9349                 (void *)&cmd_tunnel_filter_what,
9350                 (void *)&cmd_tunnel_filter_port_id,
9351                 (void *)&cmd_tunnel_filter_outer_mac,
9352                 (void *)&cmd_tunnel_filter_inner_mac,
9353                 (void *)&cmd_tunnel_filter_ip_value,
9354                 (void *)&cmd_tunnel_filter_innner_vlan,
9355                 (void *)&cmd_tunnel_filter_tunnel_type,
9356                 (void *)&cmd_tunnel_filter_filter_type,
9357                 (void *)&cmd_tunnel_filter_tenant_id,
9358                 (void *)&cmd_tunnel_filter_queue_num,
9359                 NULL,
9360         },
9361 };
9362
9363 /* *** CONFIGURE TUNNEL UDP PORT *** */
9364 struct cmd_tunnel_udp_config {
9365         cmdline_fixed_string_t cmd;
9366         cmdline_fixed_string_t what;
9367         uint16_t udp_port;
9368         portid_t port_id;
9369 };
9370
9371 static void
9372 cmd_tunnel_udp_config_parsed(void *parsed_result,
9373                           __rte_unused struct cmdline *cl,
9374                           __rte_unused void *data)
9375 {
9376         struct cmd_tunnel_udp_config *res = parsed_result;
9377         struct rte_eth_udp_tunnel tunnel_udp;
9378         int ret;
9379
9380         tunnel_udp.udp_port = res->udp_port;
9381
9382         if (!strcmp(res->cmd, "rx_vxlan_port"))
9383                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9384
9385         if (!strcmp(res->what, "add"))
9386                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9387                                                       &tunnel_udp);
9388         else
9389                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9390                                                          &tunnel_udp);
9391
9392         if (ret < 0)
9393                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9394 }
9395
9396 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9397         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9398                                 cmd, "rx_vxlan_port");
9399 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9400         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9401                                 what, "add#rm");
9402 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9403         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9404                                 udp_port, UINT16);
9405 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9406         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9407                                 port_id, UINT16);
9408
9409 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9410         .f = cmd_tunnel_udp_config_parsed,
9411         .data = (void *)0,
9412         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9413                 "Add/Remove a tunneling UDP port filter",
9414         .tokens = {
9415                 (void *)&cmd_tunnel_udp_config_cmd,
9416                 (void *)&cmd_tunnel_udp_config_what,
9417                 (void *)&cmd_tunnel_udp_config_udp_port,
9418                 (void *)&cmd_tunnel_udp_config_port_id,
9419                 NULL,
9420         },
9421 };
9422
9423 struct cmd_config_tunnel_udp_port {
9424         cmdline_fixed_string_t port;
9425         cmdline_fixed_string_t config;
9426         portid_t port_id;
9427         cmdline_fixed_string_t udp_tunnel_port;
9428         cmdline_fixed_string_t action;
9429         cmdline_fixed_string_t tunnel_type;
9430         uint16_t udp_port;
9431 };
9432
9433 static void
9434 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9435                                __rte_unused struct cmdline *cl,
9436                                __rte_unused void *data)
9437 {
9438         struct cmd_config_tunnel_udp_port *res = parsed_result;
9439         struct rte_eth_udp_tunnel tunnel_udp;
9440         int ret = 0;
9441
9442         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9443                 return;
9444
9445         tunnel_udp.udp_port = res->udp_port;
9446
9447         if (!strcmp(res->tunnel_type, "vxlan")) {
9448                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9449         } else if (!strcmp(res->tunnel_type, "geneve")) {
9450                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9451         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9452                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9453         } else {
9454                 printf("Invalid tunnel type\n");
9455                 return;
9456         }
9457
9458         if (!strcmp(res->action, "add"))
9459                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9460                                                       &tunnel_udp);
9461         else
9462                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9463                                                          &tunnel_udp);
9464
9465         if (ret < 0)
9466                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9467 }
9468
9469 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9470         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9471                                  "port");
9472 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9473         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9474                                  "config");
9475 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9476         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9477                               UINT16);
9478 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9479         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9480                                  udp_tunnel_port,
9481                                  "udp_tunnel_port");
9482 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9483         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9484                                  "add#rm");
9485 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9486         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9487                                  "vxlan#geneve#vxlan-gpe");
9488 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9489         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9490                               UINT16);
9491
9492 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9493         .f = cmd_cfg_tunnel_udp_port_parsed,
9494         .data = NULL,
9495         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9496         .tokens = {
9497                 (void *)&cmd_config_tunnel_udp_port_port,
9498                 (void *)&cmd_config_tunnel_udp_port_config,
9499                 (void *)&cmd_config_tunnel_udp_port_port_id,
9500                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9501                 (void *)&cmd_config_tunnel_udp_port_action,
9502                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9503                 (void *)&cmd_config_tunnel_udp_port_value,
9504                 NULL,
9505         },
9506 };
9507
9508 /* *** GLOBAL CONFIG *** */
9509 struct cmd_global_config_result {
9510         cmdline_fixed_string_t cmd;
9511         portid_t port_id;
9512         cmdline_fixed_string_t cfg_type;
9513         uint8_t len;
9514 };
9515
9516 static void
9517 cmd_global_config_parsed(void *parsed_result,
9518                          __rte_unused struct cmdline *cl,
9519                          __rte_unused void *data)
9520 {
9521         struct cmd_global_config_result *res = parsed_result;
9522         struct rte_eth_global_cfg conf;
9523         int ret;
9524
9525         memset(&conf, 0, sizeof(conf));
9526         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9527         conf.cfg.gre_key_len = res->len;
9528         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9529                                       RTE_ETH_FILTER_SET, &conf);
9530 #ifdef RTE_NET_I40E
9531         if (ret == -ENOTSUP)
9532                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9533 #endif
9534         if (ret != 0)
9535                 printf("Global config error\n");
9536 }
9537
9538 cmdline_parse_token_string_t cmd_global_config_cmd =
9539         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9540                 "global_config");
9541 cmdline_parse_token_num_t cmd_global_config_port_id =
9542         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9543                                UINT16);
9544 cmdline_parse_token_string_t cmd_global_config_type =
9545         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9546                 cfg_type, "gre-key-len");
9547 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9548         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9549                 len, UINT8);
9550
9551 cmdline_parse_inst_t cmd_global_config = {
9552         .f = cmd_global_config_parsed,
9553         .data = (void *)NULL,
9554         .help_str = "global_config <port_id> gre-key-len <key_len>",
9555         .tokens = {
9556                 (void *)&cmd_global_config_cmd,
9557                 (void *)&cmd_global_config_port_id,
9558                 (void *)&cmd_global_config_type,
9559                 (void *)&cmd_global_config_gre_key_len,
9560                 NULL,
9561         },
9562 };
9563
9564 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9565 struct cmd_set_mirror_mask_result {
9566         cmdline_fixed_string_t set;
9567         cmdline_fixed_string_t port;
9568         portid_t port_id;
9569         cmdline_fixed_string_t mirror;
9570         uint8_t rule_id;
9571         cmdline_fixed_string_t what;
9572         cmdline_fixed_string_t value;
9573         cmdline_fixed_string_t dstpool;
9574         uint8_t dstpool_id;
9575         cmdline_fixed_string_t on;
9576 };
9577
9578 cmdline_parse_token_string_t cmd_mirror_mask_set =
9579         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9580                                 set, "set");
9581 cmdline_parse_token_string_t cmd_mirror_mask_port =
9582         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9583                                 port, "port");
9584 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9585         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9586                                 port_id, UINT16);
9587 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9588         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9589                                 mirror, "mirror-rule");
9590 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9591         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9592                                 rule_id, UINT8);
9593 cmdline_parse_token_string_t cmd_mirror_mask_what =
9594         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9595                                 what, "pool-mirror-up#pool-mirror-down"
9596                                       "#vlan-mirror");
9597 cmdline_parse_token_string_t cmd_mirror_mask_value =
9598         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9599                                 value, NULL);
9600 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9601         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9602                                 dstpool, "dst-pool");
9603 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9604         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9605                                 dstpool_id, UINT8);
9606 cmdline_parse_token_string_t cmd_mirror_mask_on =
9607         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9608                                 on, "on#off");
9609
9610 static void
9611 cmd_set_mirror_mask_parsed(void *parsed_result,
9612                        __rte_unused struct cmdline *cl,
9613                        __rte_unused void *data)
9614 {
9615         int ret,nb_item,i;
9616         struct cmd_set_mirror_mask_result *res = parsed_result;
9617         struct rte_eth_mirror_conf mr_conf;
9618
9619         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9620
9621         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9622
9623         mr_conf.dst_pool = res->dstpool_id;
9624
9625         if (!strcmp(res->what, "pool-mirror-up")) {
9626                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9627                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9628         } else if (!strcmp(res->what, "pool-mirror-down")) {
9629                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9630                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9631         } else if (!strcmp(res->what, "vlan-mirror")) {
9632                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9633                 nb_item = parse_item_list(res->value, "vlan",
9634                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9635                 if (nb_item <= 0)
9636                         return;
9637
9638                 for (i = 0; i < nb_item; i++) {
9639                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9640                                 printf("Invalid vlan_id: must be < 4096\n");
9641                                 return;
9642                         }
9643
9644                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9645                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9646                 }
9647         }
9648
9649         if (!strcmp(res->on, "on"))
9650                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9651                                                 res->rule_id, 1);
9652         else
9653                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9654                                                 res->rule_id, 0);
9655         if (ret < 0)
9656                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9657 }
9658
9659 cmdline_parse_inst_t cmd_set_mirror_mask = {
9660                 .f = cmd_set_mirror_mask_parsed,
9661                 .data = NULL,
9662                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9663                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9664                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9665                 .tokens = {
9666                         (void *)&cmd_mirror_mask_set,
9667                         (void *)&cmd_mirror_mask_port,
9668                         (void *)&cmd_mirror_mask_portid,
9669                         (void *)&cmd_mirror_mask_mirror,
9670                         (void *)&cmd_mirror_mask_ruleid,
9671                         (void *)&cmd_mirror_mask_what,
9672                         (void *)&cmd_mirror_mask_value,
9673                         (void *)&cmd_mirror_mask_dstpool,
9674                         (void *)&cmd_mirror_mask_poolid,
9675                         (void *)&cmd_mirror_mask_on,
9676                         NULL,
9677                 },
9678 };
9679
9680 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9681 struct cmd_set_mirror_link_result {
9682         cmdline_fixed_string_t set;
9683         cmdline_fixed_string_t port;
9684         portid_t port_id;
9685         cmdline_fixed_string_t mirror;
9686         uint8_t rule_id;
9687         cmdline_fixed_string_t what;
9688         cmdline_fixed_string_t dstpool;
9689         uint8_t dstpool_id;
9690         cmdline_fixed_string_t on;
9691 };
9692
9693 cmdline_parse_token_string_t cmd_mirror_link_set =
9694         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9695                                  set, "set");
9696 cmdline_parse_token_string_t cmd_mirror_link_port =
9697         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9698                                 port, "port");
9699 cmdline_parse_token_num_t cmd_mirror_link_portid =
9700         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9701                                 port_id, UINT16);
9702 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9703         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9704                                 mirror, "mirror-rule");
9705 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9706         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9707                             rule_id, UINT8);
9708 cmdline_parse_token_string_t cmd_mirror_link_what =
9709         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9710                                 what, "uplink-mirror#downlink-mirror");
9711 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9712         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9713                                 dstpool, "dst-pool");
9714 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9715         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9716                                 dstpool_id, UINT8);
9717 cmdline_parse_token_string_t cmd_mirror_link_on =
9718         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9719                                 on, "on#off");
9720
9721 static void
9722 cmd_set_mirror_link_parsed(void *parsed_result,
9723                        __rte_unused struct cmdline *cl,
9724                        __rte_unused void *data)
9725 {
9726         int ret;
9727         struct cmd_set_mirror_link_result *res = parsed_result;
9728         struct rte_eth_mirror_conf mr_conf;
9729
9730         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9731         if (!strcmp(res->what, "uplink-mirror"))
9732                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9733         else
9734                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9735
9736         mr_conf.dst_pool = res->dstpool_id;
9737
9738         if (!strcmp(res->on, "on"))
9739                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9740                                                 res->rule_id, 1);
9741         else
9742                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9743                                                 res->rule_id, 0);
9744
9745         /* check the return value and print it if is < 0 */
9746         if (ret < 0)
9747                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9748
9749 }
9750
9751 cmdline_parse_inst_t cmd_set_mirror_link = {
9752                 .f = cmd_set_mirror_link_parsed,
9753                 .data = NULL,
9754                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9755                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9756                 .tokens = {
9757                         (void *)&cmd_mirror_link_set,
9758                         (void *)&cmd_mirror_link_port,
9759                         (void *)&cmd_mirror_link_portid,
9760                         (void *)&cmd_mirror_link_mirror,
9761                         (void *)&cmd_mirror_link_ruleid,
9762                         (void *)&cmd_mirror_link_what,
9763                         (void *)&cmd_mirror_link_dstpool,
9764                         (void *)&cmd_mirror_link_poolid,
9765                         (void *)&cmd_mirror_link_on,
9766                         NULL,
9767                 },
9768 };
9769
9770 /* *** RESET VM MIRROR RULE *** */
9771 struct cmd_rm_mirror_rule_result {
9772         cmdline_fixed_string_t reset;
9773         cmdline_fixed_string_t port;
9774         portid_t port_id;
9775         cmdline_fixed_string_t mirror;
9776         uint8_t rule_id;
9777 };
9778
9779 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9780         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9781                                  reset, "reset");
9782 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9783         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9784                                 port, "port");
9785 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9786         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9787                                 port_id, UINT16);
9788 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9789         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9790                                 mirror, "mirror-rule");
9791 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9792         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9793                                 rule_id, UINT8);
9794
9795 static void
9796 cmd_reset_mirror_rule_parsed(void *parsed_result,
9797                        __rte_unused struct cmdline *cl,
9798                        __rte_unused void *data)
9799 {
9800         int ret;
9801         struct cmd_set_mirror_link_result *res = parsed_result;
9802         /* check rule_id */
9803         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9804         if(ret < 0)
9805                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9806 }
9807
9808 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9809                 .f = cmd_reset_mirror_rule_parsed,
9810                 .data = NULL,
9811                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9812                 .tokens = {
9813                         (void *)&cmd_rm_mirror_rule_reset,
9814                         (void *)&cmd_rm_mirror_rule_port,
9815                         (void *)&cmd_rm_mirror_rule_portid,
9816                         (void *)&cmd_rm_mirror_rule_mirror,
9817                         (void *)&cmd_rm_mirror_rule_ruleid,
9818                         NULL,
9819                 },
9820 };
9821
9822 /* ******************************************************************************** */
9823
9824 struct cmd_dump_result {
9825         cmdline_fixed_string_t dump;
9826 };
9827
9828 static void
9829 dump_struct_sizes(void)
9830 {
9831 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9832         DUMP_SIZE(struct rte_mbuf);
9833         DUMP_SIZE(struct rte_mempool);
9834         DUMP_SIZE(struct rte_ring);
9835 #undef DUMP_SIZE
9836 }
9837
9838
9839 /* Dump the socket memory statistics on console */
9840 static void
9841 dump_socket_mem(FILE *f)
9842 {
9843         struct rte_malloc_socket_stats socket_stats;
9844         unsigned int i;
9845         size_t total = 0;
9846         size_t alloc = 0;
9847         size_t free = 0;
9848         unsigned int n_alloc = 0;
9849         unsigned int n_free = 0;
9850         static size_t last_allocs;
9851         static size_t last_total;
9852
9853
9854         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9855                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9856                     !socket_stats.heap_totalsz_bytes)
9857                         continue;
9858                 total += socket_stats.heap_totalsz_bytes;
9859                 alloc += socket_stats.heap_allocsz_bytes;
9860                 free += socket_stats.heap_freesz_bytes;
9861                 n_alloc += socket_stats.alloc_count;
9862                 n_free += socket_stats.free_count;
9863                 fprintf(f,
9864                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9865                         i,
9866                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9867                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9868                         (double)socket_stats.heap_allocsz_bytes * 100 /
9869                         (double)socket_stats.heap_totalsz_bytes,
9870                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9871                         socket_stats.alloc_count,
9872                         socket_stats.free_count);
9873         }
9874         fprintf(f,
9875                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9876                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9877                 (double)alloc * 100 / (double)total,
9878                 (double)free / (1024 * 1024),
9879                 n_alloc, n_free);
9880         if (last_allocs)
9881                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9882                         ((double)total - (double)last_total) / (1024 * 1024),
9883                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9884         last_allocs = alloc;
9885         last_total = total;
9886 }
9887
9888 static void cmd_dump_parsed(void *parsed_result,
9889                             __rte_unused struct cmdline *cl,
9890                             __rte_unused void *data)
9891 {
9892         struct cmd_dump_result *res = parsed_result;
9893
9894         if (!strcmp(res->dump, "dump_physmem"))
9895                 rte_dump_physmem_layout(stdout);
9896         else if (!strcmp(res->dump, "dump_socket_mem"))
9897                 dump_socket_mem(stdout);
9898         else if (!strcmp(res->dump, "dump_memzone"))
9899                 rte_memzone_dump(stdout);
9900         else if (!strcmp(res->dump, "dump_struct_sizes"))
9901                 dump_struct_sizes();
9902         else if (!strcmp(res->dump, "dump_ring"))
9903                 rte_ring_list_dump(stdout);
9904         else if (!strcmp(res->dump, "dump_mempool"))
9905                 rte_mempool_list_dump(stdout);
9906         else if (!strcmp(res->dump, "dump_devargs"))
9907                 rte_devargs_dump(stdout);
9908         else if (!strcmp(res->dump, "dump_log_types"))
9909                 rte_log_dump(stdout);
9910 }
9911
9912 cmdline_parse_token_string_t cmd_dump_dump =
9913         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9914                 "dump_physmem#"
9915                 "dump_memzone#"
9916                 "dump_socket_mem#"
9917                 "dump_struct_sizes#"
9918                 "dump_ring#"
9919                 "dump_mempool#"
9920                 "dump_devargs#"
9921                 "dump_log_types");
9922
9923 cmdline_parse_inst_t cmd_dump = {
9924         .f = cmd_dump_parsed,  /* function to call */
9925         .data = NULL,      /* 2nd arg of func */
9926         .help_str = "Dump status",
9927         .tokens = {        /* token list, NULL terminated */
9928                 (void *)&cmd_dump_dump,
9929                 NULL,
9930         },
9931 };
9932
9933 /* ******************************************************************************** */
9934
9935 struct cmd_dump_one_result {
9936         cmdline_fixed_string_t dump;
9937         cmdline_fixed_string_t name;
9938 };
9939
9940 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9941                                 __rte_unused void *data)
9942 {
9943         struct cmd_dump_one_result *res = parsed_result;
9944
9945         if (!strcmp(res->dump, "dump_ring")) {
9946                 struct rte_ring *r;
9947                 r = rte_ring_lookup(res->name);
9948                 if (r == NULL) {
9949                         cmdline_printf(cl, "Cannot find ring\n");
9950                         return;
9951                 }
9952                 rte_ring_dump(stdout, r);
9953         } else if (!strcmp(res->dump, "dump_mempool")) {
9954                 struct rte_mempool *mp;
9955                 mp = rte_mempool_lookup(res->name);
9956                 if (mp == NULL) {
9957                         cmdline_printf(cl, "Cannot find mempool\n");
9958                         return;
9959                 }
9960                 rte_mempool_dump(stdout, mp);
9961         }
9962 }
9963
9964 cmdline_parse_token_string_t cmd_dump_one_dump =
9965         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9966                                  "dump_ring#dump_mempool");
9967
9968 cmdline_parse_token_string_t cmd_dump_one_name =
9969         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9970
9971 cmdline_parse_inst_t cmd_dump_one = {
9972         .f = cmd_dump_one_parsed,  /* function to call */
9973         .data = NULL,      /* 2nd arg of func */
9974         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9975         .tokens = {        /* token list, NULL terminated */
9976                 (void *)&cmd_dump_one_dump,
9977                 (void *)&cmd_dump_one_name,
9978                 NULL,
9979         },
9980 };
9981
9982 /* *** queue region set *** */
9983 struct cmd_queue_region_result {
9984         cmdline_fixed_string_t set;
9985         cmdline_fixed_string_t port;
9986         portid_t port_id;
9987         cmdline_fixed_string_t cmd;
9988         cmdline_fixed_string_t region;
9989         uint8_t  region_id;
9990         cmdline_fixed_string_t queue_start_index;
9991         uint8_t  queue_id;
9992         cmdline_fixed_string_t queue_num;
9993         uint8_t  queue_num_value;
9994 };
9995
9996 static void
9997 cmd_queue_region_parsed(void *parsed_result,
9998                         __rte_unused struct cmdline *cl,
9999                         __rte_unused void *data)
10000 {
10001         struct cmd_queue_region_result *res = parsed_result;
10002         int ret = -ENOTSUP;
10003 #ifdef RTE_NET_I40E
10004         struct rte_pmd_i40e_queue_region_conf region_conf;
10005         enum rte_pmd_i40e_queue_region_op op_type;
10006 #endif
10007
10008         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10009                 return;
10010
10011 #ifdef RTE_NET_I40E
10012         memset(&region_conf, 0, sizeof(region_conf));
10013         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10014         region_conf.region_id = res->region_id;
10015         region_conf.queue_num = res->queue_num_value;
10016         region_conf.queue_start_index = res->queue_id;
10017
10018         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10019                                 op_type, &region_conf);
10020 #endif
10021
10022         switch (ret) {
10023         case 0:
10024                 break;
10025         case -ENOTSUP:
10026                 printf("function not implemented or supported\n");
10027                 break;
10028         default:
10029                 printf("queue region config error: (%s)\n", strerror(-ret));
10030         }
10031 }
10032
10033 cmdline_parse_token_string_t cmd_queue_region_set =
10034 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10035                 set, "set");
10036 cmdline_parse_token_string_t cmd_queue_region_port =
10037         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10038 cmdline_parse_token_num_t cmd_queue_region_port_id =
10039         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10040                                 port_id, UINT16);
10041 cmdline_parse_token_string_t cmd_queue_region_cmd =
10042         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10043                                  cmd, "queue-region");
10044 cmdline_parse_token_string_t cmd_queue_region_id =
10045         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10046                                 region, "region_id");
10047 cmdline_parse_token_num_t cmd_queue_region_index =
10048         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10049                                 region_id, UINT8);
10050 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10051         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10052                                 queue_start_index, "queue_start_index");
10053 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10054         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10055                                 queue_id, UINT8);
10056 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10057         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10058                                 queue_num, "queue_num");
10059 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10060         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10061                                 queue_num_value, UINT8);
10062
10063 cmdline_parse_inst_t cmd_queue_region = {
10064         .f = cmd_queue_region_parsed,
10065         .data = NULL,
10066         .help_str = "set port <port_id> queue-region region_id <value> "
10067                 "queue_start_index <value> queue_num <value>: Set a queue region",
10068         .tokens = {
10069                 (void *)&cmd_queue_region_set,
10070                 (void *)&cmd_queue_region_port,
10071                 (void *)&cmd_queue_region_port_id,
10072                 (void *)&cmd_queue_region_cmd,
10073                 (void *)&cmd_queue_region_id,
10074                 (void *)&cmd_queue_region_index,
10075                 (void *)&cmd_queue_region_queue_start_index,
10076                 (void *)&cmd_queue_region_queue_id,
10077                 (void *)&cmd_queue_region_queue_num,
10078                 (void *)&cmd_queue_region_queue_num_value,
10079                 NULL,
10080         },
10081 };
10082
10083 /* *** queue region and flowtype set *** */
10084 struct cmd_region_flowtype_result {
10085         cmdline_fixed_string_t set;
10086         cmdline_fixed_string_t port;
10087         portid_t port_id;
10088         cmdline_fixed_string_t cmd;
10089         cmdline_fixed_string_t region;
10090         uint8_t  region_id;
10091         cmdline_fixed_string_t flowtype;
10092         uint8_t  flowtype_id;
10093 };
10094
10095 static void
10096 cmd_region_flowtype_parsed(void *parsed_result,
10097                         __rte_unused struct cmdline *cl,
10098                         __rte_unused void *data)
10099 {
10100         struct cmd_region_flowtype_result *res = parsed_result;
10101         int ret = -ENOTSUP;
10102 #ifdef RTE_NET_I40E
10103         struct rte_pmd_i40e_queue_region_conf region_conf;
10104         enum rte_pmd_i40e_queue_region_op op_type;
10105 #endif
10106
10107         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10108                 return;
10109
10110 #ifdef RTE_NET_I40E
10111         memset(&region_conf, 0, sizeof(region_conf));
10112
10113         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10114         region_conf.region_id = res->region_id;
10115         region_conf.hw_flowtype = res->flowtype_id;
10116
10117         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10118                         op_type, &region_conf);
10119 #endif
10120
10121         switch (ret) {
10122         case 0:
10123                 break;
10124         case -ENOTSUP:
10125                 printf("function not implemented or supported\n");
10126                 break;
10127         default:
10128                 printf("region flowtype config error: (%s)\n", strerror(-ret));
10129         }
10130 }
10131
10132 cmdline_parse_token_string_t cmd_region_flowtype_set =
10133 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10134                                 set, "set");
10135 cmdline_parse_token_string_t cmd_region_flowtype_port =
10136         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10137                                 port, "port");
10138 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10139         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10140                                 port_id, UINT16);
10141 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10142         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10143                                 cmd, "queue-region");
10144 cmdline_parse_token_string_t cmd_region_flowtype_index =
10145         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10146                                 region, "region_id");
10147 cmdline_parse_token_num_t cmd_region_flowtype_id =
10148         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10149                                 region_id, UINT8);
10150 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10151         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10152                                 flowtype, "flowtype");
10153 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10154         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10155                                 flowtype_id, UINT8);
10156 cmdline_parse_inst_t cmd_region_flowtype = {
10157         .f = cmd_region_flowtype_parsed,
10158         .data = NULL,
10159         .help_str = "set port <port_id> queue-region region_id <value> "
10160                 "flowtype <value>: Set a flowtype region index",
10161         .tokens = {
10162                 (void *)&cmd_region_flowtype_set,
10163                 (void *)&cmd_region_flowtype_port,
10164                 (void *)&cmd_region_flowtype_port_index,
10165                 (void *)&cmd_region_flowtype_cmd,
10166                 (void *)&cmd_region_flowtype_index,
10167                 (void *)&cmd_region_flowtype_id,
10168                 (void *)&cmd_region_flowtype_flow_index,
10169                 (void *)&cmd_region_flowtype_flow_id,
10170                 NULL,
10171         },
10172 };
10173
10174 /* *** User Priority (UP) to queue region (region_id) set *** */
10175 struct cmd_user_priority_region_result {
10176         cmdline_fixed_string_t set;
10177         cmdline_fixed_string_t port;
10178         portid_t port_id;
10179         cmdline_fixed_string_t cmd;
10180         cmdline_fixed_string_t user_priority;
10181         uint8_t  user_priority_id;
10182         cmdline_fixed_string_t region;
10183         uint8_t  region_id;
10184 };
10185
10186 static void
10187 cmd_user_priority_region_parsed(void *parsed_result,
10188                         __rte_unused struct cmdline *cl,
10189                         __rte_unused void *data)
10190 {
10191         struct cmd_user_priority_region_result *res = parsed_result;
10192         int ret = -ENOTSUP;
10193 #ifdef RTE_NET_I40E
10194         struct rte_pmd_i40e_queue_region_conf region_conf;
10195         enum rte_pmd_i40e_queue_region_op op_type;
10196 #endif
10197
10198         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10199                 return;
10200
10201 #ifdef RTE_NET_I40E
10202         memset(&region_conf, 0, sizeof(region_conf));
10203         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10204         region_conf.user_priority = res->user_priority_id;
10205         region_conf.region_id = res->region_id;
10206
10207         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10208                                 op_type, &region_conf);
10209 #endif
10210
10211         switch (ret) {
10212         case 0:
10213                 break;
10214         case -ENOTSUP:
10215                 printf("function not implemented or supported\n");
10216                 break;
10217         default:
10218                 printf("user_priority region config error: (%s)\n",
10219                                 strerror(-ret));
10220         }
10221 }
10222
10223 cmdline_parse_token_string_t cmd_user_priority_region_set =
10224         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10225                                 set, "set");
10226 cmdline_parse_token_string_t cmd_user_priority_region_port =
10227         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10228                                 port, "port");
10229 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10230         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10231                                 port_id, UINT16);
10232 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10233         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10234                                 cmd, "queue-region");
10235 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10236         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10237                                 user_priority, "UP");
10238 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10239         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10240                                 user_priority_id, UINT8);
10241 cmdline_parse_token_string_t cmd_user_priority_region_region =
10242         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10243                                 region, "region_id");
10244 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10245         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10246                                 region_id, UINT8);
10247
10248 cmdline_parse_inst_t cmd_user_priority_region = {
10249         .f = cmd_user_priority_region_parsed,
10250         .data = NULL,
10251         .help_str = "set port <port_id> queue-region UP <value> "
10252                 "region_id <value>: Set the mapping of User Priority (UP) "
10253                 "to queue region (region_id) ",
10254         .tokens = {
10255                 (void *)&cmd_user_priority_region_set,
10256                 (void *)&cmd_user_priority_region_port,
10257                 (void *)&cmd_user_priority_region_port_index,
10258                 (void *)&cmd_user_priority_region_cmd,
10259                 (void *)&cmd_user_priority_region_UP,
10260                 (void *)&cmd_user_priority_region_UP_id,
10261                 (void *)&cmd_user_priority_region_region,
10262                 (void *)&cmd_user_priority_region_region_id,
10263                 NULL,
10264         },
10265 };
10266
10267 /* *** flush all queue region related configuration *** */
10268 struct cmd_flush_queue_region_result {
10269         cmdline_fixed_string_t set;
10270         cmdline_fixed_string_t port;
10271         portid_t port_id;
10272         cmdline_fixed_string_t cmd;
10273         cmdline_fixed_string_t flush;
10274         cmdline_fixed_string_t what;
10275 };
10276
10277 static void
10278 cmd_flush_queue_region_parsed(void *parsed_result,
10279                         __rte_unused struct cmdline *cl,
10280                         __rte_unused void *data)
10281 {
10282         struct cmd_flush_queue_region_result *res = parsed_result;
10283         int ret = -ENOTSUP;
10284 #ifdef RTE_NET_I40E
10285         struct rte_pmd_i40e_queue_region_conf region_conf;
10286         enum rte_pmd_i40e_queue_region_op op_type;
10287 #endif
10288
10289         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10290                 return;
10291
10292 #ifdef RTE_NET_I40E
10293         memset(&region_conf, 0, sizeof(region_conf));
10294
10295         if (strcmp(res->what, "on") == 0)
10296                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10297         else
10298                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10299
10300         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10301                                 op_type, &region_conf);
10302 #endif
10303
10304         switch (ret) {
10305         case 0:
10306                 break;
10307         case -ENOTSUP:
10308                 printf("function not implemented or supported\n");
10309                 break;
10310         default:
10311                 printf("queue region config flush error: (%s)\n",
10312                                 strerror(-ret));
10313         }
10314 }
10315
10316 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10317         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10318                                 set, "set");
10319 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10320         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10321                                 port, "port");
10322 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10323         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10324                                 port_id, UINT16);
10325 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10326         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10327                                 cmd, "queue-region");
10328 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10329         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10330                                 flush, "flush");
10331 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10332         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10333                                 what, "on#off");
10334
10335 cmdline_parse_inst_t cmd_flush_queue_region = {
10336         .f = cmd_flush_queue_region_parsed,
10337         .data = NULL,
10338         .help_str = "set port <port_id> queue-region flush on|off"
10339                 ": flush all queue region related configuration",
10340         .tokens = {
10341                 (void *)&cmd_flush_queue_region_set,
10342                 (void *)&cmd_flush_queue_region_port,
10343                 (void *)&cmd_flush_queue_region_port_index,
10344                 (void *)&cmd_flush_queue_region_cmd,
10345                 (void *)&cmd_flush_queue_region_flush,
10346                 (void *)&cmd_flush_queue_region_what,
10347                 NULL,
10348         },
10349 };
10350
10351 /* *** get all queue region related configuration info *** */
10352 struct cmd_show_queue_region_info {
10353         cmdline_fixed_string_t show;
10354         cmdline_fixed_string_t port;
10355         portid_t port_id;
10356         cmdline_fixed_string_t cmd;
10357 };
10358
10359 static void
10360 cmd_show_queue_region_info_parsed(void *parsed_result,
10361                         __rte_unused struct cmdline *cl,
10362                         __rte_unused void *data)
10363 {
10364         struct cmd_show_queue_region_info *res = parsed_result;
10365         int ret = -ENOTSUP;
10366 #ifdef RTE_NET_I40E
10367         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10368         enum rte_pmd_i40e_queue_region_op op_type;
10369 #endif
10370
10371         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10372                 return;
10373
10374 #ifdef RTE_NET_I40E
10375         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10376
10377         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10378
10379         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10380                                         op_type, &rte_pmd_regions);
10381
10382         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10383 #endif
10384
10385         switch (ret) {
10386         case 0:
10387                 break;
10388         case -ENOTSUP:
10389                 printf("function not implemented or supported\n");
10390                 break;
10391         default:
10392                 printf("queue region config info show error: (%s)\n",
10393                                 strerror(-ret));
10394         }
10395 }
10396
10397 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10398 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10399                                 show, "show");
10400 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10401         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10402                                 port, "port");
10403 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10404         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10405                                 port_id, UINT16);
10406 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10407         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10408                                 cmd, "queue-region");
10409
10410 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10411         .f = cmd_show_queue_region_info_parsed,
10412         .data = NULL,
10413         .help_str = "show port <port_id> queue-region"
10414                 ": show all queue region related configuration info",
10415         .tokens = {
10416                 (void *)&cmd_show_queue_region_info_get,
10417                 (void *)&cmd_show_queue_region_info_port,
10418                 (void *)&cmd_show_queue_region_info_port_index,
10419                 (void *)&cmd_show_queue_region_info_cmd,
10420                 NULL,
10421         },
10422 };
10423
10424 /* *** ADD/REMOVE A 2tuple FILTER *** */
10425 struct cmd_2tuple_filter_result {
10426         cmdline_fixed_string_t filter;
10427         portid_t port_id;
10428         cmdline_fixed_string_t ops;
10429         cmdline_fixed_string_t dst_port;
10430         uint16_t dst_port_value;
10431         cmdline_fixed_string_t protocol;
10432         uint8_t protocol_value;
10433         cmdline_fixed_string_t mask;
10434         uint8_t  mask_value;
10435         cmdline_fixed_string_t tcp_flags;
10436         uint8_t tcp_flags_value;
10437         cmdline_fixed_string_t priority;
10438         uint8_t  priority_value;
10439         cmdline_fixed_string_t queue;
10440         uint16_t  queue_id;
10441 };
10442
10443 static void
10444 cmd_2tuple_filter_parsed(void *parsed_result,
10445                         __rte_unused struct cmdline *cl,
10446                         __rte_unused void *data)
10447 {
10448         struct rte_eth_ntuple_filter filter;
10449         struct cmd_2tuple_filter_result *res = parsed_result;
10450         int ret = 0;
10451
10452         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10453         if (ret < 0) {
10454                 printf("ntuple filter is not supported on port %u.\n",
10455                         res->port_id);
10456                 return;
10457         }
10458
10459         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10460
10461         filter.flags = RTE_2TUPLE_FLAGS;
10462         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10463         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10464         filter.proto = res->protocol_value;
10465         filter.priority = res->priority_value;
10466         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10467                 printf("nonzero tcp_flags is only meaningful"
10468                         " when protocol is TCP.\n");
10469                 return;
10470         }
10471         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10472                 printf("invalid TCP flags.\n");
10473                 return;
10474         }
10475
10476         if (res->tcp_flags_value != 0) {
10477                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10478                 filter.tcp_flags = res->tcp_flags_value;
10479         }
10480
10481         /* need convert to big endian. */
10482         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10483         filter.queue = res->queue_id;
10484
10485         if (!strcmp(res->ops, "add"))
10486                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10487                                 RTE_ETH_FILTER_NTUPLE,
10488                                 RTE_ETH_FILTER_ADD,
10489                                 &filter);
10490         else
10491                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10492                                 RTE_ETH_FILTER_NTUPLE,
10493                                 RTE_ETH_FILTER_DELETE,
10494                                 &filter);
10495         if (ret < 0)
10496                 printf("2tuple filter programming error: (%s)\n",
10497                         strerror(-ret));
10498
10499 }
10500
10501 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10502         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10503                                  filter, "2tuple_filter");
10504 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10505         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10506                                 port_id, UINT16);
10507 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10508         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10509                                  ops, "add#del");
10510 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10511         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10512                                 dst_port, "dst_port");
10513 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10514         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10515                                 dst_port_value, UINT16);
10516 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10517         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10518                                 protocol, "protocol");
10519 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10520         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10521                                 protocol_value, UINT8);
10522 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10523         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10524                                 mask, "mask");
10525 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10526         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10527                                 mask_value, INT8);
10528 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10529         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10530                                 tcp_flags, "tcp_flags");
10531 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10532         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10533                                 tcp_flags_value, UINT8);
10534 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10535         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10536                                 priority, "priority");
10537 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10538         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10539                                 priority_value, UINT8);
10540 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10541         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10542                                 queue, "queue");
10543 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10544         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10545                                 queue_id, UINT16);
10546
10547 cmdline_parse_inst_t cmd_2tuple_filter = {
10548         .f = cmd_2tuple_filter_parsed,
10549         .data = NULL,
10550         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10551                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10552                 "<queue_id>: Add a 2tuple filter",
10553         .tokens = {
10554                 (void *)&cmd_2tuple_filter_filter,
10555                 (void *)&cmd_2tuple_filter_port_id,
10556                 (void *)&cmd_2tuple_filter_ops,
10557                 (void *)&cmd_2tuple_filter_dst_port,
10558                 (void *)&cmd_2tuple_filter_dst_port_value,
10559                 (void *)&cmd_2tuple_filter_protocol,
10560                 (void *)&cmd_2tuple_filter_protocol_value,
10561                 (void *)&cmd_2tuple_filter_mask,
10562                 (void *)&cmd_2tuple_filter_mask_value,
10563                 (void *)&cmd_2tuple_filter_tcp_flags,
10564                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10565                 (void *)&cmd_2tuple_filter_priority,
10566                 (void *)&cmd_2tuple_filter_priority_value,
10567                 (void *)&cmd_2tuple_filter_queue,
10568                 (void *)&cmd_2tuple_filter_queue_id,
10569                 NULL,
10570         },
10571 };
10572
10573 /* *** ADD/REMOVE A 5tuple FILTER *** */
10574 struct cmd_5tuple_filter_result {
10575         cmdline_fixed_string_t filter;
10576         portid_t port_id;
10577         cmdline_fixed_string_t ops;
10578         cmdline_fixed_string_t dst_ip;
10579         cmdline_ipaddr_t dst_ip_value;
10580         cmdline_fixed_string_t src_ip;
10581         cmdline_ipaddr_t src_ip_value;
10582         cmdline_fixed_string_t dst_port;
10583         uint16_t dst_port_value;
10584         cmdline_fixed_string_t src_port;
10585         uint16_t src_port_value;
10586         cmdline_fixed_string_t protocol;
10587         uint8_t protocol_value;
10588         cmdline_fixed_string_t mask;
10589         uint8_t  mask_value;
10590         cmdline_fixed_string_t tcp_flags;
10591         uint8_t tcp_flags_value;
10592         cmdline_fixed_string_t priority;
10593         uint8_t  priority_value;
10594         cmdline_fixed_string_t queue;
10595         uint16_t  queue_id;
10596 };
10597
10598 static void
10599 cmd_5tuple_filter_parsed(void *parsed_result,
10600                         __rte_unused struct cmdline *cl,
10601                         __rte_unused void *data)
10602 {
10603         struct rte_eth_ntuple_filter filter;
10604         struct cmd_5tuple_filter_result *res = parsed_result;
10605         int ret = 0;
10606
10607         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10608         if (ret < 0) {
10609                 printf("ntuple filter is not supported on port %u.\n",
10610                         res->port_id);
10611                 return;
10612         }
10613
10614         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10615
10616         filter.flags = RTE_5TUPLE_FLAGS;
10617         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10618         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10619         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10620         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10621         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10622         filter.proto = res->protocol_value;
10623         filter.priority = res->priority_value;
10624         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10625                 printf("nonzero tcp_flags is only meaningful"
10626                         " when protocol is TCP.\n");
10627                 return;
10628         }
10629         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10630                 printf("invalid TCP flags.\n");
10631                 return;
10632         }
10633
10634         if (res->tcp_flags_value != 0) {
10635                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10636                 filter.tcp_flags = res->tcp_flags_value;
10637         }
10638
10639         if (res->dst_ip_value.family == AF_INET)
10640                 /* no need to convert, already big endian. */
10641                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10642         else {
10643                 if (filter.dst_ip_mask == 0) {
10644                         printf("can not support ipv6 involved compare.\n");
10645                         return;
10646                 }
10647                 filter.dst_ip = 0;
10648         }
10649
10650         if (res->src_ip_value.family == AF_INET)
10651                 /* no need to convert, already big endian. */
10652                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10653         else {
10654                 if (filter.src_ip_mask == 0) {
10655                         printf("can not support ipv6 involved compare.\n");
10656                         return;
10657                 }
10658                 filter.src_ip = 0;
10659         }
10660         /* need convert to big endian. */
10661         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10662         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10663         filter.queue = res->queue_id;
10664
10665         if (!strcmp(res->ops, "add"))
10666                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10667                                 RTE_ETH_FILTER_NTUPLE,
10668                                 RTE_ETH_FILTER_ADD,
10669                                 &filter);
10670         else
10671                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10672                                 RTE_ETH_FILTER_NTUPLE,
10673                                 RTE_ETH_FILTER_DELETE,
10674                                 &filter);
10675         if (ret < 0)
10676                 printf("5tuple filter programming error: (%s)\n",
10677                         strerror(-ret));
10678 }
10679
10680 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10681         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10682                                  filter, "5tuple_filter");
10683 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10684         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10685                                 port_id, UINT16);
10686 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10687         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10688                                  ops, "add#del");
10689 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10690         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10691                                 dst_ip, "dst_ip");
10692 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10693         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10694                                 dst_ip_value);
10695 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10696         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10697                                 src_ip, "src_ip");
10698 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10699         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10700                                 src_ip_value);
10701 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10702         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10703                                 dst_port, "dst_port");
10704 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10705         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10706                                 dst_port_value, UINT16);
10707 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10708         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10709                                 src_port, "src_port");
10710 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10711         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10712                                 src_port_value, UINT16);
10713 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10714         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10715                                 protocol, "protocol");
10716 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10717         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10718                                 protocol_value, UINT8);
10719 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10720         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10721                                 mask, "mask");
10722 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10723         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10724                                 mask_value, INT8);
10725 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10726         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10727                                 tcp_flags, "tcp_flags");
10728 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10729         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10730                                 tcp_flags_value, UINT8);
10731 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10732         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10733                                 priority, "priority");
10734 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10735         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10736                                 priority_value, UINT8);
10737 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10738         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10739                                 queue, "queue");
10740 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10741         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10742                                 queue_id, UINT16);
10743
10744 cmdline_parse_inst_t cmd_5tuple_filter = {
10745         .f = cmd_5tuple_filter_parsed,
10746         .data = NULL,
10747         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10748                 "src_ip <value> dst_port <value> src_port <value> "
10749                 "protocol <value>  mask <value> tcp_flags <value> "
10750                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10751         .tokens = {
10752                 (void *)&cmd_5tuple_filter_filter,
10753                 (void *)&cmd_5tuple_filter_port_id,
10754                 (void *)&cmd_5tuple_filter_ops,
10755                 (void *)&cmd_5tuple_filter_dst_ip,
10756                 (void *)&cmd_5tuple_filter_dst_ip_value,
10757                 (void *)&cmd_5tuple_filter_src_ip,
10758                 (void *)&cmd_5tuple_filter_src_ip_value,
10759                 (void *)&cmd_5tuple_filter_dst_port,
10760                 (void *)&cmd_5tuple_filter_dst_port_value,
10761                 (void *)&cmd_5tuple_filter_src_port,
10762                 (void *)&cmd_5tuple_filter_src_port_value,
10763                 (void *)&cmd_5tuple_filter_protocol,
10764                 (void *)&cmd_5tuple_filter_protocol_value,
10765                 (void *)&cmd_5tuple_filter_mask,
10766                 (void *)&cmd_5tuple_filter_mask_value,
10767                 (void *)&cmd_5tuple_filter_tcp_flags,
10768                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10769                 (void *)&cmd_5tuple_filter_priority,
10770                 (void *)&cmd_5tuple_filter_priority_value,
10771                 (void *)&cmd_5tuple_filter_queue,
10772                 (void *)&cmd_5tuple_filter_queue_id,
10773                 NULL,
10774         },
10775 };
10776
10777 /* *** Filters Control *** */
10778
10779 /* *** deal with flow director filter *** */
10780 struct cmd_flow_director_result {
10781         cmdline_fixed_string_t flow_director_filter;
10782         portid_t port_id;
10783         cmdline_fixed_string_t mode;
10784         cmdline_fixed_string_t mode_value;
10785         cmdline_fixed_string_t ops;
10786         cmdline_fixed_string_t flow;
10787         cmdline_fixed_string_t flow_type;
10788         cmdline_fixed_string_t ether;
10789         uint16_t ether_type;
10790         cmdline_fixed_string_t src;
10791         cmdline_ipaddr_t ip_src;
10792         uint16_t port_src;
10793         cmdline_fixed_string_t dst;
10794         cmdline_ipaddr_t ip_dst;
10795         uint16_t port_dst;
10796         cmdline_fixed_string_t verify_tag;
10797         uint32_t verify_tag_value;
10798         cmdline_fixed_string_t tos;
10799         uint8_t tos_value;
10800         cmdline_fixed_string_t proto;
10801         uint8_t proto_value;
10802         cmdline_fixed_string_t ttl;
10803         uint8_t ttl_value;
10804         cmdline_fixed_string_t vlan;
10805         uint16_t vlan_value;
10806         cmdline_fixed_string_t flexbytes;
10807         cmdline_fixed_string_t flexbytes_value;
10808         cmdline_fixed_string_t pf_vf;
10809         cmdline_fixed_string_t drop;
10810         cmdline_fixed_string_t queue;
10811         uint16_t  queue_id;
10812         cmdline_fixed_string_t fd_id;
10813         uint32_t  fd_id_value;
10814         cmdline_fixed_string_t mac;
10815         struct rte_ether_addr mac_addr;
10816         cmdline_fixed_string_t tunnel;
10817         cmdline_fixed_string_t tunnel_type;
10818         cmdline_fixed_string_t tunnel_id;
10819         uint32_t tunnel_id_value;
10820         cmdline_fixed_string_t packet;
10821         char filepath[];
10822 };
10823
10824 static inline int
10825 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10826 {
10827         char s[256];
10828         const char *p, *p0 = q_arg;
10829         char *end;
10830         unsigned long int_fld;
10831         char *str_fld[max_num];
10832         int i;
10833         unsigned size;
10834         int ret = -1;
10835
10836         p = strchr(p0, '(');
10837         if (p == NULL)
10838                 return -1;
10839         ++p;
10840         p0 = strchr(p, ')');
10841         if (p0 == NULL)
10842                 return -1;
10843
10844         size = p0 - p;
10845         if (size >= sizeof(s))
10846                 return -1;
10847
10848         snprintf(s, sizeof(s), "%.*s", size, p);
10849         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10850         if (ret < 0 || ret > max_num)
10851                 return -1;
10852         for (i = 0; i < ret; i++) {
10853                 errno = 0;
10854                 int_fld = strtoul(str_fld[i], &end, 0);
10855                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10856                         return -1;
10857                 flexbytes[i] = (uint8_t)int_fld;
10858         }
10859         return ret;
10860 }
10861
10862 static uint16_t
10863 str2flowtype(char *string)
10864 {
10865         uint8_t i = 0;
10866         static const struct {
10867                 char str[32];
10868                 uint16_t type;
10869         } flowtype_str[] = {
10870                 {"raw", RTE_ETH_FLOW_RAW},
10871                 {"ipv4", RTE_ETH_FLOW_IPV4},
10872                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10873                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10874                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10875                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10876                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10877                 {"ipv6", RTE_ETH_FLOW_IPV6},
10878                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10879                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10880                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10881                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10882                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10883                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10884         };
10885
10886         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10887                 if (!strcmp(flowtype_str[i].str, string))
10888                         return flowtype_str[i].type;
10889         }
10890
10891         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10892                 return (uint16_t)atoi(string);
10893
10894         return RTE_ETH_FLOW_UNKNOWN;
10895 }
10896
10897 static enum rte_eth_fdir_tunnel_type
10898 str2fdir_tunneltype(char *string)
10899 {
10900         uint8_t i = 0;
10901
10902         static const struct {
10903                 char str[32];
10904                 enum rte_eth_fdir_tunnel_type type;
10905         } tunneltype_str[] = {
10906                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10907                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10908         };
10909
10910         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10911                 if (!strcmp(tunneltype_str[i].str, string))
10912                         return tunneltype_str[i].type;
10913         }
10914         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10915 }
10916
10917 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10918 do { \
10919         if ((ip_addr).family == AF_INET) \
10920                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10921         else { \
10922                 printf("invalid parameter.\n"); \
10923                 return; \
10924         } \
10925 } while (0)
10926
10927 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10928 do { \
10929         if ((ip_addr).family == AF_INET6) \
10930                 rte_memcpy(&(ip), \
10931                                  &((ip_addr).addr.ipv6), \
10932                                  sizeof(struct in6_addr)); \
10933         else { \
10934                 printf("invalid parameter.\n"); \
10935                 return; \
10936         } \
10937 } while (0)
10938
10939 static void
10940 cmd_flow_director_filter_parsed(void *parsed_result,
10941                           __rte_unused struct cmdline *cl,
10942                           __rte_unused void *data)
10943 {
10944         struct cmd_flow_director_result *res = parsed_result;
10945         struct rte_eth_fdir_filter entry;
10946         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10947         char *end;
10948         unsigned long vf_id;
10949         int ret = 0;
10950
10951         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10952         if (ret < 0) {
10953                 printf("flow director is not supported on port %u.\n",
10954                         res->port_id);
10955                 return;
10956         }
10957         memset(flexbytes, 0, sizeof(flexbytes));
10958         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10959
10960         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10961                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10962                         printf("Please set mode to MAC-VLAN.\n");
10963                         return;
10964                 }
10965         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10966                 if (strcmp(res->mode_value, "Tunnel")) {
10967                         printf("Please set mode to Tunnel.\n");
10968                         return;
10969                 }
10970         } else {
10971                 if (!strcmp(res->mode_value, "raw")) {
10972 #ifdef RTE_NET_I40E
10973                         struct rte_pmd_i40e_flow_type_mapping
10974                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10975                         struct rte_pmd_i40e_pkt_template_conf conf;
10976                         uint16_t flow_type = str2flowtype(res->flow_type);
10977                         uint16_t i, port = res->port_id;
10978                         uint8_t add;
10979
10980                         memset(&conf, 0, sizeof(conf));
10981
10982                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10983                                 printf("Invalid flow type specified.\n");
10984                                 return;
10985                         }
10986                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10987                                                                  mapping);
10988                         if (ret)
10989                                 return;
10990                         if (mapping[flow_type].pctype == 0ULL) {
10991                                 printf("Invalid flow type specified.\n");
10992                                 return;
10993                         }
10994                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10995                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10996                                         conf.input.pctype = i;
10997                                         break;
10998                                 }
10999                         }
11000
11001                         conf.input.packet = open_file(res->filepath,
11002                                                 &conf.input.length);
11003                         if (!conf.input.packet)
11004                                 return;
11005                         if (!strcmp(res->drop, "drop"))
11006                                 conf.action.behavior =
11007                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11008                         else
11009                                 conf.action.behavior =
11010                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11011                         conf.action.report_status =
11012                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11013                         conf.action.rx_queue = res->queue_id;
11014                         conf.soft_id = res->fd_id_value;
11015                         add  = strcmp(res->ops, "del") ? 1 : 0;
11016                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11017                                                                         &conf,
11018                                                                         add);
11019                         if (ret < 0)
11020                                 printf("flow director config error: (%s)\n",
11021                                        strerror(-ret));
11022                         close_file(conf.input.packet);
11023 #endif
11024                         return;
11025                 } else if (strcmp(res->mode_value, "IP")) {
11026                         printf("Please set mode to IP or raw.\n");
11027                         return;
11028                 }
11029                 entry.input.flow_type = str2flowtype(res->flow_type);
11030         }
11031
11032         ret = parse_flexbytes(res->flexbytes_value,
11033                                         flexbytes,
11034                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11035         if (ret < 0) {
11036                 printf("error: Cannot parse flexbytes input.\n");
11037                 return;
11038         }
11039
11040         switch (entry.input.flow_type) {
11041         case RTE_ETH_FLOW_FRAG_IPV4:
11042         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11043                 entry.input.flow.ip4_flow.proto = res->proto_value;
11044                 /* fall-through */
11045         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11046         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11047                 IPV4_ADDR_TO_UINT(res->ip_dst,
11048                         entry.input.flow.ip4_flow.dst_ip);
11049                 IPV4_ADDR_TO_UINT(res->ip_src,
11050                         entry.input.flow.ip4_flow.src_ip);
11051                 entry.input.flow.ip4_flow.tos = res->tos_value;
11052                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11053                 /* need convert to big endian. */
11054                 entry.input.flow.udp4_flow.dst_port =
11055                                 rte_cpu_to_be_16(res->port_dst);
11056                 entry.input.flow.udp4_flow.src_port =
11057                                 rte_cpu_to_be_16(res->port_src);
11058                 break;
11059         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11060                 IPV4_ADDR_TO_UINT(res->ip_dst,
11061                         entry.input.flow.sctp4_flow.ip.dst_ip);
11062                 IPV4_ADDR_TO_UINT(res->ip_src,
11063                         entry.input.flow.sctp4_flow.ip.src_ip);
11064                 entry.input.flow.ip4_flow.tos = res->tos_value;
11065                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11066                 /* need convert to big endian. */
11067                 entry.input.flow.sctp4_flow.dst_port =
11068                                 rte_cpu_to_be_16(res->port_dst);
11069                 entry.input.flow.sctp4_flow.src_port =
11070                                 rte_cpu_to_be_16(res->port_src);
11071                 entry.input.flow.sctp4_flow.verify_tag =
11072                                 rte_cpu_to_be_32(res->verify_tag_value);
11073                 break;
11074         case RTE_ETH_FLOW_FRAG_IPV6:
11075         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11076                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11077                 /* fall-through */
11078         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11079         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11080                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11081                         entry.input.flow.ipv6_flow.dst_ip);
11082                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11083                         entry.input.flow.ipv6_flow.src_ip);
11084                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11085                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11086                 /* need convert to big endian. */
11087                 entry.input.flow.udp6_flow.dst_port =
11088                                 rte_cpu_to_be_16(res->port_dst);
11089                 entry.input.flow.udp6_flow.src_port =
11090                                 rte_cpu_to_be_16(res->port_src);
11091                 break;
11092         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11093                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11094                         entry.input.flow.sctp6_flow.ip.dst_ip);
11095                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11096                         entry.input.flow.sctp6_flow.ip.src_ip);
11097                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11098                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11099                 /* need convert to big endian. */
11100                 entry.input.flow.sctp6_flow.dst_port =
11101                                 rte_cpu_to_be_16(res->port_dst);
11102                 entry.input.flow.sctp6_flow.src_port =
11103                                 rte_cpu_to_be_16(res->port_src);
11104                 entry.input.flow.sctp6_flow.verify_tag =
11105                                 rte_cpu_to_be_32(res->verify_tag_value);
11106                 break;
11107         case RTE_ETH_FLOW_L2_PAYLOAD:
11108                 entry.input.flow.l2_flow.ether_type =
11109                         rte_cpu_to_be_16(res->ether_type);
11110                 break;
11111         default:
11112                 break;
11113         }
11114
11115         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11116                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11117                                  &res->mac_addr,
11118                                  sizeof(struct rte_ether_addr));
11119
11120         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11121                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11122                                  &res->mac_addr,
11123                                  sizeof(struct rte_ether_addr));
11124                 entry.input.flow.tunnel_flow.tunnel_type =
11125                         str2fdir_tunneltype(res->tunnel_type);
11126                 entry.input.flow.tunnel_flow.tunnel_id =
11127                         rte_cpu_to_be_32(res->tunnel_id_value);
11128         }
11129
11130         rte_memcpy(entry.input.flow_ext.flexbytes,
11131                    flexbytes,
11132                    RTE_ETH_FDIR_MAX_FLEXLEN);
11133
11134         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11135
11136         entry.action.flex_off = 0;  /*use 0 by default */
11137         if (!strcmp(res->drop, "drop"))
11138                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11139         else
11140                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11141
11142         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11143             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11144                 if (!strcmp(res->pf_vf, "pf"))
11145                         entry.input.flow_ext.is_vf = 0;
11146                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11147                         struct rte_eth_dev_info dev_info;
11148
11149                         ret = eth_dev_info_get_print_err(res->port_id,
11150                                                 &dev_info);
11151                         if (ret != 0)
11152                                 return;
11153
11154                         errno = 0;
11155                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11156                         if (errno != 0 || *end != '\0' ||
11157                             vf_id >= dev_info.max_vfs) {
11158                                 printf("invalid parameter %s.\n", res->pf_vf);
11159                                 return;
11160                         }
11161                         entry.input.flow_ext.is_vf = 1;
11162                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11163                 } else {
11164                         printf("invalid parameter %s.\n", res->pf_vf);
11165                         return;
11166                 }
11167         }
11168
11169         /* set to report FD ID by default */
11170         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11171         entry.action.rx_queue = res->queue_id;
11172         entry.soft_id = res->fd_id_value;
11173         if (!strcmp(res->ops, "add"))
11174                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11175                                              RTE_ETH_FILTER_ADD, &entry);
11176         else if (!strcmp(res->ops, "del"))
11177                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11178                                              RTE_ETH_FILTER_DELETE, &entry);
11179         else
11180                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11181                                              RTE_ETH_FILTER_UPDATE, &entry);
11182         if (ret < 0)
11183                 printf("flow director programming error: (%s)\n",
11184                         strerror(-ret));
11185 }
11186
11187 cmdline_parse_token_string_t cmd_flow_director_filter =
11188         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11189                                  flow_director_filter, "flow_director_filter");
11190 cmdline_parse_token_num_t cmd_flow_director_port_id =
11191         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11192                               port_id, UINT16);
11193 cmdline_parse_token_string_t cmd_flow_director_ops =
11194         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11195                                  ops, "add#del#update");
11196 cmdline_parse_token_string_t cmd_flow_director_flow =
11197         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11198                                  flow, "flow");
11199 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11200         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11201                 flow_type, NULL);
11202 cmdline_parse_token_string_t cmd_flow_director_ether =
11203         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11204                                  ether, "ether");
11205 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11206         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11207                               ether_type, UINT16);
11208 cmdline_parse_token_string_t cmd_flow_director_src =
11209         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11210                                  src, "src");
11211 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11212         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11213                                  ip_src);
11214 cmdline_parse_token_num_t cmd_flow_director_port_src =
11215         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11216                               port_src, UINT16);
11217 cmdline_parse_token_string_t cmd_flow_director_dst =
11218         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11219                                  dst, "dst");
11220 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11221         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11222                                  ip_dst);
11223 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11224         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11225                               port_dst, UINT16);
11226 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11227         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11228                                   verify_tag, "verify_tag");
11229 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11230         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11231                               verify_tag_value, UINT32);
11232 cmdline_parse_token_string_t cmd_flow_director_tos =
11233         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11234                                  tos, "tos");
11235 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11236         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11237                               tos_value, UINT8);
11238 cmdline_parse_token_string_t cmd_flow_director_proto =
11239         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11240                                  proto, "proto");
11241 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11242         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11243                               proto_value, UINT8);
11244 cmdline_parse_token_string_t cmd_flow_director_ttl =
11245         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11246                                  ttl, "ttl");
11247 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11248         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11249                               ttl_value, UINT8);
11250 cmdline_parse_token_string_t cmd_flow_director_vlan =
11251         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11252                                  vlan, "vlan");
11253 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11254         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11255                               vlan_value, UINT16);
11256 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11257         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11258                                  flexbytes, "flexbytes");
11259 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11260         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11261                               flexbytes_value, NULL);
11262 cmdline_parse_token_string_t cmd_flow_director_drop =
11263         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11264                                  drop, "drop#fwd");
11265 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11266         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11267                               pf_vf, NULL);
11268 cmdline_parse_token_string_t cmd_flow_director_queue =
11269         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11270                                  queue, "queue");
11271 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11272         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11273                               queue_id, UINT16);
11274 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11275         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11276                                  fd_id, "fd_id");
11277 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11278         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11279                               fd_id_value, UINT32);
11280
11281 cmdline_parse_token_string_t cmd_flow_director_mode =
11282         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11283                                  mode, "mode");
11284 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11285         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11286                                  mode_value, "IP");
11287 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11288         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11289                                  mode_value, "MAC-VLAN");
11290 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11291         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11292                                  mode_value, "Tunnel");
11293 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11294         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11295                                  mode_value, "raw");
11296 cmdline_parse_token_string_t cmd_flow_director_mac =
11297         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11298                                  mac, "mac");
11299 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11300         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11301                                     mac_addr);
11302 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11303         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11304                                  tunnel, "tunnel");
11305 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11306         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11307                                  tunnel_type, "NVGRE#VxLAN");
11308 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11309         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11310                                  tunnel_id, "tunnel-id");
11311 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11312         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11313                               tunnel_id_value, UINT32);
11314 cmdline_parse_token_string_t cmd_flow_director_packet =
11315         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11316                                  packet, "packet");
11317 cmdline_parse_token_string_t cmd_flow_director_filepath =
11318         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11319                                  filepath, NULL);
11320
11321 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11322         .f = cmd_flow_director_filter_parsed,
11323         .data = NULL,
11324         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11325                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11326                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11327                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11328                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11329                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11330                 "fd_id <fd_id_value>: "
11331                 "Add or delete an ip flow director entry on NIC",
11332         .tokens = {
11333                 (void *)&cmd_flow_director_filter,
11334                 (void *)&cmd_flow_director_port_id,
11335                 (void *)&cmd_flow_director_mode,
11336                 (void *)&cmd_flow_director_mode_ip,
11337                 (void *)&cmd_flow_director_ops,
11338                 (void *)&cmd_flow_director_flow,
11339                 (void *)&cmd_flow_director_flow_type,
11340                 (void *)&cmd_flow_director_src,
11341                 (void *)&cmd_flow_director_ip_src,
11342                 (void *)&cmd_flow_director_dst,
11343                 (void *)&cmd_flow_director_ip_dst,
11344                 (void *)&cmd_flow_director_tos,
11345                 (void *)&cmd_flow_director_tos_value,
11346                 (void *)&cmd_flow_director_proto,
11347                 (void *)&cmd_flow_director_proto_value,
11348                 (void *)&cmd_flow_director_ttl,
11349                 (void *)&cmd_flow_director_ttl_value,
11350                 (void *)&cmd_flow_director_vlan,
11351                 (void *)&cmd_flow_director_vlan_value,
11352                 (void *)&cmd_flow_director_flexbytes,
11353                 (void *)&cmd_flow_director_flexbytes_value,
11354                 (void *)&cmd_flow_director_drop,
11355                 (void *)&cmd_flow_director_pf_vf,
11356                 (void *)&cmd_flow_director_queue,
11357                 (void *)&cmd_flow_director_queue_id,
11358                 (void *)&cmd_flow_director_fd_id,
11359                 (void *)&cmd_flow_director_fd_id_value,
11360                 NULL,
11361         },
11362 };
11363
11364 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11365         .f = cmd_flow_director_filter_parsed,
11366         .data = NULL,
11367         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11368                 "director entry on NIC",
11369         .tokens = {
11370                 (void *)&cmd_flow_director_filter,
11371                 (void *)&cmd_flow_director_port_id,
11372                 (void *)&cmd_flow_director_mode,
11373                 (void *)&cmd_flow_director_mode_ip,
11374                 (void *)&cmd_flow_director_ops,
11375                 (void *)&cmd_flow_director_flow,
11376                 (void *)&cmd_flow_director_flow_type,
11377                 (void *)&cmd_flow_director_src,
11378                 (void *)&cmd_flow_director_ip_src,
11379                 (void *)&cmd_flow_director_port_src,
11380                 (void *)&cmd_flow_director_dst,
11381                 (void *)&cmd_flow_director_ip_dst,
11382                 (void *)&cmd_flow_director_port_dst,
11383                 (void *)&cmd_flow_director_tos,
11384                 (void *)&cmd_flow_director_tos_value,
11385                 (void *)&cmd_flow_director_ttl,
11386                 (void *)&cmd_flow_director_ttl_value,
11387                 (void *)&cmd_flow_director_vlan,
11388                 (void *)&cmd_flow_director_vlan_value,
11389                 (void *)&cmd_flow_director_flexbytes,
11390                 (void *)&cmd_flow_director_flexbytes_value,
11391                 (void *)&cmd_flow_director_drop,
11392                 (void *)&cmd_flow_director_pf_vf,
11393                 (void *)&cmd_flow_director_queue,
11394                 (void *)&cmd_flow_director_queue_id,
11395                 (void *)&cmd_flow_director_fd_id,
11396                 (void *)&cmd_flow_director_fd_id_value,
11397                 NULL,
11398         },
11399 };
11400
11401 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11402         .f = cmd_flow_director_filter_parsed,
11403         .data = NULL,
11404         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11405                 "director entry on NIC",
11406         .tokens = {
11407                 (void *)&cmd_flow_director_filter,
11408                 (void *)&cmd_flow_director_port_id,
11409                 (void *)&cmd_flow_director_mode,
11410                 (void *)&cmd_flow_director_mode_ip,
11411                 (void *)&cmd_flow_director_ops,
11412                 (void *)&cmd_flow_director_flow,
11413                 (void *)&cmd_flow_director_flow_type,
11414                 (void *)&cmd_flow_director_src,
11415                 (void *)&cmd_flow_director_ip_src,
11416                 (void *)&cmd_flow_director_port_src,
11417                 (void *)&cmd_flow_director_dst,
11418                 (void *)&cmd_flow_director_ip_dst,
11419                 (void *)&cmd_flow_director_port_dst,
11420                 (void *)&cmd_flow_director_verify_tag,
11421                 (void *)&cmd_flow_director_verify_tag_value,
11422                 (void *)&cmd_flow_director_tos,
11423                 (void *)&cmd_flow_director_tos_value,
11424                 (void *)&cmd_flow_director_ttl,
11425                 (void *)&cmd_flow_director_ttl_value,
11426                 (void *)&cmd_flow_director_vlan,
11427                 (void *)&cmd_flow_director_vlan_value,
11428                 (void *)&cmd_flow_director_flexbytes,
11429                 (void *)&cmd_flow_director_flexbytes_value,
11430                 (void *)&cmd_flow_director_drop,
11431                 (void *)&cmd_flow_director_pf_vf,
11432                 (void *)&cmd_flow_director_queue,
11433                 (void *)&cmd_flow_director_queue_id,
11434                 (void *)&cmd_flow_director_fd_id,
11435                 (void *)&cmd_flow_director_fd_id_value,
11436                 NULL,
11437         },
11438 };
11439
11440 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11441         .f = cmd_flow_director_filter_parsed,
11442         .data = NULL,
11443         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11444                 "director entry on NIC",
11445         .tokens = {
11446                 (void *)&cmd_flow_director_filter,
11447                 (void *)&cmd_flow_director_port_id,
11448                 (void *)&cmd_flow_director_mode,
11449                 (void *)&cmd_flow_director_mode_ip,
11450                 (void *)&cmd_flow_director_ops,
11451                 (void *)&cmd_flow_director_flow,
11452                 (void *)&cmd_flow_director_flow_type,
11453                 (void *)&cmd_flow_director_ether,
11454                 (void *)&cmd_flow_director_ether_type,
11455                 (void *)&cmd_flow_director_flexbytes,
11456                 (void *)&cmd_flow_director_flexbytes_value,
11457                 (void *)&cmd_flow_director_drop,
11458                 (void *)&cmd_flow_director_pf_vf,
11459                 (void *)&cmd_flow_director_queue,
11460                 (void *)&cmd_flow_director_queue_id,
11461                 (void *)&cmd_flow_director_fd_id,
11462                 (void *)&cmd_flow_director_fd_id_value,
11463                 NULL,
11464         },
11465 };
11466
11467 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11468         .f = cmd_flow_director_filter_parsed,
11469         .data = NULL,
11470         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11471                 "director entry on NIC",
11472         .tokens = {
11473                 (void *)&cmd_flow_director_filter,
11474                 (void *)&cmd_flow_director_port_id,
11475                 (void *)&cmd_flow_director_mode,
11476                 (void *)&cmd_flow_director_mode_mac_vlan,
11477                 (void *)&cmd_flow_director_ops,
11478                 (void *)&cmd_flow_director_mac,
11479                 (void *)&cmd_flow_director_mac_addr,
11480                 (void *)&cmd_flow_director_vlan,
11481                 (void *)&cmd_flow_director_vlan_value,
11482                 (void *)&cmd_flow_director_flexbytes,
11483                 (void *)&cmd_flow_director_flexbytes_value,
11484                 (void *)&cmd_flow_director_drop,
11485                 (void *)&cmd_flow_director_queue,
11486                 (void *)&cmd_flow_director_queue_id,
11487                 (void *)&cmd_flow_director_fd_id,
11488                 (void *)&cmd_flow_director_fd_id_value,
11489                 NULL,
11490         },
11491 };
11492
11493 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11494         .f = cmd_flow_director_filter_parsed,
11495         .data = NULL,
11496         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11497                 "director entry on NIC",
11498         .tokens = {
11499                 (void *)&cmd_flow_director_filter,
11500                 (void *)&cmd_flow_director_port_id,
11501                 (void *)&cmd_flow_director_mode,
11502                 (void *)&cmd_flow_director_mode_tunnel,
11503                 (void *)&cmd_flow_director_ops,
11504                 (void *)&cmd_flow_director_mac,
11505                 (void *)&cmd_flow_director_mac_addr,
11506                 (void *)&cmd_flow_director_vlan,
11507                 (void *)&cmd_flow_director_vlan_value,
11508                 (void *)&cmd_flow_director_tunnel,
11509                 (void *)&cmd_flow_director_tunnel_type,
11510                 (void *)&cmd_flow_director_tunnel_id,
11511                 (void *)&cmd_flow_director_tunnel_id_value,
11512                 (void *)&cmd_flow_director_flexbytes,
11513                 (void *)&cmd_flow_director_flexbytes_value,
11514                 (void *)&cmd_flow_director_drop,
11515                 (void *)&cmd_flow_director_queue,
11516                 (void *)&cmd_flow_director_queue_id,
11517                 (void *)&cmd_flow_director_fd_id,
11518                 (void *)&cmd_flow_director_fd_id_value,
11519                 NULL,
11520         },
11521 };
11522
11523 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11524         .f = cmd_flow_director_filter_parsed,
11525         .data = NULL,
11526         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11527                 "director entry on NIC",
11528         .tokens = {
11529                 (void *)&cmd_flow_director_filter,
11530                 (void *)&cmd_flow_director_port_id,
11531                 (void *)&cmd_flow_director_mode,
11532                 (void *)&cmd_flow_director_mode_raw,
11533                 (void *)&cmd_flow_director_ops,
11534                 (void *)&cmd_flow_director_flow,
11535                 (void *)&cmd_flow_director_flow_type,
11536                 (void *)&cmd_flow_director_drop,
11537                 (void *)&cmd_flow_director_queue,
11538                 (void *)&cmd_flow_director_queue_id,
11539                 (void *)&cmd_flow_director_fd_id,
11540                 (void *)&cmd_flow_director_fd_id_value,
11541                 (void *)&cmd_flow_director_packet,
11542                 (void *)&cmd_flow_director_filepath,
11543                 NULL,
11544         },
11545 };
11546
11547 struct cmd_flush_flow_director_result {
11548         cmdline_fixed_string_t flush_flow_director;
11549         portid_t port_id;
11550 };
11551
11552 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11553         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11554                                  flush_flow_director, "flush_flow_director");
11555 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11556         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11557                               port_id, UINT16);
11558
11559 static void
11560 cmd_flush_flow_director_parsed(void *parsed_result,
11561                           __rte_unused struct cmdline *cl,
11562                           __rte_unused void *data)
11563 {
11564         struct cmd_flow_director_result *res = parsed_result;
11565         int ret = 0;
11566
11567         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11568         if (ret < 0) {
11569                 printf("flow director is not supported on port %u.\n",
11570                         res->port_id);
11571                 return;
11572         }
11573
11574         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11575                         RTE_ETH_FILTER_FLUSH, NULL);
11576         if (ret < 0)
11577                 printf("flow director table flushing error: (%s)\n",
11578                         strerror(-ret));
11579 }
11580
11581 cmdline_parse_inst_t cmd_flush_flow_director = {
11582         .f = cmd_flush_flow_director_parsed,
11583         .data = NULL,
11584         .help_str = "flush_flow_director <port_id>: "
11585                 "Flush all flow director entries of a device on NIC",
11586         .tokens = {
11587                 (void *)&cmd_flush_flow_director_flush,
11588                 (void *)&cmd_flush_flow_director_port_id,
11589                 NULL,
11590         },
11591 };
11592
11593 /* *** deal with flow director mask *** */
11594 struct cmd_flow_director_mask_result {
11595         cmdline_fixed_string_t flow_director_mask;
11596         portid_t port_id;
11597         cmdline_fixed_string_t mode;
11598         cmdline_fixed_string_t mode_value;
11599         cmdline_fixed_string_t vlan;
11600         uint16_t vlan_mask;
11601         cmdline_fixed_string_t src_mask;
11602         cmdline_ipaddr_t ipv4_src;
11603         cmdline_ipaddr_t ipv6_src;
11604         uint16_t port_src;
11605         cmdline_fixed_string_t dst_mask;
11606         cmdline_ipaddr_t ipv4_dst;
11607         cmdline_ipaddr_t ipv6_dst;
11608         uint16_t port_dst;
11609         cmdline_fixed_string_t mac;
11610         uint8_t mac_addr_byte_mask;
11611         cmdline_fixed_string_t tunnel_id;
11612         uint32_t tunnel_id_mask;
11613         cmdline_fixed_string_t tunnel_type;
11614         uint8_t tunnel_type_mask;
11615 };
11616
11617 static void
11618 cmd_flow_director_mask_parsed(void *parsed_result,
11619                           __rte_unused struct cmdline *cl,
11620                           __rte_unused void *data)
11621 {
11622         struct cmd_flow_director_mask_result *res = parsed_result;
11623         struct rte_eth_fdir_masks *mask;
11624         struct rte_port *port;
11625
11626         port = &ports[res->port_id];
11627         /** Check if the port is not started **/
11628         if (port->port_status != RTE_PORT_STOPPED) {
11629                 printf("Please stop port %d first\n", res->port_id);
11630                 return;
11631         }
11632
11633         mask = &port->dev_conf.fdir_conf.mask;
11634
11635         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11636                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11637                         printf("Please set mode to MAC-VLAN.\n");
11638                         return;
11639                 }
11640
11641                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11642         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11643                 if (strcmp(res->mode_value, "Tunnel")) {
11644                         printf("Please set mode to Tunnel.\n");
11645                         return;
11646                 }
11647
11648                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11649                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11650                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11651                 mask->tunnel_type_mask = res->tunnel_type_mask;
11652         } else {
11653                 if (strcmp(res->mode_value, "IP")) {
11654                         printf("Please set mode to IP.\n");
11655                         return;
11656                 }
11657
11658                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11659                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11660                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11661                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11662                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11663                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11664                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11665         }
11666
11667         cmd_reconfig_device_queue(res->port_id, 1, 1);
11668 }
11669
11670 cmdline_parse_token_string_t cmd_flow_director_mask =
11671         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11672                                  flow_director_mask, "flow_director_mask");
11673 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11674         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11675                               port_id, UINT16);
11676 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11677         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11678                                  vlan, "vlan");
11679 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11680         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11681                               vlan_mask, UINT16);
11682 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11683         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11684                                  src_mask, "src_mask");
11685 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11686         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11687                                  ipv4_src);
11688 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11689         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11690                                  ipv6_src);
11691 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11692         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11693                               port_src, UINT16);
11694 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11695         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11696                                  dst_mask, "dst_mask");
11697 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11698         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11699                                  ipv4_dst);
11700 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11701         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11702                                  ipv6_dst);
11703 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11704         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11705                               port_dst, UINT16);
11706
11707 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11708         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11709                                  mode, "mode");
11710 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11711         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11712                                  mode_value, "IP");
11713 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11714         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11715                                  mode_value, "MAC-VLAN");
11716 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11717         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11718                                  mode_value, "Tunnel");
11719 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11720         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11721                                  mac, "mac");
11722 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11723         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11724                               mac_addr_byte_mask, UINT8);
11725 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11726         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11727                                  tunnel_type, "tunnel-type");
11728 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11729         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11730                               tunnel_type_mask, UINT8);
11731 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11732         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11733                                  tunnel_id, "tunnel-id");
11734 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11735         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11736                               tunnel_id_mask, UINT32);
11737
11738 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11739         .f = cmd_flow_director_mask_parsed,
11740         .data = NULL,
11741         .help_str = "flow_director_mask ... : "
11742                 "Set IP mode flow director's mask on NIC",
11743         .tokens = {
11744                 (void *)&cmd_flow_director_mask,
11745                 (void *)&cmd_flow_director_mask_port_id,
11746                 (void *)&cmd_flow_director_mask_mode,
11747                 (void *)&cmd_flow_director_mask_mode_ip,
11748                 (void *)&cmd_flow_director_mask_vlan,
11749                 (void *)&cmd_flow_director_mask_vlan_value,
11750                 (void *)&cmd_flow_director_mask_src,
11751                 (void *)&cmd_flow_director_mask_ipv4_src,
11752                 (void *)&cmd_flow_director_mask_ipv6_src,
11753                 (void *)&cmd_flow_director_mask_port_src,
11754                 (void *)&cmd_flow_director_mask_dst,
11755                 (void *)&cmd_flow_director_mask_ipv4_dst,
11756                 (void *)&cmd_flow_director_mask_ipv6_dst,
11757                 (void *)&cmd_flow_director_mask_port_dst,
11758                 NULL,
11759         },
11760 };
11761
11762 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11763         .f = cmd_flow_director_mask_parsed,
11764         .data = NULL,
11765         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11766                 "flow director's mask on NIC",
11767         .tokens = {
11768                 (void *)&cmd_flow_director_mask,
11769                 (void *)&cmd_flow_director_mask_port_id,
11770                 (void *)&cmd_flow_director_mask_mode,
11771                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11772                 (void *)&cmd_flow_director_mask_vlan,
11773                 (void *)&cmd_flow_director_mask_vlan_value,
11774                 NULL,
11775         },
11776 };
11777
11778 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11779         .f = cmd_flow_director_mask_parsed,
11780         .data = NULL,
11781         .help_str = "flow_director_mask ... : Set tunnel mode "
11782                 "flow director's mask on NIC",
11783         .tokens = {
11784                 (void *)&cmd_flow_director_mask,
11785                 (void *)&cmd_flow_director_mask_port_id,
11786                 (void *)&cmd_flow_director_mask_mode,
11787                 (void *)&cmd_flow_director_mask_mode_tunnel,
11788                 (void *)&cmd_flow_director_mask_vlan,
11789                 (void *)&cmd_flow_director_mask_vlan_value,
11790                 (void *)&cmd_flow_director_mask_mac,
11791                 (void *)&cmd_flow_director_mask_mac_value,
11792                 (void *)&cmd_flow_director_mask_tunnel_type,
11793                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11794                 (void *)&cmd_flow_director_mask_tunnel_id,
11795                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11796                 NULL,
11797         },
11798 };
11799
11800 /* *** deal with flow director mask on flexible payload *** */
11801 struct cmd_flow_director_flex_mask_result {
11802         cmdline_fixed_string_t flow_director_flexmask;
11803         portid_t port_id;
11804         cmdline_fixed_string_t flow;
11805         cmdline_fixed_string_t flow_type;
11806         cmdline_fixed_string_t mask;
11807 };
11808
11809 static void
11810 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11811                           __rte_unused struct cmdline *cl,
11812                           __rte_unused void *data)
11813 {
11814         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11815         struct rte_eth_fdir_info fdir_info;
11816         struct rte_eth_fdir_flex_mask flex_mask;
11817         struct rte_port *port;
11818         uint64_t flow_type_mask;
11819         uint16_t i;
11820         int ret;
11821
11822         port = &ports[res->port_id];
11823         /** Check if the port is not started **/
11824         if (port->port_status != RTE_PORT_STOPPED) {
11825                 printf("Please stop port %d first\n", res->port_id);
11826                 return;
11827         }
11828
11829         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11830         ret = parse_flexbytes(res->mask,
11831                         flex_mask.mask,
11832                         RTE_ETH_FDIR_MAX_FLEXLEN);
11833         if (ret < 0) {
11834                 printf("error: Cannot parse mask input.\n");
11835                 return;
11836         }
11837
11838         memset(&fdir_info, 0, sizeof(fdir_info));
11839         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11840                                 RTE_ETH_FILTER_INFO, &fdir_info);
11841         if (ret < 0) {
11842                 printf("Cannot get FDir filter info\n");
11843                 return;
11844         }
11845
11846         if (!strcmp(res->flow_type, "none")) {
11847                 /* means don't specify the flow type */
11848                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11849                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11850                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11851                                0, sizeof(struct rte_eth_fdir_flex_mask));
11852                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11853                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11854                                  &flex_mask,
11855                                  sizeof(struct rte_eth_fdir_flex_mask));
11856                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11857                 return;
11858         }
11859         flow_type_mask = fdir_info.flow_types_mask[0];
11860         if (!strcmp(res->flow_type, "all")) {
11861                 if (!flow_type_mask) {
11862                         printf("No flow type supported\n");
11863                         return;
11864                 }
11865                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11866                         if (flow_type_mask & (1ULL << i)) {
11867                                 flex_mask.flow_type = i;
11868                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11869                         }
11870                 }
11871                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11872                 return;
11873         }
11874         flex_mask.flow_type = str2flowtype(res->flow_type);
11875         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11876                 printf("Flow type %s not supported on port %d\n",
11877                                 res->flow_type, res->port_id);
11878                 return;
11879         }
11880         fdir_set_flex_mask(res->port_id, &flex_mask);
11881         cmd_reconfig_device_queue(res->port_id, 1, 1);
11882 }
11883
11884 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11885         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11886                                  flow_director_flexmask,
11887                                  "flow_director_flex_mask");
11888 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11889         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11890                               port_id, UINT16);
11891 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11892         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11893                                  flow, "flow");
11894 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11895         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11896                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11897                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11898 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11899         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11900                                  mask, NULL);
11901
11902 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11903         .f = cmd_flow_director_flex_mask_parsed,
11904         .data = NULL,
11905         .help_str = "flow_director_flex_mask ... : "
11906                 "Set flow director's flex mask on NIC",
11907         .tokens = {
11908                 (void *)&cmd_flow_director_flexmask,
11909                 (void *)&cmd_flow_director_flexmask_port_id,
11910                 (void *)&cmd_flow_director_flexmask_flow,
11911                 (void *)&cmd_flow_director_flexmask_flow_type,
11912                 (void *)&cmd_flow_director_flexmask_mask,
11913                 NULL,
11914         },
11915 };
11916
11917 /* *** deal with flow director flexible payload configuration *** */
11918 struct cmd_flow_director_flexpayload_result {
11919         cmdline_fixed_string_t flow_director_flexpayload;
11920         portid_t port_id;
11921         cmdline_fixed_string_t payload_layer;
11922         cmdline_fixed_string_t payload_cfg;
11923 };
11924
11925 static inline int
11926 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11927 {
11928         char s[256];
11929         const char *p, *p0 = q_arg;
11930         char *end;
11931         unsigned long int_fld;
11932         char *str_fld[max_num];
11933         int i;
11934         unsigned size;
11935         int ret = -1;
11936
11937         p = strchr(p0, '(');
11938         if (p == NULL)
11939                 return -1;
11940         ++p;
11941         p0 = strchr(p, ')');
11942         if (p0 == NULL)
11943                 return -1;
11944
11945         size = p0 - p;
11946         if (size >= sizeof(s))
11947                 return -1;
11948
11949         snprintf(s, sizeof(s), "%.*s", size, p);
11950         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11951         if (ret < 0 || ret > max_num)
11952                 return -1;
11953         for (i = 0; i < ret; i++) {
11954                 errno = 0;
11955                 int_fld = strtoul(str_fld[i], &end, 0);
11956                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11957                         return -1;
11958                 offsets[i] = (uint16_t)int_fld;
11959         }
11960         return ret;
11961 }
11962
11963 static void
11964 cmd_flow_director_flxpld_parsed(void *parsed_result,
11965                           __rte_unused struct cmdline *cl,
11966                           __rte_unused void *data)
11967 {
11968         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11969         struct rte_eth_flex_payload_cfg flex_cfg;
11970         struct rte_port *port;
11971         int ret = 0;
11972
11973         port = &ports[res->port_id];
11974         /** Check if the port is not started **/
11975         if (port->port_status != RTE_PORT_STOPPED) {
11976                 printf("Please stop port %d first\n", res->port_id);
11977                 return;
11978         }
11979
11980         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11981
11982         if (!strcmp(res->payload_layer, "raw"))
11983                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11984         else if (!strcmp(res->payload_layer, "l2"))
11985                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11986         else if (!strcmp(res->payload_layer, "l3"))
11987                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11988         else if (!strcmp(res->payload_layer, "l4"))
11989                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11990
11991         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11992                             RTE_ETH_FDIR_MAX_FLEXLEN);
11993         if (ret < 0) {
11994                 printf("error: Cannot parse flex payload input.\n");
11995                 return;
11996         }
11997
11998         fdir_set_flex_payload(res->port_id, &flex_cfg);
11999         cmd_reconfig_device_queue(res->port_id, 1, 1);
12000 }
12001
12002 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12003         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12004                                  flow_director_flexpayload,
12005                                  "flow_director_flex_payload");
12006 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12007         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12008                               port_id, UINT16);
12009 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12010         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12011                                  payload_layer, "raw#l2#l3#l4");
12012 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12013         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12014                                  payload_cfg, NULL);
12015
12016 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12017         .f = cmd_flow_director_flxpld_parsed,
12018         .data = NULL,
12019         .help_str = "flow_director_flexpayload ... : "
12020                 "Set flow director's flex payload on NIC",
12021         .tokens = {
12022                 (void *)&cmd_flow_director_flexpayload,
12023                 (void *)&cmd_flow_director_flexpayload_port_id,
12024                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12025                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12026                 NULL,
12027         },
12028 };
12029
12030 /* Generic flow interface command. */
12031 extern cmdline_parse_inst_t cmd_flow;
12032
12033 /* *** Classification Filters Control *** */
12034 /* *** Get symmetric hash enable per port *** */
12035 struct cmd_get_sym_hash_ena_per_port_result {
12036         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12037         portid_t port_id;
12038 };
12039
12040 static void
12041 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12042                                  __rte_unused struct cmdline *cl,
12043                                  __rte_unused void *data)
12044 {
12045         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12046         struct rte_eth_hash_filter_info info;
12047         int ret;
12048
12049         if (rte_eth_dev_filter_supported(res->port_id,
12050                                 RTE_ETH_FILTER_HASH) < 0) {
12051                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12052                                                         res->port_id);
12053                 return;
12054         }
12055
12056         memset(&info, 0, sizeof(info));
12057         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12058         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12059                                                 RTE_ETH_FILTER_GET, &info);
12060
12061         if (ret < 0) {
12062                 printf("Cannot get symmetric hash enable per port "
12063                                         "on port %u\n", res->port_id);
12064                 return;
12065         }
12066
12067         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12068                                 "enabled" : "disabled", res->port_id);
12069 }
12070
12071 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12072         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12073                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12074 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12075         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12076                 port_id, UINT16);
12077
12078 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12079         .f = cmd_get_sym_hash_per_port_parsed,
12080         .data = NULL,
12081         .help_str = "get_sym_hash_ena_per_port <port_id>",
12082         .tokens = {
12083                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12084                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12085                 NULL,
12086         },
12087 };
12088
12089 /* *** Set symmetric hash enable per port *** */
12090 struct cmd_set_sym_hash_ena_per_port_result {
12091         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12092         cmdline_fixed_string_t enable;
12093         portid_t port_id;
12094 };
12095
12096 static void
12097 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12098                                  __rte_unused struct cmdline *cl,
12099                                  __rte_unused void *data)
12100 {
12101         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12102         struct rte_eth_hash_filter_info info;
12103         int ret;
12104
12105         if (rte_eth_dev_filter_supported(res->port_id,
12106                                 RTE_ETH_FILTER_HASH) < 0) {
12107                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12108                                                         res->port_id);
12109                 return;
12110         }
12111
12112         memset(&info, 0, sizeof(info));
12113         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12114         if (!strcmp(res->enable, "enable"))
12115                 info.info.enable = 1;
12116         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12117                                         RTE_ETH_FILTER_SET, &info);
12118         if (ret < 0) {
12119                 printf("Cannot set symmetric hash enable per port on "
12120                                         "port %u\n", res->port_id);
12121                 return;
12122         }
12123         printf("Symmetric hash has been set to %s on port %u\n",
12124                                         res->enable, res->port_id);
12125 }
12126
12127 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12128         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12129                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12130 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12131         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12132                 port_id, UINT16);
12133 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12134         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12135                 enable, "enable#disable");
12136
12137 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12138         .f = cmd_set_sym_hash_per_port_parsed,
12139         .data = NULL,
12140         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12141         .tokens = {
12142                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12143                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12144                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12145                 NULL,
12146         },
12147 };
12148
12149 /* Get global config of hash function */
12150 struct cmd_get_hash_global_config_result {
12151         cmdline_fixed_string_t get_hash_global_config;
12152         portid_t port_id;
12153 };
12154
12155 static char *
12156 flowtype_to_str(uint16_t ftype)
12157 {
12158         uint16_t i;
12159         static struct {
12160                 char str[16];
12161                 uint16_t ftype;
12162         } ftype_table[] = {
12163                 {"ipv4", RTE_ETH_FLOW_IPV4},
12164                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12165                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12166                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12167                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12168                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12169                 {"ipv6", RTE_ETH_FLOW_IPV6},
12170                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12171                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12172                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12173                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12174                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12175                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12176                 {"port", RTE_ETH_FLOW_PORT},
12177                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12178                 {"geneve", RTE_ETH_FLOW_GENEVE},
12179                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12180                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12181         };
12182
12183         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12184                 if (ftype_table[i].ftype == ftype)
12185                         return ftype_table[i].str;
12186         }
12187
12188         return NULL;
12189 }
12190
12191 static void
12192 cmd_get_hash_global_config_parsed(void *parsed_result,
12193                                   __rte_unused struct cmdline *cl,
12194                                   __rte_unused void *data)
12195 {
12196         struct cmd_get_hash_global_config_result *res = parsed_result;
12197         struct rte_eth_hash_filter_info info;
12198         uint32_t idx, offset;
12199         uint16_t i;
12200         char *str;
12201         int ret;
12202
12203         if (rte_eth_dev_filter_supported(res->port_id,
12204                         RTE_ETH_FILTER_HASH) < 0) {
12205                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12206                                                         res->port_id);
12207                 return;
12208         }
12209
12210         memset(&info, 0, sizeof(info));
12211         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12212         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12213                                         RTE_ETH_FILTER_GET, &info);
12214         if (ret < 0) {
12215                 printf("Cannot get hash global configurations by port %d\n",
12216                                                         res->port_id);
12217                 return;
12218         }
12219
12220         switch (info.info.global_conf.hash_func) {
12221         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12222                 printf("Hash function is Toeplitz\n");
12223                 break;
12224         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12225                 printf("Hash function is Simple XOR\n");
12226                 break;
12227         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12228                 printf("Hash function is Symmetric Toeplitz\n");
12229                 break;
12230         default:
12231                 printf("Unknown hash function\n");
12232                 break;
12233         }
12234
12235         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12236                 idx = i / UINT64_BIT;
12237                 offset = i % UINT64_BIT;
12238                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12239                                                 (1ULL << offset)))
12240                         continue;
12241                 str = flowtype_to_str(i);
12242                 if (!str)
12243                         continue;
12244                 printf("Symmetric hash is %s globally for flow type %s "
12245                                                         "by port %d\n",
12246                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12247                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12248                                                         res->port_id);
12249         }
12250 }
12251
12252 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12253         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12254                 get_hash_global_config, "get_hash_global_config");
12255 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12256         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12257                 port_id, UINT16);
12258
12259 cmdline_parse_inst_t cmd_get_hash_global_config = {
12260         .f = cmd_get_hash_global_config_parsed,
12261         .data = NULL,
12262         .help_str = "get_hash_global_config <port_id>",
12263         .tokens = {
12264                 (void *)&cmd_get_hash_global_config_all,
12265                 (void *)&cmd_get_hash_global_config_port_id,
12266                 NULL,
12267         },
12268 };
12269
12270 /* Set global config of hash function */
12271 struct cmd_set_hash_global_config_result {
12272         cmdline_fixed_string_t set_hash_global_config;
12273         portid_t port_id;
12274         cmdline_fixed_string_t hash_func;
12275         cmdline_fixed_string_t flow_type;
12276         cmdline_fixed_string_t enable;
12277 };
12278
12279 static void
12280 cmd_set_hash_global_config_parsed(void *parsed_result,
12281                                   __rte_unused struct cmdline *cl,
12282                                   __rte_unused void *data)
12283 {
12284         struct cmd_set_hash_global_config_result *res = parsed_result;
12285         struct rte_eth_hash_filter_info info;
12286         uint32_t ftype, idx, offset;
12287         int ret;
12288
12289         if (rte_eth_dev_filter_supported(res->port_id,
12290                                 RTE_ETH_FILTER_HASH) < 0) {
12291                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12292                                                         res->port_id);
12293                 return;
12294         }
12295         memset(&info, 0, sizeof(info));
12296         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12297         if (!strcmp(res->hash_func, "toeplitz"))
12298                 info.info.global_conf.hash_func =
12299                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12300         else if (!strcmp(res->hash_func, "simple_xor"))
12301                 info.info.global_conf.hash_func =
12302                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12303         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12304                 info.info.global_conf.hash_func =
12305                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12306         else if (!strcmp(res->hash_func, "default"))
12307                 info.info.global_conf.hash_func =
12308                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12309
12310         ftype = str2flowtype(res->flow_type);
12311         idx = ftype / UINT64_BIT;
12312         offset = ftype % UINT64_BIT;
12313         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12314         if (!strcmp(res->enable, "enable"))
12315                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12316                                                 (1ULL << offset);
12317         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12318                                         RTE_ETH_FILTER_SET, &info);
12319         if (ret < 0)
12320                 printf("Cannot set global hash configurations by port %d\n",
12321                                                         res->port_id);
12322         else
12323                 printf("Global hash configurations have been set "
12324                         "successfully by port %d\n", res->port_id);
12325 }
12326
12327 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12328         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12329                 set_hash_global_config, "set_hash_global_config");
12330 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12331         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12332                 port_id, UINT16);
12333 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12334         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12335                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12336 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12337         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12338                 flow_type,
12339                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12340                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12341 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12342         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12343                 enable, "enable#disable");
12344
12345 cmdline_parse_inst_t cmd_set_hash_global_config = {
12346         .f = cmd_set_hash_global_config_parsed,
12347         .data = NULL,
12348         .help_str = "set_hash_global_config <port_id> "
12349                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12350                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12351                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12352                 "l2_payload enable|disable",
12353         .tokens = {
12354                 (void *)&cmd_set_hash_global_config_all,
12355                 (void *)&cmd_set_hash_global_config_port_id,
12356                 (void *)&cmd_set_hash_global_config_hash_func,
12357                 (void *)&cmd_set_hash_global_config_flow_type,
12358                 (void *)&cmd_set_hash_global_config_enable,
12359                 NULL,
12360         },
12361 };
12362
12363 /* Set hash input set */
12364 struct cmd_set_hash_input_set_result {
12365         cmdline_fixed_string_t set_hash_input_set;
12366         portid_t port_id;
12367         cmdline_fixed_string_t flow_type;
12368         cmdline_fixed_string_t inset_field;
12369         cmdline_fixed_string_t select;
12370 };
12371
12372 static enum rte_eth_input_set_field
12373 str2inset(char *string)
12374 {
12375         uint16_t i;
12376
12377         static const struct {
12378                 char str[32];
12379                 enum rte_eth_input_set_field inset;
12380         } inset_table[] = {
12381                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12382                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12383                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12384                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12385                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12386                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12387                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12388                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12389                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12390                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12391                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12392                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12393                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12394                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12395                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12396                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12397                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12398                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12399                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12400                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12401                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12402                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12403                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12404                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12405                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12406                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12407                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12408                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12409                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12410                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12411                 {"none", RTE_ETH_INPUT_SET_NONE},
12412         };
12413
12414         for (i = 0; i < RTE_DIM(inset_table); i++) {
12415                 if (!strcmp(string, inset_table[i].str))
12416                         return inset_table[i].inset;
12417         }
12418
12419         return RTE_ETH_INPUT_SET_UNKNOWN;
12420 }
12421
12422 static void
12423 cmd_set_hash_input_set_parsed(void *parsed_result,
12424                               __rte_unused struct cmdline *cl,
12425                               __rte_unused void *data)
12426 {
12427         struct cmd_set_hash_input_set_result *res = parsed_result;
12428         struct rte_eth_hash_filter_info info;
12429
12430         memset(&info, 0, sizeof(info));
12431         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12432         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12433         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12434         info.info.input_set_conf.inset_size = 1;
12435         if (!strcmp(res->select, "select"))
12436                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12437         else if (!strcmp(res->select, "add"))
12438                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12439         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12440                                 RTE_ETH_FILTER_SET, &info);
12441 }
12442
12443 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12444         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12445                 set_hash_input_set, "set_hash_input_set");
12446 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12447         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12448                 port_id, UINT16);
12449 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12450         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12451                 flow_type, NULL);
12452 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12453         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12454                 inset_field,
12455                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12456                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12457                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12458                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12459                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12460                 "fld-8th#none");
12461 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12462         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12463                 select, "select#add");
12464
12465 cmdline_parse_inst_t cmd_set_hash_input_set = {
12466         .f = cmd_set_hash_input_set_parsed,
12467         .data = NULL,
12468         .help_str = "set_hash_input_set <port_id> "
12469         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12470         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12471         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12472         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12473         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12474         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12475         "fld-7th|fld-8th|none select|add",
12476         .tokens = {
12477                 (void *)&cmd_set_hash_input_set_cmd,
12478                 (void *)&cmd_set_hash_input_set_port_id,
12479                 (void *)&cmd_set_hash_input_set_flow_type,
12480                 (void *)&cmd_set_hash_input_set_field,
12481                 (void *)&cmd_set_hash_input_set_select,
12482                 NULL,
12483         },
12484 };
12485
12486 /* Set flow director input set */
12487 struct cmd_set_fdir_input_set_result {
12488         cmdline_fixed_string_t set_fdir_input_set;
12489         portid_t port_id;
12490         cmdline_fixed_string_t flow_type;
12491         cmdline_fixed_string_t inset_field;
12492         cmdline_fixed_string_t select;
12493 };
12494
12495 static void
12496 cmd_set_fdir_input_set_parsed(void *parsed_result,
12497         __rte_unused struct cmdline *cl,
12498         __rte_unused void *data)
12499 {
12500         struct cmd_set_fdir_input_set_result *res = parsed_result;
12501         struct rte_eth_fdir_filter_info info;
12502
12503         memset(&info, 0, sizeof(info));
12504         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12505         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12506         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12507         info.info.input_set_conf.inset_size = 1;
12508         if (!strcmp(res->select, "select"))
12509                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12510         else if (!strcmp(res->select, "add"))
12511                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12512         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12513                 RTE_ETH_FILTER_SET, &info);
12514 }
12515
12516 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12517         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12518         set_fdir_input_set, "set_fdir_input_set");
12519 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12520         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12521         port_id, UINT16);
12522 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12523         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12524         flow_type,
12525         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12526         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12527 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12528         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12529         inset_field,
12530         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12531         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12532         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12533         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12534         "sctp-veri-tag#none");
12535 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12536         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12537         select, "select#add");
12538
12539 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12540         .f = cmd_set_fdir_input_set_parsed,
12541         .data = NULL,
12542         .help_str = "set_fdir_input_set <port_id> "
12543         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12544         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12545         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12546         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12547         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12548         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12549         "sctp-veri-tag|none select|add",
12550         .tokens = {
12551                 (void *)&cmd_set_fdir_input_set_cmd,
12552                 (void *)&cmd_set_fdir_input_set_port_id,
12553                 (void *)&cmd_set_fdir_input_set_flow_type,
12554                 (void *)&cmd_set_fdir_input_set_field,
12555                 (void *)&cmd_set_fdir_input_set_select,
12556                 NULL,
12557         },
12558 };
12559
12560 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12561 struct cmd_mcast_addr_result {
12562         cmdline_fixed_string_t mcast_addr_cmd;
12563         cmdline_fixed_string_t what;
12564         uint16_t port_num;
12565         struct rte_ether_addr mc_addr;
12566 };
12567
12568 static void cmd_mcast_addr_parsed(void *parsed_result,
12569                 __rte_unused struct cmdline *cl,
12570                 __rte_unused void *data)
12571 {
12572         struct cmd_mcast_addr_result *res = parsed_result;
12573
12574         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12575                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12576                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12577                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12578                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12579                 return;
12580         }
12581         if (strcmp(res->what, "add") == 0)
12582                 mcast_addr_add(res->port_num, &res->mc_addr);
12583         else
12584                 mcast_addr_remove(res->port_num, &res->mc_addr);
12585 }
12586
12587 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12588         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12589                                  mcast_addr_cmd, "mcast_addr");
12590 cmdline_parse_token_string_t cmd_mcast_addr_what =
12591         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12592                                  "add#remove");
12593 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12594         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12595 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12596         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12597
12598 cmdline_parse_inst_t cmd_mcast_addr = {
12599         .f = cmd_mcast_addr_parsed,
12600         .data = (void *)0,
12601         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12602                 "Add/Remove multicast MAC address on port_id",
12603         .tokens = {
12604                 (void *)&cmd_mcast_addr_cmd,
12605                 (void *)&cmd_mcast_addr_what,
12606                 (void *)&cmd_mcast_addr_portnum,
12607                 (void *)&cmd_mcast_addr_addr,
12608                 NULL,
12609         },
12610 };
12611
12612 /* l2 tunnel config
12613  * only support E-tag now.
12614  */
12615
12616 /* Ether type config */
12617 struct cmd_config_l2_tunnel_eth_type_result {
12618         cmdline_fixed_string_t port;
12619         cmdline_fixed_string_t config;
12620         cmdline_fixed_string_t all;
12621         portid_t id;
12622         cmdline_fixed_string_t l2_tunnel;
12623         cmdline_fixed_string_t l2_tunnel_type;
12624         cmdline_fixed_string_t eth_type;
12625         uint16_t eth_type_val;
12626 };
12627
12628 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12629         TOKEN_STRING_INITIALIZER
12630                 (struct cmd_config_l2_tunnel_eth_type_result,
12631                  port, "port");
12632 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12633         TOKEN_STRING_INITIALIZER
12634                 (struct cmd_config_l2_tunnel_eth_type_result,
12635                  config, "config");
12636 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12637         TOKEN_STRING_INITIALIZER
12638                 (struct cmd_config_l2_tunnel_eth_type_result,
12639                  all, "all");
12640 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12641         TOKEN_NUM_INITIALIZER
12642                 (struct cmd_config_l2_tunnel_eth_type_result,
12643                  id, UINT16);
12644 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12645         TOKEN_STRING_INITIALIZER
12646                 (struct cmd_config_l2_tunnel_eth_type_result,
12647                  l2_tunnel, "l2-tunnel");
12648 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12649         TOKEN_STRING_INITIALIZER
12650                 (struct cmd_config_l2_tunnel_eth_type_result,
12651                  l2_tunnel_type, "E-tag");
12652 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12653         TOKEN_STRING_INITIALIZER
12654                 (struct cmd_config_l2_tunnel_eth_type_result,
12655                  eth_type, "ether-type");
12656 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12657         TOKEN_NUM_INITIALIZER
12658                 (struct cmd_config_l2_tunnel_eth_type_result,
12659                  eth_type_val, UINT16);
12660
12661 static enum rte_eth_tunnel_type
12662 str2fdir_l2_tunnel_type(char *string)
12663 {
12664         uint32_t i = 0;
12665
12666         static const struct {
12667                 char str[32];
12668                 enum rte_eth_tunnel_type type;
12669         } l2_tunnel_type_str[] = {
12670                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12671         };
12672
12673         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12674                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12675                         return l2_tunnel_type_str[i].type;
12676         }
12677         return RTE_TUNNEL_TYPE_NONE;
12678 }
12679
12680 /* ether type config for all ports */
12681 static void
12682 cmd_config_l2_tunnel_eth_type_all_parsed
12683         (void *parsed_result,
12684          __rte_unused struct cmdline *cl,
12685          __rte_unused void *data)
12686 {
12687         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12688         struct rte_eth_l2_tunnel_conf entry;
12689         portid_t pid;
12690
12691         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12692         entry.ether_type = res->eth_type_val;
12693
12694         RTE_ETH_FOREACH_DEV(pid) {
12695                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12696         }
12697 }
12698
12699 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12700         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12701         .data = NULL,
12702         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12703         .tokens = {
12704                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12705                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12706                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12707                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12708                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12709                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12710                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12711                 NULL,
12712         },
12713 };
12714
12715 /* ether type config for a specific port */
12716 static void
12717 cmd_config_l2_tunnel_eth_type_specific_parsed(
12718         void *parsed_result,
12719         __rte_unused struct cmdline *cl,
12720         __rte_unused void *data)
12721 {
12722         struct cmd_config_l2_tunnel_eth_type_result *res =
12723                  parsed_result;
12724         struct rte_eth_l2_tunnel_conf entry;
12725
12726         if (port_id_is_invalid(res->id, ENABLED_WARN))
12727                 return;
12728
12729         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12730         entry.ether_type = res->eth_type_val;
12731
12732         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12733 }
12734
12735 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12736         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12737         .data = NULL,
12738         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12739         .tokens = {
12740                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12741                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12742                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12743                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12744                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12745                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12746                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12747                 NULL,
12748         },
12749 };
12750
12751 /* Enable/disable l2 tunnel */
12752 struct cmd_config_l2_tunnel_en_dis_result {
12753         cmdline_fixed_string_t port;
12754         cmdline_fixed_string_t config;
12755         cmdline_fixed_string_t all;
12756         portid_t id;
12757         cmdline_fixed_string_t l2_tunnel;
12758         cmdline_fixed_string_t l2_tunnel_type;
12759         cmdline_fixed_string_t en_dis;
12760 };
12761
12762 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12763         TOKEN_STRING_INITIALIZER
12764                 (struct cmd_config_l2_tunnel_en_dis_result,
12765                  port, "port");
12766 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12767         TOKEN_STRING_INITIALIZER
12768                 (struct cmd_config_l2_tunnel_en_dis_result,
12769                  config, "config");
12770 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12771         TOKEN_STRING_INITIALIZER
12772                 (struct cmd_config_l2_tunnel_en_dis_result,
12773                  all, "all");
12774 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12775         TOKEN_NUM_INITIALIZER
12776                 (struct cmd_config_l2_tunnel_en_dis_result,
12777                  id, UINT16);
12778 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12779         TOKEN_STRING_INITIALIZER
12780                 (struct cmd_config_l2_tunnel_en_dis_result,
12781                  l2_tunnel, "l2-tunnel");
12782 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12783         TOKEN_STRING_INITIALIZER
12784                 (struct cmd_config_l2_tunnel_en_dis_result,
12785                  l2_tunnel_type, "E-tag");
12786 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12787         TOKEN_STRING_INITIALIZER
12788                 (struct cmd_config_l2_tunnel_en_dis_result,
12789                  en_dis, "enable#disable");
12790
12791 /* enable/disable l2 tunnel for all ports */
12792 static void
12793 cmd_config_l2_tunnel_en_dis_all_parsed(
12794         void *parsed_result,
12795         __rte_unused struct cmdline *cl,
12796         __rte_unused void *data)
12797 {
12798         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12799         struct rte_eth_l2_tunnel_conf entry;
12800         portid_t pid;
12801         uint8_t en;
12802
12803         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12804
12805         if (!strcmp("enable", res->en_dis))
12806                 en = 1;
12807         else
12808                 en = 0;
12809
12810         RTE_ETH_FOREACH_DEV(pid) {
12811                 rte_eth_dev_l2_tunnel_offload_set(pid,
12812                                                   &entry,
12813                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12814                                                   en);
12815         }
12816 }
12817
12818 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12819         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12820         .data = NULL,
12821         .help_str = "port config all l2-tunnel E-tag enable|disable",
12822         .tokens = {
12823                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12824                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12825                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12826                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12827                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12828                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12829                 NULL,
12830         },
12831 };
12832
12833 /* enable/disable l2 tunnel for a port */
12834 static void
12835 cmd_config_l2_tunnel_en_dis_specific_parsed(
12836         void *parsed_result,
12837         __rte_unused struct cmdline *cl,
12838         __rte_unused void *data)
12839 {
12840         struct cmd_config_l2_tunnel_en_dis_result *res =
12841                 parsed_result;
12842         struct rte_eth_l2_tunnel_conf entry;
12843
12844         if (port_id_is_invalid(res->id, ENABLED_WARN))
12845                 return;
12846
12847         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12848
12849         if (!strcmp("enable", res->en_dis))
12850                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12851                                                   &entry,
12852                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12853                                                   1);
12854         else
12855                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12856                                                   &entry,
12857                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12858                                                   0);
12859 }
12860
12861 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12862         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12863         .data = NULL,
12864         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12865         .tokens = {
12866                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12867                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12868                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12869                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12870                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12871                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12872                 NULL,
12873         },
12874 };
12875
12876 /* E-tag configuration */
12877
12878 /* Common result structure for all E-tag configuration */
12879 struct cmd_config_e_tag_result {
12880         cmdline_fixed_string_t e_tag;
12881         cmdline_fixed_string_t set;
12882         cmdline_fixed_string_t insertion;
12883         cmdline_fixed_string_t stripping;
12884         cmdline_fixed_string_t forwarding;
12885         cmdline_fixed_string_t filter;
12886         cmdline_fixed_string_t add;
12887         cmdline_fixed_string_t del;
12888         cmdline_fixed_string_t on;
12889         cmdline_fixed_string_t off;
12890         cmdline_fixed_string_t on_off;
12891         cmdline_fixed_string_t port_tag_id;
12892         uint32_t port_tag_id_val;
12893         cmdline_fixed_string_t e_tag_id;
12894         uint16_t e_tag_id_val;
12895         cmdline_fixed_string_t dst_pool;
12896         uint8_t dst_pool_val;
12897         cmdline_fixed_string_t port;
12898         portid_t port_id;
12899         cmdline_fixed_string_t vf;
12900         uint8_t vf_id;
12901 };
12902
12903 /* Common CLI fields for all E-tag configuration */
12904 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12905         TOKEN_STRING_INITIALIZER
12906                 (struct cmd_config_e_tag_result,
12907                  e_tag, "E-tag");
12908 cmdline_parse_token_string_t cmd_config_e_tag_set =
12909         TOKEN_STRING_INITIALIZER
12910                 (struct cmd_config_e_tag_result,
12911                  set, "set");
12912 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
12913         TOKEN_STRING_INITIALIZER
12914                 (struct cmd_config_e_tag_result,
12915                  insertion, "insertion");
12916 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
12917         TOKEN_STRING_INITIALIZER
12918                 (struct cmd_config_e_tag_result,
12919                  stripping, "stripping");
12920 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
12921         TOKEN_STRING_INITIALIZER
12922                 (struct cmd_config_e_tag_result,
12923                  forwarding, "forwarding");
12924 cmdline_parse_token_string_t cmd_config_e_tag_filter =
12925         TOKEN_STRING_INITIALIZER
12926                 (struct cmd_config_e_tag_result,
12927                  filter, "filter");
12928 cmdline_parse_token_string_t cmd_config_e_tag_add =
12929         TOKEN_STRING_INITIALIZER
12930                 (struct cmd_config_e_tag_result,
12931                  add, "add");
12932 cmdline_parse_token_string_t cmd_config_e_tag_del =
12933         TOKEN_STRING_INITIALIZER
12934                 (struct cmd_config_e_tag_result,
12935                  del, "del");
12936 cmdline_parse_token_string_t cmd_config_e_tag_on =
12937         TOKEN_STRING_INITIALIZER
12938                 (struct cmd_config_e_tag_result,
12939                  on, "on");
12940 cmdline_parse_token_string_t cmd_config_e_tag_off =
12941         TOKEN_STRING_INITIALIZER
12942                 (struct cmd_config_e_tag_result,
12943                  off, "off");
12944 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
12945         TOKEN_STRING_INITIALIZER
12946                 (struct cmd_config_e_tag_result,
12947                  on_off, "on#off");
12948 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
12949         TOKEN_STRING_INITIALIZER
12950                 (struct cmd_config_e_tag_result,
12951                  port_tag_id, "port-tag-id");
12952 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
12953         TOKEN_NUM_INITIALIZER
12954                 (struct cmd_config_e_tag_result,
12955                  port_tag_id_val, UINT32);
12956 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12957         TOKEN_STRING_INITIALIZER
12958                 (struct cmd_config_e_tag_result,
12959                  e_tag_id, "e-tag-id");
12960 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12961         TOKEN_NUM_INITIALIZER
12962                 (struct cmd_config_e_tag_result,
12963                  e_tag_id_val, UINT16);
12964 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12965         TOKEN_STRING_INITIALIZER
12966                 (struct cmd_config_e_tag_result,
12967                  dst_pool, "dst-pool");
12968 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12969         TOKEN_NUM_INITIALIZER
12970                 (struct cmd_config_e_tag_result,
12971                  dst_pool_val, UINT8);
12972 cmdline_parse_token_string_t cmd_config_e_tag_port =
12973         TOKEN_STRING_INITIALIZER
12974                 (struct cmd_config_e_tag_result,
12975                  port, "port");
12976 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12977         TOKEN_NUM_INITIALIZER
12978                 (struct cmd_config_e_tag_result,
12979                  port_id, UINT16);
12980 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12981         TOKEN_STRING_INITIALIZER
12982                 (struct cmd_config_e_tag_result,
12983                  vf, "vf");
12984 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12985         TOKEN_NUM_INITIALIZER
12986                 (struct cmd_config_e_tag_result,
12987                  vf_id, UINT8);
12988
12989 /* E-tag insertion configuration */
12990 static void
12991 cmd_config_e_tag_insertion_en_parsed(
12992         void *parsed_result,
12993         __rte_unused struct cmdline *cl,
12994         __rte_unused void *data)
12995 {
12996         struct cmd_config_e_tag_result *res =
12997                 parsed_result;
12998         struct rte_eth_l2_tunnel_conf entry;
12999
13000         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13001                 return;
13002
13003         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13004         entry.tunnel_id = res->port_tag_id_val;
13005         entry.vf_id = res->vf_id;
13006         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13007                                           &entry,
13008                                           ETH_L2_TUNNEL_INSERTION_MASK,
13009                                           1);
13010 }
13011
13012 static void
13013 cmd_config_e_tag_insertion_dis_parsed(
13014         void *parsed_result,
13015         __rte_unused struct cmdline *cl,
13016         __rte_unused void *data)
13017 {
13018         struct cmd_config_e_tag_result *res =
13019                 parsed_result;
13020         struct rte_eth_l2_tunnel_conf entry;
13021
13022         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13023                 return;
13024
13025         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13026         entry.vf_id = res->vf_id;
13027
13028         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13029                                           &entry,
13030                                           ETH_L2_TUNNEL_INSERTION_MASK,
13031                                           0);
13032 }
13033
13034 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13035         .f = cmd_config_e_tag_insertion_en_parsed,
13036         .data = NULL,
13037         .help_str = "E-tag ... : E-tag insertion enable",
13038         .tokens = {
13039                 (void *)&cmd_config_e_tag_e_tag,
13040                 (void *)&cmd_config_e_tag_set,
13041                 (void *)&cmd_config_e_tag_insertion,
13042                 (void *)&cmd_config_e_tag_on,
13043                 (void *)&cmd_config_e_tag_port_tag_id,
13044                 (void *)&cmd_config_e_tag_port_tag_id_val,
13045                 (void *)&cmd_config_e_tag_port,
13046                 (void *)&cmd_config_e_tag_port_id,
13047                 (void *)&cmd_config_e_tag_vf,
13048                 (void *)&cmd_config_e_tag_vf_id,
13049                 NULL,
13050         },
13051 };
13052
13053 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13054         .f = cmd_config_e_tag_insertion_dis_parsed,
13055         .data = NULL,
13056         .help_str = "E-tag ... : E-tag insertion disable",
13057         .tokens = {
13058                 (void *)&cmd_config_e_tag_e_tag,
13059                 (void *)&cmd_config_e_tag_set,
13060                 (void *)&cmd_config_e_tag_insertion,
13061                 (void *)&cmd_config_e_tag_off,
13062                 (void *)&cmd_config_e_tag_port,
13063                 (void *)&cmd_config_e_tag_port_id,
13064                 (void *)&cmd_config_e_tag_vf,
13065                 (void *)&cmd_config_e_tag_vf_id,
13066                 NULL,
13067         },
13068 };
13069
13070 /* E-tag stripping configuration */
13071 static void
13072 cmd_config_e_tag_stripping_parsed(
13073         void *parsed_result,
13074         __rte_unused struct cmdline *cl,
13075         __rte_unused void *data)
13076 {
13077         struct cmd_config_e_tag_result *res =
13078                 parsed_result;
13079         struct rte_eth_l2_tunnel_conf entry;
13080
13081         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13082                 return;
13083
13084         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13085
13086         if (!strcmp(res->on_off, "on"))
13087                 rte_eth_dev_l2_tunnel_offload_set
13088                         (res->port_id,
13089                          &entry,
13090                          ETH_L2_TUNNEL_STRIPPING_MASK,
13091                          1);
13092         else
13093                 rte_eth_dev_l2_tunnel_offload_set
13094                         (res->port_id,
13095                          &entry,
13096                          ETH_L2_TUNNEL_STRIPPING_MASK,
13097                          0);
13098 }
13099
13100 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13101         .f = cmd_config_e_tag_stripping_parsed,
13102         .data = NULL,
13103         .help_str = "E-tag ... : E-tag stripping enable/disable",
13104         .tokens = {
13105                 (void *)&cmd_config_e_tag_e_tag,
13106                 (void *)&cmd_config_e_tag_set,
13107                 (void *)&cmd_config_e_tag_stripping,
13108                 (void *)&cmd_config_e_tag_on_off,
13109                 (void *)&cmd_config_e_tag_port,
13110                 (void *)&cmd_config_e_tag_port_id,
13111                 NULL,
13112         },
13113 };
13114
13115 /* E-tag forwarding configuration */
13116 static void
13117 cmd_config_e_tag_forwarding_parsed(
13118         void *parsed_result,
13119         __rte_unused struct cmdline *cl,
13120         __rte_unused void *data)
13121 {
13122         struct cmd_config_e_tag_result *res = parsed_result;
13123         struct rte_eth_l2_tunnel_conf entry;
13124
13125         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13126                 return;
13127
13128         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13129
13130         if (!strcmp(res->on_off, "on"))
13131                 rte_eth_dev_l2_tunnel_offload_set
13132                         (res->port_id,
13133                          &entry,
13134                          ETH_L2_TUNNEL_FORWARDING_MASK,
13135                          1);
13136         else
13137                 rte_eth_dev_l2_tunnel_offload_set
13138                         (res->port_id,
13139                          &entry,
13140                          ETH_L2_TUNNEL_FORWARDING_MASK,
13141                          0);
13142 }
13143
13144 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13145         .f = cmd_config_e_tag_forwarding_parsed,
13146         .data = NULL,
13147         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13148         .tokens = {
13149                 (void *)&cmd_config_e_tag_e_tag,
13150                 (void *)&cmd_config_e_tag_set,
13151                 (void *)&cmd_config_e_tag_forwarding,
13152                 (void *)&cmd_config_e_tag_on_off,
13153                 (void *)&cmd_config_e_tag_port,
13154                 (void *)&cmd_config_e_tag_port_id,
13155                 NULL,
13156         },
13157 };
13158
13159 /* E-tag filter configuration */
13160 static void
13161 cmd_config_e_tag_filter_add_parsed(
13162         void *parsed_result,
13163         __rte_unused struct cmdline *cl,
13164         __rte_unused void *data)
13165 {
13166         struct cmd_config_e_tag_result *res = parsed_result;
13167         struct rte_eth_l2_tunnel_conf entry;
13168         int ret = 0;
13169
13170         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13171                 return;
13172
13173         if (res->e_tag_id_val > 0x3fff) {
13174                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13175                 return;
13176         }
13177
13178         ret = rte_eth_dev_filter_supported(res->port_id,
13179                                            RTE_ETH_FILTER_L2_TUNNEL);
13180         if (ret < 0) {
13181                 printf("E-tag filter is not supported on port %u.\n",
13182                        res->port_id);
13183                 return;
13184         }
13185
13186         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13187         entry.tunnel_id = res->e_tag_id_val;
13188         entry.pool = res->dst_pool_val;
13189
13190         ret = rte_eth_dev_filter_ctrl(res->port_id,
13191                                       RTE_ETH_FILTER_L2_TUNNEL,
13192                                       RTE_ETH_FILTER_ADD,
13193                                       &entry);
13194         if (ret < 0)
13195                 printf("E-tag filter programming error: (%s)\n",
13196                        strerror(-ret));
13197 }
13198
13199 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13200         .f = cmd_config_e_tag_filter_add_parsed,
13201         .data = NULL,
13202         .help_str = "E-tag ... : E-tag filter add",
13203         .tokens = {
13204                 (void *)&cmd_config_e_tag_e_tag,
13205                 (void *)&cmd_config_e_tag_set,
13206                 (void *)&cmd_config_e_tag_filter,
13207                 (void *)&cmd_config_e_tag_add,
13208                 (void *)&cmd_config_e_tag_e_tag_id,
13209                 (void *)&cmd_config_e_tag_e_tag_id_val,
13210                 (void *)&cmd_config_e_tag_dst_pool,
13211                 (void *)&cmd_config_e_tag_dst_pool_val,
13212                 (void *)&cmd_config_e_tag_port,
13213                 (void *)&cmd_config_e_tag_port_id,
13214                 NULL,
13215         },
13216 };
13217
13218 static void
13219 cmd_config_e_tag_filter_del_parsed(
13220         void *parsed_result,
13221         __rte_unused struct cmdline *cl,
13222         __rte_unused void *data)
13223 {
13224         struct cmd_config_e_tag_result *res = parsed_result;
13225         struct rte_eth_l2_tunnel_conf entry;
13226         int ret = 0;
13227
13228         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13229                 return;
13230
13231         if (res->e_tag_id_val > 0x3fff) {
13232                 printf("e-tag-id must be less than 0x3fff.\n");
13233                 return;
13234         }
13235
13236         ret = rte_eth_dev_filter_supported(res->port_id,
13237                                            RTE_ETH_FILTER_L2_TUNNEL);
13238         if (ret < 0) {
13239                 printf("E-tag filter is not supported on port %u.\n",
13240                        res->port_id);
13241                 return;
13242         }
13243
13244         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13245         entry.tunnel_id = res->e_tag_id_val;
13246
13247         ret = rte_eth_dev_filter_ctrl(res->port_id,
13248                                       RTE_ETH_FILTER_L2_TUNNEL,
13249                                       RTE_ETH_FILTER_DELETE,
13250                                       &entry);
13251         if (ret < 0)
13252                 printf("E-tag filter programming error: (%s)\n",
13253                        strerror(-ret));
13254 }
13255
13256 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13257         .f = cmd_config_e_tag_filter_del_parsed,
13258         .data = NULL,
13259         .help_str = "E-tag ... : E-tag filter delete",
13260         .tokens = {
13261                 (void *)&cmd_config_e_tag_e_tag,
13262                 (void *)&cmd_config_e_tag_set,
13263                 (void *)&cmd_config_e_tag_filter,
13264                 (void *)&cmd_config_e_tag_del,
13265                 (void *)&cmd_config_e_tag_e_tag_id,
13266                 (void *)&cmd_config_e_tag_e_tag_id_val,
13267                 (void *)&cmd_config_e_tag_port,
13268                 (void *)&cmd_config_e_tag_port_id,
13269                 NULL,
13270         },
13271 };
13272
13273 /* vf vlan anti spoof configuration */
13274
13275 /* Common result structure for vf vlan anti spoof */
13276 struct cmd_vf_vlan_anti_spoof_result {
13277         cmdline_fixed_string_t set;
13278         cmdline_fixed_string_t vf;
13279         cmdline_fixed_string_t vlan;
13280         cmdline_fixed_string_t antispoof;
13281         portid_t port_id;
13282         uint32_t vf_id;
13283         cmdline_fixed_string_t on_off;
13284 };
13285
13286 /* Common CLI fields for vf vlan anti spoof enable disable */
13287 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13288         TOKEN_STRING_INITIALIZER
13289                 (struct cmd_vf_vlan_anti_spoof_result,
13290                  set, "set");
13291 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13292         TOKEN_STRING_INITIALIZER
13293                 (struct cmd_vf_vlan_anti_spoof_result,
13294                  vf, "vf");
13295 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13296         TOKEN_STRING_INITIALIZER
13297                 (struct cmd_vf_vlan_anti_spoof_result,
13298                  vlan, "vlan");
13299 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13300         TOKEN_STRING_INITIALIZER
13301                 (struct cmd_vf_vlan_anti_spoof_result,
13302                  antispoof, "antispoof");
13303 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13304         TOKEN_NUM_INITIALIZER
13305                 (struct cmd_vf_vlan_anti_spoof_result,
13306                  port_id, UINT16);
13307 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13308         TOKEN_NUM_INITIALIZER
13309                 (struct cmd_vf_vlan_anti_spoof_result,
13310                  vf_id, UINT32);
13311 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13312         TOKEN_STRING_INITIALIZER
13313                 (struct cmd_vf_vlan_anti_spoof_result,
13314                  on_off, "on#off");
13315
13316 static void
13317 cmd_set_vf_vlan_anti_spoof_parsed(
13318         void *parsed_result,
13319         __rte_unused struct cmdline *cl,
13320         __rte_unused void *data)
13321 {
13322         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13323         int ret = -ENOTSUP;
13324
13325         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13326
13327         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13328                 return;
13329
13330 #ifdef RTE_NET_IXGBE
13331         if (ret == -ENOTSUP)
13332                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13333                                 res->vf_id, is_on);
13334 #endif
13335 #ifdef RTE_NET_I40E
13336         if (ret == -ENOTSUP)
13337                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13338                                 res->vf_id, is_on);
13339 #endif
13340 #ifdef RTE_NET_BNXT
13341         if (ret == -ENOTSUP)
13342                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13343                                 res->vf_id, is_on);
13344 #endif
13345
13346         switch (ret) {
13347         case 0:
13348                 break;
13349         case -EINVAL:
13350                 printf("invalid vf_id %d\n", res->vf_id);
13351                 break;
13352         case -ENODEV:
13353                 printf("invalid port_id %d\n", res->port_id);
13354                 break;
13355         case -ENOTSUP:
13356                 printf("function not implemented\n");
13357                 break;
13358         default:
13359                 printf("programming error: (%s)\n", strerror(-ret));
13360         }
13361 }
13362
13363 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13364         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13365         .data = NULL,
13366         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13367         .tokens = {
13368                 (void *)&cmd_vf_vlan_anti_spoof_set,
13369                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13370                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13371                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13372                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13373                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13374                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13375                 NULL,
13376         },
13377 };
13378
13379 /* vf mac anti spoof configuration */
13380
13381 /* Common result structure for vf mac anti spoof */
13382 struct cmd_vf_mac_anti_spoof_result {
13383         cmdline_fixed_string_t set;
13384         cmdline_fixed_string_t vf;
13385         cmdline_fixed_string_t mac;
13386         cmdline_fixed_string_t antispoof;
13387         portid_t port_id;
13388         uint32_t vf_id;
13389         cmdline_fixed_string_t on_off;
13390 };
13391
13392 /* Common CLI fields for vf mac anti spoof enable disable */
13393 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13394         TOKEN_STRING_INITIALIZER
13395                 (struct cmd_vf_mac_anti_spoof_result,
13396                  set, "set");
13397 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13398         TOKEN_STRING_INITIALIZER
13399                 (struct cmd_vf_mac_anti_spoof_result,
13400                  vf, "vf");
13401 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13402         TOKEN_STRING_INITIALIZER
13403                 (struct cmd_vf_mac_anti_spoof_result,
13404                  mac, "mac");
13405 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13406         TOKEN_STRING_INITIALIZER
13407                 (struct cmd_vf_mac_anti_spoof_result,
13408                  antispoof, "antispoof");
13409 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13410         TOKEN_NUM_INITIALIZER
13411                 (struct cmd_vf_mac_anti_spoof_result,
13412                  port_id, UINT16);
13413 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13414         TOKEN_NUM_INITIALIZER
13415                 (struct cmd_vf_mac_anti_spoof_result,
13416                  vf_id, UINT32);
13417 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13418         TOKEN_STRING_INITIALIZER
13419                 (struct cmd_vf_mac_anti_spoof_result,
13420                  on_off, "on#off");
13421
13422 static void
13423 cmd_set_vf_mac_anti_spoof_parsed(
13424         void *parsed_result,
13425         __rte_unused struct cmdline *cl,
13426         __rte_unused void *data)
13427 {
13428         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13429         int ret = -ENOTSUP;
13430
13431         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13432
13433         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13434                 return;
13435
13436 #ifdef RTE_NET_IXGBE
13437         if (ret == -ENOTSUP)
13438                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13439                         res->vf_id, is_on);
13440 #endif
13441 #ifdef RTE_NET_I40E
13442         if (ret == -ENOTSUP)
13443                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13444                         res->vf_id, is_on);
13445 #endif
13446 #ifdef RTE_NET_BNXT
13447         if (ret == -ENOTSUP)
13448                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13449                         res->vf_id, is_on);
13450 #endif
13451
13452         switch (ret) {
13453         case 0:
13454                 break;
13455         case -EINVAL:
13456                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13457                 break;
13458         case -ENODEV:
13459                 printf("invalid port_id %d\n", res->port_id);
13460                 break;
13461         case -ENOTSUP:
13462                 printf("function not implemented\n");
13463                 break;
13464         default:
13465                 printf("programming error: (%s)\n", strerror(-ret));
13466         }
13467 }
13468
13469 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13470         .f = cmd_set_vf_mac_anti_spoof_parsed,
13471         .data = NULL,
13472         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13473         .tokens = {
13474                 (void *)&cmd_vf_mac_anti_spoof_set,
13475                 (void *)&cmd_vf_mac_anti_spoof_vf,
13476                 (void *)&cmd_vf_mac_anti_spoof_mac,
13477                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13478                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13479                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13480                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13481                 NULL,
13482         },
13483 };
13484
13485 /* vf vlan strip queue configuration */
13486
13487 /* Common result structure for vf mac anti spoof */
13488 struct cmd_vf_vlan_stripq_result {
13489         cmdline_fixed_string_t set;
13490         cmdline_fixed_string_t vf;
13491         cmdline_fixed_string_t vlan;
13492         cmdline_fixed_string_t stripq;
13493         portid_t port_id;
13494         uint16_t vf_id;
13495         cmdline_fixed_string_t on_off;
13496 };
13497
13498 /* Common CLI fields for vf vlan strip enable disable */
13499 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13500         TOKEN_STRING_INITIALIZER
13501                 (struct cmd_vf_vlan_stripq_result,
13502                  set, "set");
13503 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13504         TOKEN_STRING_INITIALIZER
13505                 (struct cmd_vf_vlan_stripq_result,
13506                  vf, "vf");
13507 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13508         TOKEN_STRING_INITIALIZER
13509                 (struct cmd_vf_vlan_stripq_result,
13510                  vlan, "vlan");
13511 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13512         TOKEN_STRING_INITIALIZER
13513                 (struct cmd_vf_vlan_stripq_result,
13514                  stripq, "stripq");
13515 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13516         TOKEN_NUM_INITIALIZER
13517                 (struct cmd_vf_vlan_stripq_result,
13518                  port_id, UINT16);
13519 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13520         TOKEN_NUM_INITIALIZER
13521                 (struct cmd_vf_vlan_stripq_result,
13522                  vf_id, UINT16);
13523 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13524         TOKEN_STRING_INITIALIZER
13525                 (struct cmd_vf_vlan_stripq_result,
13526                  on_off, "on#off");
13527
13528 static void
13529 cmd_set_vf_vlan_stripq_parsed(
13530         void *parsed_result,
13531         __rte_unused struct cmdline *cl,
13532         __rte_unused void *data)
13533 {
13534         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13535         int ret = -ENOTSUP;
13536
13537         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13538
13539         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13540                 return;
13541
13542 #ifdef RTE_NET_IXGBE
13543         if (ret == -ENOTSUP)
13544                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13545                         res->vf_id, is_on);
13546 #endif
13547 #ifdef RTE_NET_I40E
13548         if (ret == -ENOTSUP)
13549                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13550                         res->vf_id, is_on);
13551 #endif
13552 #ifdef RTE_NET_BNXT
13553         if (ret == -ENOTSUP)
13554                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13555                         res->vf_id, is_on);
13556 #endif
13557
13558         switch (ret) {
13559         case 0:
13560                 break;
13561         case -EINVAL:
13562                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13563                 break;
13564         case -ENODEV:
13565                 printf("invalid port_id %d\n", res->port_id);
13566                 break;
13567         case -ENOTSUP:
13568                 printf("function not implemented\n");
13569                 break;
13570         default:
13571                 printf("programming error: (%s)\n", strerror(-ret));
13572         }
13573 }
13574
13575 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13576         .f = cmd_set_vf_vlan_stripq_parsed,
13577         .data = NULL,
13578         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13579         .tokens = {
13580                 (void *)&cmd_vf_vlan_stripq_set,
13581                 (void *)&cmd_vf_vlan_stripq_vf,
13582                 (void *)&cmd_vf_vlan_stripq_vlan,
13583                 (void *)&cmd_vf_vlan_stripq_stripq,
13584                 (void *)&cmd_vf_vlan_stripq_port_id,
13585                 (void *)&cmd_vf_vlan_stripq_vf_id,
13586                 (void *)&cmd_vf_vlan_stripq_on_off,
13587                 NULL,
13588         },
13589 };
13590
13591 /* vf vlan insert configuration */
13592
13593 /* Common result structure for vf vlan insert */
13594 struct cmd_vf_vlan_insert_result {
13595         cmdline_fixed_string_t set;
13596         cmdline_fixed_string_t vf;
13597         cmdline_fixed_string_t vlan;
13598         cmdline_fixed_string_t insert;
13599         portid_t port_id;
13600         uint16_t vf_id;
13601         uint16_t vlan_id;
13602 };
13603
13604 /* Common CLI fields for vf vlan insert enable disable */
13605 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13606         TOKEN_STRING_INITIALIZER
13607                 (struct cmd_vf_vlan_insert_result,
13608                  set, "set");
13609 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13610         TOKEN_STRING_INITIALIZER
13611                 (struct cmd_vf_vlan_insert_result,
13612                  vf, "vf");
13613 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13614         TOKEN_STRING_INITIALIZER
13615                 (struct cmd_vf_vlan_insert_result,
13616                  vlan, "vlan");
13617 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13618         TOKEN_STRING_INITIALIZER
13619                 (struct cmd_vf_vlan_insert_result,
13620                  insert, "insert");
13621 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13622         TOKEN_NUM_INITIALIZER
13623                 (struct cmd_vf_vlan_insert_result,
13624                  port_id, UINT16);
13625 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13626         TOKEN_NUM_INITIALIZER
13627                 (struct cmd_vf_vlan_insert_result,
13628                  vf_id, UINT16);
13629 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13630         TOKEN_NUM_INITIALIZER
13631                 (struct cmd_vf_vlan_insert_result,
13632                  vlan_id, UINT16);
13633
13634 static void
13635 cmd_set_vf_vlan_insert_parsed(
13636         void *parsed_result,
13637         __rte_unused struct cmdline *cl,
13638         __rte_unused void *data)
13639 {
13640         struct cmd_vf_vlan_insert_result *res = parsed_result;
13641         int ret = -ENOTSUP;
13642
13643         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13644                 return;
13645
13646 #ifdef RTE_NET_IXGBE
13647         if (ret == -ENOTSUP)
13648                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13649                         res->vlan_id);
13650 #endif
13651 #ifdef RTE_NET_I40E
13652         if (ret == -ENOTSUP)
13653                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13654                         res->vlan_id);
13655 #endif
13656 #ifdef RTE_NET_BNXT
13657         if (ret == -ENOTSUP)
13658                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13659                         res->vlan_id);
13660 #endif
13661
13662         switch (ret) {
13663         case 0:
13664                 break;
13665         case -EINVAL:
13666                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13667                 break;
13668         case -ENODEV:
13669                 printf("invalid port_id %d\n", res->port_id);
13670                 break;
13671         case -ENOTSUP:
13672                 printf("function not implemented\n");
13673                 break;
13674         default:
13675                 printf("programming error: (%s)\n", strerror(-ret));
13676         }
13677 }
13678
13679 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13680         .f = cmd_set_vf_vlan_insert_parsed,
13681         .data = NULL,
13682         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13683         .tokens = {
13684                 (void *)&cmd_vf_vlan_insert_set,
13685                 (void *)&cmd_vf_vlan_insert_vf,
13686                 (void *)&cmd_vf_vlan_insert_vlan,
13687                 (void *)&cmd_vf_vlan_insert_insert,
13688                 (void *)&cmd_vf_vlan_insert_port_id,
13689                 (void *)&cmd_vf_vlan_insert_vf_id,
13690                 (void *)&cmd_vf_vlan_insert_vlan_id,
13691                 NULL,
13692         },
13693 };
13694
13695 /* tx loopback configuration */
13696
13697 /* Common result structure for tx loopback */
13698 struct cmd_tx_loopback_result {
13699         cmdline_fixed_string_t set;
13700         cmdline_fixed_string_t tx;
13701         cmdline_fixed_string_t loopback;
13702         portid_t port_id;
13703         cmdline_fixed_string_t on_off;
13704 };
13705
13706 /* Common CLI fields for tx loopback enable disable */
13707 cmdline_parse_token_string_t cmd_tx_loopback_set =
13708         TOKEN_STRING_INITIALIZER
13709                 (struct cmd_tx_loopback_result,
13710                  set, "set");
13711 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13712         TOKEN_STRING_INITIALIZER
13713                 (struct cmd_tx_loopback_result,
13714                  tx, "tx");
13715 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13716         TOKEN_STRING_INITIALIZER
13717                 (struct cmd_tx_loopback_result,
13718                  loopback, "loopback");
13719 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13720         TOKEN_NUM_INITIALIZER
13721                 (struct cmd_tx_loopback_result,
13722                  port_id, UINT16);
13723 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13724         TOKEN_STRING_INITIALIZER
13725                 (struct cmd_tx_loopback_result,
13726                  on_off, "on#off");
13727
13728 static void
13729 cmd_set_tx_loopback_parsed(
13730         void *parsed_result,
13731         __rte_unused struct cmdline *cl,
13732         __rte_unused void *data)
13733 {
13734         struct cmd_tx_loopback_result *res = parsed_result;
13735         int ret = -ENOTSUP;
13736
13737         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13738
13739         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13740                 return;
13741
13742 #ifdef RTE_NET_IXGBE
13743         if (ret == -ENOTSUP)
13744                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13745 #endif
13746 #ifdef RTE_NET_I40E
13747         if (ret == -ENOTSUP)
13748                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13749 #endif
13750 #ifdef RTE_NET_BNXT
13751         if (ret == -ENOTSUP)
13752                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13753 #endif
13754 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
13755         if (ret == -ENOTSUP)
13756                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13757 #endif
13758
13759         switch (ret) {
13760         case 0:
13761                 break;
13762         case -EINVAL:
13763                 printf("invalid is_on %d\n", is_on);
13764                 break;
13765         case -ENODEV:
13766                 printf("invalid port_id %d\n", res->port_id);
13767                 break;
13768         case -ENOTSUP:
13769                 printf("function not implemented\n");
13770                 break;
13771         default:
13772                 printf("programming error: (%s)\n", strerror(-ret));
13773         }
13774 }
13775
13776 cmdline_parse_inst_t cmd_set_tx_loopback = {
13777         .f = cmd_set_tx_loopback_parsed,
13778         .data = NULL,
13779         .help_str = "set tx loopback <port_id> on|off",
13780         .tokens = {
13781                 (void *)&cmd_tx_loopback_set,
13782                 (void *)&cmd_tx_loopback_tx,
13783                 (void *)&cmd_tx_loopback_loopback,
13784                 (void *)&cmd_tx_loopback_port_id,
13785                 (void *)&cmd_tx_loopback_on_off,
13786                 NULL,
13787         },
13788 };
13789
13790 /* all queues drop enable configuration */
13791
13792 /* Common result structure for all queues drop enable */
13793 struct cmd_all_queues_drop_en_result {
13794         cmdline_fixed_string_t set;
13795         cmdline_fixed_string_t all;
13796         cmdline_fixed_string_t queues;
13797         cmdline_fixed_string_t drop;
13798         portid_t port_id;
13799         cmdline_fixed_string_t on_off;
13800 };
13801
13802 /* Common CLI fields for tx loopback enable disable */
13803 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13804         TOKEN_STRING_INITIALIZER
13805                 (struct cmd_all_queues_drop_en_result,
13806                  set, "set");
13807 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13808         TOKEN_STRING_INITIALIZER
13809                 (struct cmd_all_queues_drop_en_result,
13810                  all, "all");
13811 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13812         TOKEN_STRING_INITIALIZER
13813                 (struct cmd_all_queues_drop_en_result,
13814                  queues, "queues");
13815 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13816         TOKEN_STRING_INITIALIZER
13817                 (struct cmd_all_queues_drop_en_result,
13818                  drop, "drop");
13819 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13820         TOKEN_NUM_INITIALIZER
13821                 (struct cmd_all_queues_drop_en_result,
13822                  port_id, UINT16);
13823 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13824         TOKEN_STRING_INITIALIZER
13825                 (struct cmd_all_queues_drop_en_result,
13826                  on_off, "on#off");
13827
13828 static void
13829 cmd_set_all_queues_drop_en_parsed(
13830         void *parsed_result,
13831         __rte_unused struct cmdline *cl,
13832         __rte_unused void *data)
13833 {
13834         struct cmd_all_queues_drop_en_result *res = parsed_result;
13835         int ret = -ENOTSUP;
13836         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13837
13838         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13839                 return;
13840
13841 #ifdef RTE_NET_IXGBE
13842         if (ret == -ENOTSUP)
13843                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13844 #endif
13845 #ifdef RTE_NET_BNXT
13846         if (ret == -ENOTSUP)
13847                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13848 #endif
13849         switch (ret) {
13850         case 0:
13851                 break;
13852         case -EINVAL:
13853                 printf("invalid is_on %d\n", is_on);
13854                 break;
13855         case -ENODEV:
13856                 printf("invalid port_id %d\n", res->port_id);
13857                 break;
13858         case -ENOTSUP:
13859                 printf("function not implemented\n");
13860                 break;
13861         default:
13862                 printf("programming error: (%s)\n", strerror(-ret));
13863         }
13864 }
13865
13866 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13867         .f = cmd_set_all_queues_drop_en_parsed,
13868         .data = NULL,
13869         .help_str = "set all queues drop <port_id> on|off",
13870         .tokens = {
13871                 (void *)&cmd_all_queues_drop_en_set,
13872                 (void *)&cmd_all_queues_drop_en_all,
13873                 (void *)&cmd_all_queues_drop_en_queues,
13874                 (void *)&cmd_all_queues_drop_en_drop,
13875                 (void *)&cmd_all_queues_drop_en_port_id,
13876                 (void *)&cmd_all_queues_drop_en_on_off,
13877                 NULL,
13878         },
13879 };
13880
13881 /* vf split drop enable configuration */
13882
13883 /* Common result structure for vf split drop enable */
13884 struct cmd_vf_split_drop_en_result {
13885         cmdline_fixed_string_t set;
13886         cmdline_fixed_string_t vf;
13887         cmdline_fixed_string_t split;
13888         cmdline_fixed_string_t drop;
13889         portid_t port_id;
13890         uint16_t vf_id;
13891         cmdline_fixed_string_t on_off;
13892 };
13893
13894 /* Common CLI fields for vf split drop enable disable */
13895 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13896         TOKEN_STRING_INITIALIZER
13897                 (struct cmd_vf_split_drop_en_result,
13898                  set, "set");
13899 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13900         TOKEN_STRING_INITIALIZER
13901                 (struct cmd_vf_split_drop_en_result,
13902                  vf, "vf");
13903 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13904         TOKEN_STRING_INITIALIZER
13905                 (struct cmd_vf_split_drop_en_result,
13906                  split, "split");
13907 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
13908         TOKEN_STRING_INITIALIZER
13909                 (struct cmd_vf_split_drop_en_result,
13910                  drop, "drop");
13911 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
13912         TOKEN_NUM_INITIALIZER
13913                 (struct cmd_vf_split_drop_en_result,
13914                  port_id, UINT16);
13915 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
13916         TOKEN_NUM_INITIALIZER
13917                 (struct cmd_vf_split_drop_en_result,
13918                  vf_id, UINT16);
13919 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
13920         TOKEN_STRING_INITIALIZER
13921                 (struct cmd_vf_split_drop_en_result,
13922                  on_off, "on#off");
13923
13924 static void
13925 cmd_set_vf_split_drop_en_parsed(
13926         void *parsed_result,
13927         __rte_unused struct cmdline *cl,
13928         __rte_unused void *data)
13929 {
13930         struct cmd_vf_split_drop_en_result *res = parsed_result;
13931         int ret = -ENOTSUP;
13932         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13933
13934         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13935                 return;
13936
13937 #ifdef RTE_NET_IXGBE
13938         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
13939                         is_on);
13940 #endif
13941         switch (ret) {
13942         case 0:
13943                 break;
13944         case -EINVAL:
13945                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13946                 break;
13947         case -ENODEV:
13948                 printf("invalid port_id %d\n", res->port_id);
13949                 break;
13950         case -ENOTSUP:
13951                 printf("not supported on port %d\n", res->port_id);
13952                 break;
13953         default:
13954                 printf("programming error: (%s)\n", strerror(-ret));
13955         }
13956 }
13957
13958 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13959         .f = cmd_set_vf_split_drop_en_parsed,
13960         .data = NULL,
13961         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13962         .tokens = {
13963                 (void *)&cmd_vf_split_drop_en_set,
13964                 (void *)&cmd_vf_split_drop_en_vf,
13965                 (void *)&cmd_vf_split_drop_en_split,
13966                 (void *)&cmd_vf_split_drop_en_drop,
13967                 (void *)&cmd_vf_split_drop_en_port_id,
13968                 (void *)&cmd_vf_split_drop_en_vf_id,
13969                 (void *)&cmd_vf_split_drop_en_on_off,
13970                 NULL,
13971         },
13972 };
13973
13974 /* vf mac address configuration */
13975
13976 /* Common result structure for vf mac address */
13977 struct cmd_set_vf_mac_addr_result {
13978         cmdline_fixed_string_t set;
13979         cmdline_fixed_string_t vf;
13980         cmdline_fixed_string_t mac;
13981         cmdline_fixed_string_t addr;
13982         portid_t port_id;
13983         uint16_t vf_id;
13984         struct rte_ether_addr mac_addr;
13985
13986 };
13987
13988 /* Common CLI fields for vf split drop enable disable */
13989 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13990         TOKEN_STRING_INITIALIZER
13991                 (struct cmd_set_vf_mac_addr_result,
13992                  set, "set");
13993 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13994         TOKEN_STRING_INITIALIZER
13995                 (struct cmd_set_vf_mac_addr_result,
13996                  vf, "vf");
13997 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13998         TOKEN_STRING_INITIALIZER
13999                 (struct cmd_set_vf_mac_addr_result,
14000                  mac, "mac");
14001 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14002         TOKEN_STRING_INITIALIZER
14003                 (struct cmd_set_vf_mac_addr_result,
14004                  addr, "addr");
14005 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14006         TOKEN_NUM_INITIALIZER
14007                 (struct cmd_set_vf_mac_addr_result,
14008                  port_id, UINT16);
14009 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14010         TOKEN_NUM_INITIALIZER
14011                 (struct cmd_set_vf_mac_addr_result,
14012                  vf_id, UINT16);
14013 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14014         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14015                  mac_addr);
14016
14017 static void
14018 cmd_set_vf_mac_addr_parsed(
14019         void *parsed_result,
14020         __rte_unused struct cmdline *cl,
14021         __rte_unused void *data)
14022 {
14023         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14024         int ret = -ENOTSUP;
14025
14026         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14027                 return;
14028
14029 #ifdef RTE_NET_IXGBE
14030         if (ret == -ENOTSUP)
14031                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14032                                 &res->mac_addr);
14033 #endif
14034 #ifdef RTE_NET_I40E
14035         if (ret == -ENOTSUP)
14036                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14037                                 &res->mac_addr);
14038 #endif
14039 #ifdef RTE_NET_BNXT
14040         if (ret == -ENOTSUP)
14041                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14042                                 &res->mac_addr);
14043 #endif
14044
14045         switch (ret) {
14046         case 0:
14047                 break;
14048         case -EINVAL:
14049                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14050                 break;
14051         case -ENODEV:
14052                 printf("invalid port_id %d\n", res->port_id);
14053                 break;
14054         case -ENOTSUP:
14055                 printf("function not implemented\n");
14056                 break;
14057         default:
14058                 printf("programming error: (%s)\n", strerror(-ret));
14059         }
14060 }
14061
14062 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14063         .f = cmd_set_vf_mac_addr_parsed,
14064         .data = NULL,
14065         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14066         .tokens = {
14067                 (void *)&cmd_set_vf_mac_addr_set,
14068                 (void *)&cmd_set_vf_mac_addr_vf,
14069                 (void *)&cmd_set_vf_mac_addr_mac,
14070                 (void *)&cmd_set_vf_mac_addr_addr,
14071                 (void *)&cmd_set_vf_mac_addr_port_id,
14072                 (void *)&cmd_set_vf_mac_addr_vf_id,
14073                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14074                 NULL,
14075         },
14076 };
14077
14078 /* MACsec configuration */
14079
14080 /* Common result structure for MACsec offload enable */
14081 struct cmd_macsec_offload_on_result {
14082         cmdline_fixed_string_t set;
14083         cmdline_fixed_string_t macsec;
14084         cmdline_fixed_string_t offload;
14085         portid_t port_id;
14086         cmdline_fixed_string_t on;
14087         cmdline_fixed_string_t encrypt;
14088         cmdline_fixed_string_t en_on_off;
14089         cmdline_fixed_string_t replay_protect;
14090         cmdline_fixed_string_t rp_on_off;
14091 };
14092
14093 /* Common CLI fields for MACsec offload disable */
14094 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14095         TOKEN_STRING_INITIALIZER
14096                 (struct cmd_macsec_offload_on_result,
14097                  set, "set");
14098 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14099         TOKEN_STRING_INITIALIZER
14100                 (struct cmd_macsec_offload_on_result,
14101                  macsec, "macsec");
14102 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14103         TOKEN_STRING_INITIALIZER
14104                 (struct cmd_macsec_offload_on_result,
14105                  offload, "offload");
14106 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14107         TOKEN_NUM_INITIALIZER
14108                 (struct cmd_macsec_offload_on_result,
14109                  port_id, UINT16);
14110 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14111         TOKEN_STRING_INITIALIZER
14112                 (struct cmd_macsec_offload_on_result,
14113                  on, "on");
14114 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14115         TOKEN_STRING_INITIALIZER
14116                 (struct cmd_macsec_offload_on_result,
14117                  encrypt, "encrypt");
14118 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14119         TOKEN_STRING_INITIALIZER
14120                 (struct cmd_macsec_offload_on_result,
14121                  en_on_off, "on#off");
14122 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14123         TOKEN_STRING_INITIALIZER
14124                 (struct cmd_macsec_offload_on_result,
14125                  replay_protect, "replay-protect");
14126 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14127         TOKEN_STRING_INITIALIZER
14128                 (struct cmd_macsec_offload_on_result,
14129                  rp_on_off, "on#off");
14130
14131 static void
14132 cmd_set_macsec_offload_on_parsed(
14133         void *parsed_result,
14134         __rte_unused struct cmdline *cl,
14135         __rte_unused void *data)
14136 {
14137         struct cmd_macsec_offload_on_result *res = parsed_result;
14138         int ret = -ENOTSUP;
14139         portid_t port_id = res->port_id;
14140         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14141         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14142         struct rte_eth_dev_info dev_info;
14143
14144         if (port_id_is_invalid(port_id, ENABLED_WARN))
14145                 return;
14146         if (!port_is_stopped(port_id)) {
14147                 printf("Please stop port %d first\n", port_id);
14148                 return;
14149         }
14150
14151         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14152         if (ret != 0)
14153                 return;
14154
14155         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14156 #ifdef RTE_NET_IXGBE
14157                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14158 #endif
14159         }
14160         RTE_SET_USED(en);
14161         RTE_SET_USED(rp);
14162
14163         switch (ret) {
14164         case 0:
14165                 ports[port_id].dev_conf.txmode.offloads |=
14166                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14167                 cmd_reconfig_device_queue(port_id, 1, 1);
14168                 break;
14169         case -ENODEV:
14170                 printf("invalid port_id %d\n", port_id);
14171                 break;
14172         case -ENOTSUP:
14173                 printf("not supported on port %d\n", port_id);
14174                 break;
14175         default:
14176                 printf("programming error: (%s)\n", strerror(-ret));
14177         }
14178 }
14179
14180 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14181         .f = cmd_set_macsec_offload_on_parsed,
14182         .data = NULL,
14183         .help_str = "set macsec offload <port_id> on "
14184                 "encrypt on|off replay-protect on|off",
14185         .tokens = {
14186                 (void *)&cmd_macsec_offload_on_set,
14187                 (void *)&cmd_macsec_offload_on_macsec,
14188                 (void *)&cmd_macsec_offload_on_offload,
14189                 (void *)&cmd_macsec_offload_on_port_id,
14190                 (void *)&cmd_macsec_offload_on_on,
14191                 (void *)&cmd_macsec_offload_on_encrypt,
14192                 (void *)&cmd_macsec_offload_on_en_on_off,
14193                 (void *)&cmd_macsec_offload_on_replay_protect,
14194                 (void *)&cmd_macsec_offload_on_rp_on_off,
14195                 NULL,
14196         },
14197 };
14198
14199 /* Common result structure for MACsec offload disable */
14200 struct cmd_macsec_offload_off_result {
14201         cmdline_fixed_string_t set;
14202         cmdline_fixed_string_t macsec;
14203         cmdline_fixed_string_t offload;
14204         portid_t port_id;
14205         cmdline_fixed_string_t off;
14206 };
14207
14208 /* Common CLI fields for MACsec offload disable */
14209 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14210         TOKEN_STRING_INITIALIZER
14211                 (struct cmd_macsec_offload_off_result,
14212                  set, "set");
14213 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14214         TOKEN_STRING_INITIALIZER
14215                 (struct cmd_macsec_offload_off_result,
14216                  macsec, "macsec");
14217 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14218         TOKEN_STRING_INITIALIZER
14219                 (struct cmd_macsec_offload_off_result,
14220                  offload, "offload");
14221 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14222         TOKEN_NUM_INITIALIZER
14223                 (struct cmd_macsec_offload_off_result,
14224                  port_id, UINT16);
14225 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14226         TOKEN_STRING_INITIALIZER
14227                 (struct cmd_macsec_offload_off_result,
14228                  off, "off");
14229
14230 static void
14231 cmd_set_macsec_offload_off_parsed(
14232         void *parsed_result,
14233         __rte_unused struct cmdline *cl,
14234         __rte_unused void *data)
14235 {
14236         struct cmd_macsec_offload_off_result *res = parsed_result;
14237         int ret = -ENOTSUP;
14238         struct rte_eth_dev_info dev_info;
14239         portid_t port_id = res->port_id;
14240
14241         if (port_id_is_invalid(port_id, ENABLED_WARN))
14242                 return;
14243         if (!port_is_stopped(port_id)) {
14244                 printf("Please stop port %d first\n", port_id);
14245                 return;
14246         }
14247
14248         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14249         if (ret != 0)
14250                 return;
14251
14252         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14253 #ifdef RTE_NET_IXGBE
14254                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14255 #endif
14256         }
14257         switch (ret) {
14258         case 0:
14259                 ports[port_id].dev_conf.txmode.offloads &=
14260                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14261                 cmd_reconfig_device_queue(port_id, 1, 1);
14262                 break;
14263         case -ENODEV:
14264                 printf("invalid port_id %d\n", port_id);
14265                 break;
14266         case -ENOTSUP:
14267                 printf("not supported on port %d\n", port_id);
14268                 break;
14269         default:
14270                 printf("programming error: (%s)\n", strerror(-ret));
14271         }
14272 }
14273
14274 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14275         .f = cmd_set_macsec_offload_off_parsed,
14276         .data = NULL,
14277         .help_str = "set macsec offload <port_id> off",
14278         .tokens = {
14279                 (void *)&cmd_macsec_offload_off_set,
14280                 (void *)&cmd_macsec_offload_off_macsec,
14281                 (void *)&cmd_macsec_offload_off_offload,
14282                 (void *)&cmd_macsec_offload_off_port_id,
14283                 (void *)&cmd_macsec_offload_off_off,
14284                 NULL,
14285         },
14286 };
14287
14288 /* Common result structure for MACsec secure connection configure */
14289 struct cmd_macsec_sc_result {
14290         cmdline_fixed_string_t set;
14291         cmdline_fixed_string_t macsec;
14292         cmdline_fixed_string_t sc;
14293         cmdline_fixed_string_t tx_rx;
14294         portid_t port_id;
14295         struct rte_ether_addr mac;
14296         uint16_t pi;
14297 };
14298
14299 /* Common CLI fields for MACsec secure connection configure */
14300 cmdline_parse_token_string_t cmd_macsec_sc_set =
14301         TOKEN_STRING_INITIALIZER
14302                 (struct cmd_macsec_sc_result,
14303                  set, "set");
14304 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14305         TOKEN_STRING_INITIALIZER
14306                 (struct cmd_macsec_sc_result,
14307                  macsec, "macsec");
14308 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14309         TOKEN_STRING_INITIALIZER
14310                 (struct cmd_macsec_sc_result,
14311                  sc, "sc");
14312 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14313         TOKEN_STRING_INITIALIZER
14314                 (struct cmd_macsec_sc_result,
14315                  tx_rx, "tx#rx");
14316 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14317         TOKEN_NUM_INITIALIZER
14318                 (struct cmd_macsec_sc_result,
14319                  port_id, UINT16);
14320 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14321         TOKEN_ETHERADDR_INITIALIZER
14322                 (struct cmd_macsec_sc_result,
14323                  mac);
14324 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14325         TOKEN_NUM_INITIALIZER
14326                 (struct cmd_macsec_sc_result,
14327                  pi, UINT16);
14328
14329 static void
14330 cmd_set_macsec_sc_parsed(
14331         void *parsed_result,
14332         __rte_unused struct cmdline *cl,
14333         __rte_unused void *data)
14334 {
14335         struct cmd_macsec_sc_result *res = parsed_result;
14336         int ret = -ENOTSUP;
14337         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14338
14339 #ifdef RTE_NET_IXGBE
14340         ret = is_tx ?
14341                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14342                                 res->mac.addr_bytes) :
14343                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14344                                 res->mac.addr_bytes, res->pi);
14345 #endif
14346         RTE_SET_USED(is_tx);
14347
14348         switch (ret) {
14349         case 0:
14350                 break;
14351         case -ENODEV:
14352                 printf("invalid port_id %d\n", res->port_id);
14353                 break;
14354         case -ENOTSUP:
14355                 printf("not supported on port %d\n", res->port_id);
14356                 break;
14357         default:
14358                 printf("programming error: (%s)\n", strerror(-ret));
14359         }
14360 }
14361
14362 cmdline_parse_inst_t cmd_set_macsec_sc = {
14363         .f = cmd_set_macsec_sc_parsed,
14364         .data = NULL,
14365         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14366         .tokens = {
14367                 (void *)&cmd_macsec_sc_set,
14368                 (void *)&cmd_macsec_sc_macsec,
14369                 (void *)&cmd_macsec_sc_sc,
14370                 (void *)&cmd_macsec_sc_tx_rx,
14371                 (void *)&cmd_macsec_sc_port_id,
14372                 (void *)&cmd_macsec_sc_mac,
14373                 (void *)&cmd_macsec_sc_pi,
14374                 NULL,
14375         },
14376 };
14377
14378 /* Common result structure for MACsec secure connection configure */
14379 struct cmd_macsec_sa_result {
14380         cmdline_fixed_string_t set;
14381         cmdline_fixed_string_t macsec;
14382         cmdline_fixed_string_t sa;
14383         cmdline_fixed_string_t tx_rx;
14384         portid_t port_id;
14385         uint8_t idx;
14386         uint8_t an;
14387         uint32_t pn;
14388         cmdline_fixed_string_t key;
14389 };
14390
14391 /* Common CLI fields for MACsec secure connection configure */
14392 cmdline_parse_token_string_t cmd_macsec_sa_set =
14393         TOKEN_STRING_INITIALIZER
14394                 (struct cmd_macsec_sa_result,
14395                  set, "set");
14396 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14397         TOKEN_STRING_INITIALIZER
14398                 (struct cmd_macsec_sa_result,
14399                  macsec, "macsec");
14400 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14401         TOKEN_STRING_INITIALIZER
14402                 (struct cmd_macsec_sa_result,
14403                  sa, "sa");
14404 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14405         TOKEN_STRING_INITIALIZER
14406                 (struct cmd_macsec_sa_result,
14407                  tx_rx, "tx#rx");
14408 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14409         TOKEN_NUM_INITIALIZER
14410                 (struct cmd_macsec_sa_result,
14411                  port_id, UINT16);
14412 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14413         TOKEN_NUM_INITIALIZER
14414                 (struct cmd_macsec_sa_result,
14415                  idx, UINT8);
14416 cmdline_parse_token_num_t cmd_macsec_sa_an =
14417         TOKEN_NUM_INITIALIZER
14418                 (struct cmd_macsec_sa_result,
14419                  an, UINT8);
14420 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14421         TOKEN_NUM_INITIALIZER
14422                 (struct cmd_macsec_sa_result,
14423                  pn, UINT32);
14424 cmdline_parse_token_string_t cmd_macsec_sa_key =
14425         TOKEN_STRING_INITIALIZER
14426                 (struct cmd_macsec_sa_result,
14427                  key, NULL);
14428
14429 static void
14430 cmd_set_macsec_sa_parsed(
14431         void *parsed_result,
14432         __rte_unused struct cmdline *cl,
14433         __rte_unused void *data)
14434 {
14435         struct cmd_macsec_sa_result *res = parsed_result;
14436         int ret = -ENOTSUP;
14437         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14438         uint8_t key[16] = { 0 };
14439         uint8_t xdgt0;
14440         uint8_t xdgt1;
14441         int key_len;
14442         int i;
14443
14444         key_len = strlen(res->key) / 2;
14445         if (key_len > 16)
14446                 key_len = 16;
14447
14448         for (i = 0; i < key_len; i++) {
14449                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14450                 if (xdgt0 == 0xFF)
14451                         return;
14452                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14453                 if (xdgt1 == 0xFF)
14454                         return;
14455                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14456         }
14457
14458 #ifdef RTE_NET_IXGBE
14459         ret = is_tx ?
14460                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14461                         res->idx, res->an, res->pn, key) :
14462                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14463                         res->idx, res->an, res->pn, key);
14464 #endif
14465         RTE_SET_USED(is_tx);
14466         RTE_SET_USED(key);
14467
14468         switch (ret) {
14469         case 0:
14470                 break;
14471         case -EINVAL:
14472                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14473                 break;
14474         case -ENODEV:
14475                 printf("invalid port_id %d\n", res->port_id);
14476                 break;
14477         case -ENOTSUP:
14478                 printf("not supported on port %d\n", res->port_id);
14479                 break;
14480         default:
14481                 printf("programming error: (%s)\n", strerror(-ret));
14482         }
14483 }
14484
14485 cmdline_parse_inst_t cmd_set_macsec_sa = {
14486         .f = cmd_set_macsec_sa_parsed,
14487         .data = NULL,
14488         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14489         .tokens = {
14490                 (void *)&cmd_macsec_sa_set,
14491                 (void *)&cmd_macsec_sa_macsec,
14492                 (void *)&cmd_macsec_sa_sa,
14493                 (void *)&cmd_macsec_sa_tx_rx,
14494                 (void *)&cmd_macsec_sa_port_id,
14495                 (void *)&cmd_macsec_sa_idx,
14496                 (void *)&cmd_macsec_sa_an,
14497                 (void *)&cmd_macsec_sa_pn,
14498                 (void *)&cmd_macsec_sa_key,
14499                 NULL,
14500         },
14501 };
14502
14503 /* VF unicast promiscuous mode configuration */
14504
14505 /* Common result structure for VF unicast promiscuous mode */
14506 struct cmd_vf_promisc_result {
14507         cmdline_fixed_string_t set;
14508         cmdline_fixed_string_t vf;
14509         cmdline_fixed_string_t promisc;
14510         portid_t port_id;
14511         uint32_t vf_id;
14512         cmdline_fixed_string_t on_off;
14513 };
14514
14515 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14516 cmdline_parse_token_string_t cmd_vf_promisc_set =
14517         TOKEN_STRING_INITIALIZER
14518                 (struct cmd_vf_promisc_result,
14519                  set, "set");
14520 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14521         TOKEN_STRING_INITIALIZER
14522                 (struct cmd_vf_promisc_result,
14523                  vf, "vf");
14524 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14525         TOKEN_STRING_INITIALIZER
14526                 (struct cmd_vf_promisc_result,
14527                  promisc, "promisc");
14528 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14529         TOKEN_NUM_INITIALIZER
14530                 (struct cmd_vf_promisc_result,
14531                  port_id, UINT16);
14532 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14533         TOKEN_NUM_INITIALIZER
14534                 (struct cmd_vf_promisc_result,
14535                  vf_id, UINT32);
14536 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14537         TOKEN_STRING_INITIALIZER
14538                 (struct cmd_vf_promisc_result,
14539                  on_off, "on#off");
14540
14541 static void
14542 cmd_set_vf_promisc_parsed(
14543         void *parsed_result,
14544         __rte_unused struct cmdline *cl,
14545         __rte_unused void *data)
14546 {
14547         struct cmd_vf_promisc_result *res = parsed_result;
14548         int ret = -ENOTSUP;
14549
14550         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14551
14552         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14553                 return;
14554
14555 #ifdef RTE_NET_I40E
14556         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14557                                                   res->vf_id, is_on);
14558 #endif
14559
14560         switch (ret) {
14561         case 0:
14562                 break;
14563         case -EINVAL:
14564                 printf("invalid vf_id %d\n", res->vf_id);
14565                 break;
14566         case -ENODEV:
14567                 printf("invalid port_id %d\n", res->port_id);
14568                 break;
14569         case -ENOTSUP:
14570                 printf("function not implemented\n");
14571                 break;
14572         default:
14573                 printf("programming error: (%s)\n", strerror(-ret));
14574         }
14575 }
14576
14577 cmdline_parse_inst_t cmd_set_vf_promisc = {
14578         .f = cmd_set_vf_promisc_parsed,
14579         .data = NULL,
14580         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14581                 "Set unicast promiscuous mode for a VF from the PF",
14582         .tokens = {
14583                 (void *)&cmd_vf_promisc_set,
14584                 (void *)&cmd_vf_promisc_vf,
14585                 (void *)&cmd_vf_promisc_promisc,
14586                 (void *)&cmd_vf_promisc_port_id,
14587                 (void *)&cmd_vf_promisc_vf_id,
14588                 (void *)&cmd_vf_promisc_on_off,
14589                 NULL,
14590         },
14591 };
14592
14593 /* VF multicast promiscuous mode configuration */
14594
14595 /* Common result structure for VF multicast promiscuous mode */
14596 struct cmd_vf_allmulti_result {
14597         cmdline_fixed_string_t set;
14598         cmdline_fixed_string_t vf;
14599         cmdline_fixed_string_t allmulti;
14600         portid_t port_id;
14601         uint32_t vf_id;
14602         cmdline_fixed_string_t on_off;
14603 };
14604
14605 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14606 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14607         TOKEN_STRING_INITIALIZER
14608                 (struct cmd_vf_allmulti_result,
14609                  set, "set");
14610 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14611         TOKEN_STRING_INITIALIZER
14612                 (struct cmd_vf_allmulti_result,
14613                  vf, "vf");
14614 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14615         TOKEN_STRING_INITIALIZER
14616                 (struct cmd_vf_allmulti_result,
14617                  allmulti, "allmulti");
14618 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14619         TOKEN_NUM_INITIALIZER
14620                 (struct cmd_vf_allmulti_result,
14621                  port_id, UINT16);
14622 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14623         TOKEN_NUM_INITIALIZER
14624                 (struct cmd_vf_allmulti_result,
14625                  vf_id, UINT32);
14626 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14627         TOKEN_STRING_INITIALIZER
14628                 (struct cmd_vf_allmulti_result,
14629                  on_off, "on#off");
14630
14631 static void
14632 cmd_set_vf_allmulti_parsed(
14633         void *parsed_result,
14634         __rte_unused struct cmdline *cl,
14635         __rte_unused void *data)
14636 {
14637         struct cmd_vf_allmulti_result *res = parsed_result;
14638         int ret = -ENOTSUP;
14639
14640         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14641
14642         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14643                 return;
14644
14645 #ifdef RTE_NET_I40E
14646         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14647                                                     res->vf_id, is_on);
14648 #endif
14649
14650         switch (ret) {
14651         case 0:
14652                 break;
14653         case -EINVAL:
14654                 printf("invalid vf_id %d\n", res->vf_id);
14655                 break;
14656         case -ENODEV:
14657                 printf("invalid port_id %d\n", res->port_id);
14658                 break;
14659         case -ENOTSUP:
14660                 printf("function not implemented\n");
14661                 break;
14662         default:
14663                 printf("programming error: (%s)\n", strerror(-ret));
14664         }
14665 }
14666
14667 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14668         .f = cmd_set_vf_allmulti_parsed,
14669         .data = NULL,
14670         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14671                 "Set multicast promiscuous mode for a VF from the PF",
14672         .tokens = {
14673                 (void *)&cmd_vf_allmulti_set,
14674                 (void *)&cmd_vf_allmulti_vf,
14675                 (void *)&cmd_vf_allmulti_allmulti,
14676                 (void *)&cmd_vf_allmulti_port_id,
14677                 (void *)&cmd_vf_allmulti_vf_id,
14678                 (void *)&cmd_vf_allmulti_on_off,
14679                 NULL,
14680         },
14681 };
14682
14683 /* vf broadcast mode configuration */
14684
14685 /* Common result structure for vf broadcast */
14686 struct cmd_set_vf_broadcast_result {
14687         cmdline_fixed_string_t set;
14688         cmdline_fixed_string_t vf;
14689         cmdline_fixed_string_t broadcast;
14690         portid_t port_id;
14691         uint16_t vf_id;
14692         cmdline_fixed_string_t on_off;
14693 };
14694
14695 /* Common CLI fields for vf broadcast enable disable */
14696 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14697         TOKEN_STRING_INITIALIZER
14698                 (struct cmd_set_vf_broadcast_result,
14699                  set, "set");
14700 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14701         TOKEN_STRING_INITIALIZER
14702                 (struct cmd_set_vf_broadcast_result,
14703                  vf, "vf");
14704 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14705         TOKEN_STRING_INITIALIZER
14706                 (struct cmd_set_vf_broadcast_result,
14707                  broadcast, "broadcast");
14708 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14709         TOKEN_NUM_INITIALIZER
14710                 (struct cmd_set_vf_broadcast_result,
14711                  port_id, UINT16);
14712 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14713         TOKEN_NUM_INITIALIZER
14714                 (struct cmd_set_vf_broadcast_result,
14715                  vf_id, UINT16);
14716 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14717         TOKEN_STRING_INITIALIZER
14718                 (struct cmd_set_vf_broadcast_result,
14719                  on_off, "on#off");
14720
14721 static void
14722 cmd_set_vf_broadcast_parsed(
14723         void *parsed_result,
14724         __rte_unused struct cmdline *cl,
14725         __rte_unused void *data)
14726 {
14727         struct cmd_set_vf_broadcast_result *res = parsed_result;
14728         int ret = -ENOTSUP;
14729
14730         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14731
14732         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14733                 return;
14734
14735 #ifdef RTE_NET_I40E
14736         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14737                                             res->vf_id, is_on);
14738 #endif
14739
14740         switch (ret) {
14741         case 0:
14742                 break;
14743         case -EINVAL:
14744                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14745                 break;
14746         case -ENODEV:
14747                 printf("invalid port_id %d\n", res->port_id);
14748                 break;
14749         case -ENOTSUP:
14750                 printf("function not implemented\n");
14751                 break;
14752         default:
14753                 printf("programming error: (%s)\n", strerror(-ret));
14754         }
14755 }
14756
14757 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14758         .f = cmd_set_vf_broadcast_parsed,
14759         .data = NULL,
14760         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14761         .tokens = {
14762                 (void *)&cmd_set_vf_broadcast_set,
14763                 (void *)&cmd_set_vf_broadcast_vf,
14764                 (void *)&cmd_set_vf_broadcast_broadcast,
14765                 (void *)&cmd_set_vf_broadcast_port_id,
14766                 (void *)&cmd_set_vf_broadcast_vf_id,
14767                 (void *)&cmd_set_vf_broadcast_on_off,
14768                 NULL,
14769         },
14770 };
14771
14772 /* vf vlan tag configuration */
14773
14774 /* Common result structure for vf vlan tag */
14775 struct cmd_set_vf_vlan_tag_result {
14776         cmdline_fixed_string_t set;
14777         cmdline_fixed_string_t vf;
14778         cmdline_fixed_string_t vlan;
14779         cmdline_fixed_string_t tag;
14780         portid_t port_id;
14781         uint16_t vf_id;
14782         cmdline_fixed_string_t on_off;
14783 };
14784
14785 /* Common CLI fields for vf vlan tag enable disable */
14786 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14787         TOKEN_STRING_INITIALIZER
14788                 (struct cmd_set_vf_vlan_tag_result,
14789                  set, "set");
14790 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14791         TOKEN_STRING_INITIALIZER
14792                 (struct cmd_set_vf_vlan_tag_result,
14793                  vf, "vf");
14794 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14795         TOKEN_STRING_INITIALIZER
14796                 (struct cmd_set_vf_vlan_tag_result,
14797                  vlan, "vlan");
14798 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14799         TOKEN_STRING_INITIALIZER
14800                 (struct cmd_set_vf_vlan_tag_result,
14801                  tag, "tag");
14802 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14803         TOKEN_NUM_INITIALIZER
14804                 (struct cmd_set_vf_vlan_tag_result,
14805                  port_id, UINT16);
14806 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14807         TOKEN_NUM_INITIALIZER
14808                 (struct cmd_set_vf_vlan_tag_result,
14809                  vf_id, UINT16);
14810 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14811         TOKEN_STRING_INITIALIZER
14812                 (struct cmd_set_vf_vlan_tag_result,
14813                  on_off, "on#off");
14814
14815 static void
14816 cmd_set_vf_vlan_tag_parsed(
14817         void *parsed_result,
14818         __rte_unused struct cmdline *cl,
14819         __rte_unused void *data)
14820 {
14821         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14822         int ret = -ENOTSUP;
14823
14824         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14825
14826         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14827                 return;
14828
14829 #ifdef RTE_NET_I40E
14830         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14831                                            res->vf_id, is_on);
14832 #endif
14833
14834         switch (ret) {
14835         case 0:
14836                 break;
14837         case -EINVAL:
14838                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14839                 break;
14840         case -ENODEV:
14841                 printf("invalid port_id %d\n", res->port_id);
14842                 break;
14843         case -ENOTSUP:
14844                 printf("function not implemented\n");
14845                 break;
14846         default:
14847                 printf("programming error: (%s)\n", strerror(-ret));
14848         }
14849 }
14850
14851 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14852         .f = cmd_set_vf_vlan_tag_parsed,
14853         .data = NULL,
14854         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14855         .tokens = {
14856                 (void *)&cmd_set_vf_vlan_tag_set,
14857                 (void *)&cmd_set_vf_vlan_tag_vf,
14858                 (void *)&cmd_set_vf_vlan_tag_vlan,
14859                 (void *)&cmd_set_vf_vlan_tag_tag,
14860                 (void *)&cmd_set_vf_vlan_tag_port_id,
14861                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14862                 (void *)&cmd_set_vf_vlan_tag_on_off,
14863                 NULL,
14864         },
14865 };
14866
14867 /* Common definition of VF and TC TX bandwidth configuration */
14868 struct cmd_vf_tc_bw_result {
14869         cmdline_fixed_string_t set;
14870         cmdline_fixed_string_t vf;
14871         cmdline_fixed_string_t tc;
14872         cmdline_fixed_string_t tx;
14873         cmdline_fixed_string_t min_bw;
14874         cmdline_fixed_string_t max_bw;
14875         cmdline_fixed_string_t strict_link_prio;
14876         portid_t port_id;
14877         uint16_t vf_id;
14878         uint8_t tc_no;
14879         uint32_t bw;
14880         cmdline_fixed_string_t bw_list;
14881         uint8_t tc_map;
14882 };
14883
14884 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14885         TOKEN_STRING_INITIALIZER
14886                 (struct cmd_vf_tc_bw_result,
14887                  set, "set");
14888 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14889         TOKEN_STRING_INITIALIZER
14890                 (struct cmd_vf_tc_bw_result,
14891                  vf, "vf");
14892 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14893         TOKEN_STRING_INITIALIZER
14894                 (struct cmd_vf_tc_bw_result,
14895                  tc, "tc");
14896 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14897         TOKEN_STRING_INITIALIZER
14898                 (struct cmd_vf_tc_bw_result,
14899                  tx, "tx");
14900 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14901         TOKEN_STRING_INITIALIZER
14902                 (struct cmd_vf_tc_bw_result,
14903                  strict_link_prio, "strict-link-priority");
14904 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14905         TOKEN_STRING_INITIALIZER
14906                 (struct cmd_vf_tc_bw_result,
14907                  min_bw, "min-bandwidth");
14908 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
14909         TOKEN_STRING_INITIALIZER
14910                 (struct cmd_vf_tc_bw_result,
14911                  max_bw, "max-bandwidth");
14912 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
14913         TOKEN_NUM_INITIALIZER
14914                 (struct cmd_vf_tc_bw_result,
14915                  port_id, UINT16);
14916 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
14917         TOKEN_NUM_INITIALIZER
14918                 (struct cmd_vf_tc_bw_result,
14919                  vf_id, UINT16);
14920 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
14921         TOKEN_NUM_INITIALIZER
14922                 (struct cmd_vf_tc_bw_result,
14923                  tc_no, UINT8);
14924 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
14925         TOKEN_NUM_INITIALIZER
14926                 (struct cmd_vf_tc_bw_result,
14927                  bw, UINT32);
14928 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
14929         TOKEN_STRING_INITIALIZER
14930                 (struct cmd_vf_tc_bw_result,
14931                  bw_list, NULL);
14932 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
14933         TOKEN_NUM_INITIALIZER
14934                 (struct cmd_vf_tc_bw_result,
14935                  tc_map, UINT8);
14936
14937 /* VF max bandwidth setting */
14938 static void
14939 cmd_vf_max_bw_parsed(
14940         void *parsed_result,
14941         __rte_unused struct cmdline *cl,
14942         __rte_unused void *data)
14943 {
14944         struct cmd_vf_tc_bw_result *res = parsed_result;
14945         int ret = -ENOTSUP;
14946
14947         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14948                 return;
14949
14950 #ifdef RTE_NET_I40E
14951         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
14952                                          res->vf_id, res->bw);
14953 #endif
14954
14955         switch (ret) {
14956         case 0:
14957                 break;
14958         case -EINVAL:
14959                 printf("invalid vf_id %d or bandwidth %d\n",
14960                        res->vf_id, res->bw);
14961                 break;
14962         case -ENODEV:
14963                 printf("invalid port_id %d\n", res->port_id);
14964                 break;
14965         case -ENOTSUP:
14966                 printf("function not implemented\n");
14967                 break;
14968         default:
14969                 printf("programming error: (%s)\n", strerror(-ret));
14970         }
14971 }
14972
14973 cmdline_parse_inst_t cmd_vf_max_bw = {
14974         .f = cmd_vf_max_bw_parsed,
14975         .data = NULL,
14976         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14977         .tokens = {
14978                 (void *)&cmd_vf_tc_bw_set,
14979                 (void *)&cmd_vf_tc_bw_vf,
14980                 (void *)&cmd_vf_tc_bw_tx,
14981                 (void *)&cmd_vf_tc_bw_max_bw,
14982                 (void *)&cmd_vf_tc_bw_port_id,
14983                 (void *)&cmd_vf_tc_bw_vf_id,
14984                 (void *)&cmd_vf_tc_bw_bw,
14985                 NULL,
14986         },
14987 };
14988
14989 static int
14990 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14991                            uint8_t *tc_num,
14992                            char *str)
14993 {
14994         uint32_t size;
14995         const char *p, *p0 = str;
14996         char s[256];
14997         char *end;
14998         char *str_fld[16];
14999         uint16_t i;
15000         int ret;
15001
15002         p = strchr(p0, '(');
15003         if (p == NULL) {
15004                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15005                 return -1;
15006         }
15007         p++;
15008         p0 = strchr(p, ')');
15009         if (p0 == NULL) {
15010                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15011                 return -1;
15012         }
15013         size = p0 - p;
15014         if (size >= sizeof(s)) {
15015                 printf("The string size exceeds the internal buffer size\n");
15016                 return -1;
15017         }
15018         snprintf(s, sizeof(s), "%.*s", size, p);
15019         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15020         if (ret <= 0) {
15021                 printf("Failed to get the bandwidth list. ");
15022                 return -1;
15023         }
15024         *tc_num = ret;
15025         for (i = 0; i < ret; i++)
15026                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15027
15028         return 0;
15029 }
15030
15031 /* TC min bandwidth setting */
15032 static void
15033 cmd_vf_tc_min_bw_parsed(
15034         void *parsed_result,
15035         __rte_unused struct cmdline *cl,
15036         __rte_unused void *data)
15037 {
15038         struct cmd_vf_tc_bw_result *res = parsed_result;
15039         uint8_t tc_num;
15040         uint8_t bw[16];
15041         int ret = -ENOTSUP;
15042
15043         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15044                 return;
15045
15046         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15047         if (ret)
15048                 return;
15049
15050 #ifdef RTE_NET_I40E
15051         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15052                                               tc_num, bw);
15053 #endif
15054
15055         switch (ret) {
15056         case 0:
15057                 break;
15058         case -EINVAL:
15059                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15060                 break;
15061         case -ENODEV:
15062                 printf("invalid port_id %d\n", res->port_id);
15063                 break;
15064         case -ENOTSUP:
15065                 printf("function not implemented\n");
15066                 break;
15067         default:
15068                 printf("programming error: (%s)\n", strerror(-ret));
15069         }
15070 }
15071
15072 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15073         .f = cmd_vf_tc_min_bw_parsed,
15074         .data = NULL,
15075         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15076                     " <bw1, bw2, ...>",
15077         .tokens = {
15078                 (void *)&cmd_vf_tc_bw_set,
15079                 (void *)&cmd_vf_tc_bw_vf,
15080                 (void *)&cmd_vf_tc_bw_tc,
15081                 (void *)&cmd_vf_tc_bw_tx,
15082                 (void *)&cmd_vf_tc_bw_min_bw,
15083                 (void *)&cmd_vf_tc_bw_port_id,
15084                 (void *)&cmd_vf_tc_bw_vf_id,
15085                 (void *)&cmd_vf_tc_bw_bw_list,
15086                 NULL,
15087         },
15088 };
15089
15090 static void
15091 cmd_tc_min_bw_parsed(
15092         void *parsed_result,
15093         __rte_unused struct cmdline *cl,
15094         __rte_unused void *data)
15095 {
15096         struct cmd_vf_tc_bw_result *res = parsed_result;
15097         struct rte_port *port;
15098         uint8_t tc_num;
15099         uint8_t bw[16];
15100         int ret = -ENOTSUP;
15101
15102         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15103                 return;
15104
15105         port = &ports[res->port_id];
15106         /** Check if the port is not started **/
15107         if (port->port_status != RTE_PORT_STOPPED) {
15108                 printf("Please stop port %d first\n", res->port_id);
15109                 return;
15110         }
15111
15112         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15113         if (ret)
15114                 return;
15115
15116 #ifdef RTE_NET_IXGBE
15117         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15118 #endif
15119
15120         switch (ret) {
15121         case 0:
15122                 break;
15123         case -EINVAL:
15124                 printf("invalid bandwidth\n");
15125                 break;
15126         case -ENODEV:
15127                 printf("invalid port_id %d\n", res->port_id);
15128                 break;
15129         case -ENOTSUP:
15130                 printf("function not implemented\n");
15131                 break;
15132         default:
15133                 printf("programming error: (%s)\n", strerror(-ret));
15134         }
15135 }
15136
15137 cmdline_parse_inst_t cmd_tc_min_bw = {
15138         .f = cmd_tc_min_bw_parsed,
15139         .data = NULL,
15140         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15141         .tokens = {
15142                 (void *)&cmd_vf_tc_bw_set,
15143                 (void *)&cmd_vf_tc_bw_tc,
15144                 (void *)&cmd_vf_tc_bw_tx,
15145                 (void *)&cmd_vf_tc_bw_min_bw,
15146                 (void *)&cmd_vf_tc_bw_port_id,
15147                 (void *)&cmd_vf_tc_bw_bw_list,
15148                 NULL,
15149         },
15150 };
15151
15152 /* TC max bandwidth setting */
15153 static void
15154 cmd_vf_tc_max_bw_parsed(
15155         void *parsed_result,
15156         __rte_unused struct cmdline *cl,
15157         __rte_unused void *data)
15158 {
15159         struct cmd_vf_tc_bw_result *res = parsed_result;
15160         int ret = -ENOTSUP;
15161
15162         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15163                 return;
15164
15165 #ifdef RTE_NET_I40E
15166         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15167                                             res->tc_no, res->bw);
15168 #endif
15169
15170         switch (ret) {
15171         case 0:
15172                 break;
15173         case -EINVAL:
15174                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15175                        res->vf_id, res->tc_no, res->bw);
15176                 break;
15177         case -ENODEV:
15178                 printf("invalid port_id %d\n", res->port_id);
15179                 break;
15180         case -ENOTSUP:
15181                 printf("function not implemented\n");
15182                 break;
15183         default:
15184                 printf("programming error: (%s)\n", strerror(-ret));
15185         }
15186 }
15187
15188 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15189         .f = cmd_vf_tc_max_bw_parsed,
15190         .data = NULL,
15191         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15192                     " <bandwidth>",
15193         .tokens = {
15194                 (void *)&cmd_vf_tc_bw_set,
15195                 (void *)&cmd_vf_tc_bw_vf,
15196                 (void *)&cmd_vf_tc_bw_tc,
15197                 (void *)&cmd_vf_tc_bw_tx,
15198                 (void *)&cmd_vf_tc_bw_max_bw,
15199                 (void *)&cmd_vf_tc_bw_port_id,
15200                 (void *)&cmd_vf_tc_bw_vf_id,
15201                 (void *)&cmd_vf_tc_bw_tc_no,
15202                 (void *)&cmd_vf_tc_bw_bw,
15203                 NULL,
15204         },
15205 };
15206
15207 /** Set VXLAN encapsulation details */
15208 struct cmd_set_vxlan_result {
15209         cmdline_fixed_string_t set;
15210         cmdline_fixed_string_t vxlan;
15211         cmdline_fixed_string_t pos_token;
15212         cmdline_fixed_string_t ip_version;
15213         uint32_t vlan_present:1;
15214         uint32_t vni;
15215         uint16_t udp_src;
15216         uint16_t udp_dst;
15217         cmdline_ipaddr_t ip_src;
15218         cmdline_ipaddr_t ip_dst;
15219         uint16_t tci;
15220         uint8_t tos;
15221         uint8_t ttl;
15222         struct rte_ether_addr eth_src;
15223         struct rte_ether_addr eth_dst;
15224 };
15225
15226 cmdline_parse_token_string_t cmd_set_vxlan_set =
15227         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15228 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15229         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15230 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15231         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15232                                  "vxlan-tos-ttl");
15233 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15234         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15235                                  "vxlan-with-vlan");
15236 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15237         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15238                                  "ip-version");
15239 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15240         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15241                                  "ipv4#ipv6");
15242 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15243         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15244                                  "vni");
15245 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15246         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15247 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15248         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15249                                  "udp-src");
15250 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15251         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15252 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15253         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15254                                  "udp-dst");
15255 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15256         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15257 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15258         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15259                                  "ip-tos");
15260 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15261         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15262 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15263         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15264                                  "ip-ttl");
15265 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15266         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15267 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15268         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15269                                  "ip-src");
15270 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15271         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15272 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15273         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15274                                  "ip-dst");
15275 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15276         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15277 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15278         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15279                                  "vlan-tci");
15280 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15281         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15282 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15283         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15284                                  "eth-src");
15285 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15286         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15287 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15288         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15289                                  "eth-dst");
15290 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15291         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15292
15293 static void cmd_set_vxlan_parsed(void *parsed_result,
15294         __rte_unused struct cmdline *cl,
15295         __rte_unused void *data)
15296 {
15297         struct cmd_set_vxlan_result *res = parsed_result;
15298         union {
15299                 uint32_t vxlan_id;
15300                 uint8_t vni[4];
15301         } id = {
15302                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15303         };
15304
15305         vxlan_encap_conf.select_tos_ttl = 0;
15306         if (strcmp(res->vxlan, "vxlan") == 0)
15307                 vxlan_encap_conf.select_vlan = 0;
15308         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15309                 vxlan_encap_conf.select_vlan = 1;
15310         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15311                 vxlan_encap_conf.select_vlan = 0;
15312                 vxlan_encap_conf.select_tos_ttl = 1;
15313         }
15314         if (strcmp(res->ip_version, "ipv4") == 0)
15315                 vxlan_encap_conf.select_ipv4 = 1;
15316         else if (strcmp(res->ip_version, "ipv6") == 0)
15317                 vxlan_encap_conf.select_ipv4 = 0;
15318         else
15319                 return;
15320         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15321         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15322         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15323         vxlan_encap_conf.ip_tos = res->tos;
15324         vxlan_encap_conf.ip_ttl = res->ttl;
15325         if (vxlan_encap_conf.select_ipv4) {
15326                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15327                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15328         } else {
15329                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15330                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15331         }
15332         if (vxlan_encap_conf.select_vlan)
15333                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15334         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15335                    RTE_ETHER_ADDR_LEN);
15336         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15337                    RTE_ETHER_ADDR_LEN);
15338 }
15339
15340 cmdline_parse_inst_t cmd_set_vxlan = {
15341         .f = cmd_set_vxlan_parsed,
15342         .data = NULL,
15343         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15344                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15345                 " eth-src <eth-src> eth-dst <eth-dst>",
15346         .tokens = {
15347                 (void *)&cmd_set_vxlan_set,
15348                 (void *)&cmd_set_vxlan_vxlan,
15349                 (void *)&cmd_set_vxlan_ip_version,
15350                 (void *)&cmd_set_vxlan_ip_version_value,
15351                 (void *)&cmd_set_vxlan_vni,
15352                 (void *)&cmd_set_vxlan_vni_value,
15353                 (void *)&cmd_set_vxlan_udp_src,
15354                 (void *)&cmd_set_vxlan_udp_src_value,
15355                 (void *)&cmd_set_vxlan_udp_dst,
15356                 (void *)&cmd_set_vxlan_udp_dst_value,
15357                 (void *)&cmd_set_vxlan_ip_src,
15358                 (void *)&cmd_set_vxlan_ip_src_value,
15359                 (void *)&cmd_set_vxlan_ip_dst,
15360                 (void *)&cmd_set_vxlan_ip_dst_value,
15361                 (void *)&cmd_set_vxlan_eth_src,
15362                 (void *)&cmd_set_vxlan_eth_src_value,
15363                 (void *)&cmd_set_vxlan_eth_dst,
15364                 (void *)&cmd_set_vxlan_eth_dst_value,
15365                 NULL,
15366         },
15367 };
15368
15369 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15370         .f = cmd_set_vxlan_parsed,
15371         .data = NULL,
15372         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15373                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15374                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15375                 " eth-dst <eth-dst>",
15376         .tokens = {
15377                 (void *)&cmd_set_vxlan_set,
15378                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15379                 (void *)&cmd_set_vxlan_ip_version,
15380                 (void *)&cmd_set_vxlan_ip_version_value,
15381                 (void *)&cmd_set_vxlan_vni,
15382                 (void *)&cmd_set_vxlan_vni_value,
15383                 (void *)&cmd_set_vxlan_udp_src,
15384                 (void *)&cmd_set_vxlan_udp_src_value,
15385                 (void *)&cmd_set_vxlan_udp_dst,
15386                 (void *)&cmd_set_vxlan_udp_dst_value,
15387                 (void *)&cmd_set_vxlan_ip_tos,
15388                 (void *)&cmd_set_vxlan_ip_tos_value,
15389                 (void *)&cmd_set_vxlan_ip_ttl,
15390                 (void *)&cmd_set_vxlan_ip_ttl_value,
15391                 (void *)&cmd_set_vxlan_ip_src,
15392                 (void *)&cmd_set_vxlan_ip_src_value,
15393                 (void *)&cmd_set_vxlan_ip_dst,
15394                 (void *)&cmd_set_vxlan_ip_dst_value,
15395                 (void *)&cmd_set_vxlan_eth_src,
15396                 (void *)&cmd_set_vxlan_eth_src_value,
15397                 (void *)&cmd_set_vxlan_eth_dst,
15398                 (void *)&cmd_set_vxlan_eth_dst_value,
15399                 NULL,
15400         },
15401 };
15402
15403 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15404         .f = cmd_set_vxlan_parsed,
15405         .data = NULL,
15406         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15407                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15408                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15409                 " <eth-dst>",
15410         .tokens = {
15411                 (void *)&cmd_set_vxlan_set,
15412                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15413                 (void *)&cmd_set_vxlan_ip_version,
15414                 (void *)&cmd_set_vxlan_ip_version_value,
15415                 (void *)&cmd_set_vxlan_vni,
15416                 (void *)&cmd_set_vxlan_vni_value,
15417                 (void *)&cmd_set_vxlan_udp_src,
15418                 (void *)&cmd_set_vxlan_udp_src_value,
15419                 (void *)&cmd_set_vxlan_udp_dst,
15420                 (void *)&cmd_set_vxlan_udp_dst_value,
15421                 (void *)&cmd_set_vxlan_ip_src,
15422                 (void *)&cmd_set_vxlan_ip_src_value,
15423                 (void *)&cmd_set_vxlan_ip_dst,
15424                 (void *)&cmd_set_vxlan_ip_dst_value,
15425                 (void *)&cmd_set_vxlan_vlan,
15426                 (void *)&cmd_set_vxlan_vlan_value,
15427                 (void *)&cmd_set_vxlan_eth_src,
15428                 (void *)&cmd_set_vxlan_eth_src_value,
15429                 (void *)&cmd_set_vxlan_eth_dst,
15430                 (void *)&cmd_set_vxlan_eth_dst_value,
15431                 NULL,
15432         },
15433 };
15434
15435 /** Set NVGRE encapsulation details */
15436 struct cmd_set_nvgre_result {
15437         cmdline_fixed_string_t set;
15438         cmdline_fixed_string_t nvgre;
15439         cmdline_fixed_string_t pos_token;
15440         cmdline_fixed_string_t ip_version;
15441         uint32_t tni;
15442         cmdline_ipaddr_t ip_src;
15443         cmdline_ipaddr_t ip_dst;
15444         uint16_t tci;
15445         struct rte_ether_addr eth_src;
15446         struct rte_ether_addr eth_dst;
15447 };
15448
15449 cmdline_parse_token_string_t cmd_set_nvgre_set =
15450         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15451 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15452         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15453 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15454         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15455                                  "nvgre-with-vlan");
15456 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15457         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15458                                  "ip-version");
15459 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15460         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15461                                  "ipv4#ipv6");
15462 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15463         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15464                                  "tni");
15465 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15466         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15467 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15468         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15469                                  "ip-src");
15470 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15471         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15472 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15473         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15474                                  "ip-dst");
15475 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15476         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15477 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15478         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15479                                  "vlan-tci");
15480 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15481         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15482 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15483         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15484                                  "eth-src");
15485 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15486         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15487 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15488         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15489                                  "eth-dst");
15490 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15491         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15492
15493 static void cmd_set_nvgre_parsed(void *parsed_result,
15494         __rte_unused struct cmdline *cl,
15495         __rte_unused void *data)
15496 {
15497         struct cmd_set_nvgre_result *res = parsed_result;
15498         union {
15499                 uint32_t nvgre_tni;
15500                 uint8_t tni[4];
15501         } id = {
15502                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15503         };
15504
15505         if (strcmp(res->nvgre, "nvgre") == 0)
15506                 nvgre_encap_conf.select_vlan = 0;
15507         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15508                 nvgre_encap_conf.select_vlan = 1;
15509         if (strcmp(res->ip_version, "ipv4") == 0)
15510                 nvgre_encap_conf.select_ipv4 = 1;
15511         else if (strcmp(res->ip_version, "ipv6") == 0)
15512                 nvgre_encap_conf.select_ipv4 = 0;
15513         else
15514                 return;
15515         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15516         if (nvgre_encap_conf.select_ipv4) {
15517                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15518                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15519         } else {
15520                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15521                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15522         }
15523         if (nvgre_encap_conf.select_vlan)
15524                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15525         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15526                    RTE_ETHER_ADDR_LEN);
15527         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15528                    RTE_ETHER_ADDR_LEN);
15529 }
15530
15531 cmdline_parse_inst_t cmd_set_nvgre = {
15532         .f = cmd_set_nvgre_parsed,
15533         .data = NULL,
15534         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15535                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15536                 " eth-dst <eth-dst>",
15537         .tokens = {
15538                 (void *)&cmd_set_nvgre_set,
15539                 (void *)&cmd_set_nvgre_nvgre,
15540                 (void *)&cmd_set_nvgre_ip_version,
15541                 (void *)&cmd_set_nvgre_ip_version_value,
15542                 (void *)&cmd_set_nvgre_tni,
15543                 (void *)&cmd_set_nvgre_tni_value,
15544                 (void *)&cmd_set_nvgre_ip_src,
15545                 (void *)&cmd_set_nvgre_ip_src_value,
15546                 (void *)&cmd_set_nvgre_ip_dst,
15547                 (void *)&cmd_set_nvgre_ip_dst_value,
15548                 (void *)&cmd_set_nvgre_eth_src,
15549                 (void *)&cmd_set_nvgre_eth_src_value,
15550                 (void *)&cmd_set_nvgre_eth_dst,
15551                 (void *)&cmd_set_nvgre_eth_dst_value,
15552                 NULL,
15553         },
15554 };
15555
15556 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15557         .f = cmd_set_nvgre_parsed,
15558         .data = NULL,
15559         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15560                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15561                 " eth-src <eth-src> eth-dst <eth-dst>",
15562         .tokens = {
15563                 (void *)&cmd_set_nvgre_set,
15564                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15565                 (void *)&cmd_set_nvgre_ip_version,
15566                 (void *)&cmd_set_nvgre_ip_version_value,
15567                 (void *)&cmd_set_nvgre_tni,
15568                 (void *)&cmd_set_nvgre_tni_value,
15569                 (void *)&cmd_set_nvgre_ip_src,
15570                 (void *)&cmd_set_nvgre_ip_src_value,
15571                 (void *)&cmd_set_nvgre_ip_dst,
15572                 (void *)&cmd_set_nvgre_ip_dst_value,
15573                 (void *)&cmd_set_nvgre_vlan,
15574                 (void *)&cmd_set_nvgre_vlan_value,
15575                 (void *)&cmd_set_nvgre_eth_src,
15576                 (void *)&cmd_set_nvgre_eth_src_value,
15577                 (void *)&cmd_set_nvgre_eth_dst,
15578                 (void *)&cmd_set_nvgre_eth_dst_value,
15579                 NULL,
15580         },
15581 };
15582
15583 /** Set L2 encapsulation details */
15584 struct cmd_set_l2_encap_result {
15585         cmdline_fixed_string_t set;
15586         cmdline_fixed_string_t l2_encap;
15587         cmdline_fixed_string_t pos_token;
15588         cmdline_fixed_string_t ip_version;
15589         uint32_t vlan_present:1;
15590         uint16_t tci;
15591         struct rte_ether_addr eth_src;
15592         struct rte_ether_addr eth_dst;
15593 };
15594
15595 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15596         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15597 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15598         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15599 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15600         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15601                                  "l2_encap-with-vlan");
15602 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15603         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15604                                  "ip-version");
15605 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15606         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15607                                  "ipv4#ipv6");
15608 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15609         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15610                                  "vlan-tci");
15611 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15612         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15613 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15614         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15615                                  "eth-src");
15616 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15617         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15618 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15619         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15620                                  "eth-dst");
15621 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15622         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15623
15624 static void cmd_set_l2_encap_parsed(void *parsed_result,
15625         __rte_unused struct cmdline *cl,
15626         __rte_unused void *data)
15627 {
15628         struct cmd_set_l2_encap_result *res = parsed_result;
15629
15630         if (strcmp(res->l2_encap, "l2_encap") == 0)
15631                 l2_encap_conf.select_vlan = 0;
15632         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15633                 l2_encap_conf.select_vlan = 1;
15634         if (strcmp(res->ip_version, "ipv4") == 0)
15635                 l2_encap_conf.select_ipv4 = 1;
15636         else if (strcmp(res->ip_version, "ipv6") == 0)
15637                 l2_encap_conf.select_ipv4 = 0;
15638         else
15639                 return;
15640         if (l2_encap_conf.select_vlan)
15641                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15642         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15643                    RTE_ETHER_ADDR_LEN);
15644         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15645                    RTE_ETHER_ADDR_LEN);
15646 }
15647
15648 cmdline_parse_inst_t cmd_set_l2_encap = {
15649         .f = cmd_set_l2_encap_parsed,
15650         .data = NULL,
15651         .help_str = "set l2_encap ip-version ipv4|ipv6"
15652                 " eth-src <eth-src> eth-dst <eth-dst>",
15653         .tokens = {
15654                 (void *)&cmd_set_l2_encap_set,
15655                 (void *)&cmd_set_l2_encap_l2_encap,
15656                 (void *)&cmd_set_l2_encap_ip_version,
15657                 (void *)&cmd_set_l2_encap_ip_version_value,
15658                 (void *)&cmd_set_l2_encap_eth_src,
15659                 (void *)&cmd_set_l2_encap_eth_src_value,
15660                 (void *)&cmd_set_l2_encap_eth_dst,
15661                 (void *)&cmd_set_l2_encap_eth_dst_value,
15662                 NULL,
15663         },
15664 };
15665
15666 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15667         .f = cmd_set_l2_encap_parsed,
15668         .data = NULL,
15669         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15670                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15671         .tokens = {
15672                 (void *)&cmd_set_l2_encap_set,
15673                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15674                 (void *)&cmd_set_l2_encap_ip_version,
15675                 (void *)&cmd_set_l2_encap_ip_version_value,
15676                 (void *)&cmd_set_l2_encap_vlan,
15677                 (void *)&cmd_set_l2_encap_vlan_value,
15678                 (void *)&cmd_set_l2_encap_eth_src,
15679                 (void *)&cmd_set_l2_encap_eth_src_value,
15680                 (void *)&cmd_set_l2_encap_eth_dst,
15681                 (void *)&cmd_set_l2_encap_eth_dst_value,
15682                 NULL,
15683         },
15684 };
15685
15686 /** Set L2 decapsulation details */
15687 struct cmd_set_l2_decap_result {
15688         cmdline_fixed_string_t set;
15689         cmdline_fixed_string_t l2_decap;
15690         cmdline_fixed_string_t pos_token;
15691         uint32_t vlan_present:1;
15692 };
15693
15694 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15695         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15696 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15697         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15698                                  "l2_decap");
15699 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15700         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15701                                  "l2_decap-with-vlan");
15702
15703 static void cmd_set_l2_decap_parsed(void *parsed_result,
15704         __rte_unused struct cmdline *cl,
15705         __rte_unused void *data)
15706 {
15707         struct cmd_set_l2_decap_result *res = parsed_result;
15708
15709         if (strcmp(res->l2_decap, "l2_decap") == 0)
15710                 l2_decap_conf.select_vlan = 0;
15711         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15712                 l2_decap_conf.select_vlan = 1;
15713 }
15714
15715 cmdline_parse_inst_t cmd_set_l2_decap = {
15716         .f = cmd_set_l2_decap_parsed,
15717         .data = NULL,
15718         .help_str = "set l2_decap",
15719         .tokens = {
15720                 (void *)&cmd_set_l2_decap_set,
15721                 (void *)&cmd_set_l2_decap_l2_decap,
15722                 NULL,
15723         },
15724 };
15725
15726 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15727         .f = cmd_set_l2_decap_parsed,
15728         .data = NULL,
15729         .help_str = "set l2_decap-with-vlan",
15730         .tokens = {
15731                 (void *)&cmd_set_l2_decap_set,
15732                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15733                 NULL,
15734         },
15735 };
15736
15737 /** Set MPLSoGRE encapsulation details */
15738 struct cmd_set_mplsogre_encap_result {
15739         cmdline_fixed_string_t set;
15740         cmdline_fixed_string_t mplsogre;
15741         cmdline_fixed_string_t pos_token;
15742         cmdline_fixed_string_t ip_version;
15743         uint32_t vlan_present:1;
15744         uint32_t label;
15745         cmdline_ipaddr_t ip_src;
15746         cmdline_ipaddr_t ip_dst;
15747         uint16_t tci;
15748         struct rte_ether_addr eth_src;
15749         struct rte_ether_addr eth_dst;
15750 };
15751
15752 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15753         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15754                                  "set");
15755 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15756         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15757                                  "mplsogre_encap");
15758 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15759         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15760                                  mplsogre, "mplsogre_encap-with-vlan");
15761 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15762         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15763                                  pos_token, "ip-version");
15764 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15765         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15766                                  ip_version, "ipv4#ipv6");
15767 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15768         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15769                                  pos_token, "label");
15770 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15771         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15772                               UINT32);
15773 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15774         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15775                                  pos_token, "ip-src");
15776 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15777         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15778 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15779         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15780                                  pos_token, "ip-dst");
15781 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15782         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15783 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15784         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15785                                  pos_token, "vlan-tci");
15786 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15787         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15788                               UINT16);
15789 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15790         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15791                                  pos_token, "eth-src");
15792 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15793         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15794                                     eth_src);
15795 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15796         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15797                                  pos_token, "eth-dst");
15798 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15799         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15800                                     eth_dst);
15801
15802 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15803         __rte_unused struct cmdline *cl,
15804         __rte_unused void *data)
15805 {
15806         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15807         union {
15808                 uint32_t mplsogre_label;
15809                 uint8_t label[4];
15810         } id = {
15811                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15812         };
15813
15814         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15815                 mplsogre_encap_conf.select_vlan = 0;
15816         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15817                 mplsogre_encap_conf.select_vlan = 1;
15818         if (strcmp(res->ip_version, "ipv4") == 0)
15819                 mplsogre_encap_conf.select_ipv4 = 1;
15820         else if (strcmp(res->ip_version, "ipv6") == 0)
15821                 mplsogre_encap_conf.select_ipv4 = 0;
15822         else
15823                 return;
15824         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15825         if (mplsogre_encap_conf.select_ipv4) {
15826                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15827                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15828         } else {
15829                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15830                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15831         }
15832         if (mplsogre_encap_conf.select_vlan)
15833                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15834         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15835                    RTE_ETHER_ADDR_LEN);
15836         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15837                    RTE_ETHER_ADDR_LEN);
15838 }
15839
15840 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15841         .f = cmd_set_mplsogre_encap_parsed,
15842         .data = NULL,
15843         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15844                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15845                 " eth-dst <eth-dst>",
15846         .tokens = {
15847                 (void *)&cmd_set_mplsogre_encap_set,
15848                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15849                 (void *)&cmd_set_mplsogre_encap_ip_version,
15850                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15851                 (void *)&cmd_set_mplsogre_encap_label,
15852                 (void *)&cmd_set_mplsogre_encap_label_value,
15853                 (void *)&cmd_set_mplsogre_encap_ip_src,
15854                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15855                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15856                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15857                 (void *)&cmd_set_mplsogre_encap_eth_src,
15858                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15859                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15860                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15861                 NULL,
15862         },
15863 };
15864
15865 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15866         .f = cmd_set_mplsogre_encap_parsed,
15867         .data = NULL,
15868         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15869                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15870                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15871         .tokens = {
15872                 (void *)&cmd_set_mplsogre_encap_set,
15873                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15874                 (void *)&cmd_set_mplsogre_encap_ip_version,
15875                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15876                 (void *)&cmd_set_mplsogre_encap_label,
15877                 (void *)&cmd_set_mplsogre_encap_label_value,
15878                 (void *)&cmd_set_mplsogre_encap_ip_src,
15879                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15880                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15881                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15882                 (void *)&cmd_set_mplsogre_encap_vlan,
15883                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15884                 (void *)&cmd_set_mplsogre_encap_eth_src,
15885                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15886                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15887                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15888                 NULL,
15889         },
15890 };
15891
15892 /** Set MPLSoGRE decapsulation details */
15893 struct cmd_set_mplsogre_decap_result {
15894         cmdline_fixed_string_t set;
15895         cmdline_fixed_string_t mplsogre;
15896         cmdline_fixed_string_t pos_token;
15897         cmdline_fixed_string_t ip_version;
15898         uint32_t vlan_present:1;
15899 };
15900
15901 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15902         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15903                                  "set");
15904 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15905         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
15906                                  "mplsogre_decap");
15907 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
15908         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15909                                  mplsogre, "mplsogre_decap-with-vlan");
15910 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
15911         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15912                                  pos_token, "ip-version");
15913 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
15914         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
15915                                  ip_version, "ipv4#ipv6");
15916
15917 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
15918         __rte_unused struct cmdline *cl,
15919         __rte_unused void *data)
15920 {
15921         struct cmd_set_mplsogre_decap_result *res = parsed_result;
15922
15923         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
15924                 mplsogre_decap_conf.select_vlan = 0;
15925         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
15926                 mplsogre_decap_conf.select_vlan = 1;
15927         if (strcmp(res->ip_version, "ipv4") == 0)
15928                 mplsogre_decap_conf.select_ipv4 = 1;
15929         else if (strcmp(res->ip_version, "ipv6") == 0)
15930                 mplsogre_decap_conf.select_ipv4 = 0;
15931 }
15932
15933 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
15934         .f = cmd_set_mplsogre_decap_parsed,
15935         .data = NULL,
15936         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
15937         .tokens = {
15938                 (void *)&cmd_set_mplsogre_decap_set,
15939                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
15940                 (void *)&cmd_set_mplsogre_decap_ip_version,
15941                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15942                 NULL,
15943         },
15944 };
15945
15946 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
15947         .f = cmd_set_mplsogre_decap_parsed,
15948         .data = NULL,
15949         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
15950         .tokens = {
15951                 (void *)&cmd_set_mplsogre_decap_set,
15952                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
15953                 (void *)&cmd_set_mplsogre_decap_ip_version,
15954                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
15955                 NULL,
15956         },
15957 };
15958
15959 /** Set MPLSoUDP encapsulation details */
15960 struct cmd_set_mplsoudp_encap_result {
15961         cmdline_fixed_string_t set;
15962         cmdline_fixed_string_t mplsoudp;
15963         cmdline_fixed_string_t pos_token;
15964         cmdline_fixed_string_t ip_version;
15965         uint32_t vlan_present:1;
15966         uint32_t label;
15967         uint16_t udp_src;
15968         uint16_t udp_dst;
15969         cmdline_ipaddr_t ip_src;
15970         cmdline_ipaddr_t ip_dst;
15971         uint16_t tci;
15972         struct rte_ether_addr eth_src;
15973         struct rte_ether_addr eth_dst;
15974 };
15975
15976 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
15977         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
15978                                  "set");
15979 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
15980         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
15981                                  "mplsoudp_encap");
15982 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
15983         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15984                                  mplsoudp, "mplsoudp_encap-with-vlan");
15985 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
15986         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15987                                  pos_token, "ip-version");
15988 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
15989         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15990                                  ip_version, "ipv4#ipv6");
15991 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
15992         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15993                                  pos_token, "label");
15994 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
15995         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
15996                               UINT32);
15997 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
15998         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15999                                  pos_token, "udp-src");
16000 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16001         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16002                               UINT16);
16003 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16004         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16005                                  pos_token, "udp-dst");
16006 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16007         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16008                               UINT16);
16009 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16010         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16011                                  pos_token, "ip-src");
16012 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16013         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16014 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16015         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16016                                  pos_token, "ip-dst");
16017 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16018         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16019 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16020         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16021                                  pos_token, "vlan-tci");
16022 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16023         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16024                               UINT16);
16025 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16026         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16027                                  pos_token, "eth-src");
16028 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16029         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16030                                     eth_src);
16031 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16032         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16033                                  pos_token, "eth-dst");
16034 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16035         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16036                                     eth_dst);
16037
16038 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16039         __rte_unused struct cmdline *cl,
16040         __rte_unused void *data)
16041 {
16042         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16043         union {
16044                 uint32_t mplsoudp_label;
16045                 uint8_t label[4];
16046         } id = {
16047                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16048         };
16049
16050         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16051                 mplsoudp_encap_conf.select_vlan = 0;
16052         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16053                 mplsoudp_encap_conf.select_vlan = 1;
16054         if (strcmp(res->ip_version, "ipv4") == 0)
16055                 mplsoudp_encap_conf.select_ipv4 = 1;
16056         else if (strcmp(res->ip_version, "ipv6") == 0)
16057                 mplsoudp_encap_conf.select_ipv4 = 0;
16058         else
16059                 return;
16060         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16061         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16062         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16063         if (mplsoudp_encap_conf.select_ipv4) {
16064                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16065                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16066         } else {
16067                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16068                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16069         }
16070         if (mplsoudp_encap_conf.select_vlan)
16071                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16072         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16073                    RTE_ETHER_ADDR_LEN);
16074         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16075                    RTE_ETHER_ADDR_LEN);
16076 }
16077
16078 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16079         .f = cmd_set_mplsoudp_encap_parsed,
16080         .data = NULL,
16081         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16082                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16083                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16084         .tokens = {
16085                 (void *)&cmd_set_mplsoudp_encap_set,
16086                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16087                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16088                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16089                 (void *)&cmd_set_mplsoudp_encap_label,
16090                 (void *)&cmd_set_mplsoudp_encap_label_value,
16091                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16092                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16093                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16094                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16095                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16096                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16097                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16098                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16099                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16100                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16101                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16102                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16103                 NULL,
16104         },
16105 };
16106
16107 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16108         .f = cmd_set_mplsoudp_encap_parsed,
16109         .data = NULL,
16110         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16111                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16112                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16113                 " eth-src <eth-src> eth-dst <eth-dst>",
16114         .tokens = {
16115                 (void *)&cmd_set_mplsoudp_encap_set,
16116                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16117                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16118                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16119                 (void *)&cmd_set_mplsoudp_encap_label,
16120                 (void *)&cmd_set_mplsoudp_encap_label_value,
16121                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16122                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16123                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16124                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16125                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16126                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16127                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16128                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16129                 (void *)&cmd_set_mplsoudp_encap_vlan,
16130                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16131                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16132                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16133                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16134                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16135                 NULL,
16136         },
16137 };
16138
16139 /** Set MPLSoUDP decapsulation details */
16140 struct cmd_set_mplsoudp_decap_result {
16141         cmdline_fixed_string_t set;
16142         cmdline_fixed_string_t mplsoudp;
16143         cmdline_fixed_string_t pos_token;
16144         cmdline_fixed_string_t ip_version;
16145         uint32_t vlan_present:1;
16146 };
16147
16148 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16149         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16150                                  "set");
16151 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16152         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16153                                  "mplsoudp_decap");
16154 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16155         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16156                                  mplsoudp, "mplsoudp_decap-with-vlan");
16157 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16158         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16159                                  pos_token, "ip-version");
16160 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16161         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16162                                  ip_version, "ipv4#ipv6");
16163
16164 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16165         __rte_unused struct cmdline *cl,
16166         __rte_unused void *data)
16167 {
16168         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16169
16170         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16171                 mplsoudp_decap_conf.select_vlan = 0;
16172         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16173                 mplsoudp_decap_conf.select_vlan = 1;
16174         if (strcmp(res->ip_version, "ipv4") == 0)
16175                 mplsoudp_decap_conf.select_ipv4 = 1;
16176         else if (strcmp(res->ip_version, "ipv6") == 0)
16177                 mplsoudp_decap_conf.select_ipv4 = 0;
16178 }
16179
16180 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16181         .f = cmd_set_mplsoudp_decap_parsed,
16182         .data = NULL,
16183         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16184         .tokens = {
16185                 (void *)&cmd_set_mplsoudp_decap_set,
16186                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16187                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16188                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16189                 NULL,
16190         },
16191 };
16192
16193 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16194         .f = cmd_set_mplsoudp_decap_parsed,
16195         .data = NULL,
16196         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16197         .tokens = {
16198                 (void *)&cmd_set_mplsoudp_decap_set,
16199                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16200                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16201                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16202                 NULL,
16203         },
16204 };
16205
16206 /* Strict link priority scheduling mode setting */
16207 static void
16208 cmd_strict_link_prio_parsed(
16209         void *parsed_result,
16210         __rte_unused struct cmdline *cl,
16211         __rte_unused void *data)
16212 {
16213         struct cmd_vf_tc_bw_result *res = parsed_result;
16214         int ret = -ENOTSUP;
16215
16216         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16217                 return;
16218
16219 #ifdef RTE_NET_I40E
16220         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16221 #endif
16222
16223         switch (ret) {
16224         case 0:
16225                 break;
16226         case -EINVAL:
16227                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16228                 break;
16229         case -ENODEV:
16230                 printf("invalid port_id %d\n", res->port_id);
16231                 break;
16232         case -ENOTSUP:
16233                 printf("function not implemented\n");
16234                 break;
16235         default:
16236                 printf("programming error: (%s)\n", strerror(-ret));
16237         }
16238 }
16239
16240 cmdline_parse_inst_t cmd_strict_link_prio = {
16241         .f = cmd_strict_link_prio_parsed,
16242         .data = NULL,
16243         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16244         .tokens = {
16245                 (void *)&cmd_vf_tc_bw_set,
16246                 (void *)&cmd_vf_tc_bw_tx,
16247                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16248                 (void *)&cmd_vf_tc_bw_port_id,
16249                 (void *)&cmd_vf_tc_bw_tc_map,
16250                 NULL,
16251         },
16252 };
16253
16254 /* Load dynamic device personalization*/
16255 struct cmd_ddp_add_result {
16256         cmdline_fixed_string_t ddp;
16257         cmdline_fixed_string_t add;
16258         portid_t port_id;
16259         char filepath[];
16260 };
16261
16262 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16263         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16264 cmdline_parse_token_string_t cmd_ddp_add_add =
16265         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16266 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16267         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16268 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16269         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16270
16271 static void
16272 cmd_ddp_add_parsed(
16273         void *parsed_result,
16274         __rte_unused struct cmdline *cl,
16275         __rte_unused void *data)
16276 {
16277         struct cmd_ddp_add_result *res = parsed_result;
16278         uint8_t *buff;
16279         uint32_t size;
16280         char *filepath;
16281         char *file_fld[2];
16282         int file_num;
16283         int ret = -ENOTSUP;
16284
16285         if (!all_ports_stopped()) {
16286                 printf("Please stop all ports first\n");
16287                 return;
16288         }
16289
16290         filepath = strdup(res->filepath);
16291         if (filepath == NULL) {
16292                 printf("Failed to allocate memory\n");
16293                 return;
16294         }
16295         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16296
16297         buff = open_file(file_fld[0], &size);
16298         if (!buff) {
16299                 free((void *)filepath);
16300                 return;
16301         }
16302
16303 #ifdef RTE_NET_I40E
16304         if (ret == -ENOTSUP)
16305                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16306                                                buff, size,
16307                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16308 #endif
16309
16310         if (ret == -EEXIST)
16311                 printf("Profile has already existed.\n");
16312         else if (ret < 0)
16313                 printf("Failed to load profile.\n");
16314         else if (file_num == 2)
16315                 save_file(file_fld[1], buff, size);
16316
16317         close_file(buff);
16318         free((void *)filepath);
16319 }
16320
16321 cmdline_parse_inst_t cmd_ddp_add = {
16322         .f = cmd_ddp_add_parsed,
16323         .data = NULL,
16324         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16325         .tokens = {
16326                 (void *)&cmd_ddp_add_ddp,
16327                 (void *)&cmd_ddp_add_add,
16328                 (void *)&cmd_ddp_add_port_id,
16329                 (void *)&cmd_ddp_add_filepath,
16330                 NULL,
16331         },
16332 };
16333
16334 /* Delete dynamic device personalization*/
16335 struct cmd_ddp_del_result {
16336         cmdline_fixed_string_t ddp;
16337         cmdline_fixed_string_t del;
16338         portid_t port_id;
16339         char filepath[];
16340 };
16341
16342 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16343         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16344 cmdline_parse_token_string_t cmd_ddp_del_del =
16345         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16346 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16347         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16348 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16349         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16350
16351 static void
16352 cmd_ddp_del_parsed(
16353         void *parsed_result,
16354         __rte_unused struct cmdline *cl,
16355         __rte_unused void *data)
16356 {
16357         struct cmd_ddp_del_result *res = parsed_result;
16358         uint8_t *buff;
16359         uint32_t size;
16360         int ret = -ENOTSUP;
16361
16362         if (!all_ports_stopped()) {
16363                 printf("Please stop all ports first\n");
16364                 return;
16365         }
16366
16367         buff = open_file(res->filepath, &size);
16368         if (!buff)
16369                 return;
16370
16371 #ifdef RTE_NET_I40E
16372         if (ret == -ENOTSUP)
16373                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16374                                                buff, size,
16375                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16376 #endif
16377
16378         if (ret == -EACCES)
16379                 printf("Profile does not exist.\n");
16380         else if (ret < 0)
16381                 printf("Failed to delete profile.\n");
16382
16383         close_file(buff);
16384 }
16385
16386 cmdline_parse_inst_t cmd_ddp_del = {
16387         .f = cmd_ddp_del_parsed,
16388         .data = NULL,
16389         .help_str = "ddp del <port_id> <backup_profile_path>",
16390         .tokens = {
16391                 (void *)&cmd_ddp_del_ddp,
16392                 (void *)&cmd_ddp_del_del,
16393                 (void *)&cmd_ddp_del_port_id,
16394                 (void *)&cmd_ddp_del_filepath,
16395                 NULL,
16396         },
16397 };
16398
16399 /* Get dynamic device personalization profile info */
16400 struct cmd_ddp_info_result {
16401         cmdline_fixed_string_t ddp;
16402         cmdline_fixed_string_t get;
16403         cmdline_fixed_string_t info;
16404         char filepath[];
16405 };
16406
16407 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16408         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16409 cmdline_parse_token_string_t cmd_ddp_info_get =
16410         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16411 cmdline_parse_token_string_t cmd_ddp_info_info =
16412         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16413 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16414         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16415
16416 static void
16417 cmd_ddp_info_parsed(
16418         void *parsed_result,
16419         __rte_unused struct cmdline *cl,
16420         __rte_unused void *data)
16421 {
16422         struct cmd_ddp_info_result *res = parsed_result;
16423         uint8_t *pkg;
16424         uint32_t pkg_size;
16425         int ret = -ENOTSUP;
16426 #ifdef RTE_NET_I40E
16427         uint32_t i, j, n;
16428         uint8_t *buff;
16429         uint32_t buff_size = 0;
16430         struct rte_pmd_i40e_profile_info info;
16431         uint32_t dev_num = 0;
16432         struct rte_pmd_i40e_ddp_device_id *devs;
16433         uint32_t proto_num = 0;
16434         struct rte_pmd_i40e_proto_info *proto = NULL;
16435         uint32_t pctype_num = 0;
16436         struct rte_pmd_i40e_ptype_info *pctype;
16437         uint32_t ptype_num = 0;
16438         struct rte_pmd_i40e_ptype_info *ptype;
16439         uint8_t proto_id;
16440
16441 #endif
16442
16443         pkg = open_file(res->filepath, &pkg_size);
16444         if (!pkg)
16445                 return;
16446
16447 #ifdef RTE_NET_I40E
16448         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16449                                 (uint8_t *)&info, sizeof(info),
16450                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16451         if (!ret) {
16452                 printf("Global Track id:       0x%x\n", info.track_id);
16453                 printf("Global Version:        %d.%d.%d.%d\n",
16454                         info.version.major,
16455                         info.version.minor,
16456                         info.version.update,
16457                         info.version.draft);
16458                 printf("Global Package name:   %s\n\n", info.name);
16459         }
16460
16461         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16462                                 (uint8_t *)&info, sizeof(info),
16463                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16464         if (!ret) {
16465                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16466                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16467                         info.version.major,
16468                         info.version.minor,
16469                         info.version.update,
16470                         info.version.draft);
16471                 printf("i40e Profile name:     %s\n\n", info.name);
16472         }
16473
16474         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16475                                 (uint8_t *)&buff_size, sizeof(buff_size),
16476                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16477         if (!ret && buff_size) {
16478                 buff = (uint8_t *)malloc(buff_size);
16479                 if (buff) {
16480                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16481                                                 buff, buff_size,
16482                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16483                         if (!ret)
16484                                 printf("Package Notes:\n%s\n\n", buff);
16485                         free(buff);
16486                 }
16487         }
16488
16489         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16490                                 (uint8_t *)&dev_num, sizeof(dev_num),
16491                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16492         if (!ret && dev_num) {
16493                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16494                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16495                 if (devs) {
16496                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16497                                                 (uint8_t *)devs, buff_size,
16498                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16499                         if (!ret) {
16500                                 printf("List of supported devices:\n");
16501                                 for (i = 0; i < dev_num; i++) {
16502                                         printf("  %04X:%04X %04X:%04X\n",
16503                                                 devs[i].vendor_dev_id >> 16,
16504                                                 devs[i].vendor_dev_id & 0xFFFF,
16505                                                 devs[i].sub_vendor_dev_id >> 16,
16506                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16507                                 }
16508                                 printf("\n");
16509                         }
16510                         free(devs);
16511                 }
16512         }
16513
16514         /* get information about protocols and packet types */
16515         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16516                 (uint8_t *)&proto_num, sizeof(proto_num),
16517                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16518         if (ret || !proto_num)
16519                 goto no_print_return;
16520
16521         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16522         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16523         if (!proto)
16524                 goto no_print_return;
16525
16526         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16527                                         buff_size,
16528                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16529         if (!ret) {
16530                 printf("List of used protocols:\n");
16531                 for (i = 0; i < proto_num; i++)
16532                         printf("  %2u: %s\n", proto[i].proto_id,
16533                                proto[i].name);
16534                 printf("\n");
16535         }
16536         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16537                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16538                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16539         if (ret || !pctype_num)
16540                 goto no_print_pctypes;
16541
16542         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16543         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16544         if (!pctype)
16545                 goto no_print_pctypes;
16546
16547         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16548                                         buff_size,
16549                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16550         if (ret) {
16551                 free(pctype);
16552                 goto no_print_pctypes;
16553         }
16554
16555         printf("List of defined packet classification types:\n");
16556         for (i = 0; i < pctype_num; i++) {
16557                 printf("  %2u:", pctype[i].ptype_id);
16558                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16559                         proto_id = pctype[i].protocols[j];
16560                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16561                                 for (n = 0; n < proto_num; n++) {
16562                                         if (proto[n].proto_id == proto_id) {
16563                                                 printf(" %s", proto[n].name);
16564                                                 break;
16565                                         }
16566                                 }
16567                         }
16568                 }
16569                 printf("\n");
16570         }
16571         printf("\n");
16572         free(pctype);
16573
16574 no_print_pctypes:
16575
16576         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16577                                         sizeof(ptype_num),
16578                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16579         if (ret || !ptype_num)
16580                 goto no_print_return;
16581
16582         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16583         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16584         if (!ptype)
16585                 goto no_print_return;
16586
16587         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16588                                         buff_size,
16589                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16590         if (ret) {
16591                 free(ptype);
16592                 goto no_print_return;
16593         }
16594         printf("List of defined packet types:\n");
16595         for (i = 0; i < ptype_num; i++) {
16596                 printf("  %2u:", ptype[i].ptype_id);
16597                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16598                         proto_id = ptype[i].protocols[j];
16599                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16600                                 for (n = 0; n < proto_num; n++) {
16601                                         if (proto[n].proto_id == proto_id) {
16602                                                 printf(" %s", proto[n].name);
16603                                                 break;
16604                                         }
16605                                 }
16606                         }
16607                 }
16608                 printf("\n");
16609         }
16610         free(ptype);
16611         printf("\n");
16612
16613         ret = 0;
16614 no_print_return:
16615         if (proto)
16616                 free(proto);
16617 #endif
16618         if (ret == -ENOTSUP)
16619                 printf("Function not supported in PMD driver\n");
16620         close_file(pkg);
16621 }
16622
16623 cmdline_parse_inst_t cmd_ddp_get_info = {
16624         .f = cmd_ddp_info_parsed,
16625         .data = NULL,
16626         .help_str = "ddp get info <profile_path>",
16627         .tokens = {
16628                 (void *)&cmd_ddp_info_ddp,
16629                 (void *)&cmd_ddp_info_get,
16630                 (void *)&cmd_ddp_info_info,
16631                 (void *)&cmd_ddp_info_filepath,
16632                 NULL,
16633         },
16634 };
16635
16636 /* Get dynamic device personalization profile info list*/
16637 #define PROFILE_INFO_SIZE 48
16638 #define MAX_PROFILE_NUM 16
16639
16640 struct cmd_ddp_get_list_result {
16641         cmdline_fixed_string_t ddp;
16642         cmdline_fixed_string_t get;
16643         cmdline_fixed_string_t list;
16644         portid_t port_id;
16645 };
16646
16647 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16648         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16649 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16650         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16651 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16652         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16653 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16654         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16655
16656 static void
16657 cmd_ddp_get_list_parsed(
16658         __rte_unused void *parsed_result,
16659         __rte_unused struct cmdline *cl,
16660         __rte_unused void *data)
16661 {
16662 #ifdef RTE_NET_I40E
16663         struct cmd_ddp_get_list_result *res = parsed_result;
16664         struct rte_pmd_i40e_profile_list *p_list;
16665         struct rte_pmd_i40e_profile_info *p_info;
16666         uint32_t p_num;
16667         uint32_t size;
16668         uint32_t i;
16669 #endif
16670         int ret = -ENOTSUP;
16671
16672 #ifdef RTE_NET_I40E
16673         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16674         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16675         if (!p_list) {
16676                 printf("%s: Failed to malloc buffer\n", __func__);
16677                 return;
16678         }
16679
16680         if (ret == -ENOTSUP)
16681                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16682                                                 (uint8_t *)p_list, size);
16683
16684         if (!ret) {
16685                 p_num = p_list->p_count;
16686                 printf("Profile number is: %d\n\n", p_num);
16687
16688                 for (i = 0; i < p_num; i++) {
16689                         p_info = &p_list->p_info[i];
16690                         printf("Profile %d:\n", i);
16691                         printf("Track id:     0x%x\n", p_info->track_id);
16692                         printf("Version:      %d.%d.%d.%d\n",
16693                                p_info->version.major,
16694                                p_info->version.minor,
16695                                p_info->version.update,
16696                                p_info->version.draft);
16697                         printf("Profile name: %s\n\n", p_info->name);
16698                 }
16699         }
16700
16701         free(p_list);
16702 #endif
16703
16704         if (ret < 0)
16705                 printf("Failed to get ddp list\n");
16706 }
16707
16708 cmdline_parse_inst_t cmd_ddp_get_list = {
16709         .f = cmd_ddp_get_list_parsed,
16710         .data = NULL,
16711         .help_str = "ddp get list <port_id>",
16712         .tokens = {
16713                 (void *)&cmd_ddp_get_list_ddp,
16714                 (void *)&cmd_ddp_get_list_get,
16715                 (void *)&cmd_ddp_get_list_list,
16716                 (void *)&cmd_ddp_get_list_port_id,
16717                 NULL,
16718         },
16719 };
16720
16721 /* Configure input set */
16722 struct cmd_cfg_input_set_result {
16723         cmdline_fixed_string_t port;
16724         cmdline_fixed_string_t cfg;
16725         portid_t port_id;
16726         cmdline_fixed_string_t pctype;
16727         uint8_t pctype_id;
16728         cmdline_fixed_string_t inset_type;
16729         cmdline_fixed_string_t opt;
16730         cmdline_fixed_string_t field;
16731         uint8_t field_idx;
16732 };
16733
16734 static void
16735 cmd_cfg_input_set_parsed(
16736         __rte_unused void *parsed_result,
16737         __rte_unused struct cmdline *cl,
16738         __rte_unused void *data)
16739 {
16740 #ifdef RTE_NET_I40E
16741         struct cmd_cfg_input_set_result *res = parsed_result;
16742         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16743         struct rte_pmd_i40e_inset inset;
16744 #endif
16745         int ret = -ENOTSUP;
16746
16747         if (!all_ports_stopped()) {
16748                 printf("Please stop all ports first\n");
16749                 return;
16750         }
16751
16752 #ifdef RTE_NET_I40E
16753         if (!strcmp(res->inset_type, "hash_inset"))
16754                 inset_type = INSET_HASH;
16755         else if (!strcmp(res->inset_type, "fdir_inset"))
16756                 inset_type = INSET_FDIR;
16757         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16758                 inset_type = INSET_FDIR_FLX;
16759         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16760                                      &inset, inset_type);
16761         if (ret) {
16762                 printf("Failed to get input set.\n");
16763                 return;
16764         }
16765
16766         if (!strcmp(res->opt, "get")) {
16767                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16768                                                    res->field_idx);
16769                 if (ret)
16770                         printf("Field index %d is enabled.\n", res->field_idx);
16771                 else
16772                         printf("Field index %d is disabled.\n", res->field_idx);
16773                 return;
16774         } else if (!strcmp(res->opt, "set"))
16775                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16776                                                    res->field_idx);
16777         else if (!strcmp(res->opt, "clear"))
16778                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16779                                                      res->field_idx);
16780         if (ret) {
16781                 printf("Failed to configure input set field.\n");
16782                 return;
16783         }
16784
16785         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16786                                      &inset, inset_type);
16787         if (ret) {
16788                 printf("Failed to set input set.\n");
16789                 return;
16790         }
16791 #endif
16792
16793         if (ret == -ENOTSUP)
16794                 printf("Function not supported\n");
16795 }
16796
16797 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16798         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16799                                  port, "port");
16800 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16801         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16802                                  cfg, "config");
16803 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16804         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16805                               port_id, UINT16);
16806 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16807         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16808                                  pctype, "pctype");
16809 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16810         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16811                               pctype_id, UINT8);
16812 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16813         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16814                                  inset_type,
16815                                  "hash_inset#fdir_inset#fdir_flx_inset");
16816 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16817         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16818                                  opt, "get#set#clear");
16819 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16820         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16821                                  field, "field");
16822 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16823         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16824                               field_idx, UINT8);
16825
16826 cmdline_parse_inst_t cmd_cfg_input_set = {
16827         .f = cmd_cfg_input_set_parsed,
16828         .data = NULL,
16829         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16830                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16831         .tokens = {
16832                 (void *)&cmd_cfg_input_set_port,
16833                 (void *)&cmd_cfg_input_set_cfg,
16834                 (void *)&cmd_cfg_input_set_port_id,
16835                 (void *)&cmd_cfg_input_set_pctype,
16836                 (void *)&cmd_cfg_input_set_pctype_id,
16837                 (void *)&cmd_cfg_input_set_inset_type,
16838                 (void *)&cmd_cfg_input_set_opt,
16839                 (void *)&cmd_cfg_input_set_field,
16840                 (void *)&cmd_cfg_input_set_field_idx,
16841                 NULL,
16842         },
16843 };
16844
16845 /* Clear input set */
16846 struct cmd_clear_input_set_result {
16847         cmdline_fixed_string_t port;
16848         cmdline_fixed_string_t cfg;
16849         portid_t port_id;
16850         cmdline_fixed_string_t pctype;
16851         uint8_t pctype_id;
16852         cmdline_fixed_string_t inset_type;
16853         cmdline_fixed_string_t clear;
16854         cmdline_fixed_string_t all;
16855 };
16856
16857 static void
16858 cmd_clear_input_set_parsed(
16859         __rte_unused void *parsed_result,
16860         __rte_unused struct cmdline *cl,
16861         __rte_unused void *data)
16862 {
16863 #ifdef RTE_NET_I40E
16864         struct cmd_clear_input_set_result *res = parsed_result;
16865         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16866         struct rte_pmd_i40e_inset inset;
16867 #endif
16868         int ret = -ENOTSUP;
16869
16870         if (!all_ports_stopped()) {
16871                 printf("Please stop all ports first\n");
16872                 return;
16873         }
16874
16875 #ifdef RTE_NET_I40E
16876         if (!strcmp(res->inset_type, "hash_inset"))
16877                 inset_type = INSET_HASH;
16878         else if (!strcmp(res->inset_type, "fdir_inset"))
16879                 inset_type = INSET_FDIR;
16880         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16881                 inset_type = INSET_FDIR_FLX;
16882
16883         memset(&inset, 0, sizeof(inset));
16884
16885         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16886                                      &inset, inset_type);
16887         if (ret) {
16888                 printf("Failed to clear input set.\n");
16889                 return;
16890         }
16891
16892 #endif
16893
16894         if (ret == -ENOTSUP)
16895                 printf("Function not supported\n");
16896 }
16897
16898 cmdline_parse_token_string_t cmd_clear_input_set_port =
16899         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16900                                  port, "port");
16901 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16902         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16903                                  cfg, "config");
16904 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16905         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16906                               port_id, UINT16);
16907 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
16908         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16909                                  pctype, "pctype");
16910 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
16911         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
16912                               pctype_id, UINT8);
16913 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
16914         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16915                                  inset_type,
16916                                  "hash_inset#fdir_inset#fdir_flx_inset");
16917 cmdline_parse_token_string_t cmd_clear_input_set_clear =
16918         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16919                                  clear, "clear");
16920 cmdline_parse_token_string_t cmd_clear_input_set_all =
16921         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16922                                  all, "all");
16923
16924 cmdline_parse_inst_t cmd_clear_input_set = {
16925         .f = cmd_clear_input_set_parsed,
16926         .data = NULL,
16927         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16928                     "fdir_inset|fdir_flx_inset clear all",
16929         .tokens = {
16930                 (void *)&cmd_clear_input_set_port,
16931                 (void *)&cmd_clear_input_set_cfg,
16932                 (void *)&cmd_clear_input_set_port_id,
16933                 (void *)&cmd_clear_input_set_pctype,
16934                 (void *)&cmd_clear_input_set_pctype_id,
16935                 (void *)&cmd_clear_input_set_inset_type,
16936                 (void *)&cmd_clear_input_set_clear,
16937                 (void *)&cmd_clear_input_set_all,
16938                 NULL,
16939         },
16940 };
16941
16942 /* show vf stats */
16943
16944 /* Common result structure for show vf stats */
16945 struct cmd_show_vf_stats_result {
16946         cmdline_fixed_string_t show;
16947         cmdline_fixed_string_t vf;
16948         cmdline_fixed_string_t stats;
16949         portid_t port_id;
16950         uint16_t vf_id;
16951 };
16952
16953 /* Common CLI fields show vf stats*/
16954 cmdline_parse_token_string_t cmd_show_vf_stats_show =
16955         TOKEN_STRING_INITIALIZER
16956                 (struct cmd_show_vf_stats_result,
16957                  show, "show");
16958 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16959         TOKEN_STRING_INITIALIZER
16960                 (struct cmd_show_vf_stats_result,
16961                  vf, "vf");
16962 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
16963         TOKEN_STRING_INITIALIZER
16964                 (struct cmd_show_vf_stats_result,
16965                  stats, "stats");
16966 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
16967         TOKEN_NUM_INITIALIZER
16968                 (struct cmd_show_vf_stats_result,
16969                  port_id, UINT16);
16970 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
16971         TOKEN_NUM_INITIALIZER
16972                 (struct cmd_show_vf_stats_result,
16973                  vf_id, UINT16);
16974
16975 static void
16976 cmd_show_vf_stats_parsed(
16977         void *parsed_result,
16978         __rte_unused struct cmdline *cl,
16979         __rte_unused void *data)
16980 {
16981         struct cmd_show_vf_stats_result *res = parsed_result;
16982         struct rte_eth_stats stats;
16983         int ret = -ENOTSUP;
16984         static const char *nic_stats_border = "########################";
16985
16986         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16987                 return;
16988
16989         memset(&stats, 0, sizeof(stats));
16990
16991 #ifdef RTE_NET_I40E
16992         if (ret == -ENOTSUP)
16993                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
16994                                                 res->vf_id,
16995                                                 &stats);
16996 #endif
16997 #ifdef RTE_NET_BNXT
16998         if (ret == -ENOTSUP)
16999                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17000                                                 res->vf_id,
17001                                                 &stats);
17002 #endif
17003
17004         switch (ret) {
17005         case 0:
17006                 break;
17007         case -EINVAL:
17008                 printf("invalid vf_id %d\n", res->vf_id);
17009                 break;
17010         case -ENODEV:
17011                 printf("invalid port_id %d\n", res->port_id);
17012                 break;
17013         case -ENOTSUP:
17014                 printf("function not implemented\n");
17015                 break;
17016         default:
17017                 printf("programming error: (%s)\n", strerror(-ret));
17018         }
17019
17020         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17021                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17022
17023         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17024                "%-"PRIu64"\n",
17025                stats.ipackets, stats.imissed, stats.ibytes);
17026         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17027         printf("  RX-nombuf:  %-10"PRIu64"\n",
17028                stats.rx_nombuf);
17029         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17030                "%-"PRIu64"\n",
17031                stats.opackets, stats.oerrors, stats.obytes);
17032
17033         printf("  %s############################%s\n",
17034                                nic_stats_border, nic_stats_border);
17035 }
17036
17037 cmdline_parse_inst_t cmd_show_vf_stats = {
17038         .f = cmd_show_vf_stats_parsed,
17039         .data = NULL,
17040         .help_str = "show vf stats <port_id> <vf_id>",
17041         .tokens = {
17042                 (void *)&cmd_show_vf_stats_show,
17043                 (void *)&cmd_show_vf_stats_vf,
17044                 (void *)&cmd_show_vf_stats_stats,
17045                 (void *)&cmd_show_vf_stats_port_id,
17046                 (void *)&cmd_show_vf_stats_vf_id,
17047                 NULL,
17048         },
17049 };
17050
17051 /* clear vf stats */
17052
17053 /* Common result structure for clear vf stats */
17054 struct cmd_clear_vf_stats_result {
17055         cmdline_fixed_string_t clear;
17056         cmdline_fixed_string_t vf;
17057         cmdline_fixed_string_t stats;
17058         portid_t port_id;
17059         uint16_t vf_id;
17060 };
17061
17062 /* Common CLI fields clear vf stats*/
17063 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17064         TOKEN_STRING_INITIALIZER
17065                 (struct cmd_clear_vf_stats_result,
17066                  clear, "clear");
17067 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17068         TOKEN_STRING_INITIALIZER
17069                 (struct cmd_clear_vf_stats_result,
17070                  vf, "vf");
17071 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17072         TOKEN_STRING_INITIALIZER
17073                 (struct cmd_clear_vf_stats_result,
17074                  stats, "stats");
17075 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17076         TOKEN_NUM_INITIALIZER
17077                 (struct cmd_clear_vf_stats_result,
17078                  port_id, UINT16);
17079 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17080         TOKEN_NUM_INITIALIZER
17081                 (struct cmd_clear_vf_stats_result,
17082                  vf_id, UINT16);
17083
17084 static void
17085 cmd_clear_vf_stats_parsed(
17086         void *parsed_result,
17087         __rte_unused struct cmdline *cl,
17088         __rte_unused void *data)
17089 {
17090         struct cmd_clear_vf_stats_result *res = parsed_result;
17091         int ret = -ENOTSUP;
17092
17093         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17094                 return;
17095
17096 #ifdef RTE_NET_I40E
17097         if (ret == -ENOTSUP)
17098                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17099                                                   res->vf_id);
17100 #endif
17101 #ifdef RTE_NET_BNXT
17102         if (ret == -ENOTSUP)
17103                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17104                                                   res->vf_id);
17105 #endif
17106
17107         switch (ret) {
17108         case 0:
17109                 break;
17110         case -EINVAL:
17111                 printf("invalid vf_id %d\n", res->vf_id);
17112                 break;
17113         case -ENODEV:
17114                 printf("invalid port_id %d\n", res->port_id);
17115                 break;
17116         case -ENOTSUP:
17117                 printf("function not implemented\n");
17118                 break;
17119         default:
17120                 printf("programming error: (%s)\n", strerror(-ret));
17121         }
17122 }
17123
17124 cmdline_parse_inst_t cmd_clear_vf_stats = {
17125         .f = cmd_clear_vf_stats_parsed,
17126         .data = NULL,
17127         .help_str = "clear vf stats <port_id> <vf_id>",
17128         .tokens = {
17129                 (void *)&cmd_clear_vf_stats_clear,
17130                 (void *)&cmd_clear_vf_stats_vf,
17131                 (void *)&cmd_clear_vf_stats_stats,
17132                 (void *)&cmd_clear_vf_stats_port_id,
17133                 (void *)&cmd_clear_vf_stats_vf_id,
17134                 NULL,
17135         },
17136 };
17137
17138 /* port config pctype mapping reset */
17139
17140 /* Common result structure for port config pctype mapping reset */
17141 struct cmd_pctype_mapping_reset_result {
17142         cmdline_fixed_string_t port;
17143         cmdline_fixed_string_t config;
17144         portid_t port_id;
17145         cmdline_fixed_string_t pctype;
17146         cmdline_fixed_string_t mapping;
17147         cmdline_fixed_string_t reset;
17148 };
17149
17150 /* Common CLI fields for port config pctype mapping reset*/
17151 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17152         TOKEN_STRING_INITIALIZER
17153                 (struct cmd_pctype_mapping_reset_result,
17154                  port, "port");
17155 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17156         TOKEN_STRING_INITIALIZER
17157                 (struct cmd_pctype_mapping_reset_result,
17158                  config, "config");
17159 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17160         TOKEN_NUM_INITIALIZER
17161                 (struct cmd_pctype_mapping_reset_result,
17162                  port_id, UINT16);
17163 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17164         TOKEN_STRING_INITIALIZER
17165                 (struct cmd_pctype_mapping_reset_result,
17166                  pctype, "pctype");
17167 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17168         TOKEN_STRING_INITIALIZER
17169                 (struct cmd_pctype_mapping_reset_result,
17170                  mapping, "mapping");
17171 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17172         TOKEN_STRING_INITIALIZER
17173                 (struct cmd_pctype_mapping_reset_result,
17174                  reset, "reset");
17175
17176 static void
17177 cmd_pctype_mapping_reset_parsed(
17178         void *parsed_result,
17179         __rte_unused struct cmdline *cl,
17180         __rte_unused void *data)
17181 {
17182         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17183         int ret = -ENOTSUP;
17184
17185         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17186                 return;
17187
17188 #ifdef RTE_NET_I40E
17189         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17190 #endif
17191
17192         switch (ret) {
17193         case 0:
17194                 break;
17195         case -ENODEV:
17196                 printf("invalid port_id %d\n", res->port_id);
17197                 break;
17198         case -ENOTSUP:
17199                 printf("function not implemented\n");
17200                 break;
17201         default:
17202                 printf("programming error: (%s)\n", strerror(-ret));
17203         }
17204 }
17205
17206 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17207         .f = cmd_pctype_mapping_reset_parsed,
17208         .data = NULL,
17209         .help_str = "port config <port_id> pctype mapping reset",
17210         .tokens = {
17211                 (void *)&cmd_pctype_mapping_reset_port,
17212                 (void *)&cmd_pctype_mapping_reset_config,
17213                 (void *)&cmd_pctype_mapping_reset_port_id,
17214                 (void *)&cmd_pctype_mapping_reset_pctype,
17215                 (void *)&cmd_pctype_mapping_reset_mapping,
17216                 (void *)&cmd_pctype_mapping_reset_reset,
17217                 NULL,
17218         },
17219 };
17220
17221 /* show port pctype mapping */
17222
17223 /* Common result structure for show port pctype mapping */
17224 struct cmd_pctype_mapping_get_result {
17225         cmdline_fixed_string_t show;
17226         cmdline_fixed_string_t port;
17227         portid_t port_id;
17228         cmdline_fixed_string_t pctype;
17229         cmdline_fixed_string_t mapping;
17230 };
17231
17232 /* Common CLI fields for pctype mapping get */
17233 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17234         TOKEN_STRING_INITIALIZER
17235                 (struct cmd_pctype_mapping_get_result,
17236                  show, "show");
17237 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17238         TOKEN_STRING_INITIALIZER
17239                 (struct cmd_pctype_mapping_get_result,
17240                  port, "port");
17241 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17242         TOKEN_NUM_INITIALIZER
17243                 (struct cmd_pctype_mapping_get_result,
17244                  port_id, UINT16);
17245 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17246         TOKEN_STRING_INITIALIZER
17247                 (struct cmd_pctype_mapping_get_result,
17248                  pctype, "pctype");
17249 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17250         TOKEN_STRING_INITIALIZER
17251                 (struct cmd_pctype_mapping_get_result,
17252                  mapping, "mapping");
17253
17254 static void
17255 cmd_pctype_mapping_get_parsed(
17256         void *parsed_result,
17257         __rte_unused struct cmdline *cl,
17258         __rte_unused void *data)
17259 {
17260         struct cmd_pctype_mapping_get_result *res = parsed_result;
17261         int ret = -ENOTSUP;
17262 #ifdef RTE_NET_I40E
17263         struct rte_pmd_i40e_flow_type_mapping
17264                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17265         int i, j, first_pctype;
17266 #endif
17267
17268         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17269                 return;
17270
17271 #ifdef RTE_NET_I40E
17272         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17273 #endif
17274
17275         switch (ret) {
17276         case 0:
17277                 break;
17278         case -ENODEV:
17279                 printf("invalid port_id %d\n", res->port_id);
17280                 return;
17281         case -ENOTSUP:
17282                 printf("function not implemented\n");
17283                 return;
17284         default:
17285                 printf("programming error: (%s)\n", strerror(-ret));
17286                 return;
17287         }
17288
17289 #ifdef RTE_NET_I40E
17290         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17291                 if (mapping[i].pctype != 0ULL) {
17292                         first_pctype = 1;
17293
17294                         printf("pctype: ");
17295                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17296                                 if (mapping[i].pctype & (1ULL << j)) {
17297                                         printf(first_pctype ?
17298                                                "%02d" : ",%02d", j);
17299                                         first_pctype = 0;
17300                                 }
17301                         }
17302                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17303                 }
17304         }
17305 #endif
17306 }
17307
17308 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17309         .f = cmd_pctype_mapping_get_parsed,
17310         .data = NULL,
17311         .help_str = "show port <port_id> pctype mapping",
17312         .tokens = {
17313                 (void *)&cmd_pctype_mapping_get_show,
17314                 (void *)&cmd_pctype_mapping_get_port,
17315                 (void *)&cmd_pctype_mapping_get_port_id,
17316                 (void *)&cmd_pctype_mapping_get_pctype,
17317                 (void *)&cmd_pctype_mapping_get_mapping,
17318                 NULL,
17319         },
17320 };
17321
17322 /* port config pctype mapping update */
17323
17324 /* Common result structure for port config pctype mapping update */
17325 struct cmd_pctype_mapping_update_result {
17326         cmdline_fixed_string_t port;
17327         cmdline_fixed_string_t config;
17328         portid_t port_id;
17329         cmdline_fixed_string_t pctype;
17330         cmdline_fixed_string_t mapping;
17331         cmdline_fixed_string_t update;
17332         cmdline_fixed_string_t pctype_list;
17333         uint16_t flow_type;
17334 };
17335
17336 /* Common CLI fields for pctype mapping update*/
17337 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17338         TOKEN_STRING_INITIALIZER
17339                 (struct cmd_pctype_mapping_update_result,
17340                  port, "port");
17341 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17342         TOKEN_STRING_INITIALIZER
17343                 (struct cmd_pctype_mapping_update_result,
17344                  config, "config");
17345 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17346         TOKEN_NUM_INITIALIZER
17347                 (struct cmd_pctype_mapping_update_result,
17348                  port_id, UINT16);
17349 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17350         TOKEN_STRING_INITIALIZER
17351                 (struct cmd_pctype_mapping_update_result,
17352                  pctype, "pctype");
17353 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17354         TOKEN_STRING_INITIALIZER
17355                 (struct cmd_pctype_mapping_update_result,
17356                  mapping, "mapping");
17357 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17358         TOKEN_STRING_INITIALIZER
17359                 (struct cmd_pctype_mapping_update_result,
17360                  update, "update");
17361 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17362         TOKEN_STRING_INITIALIZER
17363                 (struct cmd_pctype_mapping_update_result,
17364                  pctype_list, NULL);
17365 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17366         TOKEN_NUM_INITIALIZER
17367                 (struct cmd_pctype_mapping_update_result,
17368                  flow_type, UINT16);
17369
17370 static void
17371 cmd_pctype_mapping_update_parsed(
17372         void *parsed_result,
17373         __rte_unused struct cmdline *cl,
17374         __rte_unused void *data)
17375 {
17376         struct cmd_pctype_mapping_update_result *res = parsed_result;
17377         int ret = -ENOTSUP;
17378 #ifdef RTE_NET_I40E
17379         struct rte_pmd_i40e_flow_type_mapping mapping;
17380         unsigned int i;
17381         unsigned int nb_item;
17382         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17383 #endif
17384
17385         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17386                 return;
17387
17388 #ifdef RTE_NET_I40E
17389         nb_item = parse_item_list(res->pctype_list, "pctypes",
17390                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17391         mapping.flow_type = res->flow_type;
17392         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17393                 mapping.pctype |= (1ULL << pctype_list[i]);
17394         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17395                                                 &mapping,
17396                                                 1,
17397                                                 0);
17398 #endif
17399
17400         switch (ret) {
17401         case 0:
17402                 break;
17403         case -EINVAL:
17404                 printf("invalid pctype or flow type\n");
17405                 break;
17406         case -ENODEV:
17407                 printf("invalid port_id %d\n", res->port_id);
17408                 break;
17409         case -ENOTSUP:
17410                 printf("function not implemented\n");
17411                 break;
17412         default:
17413                 printf("programming error: (%s)\n", strerror(-ret));
17414         }
17415 }
17416
17417 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17418         .f = cmd_pctype_mapping_update_parsed,
17419         .data = NULL,
17420         .help_str = "port config <port_id> pctype mapping update"
17421         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17422         .tokens = {
17423                 (void *)&cmd_pctype_mapping_update_port,
17424                 (void *)&cmd_pctype_mapping_update_config,
17425                 (void *)&cmd_pctype_mapping_update_port_id,
17426                 (void *)&cmd_pctype_mapping_update_pctype,
17427                 (void *)&cmd_pctype_mapping_update_mapping,
17428                 (void *)&cmd_pctype_mapping_update_update,
17429                 (void *)&cmd_pctype_mapping_update_pc_type,
17430                 (void *)&cmd_pctype_mapping_update_flow_type,
17431                 NULL,
17432         },
17433 };
17434
17435 /* ptype mapping get */
17436
17437 /* Common result structure for ptype mapping get */
17438 struct cmd_ptype_mapping_get_result {
17439         cmdline_fixed_string_t ptype;
17440         cmdline_fixed_string_t mapping;
17441         cmdline_fixed_string_t get;
17442         portid_t port_id;
17443         uint8_t valid_only;
17444 };
17445
17446 /* Common CLI fields for ptype mapping get */
17447 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17448         TOKEN_STRING_INITIALIZER
17449                 (struct cmd_ptype_mapping_get_result,
17450                  ptype, "ptype");
17451 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17452         TOKEN_STRING_INITIALIZER
17453                 (struct cmd_ptype_mapping_get_result,
17454                  mapping, "mapping");
17455 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17456         TOKEN_STRING_INITIALIZER
17457                 (struct cmd_ptype_mapping_get_result,
17458                  get, "get");
17459 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17460         TOKEN_NUM_INITIALIZER
17461                 (struct cmd_ptype_mapping_get_result,
17462                  port_id, UINT16);
17463 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17464         TOKEN_NUM_INITIALIZER
17465                 (struct cmd_ptype_mapping_get_result,
17466                  valid_only, UINT8);
17467
17468 static void
17469 cmd_ptype_mapping_get_parsed(
17470         void *parsed_result,
17471         __rte_unused struct cmdline *cl,
17472         __rte_unused void *data)
17473 {
17474         struct cmd_ptype_mapping_get_result *res = parsed_result;
17475         int ret = -ENOTSUP;
17476 #ifdef RTE_NET_I40E
17477         int max_ptype_num = 256;
17478         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17479         uint16_t count;
17480         int i;
17481 #endif
17482
17483         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17484                 return;
17485
17486 #ifdef RTE_NET_I40E
17487         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17488                                         mapping,
17489                                         max_ptype_num,
17490                                         &count,
17491                                         res->valid_only);
17492 #endif
17493
17494         switch (ret) {
17495         case 0:
17496                 break;
17497         case -ENODEV:
17498                 printf("invalid port_id %d\n", res->port_id);
17499                 break;
17500         case -ENOTSUP:
17501                 printf("function not implemented\n");
17502                 break;
17503         default:
17504                 printf("programming error: (%s)\n", strerror(-ret));
17505         }
17506
17507 #ifdef RTE_NET_I40E
17508         if (!ret) {
17509                 for (i = 0; i < count; i++)
17510                         printf("%3d\t0x%08x\n",
17511                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17512         }
17513 #endif
17514 }
17515
17516 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17517         .f = cmd_ptype_mapping_get_parsed,
17518         .data = NULL,
17519         .help_str = "ptype mapping get <port_id> <valid_only>",
17520         .tokens = {
17521                 (void *)&cmd_ptype_mapping_get_ptype,
17522                 (void *)&cmd_ptype_mapping_get_mapping,
17523                 (void *)&cmd_ptype_mapping_get_get,
17524                 (void *)&cmd_ptype_mapping_get_port_id,
17525                 (void *)&cmd_ptype_mapping_get_valid_only,
17526                 NULL,
17527         },
17528 };
17529
17530 /* ptype mapping replace */
17531
17532 /* Common result structure for ptype mapping replace */
17533 struct cmd_ptype_mapping_replace_result {
17534         cmdline_fixed_string_t ptype;
17535         cmdline_fixed_string_t mapping;
17536         cmdline_fixed_string_t replace;
17537         portid_t port_id;
17538         uint32_t target;
17539         uint8_t mask;
17540         uint32_t pkt_type;
17541 };
17542
17543 /* Common CLI fields for ptype mapping replace */
17544 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17545         TOKEN_STRING_INITIALIZER
17546                 (struct cmd_ptype_mapping_replace_result,
17547                  ptype, "ptype");
17548 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17549         TOKEN_STRING_INITIALIZER
17550                 (struct cmd_ptype_mapping_replace_result,
17551                  mapping, "mapping");
17552 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17553         TOKEN_STRING_INITIALIZER
17554                 (struct cmd_ptype_mapping_replace_result,
17555                  replace, "replace");
17556 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17557         TOKEN_NUM_INITIALIZER
17558                 (struct cmd_ptype_mapping_replace_result,
17559                  port_id, UINT16);
17560 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17561         TOKEN_NUM_INITIALIZER
17562                 (struct cmd_ptype_mapping_replace_result,
17563                  target, UINT32);
17564 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17565         TOKEN_NUM_INITIALIZER
17566                 (struct cmd_ptype_mapping_replace_result,
17567                  mask, UINT8);
17568 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17569         TOKEN_NUM_INITIALIZER
17570                 (struct cmd_ptype_mapping_replace_result,
17571                  pkt_type, UINT32);
17572
17573 static void
17574 cmd_ptype_mapping_replace_parsed(
17575         void *parsed_result,
17576         __rte_unused struct cmdline *cl,
17577         __rte_unused void *data)
17578 {
17579         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17580         int ret = -ENOTSUP;
17581
17582         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17583                 return;
17584
17585 #ifdef RTE_NET_I40E
17586         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17587                                         res->target,
17588                                         res->mask,
17589                                         res->pkt_type);
17590 #endif
17591
17592         switch (ret) {
17593         case 0:
17594                 break;
17595         case -EINVAL:
17596                 printf("invalid ptype 0x%8x or 0x%8x\n",
17597                                 res->target, res->pkt_type);
17598                 break;
17599         case -ENODEV:
17600                 printf("invalid port_id %d\n", res->port_id);
17601                 break;
17602         case -ENOTSUP:
17603                 printf("function not implemented\n");
17604                 break;
17605         default:
17606                 printf("programming error: (%s)\n", strerror(-ret));
17607         }
17608 }
17609
17610 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17611         .f = cmd_ptype_mapping_replace_parsed,
17612         .data = NULL,
17613         .help_str =
17614                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17615         .tokens = {
17616                 (void *)&cmd_ptype_mapping_replace_ptype,
17617                 (void *)&cmd_ptype_mapping_replace_mapping,
17618                 (void *)&cmd_ptype_mapping_replace_replace,
17619                 (void *)&cmd_ptype_mapping_replace_port_id,
17620                 (void *)&cmd_ptype_mapping_replace_target,
17621                 (void *)&cmd_ptype_mapping_replace_mask,
17622                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17623                 NULL,
17624         },
17625 };
17626
17627 /* ptype mapping reset */
17628
17629 /* Common result structure for ptype mapping reset */
17630 struct cmd_ptype_mapping_reset_result {
17631         cmdline_fixed_string_t ptype;
17632         cmdline_fixed_string_t mapping;
17633         cmdline_fixed_string_t reset;
17634         portid_t port_id;
17635 };
17636
17637 /* Common CLI fields for ptype mapping reset*/
17638 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17639         TOKEN_STRING_INITIALIZER
17640                 (struct cmd_ptype_mapping_reset_result,
17641                  ptype, "ptype");
17642 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17643         TOKEN_STRING_INITIALIZER
17644                 (struct cmd_ptype_mapping_reset_result,
17645                  mapping, "mapping");
17646 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17647         TOKEN_STRING_INITIALIZER
17648                 (struct cmd_ptype_mapping_reset_result,
17649                  reset, "reset");
17650 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17651         TOKEN_NUM_INITIALIZER
17652                 (struct cmd_ptype_mapping_reset_result,
17653                  port_id, UINT16);
17654
17655 static void
17656 cmd_ptype_mapping_reset_parsed(
17657         void *parsed_result,
17658         __rte_unused struct cmdline *cl,
17659         __rte_unused void *data)
17660 {
17661         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17662         int ret = -ENOTSUP;
17663
17664         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17665                 return;
17666
17667 #ifdef RTE_NET_I40E
17668         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17669 #endif
17670
17671         switch (ret) {
17672         case 0:
17673                 break;
17674         case -ENODEV:
17675                 printf("invalid port_id %d\n", res->port_id);
17676                 break;
17677         case -ENOTSUP:
17678                 printf("function not implemented\n");
17679                 break;
17680         default:
17681                 printf("programming error: (%s)\n", strerror(-ret));
17682         }
17683 }
17684
17685 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17686         .f = cmd_ptype_mapping_reset_parsed,
17687         .data = NULL,
17688         .help_str = "ptype mapping reset <port_id>",
17689         .tokens = {
17690                 (void *)&cmd_ptype_mapping_reset_ptype,
17691                 (void *)&cmd_ptype_mapping_reset_mapping,
17692                 (void *)&cmd_ptype_mapping_reset_reset,
17693                 (void *)&cmd_ptype_mapping_reset_port_id,
17694                 NULL,
17695         },
17696 };
17697
17698 /* ptype mapping update */
17699
17700 /* Common result structure for ptype mapping update */
17701 struct cmd_ptype_mapping_update_result {
17702         cmdline_fixed_string_t ptype;
17703         cmdline_fixed_string_t mapping;
17704         cmdline_fixed_string_t reset;
17705         portid_t port_id;
17706         uint8_t hw_ptype;
17707         uint32_t sw_ptype;
17708 };
17709
17710 /* Common CLI fields for ptype mapping update*/
17711 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17712         TOKEN_STRING_INITIALIZER
17713                 (struct cmd_ptype_mapping_update_result,
17714                  ptype, "ptype");
17715 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17716         TOKEN_STRING_INITIALIZER
17717                 (struct cmd_ptype_mapping_update_result,
17718                  mapping, "mapping");
17719 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17720         TOKEN_STRING_INITIALIZER
17721                 (struct cmd_ptype_mapping_update_result,
17722                  reset, "update");
17723 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17724         TOKEN_NUM_INITIALIZER
17725                 (struct cmd_ptype_mapping_update_result,
17726                  port_id, UINT16);
17727 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17728         TOKEN_NUM_INITIALIZER
17729                 (struct cmd_ptype_mapping_update_result,
17730                  hw_ptype, UINT8);
17731 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17732         TOKEN_NUM_INITIALIZER
17733                 (struct cmd_ptype_mapping_update_result,
17734                  sw_ptype, UINT32);
17735
17736 static void
17737 cmd_ptype_mapping_update_parsed(
17738         void *parsed_result,
17739         __rte_unused struct cmdline *cl,
17740         __rte_unused void *data)
17741 {
17742         struct cmd_ptype_mapping_update_result *res = parsed_result;
17743         int ret = -ENOTSUP;
17744 #ifdef RTE_NET_I40E
17745         struct rte_pmd_i40e_ptype_mapping mapping;
17746 #endif
17747         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17748                 return;
17749
17750 #ifdef RTE_NET_I40E
17751         mapping.hw_ptype = res->hw_ptype;
17752         mapping.sw_ptype = res->sw_ptype;
17753         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17754                                                 &mapping,
17755                                                 1,
17756                                                 0);
17757 #endif
17758
17759         switch (ret) {
17760         case 0:
17761                 break;
17762         case -EINVAL:
17763                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17764                 break;
17765         case -ENODEV:
17766                 printf("invalid port_id %d\n", res->port_id);
17767                 break;
17768         case -ENOTSUP:
17769                 printf("function not implemented\n");
17770                 break;
17771         default:
17772                 printf("programming error: (%s)\n", strerror(-ret));
17773         }
17774 }
17775
17776 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17777         .f = cmd_ptype_mapping_update_parsed,
17778         .data = NULL,
17779         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17780         .tokens = {
17781                 (void *)&cmd_ptype_mapping_update_ptype,
17782                 (void *)&cmd_ptype_mapping_update_mapping,
17783                 (void *)&cmd_ptype_mapping_update_update,
17784                 (void *)&cmd_ptype_mapping_update_port_id,
17785                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17786                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17787                 NULL,
17788         },
17789 };
17790
17791 /* Common result structure for file commands */
17792 struct cmd_cmdfile_result {
17793         cmdline_fixed_string_t load;
17794         cmdline_fixed_string_t filename;
17795 };
17796
17797 /* Common CLI fields for file commands */
17798 cmdline_parse_token_string_t cmd_load_cmdfile =
17799         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17800 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17801         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17802
17803 static void
17804 cmd_load_from_file_parsed(
17805         void *parsed_result,
17806         __rte_unused struct cmdline *cl,
17807         __rte_unused void *data)
17808 {
17809         struct cmd_cmdfile_result *res = parsed_result;
17810
17811         cmdline_read_from_file(res->filename);
17812 }
17813
17814 cmdline_parse_inst_t cmd_load_from_file = {
17815         .f = cmd_load_from_file_parsed,
17816         .data = NULL,
17817         .help_str = "load <filename>",
17818         .tokens = {
17819                 (void *)&cmd_load_cmdfile,
17820                 (void *)&cmd_load_cmdfile_filename,
17821                 NULL,
17822         },
17823 };
17824
17825 /* Get Rx offloads capabilities */
17826 struct cmd_rx_offload_get_capa_result {
17827         cmdline_fixed_string_t show;
17828         cmdline_fixed_string_t port;
17829         portid_t port_id;
17830         cmdline_fixed_string_t rx_offload;
17831         cmdline_fixed_string_t capabilities;
17832 };
17833
17834 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17835         TOKEN_STRING_INITIALIZER
17836                 (struct cmd_rx_offload_get_capa_result,
17837                  show, "show");
17838 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17839         TOKEN_STRING_INITIALIZER
17840                 (struct cmd_rx_offload_get_capa_result,
17841                  port, "port");
17842 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17843         TOKEN_NUM_INITIALIZER
17844                 (struct cmd_rx_offload_get_capa_result,
17845                  port_id, UINT16);
17846 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17847         TOKEN_STRING_INITIALIZER
17848                 (struct cmd_rx_offload_get_capa_result,
17849                  rx_offload, "rx_offload");
17850 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17851         TOKEN_STRING_INITIALIZER
17852                 (struct cmd_rx_offload_get_capa_result,
17853                  capabilities, "capabilities");
17854
17855 static void
17856 print_rx_offloads(uint64_t offloads)
17857 {
17858         uint64_t single_offload;
17859         int begin;
17860         int end;
17861         int bit;
17862
17863         if (offloads == 0)
17864                 return;
17865
17866         begin = __builtin_ctzll(offloads);
17867         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17868
17869         single_offload = 1ULL << begin;
17870         for (bit = begin; bit < end; bit++) {
17871                 if (offloads & single_offload)
17872                         printf(" %s",
17873                                rte_eth_dev_rx_offload_name(single_offload));
17874                 single_offload <<= 1;
17875         }
17876 }
17877
17878 static void
17879 cmd_rx_offload_get_capa_parsed(
17880         void *parsed_result,
17881         __rte_unused struct cmdline *cl,
17882         __rte_unused void *data)
17883 {
17884         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17885         struct rte_eth_dev_info dev_info;
17886         portid_t port_id = res->port_id;
17887         uint64_t queue_offloads;
17888         uint64_t port_offloads;
17889         int ret;
17890
17891         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17892         if (ret != 0)
17893                 return;
17894
17895         queue_offloads = dev_info.rx_queue_offload_capa;
17896         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17897
17898         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17899         printf("  Per Queue :");
17900         print_rx_offloads(queue_offloads);
17901
17902         printf("\n");
17903         printf("  Per Port  :");
17904         print_rx_offloads(port_offloads);
17905         printf("\n\n");
17906 }
17907
17908 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
17909         .f = cmd_rx_offload_get_capa_parsed,
17910         .data = NULL,
17911         .help_str = "show port <port_id> rx_offload capabilities",
17912         .tokens = {
17913                 (void *)&cmd_rx_offload_get_capa_show,
17914                 (void *)&cmd_rx_offload_get_capa_port,
17915                 (void *)&cmd_rx_offload_get_capa_port_id,
17916                 (void *)&cmd_rx_offload_get_capa_rx_offload,
17917                 (void *)&cmd_rx_offload_get_capa_capabilities,
17918                 NULL,
17919         }
17920 };
17921
17922 /* Get Rx offloads configuration */
17923 struct cmd_rx_offload_get_configuration_result {
17924         cmdline_fixed_string_t show;
17925         cmdline_fixed_string_t port;
17926         portid_t port_id;
17927         cmdline_fixed_string_t rx_offload;
17928         cmdline_fixed_string_t configuration;
17929 };
17930
17931 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
17932         TOKEN_STRING_INITIALIZER
17933                 (struct cmd_rx_offload_get_configuration_result,
17934                  show, "show");
17935 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
17936         TOKEN_STRING_INITIALIZER
17937                 (struct cmd_rx_offload_get_configuration_result,
17938                  port, "port");
17939 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
17940         TOKEN_NUM_INITIALIZER
17941                 (struct cmd_rx_offload_get_configuration_result,
17942                  port_id, UINT16);
17943 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
17944         TOKEN_STRING_INITIALIZER
17945                 (struct cmd_rx_offload_get_configuration_result,
17946                  rx_offload, "rx_offload");
17947 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
17948         TOKEN_STRING_INITIALIZER
17949                 (struct cmd_rx_offload_get_configuration_result,
17950                  configuration, "configuration");
17951
17952 static void
17953 cmd_rx_offload_get_configuration_parsed(
17954         void *parsed_result,
17955         __rte_unused struct cmdline *cl,
17956         __rte_unused void *data)
17957 {
17958         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17959         struct rte_eth_dev_info dev_info;
17960         portid_t port_id = res->port_id;
17961         struct rte_port *port = &ports[port_id];
17962         uint64_t port_offloads;
17963         uint64_t queue_offloads;
17964         uint16_t nb_rx_queues;
17965         int q;
17966         int ret;
17967
17968         printf("Rx Offloading Configuration of port %d :\n", port_id);
17969
17970         port_offloads = port->dev_conf.rxmode.offloads;
17971         printf("  Port :");
17972         print_rx_offloads(port_offloads);
17973         printf("\n");
17974
17975         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17976         if (ret != 0)
17977                 return;
17978
17979         nb_rx_queues = dev_info.nb_rx_queues;
17980         for (q = 0; q < nb_rx_queues; q++) {
17981                 queue_offloads = port->rx_conf[q].offloads;
17982                 printf("  Queue[%2d] :", q);
17983                 print_rx_offloads(queue_offloads);
17984                 printf("\n");
17985         }
17986         printf("\n");
17987 }
17988
17989 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
17990         .f = cmd_rx_offload_get_configuration_parsed,
17991         .data = NULL,
17992         .help_str = "show port <port_id> rx_offload configuration",
17993         .tokens = {
17994                 (void *)&cmd_rx_offload_get_configuration_show,
17995                 (void *)&cmd_rx_offload_get_configuration_port,
17996                 (void *)&cmd_rx_offload_get_configuration_port_id,
17997                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
17998                 (void *)&cmd_rx_offload_get_configuration_configuration,
17999                 NULL,
18000         }
18001 };
18002
18003 /* Enable/Disable a per port offloading */
18004 struct cmd_config_per_port_rx_offload_result {
18005         cmdline_fixed_string_t port;
18006         cmdline_fixed_string_t config;
18007         portid_t port_id;
18008         cmdline_fixed_string_t rx_offload;
18009         cmdline_fixed_string_t offload;
18010         cmdline_fixed_string_t on_off;
18011 };
18012
18013 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18014         TOKEN_STRING_INITIALIZER
18015                 (struct cmd_config_per_port_rx_offload_result,
18016                  port, "port");
18017 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18018         TOKEN_STRING_INITIALIZER
18019                 (struct cmd_config_per_port_rx_offload_result,
18020                  config, "config");
18021 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18022         TOKEN_NUM_INITIALIZER
18023                 (struct cmd_config_per_port_rx_offload_result,
18024                  port_id, UINT16);
18025 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18026         TOKEN_STRING_INITIALIZER
18027                 (struct cmd_config_per_port_rx_offload_result,
18028                  rx_offload, "rx_offload");
18029 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18030         TOKEN_STRING_INITIALIZER
18031                 (struct cmd_config_per_port_rx_offload_result,
18032                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18033                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18034                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18035                            "scatter#buffer_split#timestamp#security#"
18036                            "keep_crc#rss_hash");
18037 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18038         TOKEN_STRING_INITIALIZER
18039                 (struct cmd_config_per_port_rx_offload_result,
18040                  on_off, "on#off");
18041
18042 static uint64_t
18043 search_rx_offload(const char *name)
18044 {
18045         uint64_t single_offload;
18046         const char *single_name;
18047         int found = 0;
18048         unsigned int bit;
18049
18050         single_offload = 1;
18051         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18052                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18053                 if (!strcasecmp(single_name, name)) {
18054                         found = 1;
18055                         break;
18056                 }
18057                 single_offload <<= 1;
18058         }
18059
18060         if (found)
18061                 return single_offload;
18062
18063         return 0;
18064 }
18065
18066 static void
18067 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18068                                 __rte_unused struct cmdline *cl,
18069                                 __rte_unused void *data)
18070 {
18071         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18072         portid_t port_id = res->port_id;
18073         struct rte_eth_dev_info dev_info;
18074         struct rte_port *port = &ports[port_id];
18075         uint64_t single_offload;
18076         uint16_t nb_rx_queues;
18077         int q;
18078         int ret;
18079
18080         if (port->port_status != RTE_PORT_STOPPED) {
18081                 printf("Error: Can't config offload when Port %d "
18082                        "is not stopped\n", port_id);
18083                 return;
18084         }
18085
18086         single_offload = search_rx_offload(res->offload);
18087         if (single_offload == 0) {
18088                 printf("Unknown offload name: %s\n", res->offload);
18089                 return;
18090         }
18091
18092         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18093         if (ret != 0)
18094                 return;
18095
18096         nb_rx_queues = dev_info.nb_rx_queues;
18097         if (!strcmp(res->on_off, "on")) {
18098                 port->dev_conf.rxmode.offloads |= single_offload;
18099                 for (q = 0; q < nb_rx_queues; q++)
18100                         port->rx_conf[q].offloads |= single_offload;
18101         } else {
18102                 port->dev_conf.rxmode.offloads &= ~single_offload;
18103                 for (q = 0; q < nb_rx_queues; q++)
18104                         port->rx_conf[q].offloads &= ~single_offload;
18105         }
18106
18107         cmd_reconfig_device_queue(port_id, 1, 1);
18108 }
18109
18110 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18111         .f = cmd_config_per_port_rx_offload_parsed,
18112         .data = NULL,
18113         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18114                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18115                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18116                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
18117                     "keep_crc|rss_hash on|off",
18118         .tokens = {
18119                 (void *)&cmd_config_per_port_rx_offload_result_port,
18120                 (void *)&cmd_config_per_port_rx_offload_result_config,
18121                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18122                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18123                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18124                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18125                 NULL,
18126         }
18127 };
18128
18129 /* Enable/Disable a per queue offloading */
18130 struct cmd_config_per_queue_rx_offload_result {
18131         cmdline_fixed_string_t port;
18132         portid_t port_id;
18133         cmdline_fixed_string_t rxq;
18134         uint16_t queue_id;
18135         cmdline_fixed_string_t rx_offload;
18136         cmdline_fixed_string_t offload;
18137         cmdline_fixed_string_t on_off;
18138 };
18139
18140 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18141         TOKEN_STRING_INITIALIZER
18142                 (struct cmd_config_per_queue_rx_offload_result,
18143                  port, "port");
18144 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18145         TOKEN_NUM_INITIALIZER
18146                 (struct cmd_config_per_queue_rx_offload_result,
18147                  port_id, UINT16);
18148 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18149         TOKEN_STRING_INITIALIZER
18150                 (struct cmd_config_per_queue_rx_offload_result,
18151                  rxq, "rxq");
18152 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18153         TOKEN_NUM_INITIALIZER
18154                 (struct cmd_config_per_queue_rx_offload_result,
18155                  queue_id, UINT16);
18156 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18157         TOKEN_STRING_INITIALIZER
18158                 (struct cmd_config_per_queue_rx_offload_result,
18159                  rx_offload, "rx_offload");
18160 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18161         TOKEN_STRING_INITIALIZER
18162                 (struct cmd_config_per_queue_rx_offload_result,
18163                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18164                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18165                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18166                            "scatter#buffer_split#timestamp#security#keep_crc");
18167 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18168         TOKEN_STRING_INITIALIZER
18169                 (struct cmd_config_per_queue_rx_offload_result,
18170                  on_off, "on#off");
18171
18172 static void
18173 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18174                                 __rte_unused struct cmdline *cl,
18175                                 __rte_unused void *data)
18176 {
18177         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18178         struct rte_eth_dev_info dev_info;
18179         portid_t port_id = res->port_id;
18180         uint16_t queue_id = res->queue_id;
18181         struct rte_port *port = &ports[port_id];
18182         uint64_t single_offload;
18183         int ret;
18184
18185         if (port->port_status != RTE_PORT_STOPPED) {
18186                 printf("Error: Can't config offload when Port %d "
18187                        "is not stopped\n", port_id);
18188                 return;
18189         }
18190
18191         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18192         if (ret != 0)
18193                 return;
18194
18195         if (queue_id >= dev_info.nb_rx_queues) {
18196                 printf("Error: input queue_id should be 0 ... "
18197                        "%d\n", dev_info.nb_rx_queues - 1);
18198                 return;
18199         }
18200
18201         single_offload = search_rx_offload(res->offload);
18202         if (single_offload == 0) {
18203                 printf("Unknown offload name: %s\n", res->offload);
18204                 return;
18205         }
18206
18207         if (!strcmp(res->on_off, "on"))
18208                 port->rx_conf[queue_id].offloads |= single_offload;
18209         else
18210                 port->rx_conf[queue_id].offloads &= ~single_offload;
18211
18212         cmd_reconfig_device_queue(port_id, 1, 1);
18213 }
18214
18215 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18216         .f = cmd_config_per_queue_rx_offload_parsed,
18217         .data = NULL,
18218         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18219                     "vlan_strip|ipv4_cksum|"
18220                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18221                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18222                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
18223                     "keep_crc on|off",
18224         .tokens = {
18225                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18226                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18227                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18228                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18229                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18230                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18231                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18232                 NULL,
18233         }
18234 };
18235
18236 /* Get Tx offloads capabilities */
18237 struct cmd_tx_offload_get_capa_result {
18238         cmdline_fixed_string_t show;
18239         cmdline_fixed_string_t port;
18240         portid_t port_id;
18241         cmdline_fixed_string_t tx_offload;
18242         cmdline_fixed_string_t capabilities;
18243 };
18244
18245 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18246         TOKEN_STRING_INITIALIZER
18247                 (struct cmd_tx_offload_get_capa_result,
18248                  show, "show");
18249 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18250         TOKEN_STRING_INITIALIZER
18251                 (struct cmd_tx_offload_get_capa_result,
18252                  port, "port");
18253 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18254         TOKEN_NUM_INITIALIZER
18255                 (struct cmd_tx_offload_get_capa_result,
18256                  port_id, UINT16);
18257 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18258         TOKEN_STRING_INITIALIZER
18259                 (struct cmd_tx_offload_get_capa_result,
18260                  tx_offload, "tx_offload");
18261 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18262         TOKEN_STRING_INITIALIZER
18263                 (struct cmd_tx_offload_get_capa_result,
18264                  capabilities, "capabilities");
18265
18266 static void
18267 print_tx_offloads(uint64_t offloads)
18268 {
18269         uint64_t single_offload;
18270         int begin;
18271         int end;
18272         int bit;
18273
18274         if (offloads == 0)
18275                 return;
18276
18277         begin = __builtin_ctzll(offloads);
18278         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18279
18280         single_offload = 1ULL << begin;
18281         for (bit = begin; bit < end; bit++) {
18282                 if (offloads & single_offload)
18283                         printf(" %s",
18284                                rte_eth_dev_tx_offload_name(single_offload));
18285                 single_offload <<= 1;
18286         }
18287 }
18288
18289 static void
18290 cmd_tx_offload_get_capa_parsed(
18291         void *parsed_result,
18292         __rte_unused struct cmdline *cl,
18293         __rte_unused void *data)
18294 {
18295         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18296         struct rte_eth_dev_info dev_info;
18297         portid_t port_id = res->port_id;
18298         uint64_t queue_offloads;
18299         uint64_t port_offloads;
18300         int ret;
18301
18302         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18303         if (ret != 0)
18304                 return;
18305
18306         queue_offloads = dev_info.tx_queue_offload_capa;
18307         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18308
18309         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18310         printf("  Per Queue :");
18311         print_tx_offloads(queue_offloads);
18312
18313         printf("\n");
18314         printf("  Per Port  :");
18315         print_tx_offloads(port_offloads);
18316         printf("\n\n");
18317 }
18318
18319 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18320         .f = cmd_tx_offload_get_capa_parsed,
18321         .data = NULL,
18322         .help_str = "show port <port_id> tx_offload capabilities",
18323         .tokens = {
18324                 (void *)&cmd_tx_offload_get_capa_show,
18325                 (void *)&cmd_tx_offload_get_capa_port,
18326                 (void *)&cmd_tx_offload_get_capa_port_id,
18327                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18328                 (void *)&cmd_tx_offload_get_capa_capabilities,
18329                 NULL,
18330         }
18331 };
18332
18333 /* Get Tx offloads configuration */
18334 struct cmd_tx_offload_get_configuration_result {
18335         cmdline_fixed_string_t show;
18336         cmdline_fixed_string_t port;
18337         portid_t port_id;
18338         cmdline_fixed_string_t tx_offload;
18339         cmdline_fixed_string_t configuration;
18340 };
18341
18342 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18343         TOKEN_STRING_INITIALIZER
18344                 (struct cmd_tx_offload_get_configuration_result,
18345                  show, "show");
18346 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18347         TOKEN_STRING_INITIALIZER
18348                 (struct cmd_tx_offload_get_configuration_result,
18349                  port, "port");
18350 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18351         TOKEN_NUM_INITIALIZER
18352                 (struct cmd_tx_offload_get_configuration_result,
18353                  port_id, UINT16);
18354 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18355         TOKEN_STRING_INITIALIZER
18356                 (struct cmd_tx_offload_get_configuration_result,
18357                  tx_offload, "tx_offload");
18358 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18359         TOKEN_STRING_INITIALIZER
18360                 (struct cmd_tx_offload_get_configuration_result,
18361                  configuration, "configuration");
18362
18363 static void
18364 cmd_tx_offload_get_configuration_parsed(
18365         void *parsed_result,
18366         __rte_unused struct cmdline *cl,
18367         __rte_unused void *data)
18368 {
18369         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18370         struct rte_eth_dev_info dev_info;
18371         portid_t port_id = res->port_id;
18372         struct rte_port *port = &ports[port_id];
18373         uint64_t port_offloads;
18374         uint64_t queue_offloads;
18375         uint16_t nb_tx_queues;
18376         int q;
18377         int ret;
18378
18379         printf("Tx Offloading Configuration of port %d :\n", port_id);
18380
18381         port_offloads = port->dev_conf.txmode.offloads;
18382         printf("  Port :");
18383         print_tx_offloads(port_offloads);
18384         printf("\n");
18385
18386         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18387         if (ret != 0)
18388                 return;
18389
18390         nb_tx_queues = dev_info.nb_tx_queues;
18391         for (q = 0; q < nb_tx_queues; q++) {
18392                 queue_offloads = port->tx_conf[q].offloads;
18393                 printf("  Queue[%2d] :", q);
18394                 print_tx_offloads(queue_offloads);
18395                 printf("\n");
18396         }
18397         printf("\n");
18398 }
18399
18400 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18401         .f = cmd_tx_offload_get_configuration_parsed,
18402         .data = NULL,
18403         .help_str = "show port <port_id> tx_offload configuration",
18404         .tokens = {
18405                 (void *)&cmd_tx_offload_get_configuration_show,
18406                 (void *)&cmd_tx_offload_get_configuration_port,
18407                 (void *)&cmd_tx_offload_get_configuration_port_id,
18408                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18409                 (void *)&cmd_tx_offload_get_configuration_configuration,
18410                 NULL,
18411         }
18412 };
18413
18414 /* Enable/Disable a per port offloading */
18415 struct cmd_config_per_port_tx_offload_result {
18416         cmdline_fixed_string_t port;
18417         cmdline_fixed_string_t config;
18418         portid_t port_id;
18419         cmdline_fixed_string_t tx_offload;
18420         cmdline_fixed_string_t offload;
18421         cmdline_fixed_string_t on_off;
18422 };
18423
18424 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18425         TOKEN_STRING_INITIALIZER
18426                 (struct cmd_config_per_port_tx_offload_result,
18427                  port, "port");
18428 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18429         TOKEN_STRING_INITIALIZER
18430                 (struct cmd_config_per_port_tx_offload_result,
18431                  config, "config");
18432 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18433         TOKEN_NUM_INITIALIZER
18434                 (struct cmd_config_per_port_tx_offload_result,
18435                  port_id, UINT16);
18436 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18437         TOKEN_STRING_INITIALIZER
18438                 (struct cmd_config_per_port_tx_offload_result,
18439                  tx_offload, "tx_offload");
18440 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18441         TOKEN_STRING_INITIALIZER
18442                 (struct cmd_config_per_port_tx_offload_result,
18443                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18444                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18445                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18446                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18447                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18448                           "send_on_timestamp");
18449 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18450         TOKEN_STRING_INITIALIZER
18451                 (struct cmd_config_per_port_tx_offload_result,
18452                  on_off, "on#off");
18453
18454 static uint64_t
18455 search_tx_offload(const char *name)
18456 {
18457         uint64_t single_offload;
18458         const char *single_name;
18459         int found = 0;
18460         unsigned int bit;
18461
18462         single_offload = 1;
18463         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18464                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18465                 if (single_name == NULL)
18466                         break;
18467                 if (!strcasecmp(single_name, name)) {
18468                         found = 1;
18469                         break;
18470                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18471                         break;
18472                 single_offload <<= 1;
18473         }
18474
18475         if (found)
18476                 return single_offload;
18477
18478         return 0;
18479 }
18480
18481 static void
18482 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18483                                 __rte_unused struct cmdline *cl,
18484                                 __rte_unused void *data)
18485 {
18486         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18487         portid_t port_id = res->port_id;
18488         struct rte_eth_dev_info dev_info;
18489         struct rte_port *port = &ports[port_id];
18490         uint64_t single_offload;
18491         uint16_t nb_tx_queues;
18492         int q;
18493         int ret;
18494
18495         if (port->port_status != RTE_PORT_STOPPED) {
18496                 printf("Error: Can't config offload when Port %d "
18497                        "is not stopped\n", port_id);
18498                 return;
18499         }
18500
18501         single_offload = search_tx_offload(res->offload);
18502         if (single_offload == 0) {
18503                 printf("Unknown offload name: %s\n", res->offload);
18504                 return;
18505         }
18506
18507         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18508         if (ret != 0)
18509                 return;
18510
18511         nb_tx_queues = dev_info.nb_tx_queues;
18512         if (!strcmp(res->on_off, "on")) {
18513                 port->dev_conf.txmode.offloads |= single_offload;
18514                 for (q = 0; q < nb_tx_queues; q++)
18515                         port->tx_conf[q].offloads |= single_offload;
18516         } else {
18517                 port->dev_conf.txmode.offloads &= ~single_offload;
18518                 for (q = 0; q < nb_tx_queues; q++)
18519                         port->tx_conf[q].offloads &= ~single_offload;
18520         }
18521
18522         cmd_reconfig_device_queue(port_id, 1, 1);
18523 }
18524
18525 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18526         .f = cmd_config_per_port_tx_offload_parsed,
18527         .data = NULL,
18528         .help_str = "port config <port_id> tx_offload "
18529                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18530                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18531                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18532                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18533                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18534                     "send_on_timestamp on|off",
18535         .tokens = {
18536                 (void *)&cmd_config_per_port_tx_offload_result_port,
18537                 (void *)&cmd_config_per_port_tx_offload_result_config,
18538                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18539                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18540                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18541                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18542                 NULL,
18543         }
18544 };
18545
18546 /* Enable/Disable a per queue offloading */
18547 struct cmd_config_per_queue_tx_offload_result {
18548         cmdline_fixed_string_t port;
18549         portid_t port_id;
18550         cmdline_fixed_string_t txq;
18551         uint16_t queue_id;
18552         cmdline_fixed_string_t tx_offload;
18553         cmdline_fixed_string_t offload;
18554         cmdline_fixed_string_t on_off;
18555 };
18556
18557 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18558         TOKEN_STRING_INITIALIZER
18559                 (struct cmd_config_per_queue_tx_offload_result,
18560                  port, "port");
18561 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18562         TOKEN_NUM_INITIALIZER
18563                 (struct cmd_config_per_queue_tx_offload_result,
18564                  port_id, UINT16);
18565 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18566         TOKEN_STRING_INITIALIZER
18567                 (struct cmd_config_per_queue_tx_offload_result,
18568                  txq, "txq");
18569 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18570         TOKEN_NUM_INITIALIZER
18571                 (struct cmd_config_per_queue_tx_offload_result,
18572                  queue_id, UINT16);
18573 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18574         TOKEN_STRING_INITIALIZER
18575                 (struct cmd_config_per_queue_tx_offload_result,
18576                  tx_offload, "tx_offload");
18577 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18578         TOKEN_STRING_INITIALIZER
18579                 (struct cmd_config_per_queue_tx_offload_result,
18580                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18581                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18582                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18583                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18584                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18585 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18586         TOKEN_STRING_INITIALIZER
18587                 (struct cmd_config_per_queue_tx_offload_result,
18588                  on_off, "on#off");
18589
18590 static void
18591 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18592                                 __rte_unused struct cmdline *cl,
18593                                 __rte_unused void *data)
18594 {
18595         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18596         struct rte_eth_dev_info dev_info;
18597         portid_t port_id = res->port_id;
18598         uint16_t queue_id = res->queue_id;
18599         struct rte_port *port = &ports[port_id];
18600         uint64_t single_offload;
18601         int ret;
18602
18603         if (port->port_status != RTE_PORT_STOPPED) {
18604                 printf("Error: Can't config offload when Port %d "
18605                        "is not stopped\n", port_id);
18606                 return;
18607         }
18608
18609         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18610         if (ret != 0)
18611                 return;
18612
18613         if (queue_id >= dev_info.nb_tx_queues) {
18614                 printf("Error: input queue_id should be 0 ... "
18615                        "%d\n", dev_info.nb_tx_queues - 1);
18616                 return;
18617         }
18618
18619         single_offload = search_tx_offload(res->offload);
18620         if (single_offload == 0) {
18621                 printf("Unknown offload name: %s\n", res->offload);
18622                 return;
18623         }
18624
18625         if (!strcmp(res->on_off, "on"))
18626                 port->tx_conf[queue_id].offloads |= single_offload;
18627         else
18628                 port->tx_conf[queue_id].offloads &= ~single_offload;
18629
18630         cmd_reconfig_device_queue(port_id, 1, 1);
18631 }
18632
18633 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18634         .f = cmd_config_per_queue_tx_offload_parsed,
18635         .data = NULL,
18636         .help_str = "port <port_id> txq <queue_id> tx_offload "
18637                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18638                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18639                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18640                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18641                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18642                     "on|off",
18643         .tokens = {
18644                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18645                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18646                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18647                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18648                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18649                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18650                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18651                 NULL,
18652         }
18653 };
18654
18655 /* *** configure tx_metadata for specific port *** */
18656 struct cmd_config_tx_metadata_specific_result {
18657         cmdline_fixed_string_t port;
18658         cmdline_fixed_string_t keyword;
18659         uint16_t port_id;
18660         cmdline_fixed_string_t item;
18661         uint32_t value;
18662 };
18663
18664 static void
18665 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18666                                 __rte_unused struct cmdline *cl,
18667                                 __rte_unused void *data)
18668 {
18669         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18670
18671         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18672                 return;
18673         ports[res->port_id].tx_metadata = res->value;
18674         /* Add/remove callback to insert valid metadata in every Tx packet. */
18675         if (ports[res->port_id].tx_metadata)
18676                 add_tx_md_callback(res->port_id);
18677         else
18678                 remove_tx_md_callback(res->port_id);
18679         rte_flow_dynf_metadata_register();
18680 }
18681
18682 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18683         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18684                         port, "port");
18685 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18686         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18687                         keyword, "config");
18688 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18689         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18690                         port_id, UINT16);
18691 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18692         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18693                         item, "tx_metadata");
18694 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18695         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18696                         value, UINT32);
18697
18698 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18699         .f = cmd_config_tx_metadata_specific_parsed,
18700         .data = NULL,
18701         .help_str = "port config <port_id> tx_metadata <value>",
18702         .tokens = {
18703                 (void *)&cmd_config_tx_metadata_specific_port,
18704                 (void *)&cmd_config_tx_metadata_specific_keyword,
18705                 (void *)&cmd_config_tx_metadata_specific_id,
18706                 (void *)&cmd_config_tx_metadata_specific_item,
18707                 (void *)&cmd_config_tx_metadata_specific_value,
18708                 NULL,
18709         },
18710 };
18711
18712 /* *** set dynf *** */
18713 struct cmd_config_tx_dynf_specific_result {
18714         cmdline_fixed_string_t port;
18715         cmdline_fixed_string_t keyword;
18716         uint16_t port_id;
18717         cmdline_fixed_string_t item;
18718         cmdline_fixed_string_t name;
18719         cmdline_fixed_string_t value;
18720 };
18721
18722 static void
18723 cmd_config_dynf_specific_parsed(void *parsed_result,
18724                                 __rte_unused struct cmdline *cl,
18725                                 __rte_unused void *data)
18726 {
18727         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18728         struct rte_mbuf_dynflag desc_flag;
18729         int flag;
18730         uint64_t old_port_flags;
18731
18732         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18733                 return;
18734         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18735         if (flag <= 0) {
18736                 if (strlcpy(desc_flag.name, res->name,
18737                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18738                         printf("Flag name too long\n");
18739                         return;
18740                 }
18741                 desc_flag.flags = 0;
18742                 flag = rte_mbuf_dynflag_register(&desc_flag);
18743                 if (flag < 0) {
18744                         printf("Can't register flag\n");
18745                         return;
18746                 }
18747                 strcpy(dynf_names[flag], desc_flag.name);
18748         }
18749         old_port_flags = ports[res->port_id].mbuf_dynf;
18750         if (!strcmp(res->value, "set")) {
18751                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
18752                 if (old_port_flags == 0)
18753                         add_tx_dynf_callback(res->port_id);
18754         } else {
18755                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18756                 if (ports[res->port_id].mbuf_dynf == 0)
18757                         remove_tx_dynf_callback(res->port_id);
18758         }
18759 }
18760
18761 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18762         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18763                         keyword, "port");
18764 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18765         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18766                         keyword, "config");
18767 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18768         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18769                         port_id, UINT16);
18770 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18771         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18772                         item, "dynf");
18773 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18774         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18775                         name, NULL);
18776 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
18777         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18778                         value, "set#clear");
18779
18780 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
18781         .f = cmd_config_dynf_specific_parsed,
18782         .data = NULL,
18783         .help_str = "port config <port id> dynf <name> set|clear",
18784         .tokens = {
18785                 (void *)&cmd_config_tx_dynf_specific_port,
18786                 (void *)&cmd_config_tx_dynf_specific_keyword,
18787                 (void *)&cmd_config_tx_dynf_specific_port_id,
18788                 (void *)&cmd_config_tx_dynf_specific_item,
18789                 (void *)&cmd_config_tx_dynf_specific_name,
18790                 (void *)&cmd_config_tx_dynf_specific_value,
18791                 NULL,
18792         },
18793 };
18794
18795 /* *** display tx_metadata per port configuration *** */
18796 struct cmd_show_tx_metadata_result {
18797         cmdline_fixed_string_t cmd_show;
18798         cmdline_fixed_string_t cmd_port;
18799         cmdline_fixed_string_t cmd_keyword;
18800         portid_t cmd_pid;
18801 };
18802
18803 static void
18804 cmd_show_tx_metadata_parsed(void *parsed_result,
18805                 __rte_unused struct cmdline *cl,
18806                 __rte_unused void *data)
18807 {
18808         struct cmd_show_tx_metadata_result *res = parsed_result;
18809
18810         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18811                 printf("invalid port id %u\n", res->cmd_pid);
18812                 return;
18813         }
18814         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18815                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18816                        ports[res->cmd_pid].tx_metadata);
18817         }
18818 }
18819
18820 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18821         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18822                         cmd_show, "show");
18823 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18824         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18825                         cmd_port, "port");
18826 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18827         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18828                         cmd_pid, UINT16);
18829 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18830         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18831                         cmd_keyword, "tx_metadata");
18832
18833 cmdline_parse_inst_t cmd_show_tx_metadata = {
18834         .f = cmd_show_tx_metadata_parsed,
18835         .data = NULL,
18836         .help_str = "show port <port_id> tx_metadata",
18837         .tokens = {
18838                 (void *)&cmd_show_tx_metadata_show,
18839                 (void *)&cmd_show_tx_metadata_port,
18840                 (void *)&cmd_show_tx_metadata_pid,
18841                 (void *)&cmd_show_tx_metadata_keyword,
18842                 NULL,
18843         },
18844 };
18845
18846 /* *** show fec capability per port configuration *** */
18847 struct cmd_show_fec_capability_result {
18848         cmdline_fixed_string_t cmd_show;
18849         cmdline_fixed_string_t cmd_port;
18850         cmdline_fixed_string_t cmd_fec;
18851         cmdline_fixed_string_t cmd_keyword;
18852         portid_t cmd_pid;
18853 };
18854
18855 static void
18856 cmd_show_fec_capability_parsed(void *parsed_result,
18857                 __rte_unused struct cmdline *cl,
18858                 __rte_unused void *data)
18859 {
18860 #define FEC_CAP_NUM 2
18861         struct cmd_show_fec_capability_result *res = parsed_result;
18862         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
18863         unsigned int num = FEC_CAP_NUM;
18864         unsigned int ret_num;
18865         int ret;
18866
18867         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18868                 printf("Invalid port id %u\n", res->cmd_pid);
18869                 return;
18870         }
18871
18872         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
18873         if (ret == -ENOTSUP) {
18874                 printf("Function not implemented\n");
18875                 return;
18876         } else if (ret < 0) {
18877                 printf("Get FEC capability failed\n");
18878                 return;
18879         }
18880
18881         ret_num = (unsigned int)ret;
18882         show_fec_capability(ret_num, speed_fec_capa);
18883 }
18884
18885 cmdline_parse_token_string_t cmd_show_fec_capability_show =
18886         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
18887                         cmd_show, "show");
18888 cmdline_parse_token_string_t cmd_show_fec_capability_port =
18889         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
18890                         cmd_port, "port");
18891 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
18892         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
18893                         cmd_pid, UINT16);
18894 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
18895         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
18896                         cmd_fec, "fec");
18897 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
18898         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
18899                         cmd_keyword, "capabilities");
18900
18901 cmdline_parse_inst_t cmd_show_capability = {
18902         .f = cmd_show_fec_capability_parsed,
18903         .data = NULL,
18904         .help_str = "show port <port_id> fec capabilities",
18905         .tokens = {
18906                 (void *)&cmd_show_fec_capability_show,
18907                 (void *)&cmd_show_fec_capability_port,
18908                 (void *)&cmd_show_fec_capability_pid,
18909                 (void *)&cmd_show_fec_capability_fec,
18910                 (void *)&cmd_show_fec_capability_keyword,
18911                 NULL,
18912         },
18913 };
18914
18915 /* *** show fec mode per port configuration *** */
18916 struct cmd_show_fec_metadata_result {
18917         cmdline_fixed_string_t cmd_show;
18918         cmdline_fixed_string_t cmd_port;
18919         cmdline_fixed_string_t cmd_keyword;
18920         portid_t cmd_pid;
18921 };
18922
18923 static void
18924 cmd_show_fec_mode_parsed(void *parsed_result,
18925                 __rte_unused struct cmdline *cl,
18926                 __rte_unused void *data)
18927 {
18928 #define FEC_NAME_SIZE 16
18929         struct cmd_show_fec_metadata_result *res = parsed_result;
18930         uint32_t mode;
18931         char buf[FEC_NAME_SIZE];
18932         int ret;
18933
18934         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18935                 printf("Invalid port id %u\n", res->cmd_pid);
18936                 return;
18937         }
18938         ret = rte_eth_fec_get(res->cmd_pid, &mode);
18939         if (ret == -ENOTSUP) {
18940                 printf("Function not implemented\n");
18941                 return;
18942         } else if (ret < 0) {
18943                 printf("Get FEC mode failed\n");
18944                 return;
18945         }
18946
18947         switch (mode) {
18948         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
18949                 strlcpy(buf, "off", sizeof(buf));
18950                 break;
18951         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
18952                 strlcpy(buf, "auto", sizeof(buf));
18953                 break;
18954         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
18955                 strlcpy(buf, "baser", sizeof(buf));
18956                 break;
18957         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
18958                 strlcpy(buf, "rs", sizeof(buf));
18959                 break;
18960         default:
18961                 return;
18962         }
18963
18964         printf("%s\n", buf);
18965 }
18966
18967 cmdline_parse_token_string_t cmd_show_fec_mode_show =
18968         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
18969                         cmd_show, "show");
18970 cmdline_parse_token_string_t cmd_show_fec_mode_port =
18971         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
18972                         cmd_port, "port");
18973 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
18974         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
18975                         cmd_pid, UINT16);
18976 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
18977         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
18978                         cmd_keyword, "fec_mode");
18979
18980 cmdline_parse_inst_t cmd_show_fec_mode = {
18981         .f = cmd_show_fec_mode_parsed,
18982         .data = NULL,
18983         .help_str = "show port <port_id> fec_mode",
18984         .tokens = {
18985                 (void *)&cmd_show_fec_mode_show,
18986                 (void *)&cmd_show_fec_mode_port,
18987                 (void *)&cmd_show_fec_mode_pid,
18988                 (void *)&cmd_show_fec_mode_keyword,
18989                 NULL,
18990         },
18991 };
18992
18993 /* *** set fec mode per port configuration *** */
18994 struct cmd_set_port_fec_mode {
18995         cmdline_fixed_string_t set;
18996         cmdline_fixed_string_t port;
18997         portid_t port_id;
18998         cmdline_fixed_string_t fec_mode;
18999         cmdline_fixed_string_t fec_value;
19000 };
19001
19002 /* Common CLI fields for set fec mode */
19003 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
19004         TOKEN_STRING_INITIALIZER
19005                 (struct cmd_set_port_fec_mode,
19006                  set, "set");
19007 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
19008         TOKEN_STRING_INITIALIZER
19009                 (struct cmd_set_port_fec_mode,
19010                  port, "port");
19011 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
19012         TOKEN_NUM_INITIALIZER
19013                 (struct cmd_set_port_fec_mode,
19014                  port_id, UINT16);
19015 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
19016         TOKEN_STRING_INITIALIZER
19017                 (struct cmd_set_port_fec_mode,
19018                  fec_mode, "fec_mode");
19019 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
19020         TOKEN_STRING_INITIALIZER
19021                 (struct cmd_set_port_fec_mode,
19022                  fec_value, NULL);
19023
19024 static void
19025 cmd_set_port_fec_mode_parsed(
19026         void *parsed_result,
19027         __rte_unused struct cmdline *cl,
19028         __rte_unused void *data)
19029 {
19030         struct cmd_set_port_fec_mode *res = parsed_result;
19031         uint16_t port_id = res->port_id;
19032         uint32_t mode;
19033         int ret;
19034
19035         ret = parse_fec_mode(res->fec_value, &mode);
19036         if (ret < 0) {
19037                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
19038                         port_id);
19039                 return;
19040         }
19041
19042         ret = rte_eth_fec_set(port_id, mode);
19043         if (ret == -ENOTSUP) {
19044                 printf("Function not implemented\n");
19045                 return;
19046         } else if (ret < 0) {
19047                 printf("Set FEC mode failed\n");
19048                 return;
19049         }
19050 }
19051
19052 cmdline_parse_inst_t cmd_set_fec_mode = {
19053         .f = cmd_set_port_fec_mode_parsed,
19054         .data = NULL,
19055         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
19056         .tokens = {
19057                 (void *)&cmd_set_port_fec_mode_set,
19058                 (void *)&cmd_set_port_fec_mode_port,
19059                 (void *)&cmd_set_port_fec_mode_port_id,
19060                 (void *)&cmd_set_port_fec_mode_str,
19061                 (void *)&cmd_set_port_fec_mode_value,
19062                 NULL,
19063         },
19064 };
19065
19066 /* show port supported ptypes */
19067
19068 /* Common result structure for show port ptypes */
19069 struct cmd_show_port_supported_ptypes_result {
19070         cmdline_fixed_string_t show;
19071         cmdline_fixed_string_t port;
19072         portid_t port_id;
19073         cmdline_fixed_string_t ptypes;
19074 };
19075
19076 /* Common CLI fields for show port ptypes */
19077 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19078         TOKEN_STRING_INITIALIZER
19079                 (struct cmd_show_port_supported_ptypes_result,
19080                  show, "show");
19081 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19082         TOKEN_STRING_INITIALIZER
19083                 (struct cmd_show_port_supported_ptypes_result,
19084                  port, "port");
19085 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19086         TOKEN_NUM_INITIALIZER
19087                 (struct cmd_show_port_supported_ptypes_result,
19088                  port_id, UINT16);
19089 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19090         TOKEN_STRING_INITIALIZER
19091                 (struct cmd_show_port_supported_ptypes_result,
19092                  ptypes, "ptypes");
19093
19094 static void
19095 cmd_show_port_supported_ptypes_parsed(
19096         void *parsed_result,
19097         __rte_unused struct cmdline *cl,
19098         __rte_unused void *data)
19099 {
19100 #define RSVD_PTYPE_MASK       0xf0000000
19101 #define MAX_PTYPES_PER_LAYER  16
19102 #define LTYPE_NAMESIZE        32
19103 #define PTYPE_NAMESIZE        256
19104         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19105         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19106         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19107         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19108         uint16_t port_id = res->port_id;
19109         int ret, i;
19110
19111         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19112         if (ret < 0)
19113                 return;
19114
19115         while (ptype_mask != RSVD_PTYPE_MASK) {
19116
19117                 switch (ptype_mask) {
19118                 case RTE_PTYPE_L2_MASK:
19119                         strlcpy(ltype, "L2", sizeof(ltype));
19120                         break;
19121                 case RTE_PTYPE_L3_MASK:
19122                         strlcpy(ltype, "L3", sizeof(ltype));
19123                         break;
19124                 case RTE_PTYPE_L4_MASK:
19125                         strlcpy(ltype, "L4", sizeof(ltype));
19126                         break;
19127                 case RTE_PTYPE_TUNNEL_MASK:
19128                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19129                         break;
19130                 case RTE_PTYPE_INNER_L2_MASK:
19131                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19132                         break;
19133                 case RTE_PTYPE_INNER_L3_MASK:
19134                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19135                         break;
19136                 case RTE_PTYPE_INNER_L4_MASK:
19137                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19138                         break;
19139                 default:
19140                         return;
19141                 }
19142
19143                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19144                                                        ptype_mask, ptypes,
19145                                                        MAX_PTYPES_PER_LAYER);
19146
19147                 if (ret > 0)
19148                         printf("Supported %s ptypes:\n", ltype);
19149                 else
19150                         printf("%s ptypes unsupported\n", ltype);
19151
19152                 for (i = 0; i < ret; ++i) {
19153                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19154                         printf("%s\n", buf);
19155                 }
19156
19157                 ptype_mask <<= 4;
19158         }
19159 }
19160
19161 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19162         .f = cmd_show_port_supported_ptypes_parsed,
19163         .data = NULL,
19164         .help_str = "show port <port_id> ptypes",
19165         .tokens = {
19166                 (void *)&cmd_show_port_supported_ptypes_show,
19167                 (void *)&cmd_show_port_supported_ptypes_port,
19168                 (void *)&cmd_show_port_supported_ptypes_port_id,
19169                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19170                 NULL,
19171         },
19172 };
19173
19174 /* *** display rx/tx descriptor status *** */
19175 struct cmd_show_rx_tx_desc_status_result {
19176         cmdline_fixed_string_t cmd_show;
19177         cmdline_fixed_string_t cmd_port;
19178         cmdline_fixed_string_t cmd_keyword;
19179         cmdline_fixed_string_t cmd_desc;
19180         cmdline_fixed_string_t cmd_status;
19181         portid_t cmd_pid;
19182         portid_t cmd_qid;
19183         portid_t cmd_did;
19184 };
19185
19186 static void
19187 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19188                 __rte_unused struct cmdline *cl,
19189                 __rte_unused void *data)
19190 {
19191         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19192         int rc;
19193
19194         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19195                 printf("invalid port id %u\n", res->cmd_pid);
19196                 return;
19197         }
19198
19199         if (!strcmp(res->cmd_keyword, "rxq")) {
19200                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19201                                              res->cmd_did);
19202                 if (rc < 0) {
19203                         printf("Invalid queueid = %d\n", res->cmd_qid);
19204                         return;
19205                 }
19206                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19207                         printf("Desc status = AVAILABLE\n");
19208                 else if (rc == RTE_ETH_RX_DESC_DONE)
19209                         printf("Desc status = DONE\n");
19210                 else
19211                         printf("Desc status = UNAVAILABLE\n");
19212         } else if (!strcmp(res->cmd_keyword, "txq")) {
19213                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19214                                              res->cmd_did);
19215                 if (rc < 0) {
19216                         printf("Invalid queueid = %d\n", res->cmd_qid);
19217                         return;
19218                 }
19219                 if (rc == RTE_ETH_TX_DESC_FULL)
19220                         printf("Desc status = FULL\n");
19221                 else if (rc == RTE_ETH_TX_DESC_DONE)
19222                         printf("Desc status = DONE\n");
19223                 else
19224                         printf("Desc status = UNAVAILABLE\n");
19225         }
19226 }
19227
19228 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19229         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19230                         cmd_show, "show");
19231 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19232         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19233                         cmd_port, "port");
19234 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19235         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19236                         cmd_pid, UINT16);
19237 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19238         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19239                         cmd_keyword, "rxq#txq");
19240 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19241         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19242                         cmd_qid, UINT16);
19243 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19244         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19245                         cmd_desc, "desc");
19246 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19247         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19248                         cmd_did, UINT16);
19249 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19250         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19251                         cmd_status, "status");
19252 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19253         .f = cmd_show_rx_tx_desc_status_parsed,
19254         .data = NULL,
19255         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19256                 "status",
19257         .tokens = {
19258                 (void *)&cmd_show_rx_tx_desc_status_show,
19259                 (void *)&cmd_show_rx_tx_desc_status_port,
19260                 (void *)&cmd_show_rx_tx_desc_status_pid,
19261                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19262                 (void *)&cmd_show_rx_tx_desc_status_qid,
19263                 (void *)&cmd_show_rx_tx_desc_status_desc,
19264                 (void *)&cmd_show_rx_tx_desc_status_did,
19265                 (void *)&cmd_show_rx_tx_desc_status_status,
19266                 NULL,
19267         },
19268 };
19269
19270 /* Common result structure for set port ptypes */
19271 struct cmd_set_port_ptypes_result {
19272         cmdline_fixed_string_t set;
19273         cmdline_fixed_string_t port;
19274         portid_t port_id;
19275         cmdline_fixed_string_t ptype_mask;
19276         uint32_t mask;
19277 };
19278
19279 /* Common CLI fields for set port ptypes */
19280 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19281         TOKEN_STRING_INITIALIZER
19282                 (struct cmd_set_port_ptypes_result,
19283                  set, "set");
19284 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19285         TOKEN_STRING_INITIALIZER
19286                 (struct cmd_set_port_ptypes_result,
19287                  port, "port");
19288 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19289         TOKEN_NUM_INITIALIZER
19290                 (struct cmd_set_port_ptypes_result,
19291                  port_id, UINT16);
19292 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19293         TOKEN_STRING_INITIALIZER
19294                 (struct cmd_set_port_ptypes_result,
19295                  ptype_mask, "ptype_mask");
19296 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19297         TOKEN_NUM_INITIALIZER
19298                 (struct cmd_set_port_ptypes_result,
19299                  mask, UINT32);
19300
19301 static void
19302 cmd_set_port_ptypes_parsed(
19303         void *parsed_result,
19304         __rte_unused struct cmdline *cl,
19305         __rte_unused void *data)
19306 {
19307         struct cmd_set_port_ptypes_result *res = parsed_result;
19308 #define PTYPE_NAMESIZE        256
19309         char ptype_name[PTYPE_NAMESIZE];
19310         uint16_t port_id = res->port_id;
19311         uint32_t ptype_mask = res->mask;
19312         int ret, i;
19313
19314         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19315                                                NULL, 0);
19316         if (ret <= 0) {
19317                 printf("Port %d doesn't support any ptypes.\n", port_id);
19318                 return;
19319         }
19320
19321         uint32_t ptypes[ret];
19322
19323         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19324         if (ret < 0) {
19325                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19326                 return;
19327         }
19328
19329         printf("Successfully set following ptypes for Port %d\n", port_id);
19330         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19331                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19332                 printf("%s\n", ptype_name);
19333         }
19334
19335         clear_ptypes = false;
19336 }
19337
19338 cmdline_parse_inst_t cmd_set_port_ptypes = {
19339         .f = cmd_set_port_ptypes_parsed,
19340         .data = NULL,
19341         .help_str = "set port <port_id> ptype_mask <mask>",
19342         .tokens = {
19343                 (void *)&cmd_set_port_ptypes_set,
19344                 (void *)&cmd_set_port_ptypes_port,
19345                 (void *)&cmd_set_port_ptypes_port_id,
19346                 (void *)&cmd_set_port_ptypes_mask_str,
19347                 (void *)&cmd_set_port_ptypes_mask_u32,
19348                 NULL,
19349         },
19350 };
19351
19352 /* *** display mac addresses added to a port *** */
19353 struct cmd_showport_macs_result {
19354         cmdline_fixed_string_t cmd_show;
19355         cmdline_fixed_string_t cmd_port;
19356         cmdline_fixed_string_t cmd_keyword;
19357         portid_t cmd_pid;
19358 };
19359
19360 static void
19361 cmd_showport_macs_parsed(void *parsed_result,
19362                 __rte_unused struct cmdline *cl,
19363                 __rte_unused void *data)
19364 {
19365         struct cmd_showport_macs_result *res = parsed_result;
19366
19367         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19368                 return;
19369
19370         if (!strcmp(res->cmd_keyword, "macs"))
19371                 show_macs(res->cmd_pid);
19372         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19373                 show_mcast_macs(res->cmd_pid);
19374 }
19375
19376 cmdline_parse_token_string_t cmd_showport_macs_show =
19377         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19378                         cmd_show, "show");
19379 cmdline_parse_token_string_t cmd_showport_macs_port =
19380         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19381                         cmd_port, "port");
19382 cmdline_parse_token_num_t cmd_showport_macs_pid =
19383         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19384                         cmd_pid, UINT16);
19385 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19386         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19387                         cmd_keyword, "macs#mcast_macs");
19388
19389 cmdline_parse_inst_t cmd_showport_macs = {
19390         .f = cmd_showport_macs_parsed,
19391         .data = NULL,
19392         .help_str = "show port <port_id> macs|mcast_macs",
19393         .tokens = {
19394                 (void *)&cmd_showport_macs_show,
19395                 (void *)&cmd_showport_macs_port,
19396                 (void *)&cmd_showport_macs_pid,
19397                 (void *)&cmd_showport_macs_keyword,
19398                 NULL,
19399         },
19400 };
19401
19402 /* ******************************************************************************** */
19403
19404 /* list of instructions */
19405 cmdline_parse_ctx_t main_ctx[] = {
19406         (cmdline_parse_inst_t *)&cmd_help_brief,
19407         (cmdline_parse_inst_t *)&cmd_help_long,
19408         (cmdline_parse_inst_t *)&cmd_quit,
19409         (cmdline_parse_inst_t *)&cmd_load_from_file,
19410         (cmdline_parse_inst_t *)&cmd_showport,
19411         (cmdline_parse_inst_t *)&cmd_showqueue,
19412         (cmdline_parse_inst_t *)&cmd_showeeprom,
19413         (cmdline_parse_inst_t *)&cmd_showportall,
19414         (cmdline_parse_inst_t *)&cmd_showdevice,
19415         (cmdline_parse_inst_t *)&cmd_showcfg,
19416         (cmdline_parse_inst_t *)&cmd_showfwdall,
19417         (cmdline_parse_inst_t *)&cmd_start,
19418         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19419         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19420         (cmdline_parse_inst_t *)&cmd_set_link_up,
19421         (cmdline_parse_inst_t *)&cmd_set_link_down,
19422         (cmdline_parse_inst_t *)&cmd_reset,
19423         (cmdline_parse_inst_t *)&cmd_set_numbers,
19424         (cmdline_parse_inst_t *)&cmd_set_log,
19425         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
19426         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
19427         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19428         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19429         (cmdline_parse_inst_t *)&cmd_set_txtimes,
19430         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19431         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19432         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19433         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19434         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19435         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19436         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19437         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19438         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19439         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19440         (cmdline_parse_inst_t *)&cmd_set_link_check,
19441         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19442         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19443         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19444         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19445 #ifdef RTE_NET_BOND
19446         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19447         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19448         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19449         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19450         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19451         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19452         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19453         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19454         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19455         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19456         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19457 #endif
19458         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19459         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19460         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19461         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19462         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19463         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19464         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19465         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19466         (cmdline_parse_inst_t *)&cmd_csum_set,
19467         (cmdline_parse_inst_t *)&cmd_csum_show,
19468         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19469         (cmdline_parse_inst_t *)&cmd_tso_set,
19470         (cmdline_parse_inst_t *)&cmd_tso_show,
19471         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19472         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19473         (cmdline_parse_inst_t *)&cmd_gro_enable,
19474         (cmdline_parse_inst_t *)&cmd_gro_flush,
19475         (cmdline_parse_inst_t *)&cmd_gro_show,
19476         (cmdline_parse_inst_t *)&cmd_gso_enable,
19477         (cmdline_parse_inst_t *)&cmd_gso_size,
19478         (cmdline_parse_inst_t *)&cmd_gso_show,
19479         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19480         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19481         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19482         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19483         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19484         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19485         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19486         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19487         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19488         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19489         (cmdline_parse_inst_t *)&cmd_config_dcb,
19490         (cmdline_parse_inst_t *)&cmd_read_reg,
19491         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19492         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19493         (cmdline_parse_inst_t *)&cmd_write_reg,
19494         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19495         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19496         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19497         (cmdline_parse_inst_t *)&cmd_stop,
19498         (cmdline_parse_inst_t *)&cmd_mac_addr,
19499         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19500         (cmdline_parse_inst_t *)&cmd_set_qmap,
19501         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19502         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
19503         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
19504         (cmdline_parse_inst_t *)&cmd_operate_port,
19505         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19506         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19507         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19508         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19509         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19510         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19511         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19512         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19513         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19514         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19515         (cmdline_parse_inst_t *)&cmd_config_mtu,
19516         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19517         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19518         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19519         (cmdline_parse_inst_t *)&cmd_config_rss,
19520         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19521         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19522         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19523         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19524         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19525         (cmdline_parse_inst_t *)&cmd_showport_reta,
19526         (cmdline_parse_inst_t *)&cmd_showport_macs,
19527         (cmdline_parse_inst_t *)&cmd_config_burst,
19528         (cmdline_parse_inst_t *)&cmd_config_thresh,
19529         (cmdline_parse_inst_t *)&cmd_config_threshold,
19530         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19531         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19532         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19533         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19534         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19535         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19536         (cmdline_parse_inst_t *)&cmd_global_config,
19537         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19538         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19539         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19540         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19541         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19542         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19543         (cmdline_parse_inst_t *)&cmd_dump,
19544         (cmdline_parse_inst_t *)&cmd_dump_one,
19545         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19546         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19547         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19548         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19549         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19550         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19551         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19552         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19553         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19554         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19555         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19556         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19557         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19558         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19559         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19560         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19561         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19562         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19563         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19564         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19565         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19566         (cmdline_parse_inst_t *)&cmd_flow,
19567         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19568         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19569         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19570         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19571         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19572         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19573         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19574         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19575         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19576         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19577         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19578         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19579         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19580         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19581         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19582         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19583         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19584         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19585         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19586         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19587         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19588         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19589         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19590         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19591         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19592         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19593         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19594         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19595         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19596         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19597         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19598         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19599         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19600         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19601         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19602         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19603         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19604         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19605         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19606         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19607         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19608         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19609         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19610         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19611         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19612         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19613         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19614         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19615         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19616         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19617         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19618         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19619         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19620         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19621         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19622         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19623         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19624         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19625         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19626         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19627         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19628         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19629         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19630         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19631         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19632         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19633         (cmdline_parse_inst_t *)&cmd_ddp_add,
19634         (cmdline_parse_inst_t *)&cmd_ddp_del,
19635         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19636         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19637         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19638         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19639         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19640         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19641         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19642         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19643         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19644         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19645         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19646         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19647
19648         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19649         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19650         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19651         (cmdline_parse_inst_t *)&cmd_queue_region,
19652         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19653         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19654         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19655         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19656         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19657         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19658         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19659         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19660         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19661         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19662         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19663         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19664         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19665         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19666         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19667         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19668         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19669         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
19670         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19671         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19672         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19673         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19674         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19675         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19676         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19677         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19678         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19679         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19680         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19681         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19682         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19683         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19684         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19685         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19686         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19687         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19688 #ifdef RTE_LIB_BPF
19689         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19690         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19691 #endif
19692         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19693         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19694         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19695         (cmdline_parse_inst_t *)&cmd_set_raw,
19696         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19697         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19698         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19699         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
19700         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
19701         (cmdline_parse_inst_t *)&cmd_show_capability,
19702         NULL,
19703 };
19704
19705 /* read cmdline commands from file */
19706 void
19707 cmdline_read_from_file(const char *filename)
19708 {
19709         struct cmdline *cl;
19710
19711         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19712         if (cl == NULL) {
19713                 printf("Failed to create file based cmdline context: %s\n",
19714                        filename);
19715                 return;
19716         }
19717
19718         cmdline_interact(cl);
19719         cmdline_quit(cl);
19720
19721         cmdline_free(cl);
19722
19723         printf("Read CLI commands from %s\n", filename);
19724 }
19725
19726 /* prompt function, called from main on MAIN lcore */
19727 void
19728 prompt(void)
19729 {
19730         /* initialize non-constant commands */
19731         cmd_set_fwd_mode_init();
19732         cmd_set_fwd_retry_mode_init();
19733
19734         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19735         if (testpmd_cl == NULL)
19736                 return;
19737         cmdline_interact(testpmd_cl);
19738         cmdline_stdin_exit(testpmd_cl);
19739 }
19740
19741 void
19742 prompt_exit(void)
19743 {
19744         if (testpmd_cl != NULL)
19745                 cmdline_quit(testpmd_cl);
19746 }
19747
19748 static void
19749 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19750 {
19751         if (id == (portid_t)RTE_PORT_ALL) {
19752                 portid_t pid;
19753
19754                 RTE_ETH_FOREACH_DEV(pid) {
19755                         /* check if need_reconfig has been set to 1 */
19756                         if (ports[pid].need_reconfig == 0)
19757                                 ports[pid].need_reconfig = dev;
19758                         /* check if need_reconfig_queues has been set to 1 */
19759                         if (ports[pid].need_reconfig_queues == 0)
19760                                 ports[pid].need_reconfig_queues = queue;
19761                 }
19762         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19763                 /* check if need_reconfig has been set to 1 */
19764                 if (ports[id].need_reconfig == 0)
19765                         ports[id].need_reconfig = dev;
19766                 /* check if need_reconfig_queues has been set to 1 */
19767                 if (ports[id].need_reconfig_queues == 0)
19768                         ports[id].need_reconfig_queues = queue;
19769         }
19770 }