cae2444fdeef55cf885c7e4b7eba21c7474ffd01
[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                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
994                         "    Add/Del syn filter.\n\n"
995
996                         "flex_filter (port_id) (add|del) len (len_value)"
997                         " bytes (bytes_value) mask (mask_value)"
998                         " priority (prio_value) queue (queue_id)\n"
999                         "    Add/Del a flex filter.\n\n"
1000
1001                         "flow_director_filter (port_id) mode IP (add|del|update)"
1002                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
1003                         " src (src_ip_address) dst (dst_ip_address)"
1004                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
1005                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1006                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1007                         " fd_id (fd_id_value)\n"
1008                         "    Add/Del an IP type flow director filter.\n\n"
1009
1010                         "flow_director_filter (port_id) mode IP (add|del|update)"
1011                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
1012                         " src (src_ip_address) (src_port)"
1013                         " dst (dst_ip_address) (dst_port)"
1014                         " tos (tos_value) ttl (ttl_value)"
1015                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1016                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1017                         " fd_id (fd_id_value)\n"
1018                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1019
1020                         "flow_director_filter (port_id) mode IP (add|del|update)"
1021                         " flow (ipv4-sctp|ipv6-sctp)"
1022                         " src (src_ip_address) (src_port)"
1023                         " dst (dst_ip_address) (dst_port)"
1024                         " tag (verification_tag) "
1025                         " tos (tos_value) ttl (ttl_value)"
1026                         " vlan (vlan_value)"
1027                         " flexbytes (flexbytes_value) (drop|fwd)"
1028                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1029                         "    Add/Del a SCTP type flow director filter.\n\n"
1030
1031                         "flow_director_filter (port_id) mode IP (add|del|update)"
1032                         " flow l2_payload ether (ethertype)"
1033                         " flexbytes (flexbytes_value) (drop|fwd)"
1034                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1035                         "    Add/Del a l2 payload type flow director filter.\n\n"
1036
1037                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1038                         " mac (mac_address) vlan (vlan_value)"
1039                         " flexbytes (flexbytes_value) (drop|fwd)"
1040                         " queue (queue_id) fd_id (fd_id_value)\n"
1041                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1042
1043                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1044                         " mac (mac_address) vlan (vlan_value)"
1045                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1046                         " flexbytes (flexbytes_value) (drop|fwd)"
1047                         " queue (queue_id) fd_id (fd_id_value)\n"
1048                         "    Add/Del a Tunnel flow director filter.\n\n"
1049
1050                         "flow_director_filter (port_id) mode raw (add|del|update)"
1051                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1052                         " fd_id (fd_id_value) packet (packet file name)\n"
1053                         "    Add/Del a raw type flow director filter.\n\n"
1054
1055                         "flush_flow_director (port_id)\n"
1056                         "    Flush all flow director entries of a device.\n\n"
1057
1058                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1059                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1060                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1061                         "    Set flow director IP mask.\n\n"
1062
1063                         "flow_director_mask (port_id) mode MAC-VLAN"
1064                         " vlan (vlan_value)\n"
1065                         "    Set flow director MAC-VLAN mask.\n\n"
1066
1067                         "flow_director_mask (port_id) mode Tunnel"
1068                         " vlan (vlan_value) mac (mac_value)"
1069                         " tunnel-type (tunnel_type_value)"
1070                         " tunnel-id (tunnel_id_value)\n"
1071                         "    Set flow director Tunnel mask.\n\n"
1072
1073                         "flow_director_flex_mask (port_id)"
1074                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1075                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1076                         " (mask)\n"
1077                         "    Configure mask of flex payload.\n\n"
1078
1079                         "flow_director_flex_payload (port_id)"
1080                         " (raw|l2|l3|l4) (config)\n"
1081                         "    Configure flex payload selection.\n\n"
1082
1083                         "get_sym_hash_ena_per_port (port_id)\n"
1084                         "    get symmetric hash enable configuration per port.\n\n"
1085
1086                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1087                         "    set symmetric hash enable configuration per port"
1088                         " to enable or disable.\n\n"
1089
1090                         "get_hash_global_config (port_id)\n"
1091                         "    Get the global configurations of hash filters.\n\n"
1092
1093                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1094                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1095                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1096                         " (enable|disable)\n"
1097                         "    Set the global configurations of hash filters.\n\n"
1098
1099                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1100                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1101                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1102                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1103                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1104                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1105                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1106                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1107                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1108                         "fld-8th|none) (select|add)\n"
1109                         "    Set the input set for hash.\n\n"
1110
1111                         "set_fdir_input_set (port_id) "
1112                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1113                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1114                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1115                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1116                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1117                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1118                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1119                         " (select|add)\n"
1120                         "    Set the input set for FDir.\n\n"
1121
1122                         "flow validate {port_id}"
1123                         " [group {group_id}] [priority {level}]"
1124                         " [ingress] [egress]"
1125                         " pattern {item} [/ {item} [...]] / end"
1126                         " actions {action} [/ {action} [...]] / end\n"
1127                         "    Check whether a flow rule can be created.\n\n"
1128
1129                         "flow create {port_id}"
1130                         " [group {group_id}] [priority {level}]"
1131                         " [ingress] [egress]"
1132                         " pattern {item} [/ {item} [...]] / end"
1133                         " actions {action} [/ {action} [...]] / end\n"
1134                         "    Create a flow rule.\n\n"
1135
1136                         "flow destroy {port_id} rule {rule_id} [...]\n"
1137                         "    Destroy specific flow rules.\n\n"
1138
1139                         "flow flush {port_id}\n"
1140                         "    Destroy all flow rules.\n\n"
1141
1142                         "flow query {port_id} {rule_id} {action}\n"
1143                         "    Query an existing flow rule.\n\n"
1144
1145                         "flow list {port_id} [group {group_id}] [...]\n"
1146                         "    List existing flow rules sorted by priority,"
1147                         " filtered by group identifiers.\n\n"
1148
1149                         "flow isolate {port_id} {boolean}\n"
1150                         "    Restrict ingress traffic to the defined"
1151                         " flow rules\n\n"
1152
1153                         "flow aged {port_id} [destroy]\n"
1154                         "    List and destroy aged flows"
1155                         " flow rules\n\n"
1156
1157                         "flow shared_action {port_id} create"
1158                         " [action_id {shared_action_id}]"
1159                         " [ingress] [egress]"
1160                         " action {action} / end\n"
1161                         "    Create shared action.\n\n"
1162
1163                         "flow shared_action {port_id} update"
1164                         " {shared_action_id} action {action} / end\n"
1165                         "    Update shared action.\n\n"
1166
1167                         "flow shared_action {port_id} destroy"
1168                         " action_id {shared_action_id} [...]\n"
1169                         "    Destroy specific shared actions.\n\n"
1170
1171                         "flow shared_action {port_id} query"
1172                         " {shared_action_id}\n"
1173                         "    Query an existing shared action.\n\n"
1174
1175                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1176                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1177                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1178                         "       Configure the VXLAN encapsulation for flows.\n\n"
1179
1180                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1181                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1182                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1183                         " eth-dst (eth-dst)\n"
1184                         "       Configure the VXLAN encapsulation for flows.\n\n"
1185
1186                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1187                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1188                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1189                         " eth-dst (eth-dst)\n"
1190                         "       Configure the VXLAN encapsulation for flows.\n\n"
1191
1192                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1193                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1194                         " (eth-dst)\n"
1195                         "       Configure the NVGRE encapsulation for flows.\n\n"
1196
1197                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1198                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1199                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1200                         "       Configure the NVGRE encapsulation for flows.\n\n"
1201
1202                         "set raw_encap {flow items}\n"
1203                         "       Configure the encapsulation with raw data.\n\n"
1204
1205                         "set raw_decap {flow items}\n"
1206                         "       Configure the decapsulation with raw data.\n\n"
1207
1208                 );
1209         }
1210
1211         if (show_all || !strcmp(res->section, "traffic_management")) {
1212                 cmdline_printf(
1213                         cl,
1214                         "\n"
1215                         "Traffic Management:\n"
1216                         "--------------\n"
1217                         "show port tm cap (port_id)\n"
1218                         "       Display the port TM capability.\n\n"
1219
1220                         "show port tm level cap (port_id) (level_id)\n"
1221                         "       Display the port TM hierarchical level capability.\n\n"
1222
1223                         "show port tm node cap (port_id) (node_id)\n"
1224                         "       Display the port TM node capability.\n\n"
1225
1226                         "show port tm node type (port_id) (node_id)\n"
1227                         "       Display the port TM node type.\n\n"
1228
1229                         "show port tm node stats (port_id) (node_id) (clear)\n"
1230                         "       Display the port TM node stats.\n\n"
1231
1232                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1233                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1234                         " (packet_length_adjust) (packet_mode)\n"
1235                         "       Add port tm node private shaper profile.\n\n"
1236
1237                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1238                         "       Delete port tm node private shaper profile.\n\n"
1239
1240                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1241                         " (shaper_profile_id)\n"
1242                         "       Add/update port tm node shared shaper.\n\n"
1243
1244                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1245                         "       Delete port tm node shared shaper.\n\n"
1246
1247                         "set port tm node shaper profile (port_id) (node_id)"
1248                         " (shaper_profile_id)\n"
1249                         "       Set port tm node shaper profile.\n\n"
1250
1251                         "add port tm node wred profile (port_id) (wred_profile_id)"
1252                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1253                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1254                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1255                         "       Add port tm node wred profile.\n\n"
1256
1257                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1258                         "       Delete port tm node wred profile.\n\n"
1259
1260                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1261                         " (priority) (weight) (level_id) (shaper_profile_id)"
1262                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1263                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1264                         "       Add port tm nonleaf node.\n\n"
1265
1266                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1267                         " (priority) (weight) (level_id) (shaper_profile_id)"
1268                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1269                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1270                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1271
1272                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1273                         " (priority) (weight) (level_id) (shaper_profile_id)"
1274                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1275                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1276                         "       Add port tm leaf node.\n\n"
1277
1278                         "del port tm node (port_id) (node_id)\n"
1279                         "       Delete port tm node.\n\n"
1280
1281                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1282                         " (priority) (weight)\n"
1283                         "       Set port tm node parent.\n\n"
1284
1285                         "suspend port tm node (port_id) (node_id)"
1286                         "       Suspend tm node.\n\n"
1287
1288                         "resume port tm node (port_id) (node_id)"
1289                         "       Resume tm node.\n\n"
1290
1291                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1292                         "       Commit tm hierarchy.\n\n"
1293
1294                         "set port tm mark ip_ecn (port) (green) (yellow)"
1295                         " (red)\n"
1296                         "    Enables/Disables the traffic management marking"
1297                         " for IP ECN (Explicit Congestion Notification)"
1298                         " packets on a given port\n\n"
1299
1300                         "set port tm mark ip_dscp (port) (green) (yellow)"
1301                         " (red)\n"
1302                         "    Enables/Disables the traffic management marking"
1303                         " on the port for IP dscp packets\n\n"
1304
1305                         "set port tm mark vlan_dei (port) (green) (yellow)"
1306                         " (red)\n"
1307                         "    Enables/Disables the traffic management marking"
1308                         " on the port for VLAN packets with DEI enabled\n\n"
1309                 );
1310         }
1311
1312         if (show_all || !strcmp(res->section, "devices")) {
1313                 cmdline_printf(
1314                         cl,
1315                         "\n"
1316                         "Device Operations:\n"
1317                         "--------------\n"
1318                         "device detach (identifier)\n"
1319                         "       Detach device by identifier.\n\n"
1320                 );
1321         }
1322
1323 }
1324
1325 cmdline_parse_token_string_t cmd_help_long_help =
1326         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1327
1328 cmdline_parse_token_string_t cmd_help_long_section =
1329         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1330                         "all#control#display#config#"
1331                         "ports#registers#filters#traffic_management#devices");
1332
1333 cmdline_parse_inst_t cmd_help_long = {
1334         .f = cmd_help_long_parsed,
1335         .data = NULL,
1336         .help_str = "help all|control|display|config|ports|register|"
1337                 "filters|traffic_management|devices: "
1338                 "Show help",
1339         .tokens = {
1340                 (void *)&cmd_help_long_help,
1341                 (void *)&cmd_help_long_section,
1342                 NULL,
1343         },
1344 };
1345
1346
1347 /* *** start/stop/close all ports *** */
1348 struct cmd_operate_port_result {
1349         cmdline_fixed_string_t keyword;
1350         cmdline_fixed_string_t name;
1351         cmdline_fixed_string_t value;
1352 };
1353
1354 static void cmd_operate_port_parsed(void *parsed_result,
1355                                 __rte_unused struct cmdline *cl,
1356                                 __rte_unused void *data)
1357 {
1358         struct cmd_operate_port_result *res = parsed_result;
1359
1360         if (!strcmp(res->name, "start"))
1361                 start_port(RTE_PORT_ALL);
1362         else if (!strcmp(res->name, "stop"))
1363                 stop_port(RTE_PORT_ALL);
1364         else if (!strcmp(res->name, "close"))
1365                 close_port(RTE_PORT_ALL);
1366         else if (!strcmp(res->name, "reset"))
1367                 reset_port(RTE_PORT_ALL);
1368         else
1369                 printf("Unknown parameter\n");
1370 }
1371
1372 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1373         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1374                                                                 "port");
1375 cmdline_parse_token_string_t cmd_operate_port_all_port =
1376         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1377                                                 "start#stop#close#reset");
1378 cmdline_parse_token_string_t cmd_operate_port_all_all =
1379         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1380
1381 cmdline_parse_inst_t cmd_operate_port = {
1382         .f = cmd_operate_port_parsed,
1383         .data = NULL,
1384         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1385         .tokens = {
1386                 (void *)&cmd_operate_port_all_cmd,
1387                 (void *)&cmd_operate_port_all_port,
1388                 (void *)&cmd_operate_port_all_all,
1389                 NULL,
1390         },
1391 };
1392
1393 /* *** start/stop/close specific port *** */
1394 struct cmd_operate_specific_port_result {
1395         cmdline_fixed_string_t keyword;
1396         cmdline_fixed_string_t name;
1397         uint8_t value;
1398 };
1399
1400 static void cmd_operate_specific_port_parsed(void *parsed_result,
1401                         __rte_unused struct cmdline *cl,
1402                                 __rte_unused void *data)
1403 {
1404         struct cmd_operate_specific_port_result *res = parsed_result;
1405
1406         if (!strcmp(res->name, "start"))
1407                 start_port(res->value);
1408         else if (!strcmp(res->name, "stop"))
1409                 stop_port(res->value);
1410         else if (!strcmp(res->name, "close"))
1411                 close_port(res->value);
1412         else if (!strcmp(res->name, "reset"))
1413                 reset_port(res->value);
1414         else
1415                 printf("Unknown parameter\n");
1416 }
1417
1418 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1419         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1420                                                         keyword, "port");
1421 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1422         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1423                                                 name, "start#stop#close#reset");
1424 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1425         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1426                                                         value, UINT8);
1427
1428 cmdline_parse_inst_t cmd_operate_specific_port = {
1429         .f = cmd_operate_specific_port_parsed,
1430         .data = NULL,
1431         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1432         .tokens = {
1433                 (void *)&cmd_operate_specific_port_cmd,
1434                 (void *)&cmd_operate_specific_port_port,
1435                 (void *)&cmd_operate_specific_port_id,
1436                 NULL,
1437         },
1438 };
1439
1440 /* *** enable port setup (after attach) via iterator or event *** */
1441 struct cmd_set_port_setup_on_result {
1442         cmdline_fixed_string_t set;
1443         cmdline_fixed_string_t port;
1444         cmdline_fixed_string_t setup;
1445         cmdline_fixed_string_t on;
1446         cmdline_fixed_string_t mode;
1447 };
1448
1449 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1450                                 __rte_unused struct cmdline *cl,
1451                                 __rte_unused void *data)
1452 {
1453         struct cmd_set_port_setup_on_result *res = parsed_result;
1454
1455         if (strcmp(res->mode, "event") == 0)
1456                 setup_on_probe_event = true;
1457         else if (strcmp(res->mode, "iterator") == 0)
1458                 setup_on_probe_event = false;
1459         else
1460                 printf("Unknown mode\n");
1461 }
1462
1463 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1464         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1465                         set, "set");
1466 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1467         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1468                         port, "port");
1469 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1470         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1471                         setup, "setup");
1472 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1473         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1474                         on, "on");
1475 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1476         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1477                         mode, "iterator#event");
1478
1479 cmdline_parse_inst_t cmd_set_port_setup_on = {
1480         .f = cmd_set_port_setup_on_parsed,
1481         .data = NULL,
1482         .help_str = "set port setup on iterator|event",
1483         .tokens = {
1484                 (void *)&cmd_set_port_setup_on_set,
1485                 (void *)&cmd_set_port_setup_on_port,
1486                 (void *)&cmd_set_port_setup_on_setup,
1487                 (void *)&cmd_set_port_setup_on_on,
1488                 (void *)&cmd_set_port_setup_on_mode,
1489                 NULL,
1490         },
1491 };
1492
1493 /* *** attach a specified port *** */
1494 struct cmd_operate_attach_port_result {
1495         cmdline_fixed_string_t port;
1496         cmdline_fixed_string_t keyword;
1497         cmdline_multi_string_t identifier;
1498 };
1499
1500 static void cmd_operate_attach_port_parsed(void *parsed_result,
1501                                 __rte_unused struct cmdline *cl,
1502                                 __rte_unused void *data)
1503 {
1504         struct cmd_operate_attach_port_result *res = parsed_result;
1505
1506         if (!strcmp(res->keyword, "attach"))
1507                 attach_port(res->identifier);
1508         else
1509                 printf("Unknown parameter\n");
1510 }
1511
1512 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1513         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1514                         port, "port");
1515 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1516         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1517                         keyword, "attach");
1518 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1519         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1520                         identifier, TOKEN_STRING_MULTI);
1521
1522 cmdline_parse_inst_t cmd_operate_attach_port = {
1523         .f = cmd_operate_attach_port_parsed,
1524         .data = NULL,
1525         .help_str = "port attach <identifier>: "
1526                 "(identifier: pci address or virtual dev name)",
1527         .tokens = {
1528                 (void *)&cmd_operate_attach_port_port,
1529                 (void *)&cmd_operate_attach_port_keyword,
1530                 (void *)&cmd_operate_attach_port_identifier,
1531                 NULL,
1532         },
1533 };
1534
1535 /* *** detach a specified port *** */
1536 struct cmd_operate_detach_port_result {
1537         cmdline_fixed_string_t port;
1538         cmdline_fixed_string_t keyword;
1539         portid_t port_id;
1540 };
1541
1542 static void cmd_operate_detach_port_parsed(void *parsed_result,
1543                                 __rte_unused struct cmdline *cl,
1544                                 __rte_unused void *data)
1545 {
1546         struct cmd_operate_detach_port_result *res = parsed_result;
1547
1548         if (!strcmp(res->keyword, "detach")) {
1549                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1550                 detach_port_device(res->port_id);
1551         } else {
1552                 printf("Unknown parameter\n");
1553         }
1554 }
1555
1556 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1557         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1558                         port, "port");
1559 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1560         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1561                         keyword, "detach");
1562 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1563         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1564                         port_id, UINT16);
1565
1566 cmdline_parse_inst_t cmd_operate_detach_port = {
1567         .f = cmd_operate_detach_port_parsed,
1568         .data = NULL,
1569         .help_str = "port detach <port_id>",
1570         .tokens = {
1571                 (void *)&cmd_operate_detach_port_port,
1572                 (void *)&cmd_operate_detach_port_keyword,
1573                 (void *)&cmd_operate_detach_port_port_id,
1574                 NULL,
1575         },
1576 };
1577
1578 /* *** detach device by identifier *** */
1579 struct cmd_operate_detach_device_result {
1580         cmdline_fixed_string_t device;
1581         cmdline_fixed_string_t keyword;
1582         cmdline_fixed_string_t identifier;
1583 };
1584
1585 static void cmd_operate_detach_device_parsed(void *parsed_result,
1586                                 __rte_unused struct cmdline *cl,
1587                                 __rte_unused void *data)
1588 {
1589         struct cmd_operate_detach_device_result *res = parsed_result;
1590
1591         if (!strcmp(res->keyword, "detach"))
1592                 detach_devargs(res->identifier);
1593         else
1594                 printf("Unknown parameter\n");
1595 }
1596
1597 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1598         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1599                         device, "device");
1600 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1601         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1602                         keyword, "detach");
1603 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1604         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1605                         identifier, NULL);
1606
1607 cmdline_parse_inst_t cmd_operate_detach_device = {
1608         .f = cmd_operate_detach_device_parsed,
1609         .data = NULL,
1610         .help_str = "device detach <identifier>:"
1611                 "(identifier: pci address or virtual dev name)",
1612         .tokens = {
1613                 (void *)&cmd_operate_detach_device_device,
1614                 (void *)&cmd_operate_detach_device_keyword,
1615                 (void *)&cmd_operate_detach_device_identifier,
1616                 NULL,
1617         },
1618 };
1619 /* *** configure speed for all ports *** */
1620 struct cmd_config_speed_all {
1621         cmdline_fixed_string_t port;
1622         cmdline_fixed_string_t keyword;
1623         cmdline_fixed_string_t all;
1624         cmdline_fixed_string_t item1;
1625         cmdline_fixed_string_t item2;
1626         cmdline_fixed_string_t value1;
1627         cmdline_fixed_string_t value2;
1628 };
1629
1630 static int
1631 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1632 {
1633
1634         int duplex;
1635
1636         if (!strcmp(duplexstr, "half")) {
1637                 duplex = ETH_LINK_HALF_DUPLEX;
1638         } else if (!strcmp(duplexstr, "full")) {
1639                 duplex = ETH_LINK_FULL_DUPLEX;
1640         } else if (!strcmp(duplexstr, "auto")) {
1641                 duplex = ETH_LINK_FULL_DUPLEX;
1642         } else {
1643                 printf("Unknown duplex parameter\n");
1644                 return -1;
1645         }
1646
1647         if (!strcmp(speedstr, "10")) {
1648                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1649                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1650         } else if (!strcmp(speedstr, "100")) {
1651                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1652                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1653         } else {
1654                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1655                         printf("Invalid speed/duplex parameters\n");
1656                         return -1;
1657                 }
1658                 if (!strcmp(speedstr, "1000")) {
1659                         *speed = ETH_LINK_SPEED_1G;
1660                 } else if (!strcmp(speedstr, "10000")) {
1661                         *speed = ETH_LINK_SPEED_10G;
1662                 } else if (!strcmp(speedstr, "25000")) {
1663                         *speed = ETH_LINK_SPEED_25G;
1664                 } else if (!strcmp(speedstr, "40000")) {
1665                         *speed = ETH_LINK_SPEED_40G;
1666                 } else if (!strcmp(speedstr, "50000")) {
1667                         *speed = ETH_LINK_SPEED_50G;
1668                 } else if (!strcmp(speedstr, "100000")) {
1669                         *speed = ETH_LINK_SPEED_100G;
1670                 } else if (!strcmp(speedstr, "200000")) {
1671                         *speed = ETH_LINK_SPEED_200G;
1672                 } else if (!strcmp(speedstr, "auto")) {
1673                         *speed = ETH_LINK_SPEED_AUTONEG;
1674                 } else {
1675                         printf("Unknown speed parameter\n");
1676                         return -1;
1677                 }
1678         }
1679
1680         return 0;
1681 }
1682
1683 static void
1684 cmd_config_speed_all_parsed(void *parsed_result,
1685                         __rte_unused struct cmdline *cl,
1686                         __rte_unused void *data)
1687 {
1688         struct cmd_config_speed_all *res = parsed_result;
1689         uint32_t link_speed;
1690         portid_t pid;
1691
1692         if (!all_ports_stopped()) {
1693                 printf("Please stop all ports first\n");
1694                 return;
1695         }
1696
1697         if (parse_and_check_speed_duplex(res->value1, res->value2,
1698                         &link_speed) < 0)
1699                 return;
1700
1701         RTE_ETH_FOREACH_DEV(pid) {
1702                 ports[pid].dev_conf.link_speeds = link_speed;
1703         }
1704
1705         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1706 }
1707
1708 cmdline_parse_token_string_t cmd_config_speed_all_port =
1709         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1710 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1711         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1712                                                         "config");
1713 cmdline_parse_token_string_t cmd_config_speed_all_all =
1714         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1715 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1716         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1717 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1718         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1719                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1720 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1721         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1722 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1723         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1724                                                 "half#full#auto");
1725
1726 cmdline_parse_inst_t cmd_config_speed_all = {
1727         .f = cmd_config_speed_all_parsed,
1728         .data = NULL,
1729         .help_str = "port config all speed "
1730                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1731                                                         "half|full|auto",
1732         .tokens = {
1733                 (void *)&cmd_config_speed_all_port,
1734                 (void *)&cmd_config_speed_all_keyword,
1735                 (void *)&cmd_config_speed_all_all,
1736                 (void *)&cmd_config_speed_all_item1,
1737                 (void *)&cmd_config_speed_all_value1,
1738                 (void *)&cmd_config_speed_all_item2,
1739                 (void *)&cmd_config_speed_all_value2,
1740                 NULL,
1741         },
1742 };
1743
1744 /* *** configure speed for specific port *** */
1745 struct cmd_config_speed_specific {
1746         cmdline_fixed_string_t port;
1747         cmdline_fixed_string_t keyword;
1748         portid_t id;
1749         cmdline_fixed_string_t item1;
1750         cmdline_fixed_string_t item2;
1751         cmdline_fixed_string_t value1;
1752         cmdline_fixed_string_t value2;
1753 };
1754
1755 static void
1756 cmd_config_speed_specific_parsed(void *parsed_result,
1757                                 __rte_unused struct cmdline *cl,
1758                                 __rte_unused void *data)
1759 {
1760         struct cmd_config_speed_specific *res = parsed_result;
1761         uint32_t link_speed;
1762
1763         if (!all_ports_stopped()) {
1764                 printf("Please stop all ports first\n");
1765                 return;
1766         }
1767
1768         if (port_id_is_invalid(res->id, ENABLED_WARN))
1769                 return;
1770
1771         if (parse_and_check_speed_duplex(res->value1, res->value2,
1772                         &link_speed) < 0)
1773                 return;
1774
1775         ports[res->id].dev_conf.link_speeds = link_speed;
1776
1777         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1778 }
1779
1780
1781 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1782         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1783                                                                 "port");
1784 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1785         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1786                                                                 "config");
1787 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1788         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1789 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1790         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1791                                                                 "speed");
1792 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1793         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1794                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1795 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1796         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1797                                                                 "duplex");
1798 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1799         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1800                                                         "half#full#auto");
1801
1802 cmdline_parse_inst_t cmd_config_speed_specific = {
1803         .f = cmd_config_speed_specific_parsed,
1804         .data = NULL,
1805         .help_str = "port config <port_id> speed "
1806                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1807                                                         "half|full|auto",
1808         .tokens = {
1809                 (void *)&cmd_config_speed_specific_port,
1810                 (void *)&cmd_config_speed_specific_keyword,
1811                 (void *)&cmd_config_speed_specific_id,
1812                 (void *)&cmd_config_speed_specific_item1,
1813                 (void *)&cmd_config_speed_specific_value1,
1814                 (void *)&cmd_config_speed_specific_item2,
1815                 (void *)&cmd_config_speed_specific_value2,
1816                 NULL,
1817         },
1818 };
1819
1820 /* *** configure loopback for all ports *** */
1821 struct cmd_config_loopback_all {
1822         cmdline_fixed_string_t port;
1823         cmdline_fixed_string_t keyword;
1824         cmdline_fixed_string_t all;
1825         cmdline_fixed_string_t item;
1826         uint32_t mode;
1827 };
1828
1829 static void
1830 cmd_config_loopback_all_parsed(void *parsed_result,
1831                         __rte_unused struct cmdline *cl,
1832                         __rte_unused void *data)
1833 {
1834         struct cmd_config_loopback_all *res = parsed_result;
1835         portid_t pid;
1836
1837         if (!all_ports_stopped()) {
1838                 printf("Please stop all ports first\n");
1839                 return;
1840         }
1841
1842         RTE_ETH_FOREACH_DEV(pid) {
1843                 ports[pid].dev_conf.lpbk_mode = res->mode;
1844         }
1845
1846         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1847 }
1848
1849 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1850         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1851 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1852         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1853                                                         "config");
1854 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1855         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1856 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1857         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1858                                                         "loopback");
1859 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1860         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1861
1862 cmdline_parse_inst_t cmd_config_loopback_all = {
1863         .f = cmd_config_loopback_all_parsed,
1864         .data = NULL,
1865         .help_str = "port config all loopback <mode>",
1866         .tokens = {
1867                 (void *)&cmd_config_loopback_all_port,
1868                 (void *)&cmd_config_loopback_all_keyword,
1869                 (void *)&cmd_config_loopback_all_all,
1870                 (void *)&cmd_config_loopback_all_item,
1871                 (void *)&cmd_config_loopback_all_mode,
1872                 NULL,
1873         },
1874 };
1875
1876 /* *** configure loopback for specific port *** */
1877 struct cmd_config_loopback_specific {
1878         cmdline_fixed_string_t port;
1879         cmdline_fixed_string_t keyword;
1880         uint16_t port_id;
1881         cmdline_fixed_string_t item;
1882         uint32_t mode;
1883 };
1884
1885 static void
1886 cmd_config_loopback_specific_parsed(void *parsed_result,
1887                                 __rte_unused struct cmdline *cl,
1888                                 __rte_unused void *data)
1889 {
1890         struct cmd_config_loopback_specific *res = parsed_result;
1891
1892         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1893                 return;
1894
1895         if (!port_is_stopped(res->port_id)) {
1896                 printf("Please stop port %u first\n", res->port_id);
1897                 return;
1898         }
1899
1900         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1901
1902         cmd_reconfig_device_queue(res->port_id, 1, 1);
1903 }
1904
1905
1906 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1907         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1908                                                                 "port");
1909 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1910         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1911                                                                 "config");
1912 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1913         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1914                                                                 UINT16);
1915 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1916         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1917                                                                 "loopback");
1918 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1919         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1920                               UINT32);
1921
1922 cmdline_parse_inst_t cmd_config_loopback_specific = {
1923         .f = cmd_config_loopback_specific_parsed,
1924         .data = NULL,
1925         .help_str = "port config <port_id> loopback <mode>",
1926         .tokens = {
1927                 (void *)&cmd_config_loopback_specific_port,
1928                 (void *)&cmd_config_loopback_specific_keyword,
1929                 (void *)&cmd_config_loopback_specific_id,
1930                 (void *)&cmd_config_loopback_specific_item,
1931                 (void *)&cmd_config_loopback_specific_mode,
1932                 NULL,
1933         },
1934 };
1935
1936 /* *** configure txq/rxq, txd/rxd *** */
1937 struct cmd_config_rx_tx {
1938         cmdline_fixed_string_t port;
1939         cmdline_fixed_string_t keyword;
1940         cmdline_fixed_string_t all;
1941         cmdline_fixed_string_t name;
1942         uint16_t value;
1943 };
1944
1945 static void
1946 cmd_config_rx_tx_parsed(void *parsed_result,
1947                         __rte_unused struct cmdline *cl,
1948                         __rte_unused void *data)
1949 {
1950         struct cmd_config_rx_tx *res = parsed_result;
1951
1952         if (!all_ports_stopped()) {
1953                 printf("Please stop all ports first\n");
1954                 return;
1955         }
1956         if (!strcmp(res->name, "rxq")) {
1957                 if (!res->value && !nb_txq) {
1958                         printf("Warning: Either rx or tx queues should be non zero\n");
1959                         return;
1960                 }
1961                 if (check_nb_rxq(res->value) != 0)
1962                         return;
1963                 nb_rxq = res->value;
1964         }
1965         else if (!strcmp(res->name, "txq")) {
1966                 if (!res->value && !nb_rxq) {
1967                         printf("Warning: Either rx or tx queues should be non zero\n");
1968                         return;
1969                 }
1970                 if (check_nb_txq(res->value) != 0)
1971                         return;
1972                 nb_txq = res->value;
1973         }
1974         else if (!strcmp(res->name, "rxd")) {
1975                 if (check_nb_rxd(res->value) != 0)
1976                         return;
1977                 nb_rxd = res->value;
1978         } else if (!strcmp(res->name, "txd")) {
1979                 if (check_nb_txd(res->value) != 0)
1980                         return;
1981
1982                 nb_txd = res->value;
1983         } else {
1984                 printf("Unknown parameter\n");
1985                 return;
1986         }
1987
1988         fwd_config_setup();
1989
1990         init_port_config();
1991
1992         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1993 }
1994
1995 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1996         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1997 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1998         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1999 cmdline_parse_token_string_t cmd_config_rx_tx_all =
2000         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
2001 cmdline_parse_token_string_t cmd_config_rx_tx_name =
2002         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
2003                                                 "rxq#txq#rxd#txd");
2004 cmdline_parse_token_num_t cmd_config_rx_tx_value =
2005         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
2006
2007 cmdline_parse_inst_t cmd_config_rx_tx = {
2008         .f = cmd_config_rx_tx_parsed,
2009         .data = NULL,
2010         .help_str = "port config all rxq|txq|rxd|txd <value>",
2011         .tokens = {
2012                 (void *)&cmd_config_rx_tx_port,
2013                 (void *)&cmd_config_rx_tx_keyword,
2014                 (void *)&cmd_config_rx_tx_all,
2015                 (void *)&cmd_config_rx_tx_name,
2016                 (void *)&cmd_config_rx_tx_value,
2017                 NULL,
2018         },
2019 };
2020
2021 /* *** config max packet length *** */
2022 struct cmd_config_max_pkt_len_result {
2023         cmdline_fixed_string_t port;
2024         cmdline_fixed_string_t keyword;
2025         cmdline_fixed_string_t all;
2026         cmdline_fixed_string_t name;
2027         uint32_t value;
2028 };
2029
2030 static void
2031 cmd_config_max_pkt_len_parsed(void *parsed_result,
2032                                 __rte_unused struct cmdline *cl,
2033                                 __rte_unused void *data)
2034 {
2035         struct cmd_config_max_pkt_len_result *res = parsed_result;
2036         portid_t pid;
2037
2038         if (!all_ports_stopped()) {
2039                 printf("Please stop all ports first\n");
2040                 return;
2041         }
2042
2043         RTE_ETH_FOREACH_DEV(pid) {
2044                 struct rte_port *port = &ports[pid];
2045                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2046
2047                 if (!strcmp(res->name, "max-pkt-len")) {
2048                         if (res->value < RTE_ETHER_MIN_LEN) {
2049                                 printf("max-pkt-len can not be less than %d\n",
2050                                                 RTE_ETHER_MIN_LEN);
2051                                 return;
2052                         }
2053                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2054                                 return;
2055
2056                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2057                         if (res->value > RTE_ETHER_MAX_LEN)
2058                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2059                         else
2060                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2061                         port->dev_conf.rxmode.offloads = rx_offloads;
2062                 } else {
2063                         printf("Unknown parameter\n");
2064                         return;
2065                 }
2066         }
2067
2068         init_port_config();
2069
2070         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2071 }
2072
2073 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2074         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2075                                                                 "port");
2076 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2077         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2078                                                                 "config");
2079 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2080         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2081                                                                 "all");
2082 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2083         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2084                                                                 "max-pkt-len");
2085 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2086         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2087                                                                 UINT32);
2088
2089 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2090         .f = cmd_config_max_pkt_len_parsed,
2091         .data = NULL,
2092         .help_str = "port config all max-pkt-len <value>",
2093         .tokens = {
2094                 (void *)&cmd_config_max_pkt_len_port,
2095                 (void *)&cmd_config_max_pkt_len_keyword,
2096                 (void *)&cmd_config_max_pkt_len_all,
2097                 (void *)&cmd_config_max_pkt_len_name,
2098                 (void *)&cmd_config_max_pkt_len_value,
2099                 NULL,
2100         },
2101 };
2102
2103 /* *** config max LRO aggregated packet size *** */
2104 struct cmd_config_max_lro_pkt_size_result {
2105         cmdline_fixed_string_t port;
2106         cmdline_fixed_string_t keyword;
2107         cmdline_fixed_string_t all;
2108         cmdline_fixed_string_t name;
2109         uint32_t value;
2110 };
2111
2112 static void
2113 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2114                                 __rte_unused struct cmdline *cl,
2115                                 __rte_unused void *data)
2116 {
2117         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2118         portid_t pid;
2119
2120         if (!all_ports_stopped()) {
2121                 printf("Please stop all ports first\n");
2122                 return;
2123         }
2124
2125         RTE_ETH_FOREACH_DEV(pid) {
2126                 struct rte_port *port = &ports[pid];
2127
2128                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2129                         if (res->value ==
2130                                         port->dev_conf.rxmode.max_lro_pkt_size)
2131                                 return;
2132
2133                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2134                 } else {
2135                         printf("Unknown parameter\n");
2136                         return;
2137                 }
2138         }
2139
2140         init_port_config();
2141
2142         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2143 }
2144
2145 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2146         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2147                                  port, "port");
2148 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2149         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2150                                  keyword, "config");
2151 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2152         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2153                                  all, "all");
2154 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2155         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2156                                  name, "max-lro-pkt-size");
2157 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2158         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2159                               value, UINT32);
2160
2161 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2162         .f = cmd_config_max_lro_pkt_size_parsed,
2163         .data = NULL,
2164         .help_str = "port config all max-lro-pkt-size <value>",
2165         .tokens = {
2166                 (void *)&cmd_config_max_lro_pkt_size_port,
2167                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2168                 (void *)&cmd_config_max_lro_pkt_size_all,
2169                 (void *)&cmd_config_max_lro_pkt_size_name,
2170                 (void *)&cmd_config_max_lro_pkt_size_value,
2171                 NULL,
2172         },
2173 };
2174
2175 /* *** configure port MTU *** */
2176 struct cmd_config_mtu_result {
2177         cmdline_fixed_string_t port;
2178         cmdline_fixed_string_t keyword;
2179         cmdline_fixed_string_t mtu;
2180         portid_t port_id;
2181         uint16_t value;
2182 };
2183
2184 static void
2185 cmd_config_mtu_parsed(void *parsed_result,
2186                       __rte_unused struct cmdline *cl,
2187                       __rte_unused void *data)
2188 {
2189         struct cmd_config_mtu_result *res = parsed_result;
2190
2191         if (res->value < RTE_ETHER_MIN_LEN) {
2192                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2193                 return;
2194         }
2195         port_mtu_set(res->port_id, res->value);
2196 }
2197
2198 cmdline_parse_token_string_t cmd_config_mtu_port =
2199         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2200                                  "port");
2201 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2202         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2203                                  "config");
2204 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2205         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2206                                  "mtu");
2207 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2208         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2209 cmdline_parse_token_num_t cmd_config_mtu_value =
2210         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2211
2212 cmdline_parse_inst_t cmd_config_mtu = {
2213         .f = cmd_config_mtu_parsed,
2214         .data = NULL,
2215         .help_str = "port config mtu <port_id> <value>",
2216         .tokens = {
2217                 (void *)&cmd_config_mtu_port,
2218                 (void *)&cmd_config_mtu_keyword,
2219                 (void *)&cmd_config_mtu_mtu,
2220                 (void *)&cmd_config_mtu_port_id,
2221                 (void *)&cmd_config_mtu_value,
2222                 NULL,
2223         },
2224 };
2225
2226 /* *** configure rx mode *** */
2227 struct cmd_config_rx_mode_flag {
2228         cmdline_fixed_string_t port;
2229         cmdline_fixed_string_t keyword;
2230         cmdline_fixed_string_t all;
2231         cmdline_fixed_string_t name;
2232         cmdline_fixed_string_t value;
2233 };
2234
2235 static void
2236 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2237                                 __rte_unused struct cmdline *cl,
2238                                 __rte_unused void *data)
2239 {
2240         struct cmd_config_rx_mode_flag *res = parsed_result;
2241
2242         if (!all_ports_stopped()) {
2243                 printf("Please stop all ports first\n");
2244                 return;
2245         }
2246
2247         if (!strcmp(res->name, "drop-en")) {
2248                 if (!strcmp(res->value, "on"))
2249                         rx_drop_en = 1;
2250                 else if (!strcmp(res->value, "off"))
2251                         rx_drop_en = 0;
2252                 else {
2253                         printf("Unknown parameter\n");
2254                         return;
2255                 }
2256         } else {
2257                 printf("Unknown parameter\n");
2258                 return;
2259         }
2260
2261         init_port_config();
2262
2263         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2264 }
2265
2266 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2267         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2268 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2269         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2270                                                                 "config");
2271 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2272         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2273 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2274         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2275                                         "drop-en");
2276 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2277         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2278                                                         "on#off");
2279
2280 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2281         .f = cmd_config_rx_mode_flag_parsed,
2282         .data = NULL,
2283         .help_str = "port config all drop-en on|off",
2284         .tokens = {
2285                 (void *)&cmd_config_rx_mode_flag_port,
2286                 (void *)&cmd_config_rx_mode_flag_keyword,
2287                 (void *)&cmd_config_rx_mode_flag_all,
2288                 (void *)&cmd_config_rx_mode_flag_name,
2289                 (void *)&cmd_config_rx_mode_flag_value,
2290                 NULL,
2291         },
2292 };
2293
2294 /* *** configure rss *** */
2295 struct cmd_config_rss {
2296         cmdline_fixed_string_t port;
2297         cmdline_fixed_string_t keyword;
2298         cmdline_fixed_string_t all;
2299         cmdline_fixed_string_t name;
2300         cmdline_fixed_string_t value;
2301 };
2302
2303 static void
2304 cmd_config_rss_parsed(void *parsed_result,
2305                         __rte_unused struct cmdline *cl,
2306                         __rte_unused void *data)
2307 {
2308         struct cmd_config_rss *res = parsed_result;
2309         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2310         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2311         int use_default = 0;
2312         int all_updated = 1;
2313         int diag;
2314         uint16_t i;
2315         int ret;
2316
2317         if (!strcmp(res->value, "all"))
2318                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2319                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2320                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2321                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2322         else if (!strcmp(res->value, "eth"))
2323                 rss_conf.rss_hf = ETH_RSS_ETH;
2324         else if (!strcmp(res->value, "vlan"))
2325                 rss_conf.rss_hf = ETH_RSS_VLAN;
2326         else if (!strcmp(res->value, "ip"))
2327                 rss_conf.rss_hf = ETH_RSS_IP;
2328         else if (!strcmp(res->value, "udp"))
2329                 rss_conf.rss_hf = ETH_RSS_UDP;
2330         else if (!strcmp(res->value, "tcp"))
2331                 rss_conf.rss_hf = ETH_RSS_TCP;
2332         else if (!strcmp(res->value, "sctp"))
2333                 rss_conf.rss_hf = ETH_RSS_SCTP;
2334         else if (!strcmp(res->value, "ether"))
2335                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2336         else if (!strcmp(res->value, "port"))
2337                 rss_conf.rss_hf = ETH_RSS_PORT;
2338         else if (!strcmp(res->value, "vxlan"))
2339                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2340         else if (!strcmp(res->value, "geneve"))
2341                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2342         else if (!strcmp(res->value, "nvgre"))
2343                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2344         else if (!strcmp(res->value, "l3-pre32"))
2345                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2346         else if (!strcmp(res->value, "l3-pre40"))
2347                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2348         else if (!strcmp(res->value, "l3-pre48"))
2349                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2350         else if (!strcmp(res->value, "l3-pre56"))
2351                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2352         else if (!strcmp(res->value, "l3-pre64"))
2353                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2354         else if (!strcmp(res->value, "l3-pre96"))
2355                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2356         else if (!strcmp(res->value, "l3-src-only"))
2357                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2358         else if (!strcmp(res->value, "l3-dst-only"))
2359                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2360         else if (!strcmp(res->value, "l4-src-only"))
2361                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2362         else if (!strcmp(res->value, "l4-dst-only"))
2363                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2364         else if (!strcmp(res->value, "l2-src-only"))
2365                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2366         else if (!strcmp(res->value, "l2-dst-only"))
2367                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2368         else if (!strcmp(res->value, "l2tpv3"))
2369                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2370         else if (!strcmp(res->value, "esp"))
2371                 rss_conf.rss_hf = ETH_RSS_ESP;
2372         else if (!strcmp(res->value, "ah"))
2373                 rss_conf.rss_hf = ETH_RSS_AH;
2374         else if (!strcmp(res->value, "pfcp"))
2375                 rss_conf.rss_hf = ETH_RSS_PFCP;
2376         else if (!strcmp(res->value, "pppoe"))
2377                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2378         else if (!strcmp(res->value, "gtpu"))
2379                 rss_conf.rss_hf = ETH_RSS_GTPU;
2380         else if (!strcmp(res->value, "none"))
2381                 rss_conf.rss_hf = 0;
2382         else if (!strcmp(res->value, "level-default")) {
2383                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2384                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2385         } else if (!strcmp(res->value, "level-outer")) {
2386                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2387                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2388         } else if (!strcmp(res->value, "level-inner")) {
2389                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2390                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2391         } else if (!strcmp(res->value, "default"))
2392                 use_default = 1;
2393         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2394                                                 atoi(res->value) < 64)
2395                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2396         else {
2397                 printf("Unknown parameter\n");
2398                 return;
2399         }
2400         rss_conf.rss_key = NULL;
2401         /* Update global configuration for RSS types. */
2402         RTE_ETH_FOREACH_DEV(i) {
2403                 struct rte_eth_rss_conf local_rss_conf;
2404
2405                 ret = eth_dev_info_get_print_err(i, &dev_info);
2406                 if (ret != 0)
2407                         return;
2408
2409                 if (use_default)
2410                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2411
2412                 local_rss_conf = rss_conf;
2413                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2414                         dev_info.flow_type_rss_offloads;
2415                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2416                         printf("Port %u modified RSS hash function based on hardware support,"
2417                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2418                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2419                 }
2420                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2421                 if (diag < 0) {
2422                         all_updated = 0;
2423                         printf("Configuration of RSS hash at ethernet port %d "
2424                                 "failed with error (%d): %s.\n",
2425                                 i, -diag, strerror(-diag));
2426                 }
2427         }
2428         if (all_updated && !use_default) {
2429                 rss_hf = rss_conf.rss_hf;
2430                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2431         }
2432 }
2433
2434 cmdline_parse_token_string_t cmd_config_rss_port =
2435         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2436 cmdline_parse_token_string_t cmd_config_rss_keyword =
2437         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2438 cmdline_parse_token_string_t cmd_config_rss_all =
2439         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2440 cmdline_parse_token_string_t cmd_config_rss_name =
2441         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2442 cmdline_parse_token_string_t cmd_config_rss_value =
2443         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2444
2445 cmdline_parse_inst_t cmd_config_rss = {
2446         .f = cmd_config_rss_parsed,
2447         .data = NULL,
2448         .help_str = "port config all rss "
2449                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2450                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2451                 "level-outer|level-inner|<flowtype_id>",
2452         .tokens = {
2453                 (void *)&cmd_config_rss_port,
2454                 (void *)&cmd_config_rss_keyword,
2455                 (void *)&cmd_config_rss_all,
2456                 (void *)&cmd_config_rss_name,
2457                 (void *)&cmd_config_rss_value,
2458                 NULL,
2459         },
2460 };
2461
2462 /* *** configure rss hash key *** */
2463 struct cmd_config_rss_hash_key {
2464         cmdline_fixed_string_t port;
2465         cmdline_fixed_string_t config;
2466         portid_t port_id;
2467         cmdline_fixed_string_t rss_hash_key;
2468         cmdline_fixed_string_t rss_type;
2469         cmdline_fixed_string_t key;
2470 };
2471
2472 static uint8_t
2473 hexa_digit_to_value(char hexa_digit)
2474 {
2475         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2476                 return (uint8_t) (hexa_digit - '0');
2477         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2478                 return (uint8_t) ((hexa_digit - 'a') + 10);
2479         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2480                 return (uint8_t) ((hexa_digit - 'A') + 10);
2481         /* Invalid hexa digit */
2482         return 0xFF;
2483 }
2484
2485 static uint8_t
2486 parse_and_check_key_hexa_digit(char *key, int idx)
2487 {
2488         uint8_t hexa_v;
2489
2490         hexa_v = hexa_digit_to_value(key[idx]);
2491         if (hexa_v == 0xFF)
2492                 printf("invalid key: character %c at position %d is not a "
2493                        "valid hexa digit\n", key[idx], idx);
2494         return hexa_v;
2495 }
2496
2497 static void
2498 cmd_config_rss_hash_key_parsed(void *parsed_result,
2499                                __rte_unused struct cmdline *cl,
2500                                __rte_unused void *data)
2501 {
2502         struct cmd_config_rss_hash_key *res = parsed_result;
2503         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2504         uint8_t xdgt0;
2505         uint8_t xdgt1;
2506         int i;
2507         struct rte_eth_dev_info dev_info;
2508         uint8_t hash_key_size;
2509         uint32_t key_len;
2510         int ret;
2511
2512         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2513         if (ret != 0)
2514                 return;
2515
2516         if (dev_info.hash_key_size > 0 &&
2517                         dev_info.hash_key_size <= sizeof(hash_key))
2518                 hash_key_size = dev_info.hash_key_size;
2519         else {
2520                 printf("dev_info did not provide a valid hash key size\n");
2521                 return;
2522         }
2523         /* Check the length of the RSS hash key */
2524         key_len = strlen(res->key);
2525         if (key_len != (hash_key_size * 2)) {
2526                 printf("key length: %d invalid - key must be a string of %d"
2527                            " hexa-decimal numbers\n",
2528                            (int) key_len, hash_key_size * 2);
2529                 return;
2530         }
2531         /* Translate RSS hash key into binary representation */
2532         for (i = 0; i < hash_key_size; i++) {
2533                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2534                 if (xdgt0 == 0xFF)
2535                         return;
2536                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2537                 if (xdgt1 == 0xFF)
2538                         return;
2539                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2540         }
2541         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2542                         hash_key_size);
2543 }
2544
2545 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2546         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2547 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2548         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2549                                  "config");
2550 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2551         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2552 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2553         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2554                                  rss_hash_key, "rss-hash-key");
2555 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2556         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2557                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2558                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2559                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2560                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2561                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2562                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2563                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2564 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2565         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2566
2567 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2568         .f = cmd_config_rss_hash_key_parsed,
2569         .data = NULL,
2570         .help_str = "port config <port_id> rss-hash-key "
2571                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2572                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2573                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2574                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2575                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2576                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2577                 "<string of hex digits (variable length, NIC dependent)>",
2578         .tokens = {
2579                 (void *)&cmd_config_rss_hash_key_port,
2580                 (void *)&cmd_config_rss_hash_key_config,
2581                 (void *)&cmd_config_rss_hash_key_port_id,
2582                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2583                 (void *)&cmd_config_rss_hash_key_rss_type,
2584                 (void *)&cmd_config_rss_hash_key_value,
2585                 NULL,
2586         },
2587 };
2588
2589 /* *** configure port rxq/txq ring size *** */
2590 struct cmd_config_rxtx_ring_size {
2591         cmdline_fixed_string_t port;
2592         cmdline_fixed_string_t config;
2593         portid_t portid;
2594         cmdline_fixed_string_t rxtxq;
2595         uint16_t qid;
2596         cmdline_fixed_string_t rsize;
2597         uint16_t size;
2598 };
2599
2600 static void
2601 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2602                                  __rte_unused struct cmdline *cl,
2603                                  __rte_unused void *data)
2604 {
2605         struct cmd_config_rxtx_ring_size *res = parsed_result;
2606         struct rte_port *port;
2607         uint8_t isrx;
2608
2609         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2610                 return;
2611
2612         if (res->portid == (portid_t)RTE_PORT_ALL) {
2613                 printf("Invalid port id\n");
2614                 return;
2615         }
2616
2617         port = &ports[res->portid];
2618
2619         if (!strcmp(res->rxtxq, "rxq"))
2620                 isrx = 1;
2621         else if (!strcmp(res->rxtxq, "txq"))
2622                 isrx = 0;
2623         else {
2624                 printf("Unknown parameter\n");
2625                 return;
2626         }
2627
2628         if (isrx && rx_queue_id_is_invalid(res->qid))
2629                 return;
2630         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2631                 return;
2632
2633         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2634                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2635                        rx_free_thresh);
2636                 return;
2637         }
2638
2639         if (isrx)
2640                 port->nb_rx_desc[res->qid] = res->size;
2641         else
2642                 port->nb_tx_desc[res->qid] = res->size;
2643
2644         cmd_reconfig_device_queue(res->portid, 0, 1);
2645 }
2646
2647 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2648         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2649                                  port, "port");
2650 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2651         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2652                                  config, "config");
2653 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2654         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2655                                  portid, UINT16);
2656 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2657         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2658                                  rxtxq, "rxq#txq");
2659 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2660         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2661                               qid, UINT16);
2662 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2663         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2664                                  rsize, "ring_size");
2665 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2666         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2667                               size, UINT16);
2668
2669 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2670         .f = cmd_config_rxtx_ring_size_parsed,
2671         .data = NULL,
2672         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2673         .tokens = {
2674                 (void *)&cmd_config_rxtx_ring_size_port,
2675                 (void *)&cmd_config_rxtx_ring_size_config,
2676                 (void *)&cmd_config_rxtx_ring_size_portid,
2677                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2678                 (void *)&cmd_config_rxtx_ring_size_qid,
2679                 (void *)&cmd_config_rxtx_ring_size_rsize,
2680                 (void *)&cmd_config_rxtx_ring_size_size,
2681                 NULL,
2682         },
2683 };
2684
2685 /* *** configure port rxq/txq start/stop *** */
2686 struct cmd_config_rxtx_queue {
2687         cmdline_fixed_string_t port;
2688         portid_t portid;
2689         cmdline_fixed_string_t rxtxq;
2690         uint16_t qid;
2691         cmdline_fixed_string_t opname;
2692 };
2693
2694 static void
2695 cmd_config_rxtx_queue_parsed(void *parsed_result,
2696                         __rte_unused struct cmdline *cl,
2697                         __rte_unused void *data)
2698 {
2699         struct cmd_config_rxtx_queue *res = parsed_result;
2700         uint8_t isrx;
2701         uint8_t isstart;
2702         int ret = 0;
2703
2704         if (test_done == 0) {
2705                 printf("Please stop forwarding first\n");
2706                 return;
2707         }
2708
2709         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2710                 return;
2711
2712         if (port_is_started(res->portid) != 1) {
2713                 printf("Please start port %u first\n", res->portid);
2714                 return;
2715         }
2716
2717         if (!strcmp(res->rxtxq, "rxq"))
2718                 isrx = 1;
2719         else if (!strcmp(res->rxtxq, "txq"))
2720                 isrx = 0;
2721         else {
2722                 printf("Unknown parameter\n");
2723                 return;
2724         }
2725
2726         if (isrx && rx_queue_id_is_invalid(res->qid))
2727                 return;
2728         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2729                 return;
2730
2731         if (!strcmp(res->opname, "start"))
2732                 isstart = 1;
2733         else if (!strcmp(res->opname, "stop"))
2734                 isstart = 0;
2735         else {
2736                 printf("Unknown parameter\n");
2737                 return;
2738         }
2739
2740         if (isstart && isrx)
2741                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2742         else if (!isstart && isrx)
2743                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2744         else if (isstart && !isrx)
2745                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2746         else
2747                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2748
2749         if (ret == -ENOTSUP)
2750                 printf("Function not supported in PMD driver\n");
2751 }
2752
2753 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2754         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2755 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2756         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2757 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2758         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2759 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2760         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2761 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2762         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2763                                                 "start#stop");
2764
2765 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2766         .f = cmd_config_rxtx_queue_parsed,
2767         .data = NULL,
2768         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2769         .tokens = {
2770                 (void *)&cmd_config_rxtx_queue_port,
2771                 (void *)&cmd_config_rxtx_queue_portid,
2772                 (void *)&cmd_config_rxtx_queue_rxtxq,
2773                 (void *)&cmd_config_rxtx_queue_qid,
2774                 (void *)&cmd_config_rxtx_queue_opname,
2775                 NULL,
2776         },
2777 };
2778
2779 /* *** configure port rxq/txq deferred start on/off *** */
2780 struct cmd_config_deferred_start_rxtx_queue {
2781         cmdline_fixed_string_t port;
2782         portid_t port_id;
2783         cmdline_fixed_string_t rxtxq;
2784         uint16_t qid;
2785         cmdline_fixed_string_t opname;
2786         cmdline_fixed_string_t state;
2787 };
2788
2789 static void
2790 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2791                         __rte_unused struct cmdline *cl,
2792                         __rte_unused void *data)
2793 {
2794         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2795         struct rte_port *port;
2796         uint8_t isrx;
2797         uint8_t ison;
2798         uint8_t needreconfig = 0;
2799
2800         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2801                 return;
2802
2803         if (port_is_started(res->port_id) != 0) {
2804                 printf("Please stop port %u first\n", res->port_id);
2805                 return;
2806         }
2807
2808         port = &ports[res->port_id];
2809
2810         isrx = !strcmp(res->rxtxq, "rxq");
2811
2812         if (isrx && rx_queue_id_is_invalid(res->qid))
2813                 return;
2814         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2815                 return;
2816
2817         ison = !strcmp(res->state, "on");
2818
2819         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2820                 port->rx_conf[res->qid].rx_deferred_start = ison;
2821                 needreconfig = 1;
2822         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2823                 port->tx_conf[res->qid].tx_deferred_start = ison;
2824                 needreconfig = 1;
2825         }
2826
2827         if (needreconfig)
2828                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2829 }
2830
2831 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2832         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2833                                                 port, "port");
2834 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2835         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2836                                                 port_id, UINT16);
2837 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2838         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2839                                                 rxtxq, "rxq#txq");
2840 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2841         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2842                                                 qid, UINT16);
2843 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2844         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2845                                                 opname, "deferred_start");
2846 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2847         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2848                                                 state, "on#off");
2849
2850 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2851         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2852         .data = NULL,
2853         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2854         .tokens = {
2855                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2856                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2857                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2858                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2859                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2860                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2861                 NULL,
2862         },
2863 };
2864
2865 /* *** configure port rxq/txq setup *** */
2866 struct cmd_setup_rxtx_queue {
2867         cmdline_fixed_string_t port;
2868         portid_t portid;
2869         cmdline_fixed_string_t rxtxq;
2870         uint16_t qid;
2871         cmdline_fixed_string_t setup;
2872 };
2873
2874 /* Common CLI fields for queue setup */
2875 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2876         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2877 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2878         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2879 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2880         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2881 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2882         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2883 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2884         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2885
2886 static void
2887 cmd_setup_rxtx_queue_parsed(
2888         void *parsed_result,
2889         __rte_unused struct cmdline *cl,
2890         __rte_unused void *data)
2891 {
2892         struct cmd_setup_rxtx_queue *res = parsed_result;
2893         struct rte_port *port;
2894         struct rte_mempool *mp;
2895         unsigned int socket_id;
2896         uint8_t isrx = 0;
2897         int ret;
2898
2899         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2900                 return;
2901
2902         if (res->portid == (portid_t)RTE_PORT_ALL) {
2903                 printf("Invalid port id\n");
2904                 return;
2905         }
2906
2907         if (!strcmp(res->rxtxq, "rxq"))
2908                 isrx = 1;
2909         else if (!strcmp(res->rxtxq, "txq"))
2910                 isrx = 0;
2911         else {
2912                 printf("Unknown parameter\n");
2913                 return;
2914         }
2915
2916         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2917                 printf("Invalid rx queue\n");
2918                 return;
2919         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2920                 printf("Invalid tx queue\n");
2921                 return;
2922         }
2923
2924         port = &ports[res->portid];
2925         if (isrx) {
2926                 socket_id = rxring_numa[res->portid];
2927                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2928                         socket_id = port->socket_id;
2929
2930                 mp = mbuf_pool_find(socket_id, 0);
2931                 if (mp == NULL) {
2932                         printf("Failed to setup RX queue: "
2933                                 "No mempool allocation"
2934                                 " on the socket %d\n",
2935                                 rxring_numa[res->portid]);
2936                         return;
2937                 }
2938                 ret = rx_queue_setup(res->portid,
2939                                      res->qid,
2940                                      port->nb_rx_desc[res->qid],
2941                                      socket_id,
2942                                      &port->rx_conf[res->qid],
2943                                      mp);
2944                 if (ret)
2945                         printf("Failed to setup RX queue\n");
2946         } else {
2947                 socket_id = txring_numa[res->portid];
2948                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2949                         socket_id = port->socket_id;
2950
2951                 ret = rte_eth_tx_queue_setup(res->portid,
2952                                              res->qid,
2953                                              port->nb_tx_desc[res->qid],
2954                                              socket_id,
2955                                              &port->tx_conf[res->qid]);
2956                 if (ret)
2957                         printf("Failed to setup TX queue\n");
2958         }
2959 }
2960
2961 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2962         .f = cmd_setup_rxtx_queue_parsed,
2963         .data = NULL,
2964         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2965         .tokens = {
2966                 (void *)&cmd_setup_rxtx_queue_port,
2967                 (void *)&cmd_setup_rxtx_queue_portid,
2968                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2969                 (void *)&cmd_setup_rxtx_queue_qid,
2970                 (void *)&cmd_setup_rxtx_queue_setup,
2971                 NULL,
2972         },
2973 };
2974
2975
2976 /* *** Configure RSS RETA *** */
2977 struct cmd_config_rss_reta {
2978         cmdline_fixed_string_t port;
2979         cmdline_fixed_string_t keyword;
2980         portid_t port_id;
2981         cmdline_fixed_string_t name;
2982         cmdline_fixed_string_t list_name;
2983         cmdline_fixed_string_t list_of_items;
2984 };
2985
2986 static int
2987 parse_reta_config(const char *str,
2988                   struct rte_eth_rss_reta_entry64 *reta_conf,
2989                   uint16_t nb_entries)
2990 {
2991         int i;
2992         unsigned size;
2993         uint16_t hash_index, idx, shift;
2994         uint16_t nb_queue;
2995         char s[256];
2996         const char *p, *p0 = str;
2997         char *end;
2998         enum fieldnames {
2999                 FLD_HASH_INDEX = 0,
3000                 FLD_QUEUE,
3001                 _NUM_FLD
3002         };
3003         unsigned long int_fld[_NUM_FLD];
3004         char *str_fld[_NUM_FLD];
3005
3006         while ((p = strchr(p0,'(')) != NULL) {
3007                 ++p;
3008                 if((p0 = strchr(p,')')) == NULL)
3009                         return -1;
3010
3011                 size = p0 - p;
3012                 if(size >= sizeof(s))
3013                         return -1;
3014
3015                 snprintf(s, sizeof(s), "%.*s", size, p);
3016                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
3017                         return -1;
3018                 for (i = 0; i < _NUM_FLD; i++) {
3019                         errno = 0;
3020                         int_fld[i] = strtoul(str_fld[i], &end, 0);
3021                         if (errno != 0 || end == str_fld[i] ||
3022                                         int_fld[i] > 65535)
3023                                 return -1;
3024                 }
3025
3026                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
3027                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
3028
3029                 if (hash_index >= nb_entries) {
3030                         printf("Invalid RETA hash index=%d\n", hash_index);
3031                         return -1;
3032                 }
3033
3034                 idx = hash_index / RTE_RETA_GROUP_SIZE;
3035                 shift = hash_index % RTE_RETA_GROUP_SIZE;
3036                 reta_conf[idx].mask |= (1ULL << shift);
3037                 reta_conf[idx].reta[shift] = nb_queue;
3038         }
3039
3040         return 0;
3041 }
3042
3043 static void
3044 cmd_set_rss_reta_parsed(void *parsed_result,
3045                         __rte_unused struct cmdline *cl,
3046                         __rte_unused void *data)
3047 {
3048         int ret;
3049         struct rte_eth_dev_info dev_info;
3050         struct rte_eth_rss_reta_entry64 reta_conf[8];
3051         struct cmd_config_rss_reta *res = parsed_result;
3052
3053         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3054         if (ret != 0)
3055                 return;
3056
3057         if (dev_info.reta_size == 0) {
3058                 printf("Redirection table size is 0 which is "
3059                                         "invalid for RSS\n");
3060                 return;
3061         } else
3062                 printf("The reta size of port %d is %u\n",
3063                         res->port_id, dev_info.reta_size);
3064         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3065                 printf("Currently do not support more than %u entries of "
3066                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3067                 return;
3068         }
3069
3070         memset(reta_conf, 0, sizeof(reta_conf));
3071         if (!strcmp(res->list_name, "reta")) {
3072                 if (parse_reta_config(res->list_of_items, reta_conf,
3073                                                 dev_info.reta_size)) {
3074                         printf("Invalid RSS Redirection Table "
3075                                         "config entered\n");
3076                         return;
3077                 }
3078                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3079                                 reta_conf, dev_info.reta_size);
3080                 if (ret != 0)
3081                         printf("Bad redirection table parameter, "
3082                                         "return code = %d \n", ret);
3083         }
3084 }
3085
3086 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3087         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3088 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3089         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3090 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3091         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3092 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3093         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3094 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3095         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3096 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3097         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3098                                  NULL);
3099 cmdline_parse_inst_t cmd_config_rss_reta = {
3100         .f = cmd_set_rss_reta_parsed,
3101         .data = NULL,
3102         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3103         .tokens = {
3104                 (void *)&cmd_config_rss_reta_port,
3105                 (void *)&cmd_config_rss_reta_keyword,
3106                 (void *)&cmd_config_rss_reta_port_id,
3107                 (void *)&cmd_config_rss_reta_name,
3108                 (void *)&cmd_config_rss_reta_list_name,
3109                 (void *)&cmd_config_rss_reta_list_of_items,
3110                 NULL,
3111         },
3112 };
3113
3114 /* *** SHOW PORT RETA INFO *** */
3115 struct cmd_showport_reta {
3116         cmdline_fixed_string_t show;
3117         cmdline_fixed_string_t port;
3118         portid_t port_id;
3119         cmdline_fixed_string_t rss;
3120         cmdline_fixed_string_t reta;
3121         uint16_t size;
3122         cmdline_fixed_string_t list_of_items;
3123 };
3124
3125 static int
3126 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3127                            uint16_t nb_entries,
3128                            char *str)
3129 {
3130         uint32_t size;
3131         const char *p, *p0 = str;
3132         char s[256];
3133         char *end;
3134         char *str_fld[8];
3135         uint16_t i;
3136         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3137                         RTE_RETA_GROUP_SIZE;
3138         int ret;
3139
3140         p = strchr(p0, '(');
3141         if (p == NULL)
3142                 return -1;
3143         p++;
3144         p0 = strchr(p, ')');
3145         if (p0 == NULL)
3146                 return -1;
3147         size = p0 - p;
3148         if (size >= sizeof(s)) {
3149                 printf("The string size exceeds the internal buffer size\n");
3150                 return -1;
3151         }
3152         snprintf(s, sizeof(s), "%.*s", size, p);
3153         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3154         if (ret <= 0 || ret != num) {
3155                 printf("The bits of masks do not match the number of "
3156                                         "reta entries: %u\n", num);
3157                 return -1;
3158         }
3159         for (i = 0; i < ret; i++)
3160                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3161
3162         return 0;
3163 }
3164
3165 static void
3166 cmd_showport_reta_parsed(void *parsed_result,
3167                          __rte_unused struct cmdline *cl,
3168                          __rte_unused void *data)
3169 {
3170         struct cmd_showport_reta *res = parsed_result;
3171         struct rte_eth_rss_reta_entry64 reta_conf[8];
3172         struct rte_eth_dev_info dev_info;
3173         uint16_t max_reta_size;
3174         int ret;
3175
3176         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3177         if (ret != 0)
3178                 return;
3179
3180         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3181         if (res->size == 0 || res->size > max_reta_size) {
3182                 printf("Invalid redirection table size: %u (1-%u)\n",
3183                         res->size, max_reta_size);
3184                 return;
3185         }
3186
3187         memset(reta_conf, 0, sizeof(reta_conf));
3188         if (showport_parse_reta_config(reta_conf, res->size,
3189                                 res->list_of_items) < 0) {
3190                 printf("Invalid string: %s for reta masks\n",
3191                                         res->list_of_items);
3192                 return;
3193         }
3194         port_rss_reta_info(res->port_id, reta_conf, res->size);
3195 }
3196
3197 cmdline_parse_token_string_t cmd_showport_reta_show =
3198         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3199 cmdline_parse_token_string_t cmd_showport_reta_port =
3200         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3201 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3202         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3203 cmdline_parse_token_string_t cmd_showport_reta_rss =
3204         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3205 cmdline_parse_token_string_t cmd_showport_reta_reta =
3206         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3207 cmdline_parse_token_num_t cmd_showport_reta_size =
3208         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3209 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3210         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3211                                         list_of_items, NULL);
3212
3213 cmdline_parse_inst_t cmd_showport_reta = {
3214         .f = cmd_showport_reta_parsed,
3215         .data = NULL,
3216         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3217         .tokens = {
3218                 (void *)&cmd_showport_reta_show,
3219                 (void *)&cmd_showport_reta_port,
3220                 (void *)&cmd_showport_reta_port_id,
3221                 (void *)&cmd_showport_reta_rss,
3222                 (void *)&cmd_showport_reta_reta,
3223                 (void *)&cmd_showport_reta_size,
3224                 (void *)&cmd_showport_reta_list_of_items,
3225                 NULL,
3226         },
3227 };
3228
3229 /* *** Show RSS hash configuration *** */
3230 struct cmd_showport_rss_hash {
3231         cmdline_fixed_string_t show;
3232         cmdline_fixed_string_t port;
3233         portid_t port_id;
3234         cmdline_fixed_string_t rss_hash;
3235         cmdline_fixed_string_t rss_type;
3236         cmdline_fixed_string_t key; /* optional argument */
3237 };
3238
3239 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3240                                 __rte_unused struct cmdline *cl,
3241                                 void *show_rss_key)
3242 {
3243         struct cmd_showport_rss_hash *res = parsed_result;
3244
3245         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3246 }
3247
3248 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3249         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3250 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3251         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3252 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3253         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3254 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3255         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3256                                  "rss-hash");
3257 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3258         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3259
3260 cmdline_parse_inst_t cmd_showport_rss_hash = {
3261         .f = cmd_showport_rss_hash_parsed,
3262         .data = NULL,
3263         .help_str = "show port <port_id> rss-hash",
3264         .tokens = {
3265                 (void *)&cmd_showport_rss_hash_show,
3266                 (void *)&cmd_showport_rss_hash_port,
3267                 (void *)&cmd_showport_rss_hash_port_id,
3268                 (void *)&cmd_showport_rss_hash_rss_hash,
3269                 NULL,
3270         },
3271 };
3272
3273 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3274         .f = cmd_showport_rss_hash_parsed,
3275         .data = (void *)1,
3276         .help_str = "show port <port_id> rss-hash key",
3277         .tokens = {
3278                 (void *)&cmd_showport_rss_hash_show,
3279                 (void *)&cmd_showport_rss_hash_port,
3280                 (void *)&cmd_showport_rss_hash_port_id,
3281                 (void *)&cmd_showport_rss_hash_rss_hash,
3282                 (void *)&cmd_showport_rss_hash_rss_key,
3283                 NULL,
3284         },
3285 };
3286
3287 /* *** Configure DCB *** */
3288 struct cmd_config_dcb {
3289         cmdline_fixed_string_t port;
3290         cmdline_fixed_string_t config;
3291         portid_t port_id;
3292         cmdline_fixed_string_t dcb;
3293         cmdline_fixed_string_t vt;
3294         cmdline_fixed_string_t vt_en;
3295         uint8_t num_tcs;
3296         cmdline_fixed_string_t pfc;
3297         cmdline_fixed_string_t pfc_en;
3298 };
3299
3300 static void
3301 cmd_config_dcb_parsed(void *parsed_result,
3302                         __rte_unused struct cmdline *cl,
3303                         __rte_unused void *data)
3304 {
3305         struct cmd_config_dcb *res = parsed_result;
3306         portid_t port_id = res->port_id;
3307         struct rte_port *port;
3308         uint8_t pfc_en;
3309         int ret;
3310
3311         port = &ports[port_id];
3312         /** Check if the port is not started **/
3313         if (port->port_status != RTE_PORT_STOPPED) {
3314                 printf("Please stop port %d first\n", port_id);
3315                 return;
3316         }
3317
3318         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3319                 printf("The invalid number of traffic class,"
3320                         " only 4 or 8 allowed.\n");
3321                 return;
3322         }
3323
3324         if (nb_fwd_lcores < res->num_tcs) {
3325                 printf("nb_cores shouldn't be less than number of TCs.\n");
3326                 return;
3327         }
3328         if (!strncmp(res->pfc_en, "on", 2))
3329                 pfc_en = 1;
3330         else
3331                 pfc_en = 0;
3332
3333         /* DCB in VT mode */
3334         if (!strncmp(res->vt_en, "on", 2))
3335                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3336                                 (enum rte_eth_nb_tcs)res->num_tcs,
3337                                 pfc_en);
3338         else
3339                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3340                                 (enum rte_eth_nb_tcs)res->num_tcs,
3341                                 pfc_en);
3342
3343
3344         if (ret != 0) {
3345                 printf("Cannot initialize network ports.\n");
3346                 return;
3347         }
3348
3349         cmd_reconfig_device_queue(port_id, 1, 1);
3350 }
3351
3352 cmdline_parse_token_string_t cmd_config_dcb_port =
3353         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3354 cmdline_parse_token_string_t cmd_config_dcb_config =
3355         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3356 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3357         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3358 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3359         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3360 cmdline_parse_token_string_t cmd_config_dcb_vt =
3361         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3362 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3363         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3364 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3365         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3366 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3367         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3368 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3369         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3370
3371 cmdline_parse_inst_t cmd_config_dcb = {
3372         .f = cmd_config_dcb_parsed,
3373         .data = NULL,
3374         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3375         .tokens = {
3376                 (void *)&cmd_config_dcb_port,
3377                 (void *)&cmd_config_dcb_config,
3378                 (void *)&cmd_config_dcb_port_id,
3379                 (void *)&cmd_config_dcb_dcb,
3380                 (void *)&cmd_config_dcb_vt,
3381                 (void *)&cmd_config_dcb_vt_en,
3382                 (void *)&cmd_config_dcb_num_tcs,
3383                 (void *)&cmd_config_dcb_pfc,
3384                 (void *)&cmd_config_dcb_pfc_en,
3385                 NULL,
3386         },
3387 };
3388
3389 /* *** configure number of packets per burst *** */
3390 struct cmd_config_burst {
3391         cmdline_fixed_string_t port;
3392         cmdline_fixed_string_t keyword;
3393         cmdline_fixed_string_t all;
3394         cmdline_fixed_string_t name;
3395         uint16_t value;
3396 };
3397
3398 static void
3399 cmd_config_burst_parsed(void *parsed_result,
3400                         __rte_unused struct cmdline *cl,
3401                         __rte_unused void *data)
3402 {
3403         struct cmd_config_burst *res = parsed_result;
3404         struct rte_eth_dev_info dev_info;
3405         uint16_t rec_nb_pkts;
3406         int ret;
3407
3408         if (!all_ports_stopped()) {
3409                 printf("Please stop all ports first\n");
3410                 return;
3411         }
3412
3413         if (!strcmp(res->name, "burst")) {
3414                 if (res->value == 0) {
3415                         /* If user gives a value of zero, query the PMD for
3416                          * its recommended Rx burst size. Testpmd uses a single
3417                          * size for all ports, so assume all ports are the same
3418                          * NIC model and use the values from Port 0.
3419                          */
3420                         ret = eth_dev_info_get_print_err(0, &dev_info);
3421                         if (ret != 0)
3422                                 return;
3423
3424                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3425
3426                         if (rec_nb_pkts == 0) {
3427                                 printf("PMD does not recommend a burst size.\n"
3428                                         "User provided value must be between"
3429                                         " 1 and %d\n", MAX_PKT_BURST);
3430                                 return;
3431                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3432                                 printf("PMD recommended burst size of %d"
3433                                         " exceeds maximum value of %d\n",
3434                                         rec_nb_pkts, MAX_PKT_BURST);
3435                                 return;
3436                         }
3437                         printf("Using PMD-provided burst value of %d\n",
3438                                 rec_nb_pkts);
3439                         nb_pkt_per_burst = rec_nb_pkts;
3440                 } else if (res->value > MAX_PKT_BURST) {
3441                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3442                         return;
3443                 } else
3444                         nb_pkt_per_burst = res->value;
3445         } else {
3446                 printf("Unknown parameter\n");
3447                 return;
3448         }
3449
3450         init_port_config();
3451
3452         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3453 }
3454
3455 cmdline_parse_token_string_t cmd_config_burst_port =
3456         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3457 cmdline_parse_token_string_t cmd_config_burst_keyword =
3458         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3459 cmdline_parse_token_string_t cmd_config_burst_all =
3460         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3461 cmdline_parse_token_string_t cmd_config_burst_name =
3462         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3463 cmdline_parse_token_num_t cmd_config_burst_value =
3464         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3465
3466 cmdline_parse_inst_t cmd_config_burst = {
3467         .f = cmd_config_burst_parsed,
3468         .data = NULL,
3469         .help_str = "port config all burst <value>",
3470         .tokens = {
3471                 (void *)&cmd_config_burst_port,
3472                 (void *)&cmd_config_burst_keyword,
3473                 (void *)&cmd_config_burst_all,
3474                 (void *)&cmd_config_burst_name,
3475                 (void *)&cmd_config_burst_value,
3476                 NULL,
3477         },
3478 };
3479
3480 /* *** configure rx/tx queues *** */
3481 struct cmd_config_thresh {
3482         cmdline_fixed_string_t port;
3483         cmdline_fixed_string_t keyword;
3484         cmdline_fixed_string_t all;
3485         cmdline_fixed_string_t name;
3486         uint8_t value;
3487 };
3488
3489 static void
3490 cmd_config_thresh_parsed(void *parsed_result,
3491                         __rte_unused struct cmdline *cl,
3492                         __rte_unused void *data)
3493 {
3494         struct cmd_config_thresh *res = parsed_result;
3495
3496         if (!all_ports_stopped()) {
3497                 printf("Please stop all ports first\n");
3498                 return;
3499         }
3500
3501         if (!strcmp(res->name, "txpt"))
3502                 tx_pthresh = res->value;
3503         else if(!strcmp(res->name, "txht"))
3504                 tx_hthresh = res->value;
3505         else if(!strcmp(res->name, "txwt"))
3506                 tx_wthresh = res->value;
3507         else if(!strcmp(res->name, "rxpt"))
3508                 rx_pthresh = res->value;
3509         else if(!strcmp(res->name, "rxht"))
3510                 rx_hthresh = res->value;
3511         else if(!strcmp(res->name, "rxwt"))
3512                 rx_wthresh = res->value;
3513         else {
3514                 printf("Unknown parameter\n");
3515                 return;
3516         }
3517
3518         init_port_config();
3519
3520         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3521 }
3522
3523 cmdline_parse_token_string_t cmd_config_thresh_port =
3524         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3525 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3526         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3527 cmdline_parse_token_string_t cmd_config_thresh_all =
3528         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3529 cmdline_parse_token_string_t cmd_config_thresh_name =
3530         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3531                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3532 cmdline_parse_token_num_t cmd_config_thresh_value =
3533         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3534
3535 cmdline_parse_inst_t cmd_config_thresh = {
3536         .f = cmd_config_thresh_parsed,
3537         .data = NULL,
3538         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3539         .tokens = {
3540                 (void *)&cmd_config_thresh_port,
3541                 (void *)&cmd_config_thresh_keyword,
3542                 (void *)&cmd_config_thresh_all,
3543                 (void *)&cmd_config_thresh_name,
3544                 (void *)&cmd_config_thresh_value,
3545                 NULL,
3546         },
3547 };
3548
3549 /* *** configure free/rs threshold *** */
3550 struct cmd_config_threshold {
3551         cmdline_fixed_string_t port;
3552         cmdline_fixed_string_t keyword;
3553         cmdline_fixed_string_t all;
3554         cmdline_fixed_string_t name;
3555         uint16_t value;
3556 };
3557
3558 static void
3559 cmd_config_threshold_parsed(void *parsed_result,
3560                         __rte_unused struct cmdline *cl,
3561                         __rte_unused void *data)
3562 {
3563         struct cmd_config_threshold *res = parsed_result;
3564
3565         if (!all_ports_stopped()) {
3566                 printf("Please stop all ports first\n");
3567                 return;
3568         }
3569
3570         if (!strcmp(res->name, "txfreet"))
3571                 tx_free_thresh = res->value;
3572         else if (!strcmp(res->name, "txrst"))
3573                 tx_rs_thresh = res->value;
3574         else if (!strcmp(res->name, "rxfreet"))
3575                 rx_free_thresh = res->value;
3576         else {
3577                 printf("Unknown parameter\n");
3578                 return;
3579         }
3580
3581         init_port_config();
3582
3583         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3584 }
3585
3586 cmdline_parse_token_string_t cmd_config_threshold_port =
3587         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3588 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3589         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3590                                                                 "config");
3591 cmdline_parse_token_string_t cmd_config_threshold_all =
3592         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3593 cmdline_parse_token_string_t cmd_config_threshold_name =
3594         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3595                                                 "txfreet#txrst#rxfreet");
3596 cmdline_parse_token_num_t cmd_config_threshold_value =
3597         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3598
3599 cmdline_parse_inst_t cmd_config_threshold = {
3600         .f = cmd_config_threshold_parsed,
3601         .data = NULL,
3602         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3603         .tokens = {
3604                 (void *)&cmd_config_threshold_port,
3605                 (void *)&cmd_config_threshold_keyword,
3606                 (void *)&cmd_config_threshold_all,
3607                 (void *)&cmd_config_threshold_name,
3608                 (void *)&cmd_config_threshold_value,
3609                 NULL,
3610         },
3611 };
3612
3613 /* *** stop *** */
3614 struct cmd_stop_result {
3615         cmdline_fixed_string_t stop;
3616 };
3617
3618 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3619                             __rte_unused struct cmdline *cl,
3620                             __rte_unused void *data)
3621 {
3622         stop_packet_forwarding();
3623 }
3624
3625 cmdline_parse_token_string_t cmd_stop_stop =
3626         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3627
3628 cmdline_parse_inst_t cmd_stop = {
3629         .f = cmd_stop_parsed,
3630         .data = NULL,
3631         .help_str = "stop: Stop packet forwarding",
3632         .tokens = {
3633                 (void *)&cmd_stop_stop,
3634                 NULL,
3635         },
3636 };
3637
3638 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3639
3640 unsigned int
3641 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3642                 unsigned int *parsed_items, int check_unique_values)
3643 {
3644         unsigned int nb_item;
3645         unsigned int value;
3646         unsigned int i;
3647         unsigned int j;
3648         int value_ok;
3649         char c;
3650
3651         /*
3652          * First parse all items in the list and store their value.
3653          */
3654         value = 0;
3655         nb_item = 0;
3656         value_ok = 0;
3657         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3658                 c = str[i];
3659                 if ((c >= '0') && (c <= '9')) {
3660                         value = (unsigned int) (value * 10 + (c - '0'));
3661                         value_ok = 1;
3662                         continue;
3663                 }
3664                 if (c != ',') {
3665                         printf("character %c is not a decimal digit\n", c);
3666                         return 0;
3667                 }
3668                 if (! value_ok) {
3669                         printf("No valid value before comma\n");
3670                         return 0;
3671                 }
3672                 if (nb_item < max_items) {
3673                         parsed_items[nb_item] = value;
3674                         value_ok = 0;
3675                         value = 0;
3676                 }
3677                 nb_item++;
3678         }
3679         if (nb_item >= max_items) {
3680                 printf("Number of %s = %u > %u (maximum items)\n",
3681                        item_name, nb_item + 1, max_items);
3682                 return 0;
3683         }
3684         parsed_items[nb_item++] = value;
3685         if (! check_unique_values)
3686                 return nb_item;
3687
3688         /*
3689          * Then, check that all values in the list are differents.
3690          * No optimization here...
3691          */
3692         for (i = 0; i < nb_item; i++) {
3693                 for (j = i + 1; j < nb_item; j++) {
3694                         if (parsed_items[j] == parsed_items[i]) {
3695                                 printf("duplicated %s %u at index %u and %u\n",
3696                                        item_name, parsed_items[i], i, j);
3697                                 return 0;
3698                         }
3699                 }
3700         }
3701         return nb_item;
3702 }
3703
3704 struct cmd_set_list_result {
3705         cmdline_fixed_string_t cmd_keyword;
3706         cmdline_fixed_string_t list_name;
3707         cmdline_fixed_string_t list_of_items;
3708 };
3709
3710 static void cmd_set_list_parsed(void *parsed_result,
3711                                 __rte_unused struct cmdline *cl,
3712                                 __rte_unused void *data)
3713 {
3714         struct cmd_set_list_result *res;
3715         union {
3716                 unsigned int lcorelist[RTE_MAX_LCORE];
3717                 unsigned int portlist[RTE_MAX_ETHPORTS];
3718         } parsed_items;
3719         unsigned int nb_item;
3720
3721         if (test_done == 0) {
3722                 printf("Please stop forwarding first\n");
3723                 return;
3724         }
3725
3726         res = parsed_result;
3727         if (!strcmp(res->list_name, "corelist")) {
3728                 nb_item = parse_item_list(res->list_of_items, "core",
3729                                           RTE_MAX_LCORE,
3730                                           parsed_items.lcorelist, 1);
3731                 if (nb_item > 0) {
3732                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3733                         fwd_config_setup();
3734                 }
3735                 return;
3736         }
3737         if (!strcmp(res->list_name, "portlist")) {
3738                 nb_item = parse_item_list(res->list_of_items, "port",
3739                                           RTE_MAX_ETHPORTS,
3740                                           parsed_items.portlist, 1);
3741                 if (nb_item > 0) {
3742                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3743                         fwd_config_setup();
3744                 }
3745         }
3746 }
3747
3748 cmdline_parse_token_string_t cmd_set_list_keyword =
3749         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3750                                  "set");
3751 cmdline_parse_token_string_t cmd_set_list_name =
3752         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3753                                  "corelist#portlist");
3754 cmdline_parse_token_string_t cmd_set_list_of_items =
3755         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3756                                  NULL);
3757
3758 cmdline_parse_inst_t cmd_set_fwd_list = {
3759         .f = cmd_set_list_parsed,
3760         .data = NULL,
3761         .help_str = "set corelist|portlist <list0[,list1]*>",
3762         .tokens = {
3763                 (void *)&cmd_set_list_keyword,
3764                 (void *)&cmd_set_list_name,
3765                 (void *)&cmd_set_list_of_items,
3766                 NULL,
3767         },
3768 };
3769
3770 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3771
3772 struct cmd_setmask_result {
3773         cmdline_fixed_string_t set;
3774         cmdline_fixed_string_t mask;
3775         uint64_t hexavalue;
3776 };
3777
3778 static void cmd_set_mask_parsed(void *parsed_result,
3779                                 __rte_unused struct cmdline *cl,
3780                                 __rte_unused void *data)
3781 {
3782         struct cmd_setmask_result *res = parsed_result;
3783
3784         if (test_done == 0) {
3785                 printf("Please stop forwarding first\n");
3786                 return;
3787         }
3788         if (!strcmp(res->mask, "coremask")) {
3789                 set_fwd_lcores_mask(res->hexavalue);
3790                 fwd_config_setup();
3791         } else if (!strcmp(res->mask, "portmask")) {
3792                 set_fwd_ports_mask(res->hexavalue);
3793                 fwd_config_setup();
3794         }
3795 }
3796
3797 cmdline_parse_token_string_t cmd_setmask_set =
3798         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3799 cmdline_parse_token_string_t cmd_setmask_mask =
3800         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3801                                  "coremask#portmask");
3802 cmdline_parse_token_num_t cmd_setmask_value =
3803         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3804
3805 cmdline_parse_inst_t cmd_set_fwd_mask = {
3806         .f = cmd_set_mask_parsed,
3807         .data = NULL,
3808         .help_str = "set coremask|portmask <hexadecimal value>",
3809         .tokens = {
3810                 (void *)&cmd_setmask_set,
3811                 (void *)&cmd_setmask_mask,
3812                 (void *)&cmd_setmask_value,
3813                 NULL,
3814         },
3815 };
3816
3817 /*
3818  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3819  */
3820 struct cmd_set_result {
3821         cmdline_fixed_string_t set;
3822         cmdline_fixed_string_t what;
3823         uint16_t value;
3824 };
3825
3826 static void cmd_set_parsed(void *parsed_result,
3827                            __rte_unused struct cmdline *cl,
3828                            __rte_unused void *data)
3829 {
3830         struct cmd_set_result *res = parsed_result;
3831         if (!strcmp(res->what, "nbport")) {
3832                 set_fwd_ports_number(res->value);
3833                 fwd_config_setup();
3834         } else if (!strcmp(res->what, "nbcore")) {
3835                 set_fwd_lcores_number(res->value);
3836                 fwd_config_setup();
3837         } else if (!strcmp(res->what, "burst"))
3838                 set_nb_pkt_per_burst(res->value);
3839         else if (!strcmp(res->what, "verbose"))
3840                 set_verbose_level(res->value);
3841 }
3842
3843 cmdline_parse_token_string_t cmd_set_set =
3844         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3845 cmdline_parse_token_string_t cmd_set_what =
3846         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3847                                  "nbport#nbcore#burst#verbose");
3848 cmdline_parse_token_num_t cmd_set_value =
3849         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3850
3851 cmdline_parse_inst_t cmd_set_numbers = {
3852         .f = cmd_set_parsed,
3853         .data = NULL,
3854         .help_str = "set nbport|nbcore|burst|verbose <value>",
3855         .tokens = {
3856                 (void *)&cmd_set_set,
3857                 (void *)&cmd_set_what,
3858                 (void *)&cmd_set_value,
3859                 NULL,
3860         },
3861 };
3862
3863 /* *** SET LOG LEVEL CONFIGURATION *** */
3864
3865 struct cmd_set_log_result {
3866         cmdline_fixed_string_t set;
3867         cmdline_fixed_string_t log;
3868         cmdline_fixed_string_t type;
3869         uint32_t level;
3870 };
3871
3872 static void
3873 cmd_set_log_parsed(void *parsed_result,
3874                    __rte_unused struct cmdline *cl,
3875                    __rte_unused void *data)
3876 {
3877         struct cmd_set_log_result *res;
3878         int ret;
3879
3880         res = parsed_result;
3881         if (!strcmp(res->type, "global"))
3882                 rte_log_set_global_level(res->level);
3883         else {
3884                 ret = rte_log_set_level_regexp(res->type, res->level);
3885                 if (ret < 0)
3886                         printf("Unable to set log level\n");
3887         }
3888 }
3889
3890 cmdline_parse_token_string_t cmd_set_log_set =
3891         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3892 cmdline_parse_token_string_t cmd_set_log_log =
3893         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3894 cmdline_parse_token_string_t cmd_set_log_type =
3895         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3896 cmdline_parse_token_num_t cmd_set_log_level =
3897         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3898
3899 cmdline_parse_inst_t cmd_set_log = {
3900         .f = cmd_set_log_parsed,
3901         .data = NULL,
3902         .help_str = "set log global|<type> <level>",
3903         .tokens = {
3904                 (void *)&cmd_set_log_set,
3905                 (void *)&cmd_set_log_log,
3906                 (void *)&cmd_set_log_type,
3907                 (void *)&cmd_set_log_level,
3908                 NULL,
3909         },
3910 };
3911
3912 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3913
3914 struct cmd_set_rxoffs_result {
3915         cmdline_fixed_string_t cmd_keyword;
3916         cmdline_fixed_string_t rxoffs;
3917         cmdline_fixed_string_t seg_offsets;
3918 };
3919
3920 static void
3921 cmd_set_rxoffs_parsed(void *parsed_result,
3922                       __rte_unused struct cmdline *cl,
3923                       __rte_unused void *data)
3924 {
3925         struct cmd_set_rxoffs_result *res;
3926         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3927         unsigned int nb_segs;
3928
3929         res = parsed_result;
3930         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3931                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3932         if (nb_segs > 0)
3933                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3934 }
3935
3936 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3937         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3938                                  cmd_keyword, "set");
3939 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3940         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3941                                  rxoffs, "rxoffs");
3942 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3943         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3944                                  seg_offsets, NULL);
3945
3946 cmdline_parse_inst_t cmd_set_rxoffs = {
3947         .f = cmd_set_rxoffs_parsed,
3948         .data = NULL,
3949         .help_str = "set rxoffs <len0[,len1]*>",
3950         .tokens = {
3951                 (void *)&cmd_set_rxoffs_keyword,
3952                 (void *)&cmd_set_rxoffs_name,
3953                 (void *)&cmd_set_rxoffs_offsets,
3954                 NULL,
3955         },
3956 };
3957
3958 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3959
3960 struct cmd_set_rxpkts_result {
3961         cmdline_fixed_string_t cmd_keyword;
3962         cmdline_fixed_string_t rxpkts;
3963         cmdline_fixed_string_t seg_lengths;
3964 };
3965
3966 static void
3967 cmd_set_rxpkts_parsed(void *parsed_result,
3968                       __rte_unused struct cmdline *cl,
3969                       __rte_unused void *data)
3970 {
3971         struct cmd_set_rxpkts_result *res;
3972         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3973         unsigned int nb_segs;
3974
3975         res = parsed_result;
3976         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3977                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3978         if (nb_segs > 0)
3979                 set_rx_pkt_segments(seg_lengths, nb_segs);
3980 }
3981
3982 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3983         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3984                                  cmd_keyword, "set");
3985 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3986         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3987                                  rxpkts, "rxpkts");
3988 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3989         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3990                                  seg_lengths, NULL);
3991
3992 cmdline_parse_inst_t cmd_set_rxpkts = {
3993         .f = cmd_set_rxpkts_parsed,
3994         .data = NULL,
3995         .help_str = "set rxpkts <len0[,len1]*>",
3996         .tokens = {
3997                 (void *)&cmd_set_rxpkts_keyword,
3998                 (void *)&cmd_set_rxpkts_name,
3999                 (void *)&cmd_set_rxpkts_lengths,
4000                 NULL,
4001         },
4002 };
4003
4004 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
4005
4006 struct cmd_set_txpkts_result {
4007         cmdline_fixed_string_t cmd_keyword;
4008         cmdline_fixed_string_t txpkts;
4009         cmdline_fixed_string_t seg_lengths;
4010 };
4011
4012 static void
4013 cmd_set_txpkts_parsed(void *parsed_result,
4014                       __rte_unused struct cmdline *cl,
4015                       __rte_unused void *data)
4016 {
4017         struct cmd_set_txpkts_result *res;
4018         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4019         unsigned int nb_segs;
4020
4021         res = parsed_result;
4022         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4023                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4024         if (nb_segs > 0)
4025                 set_tx_pkt_segments(seg_lengths, nb_segs);
4026 }
4027
4028 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4029         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4030                                  cmd_keyword, "set");
4031 cmdline_parse_token_string_t cmd_set_txpkts_name =
4032         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4033                                  txpkts, "txpkts");
4034 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4035         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4036                                  seg_lengths, NULL);
4037
4038 cmdline_parse_inst_t cmd_set_txpkts = {
4039         .f = cmd_set_txpkts_parsed,
4040         .data = NULL,
4041         .help_str = "set txpkts <len0[,len1]*>",
4042         .tokens = {
4043                 (void *)&cmd_set_txpkts_keyword,
4044                 (void *)&cmd_set_txpkts_name,
4045                 (void *)&cmd_set_txpkts_lengths,
4046                 NULL,
4047         },
4048 };
4049
4050 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4051
4052 struct cmd_set_txsplit_result {
4053         cmdline_fixed_string_t cmd_keyword;
4054         cmdline_fixed_string_t txsplit;
4055         cmdline_fixed_string_t mode;
4056 };
4057
4058 static void
4059 cmd_set_txsplit_parsed(void *parsed_result,
4060                       __rte_unused struct cmdline *cl,
4061                       __rte_unused void *data)
4062 {
4063         struct cmd_set_txsplit_result *res;
4064
4065         res = parsed_result;
4066         set_tx_pkt_split(res->mode);
4067 }
4068
4069 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4070         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4071                                  cmd_keyword, "set");
4072 cmdline_parse_token_string_t cmd_set_txsplit_name =
4073         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4074                                  txsplit, "txsplit");
4075 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4076         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4077                                  mode, NULL);
4078
4079 cmdline_parse_inst_t cmd_set_txsplit = {
4080         .f = cmd_set_txsplit_parsed,
4081         .data = NULL,
4082         .help_str = "set txsplit on|off|rand",
4083         .tokens = {
4084                 (void *)&cmd_set_txsplit_keyword,
4085                 (void *)&cmd_set_txsplit_name,
4086                 (void *)&cmd_set_txsplit_mode,
4087                 NULL,
4088         },
4089 };
4090
4091 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4092
4093 struct cmd_set_txtimes_result {
4094         cmdline_fixed_string_t cmd_keyword;
4095         cmdline_fixed_string_t txtimes;
4096         cmdline_fixed_string_t tx_times;
4097 };
4098
4099 static void
4100 cmd_set_txtimes_parsed(void *parsed_result,
4101                        __rte_unused struct cmdline *cl,
4102                        __rte_unused void *data)
4103 {
4104         struct cmd_set_txtimes_result *res;
4105         unsigned int tx_times[2] = {0, 0};
4106         unsigned int n_times;
4107
4108         res = parsed_result;
4109         n_times = parse_item_list(res->tx_times, "tx times",
4110                                   2, tx_times, 0);
4111         if (n_times == 2)
4112                 set_tx_pkt_times(tx_times);
4113 }
4114
4115 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4116         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4117                                  cmd_keyword, "set");
4118 cmdline_parse_token_string_t cmd_set_txtimes_name =
4119         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4120                                  txtimes, "txtimes");
4121 cmdline_parse_token_string_t cmd_set_txtimes_value =
4122         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4123                                  tx_times, NULL);
4124
4125 cmdline_parse_inst_t cmd_set_txtimes = {
4126         .f = cmd_set_txtimes_parsed,
4127         .data = NULL,
4128         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4129         .tokens = {
4130                 (void *)&cmd_set_txtimes_keyword,
4131                 (void *)&cmd_set_txtimes_name,
4132                 (void *)&cmd_set_txtimes_value,
4133                 NULL,
4134         },
4135 };
4136
4137 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4138 struct cmd_rx_vlan_filter_all_result {
4139         cmdline_fixed_string_t rx_vlan;
4140         cmdline_fixed_string_t what;
4141         cmdline_fixed_string_t all;
4142         portid_t port_id;
4143 };
4144
4145 static void
4146 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4147                               __rte_unused struct cmdline *cl,
4148                               __rte_unused void *data)
4149 {
4150         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4151
4152         if (!strcmp(res->what, "add"))
4153                 rx_vlan_all_filter_set(res->port_id, 1);
4154         else
4155                 rx_vlan_all_filter_set(res->port_id, 0);
4156 }
4157
4158 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4159         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4160                                  rx_vlan, "rx_vlan");
4161 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4162         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4163                                  what, "add#rm");
4164 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4165         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4166                                  all, "all");
4167 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4168         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4169                               port_id, UINT16);
4170
4171 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4172         .f = cmd_rx_vlan_filter_all_parsed,
4173         .data = NULL,
4174         .help_str = "rx_vlan add|rm all <port_id>: "
4175                 "Add/Remove all identifiers to/from the set of VLAN "
4176                 "identifiers filtered by a port",
4177         .tokens = {
4178                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4179                 (void *)&cmd_rx_vlan_filter_all_what,
4180                 (void *)&cmd_rx_vlan_filter_all_all,
4181                 (void *)&cmd_rx_vlan_filter_all_portid,
4182                 NULL,
4183         },
4184 };
4185
4186 /* *** VLAN OFFLOAD SET ON A PORT *** */
4187 struct cmd_vlan_offload_result {
4188         cmdline_fixed_string_t vlan;
4189         cmdline_fixed_string_t set;
4190         cmdline_fixed_string_t vlan_type;
4191         cmdline_fixed_string_t what;
4192         cmdline_fixed_string_t on;
4193         cmdline_fixed_string_t port_id;
4194 };
4195
4196 static void
4197 cmd_vlan_offload_parsed(void *parsed_result,
4198                           __rte_unused struct cmdline *cl,
4199                           __rte_unused void *data)
4200 {
4201         int on;
4202         struct cmd_vlan_offload_result *res = parsed_result;
4203         char *str;
4204         int i, len = 0;
4205         portid_t port_id = 0;
4206         unsigned int tmp;
4207
4208         str = res->port_id;
4209         len = strnlen(str, STR_TOKEN_SIZE);
4210         i = 0;
4211         /* Get port_id first */
4212         while(i < len){
4213                 if(str[i] == ',')
4214                         break;
4215
4216                 i++;
4217         }
4218         str[i]='\0';
4219         tmp = strtoul(str, NULL, 0);
4220         /* If port_id greater that what portid_t can represent, return */
4221         if(tmp >= RTE_MAX_ETHPORTS)
4222                 return;
4223         port_id = (portid_t)tmp;
4224
4225         if (!strcmp(res->on, "on"))
4226                 on = 1;
4227         else
4228                 on = 0;
4229
4230         if (!strcmp(res->what, "strip"))
4231                 rx_vlan_strip_set(port_id,  on);
4232         else if(!strcmp(res->what, "stripq")){
4233                 uint16_t queue_id = 0;
4234
4235                 /* No queue_id, return */
4236                 if(i + 1 >= len) {
4237                         printf("must specify (port,queue_id)\n");
4238                         return;
4239                 }
4240                 tmp = strtoul(str + i + 1, NULL, 0);
4241                 /* If queue_id greater that what 16-bits can represent, return */
4242                 if(tmp > 0xffff)
4243                         return;
4244
4245                 queue_id = (uint16_t)tmp;
4246                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4247         }
4248         else if (!strcmp(res->what, "filter"))
4249                 rx_vlan_filter_set(port_id, on);
4250         else if (!strcmp(res->what, "qinq_strip"))
4251                 rx_vlan_qinq_strip_set(port_id, on);
4252         else
4253                 vlan_extend_set(port_id, on);
4254
4255         return;
4256 }
4257
4258 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4259         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4260                                  vlan, "vlan");
4261 cmdline_parse_token_string_t cmd_vlan_offload_set =
4262         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4263                                  set, "set");
4264 cmdline_parse_token_string_t cmd_vlan_offload_what =
4265         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4266                                 what, "strip#filter#qinq_strip#extend#stripq");
4267 cmdline_parse_token_string_t cmd_vlan_offload_on =
4268         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4269                               on, "on#off");
4270 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4271         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4272                               port_id, NULL);
4273
4274 cmdline_parse_inst_t cmd_vlan_offload = {
4275         .f = cmd_vlan_offload_parsed,
4276         .data = NULL,
4277         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4278                 "<port_id[,queue_id]>: "
4279                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4280         .tokens = {
4281                 (void *)&cmd_vlan_offload_vlan,
4282                 (void *)&cmd_vlan_offload_set,
4283                 (void *)&cmd_vlan_offload_what,
4284                 (void *)&cmd_vlan_offload_on,
4285                 (void *)&cmd_vlan_offload_portid,
4286                 NULL,
4287         },
4288 };
4289
4290 /* *** VLAN TPID SET ON A PORT *** */
4291 struct cmd_vlan_tpid_result {
4292         cmdline_fixed_string_t vlan;
4293         cmdline_fixed_string_t set;
4294         cmdline_fixed_string_t vlan_type;
4295         cmdline_fixed_string_t what;
4296         uint16_t tp_id;
4297         portid_t port_id;
4298 };
4299
4300 static void
4301 cmd_vlan_tpid_parsed(void *parsed_result,
4302                           __rte_unused struct cmdline *cl,
4303                           __rte_unused void *data)
4304 {
4305         struct cmd_vlan_tpid_result *res = parsed_result;
4306         enum rte_vlan_type vlan_type;
4307
4308         if (!strcmp(res->vlan_type, "inner"))
4309                 vlan_type = ETH_VLAN_TYPE_INNER;
4310         else if (!strcmp(res->vlan_type, "outer"))
4311                 vlan_type = ETH_VLAN_TYPE_OUTER;
4312         else {
4313                 printf("Unknown vlan type\n");
4314                 return;
4315         }
4316         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4317 }
4318
4319 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4320         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4321                                  vlan, "vlan");
4322 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4323         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4324                                  set, "set");
4325 cmdline_parse_token_string_t cmd_vlan_type =
4326         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4327                                  vlan_type, "inner#outer");
4328 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4329         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4330                                  what, "tpid");
4331 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4332         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4333                               tp_id, UINT16);
4334 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4335         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4336                               port_id, UINT16);
4337
4338 cmdline_parse_inst_t cmd_vlan_tpid = {
4339         .f = cmd_vlan_tpid_parsed,
4340         .data = NULL,
4341         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4342                 "Set the VLAN Ether type",
4343         .tokens = {
4344                 (void *)&cmd_vlan_tpid_vlan,
4345                 (void *)&cmd_vlan_tpid_set,
4346                 (void *)&cmd_vlan_type,
4347                 (void *)&cmd_vlan_tpid_what,
4348                 (void *)&cmd_vlan_tpid_tpid,
4349                 (void *)&cmd_vlan_tpid_portid,
4350                 NULL,
4351         },
4352 };
4353
4354 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4355 struct cmd_rx_vlan_filter_result {
4356         cmdline_fixed_string_t rx_vlan;
4357         cmdline_fixed_string_t what;
4358         uint16_t vlan_id;
4359         portid_t port_id;
4360 };
4361
4362 static void
4363 cmd_rx_vlan_filter_parsed(void *parsed_result,
4364                           __rte_unused struct cmdline *cl,
4365                           __rte_unused void *data)
4366 {
4367         struct cmd_rx_vlan_filter_result *res = parsed_result;
4368
4369         if (!strcmp(res->what, "add"))
4370                 rx_vft_set(res->port_id, res->vlan_id, 1);
4371         else
4372                 rx_vft_set(res->port_id, res->vlan_id, 0);
4373 }
4374
4375 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4376         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4377                                  rx_vlan, "rx_vlan");
4378 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4379         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4380                                  what, "add#rm");
4381 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4382         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4383                               vlan_id, UINT16);
4384 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4385         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4386                               port_id, UINT16);
4387
4388 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4389         .f = cmd_rx_vlan_filter_parsed,
4390         .data = NULL,
4391         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4392                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4393                 "identifiers filtered by a port",
4394         .tokens = {
4395                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4396                 (void *)&cmd_rx_vlan_filter_what,
4397                 (void *)&cmd_rx_vlan_filter_vlanid,
4398                 (void *)&cmd_rx_vlan_filter_portid,
4399                 NULL,
4400         },
4401 };
4402
4403 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4404 struct cmd_tx_vlan_set_result {
4405         cmdline_fixed_string_t tx_vlan;
4406         cmdline_fixed_string_t set;
4407         portid_t port_id;
4408         uint16_t vlan_id;
4409 };
4410
4411 static void
4412 cmd_tx_vlan_set_parsed(void *parsed_result,
4413                        __rte_unused struct cmdline *cl,
4414                        __rte_unused void *data)
4415 {
4416         struct cmd_tx_vlan_set_result *res = parsed_result;
4417
4418         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4419                 return;
4420
4421         if (!port_is_stopped(res->port_id)) {
4422                 printf("Please stop port %d first\n", res->port_id);
4423                 return;
4424         }
4425
4426         tx_vlan_set(res->port_id, res->vlan_id);
4427
4428         cmd_reconfig_device_queue(res->port_id, 1, 1);
4429 }
4430
4431 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4432         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4433                                  tx_vlan, "tx_vlan");
4434 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4435         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4436                                  set, "set");
4437 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4438         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4439                               port_id, UINT16);
4440 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4441         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4442                               vlan_id, UINT16);
4443
4444 cmdline_parse_inst_t cmd_tx_vlan_set = {
4445         .f = cmd_tx_vlan_set_parsed,
4446         .data = NULL,
4447         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4448                 "Enable hardware insertion of a single VLAN header "
4449                 "with a given TAG Identifier in packets sent on a port",
4450         .tokens = {
4451                 (void *)&cmd_tx_vlan_set_tx_vlan,
4452                 (void *)&cmd_tx_vlan_set_set,
4453                 (void *)&cmd_tx_vlan_set_portid,
4454                 (void *)&cmd_tx_vlan_set_vlanid,
4455                 NULL,
4456         },
4457 };
4458
4459 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4460 struct cmd_tx_vlan_set_qinq_result {
4461         cmdline_fixed_string_t tx_vlan;
4462         cmdline_fixed_string_t set;
4463         portid_t port_id;
4464         uint16_t vlan_id;
4465         uint16_t vlan_id_outer;
4466 };
4467
4468 static void
4469 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4470                             __rte_unused struct cmdline *cl,
4471                             __rte_unused void *data)
4472 {
4473         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4474
4475         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4476                 return;
4477
4478         if (!port_is_stopped(res->port_id)) {
4479                 printf("Please stop port %d first\n", res->port_id);
4480                 return;
4481         }
4482
4483         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4484
4485         cmd_reconfig_device_queue(res->port_id, 1, 1);
4486 }
4487
4488 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4489         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4490                 tx_vlan, "tx_vlan");
4491 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4492         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4493                 set, "set");
4494 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4495         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4496                 port_id, UINT16);
4497 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4498         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4499                 vlan_id, UINT16);
4500 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4501         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4502                 vlan_id_outer, UINT16);
4503
4504 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4505         .f = cmd_tx_vlan_set_qinq_parsed,
4506         .data = NULL,
4507         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4508                 "Enable hardware insertion of double VLAN header "
4509                 "with given TAG Identifiers in packets sent on a port",
4510         .tokens = {
4511                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4512                 (void *)&cmd_tx_vlan_set_qinq_set,
4513                 (void *)&cmd_tx_vlan_set_qinq_portid,
4514                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4515                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4516                 NULL,
4517         },
4518 };
4519
4520 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4521 struct cmd_tx_vlan_set_pvid_result {
4522         cmdline_fixed_string_t tx_vlan;
4523         cmdline_fixed_string_t set;
4524         cmdline_fixed_string_t pvid;
4525         portid_t port_id;
4526         uint16_t vlan_id;
4527         cmdline_fixed_string_t mode;
4528 };
4529
4530 static void
4531 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4532                             __rte_unused struct cmdline *cl,
4533                             __rte_unused void *data)
4534 {
4535         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4536
4537         if (strcmp(res->mode, "on") == 0)
4538                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4539         else
4540                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4541 }
4542
4543 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4544         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4545                                  tx_vlan, "tx_vlan");
4546 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4547         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4548                                  set, "set");
4549 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4550         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4551                                  pvid, "pvid");
4552 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4553         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4554                              port_id, UINT16);
4555 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4556         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4557                               vlan_id, UINT16);
4558 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4559         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4560                                  mode, "on#off");
4561
4562 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4563         .f = cmd_tx_vlan_set_pvid_parsed,
4564         .data = NULL,
4565         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4566         .tokens = {
4567                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4568                 (void *)&cmd_tx_vlan_set_pvid_set,
4569                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4570                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4571                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4572                 (void *)&cmd_tx_vlan_set_pvid_mode,
4573                 NULL,
4574         },
4575 };
4576
4577 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4578 struct cmd_tx_vlan_reset_result {
4579         cmdline_fixed_string_t tx_vlan;
4580         cmdline_fixed_string_t reset;
4581         portid_t port_id;
4582 };
4583
4584 static void
4585 cmd_tx_vlan_reset_parsed(void *parsed_result,
4586                          __rte_unused struct cmdline *cl,
4587                          __rte_unused void *data)
4588 {
4589         struct cmd_tx_vlan_reset_result *res = parsed_result;
4590
4591         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4592                 return;
4593
4594         if (!port_is_stopped(res->port_id)) {
4595                 printf("Please stop port %d first\n", res->port_id);
4596                 return;
4597         }
4598
4599         tx_vlan_reset(res->port_id);
4600
4601         cmd_reconfig_device_queue(res->port_id, 1, 1);
4602 }
4603
4604 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4605         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4606                                  tx_vlan, "tx_vlan");
4607 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4608         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4609                                  reset, "reset");
4610 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4611         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4612                               port_id, UINT16);
4613
4614 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4615         .f = cmd_tx_vlan_reset_parsed,
4616         .data = NULL,
4617         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4618                 "VLAN header in packets sent on a port",
4619         .tokens = {
4620                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4621                 (void *)&cmd_tx_vlan_reset_reset,
4622                 (void *)&cmd_tx_vlan_reset_portid,
4623                 NULL,
4624         },
4625 };
4626
4627
4628 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4629 struct cmd_csum_result {
4630         cmdline_fixed_string_t csum;
4631         cmdline_fixed_string_t mode;
4632         cmdline_fixed_string_t proto;
4633         cmdline_fixed_string_t hwsw;
4634         portid_t port_id;
4635 };
4636
4637 static void
4638 csum_show(int port_id)
4639 {
4640         struct rte_eth_dev_info dev_info;
4641         uint64_t tx_offloads;
4642         int ret;
4643
4644         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4645         printf("Parse tunnel is %s\n",
4646                 (ports[port_id].parse_tunnel) ? "on" : "off");
4647         printf("IP checksum offload is %s\n",
4648                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4649         printf("UDP checksum offload is %s\n",
4650                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4651         printf("TCP checksum offload is %s\n",
4652                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4653         printf("SCTP checksum offload is %s\n",
4654                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4655         printf("Outer-Ip checksum offload is %s\n",
4656                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4657         printf("Outer-Udp checksum offload is %s\n",
4658                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4659
4660         /* display warnings if configuration is not supported by the NIC */
4661         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4662         if (ret != 0)
4663                 return;
4664
4665         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4666                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4667                 printf("Warning: hardware IP checksum enabled but not "
4668                         "supported by port %d\n", port_id);
4669         }
4670         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4671                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4672                 printf("Warning: hardware UDP checksum enabled but not "
4673                         "supported by port %d\n", port_id);
4674         }
4675         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4676                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4677                 printf("Warning: hardware TCP checksum enabled but not "
4678                         "supported by port %d\n", port_id);
4679         }
4680         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4681                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4682                 printf("Warning: hardware SCTP checksum enabled but not "
4683                         "supported by port %d\n", port_id);
4684         }
4685         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4686                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4687                 printf("Warning: hardware outer IP checksum enabled but not "
4688                         "supported by port %d\n", port_id);
4689         }
4690         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4691                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4692                         == 0) {
4693                 printf("Warning: hardware outer UDP checksum enabled but not "
4694                         "supported by port %d\n", port_id);
4695         }
4696 }
4697
4698 static void
4699 cmd_config_queue_tx_offloads(struct rte_port *port)
4700 {
4701         int k;
4702
4703         /* Apply queue tx offloads configuration */
4704         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4705                 port->tx_conf[k].offloads =
4706                         port->dev_conf.txmode.offloads;
4707 }
4708
4709 static void
4710 cmd_csum_parsed(void *parsed_result,
4711                        __rte_unused struct cmdline *cl,
4712                        __rte_unused void *data)
4713 {
4714         struct cmd_csum_result *res = parsed_result;
4715         int hw = 0;
4716         uint64_t csum_offloads = 0;
4717         struct rte_eth_dev_info dev_info;
4718         int ret;
4719
4720         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4721                 printf("invalid port %d\n", res->port_id);
4722                 return;
4723         }
4724         if (!port_is_stopped(res->port_id)) {
4725                 printf("Please stop port %d first\n", res->port_id);
4726                 return;
4727         }
4728
4729         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4730         if (ret != 0)
4731                 return;
4732
4733         if (!strcmp(res->mode, "set")) {
4734
4735                 if (!strcmp(res->hwsw, "hw"))
4736                         hw = 1;
4737
4738                 if (!strcmp(res->proto, "ip")) {
4739                         if (hw == 0 || (dev_info.tx_offload_capa &
4740                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4741                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4742                         } else {
4743                                 printf("IP checksum offload is not supported "
4744                                        "by port %u\n", res->port_id);
4745                         }
4746                 } else if (!strcmp(res->proto, "udp")) {
4747                         if (hw == 0 || (dev_info.tx_offload_capa &
4748                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4749                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4750                         } else {
4751                                 printf("UDP checksum offload is not supported "
4752                                        "by port %u\n", res->port_id);
4753                         }
4754                 } else if (!strcmp(res->proto, "tcp")) {
4755                         if (hw == 0 || (dev_info.tx_offload_capa &
4756                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4757                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4758                         } else {
4759                                 printf("TCP checksum offload is not supported "
4760                                        "by port %u\n", res->port_id);
4761                         }
4762                 } else if (!strcmp(res->proto, "sctp")) {
4763                         if (hw == 0 || (dev_info.tx_offload_capa &
4764                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4765                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4766                         } else {
4767                                 printf("SCTP checksum offload is not supported "
4768                                        "by port %u\n", res->port_id);
4769                         }
4770                 } else if (!strcmp(res->proto, "outer-ip")) {
4771                         if (hw == 0 || (dev_info.tx_offload_capa &
4772                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4773                                 csum_offloads |=
4774                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4775                         } else {
4776                                 printf("Outer IP checksum offload is not "
4777                                        "supported by port %u\n", res->port_id);
4778                         }
4779                 } else if (!strcmp(res->proto, "outer-udp")) {
4780                         if (hw == 0 || (dev_info.tx_offload_capa &
4781                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4782                                 csum_offloads |=
4783                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4784                         } else {
4785                                 printf("Outer UDP checksum offload is not "
4786                                        "supported by port %u\n", res->port_id);
4787                         }
4788                 }
4789
4790                 if (hw) {
4791                         ports[res->port_id].dev_conf.txmode.offloads |=
4792                                                         csum_offloads;
4793                 } else {
4794                         ports[res->port_id].dev_conf.txmode.offloads &=
4795                                                         (~csum_offloads);
4796                 }
4797                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4798         }
4799         csum_show(res->port_id);
4800
4801         cmd_reconfig_device_queue(res->port_id, 1, 1);
4802 }
4803
4804 cmdline_parse_token_string_t cmd_csum_csum =
4805         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4806                                 csum, "csum");
4807 cmdline_parse_token_string_t cmd_csum_mode =
4808         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4809                                 mode, "set");
4810 cmdline_parse_token_string_t cmd_csum_proto =
4811         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4812                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4813 cmdline_parse_token_string_t cmd_csum_hwsw =
4814         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4815                                 hwsw, "hw#sw");
4816 cmdline_parse_token_num_t cmd_csum_portid =
4817         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4818                                 port_id, UINT16);
4819
4820 cmdline_parse_inst_t cmd_csum_set = {
4821         .f = cmd_csum_parsed,
4822         .data = NULL,
4823         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4824                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4825                 "using csum forward engine",
4826         .tokens = {
4827                 (void *)&cmd_csum_csum,
4828                 (void *)&cmd_csum_mode,
4829                 (void *)&cmd_csum_proto,
4830                 (void *)&cmd_csum_hwsw,
4831                 (void *)&cmd_csum_portid,
4832                 NULL,
4833         },
4834 };
4835
4836 cmdline_parse_token_string_t cmd_csum_mode_show =
4837         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4838                                 mode, "show");
4839
4840 cmdline_parse_inst_t cmd_csum_show = {
4841         .f = cmd_csum_parsed,
4842         .data = NULL,
4843         .help_str = "csum show <port_id>: Show checksum offload configuration",
4844         .tokens = {
4845                 (void *)&cmd_csum_csum,
4846                 (void *)&cmd_csum_mode_show,
4847                 (void *)&cmd_csum_portid,
4848                 NULL,
4849         },
4850 };
4851
4852 /* Enable/disable tunnel parsing */
4853 struct cmd_csum_tunnel_result {
4854         cmdline_fixed_string_t csum;
4855         cmdline_fixed_string_t parse;
4856         cmdline_fixed_string_t onoff;
4857         portid_t port_id;
4858 };
4859
4860 static void
4861 cmd_csum_tunnel_parsed(void *parsed_result,
4862                        __rte_unused struct cmdline *cl,
4863                        __rte_unused void *data)
4864 {
4865         struct cmd_csum_tunnel_result *res = parsed_result;
4866
4867         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4868                 return;
4869
4870         if (!strcmp(res->onoff, "on"))
4871                 ports[res->port_id].parse_tunnel = 1;
4872         else
4873                 ports[res->port_id].parse_tunnel = 0;
4874
4875         csum_show(res->port_id);
4876 }
4877
4878 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4879         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4880                                 csum, "csum");
4881 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4882         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4883                                 parse, "parse-tunnel");
4884 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4885         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4886                                 onoff, "on#off");
4887 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4888         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4889                                 port_id, UINT16);
4890
4891 cmdline_parse_inst_t cmd_csum_tunnel = {
4892         .f = cmd_csum_tunnel_parsed,
4893         .data = NULL,
4894         .help_str = "csum parse-tunnel on|off <port_id>: "
4895                 "Enable/Disable parsing of tunnels for csum engine",
4896         .tokens = {
4897                 (void *)&cmd_csum_tunnel_csum,
4898                 (void *)&cmd_csum_tunnel_parse,
4899                 (void *)&cmd_csum_tunnel_onoff,
4900                 (void *)&cmd_csum_tunnel_portid,
4901                 NULL,
4902         },
4903 };
4904
4905 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4906 struct cmd_tso_set_result {
4907         cmdline_fixed_string_t tso;
4908         cmdline_fixed_string_t mode;
4909         uint16_t tso_segsz;
4910         portid_t port_id;
4911 };
4912
4913 static void
4914 cmd_tso_set_parsed(void *parsed_result,
4915                        __rte_unused struct cmdline *cl,
4916                        __rte_unused void *data)
4917 {
4918         struct cmd_tso_set_result *res = parsed_result;
4919         struct rte_eth_dev_info dev_info;
4920         int ret;
4921
4922         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4923                 return;
4924         if (!port_is_stopped(res->port_id)) {
4925                 printf("Please stop port %d first\n", res->port_id);
4926                 return;
4927         }
4928
4929         if (!strcmp(res->mode, "set"))
4930                 ports[res->port_id].tso_segsz = res->tso_segsz;
4931
4932         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4933         if (ret != 0)
4934                 return;
4935
4936         if ((ports[res->port_id].tso_segsz != 0) &&
4937                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4938                 printf("Error: TSO is not supported by port %d\n",
4939                        res->port_id);
4940                 return;
4941         }
4942
4943         if (ports[res->port_id].tso_segsz == 0) {
4944                 ports[res->port_id].dev_conf.txmode.offloads &=
4945                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4946                 printf("TSO for non-tunneled packets is disabled\n");
4947         } else {
4948                 ports[res->port_id].dev_conf.txmode.offloads |=
4949                                                 DEV_TX_OFFLOAD_TCP_TSO;
4950                 printf("TSO segment size for non-tunneled packets is %d\n",
4951                         ports[res->port_id].tso_segsz);
4952         }
4953         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4954
4955         /* display warnings if configuration is not supported by the NIC */
4956         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4957         if (ret != 0)
4958                 return;
4959
4960         if ((ports[res->port_id].tso_segsz != 0) &&
4961                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4962                 printf("Warning: TSO enabled but not "
4963                         "supported by port %d\n", res->port_id);
4964         }
4965
4966         cmd_reconfig_device_queue(res->port_id, 1, 1);
4967 }
4968
4969 cmdline_parse_token_string_t cmd_tso_set_tso =
4970         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4971                                 tso, "tso");
4972 cmdline_parse_token_string_t cmd_tso_set_mode =
4973         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4974                                 mode, "set");
4975 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4976         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4977                                 tso_segsz, UINT16);
4978 cmdline_parse_token_num_t cmd_tso_set_portid =
4979         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4980                                 port_id, UINT16);
4981
4982 cmdline_parse_inst_t cmd_tso_set = {
4983         .f = cmd_tso_set_parsed,
4984         .data = NULL,
4985         .help_str = "tso set <tso_segsz> <port_id>: "
4986                 "Set TSO segment size of non-tunneled packets for csum engine "
4987                 "(0 to disable)",
4988         .tokens = {
4989                 (void *)&cmd_tso_set_tso,
4990                 (void *)&cmd_tso_set_mode,
4991                 (void *)&cmd_tso_set_tso_segsz,
4992                 (void *)&cmd_tso_set_portid,
4993                 NULL,
4994         },
4995 };
4996
4997 cmdline_parse_token_string_t cmd_tso_show_mode =
4998         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4999                                 mode, "show");
5000
5001
5002 cmdline_parse_inst_t cmd_tso_show = {
5003         .f = cmd_tso_set_parsed,
5004         .data = NULL,
5005         .help_str = "tso show <port_id>: "
5006                 "Show TSO segment size of non-tunneled packets for csum engine",
5007         .tokens = {
5008                 (void *)&cmd_tso_set_tso,
5009                 (void *)&cmd_tso_show_mode,
5010                 (void *)&cmd_tso_set_portid,
5011                 NULL,
5012         },
5013 };
5014
5015 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5016 struct cmd_tunnel_tso_set_result {
5017         cmdline_fixed_string_t tso;
5018         cmdline_fixed_string_t mode;
5019         uint16_t tso_segsz;
5020         portid_t port_id;
5021 };
5022
5023 static struct rte_eth_dev_info
5024 check_tunnel_tso_nic_support(portid_t port_id)
5025 {
5026         struct rte_eth_dev_info dev_info;
5027
5028         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5029                 return dev_info;
5030
5031         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
5032                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
5033                        "not enabled for port %d\n", port_id);
5034         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
5035                 printf("Warning: GRE TUNNEL TSO not supported therefore "
5036                        "not enabled for port %d\n", port_id);
5037         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
5038                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
5039                        "not enabled for port %d\n", port_id);
5040         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
5041                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
5042                        "not enabled for port %d\n", port_id);
5043         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
5044                 printf("Warning: IP TUNNEL TSO not supported therefore "
5045                        "not enabled for port %d\n", port_id);
5046         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
5047                 printf("Warning: UDP TUNNEL TSO not supported therefore "
5048                        "not enabled for port %d\n", port_id);
5049         return dev_info;
5050 }
5051
5052 static void
5053 cmd_tunnel_tso_set_parsed(void *parsed_result,
5054                           __rte_unused struct cmdline *cl,
5055                           __rte_unused void *data)
5056 {
5057         struct cmd_tunnel_tso_set_result *res = parsed_result;
5058         struct rte_eth_dev_info dev_info;
5059
5060         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5061                 return;
5062         if (!port_is_stopped(res->port_id)) {
5063                 printf("Please stop port %d first\n", res->port_id);
5064                 return;
5065         }
5066
5067         if (!strcmp(res->mode, "set"))
5068                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5069
5070         dev_info = check_tunnel_tso_nic_support(res->port_id);
5071         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5072                 ports[res->port_id].dev_conf.txmode.offloads &=
5073                         ~(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                 printf("TSO for tunneled packets is disabled\n");
5080         } else {
5081                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5082                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
5083                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5084                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5085                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
5086                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
5087
5088                 ports[res->port_id].dev_conf.txmode.offloads |=
5089                         (tso_offloads & dev_info.tx_offload_capa);
5090                 printf("TSO segment size for tunneled packets is %d\n",
5091                         ports[res->port_id].tunnel_tso_segsz);
5092
5093                 /* Below conditions are needed to make it work:
5094                  * (1) tunnel TSO is supported by the NIC;
5095                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5096                  * are recognized;
5097                  * (3) for tunneled pkts with outer L3 of IPv4,
5098                  * "csum set outer-ip" must be set to hw, because after tso,
5099                  * total_len of outer IP header is changed, and the checksum
5100                  * of outer IP header calculated by sw should be wrong; that
5101                  * is not necessary for IPv6 tunneled pkts because there's no
5102                  * checksum in IP header anymore.
5103                  */
5104
5105                 if (!ports[res->port_id].parse_tunnel)
5106                         printf("Warning: csum parse_tunnel must be set "
5107                                 "so that tunneled packets are recognized\n");
5108                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5109                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5110                         printf("Warning: csum set outer-ip must be set to hw "
5111                                 "if outer L3 is IPv4; not necessary for IPv6\n");
5112         }
5113
5114         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5115         cmd_reconfig_device_queue(res->port_id, 1, 1);
5116 }
5117
5118 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5119         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5120                                 tso, "tunnel_tso");
5121 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5122         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5123                                 mode, "set");
5124 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5125         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5126                                 tso_segsz, UINT16);
5127 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5128         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5129                                 port_id, UINT16);
5130
5131 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5132         .f = cmd_tunnel_tso_set_parsed,
5133         .data = NULL,
5134         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5135                 "Set TSO segment size of tunneled packets for csum engine "
5136                 "(0 to disable)",
5137         .tokens = {
5138                 (void *)&cmd_tunnel_tso_set_tso,
5139                 (void *)&cmd_tunnel_tso_set_mode,
5140                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5141                 (void *)&cmd_tunnel_tso_set_portid,
5142                 NULL,
5143         },
5144 };
5145
5146 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5147         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5148                                 mode, "show");
5149
5150
5151 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5152         .f = cmd_tunnel_tso_set_parsed,
5153         .data = NULL,
5154         .help_str = "tunnel_tso show <port_id> "
5155                 "Show TSO segment size of tunneled packets for csum engine",
5156         .tokens = {
5157                 (void *)&cmd_tunnel_tso_set_tso,
5158                 (void *)&cmd_tunnel_tso_show_mode,
5159                 (void *)&cmd_tunnel_tso_set_portid,
5160                 NULL,
5161         },
5162 };
5163
5164 /* *** SET GRO FOR A PORT *** */
5165 struct cmd_gro_enable_result {
5166         cmdline_fixed_string_t cmd_set;
5167         cmdline_fixed_string_t cmd_port;
5168         cmdline_fixed_string_t cmd_keyword;
5169         cmdline_fixed_string_t cmd_onoff;
5170         portid_t cmd_pid;
5171 };
5172
5173 static void
5174 cmd_gro_enable_parsed(void *parsed_result,
5175                 __rte_unused struct cmdline *cl,
5176                 __rte_unused void *data)
5177 {
5178         struct cmd_gro_enable_result *res;
5179
5180         res = parsed_result;
5181         if (!strcmp(res->cmd_keyword, "gro"))
5182                 setup_gro(res->cmd_onoff, res->cmd_pid);
5183 }
5184
5185 cmdline_parse_token_string_t cmd_gro_enable_set =
5186         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5187                         cmd_set, "set");
5188 cmdline_parse_token_string_t cmd_gro_enable_port =
5189         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5190                         cmd_keyword, "port");
5191 cmdline_parse_token_num_t cmd_gro_enable_pid =
5192         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5193                         cmd_pid, UINT16);
5194 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5195         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5196                         cmd_keyword, "gro");
5197 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5198         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5199                         cmd_onoff, "on#off");
5200
5201 cmdline_parse_inst_t cmd_gro_enable = {
5202         .f = cmd_gro_enable_parsed,
5203         .data = NULL,
5204         .help_str = "set port <port_id> gro on|off",
5205         .tokens = {
5206                 (void *)&cmd_gro_enable_set,
5207                 (void *)&cmd_gro_enable_port,
5208                 (void *)&cmd_gro_enable_pid,
5209                 (void *)&cmd_gro_enable_keyword,
5210                 (void *)&cmd_gro_enable_onoff,
5211                 NULL,
5212         },
5213 };
5214
5215 /* *** DISPLAY GRO CONFIGURATION *** */
5216 struct cmd_gro_show_result {
5217         cmdline_fixed_string_t cmd_show;
5218         cmdline_fixed_string_t cmd_port;
5219         cmdline_fixed_string_t cmd_keyword;
5220         portid_t cmd_pid;
5221 };
5222
5223 static void
5224 cmd_gro_show_parsed(void *parsed_result,
5225                 __rte_unused struct cmdline *cl,
5226                 __rte_unused void *data)
5227 {
5228         struct cmd_gro_show_result *res;
5229
5230         res = parsed_result;
5231         if (!strcmp(res->cmd_keyword, "gro"))
5232                 show_gro(res->cmd_pid);
5233 }
5234
5235 cmdline_parse_token_string_t cmd_gro_show_show =
5236         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5237                         cmd_show, "show");
5238 cmdline_parse_token_string_t cmd_gro_show_port =
5239         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5240                         cmd_port, "port");
5241 cmdline_parse_token_num_t cmd_gro_show_pid =
5242         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5243                         cmd_pid, UINT16);
5244 cmdline_parse_token_string_t cmd_gro_show_keyword =
5245         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5246                         cmd_keyword, "gro");
5247
5248 cmdline_parse_inst_t cmd_gro_show = {
5249         .f = cmd_gro_show_parsed,
5250         .data = NULL,
5251         .help_str = "show port <port_id> gro",
5252         .tokens = {
5253                 (void *)&cmd_gro_show_show,
5254                 (void *)&cmd_gro_show_port,
5255                 (void *)&cmd_gro_show_pid,
5256                 (void *)&cmd_gro_show_keyword,
5257                 NULL,
5258         },
5259 };
5260
5261 /* *** SET FLUSH CYCLES FOR GRO *** */
5262 struct cmd_gro_flush_result {
5263         cmdline_fixed_string_t cmd_set;
5264         cmdline_fixed_string_t cmd_keyword;
5265         cmdline_fixed_string_t cmd_flush;
5266         uint8_t cmd_cycles;
5267 };
5268
5269 static void
5270 cmd_gro_flush_parsed(void *parsed_result,
5271                 __rte_unused struct cmdline *cl,
5272                 __rte_unused void *data)
5273 {
5274         struct cmd_gro_flush_result *res;
5275
5276         res = parsed_result;
5277         if ((!strcmp(res->cmd_keyword, "gro")) &&
5278                         (!strcmp(res->cmd_flush, "flush")))
5279                 setup_gro_flush_cycles(res->cmd_cycles);
5280 }
5281
5282 cmdline_parse_token_string_t cmd_gro_flush_set =
5283         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5284                         cmd_set, "set");
5285 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5286         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5287                         cmd_keyword, "gro");
5288 cmdline_parse_token_string_t cmd_gro_flush_flush =
5289         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5290                         cmd_flush, "flush");
5291 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5292         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5293                         cmd_cycles, UINT8);
5294
5295 cmdline_parse_inst_t cmd_gro_flush = {
5296         .f = cmd_gro_flush_parsed,
5297         .data = NULL,
5298         .help_str = "set gro flush <cycles>",
5299         .tokens = {
5300                 (void *)&cmd_gro_flush_set,
5301                 (void *)&cmd_gro_flush_keyword,
5302                 (void *)&cmd_gro_flush_flush,
5303                 (void *)&cmd_gro_flush_cycles,
5304                 NULL,
5305         },
5306 };
5307
5308 /* *** ENABLE/DISABLE GSO *** */
5309 struct cmd_gso_enable_result {
5310         cmdline_fixed_string_t cmd_set;
5311         cmdline_fixed_string_t cmd_port;
5312         cmdline_fixed_string_t cmd_keyword;
5313         cmdline_fixed_string_t cmd_mode;
5314         portid_t cmd_pid;
5315 };
5316
5317 static void
5318 cmd_gso_enable_parsed(void *parsed_result,
5319                 __rte_unused struct cmdline *cl,
5320                 __rte_unused void *data)
5321 {
5322         struct cmd_gso_enable_result *res;
5323
5324         res = parsed_result;
5325         if (!strcmp(res->cmd_keyword, "gso"))
5326                 setup_gso(res->cmd_mode, res->cmd_pid);
5327 }
5328
5329 cmdline_parse_token_string_t cmd_gso_enable_set =
5330         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5331                         cmd_set, "set");
5332 cmdline_parse_token_string_t cmd_gso_enable_port =
5333         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5334                         cmd_port, "port");
5335 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5336         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5337                         cmd_keyword, "gso");
5338 cmdline_parse_token_string_t cmd_gso_enable_mode =
5339         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5340                         cmd_mode, "on#off");
5341 cmdline_parse_token_num_t cmd_gso_enable_pid =
5342         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5343                         cmd_pid, UINT16);
5344
5345 cmdline_parse_inst_t cmd_gso_enable = {
5346         .f = cmd_gso_enable_parsed,
5347         .data = NULL,
5348         .help_str = "set port <port_id> gso on|off",
5349         .tokens = {
5350                 (void *)&cmd_gso_enable_set,
5351                 (void *)&cmd_gso_enable_port,
5352                 (void *)&cmd_gso_enable_pid,
5353                 (void *)&cmd_gso_enable_keyword,
5354                 (void *)&cmd_gso_enable_mode,
5355                 NULL,
5356         },
5357 };
5358
5359 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5360 struct cmd_gso_size_result {
5361         cmdline_fixed_string_t cmd_set;
5362         cmdline_fixed_string_t cmd_keyword;
5363         cmdline_fixed_string_t cmd_segsz;
5364         uint16_t cmd_size;
5365 };
5366
5367 static void
5368 cmd_gso_size_parsed(void *parsed_result,
5369                        __rte_unused struct cmdline *cl,
5370                        __rte_unused void *data)
5371 {
5372         struct cmd_gso_size_result *res = parsed_result;
5373
5374         if (test_done == 0) {
5375                 printf("Before setting GSO segsz, please first"
5376                                 " stop forwarding\n");
5377                 return;
5378         }
5379
5380         if (!strcmp(res->cmd_keyword, "gso") &&
5381                         !strcmp(res->cmd_segsz, "segsz")) {
5382                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5383                         printf("gso_size should be larger than %zu."
5384                                         " Please input a legal value\n",
5385                                         RTE_GSO_SEG_SIZE_MIN);
5386                 else
5387                         gso_max_segment_size = res->cmd_size;
5388         }
5389 }
5390
5391 cmdline_parse_token_string_t cmd_gso_size_set =
5392         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5393                                 cmd_set, "set");
5394 cmdline_parse_token_string_t cmd_gso_size_keyword =
5395         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5396                                 cmd_keyword, "gso");
5397 cmdline_parse_token_string_t cmd_gso_size_segsz =
5398         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5399                                 cmd_segsz, "segsz");
5400 cmdline_parse_token_num_t cmd_gso_size_size =
5401         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5402                                 cmd_size, UINT16);
5403
5404 cmdline_parse_inst_t cmd_gso_size = {
5405         .f = cmd_gso_size_parsed,
5406         .data = NULL,
5407         .help_str = "set gso segsz <length>",
5408         .tokens = {
5409                 (void *)&cmd_gso_size_set,
5410                 (void *)&cmd_gso_size_keyword,
5411                 (void *)&cmd_gso_size_segsz,
5412                 (void *)&cmd_gso_size_size,
5413                 NULL,
5414         },
5415 };
5416
5417 /* *** SHOW GSO CONFIGURATION *** */
5418 struct cmd_gso_show_result {
5419         cmdline_fixed_string_t cmd_show;
5420         cmdline_fixed_string_t cmd_port;
5421         cmdline_fixed_string_t cmd_keyword;
5422         portid_t cmd_pid;
5423 };
5424
5425 static void
5426 cmd_gso_show_parsed(void *parsed_result,
5427                        __rte_unused struct cmdline *cl,
5428                        __rte_unused void *data)
5429 {
5430         struct cmd_gso_show_result *res = parsed_result;
5431
5432         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5433                 printf("invalid port id %u\n", res->cmd_pid);
5434                 return;
5435         }
5436         if (!strcmp(res->cmd_keyword, "gso")) {
5437                 if (gso_ports[res->cmd_pid].enable) {
5438                         printf("Max GSO'd packet size: %uB\n"
5439                                         "Supported GSO types: TCP/IPv4, "
5440                                         "UDP/IPv4, VxLAN with inner "
5441                                         "TCP/IPv4 packet, GRE with inner "
5442                                         "TCP/IPv4 packet\n",
5443                                         gso_max_segment_size);
5444                 } else
5445                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5446         }
5447 }
5448
5449 cmdline_parse_token_string_t cmd_gso_show_show =
5450 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5451                 cmd_show, "show");
5452 cmdline_parse_token_string_t cmd_gso_show_port =
5453 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5454                 cmd_port, "port");
5455 cmdline_parse_token_string_t cmd_gso_show_keyword =
5456         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5457                                 cmd_keyword, "gso");
5458 cmdline_parse_token_num_t cmd_gso_show_pid =
5459         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5460                                 cmd_pid, UINT16);
5461
5462 cmdline_parse_inst_t cmd_gso_show = {
5463         .f = cmd_gso_show_parsed,
5464         .data = NULL,
5465         .help_str = "show port <port_id> gso",
5466         .tokens = {
5467                 (void *)&cmd_gso_show_show,
5468                 (void *)&cmd_gso_show_port,
5469                 (void *)&cmd_gso_show_pid,
5470                 (void *)&cmd_gso_show_keyword,
5471                 NULL,
5472         },
5473 };
5474
5475 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5476 struct cmd_set_flush_rx {
5477         cmdline_fixed_string_t set;
5478         cmdline_fixed_string_t flush_rx;
5479         cmdline_fixed_string_t mode;
5480 };
5481
5482 static void
5483 cmd_set_flush_rx_parsed(void *parsed_result,
5484                 __rte_unused struct cmdline *cl,
5485                 __rte_unused void *data)
5486 {
5487         struct cmd_set_flush_rx *res = parsed_result;
5488         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5489 }
5490
5491 cmdline_parse_token_string_t cmd_setflushrx_set =
5492         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5493                         set, "set");
5494 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5495         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5496                         flush_rx, "flush_rx");
5497 cmdline_parse_token_string_t cmd_setflushrx_mode =
5498         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5499                         mode, "on#off");
5500
5501
5502 cmdline_parse_inst_t cmd_set_flush_rx = {
5503         .f = cmd_set_flush_rx_parsed,
5504         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5505         .data = NULL,
5506         .tokens = {
5507                 (void *)&cmd_setflushrx_set,
5508                 (void *)&cmd_setflushrx_flush_rx,
5509                 (void *)&cmd_setflushrx_mode,
5510                 NULL,
5511         },
5512 };
5513
5514 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5515 struct cmd_set_link_check {
5516         cmdline_fixed_string_t set;
5517         cmdline_fixed_string_t link_check;
5518         cmdline_fixed_string_t mode;
5519 };
5520
5521 static void
5522 cmd_set_link_check_parsed(void *parsed_result,
5523                 __rte_unused struct cmdline *cl,
5524                 __rte_unused void *data)
5525 {
5526         struct cmd_set_link_check *res = parsed_result;
5527         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5528 }
5529
5530 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5531         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5532                         set, "set");
5533 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5534         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5535                         link_check, "link_check");
5536 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5537         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5538                         mode, "on#off");
5539
5540
5541 cmdline_parse_inst_t cmd_set_link_check = {
5542         .f = cmd_set_link_check_parsed,
5543         .help_str = "set link_check on|off: Enable/Disable link status check "
5544                     "when starting/stopping a port",
5545         .data = NULL,
5546         .tokens = {
5547                 (void *)&cmd_setlinkcheck_set,
5548                 (void *)&cmd_setlinkcheck_link_check,
5549                 (void *)&cmd_setlinkcheck_mode,
5550                 NULL,
5551         },
5552 };
5553
5554 /* *** SET NIC BYPASS MODE *** */
5555 struct cmd_set_bypass_mode_result {
5556         cmdline_fixed_string_t set;
5557         cmdline_fixed_string_t bypass;
5558         cmdline_fixed_string_t mode;
5559         cmdline_fixed_string_t value;
5560         portid_t port_id;
5561 };
5562
5563 static void
5564 cmd_set_bypass_mode_parsed(void *parsed_result,
5565                 __rte_unused struct cmdline *cl,
5566                 __rte_unused void *data)
5567 {
5568         struct cmd_set_bypass_mode_result *res = parsed_result;
5569         portid_t port_id = res->port_id;
5570         int32_t rc = -EINVAL;
5571
5572 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5573         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5574
5575         if (!strcmp(res->value, "bypass"))
5576                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5577         else if (!strcmp(res->value, "isolate"))
5578                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5579         else
5580                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5581
5582         /* Set the bypass mode for the relevant port. */
5583         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5584 #endif
5585         if (rc != 0)
5586                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5587 }
5588
5589 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5590         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5591                         set, "set");
5592 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5593         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5594                         bypass, "bypass");
5595 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5596         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5597                         mode, "mode");
5598 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5599         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5600                         value, "normal#bypass#isolate");
5601 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5602         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5603                                 port_id, UINT16);
5604
5605 cmdline_parse_inst_t cmd_set_bypass_mode = {
5606         .f = cmd_set_bypass_mode_parsed,
5607         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5608                     "Set the NIC bypass mode for port_id",
5609         .data = NULL,
5610         .tokens = {
5611                 (void *)&cmd_setbypass_mode_set,
5612                 (void *)&cmd_setbypass_mode_bypass,
5613                 (void *)&cmd_setbypass_mode_mode,
5614                 (void *)&cmd_setbypass_mode_value,
5615                 (void *)&cmd_setbypass_mode_port,
5616                 NULL,
5617         },
5618 };
5619
5620 /* *** SET NIC BYPASS EVENT *** */
5621 struct cmd_set_bypass_event_result {
5622         cmdline_fixed_string_t set;
5623         cmdline_fixed_string_t bypass;
5624         cmdline_fixed_string_t event;
5625         cmdline_fixed_string_t event_value;
5626         cmdline_fixed_string_t mode;
5627         cmdline_fixed_string_t mode_value;
5628         portid_t port_id;
5629 };
5630
5631 static void
5632 cmd_set_bypass_event_parsed(void *parsed_result,
5633                 __rte_unused struct cmdline *cl,
5634                 __rte_unused void *data)
5635 {
5636         int32_t rc = -EINVAL;
5637         struct cmd_set_bypass_event_result *res = parsed_result;
5638         portid_t port_id = res->port_id;
5639
5640 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5641         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5642         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5643
5644         if (!strcmp(res->event_value, "timeout"))
5645                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5646         else if (!strcmp(res->event_value, "os_on"))
5647                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5648         else if (!strcmp(res->event_value, "os_off"))
5649                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5650         else if (!strcmp(res->event_value, "power_on"))
5651                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5652         else if (!strcmp(res->event_value, "power_off"))
5653                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5654         else
5655                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5656
5657         if (!strcmp(res->mode_value, "bypass"))
5658                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5659         else if (!strcmp(res->mode_value, "isolate"))
5660                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5661         else
5662                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5663
5664         /* Set the watchdog timeout. */
5665         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5666
5667                 rc = -EINVAL;
5668                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5669                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5670                                                            bypass_timeout);
5671                 }
5672                 if (rc != 0) {
5673                         printf("Failed to set timeout value %u "
5674                         "for port %d, errto code: %d.\n",
5675                         bypass_timeout, port_id, rc);
5676                 }
5677         }
5678
5679         /* Set the bypass event to transition to bypass mode. */
5680         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5681                                               bypass_mode);
5682 #endif
5683
5684         if (rc != 0)
5685                 printf("\t Failed to set bypass event for port = %d.\n",
5686                        port_id);
5687 }
5688
5689 cmdline_parse_token_string_t cmd_setbypass_event_set =
5690         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5691                         set, "set");
5692 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5693         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5694                         bypass, "bypass");
5695 cmdline_parse_token_string_t cmd_setbypass_event_event =
5696         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5697                         event, "event");
5698 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5699         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5700                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5701 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5702         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5703                         mode, "mode");
5704 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5705         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5706                         mode_value, "normal#bypass#isolate");
5707 cmdline_parse_token_num_t cmd_setbypass_event_port =
5708         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5709                                 port_id, UINT16);
5710
5711 cmdline_parse_inst_t cmd_set_bypass_event = {
5712         .f = cmd_set_bypass_event_parsed,
5713         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5714                 "power_off mode normal|bypass|isolate <port_id>: "
5715                 "Set the NIC bypass event mode for port_id",
5716         .data = NULL,
5717         .tokens = {
5718                 (void *)&cmd_setbypass_event_set,
5719                 (void *)&cmd_setbypass_event_bypass,
5720                 (void *)&cmd_setbypass_event_event,
5721                 (void *)&cmd_setbypass_event_event_value,
5722                 (void *)&cmd_setbypass_event_mode,
5723                 (void *)&cmd_setbypass_event_mode_value,
5724                 (void *)&cmd_setbypass_event_port,
5725                 NULL,
5726         },
5727 };
5728
5729
5730 /* *** SET NIC BYPASS TIMEOUT *** */
5731 struct cmd_set_bypass_timeout_result {
5732         cmdline_fixed_string_t set;
5733         cmdline_fixed_string_t bypass;
5734         cmdline_fixed_string_t timeout;
5735         cmdline_fixed_string_t value;
5736 };
5737
5738 static void
5739 cmd_set_bypass_timeout_parsed(void *parsed_result,
5740                 __rte_unused struct cmdline *cl,
5741                 __rte_unused void *data)
5742 {
5743         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5744
5745 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5746         if (!strcmp(res->value, "1.5"))
5747                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5748         else if (!strcmp(res->value, "2"))
5749                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5750         else if (!strcmp(res->value, "3"))
5751                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5752         else if (!strcmp(res->value, "4"))
5753                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5754         else if (!strcmp(res->value, "8"))
5755                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5756         else if (!strcmp(res->value, "16"))
5757                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5758         else if (!strcmp(res->value, "32"))
5759                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5760         else
5761                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5762 #endif
5763 }
5764
5765 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5766         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5767                         set, "set");
5768 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5769         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5770                         bypass, "bypass");
5771 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5772         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5773                         timeout, "timeout");
5774 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5775         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5776                         value, "0#1.5#2#3#4#8#16#32");
5777
5778 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5779         .f = cmd_set_bypass_timeout_parsed,
5780         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5781                 "Set the NIC bypass watchdog timeout in seconds",
5782         .data = NULL,
5783         .tokens = {
5784                 (void *)&cmd_setbypass_timeout_set,
5785                 (void *)&cmd_setbypass_timeout_bypass,
5786                 (void *)&cmd_setbypass_timeout_timeout,
5787                 (void *)&cmd_setbypass_timeout_value,
5788                 NULL,
5789         },
5790 };
5791
5792 /* *** SHOW NIC BYPASS MODE *** */
5793 struct cmd_show_bypass_config_result {
5794         cmdline_fixed_string_t show;
5795         cmdline_fixed_string_t bypass;
5796         cmdline_fixed_string_t config;
5797         portid_t port_id;
5798 };
5799
5800 static void
5801 cmd_show_bypass_config_parsed(void *parsed_result,
5802                 __rte_unused struct cmdline *cl,
5803                 __rte_unused void *data)
5804 {
5805         struct cmd_show_bypass_config_result *res = parsed_result;
5806         portid_t port_id = res->port_id;
5807         int rc = -EINVAL;
5808 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5809         uint32_t event_mode;
5810         uint32_t bypass_mode;
5811         uint32_t timeout = bypass_timeout;
5812         unsigned int i;
5813
5814         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5815                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5816         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5817                 {"UNKNOWN", "normal", "bypass", "isolate"};
5818         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5819                 "NONE",
5820                 "OS/board on",
5821                 "power supply on",
5822                 "OS/board off",
5823                 "power supply off",
5824                 "timeout"};
5825
5826         /* Display the bypass mode.*/
5827         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5828                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5829                 return;
5830         }
5831         else {
5832                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5833                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5834
5835                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5836         }
5837
5838         /* Display the bypass timeout.*/
5839         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5840                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5841
5842         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5843
5844         /* Display the bypass events and associated modes. */
5845         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5846
5847                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5848                         printf("\tFailed to get bypass mode for event = %s\n",
5849                                 events[i]);
5850                 } else {
5851                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5852                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5853
5854                         printf("\tbypass event: %-16s = %s\n", events[i],
5855                                 modes[event_mode]);
5856                 }
5857         }
5858 #endif
5859         if (rc != 0)
5860                 printf("\tFailed to get bypass configuration for port = %d\n",
5861                        port_id);
5862 }
5863
5864 cmdline_parse_token_string_t cmd_showbypass_config_show =
5865         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5866                         show, "show");
5867 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5868         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5869                         bypass, "bypass");
5870 cmdline_parse_token_string_t cmd_showbypass_config_config =
5871         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5872                         config, "config");
5873 cmdline_parse_token_num_t cmd_showbypass_config_port =
5874         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5875                                 port_id, UINT16);
5876
5877 cmdline_parse_inst_t cmd_show_bypass_config = {
5878         .f = cmd_show_bypass_config_parsed,
5879         .help_str = "show bypass config <port_id>: "
5880                     "Show the NIC bypass config for port_id",
5881         .data = NULL,
5882         .tokens = {
5883                 (void *)&cmd_showbypass_config_show,
5884                 (void *)&cmd_showbypass_config_bypass,
5885                 (void *)&cmd_showbypass_config_config,
5886                 (void *)&cmd_showbypass_config_port,
5887                 NULL,
5888         },
5889 };
5890
5891 #ifdef RTE_NET_BOND
5892 /* *** SET BONDING MODE *** */
5893 struct cmd_set_bonding_mode_result {
5894         cmdline_fixed_string_t set;
5895         cmdline_fixed_string_t bonding;
5896         cmdline_fixed_string_t mode;
5897         uint8_t value;
5898         portid_t port_id;
5899 };
5900
5901 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5902                 __rte_unused  struct cmdline *cl,
5903                 __rte_unused void *data)
5904 {
5905         struct cmd_set_bonding_mode_result *res = parsed_result;
5906         portid_t port_id = res->port_id;
5907
5908         /* Set the bonding mode for the relevant port. */
5909         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5910                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5911 }
5912
5913 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5914 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5915                 set, "set");
5916 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5917 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5918                 bonding, "bonding");
5919 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5920 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5921                 mode, "mode");
5922 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5923 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5924                 value, UINT8);
5925 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5926 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5927                 port_id, UINT16);
5928
5929 cmdline_parse_inst_t cmd_set_bonding_mode = {
5930                 .f = cmd_set_bonding_mode_parsed,
5931                 .help_str = "set bonding mode <mode_value> <port_id>: "
5932                         "Set the bonding mode for port_id",
5933                 .data = NULL,
5934                 .tokens = {
5935                                 (void *) &cmd_setbonding_mode_set,
5936                                 (void *) &cmd_setbonding_mode_bonding,
5937                                 (void *) &cmd_setbonding_mode_mode,
5938                                 (void *) &cmd_setbonding_mode_value,
5939                                 (void *) &cmd_setbonding_mode_port,
5940                                 NULL
5941                 }
5942 };
5943
5944 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5945 struct cmd_set_bonding_lacp_dedicated_queues_result {
5946         cmdline_fixed_string_t set;
5947         cmdline_fixed_string_t bonding;
5948         cmdline_fixed_string_t lacp;
5949         cmdline_fixed_string_t dedicated_queues;
5950         portid_t port_id;
5951         cmdline_fixed_string_t mode;
5952 };
5953
5954 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5955                 __rte_unused  struct cmdline *cl,
5956                 __rte_unused void *data)
5957 {
5958         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5959         portid_t port_id = res->port_id;
5960         struct rte_port *port;
5961
5962         port = &ports[port_id];
5963
5964         /** Check if the port is not started **/
5965         if (port->port_status != RTE_PORT_STOPPED) {
5966                 printf("Please stop port %d first\n", port_id);
5967                 return;
5968         }
5969
5970         if (!strcmp(res->mode, "enable")) {
5971                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5972                         printf("Dedicate queues for LACP control packets"
5973                                         " enabled\n");
5974                 else
5975                         printf("Enabling dedicate queues for LACP control "
5976                                         "packets on port %d failed\n", port_id);
5977         } else if (!strcmp(res->mode, "disable")) {
5978                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5979                         printf("Dedicated queues for LACP control packets "
5980                                         "disabled\n");
5981                 else
5982                         printf("Disabling dedicated queues for LACP control "
5983                                         "traffic on port %d failed\n", port_id);
5984         }
5985 }
5986
5987 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5988 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5989                 set, "set");
5990 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5991 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5992                 bonding, "bonding");
5993 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5994 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5995                 lacp, "lacp");
5996 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5997 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5998                 dedicated_queues, "dedicated_queues");
5999 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6000 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6001                 port_id, UINT16);
6002 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6003 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6004                 mode, "enable#disable");
6005
6006 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6007                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6008                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6009                         "enable|disable: "
6010                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6011                 .data = NULL,
6012                 .tokens = {
6013                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6014                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6015                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6016                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6017                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6018                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6019                         NULL
6020                 }
6021 };
6022
6023 /* *** SET BALANCE XMIT POLICY *** */
6024 struct cmd_set_bonding_balance_xmit_policy_result {
6025         cmdline_fixed_string_t set;
6026         cmdline_fixed_string_t bonding;
6027         cmdline_fixed_string_t balance_xmit_policy;
6028         portid_t port_id;
6029         cmdline_fixed_string_t policy;
6030 };
6031
6032 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6033                 __rte_unused  struct cmdline *cl,
6034                 __rte_unused void *data)
6035 {
6036         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6037         portid_t port_id = res->port_id;
6038         uint8_t policy;
6039
6040         if (!strcmp(res->policy, "l2")) {
6041                 policy = BALANCE_XMIT_POLICY_LAYER2;
6042         } else if (!strcmp(res->policy, "l23")) {
6043                 policy = BALANCE_XMIT_POLICY_LAYER23;
6044         } else if (!strcmp(res->policy, "l34")) {
6045                 policy = BALANCE_XMIT_POLICY_LAYER34;
6046         } else {
6047                 printf("\t Invalid xmit policy selection");
6048                 return;
6049         }
6050
6051         /* Set the bonding mode for the relevant port. */
6052         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6053                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
6054                                 port_id);
6055         }
6056 }
6057
6058 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6059 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6060                 set, "set");
6061 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6062 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6063                 bonding, "bonding");
6064 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6065 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6066                 balance_xmit_policy, "balance_xmit_policy");
6067 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6068 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6069                 port_id, UINT16);
6070 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6071 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6072                 policy, "l2#l23#l34");
6073
6074 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6075                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6076                 .help_str = "set bonding balance_xmit_policy <port_id> "
6077                         "l2|l23|l34: "
6078                         "Set the bonding balance_xmit_policy for port_id",
6079                 .data = NULL,
6080                 .tokens = {
6081                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6082                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6083                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6084                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6085                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6086                                 NULL
6087                 }
6088 };
6089
6090 /* *** SHOW NIC BONDING CONFIGURATION *** */
6091 struct cmd_show_bonding_config_result {
6092         cmdline_fixed_string_t show;
6093         cmdline_fixed_string_t bonding;
6094         cmdline_fixed_string_t config;
6095         portid_t port_id;
6096 };
6097
6098 static void cmd_show_bonding_config_parsed(void *parsed_result,
6099                 __rte_unused  struct cmdline *cl,
6100                 __rte_unused void *data)
6101 {
6102         struct cmd_show_bonding_config_result *res = parsed_result;
6103         int bonding_mode, agg_mode;
6104         portid_t slaves[RTE_MAX_ETHPORTS];
6105         int num_slaves, num_active_slaves;
6106         int primary_id;
6107         int i;
6108         portid_t port_id = res->port_id;
6109
6110         /* Display the bonding mode.*/
6111         bonding_mode = rte_eth_bond_mode_get(port_id);
6112         if (bonding_mode < 0) {
6113                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
6114                 return;
6115         } else
6116                 printf("\tBonding mode: %d\n", bonding_mode);
6117
6118         if (bonding_mode == BONDING_MODE_BALANCE) {
6119                 int balance_xmit_policy;
6120
6121                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6122                 if (balance_xmit_policy < 0) {
6123                         printf("\tFailed to get balance xmit policy for port = %d\n",
6124                                         port_id);
6125                         return;
6126                 } else {
6127                         printf("\tBalance Xmit Policy: ");
6128
6129                         switch (balance_xmit_policy) {
6130                         case BALANCE_XMIT_POLICY_LAYER2:
6131                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6132                                 break;
6133                         case BALANCE_XMIT_POLICY_LAYER23:
6134                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6135                                 break;
6136                         case BALANCE_XMIT_POLICY_LAYER34:
6137                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6138                                 break;
6139                         }
6140                         printf("\n");
6141                 }
6142         }
6143
6144         if (bonding_mode == BONDING_MODE_8023AD) {
6145                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6146                 printf("\tIEEE802.3AD Aggregator Mode: ");
6147                 switch (agg_mode) {
6148                 case AGG_BANDWIDTH:
6149                         printf("bandwidth");
6150                         break;
6151                 case AGG_STABLE:
6152                         printf("stable");
6153                         break;
6154                 case AGG_COUNT:
6155                         printf("count");
6156                         break;
6157                 }
6158                 printf("\n");
6159         }
6160
6161         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6162
6163         if (num_slaves < 0) {
6164                 printf("\tFailed to get slave list for port = %d\n", port_id);
6165                 return;
6166         }
6167         if (num_slaves > 0) {
6168                 printf("\tSlaves (%d): [", num_slaves);
6169                 for (i = 0; i < num_slaves - 1; i++)
6170                         printf("%d ", slaves[i]);
6171
6172                 printf("%d]\n", slaves[num_slaves - 1]);
6173         } else {
6174                 printf("\tSlaves: []\n");
6175
6176         }
6177
6178         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6179                         RTE_MAX_ETHPORTS);
6180
6181         if (num_active_slaves < 0) {
6182                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6183                 return;
6184         }
6185         if (num_active_slaves > 0) {
6186                 printf("\tActive Slaves (%d): [", num_active_slaves);
6187                 for (i = 0; i < num_active_slaves - 1; i++)
6188                         printf("%d ", slaves[i]);
6189
6190                 printf("%d]\n", slaves[num_active_slaves - 1]);
6191
6192         } else {
6193                 printf("\tActive Slaves: []\n");
6194
6195         }
6196
6197         primary_id = rte_eth_bond_primary_get(port_id);
6198         if (primary_id < 0) {
6199                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6200                 return;
6201         } else
6202                 printf("\tPrimary: [%d]\n", primary_id);
6203
6204 }
6205
6206 cmdline_parse_token_string_t cmd_showbonding_config_show =
6207 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6208                 show, "show");
6209 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6210 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6211                 bonding, "bonding");
6212 cmdline_parse_token_string_t cmd_showbonding_config_config =
6213 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6214                 config, "config");
6215 cmdline_parse_token_num_t cmd_showbonding_config_port =
6216 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6217                 port_id, UINT16);
6218
6219 cmdline_parse_inst_t cmd_show_bonding_config = {
6220                 .f = cmd_show_bonding_config_parsed,
6221                 .help_str = "show bonding config <port_id>: "
6222                         "Show the bonding config for port_id",
6223                 .data = NULL,
6224                 .tokens = {
6225                                 (void *)&cmd_showbonding_config_show,
6226                                 (void *)&cmd_showbonding_config_bonding,
6227                                 (void *)&cmd_showbonding_config_config,
6228                                 (void *)&cmd_showbonding_config_port,
6229                                 NULL
6230                 }
6231 };
6232
6233 /* *** SET BONDING PRIMARY *** */
6234 struct cmd_set_bonding_primary_result {
6235         cmdline_fixed_string_t set;
6236         cmdline_fixed_string_t bonding;
6237         cmdline_fixed_string_t primary;
6238         portid_t slave_id;
6239         portid_t port_id;
6240 };
6241
6242 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6243                 __rte_unused  struct cmdline *cl,
6244                 __rte_unused void *data)
6245 {
6246         struct cmd_set_bonding_primary_result *res = parsed_result;
6247         portid_t master_port_id = res->port_id;
6248         portid_t slave_port_id = res->slave_id;
6249
6250         /* Set the primary slave for a bonded device. */
6251         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6252                 printf("\t Failed to set primary slave for port = %d.\n",
6253                                 master_port_id);
6254                 return;
6255         }
6256         init_port_config();
6257 }
6258
6259 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6260 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6261                 set, "set");
6262 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6263 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6264                 bonding, "bonding");
6265 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6266 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6267                 primary, "primary");
6268 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6269 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6270                 slave_id, UINT16);
6271 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6272 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6273                 port_id, UINT16);
6274
6275 cmdline_parse_inst_t cmd_set_bonding_primary = {
6276                 .f = cmd_set_bonding_primary_parsed,
6277                 .help_str = "set bonding primary <slave_id> <port_id>: "
6278                         "Set the primary slave for port_id",
6279                 .data = NULL,
6280                 .tokens = {
6281                                 (void *)&cmd_setbonding_primary_set,
6282                                 (void *)&cmd_setbonding_primary_bonding,
6283                                 (void *)&cmd_setbonding_primary_primary,
6284                                 (void *)&cmd_setbonding_primary_slave,
6285                                 (void *)&cmd_setbonding_primary_port,
6286                                 NULL
6287                 }
6288 };
6289
6290 /* *** ADD SLAVE *** */
6291 struct cmd_add_bonding_slave_result {
6292         cmdline_fixed_string_t add;
6293         cmdline_fixed_string_t bonding;
6294         cmdline_fixed_string_t slave;
6295         portid_t slave_id;
6296         portid_t port_id;
6297 };
6298
6299 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6300                 __rte_unused  struct cmdline *cl,
6301                 __rte_unused void *data)
6302 {
6303         struct cmd_add_bonding_slave_result *res = parsed_result;
6304         portid_t master_port_id = res->port_id;
6305         portid_t slave_port_id = res->slave_id;
6306
6307         /* add the slave for a bonded device. */
6308         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6309                 printf("\t Failed to add slave %d to master port = %d.\n",
6310                                 slave_port_id, master_port_id);
6311                 return;
6312         }
6313         init_port_config();
6314         set_port_slave_flag(slave_port_id);
6315 }
6316
6317 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6318 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6319                 add, "add");
6320 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6321 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6322                 bonding, "bonding");
6323 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6324 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6325                 slave, "slave");
6326 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6327 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6328                 slave_id, UINT16);
6329 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6330 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6331                 port_id, UINT16);
6332
6333 cmdline_parse_inst_t cmd_add_bonding_slave = {
6334                 .f = cmd_add_bonding_slave_parsed,
6335                 .help_str = "add bonding slave <slave_id> <port_id>: "
6336                         "Add a slave device to a bonded device",
6337                 .data = NULL,
6338                 .tokens = {
6339                                 (void *)&cmd_addbonding_slave_add,
6340                                 (void *)&cmd_addbonding_slave_bonding,
6341                                 (void *)&cmd_addbonding_slave_slave,
6342                                 (void *)&cmd_addbonding_slave_slaveid,
6343                                 (void *)&cmd_addbonding_slave_port,
6344                                 NULL
6345                 }
6346 };
6347
6348 /* *** REMOVE SLAVE *** */
6349 struct cmd_remove_bonding_slave_result {
6350         cmdline_fixed_string_t remove;
6351         cmdline_fixed_string_t bonding;
6352         cmdline_fixed_string_t slave;
6353         portid_t slave_id;
6354         portid_t port_id;
6355 };
6356
6357 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6358                 __rte_unused  struct cmdline *cl,
6359                 __rte_unused void *data)
6360 {
6361         struct cmd_remove_bonding_slave_result *res = parsed_result;
6362         portid_t master_port_id = res->port_id;
6363         portid_t slave_port_id = res->slave_id;
6364
6365         /* remove the slave from a bonded device. */
6366         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6367                 printf("\t Failed to remove slave %d from master port = %d.\n",
6368                                 slave_port_id, master_port_id);
6369                 return;
6370         }
6371         init_port_config();
6372         clear_port_slave_flag(slave_port_id);
6373 }
6374
6375 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6376                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6377                                 remove, "remove");
6378 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6379                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6380                                 bonding, "bonding");
6381 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6382                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6383                                 slave, "slave");
6384 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6385                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6386                                 slave_id, UINT16);
6387 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6388                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6389                                 port_id, UINT16);
6390
6391 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6392                 .f = cmd_remove_bonding_slave_parsed,
6393                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6394                         "Remove a slave device from a bonded device",
6395                 .data = NULL,
6396                 .tokens = {
6397                                 (void *)&cmd_removebonding_slave_remove,
6398                                 (void *)&cmd_removebonding_slave_bonding,
6399                                 (void *)&cmd_removebonding_slave_slave,
6400                                 (void *)&cmd_removebonding_slave_slaveid,
6401                                 (void *)&cmd_removebonding_slave_port,
6402                                 NULL
6403                 }
6404 };
6405
6406 /* *** CREATE BONDED DEVICE *** */
6407 struct cmd_create_bonded_device_result {
6408         cmdline_fixed_string_t create;
6409         cmdline_fixed_string_t bonded;
6410         cmdline_fixed_string_t device;
6411         uint8_t mode;
6412         uint8_t socket;
6413 };
6414
6415 static int bond_dev_num = 0;
6416
6417 static void cmd_create_bonded_device_parsed(void *parsed_result,
6418                 __rte_unused  struct cmdline *cl,
6419                 __rte_unused void *data)
6420 {
6421         struct cmd_create_bonded_device_result *res = parsed_result;
6422         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6423         int port_id;
6424         int ret;
6425
6426         if (test_done == 0) {
6427                 printf("Please stop forwarding first\n");
6428                 return;
6429         }
6430
6431         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6432                         bond_dev_num++);
6433
6434         /* Create a new bonded device. */
6435         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6436         if (port_id < 0) {
6437                 printf("\t Failed to create bonded device.\n");
6438                 return;
6439         } else {
6440                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6441                                 port_id);
6442
6443                 /* Update number of ports */
6444                 nb_ports = rte_eth_dev_count_avail();
6445                 reconfig(port_id, res->socket);
6446                 ret = rte_eth_promiscuous_enable(port_id);
6447                 if (ret != 0)
6448                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6449                                 port_id, rte_strerror(-ret));
6450
6451                 ports[port_id].need_setup = 0;
6452                 ports[port_id].port_status = RTE_PORT_STOPPED;
6453         }
6454
6455 }
6456
6457 cmdline_parse_token_string_t cmd_createbonded_device_create =
6458                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6459                                 create, "create");
6460 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6461                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6462                                 bonded, "bonded");
6463 cmdline_parse_token_string_t cmd_createbonded_device_device =
6464                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6465                                 device, "device");
6466 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6467                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6468                                 mode, UINT8);
6469 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6470                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6471                                 socket, UINT8);
6472
6473 cmdline_parse_inst_t cmd_create_bonded_device = {
6474                 .f = cmd_create_bonded_device_parsed,
6475                 .help_str = "create bonded device <mode> <socket>: "
6476                         "Create a new bonded device with specific bonding mode and socket",
6477                 .data = NULL,
6478                 .tokens = {
6479                                 (void *)&cmd_createbonded_device_create,
6480                                 (void *)&cmd_createbonded_device_bonded,
6481                                 (void *)&cmd_createbonded_device_device,
6482                                 (void *)&cmd_createbonded_device_mode,
6483                                 (void *)&cmd_createbonded_device_socket,
6484                                 NULL
6485                 }
6486 };
6487
6488 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6489 struct cmd_set_bond_mac_addr_result {
6490         cmdline_fixed_string_t set;
6491         cmdline_fixed_string_t bonding;
6492         cmdline_fixed_string_t mac_addr;
6493         uint16_t port_num;
6494         struct rte_ether_addr address;
6495 };
6496
6497 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6498                 __rte_unused  struct cmdline *cl,
6499                 __rte_unused void *data)
6500 {
6501         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6502         int ret;
6503
6504         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6505                 return;
6506
6507         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6508
6509         /* check the return value and print it if is < 0 */
6510         if (ret < 0)
6511                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6512 }
6513
6514 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6515                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6516 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6517                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6518                                 "bonding");
6519 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6520                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6521                                 "mac_addr");
6522 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6523                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6524                                 port_num, UINT16);
6525 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6526                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6527
6528 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6529                 .f = cmd_set_bond_mac_addr_parsed,
6530                 .data = (void *) 0,
6531                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6532                 .tokens = {
6533                                 (void *)&cmd_set_bond_mac_addr_set,
6534                                 (void *)&cmd_set_bond_mac_addr_bonding,
6535                                 (void *)&cmd_set_bond_mac_addr_mac,
6536                                 (void *)&cmd_set_bond_mac_addr_portnum,
6537                                 (void *)&cmd_set_bond_mac_addr_addr,
6538                                 NULL
6539                 }
6540 };
6541
6542
6543 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6544 struct cmd_set_bond_mon_period_result {
6545         cmdline_fixed_string_t set;
6546         cmdline_fixed_string_t bonding;
6547         cmdline_fixed_string_t mon_period;
6548         uint16_t port_num;
6549         uint32_t period_ms;
6550 };
6551
6552 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6553                 __rte_unused  struct cmdline *cl,
6554                 __rte_unused void *data)
6555 {
6556         struct cmd_set_bond_mon_period_result *res = parsed_result;
6557         int ret;
6558
6559         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6560
6561         /* check the return value and print it if is < 0 */
6562         if (ret < 0)
6563                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6564 }
6565
6566 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6567                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6568                                 set, "set");
6569 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6570                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6571                                 bonding, "bonding");
6572 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6573                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6574                                 mon_period,     "mon_period");
6575 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6576                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6577                                 port_num, UINT16);
6578 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6579                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6580                                 period_ms, UINT32);
6581
6582 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6583                 .f = cmd_set_bond_mon_period_parsed,
6584                 .data = (void *) 0,
6585                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6586                 .tokens = {
6587                                 (void *)&cmd_set_bond_mon_period_set,
6588                                 (void *)&cmd_set_bond_mon_period_bonding,
6589                                 (void *)&cmd_set_bond_mon_period_mon_period,
6590                                 (void *)&cmd_set_bond_mon_period_portnum,
6591                                 (void *)&cmd_set_bond_mon_period_period_ms,
6592                                 NULL
6593                 }
6594 };
6595
6596
6597
6598 struct cmd_set_bonding_agg_mode_policy_result {
6599         cmdline_fixed_string_t set;
6600         cmdline_fixed_string_t bonding;
6601         cmdline_fixed_string_t agg_mode;
6602         uint16_t port_num;
6603         cmdline_fixed_string_t policy;
6604 };
6605
6606
6607 static void
6608 cmd_set_bonding_agg_mode(void *parsed_result,
6609                 __rte_unused struct cmdline *cl,
6610                 __rte_unused void *data)
6611 {
6612         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6613         uint8_t policy = AGG_BANDWIDTH;
6614
6615         if (!strcmp(res->policy, "bandwidth"))
6616                 policy = AGG_BANDWIDTH;
6617         else if (!strcmp(res->policy, "stable"))
6618                 policy = AGG_STABLE;
6619         else if (!strcmp(res->policy, "count"))
6620                 policy = AGG_COUNT;
6621
6622         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6623 }
6624
6625
6626 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6627         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6628                                 set, "set");
6629 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6630         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6631                                 bonding, "bonding");
6632
6633 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6634         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6635                                 agg_mode, "agg_mode");
6636
6637 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6638         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6639                                 port_num, UINT16);
6640
6641 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6642         TOKEN_STRING_INITIALIZER(
6643                         struct cmd_set_bonding_balance_xmit_policy_result,
6644                 policy, "stable#bandwidth#count");
6645
6646 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6647         .f = cmd_set_bonding_agg_mode,
6648         .data = (void *) 0,
6649         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6650         .tokens = {
6651                         (void *)&cmd_set_bonding_agg_mode_set,
6652                         (void *)&cmd_set_bonding_agg_mode_bonding,
6653                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6654                         (void *)&cmd_set_bonding_agg_mode_portnum,
6655                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6656                         NULL
6657                 }
6658 };
6659
6660
6661 #endif /* RTE_NET_BOND */
6662
6663 /* *** SET FORWARDING MODE *** */
6664 struct cmd_set_fwd_mode_result {
6665         cmdline_fixed_string_t set;
6666         cmdline_fixed_string_t fwd;
6667         cmdline_fixed_string_t mode;
6668 };
6669
6670 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6671                                     __rte_unused struct cmdline *cl,
6672                                     __rte_unused void *data)
6673 {
6674         struct cmd_set_fwd_mode_result *res = parsed_result;
6675
6676         retry_enabled = 0;
6677         set_pkt_forwarding_mode(res->mode);
6678 }
6679
6680 cmdline_parse_token_string_t cmd_setfwd_set =
6681         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6682 cmdline_parse_token_string_t cmd_setfwd_fwd =
6683         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6684 cmdline_parse_token_string_t cmd_setfwd_mode =
6685         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6686                 "" /* defined at init */);
6687
6688 cmdline_parse_inst_t cmd_set_fwd_mode = {
6689         .f = cmd_set_fwd_mode_parsed,
6690         .data = NULL,
6691         .help_str = NULL, /* defined at init */
6692         .tokens = {
6693                 (void *)&cmd_setfwd_set,
6694                 (void *)&cmd_setfwd_fwd,
6695                 (void *)&cmd_setfwd_mode,
6696                 NULL,
6697         },
6698 };
6699
6700 static void cmd_set_fwd_mode_init(void)
6701 {
6702         char *modes, *c;
6703         static char token[128];
6704         static char help[256];
6705         cmdline_parse_token_string_t *token_struct;
6706
6707         modes = list_pkt_forwarding_modes();
6708         snprintf(help, sizeof(help), "set fwd %s: "
6709                 "Set packet forwarding mode", modes);
6710         cmd_set_fwd_mode.help_str = help;
6711
6712         /* string token separator is # */
6713         for (c = token; *modes != '\0'; modes++)
6714                 if (*modes == '|')
6715                         *c++ = '#';
6716                 else
6717                         *c++ = *modes;
6718         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6719         token_struct->string_data.str = token;
6720 }
6721
6722 /* *** SET RETRY FORWARDING MODE *** */
6723 struct cmd_set_fwd_retry_mode_result {
6724         cmdline_fixed_string_t set;
6725         cmdline_fixed_string_t fwd;
6726         cmdline_fixed_string_t mode;
6727         cmdline_fixed_string_t retry;
6728 };
6729
6730 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6731                             __rte_unused struct cmdline *cl,
6732                             __rte_unused void *data)
6733 {
6734         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6735
6736         retry_enabled = 1;
6737         set_pkt_forwarding_mode(res->mode);
6738 }
6739
6740 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6741         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6742                         set, "set");
6743 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6744         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6745                         fwd, "fwd");
6746 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6747         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6748                         mode,
6749                 "" /* defined at init */);
6750 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6751         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6752                         retry, "retry");
6753
6754 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6755         .f = cmd_set_fwd_retry_mode_parsed,
6756         .data = NULL,
6757         .help_str = NULL, /* defined at init */
6758         .tokens = {
6759                 (void *)&cmd_setfwd_retry_set,
6760                 (void *)&cmd_setfwd_retry_fwd,
6761                 (void *)&cmd_setfwd_retry_mode,
6762                 (void *)&cmd_setfwd_retry_retry,
6763                 NULL,
6764         },
6765 };
6766
6767 static void cmd_set_fwd_retry_mode_init(void)
6768 {
6769         char *modes, *c;
6770         static char token[128];
6771         static char help[256];
6772         cmdline_parse_token_string_t *token_struct;
6773
6774         modes = list_pkt_forwarding_retry_modes();
6775         snprintf(help, sizeof(help), "set fwd %s retry: "
6776                 "Set packet forwarding mode with retry", modes);
6777         cmd_set_fwd_retry_mode.help_str = help;
6778
6779         /* string token separator is # */
6780         for (c = token; *modes != '\0'; modes++)
6781                 if (*modes == '|')
6782                         *c++ = '#';
6783                 else
6784                         *c++ = *modes;
6785         token_struct = (cmdline_parse_token_string_t *)
6786                 cmd_set_fwd_retry_mode.tokens[2];
6787         token_struct->string_data.str = token;
6788 }
6789
6790 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6791 struct cmd_set_burst_tx_retry_result {
6792         cmdline_fixed_string_t set;
6793         cmdline_fixed_string_t burst;
6794         cmdline_fixed_string_t tx;
6795         cmdline_fixed_string_t delay;
6796         uint32_t time;
6797         cmdline_fixed_string_t retry;
6798         uint32_t retry_num;
6799 };
6800
6801 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6802                                         __rte_unused struct cmdline *cl,
6803                                         __rte_unused void *data)
6804 {
6805         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6806
6807         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6808                 && !strcmp(res->tx, "tx")) {
6809                 if (!strcmp(res->delay, "delay"))
6810                         burst_tx_delay_time = res->time;
6811                 if (!strcmp(res->retry, "retry"))
6812                         burst_tx_retry_num = res->retry_num;
6813         }
6814
6815 }
6816
6817 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6818         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6819 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6820         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6821                                  "burst");
6822 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6823         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6824 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6825         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6826 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6827         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6828 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6829         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6830 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6831         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6832
6833 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6834         .f = cmd_set_burst_tx_retry_parsed,
6835         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6836         .tokens = {
6837                 (void *)&cmd_set_burst_tx_retry_set,
6838                 (void *)&cmd_set_burst_tx_retry_burst,
6839                 (void *)&cmd_set_burst_tx_retry_tx,
6840                 (void *)&cmd_set_burst_tx_retry_delay,
6841                 (void *)&cmd_set_burst_tx_retry_time,
6842                 (void *)&cmd_set_burst_tx_retry_retry,
6843                 (void *)&cmd_set_burst_tx_retry_retry_num,
6844                 NULL,
6845         },
6846 };
6847
6848 /* *** SET PROMISC MODE *** */
6849 struct cmd_set_promisc_mode_result {
6850         cmdline_fixed_string_t set;
6851         cmdline_fixed_string_t promisc;
6852         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6853         uint16_t port_num;               /* valid if "allports" argument == 0 */
6854         cmdline_fixed_string_t mode;
6855 };
6856
6857 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6858                                         __rte_unused struct cmdline *cl,
6859                                         void *allports)
6860 {
6861         struct cmd_set_promisc_mode_result *res = parsed_result;
6862         int enable;
6863         portid_t i;
6864
6865         if (!strcmp(res->mode, "on"))
6866                 enable = 1;
6867         else
6868                 enable = 0;
6869
6870         /* all ports */
6871         if (allports) {
6872                 RTE_ETH_FOREACH_DEV(i)
6873                         eth_set_promisc_mode(i, enable);
6874         } else {
6875                 eth_set_promisc_mode(res->port_num, enable);
6876         }
6877 }
6878
6879 cmdline_parse_token_string_t cmd_setpromisc_set =
6880         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6881 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6882         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6883                                  "promisc");
6884 cmdline_parse_token_string_t cmd_setpromisc_portall =
6885         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6886                                  "all");
6887 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6888         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6889                               UINT16);
6890 cmdline_parse_token_string_t cmd_setpromisc_mode =
6891         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6892                                  "on#off");
6893
6894 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6895         .f = cmd_set_promisc_mode_parsed,
6896         .data = (void *)1,
6897         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6898         .tokens = {
6899                 (void *)&cmd_setpromisc_set,
6900                 (void *)&cmd_setpromisc_promisc,
6901                 (void *)&cmd_setpromisc_portall,
6902                 (void *)&cmd_setpromisc_mode,
6903                 NULL,
6904         },
6905 };
6906
6907 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6908         .f = cmd_set_promisc_mode_parsed,
6909         .data = (void *)0,
6910         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6911         .tokens = {
6912                 (void *)&cmd_setpromisc_set,
6913                 (void *)&cmd_setpromisc_promisc,
6914                 (void *)&cmd_setpromisc_portnum,
6915                 (void *)&cmd_setpromisc_mode,
6916                 NULL,
6917         },
6918 };
6919
6920 /* *** SET ALLMULTI MODE *** */
6921 struct cmd_set_allmulti_mode_result {
6922         cmdline_fixed_string_t set;
6923         cmdline_fixed_string_t allmulti;
6924         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6925         uint16_t port_num;               /* valid if "allports" argument == 0 */
6926         cmdline_fixed_string_t mode;
6927 };
6928
6929 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6930                                         __rte_unused struct cmdline *cl,
6931                                         void *allports)
6932 {
6933         struct cmd_set_allmulti_mode_result *res = parsed_result;
6934         int enable;
6935         portid_t i;
6936
6937         if (!strcmp(res->mode, "on"))
6938                 enable = 1;
6939         else
6940                 enable = 0;
6941
6942         /* all ports */
6943         if (allports) {
6944                 RTE_ETH_FOREACH_DEV(i) {
6945                         eth_set_allmulticast_mode(i, enable);
6946                 }
6947         }
6948         else {
6949                 eth_set_allmulticast_mode(res->port_num, enable);
6950         }
6951 }
6952
6953 cmdline_parse_token_string_t cmd_setallmulti_set =
6954         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6955 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6956         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6957                                  "allmulti");
6958 cmdline_parse_token_string_t cmd_setallmulti_portall =
6959         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6960                                  "all");
6961 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6962         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6963                               UINT16);
6964 cmdline_parse_token_string_t cmd_setallmulti_mode =
6965         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6966                                  "on#off");
6967
6968 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6969         .f = cmd_set_allmulti_mode_parsed,
6970         .data = (void *)1,
6971         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6972         .tokens = {
6973                 (void *)&cmd_setallmulti_set,
6974                 (void *)&cmd_setallmulti_allmulti,
6975                 (void *)&cmd_setallmulti_portall,
6976                 (void *)&cmd_setallmulti_mode,
6977                 NULL,
6978         },
6979 };
6980
6981 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6982         .f = cmd_set_allmulti_mode_parsed,
6983         .data = (void *)0,
6984         .help_str = "set allmulti <port_id> on|off: "
6985                 "Set allmulti mode on port_id",
6986         .tokens = {
6987                 (void *)&cmd_setallmulti_set,
6988                 (void *)&cmd_setallmulti_allmulti,
6989                 (void *)&cmd_setallmulti_portnum,
6990                 (void *)&cmd_setallmulti_mode,
6991                 NULL,
6992         },
6993 };
6994
6995 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6996 struct cmd_link_flow_ctrl_set_result {
6997         cmdline_fixed_string_t set;
6998         cmdline_fixed_string_t flow_ctrl;
6999         cmdline_fixed_string_t rx;
7000         cmdline_fixed_string_t rx_lfc_mode;
7001         cmdline_fixed_string_t tx;
7002         cmdline_fixed_string_t tx_lfc_mode;
7003         cmdline_fixed_string_t mac_ctrl_frame_fwd;
7004         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7005         cmdline_fixed_string_t autoneg_str;
7006         cmdline_fixed_string_t autoneg;
7007         cmdline_fixed_string_t hw_str;
7008         uint32_t high_water;
7009         cmdline_fixed_string_t lw_str;
7010         uint32_t low_water;
7011         cmdline_fixed_string_t pt_str;
7012         uint16_t pause_time;
7013         cmdline_fixed_string_t xon_str;
7014         uint16_t send_xon;
7015         portid_t port_id;
7016 };
7017
7018 cmdline_parse_token_string_t cmd_lfc_set_set =
7019         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7020                                 set, "set");
7021 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7022         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7023                                 flow_ctrl, "flow_ctrl");
7024 cmdline_parse_token_string_t cmd_lfc_set_rx =
7025         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7026                                 rx, "rx");
7027 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7028         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7029                                 rx_lfc_mode, "on#off");
7030 cmdline_parse_token_string_t cmd_lfc_set_tx =
7031         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7032                                 tx, "tx");
7033 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7034         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7035                                 tx_lfc_mode, "on#off");
7036 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7037         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7038                                 hw_str, "high_water");
7039 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7040         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7041                                 high_water, UINT32);
7042 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7043         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7044                                 lw_str, "low_water");
7045 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7046         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7047                                 low_water, UINT32);
7048 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7049         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7050                                 pt_str, "pause_time");
7051 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7052         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7053                                 pause_time, UINT16);
7054 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7055         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7056                                 xon_str, "send_xon");
7057 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7058         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7059                                 send_xon, UINT16);
7060 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7061         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7062                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7063 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7064         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7065                                 mac_ctrl_frame_fwd_mode, "on#off");
7066 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7067         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7068                                 autoneg_str, "autoneg");
7069 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7070         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7071                                 autoneg, "on#off");
7072 cmdline_parse_token_num_t cmd_lfc_set_portid =
7073         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7074                                 port_id, UINT16);
7075
7076 /* forward declaration */
7077 static void
7078 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7079                               void *data);
7080
7081 cmdline_parse_inst_t cmd_link_flow_control_set = {
7082         .f = cmd_link_flow_ctrl_set_parsed,
7083         .data = NULL,
7084         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7085                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7086                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7087         .tokens = {
7088                 (void *)&cmd_lfc_set_set,
7089                 (void *)&cmd_lfc_set_flow_ctrl,
7090                 (void *)&cmd_lfc_set_rx,
7091                 (void *)&cmd_lfc_set_rx_mode,
7092                 (void *)&cmd_lfc_set_tx,
7093                 (void *)&cmd_lfc_set_tx_mode,
7094                 (void *)&cmd_lfc_set_high_water,
7095                 (void *)&cmd_lfc_set_low_water,
7096                 (void *)&cmd_lfc_set_pause_time,
7097                 (void *)&cmd_lfc_set_send_xon,
7098                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7099                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7100                 (void *)&cmd_lfc_set_autoneg_str,
7101                 (void *)&cmd_lfc_set_autoneg,
7102                 (void *)&cmd_lfc_set_portid,
7103                 NULL,
7104         },
7105 };
7106
7107 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7108         .f = cmd_link_flow_ctrl_set_parsed,
7109         .data = (void *)&cmd_link_flow_control_set_rx,
7110         .help_str = "set flow_ctrl rx on|off <port_id>: "
7111                 "Change rx flow control parameter",
7112         .tokens = {
7113                 (void *)&cmd_lfc_set_set,
7114                 (void *)&cmd_lfc_set_flow_ctrl,
7115                 (void *)&cmd_lfc_set_rx,
7116                 (void *)&cmd_lfc_set_rx_mode,
7117                 (void *)&cmd_lfc_set_portid,
7118                 NULL,
7119         },
7120 };
7121
7122 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7123         .f = cmd_link_flow_ctrl_set_parsed,
7124         .data = (void *)&cmd_link_flow_control_set_tx,
7125         .help_str = "set flow_ctrl tx on|off <port_id>: "
7126                 "Change tx flow control parameter",
7127         .tokens = {
7128                 (void *)&cmd_lfc_set_set,
7129                 (void *)&cmd_lfc_set_flow_ctrl,
7130                 (void *)&cmd_lfc_set_tx,
7131                 (void *)&cmd_lfc_set_tx_mode,
7132                 (void *)&cmd_lfc_set_portid,
7133                 NULL,
7134         },
7135 };
7136
7137 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7138         .f = cmd_link_flow_ctrl_set_parsed,
7139         .data = (void *)&cmd_link_flow_control_set_hw,
7140         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7141                 "Change high water flow control parameter",
7142         .tokens = {
7143                 (void *)&cmd_lfc_set_set,
7144                 (void *)&cmd_lfc_set_flow_ctrl,
7145                 (void *)&cmd_lfc_set_high_water_str,
7146                 (void *)&cmd_lfc_set_high_water,
7147                 (void *)&cmd_lfc_set_portid,
7148                 NULL,
7149         },
7150 };
7151
7152 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7153         .f = cmd_link_flow_ctrl_set_parsed,
7154         .data = (void *)&cmd_link_flow_control_set_lw,
7155         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7156                 "Change low water flow control parameter",
7157         .tokens = {
7158                 (void *)&cmd_lfc_set_set,
7159                 (void *)&cmd_lfc_set_flow_ctrl,
7160                 (void *)&cmd_lfc_set_low_water_str,
7161                 (void *)&cmd_lfc_set_low_water,
7162                 (void *)&cmd_lfc_set_portid,
7163                 NULL,
7164         },
7165 };
7166
7167 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7168         .f = cmd_link_flow_ctrl_set_parsed,
7169         .data = (void *)&cmd_link_flow_control_set_pt,
7170         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7171                 "Change pause time flow control parameter",
7172         .tokens = {
7173                 (void *)&cmd_lfc_set_set,
7174                 (void *)&cmd_lfc_set_flow_ctrl,
7175                 (void *)&cmd_lfc_set_pause_time_str,
7176                 (void *)&cmd_lfc_set_pause_time,
7177                 (void *)&cmd_lfc_set_portid,
7178                 NULL,
7179         },
7180 };
7181
7182 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7183         .f = cmd_link_flow_ctrl_set_parsed,
7184         .data = (void *)&cmd_link_flow_control_set_xon,
7185         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7186                 "Change send_xon flow control parameter",
7187         .tokens = {
7188                 (void *)&cmd_lfc_set_set,
7189                 (void *)&cmd_lfc_set_flow_ctrl,
7190                 (void *)&cmd_lfc_set_send_xon_str,
7191                 (void *)&cmd_lfc_set_send_xon,
7192                 (void *)&cmd_lfc_set_portid,
7193                 NULL,
7194         },
7195 };
7196
7197 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7198         .f = cmd_link_flow_ctrl_set_parsed,
7199         .data = (void *)&cmd_link_flow_control_set_macfwd,
7200         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7201                 "Change mac ctrl fwd flow control parameter",
7202         .tokens = {
7203                 (void *)&cmd_lfc_set_set,
7204                 (void *)&cmd_lfc_set_flow_ctrl,
7205                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7206                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7207                 (void *)&cmd_lfc_set_portid,
7208                 NULL,
7209         },
7210 };
7211
7212 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7213         .f = cmd_link_flow_ctrl_set_parsed,
7214         .data = (void *)&cmd_link_flow_control_set_autoneg,
7215         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7216                 "Change autoneg flow control parameter",
7217         .tokens = {
7218                 (void *)&cmd_lfc_set_set,
7219                 (void *)&cmd_lfc_set_flow_ctrl,
7220                 (void *)&cmd_lfc_set_autoneg_str,
7221                 (void *)&cmd_lfc_set_autoneg,
7222                 (void *)&cmd_lfc_set_portid,
7223                 NULL,
7224         },
7225 };
7226
7227 static void
7228 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7229                               __rte_unused struct cmdline *cl,
7230                               void *data)
7231 {
7232         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7233         cmdline_parse_inst_t *cmd = data;
7234         struct rte_eth_fc_conf fc_conf;
7235         int rx_fc_en = 0;
7236         int tx_fc_en = 0;
7237         int ret;
7238
7239         /*
7240          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7241          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7242          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7243          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7244          */
7245         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7246                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7247         };
7248
7249         /* Partial command line, retrieve current configuration */
7250         if (cmd) {
7251                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7252                 if (ret != 0) {
7253                         printf("cannot get current flow ctrl parameters, return"
7254                                "code = %d\n", ret);
7255                         return;
7256                 }
7257
7258                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7259                     (fc_conf.mode == RTE_FC_FULL))
7260                         rx_fc_en = 1;
7261                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7262                     (fc_conf.mode == RTE_FC_FULL))
7263                         tx_fc_en = 1;
7264         }
7265
7266         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7267                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7268
7269         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7270                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7271
7272         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7273
7274         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7275                 fc_conf.high_water = res->high_water;
7276
7277         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7278                 fc_conf.low_water = res->low_water;
7279
7280         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7281                 fc_conf.pause_time = res->pause_time;
7282
7283         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7284                 fc_conf.send_xon = res->send_xon;
7285
7286         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7287                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7288                         fc_conf.mac_ctrl_frame_fwd = 1;
7289                 else
7290                         fc_conf.mac_ctrl_frame_fwd = 0;
7291         }
7292
7293         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7294                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7295
7296         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7297         if (ret != 0)
7298                 printf("bad flow contrl parameter, return code = %d \n", ret);
7299 }
7300
7301 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7302 struct cmd_priority_flow_ctrl_set_result {
7303         cmdline_fixed_string_t set;
7304         cmdline_fixed_string_t pfc_ctrl;
7305         cmdline_fixed_string_t rx;
7306         cmdline_fixed_string_t rx_pfc_mode;
7307         cmdline_fixed_string_t tx;
7308         cmdline_fixed_string_t tx_pfc_mode;
7309         uint32_t high_water;
7310         uint32_t low_water;
7311         uint16_t pause_time;
7312         uint8_t  priority;
7313         portid_t port_id;
7314 };
7315
7316 static void
7317 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7318                        __rte_unused struct cmdline *cl,
7319                        __rte_unused void *data)
7320 {
7321         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7322         struct rte_eth_pfc_conf pfc_conf;
7323         int rx_fc_enable, tx_fc_enable;
7324         int ret;
7325
7326         /*
7327          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7328          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7329          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7330          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7331          */
7332         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7333                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7334         };
7335
7336         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7337         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7338         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7339         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7340         pfc_conf.fc.high_water = res->high_water;
7341         pfc_conf.fc.low_water  = res->low_water;
7342         pfc_conf.fc.pause_time = res->pause_time;
7343         pfc_conf.priority      = res->priority;
7344
7345         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7346         if (ret != 0)
7347                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7348 }
7349
7350 cmdline_parse_token_string_t cmd_pfc_set_set =
7351         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7352                                 set, "set");
7353 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7354         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7355                                 pfc_ctrl, "pfc_ctrl");
7356 cmdline_parse_token_string_t cmd_pfc_set_rx =
7357         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7358                                 rx, "rx");
7359 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7360         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7361                                 rx_pfc_mode, "on#off");
7362 cmdline_parse_token_string_t cmd_pfc_set_tx =
7363         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7364                                 tx, "tx");
7365 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7366         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7367                                 tx_pfc_mode, "on#off");
7368 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7369         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7370                                 high_water, UINT32);
7371 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7372         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7373                                 low_water, UINT32);
7374 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7375         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7376                                 pause_time, UINT16);
7377 cmdline_parse_token_num_t cmd_pfc_set_priority =
7378         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7379                                 priority, UINT8);
7380 cmdline_parse_token_num_t cmd_pfc_set_portid =
7381         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7382                                 port_id, UINT16);
7383
7384 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7385         .f = cmd_priority_flow_ctrl_set_parsed,
7386         .data = NULL,
7387         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7388                 "<pause_time> <priority> <port_id>: "
7389                 "Configure the Ethernet priority flow control",
7390         .tokens = {
7391                 (void *)&cmd_pfc_set_set,
7392                 (void *)&cmd_pfc_set_flow_ctrl,
7393                 (void *)&cmd_pfc_set_rx,
7394                 (void *)&cmd_pfc_set_rx_mode,
7395                 (void *)&cmd_pfc_set_tx,
7396                 (void *)&cmd_pfc_set_tx_mode,
7397                 (void *)&cmd_pfc_set_high_water,
7398                 (void *)&cmd_pfc_set_low_water,
7399                 (void *)&cmd_pfc_set_pause_time,
7400                 (void *)&cmd_pfc_set_priority,
7401                 (void *)&cmd_pfc_set_portid,
7402                 NULL,
7403         },
7404 };
7405
7406 /* *** RESET CONFIGURATION *** */
7407 struct cmd_reset_result {
7408         cmdline_fixed_string_t reset;
7409         cmdline_fixed_string_t def;
7410 };
7411
7412 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7413                              struct cmdline *cl,
7414                              __rte_unused void *data)
7415 {
7416         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7417         set_def_fwd_config();
7418 }
7419
7420 cmdline_parse_token_string_t cmd_reset_set =
7421         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7422 cmdline_parse_token_string_t cmd_reset_def =
7423         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7424                                  "default");
7425
7426 cmdline_parse_inst_t cmd_reset = {
7427         .f = cmd_reset_parsed,
7428         .data = NULL,
7429         .help_str = "set default: Reset default forwarding configuration",
7430         .tokens = {
7431                 (void *)&cmd_reset_set,
7432                 (void *)&cmd_reset_def,
7433                 NULL,
7434         },
7435 };
7436
7437 /* *** START FORWARDING *** */
7438 struct cmd_start_result {
7439         cmdline_fixed_string_t start;
7440 };
7441
7442 cmdline_parse_token_string_t cmd_start_start =
7443         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7444
7445 static void cmd_start_parsed(__rte_unused void *parsed_result,
7446                              __rte_unused struct cmdline *cl,
7447                              __rte_unused void *data)
7448 {
7449         start_packet_forwarding(0);
7450 }
7451
7452 cmdline_parse_inst_t cmd_start = {
7453         .f = cmd_start_parsed,
7454         .data = NULL,
7455         .help_str = "start: Start packet forwarding",
7456         .tokens = {
7457                 (void *)&cmd_start_start,
7458                 NULL,
7459         },
7460 };
7461
7462 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7463 struct cmd_start_tx_first_result {
7464         cmdline_fixed_string_t start;
7465         cmdline_fixed_string_t tx_first;
7466 };
7467
7468 static void
7469 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7470                           __rte_unused struct cmdline *cl,
7471                           __rte_unused void *data)
7472 {
7473         start_packet_forwarding(1);
7474 }
7475
7476 cmdline_parse_token_string_t cmd_start_tx_first_start =
7477         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7478                                  "start");
7479 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7480         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7481                                  tx_first, "tx_first");
7482
7483 cmdline_parse_inst_t cmd_start_tx_first = {
7484         .f = cmd_start_tx_first_parsed,
7485         .data = NULL,
7486         .help_str = "start tx_first: Start packet forwarding, "
7487                 "after sending 1 burst of packets",
7488         .tokens = {
7489                 (void *)&cmd_start_tx_first_start,
7490                 (void *)&cmd_start_tx_first_tx_first,
7491                 NULL,
7492         },
7493 };
7494
7495 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7496 struct cmd_start_tx_first_n_result {
7497         cmdline_fixed_string_t start;
7498         cmdline_fixed_string_t tx_first;
7499         uint32_t tx_num;
7500 };
7501
7502 static void
7503 cmd_start_tx_first_n_parsed(void *parsed_result,
7504                           __rte_unused struct cmdline *cl,
7505                           __rte_unused void *data)
7506 {
7507         struct cmd_start_tx_first_n_result *res = parsed_result;
7508
7509         start_packet_forwarding(res->tx_num);
7510 }
7511
7512 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7513         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7514                         start, "start");
7515 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7516         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7517                         tx_first, "tx_first");
7518 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7519         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7520                         tx_num, UINT32);
7521
7522 cmdline_parse_inst_t cmd_start_tx_first_n = {
7523         .f = cmd_start_tx_first_n_parsed,
7524         .data = NULL,
7525         .help_str = "start tx_first <num>: "
7526                 "packet forwarding, after sending <num> bursts of packets",
7527         .tokens = {
7528                 (void *)&cmd_start_tx_first_n_start,
7529                 (void *)&cmd_start_tx_first_n_tx_first,
7530                 (void *)&cmd_start_tx_first_n_tx_num,
7531                 NULL,
7532         },
7533 };
7534
7535 /* *** SET LINK UP *** */
7536 struct cmd_set_link_up_result {
7537         cmdline_fixed_string_t set;
7538         cmdline_fixed_string_t link_up;
7539         cmdline_fixed_string_t port;
7540         portid_t port_id;
7541 };
7542
7543 cmdline_parse_token_string_t cmd_set_link_up_set =
7544         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7545 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7546         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7547                                 "link-up");
7548 cmdline_parse_token_string_t cmd_set_link_up_port =
7549         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7550 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7551         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7552
7553 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7554                              __rte_unused struct cmdline *cl,
7555                              __rte_unused void *data)
7556 {
7557         struct cmd_set_link_up_result *res = parsed_result;
7558         dev_set_link_up(res->port_id);
7559 }
7560
7561 cmdline_parse_inst_t cmd_set_link_up = {
7562         .f = cmd_set_link_up_parsed,
7563         .data = NULL,
7564         .help_str = "set link-up port <port id>",
7565         .tokens = {
7566                 (void *)&cmd_set_link_up_set,
7567                 (void *)&cmd_set_link_up_link_up,
7568                 (void *)&cmd_set_link_up_port,
7569                 (void *)&cmd_set_link_up_port_id,
7570                 NULL,
7571         },
7572 };
7573
7574 /* *** SET LINK DOWN *** */
7575 struct cmd_set_link_down_result {
7576         cmdline_fixed_string_t set;
7577         cmdline_fixed_string_t link_down;
7578         cmdline_fixed_string_t port;
7579         portid_t port_id;
7580 };
7581
7582 cmdline_parse_token_string_t cmd_set_link_down_set =
7583         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7584 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7585         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7586                                 "link-down");
7587 cmdline_parse_token_string_t cmd_set_link_down_port =
7588         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7589 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7590         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7591
7592 static void cmd_set_link_down_parsed(
7593                                 __rte_unused void *parsed_result,
7594                                 __rte_unused struct cmdline *cl,
7595                                 __rte_unused void *data)
7596 {
7597         struct cmd_set_link_down_result *res = parsed_result;
7598         dev_set_link_down(res->port_id);
7599 }
7600
7601 cmdline_parse_inst_t cmd_set_link_down = {
7602         .f = cmd_set_link_down_parsed,
7603         .data = NULL,
7604         .help_str = "set link-down port <port id>",
7605         .tokens = {
7606                 (void *)&cmd_set_link_down_set,
7607                 (void *)&cmd_set_link_down_link_down,
7608                 (void *)&cmd_set_link_down_port,
7609                 (void *)&cmd_set_link_down_port_id,
7610                 NULL,
7611         },
7612 };
7613
7614 /* *** SHOW CFG *** */
7615 struct cmd_showcfg_result {
7616         cmdline_fixed_string_t show;
7617         cmdline_fixed_string_t cfg;
7618         cmdline_fixed_string_t what;
7619 };
7620
7621 static void cmd_showcfg_parsed(void *parsed_result,
7622                                __rte_unused struct cmdline *cl,
7623                                __rte_unused void *data)
7624 {
7625         struct cmd_showcfg_result *res = parsed_result;
7626         if (!strcmp(res->what, "rxtx"))
7627                 rxtx_config_display();
7628         else if (!strcmp(res->what, "cores"))
7629                 fwd_lcores_config_display();
7630         else if (!strcmp(res->what, "fwd"))
7631                 pkt_fwd_config_display(&cur_fwd_config);
7632         else if (!strcmp(res->what, "rxoffs"))
7633                 show_rx_pkt_offsets();
7634         else if (!strcmp(res->what, "rxpkts"))
7635                 show_rx_pkt_segments();
7636         else if (!strcmp(res->what, "txpkts"))
7637                 show_tx_pkt_segments();
7638         else if (!strcmp(res->what, "txtimes"))
7639                 show_tx_pkt_times();
7640 }
7641
7642 cmdline_parse_token_string_t cmd_showcfg_show =
7643         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7644 cmdline_parse_token_string_t cmd_showcfg_port =
7645         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7646 cmdline_parse_token_string_t cmd_showcfg_what =
7647         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7648                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7649
7650 cmdline_parse_inst_t cmd_showcfg = {
7651         .f = cmd_showcfg_parsed,
7652         .data = NULL,
7653         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7654         .tokens = {
7655                 (void *)&cmd_showcfg_show,
7656                 (void *)&cmd_showcfg_port,
7657                 (void *)&cmd_showcfg_what,
7658                 NULL,
7659         },
7660 };
7661
7662 /* *** SHOW ALL PORT INFO *** */
7663 struct cmd_showportall_result {
7664         cmdline_fixed_string_t show;
7665         cmdline_fixed_string_t port;
7666         cmdline_fixed_string_t what;
7667         cmdline_fixed_string_t all;
7668 };
7669
7670 static void cmd_showportall_parsed(void *parsed_result,
7671                                 __rte_unused struct cmdline *cl,
7672                                 __rte_unused void *data)
7673 {
7674         portid_t i;
7675
7676         struct cmd_showportall_result *res = parsed_result;
7677         if (!strcmp(res->show, "clear")) {
7678                 if (!strcmp(res->what, "stats"))
7679                         RTE_ETH_FOREACH_DEV(i)
7680                                 nic_stats_clear(i);
7681                 else if (!strcmp(res->what, "xstats"))
7682                         RTE_ETH_FOREACH_DEV(i)
7683                                 nic_xstats_clear(i);
7684         } else if (!strcmp(res->what, "info"))
7685                 RTE_ETH_FOREACH_DEV(i)
7686                         port_infos_display(i);
7687         else if (!strcmp(res->what, "summary")) {
7688                 port_summary_header_display();
7689                 RTE_ETH_FOREACH_DEV(i)
7690                         port_summary_display(i);
7691         }
7692         else if (!strcmp(res->what, "stats"))
7693                 RTE_ETH_FOREACH_DEV(i)
7694                         nic_stats_display(i);
7695         else if (!strcmp(res->what, "xstats"))
7696                 RTE_ETH_FOREACH_DEV(i)
7697                         nic_xstats_display(i);
7698         else if (!strcmp(res->what, "fdir"))
7699                 RTE_ETH_FOREACH_DEV(i)
7700                         fdir_get_infos(i);
7701         else if (!strcmp(res->what, "stat_qmap"))
7702                 RTE_ETH_FOREACH_DEV(i)
7703                         nic_stats_mapping_display(i);
7704         else if (!strcmp(res->what, "dcb_tc"))
7705                 RTE_ETH_FOREACH_DEV(i)
7706                         port_dcb_info_display(i);
7707         else if (!strcmp(res->what, "cap"))
7708                 RTE_ETH_FOREACH_DEV(i)
7709                         port_offload_cap_display(i);
7710 }
7711
7712 cmdline_parse_token_string_t cmd_showportall_show =
7713         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7714                                  "show#clear");
7715 cmdline_parse_token_string_t cmd_showportall_port =
7716         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7717 cmdline_parse_token_string_t cmd_showportall_what =
7718         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7719                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7720 cmdline_parse_token_string_t cmd_showportall_all =
7721         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7722 cmdline_parse_inst_t cmd_showportall = {
7723         .f = cmd_showportall_parsed,
7724         .data = NULL,
7725         .help_str = "show|clear port "
7726                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7727         .tokens = {
7728                 (void *)&cmd_showportall_show,
7729                 (void *)&cmd_showportall_port,
7730                 (void *)&cmd_showportall_what,
7731                 (void *)&cmd_showportall_all,
7732                 NULL,
7733         },
7734 };
7735
7736 /* *** SHOW PORT INFO *** */
7737 struct cmd_showport_result {
7738         cmdline_fixed_string_t show;
7739         cmdline_fixed_string_t port;
7740         cmdline_fixed_string_t what;
7741         uint16_t portnum;
7742 };
7743
7744 static void cmd_showport_parsed(void *parsed_result,
7745                                 __rte_unused struct cmdline *cl,
7746                                 __rte_unused void *data)
7747 {
7748         struct cmd_showport_result *res = parsed_result;
7749         if (!strcmp(res->show, "clear")) {
7750                 if (!strcmp(res->what, "stats"))
7751                         nic_stats_clear(res->portnum);
7752                 else if (!strcmp(res->what, "xstats"))
7753                         nic_xstats_clear(res->portnum);
7754         } else if (!strcmp(res->what, "info"))
7755                 port_infos_display(res->portnum);
7756         else if (!strcmp(res->what, "summary")) {
7757                 port_summary_header_display();
7758                 port_summary_display(res->portnum);
7759         }
7760         else if (!strcmp(res->what, "stats"))
7761                 nic_stats_display(res->portnum);
7762         else if (!strcmp(res->what, "xstats"))
7763                 nic_xstats_display(res->portnum);
7764         else if (!strcmp(res->what, "fdir"))
7765                  fdir_get_infos(res->portnum);
7766         else if (!strcmp(res->what, "stat_qmap"))
7767                 nic_stats_mapping_display(res->portnum);
7768         else if (!strcmp(res->what, "dcb_tc"))
7769                 port_dcb_info_display(res->portnum);
7770         else if (!strcmp(res->what, "cap"))
7771                 port_offload_cap_display(res->portnum);
7772 }
7773
7774 cmdline_parse_token_string_t cmd_showport_show =
7775         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7776                                  "show#clear");
7777 cmdline_parse_token_string_t cmd_showport_port =
7778         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7779 cmdline_parse_token_string_t cmd_showport_what =
7780         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7781                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7782 cmdline_parse_token_num_t cmd_showport_portnum =
7783         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7784
7785 cmdline_parse_inst_t cmd_showport = {
7786         .f = cmd_showport_parsed,
7787         .data = NULL,
7788         .help_str = "show|clear port "
7789                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7790                 "<port_id>",
7791         .tokens = {
7792                 (void *)&cmd_showport_show,
7793                 (void *)&cmd_showport_port,
7794                 (void *)&cmd_showport_what,
7795                 (void *)&cmd_showport_portnum,
7796                 NULL,
7797         },
7798 };
7799
7800 /* *** SHOW DEVICE INFO *** */
7801 struct cmd_showdevice_result {
7802         cmdline_fixed_string_t show;
7803         cmdline_fixed_string_t device;
7804         cmdline_fixed_string_t what;
7805         cmdline_fixed_string_t identifier;
7806 };
7807
7808 static void cmd_showdevice_parsed(void *parsed_result,
7809                                 __rte_unused struct cmdline *cl,
7810                                 __rte_unused void *data)
7811 {
7812         struct cmd_showdevice_result *res = parsed_result;
7813         if (!strcmp(res->what, "info")) {
7814                 if (!strcmp(res->identifier, "all"))
7815                         device_infos_display(NULL);
7816                 else
7817                         device_infos_display(res->identifier);
7818         }
7819 }
7820
7821 cmdline_parse_token_string_t cmd_showdevice_show =
7822         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7823                                  "show");
7824 cmdline_parse_token_string_t cmd_showdevice_device =
7825         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7826 cmdline_parse_token_string_t cmd_showdevice_what =
7827         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7828                                  "info");
7829 cmdline_parse_token_string_t cmd_showdevice_identifier =
7830         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7831                         identifier, NULL);
7832
7833 cmdline_parse_inst_t cmd_showdevice = {
7834         .f = cmd_showdevice_parsed,
7835         .data = NULL,
7836         .help_str = "show device info <identifier>|all",
7837         .tokens = {
7838                 (void *)&cmd_showdevice_show,
7839                 (void *)&cmd_showdevice_device,
7840                 (void *)&cmd_showdevice_what,
7841                 (void *)&cmd_showdevice_identifier,
7842                 NULL,
7843         },
7844 };
7845
7846 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7847 struct cmd_showeeprom_result {
7848         cmdline_fixed_string_t show;
7849         cmdline_fixed_string_t port;
7850         uint16_t portnum;
7851         cmdline_fixed_string_t type;
7852 };
7853
7854 static void cmd_showeeprom_parsed(void *parsed_result,
7855                 __rte_unused struct cmdline *cl,
7856                 __rte_unused void *data)
7857 {
7858         struct cmd_showeeprom_result *res = parsed_result;
7859
7860         if (!strcmp(res->type, "eeprom"))
7861                 port_eeprom_display(res->portnum);
7862         else if (!strcmp(res->type, "module_eeprom"))
7863                 port_module_eeprom_display(res->portnum);
7864         else
7865                 printf("Unknown argument\n");
7866 }
7867
7868 cmdline_parse_token_string_t cmd_showeeprom_show =
7869         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7870 cmdline_parse_token_string_t cmd_showeeprom_port =
7871         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7872 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7873         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7874 cmdline_parse_token_string_t cmd_showeeprom_type =
7875         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7876
7877 cmdline_parse_inst_t cmd_showeeprom = {
7878         .f = cmd_showeeprom_parsed,
7879         .data = NULL,
7880         .help_str = "show port <port_id> module_eeprom|eeprom",
7881         .tokens = {
7882                 (void *)&cmd_showeeprom_show,
7883                 (void *)&cmd_showeeprom_port,
7884                 (void *)&cmd_showeeprom_portnum,
7885                 (void *)&cmd_showeeprom_type,
7886                 NULL,
7887         },
7888 };
7889
7890 /* *** SHOW QUEUE INFO *** */
7891 struct cmd_showqueue_result {
7892         cmdline_fixed_string_t show;
7893         cmdline_fixed_string_t type;
7894         cmdline_fixed_string_t what;
7895         uint16_t portnum;
7896         uint16_t queuenum;
7897 };
7898
7899 static void
7900 cmd_showqueue_parsed(void *parsed_result,
7901         __rte_unused struct cmdline *cl,
7902         __rte_unused void *data)
7903 {
7904         struct cmd_showqueue_result *res = parsed_result;
7905
7906         if (!strcmp(res->type, "rxq"))
7907                 rx_queue_infos_display(res->portnum, res->queuenum);
7908         else if (!strcmp(res->type, "txq"))
7909                 tx_queue_infos_display(res->portnum, res->queuenum);
7910 }
7911
7912 cmdline_parse_token_string_t cmd_showqueue_show =
7913         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7914 cmdline_parse_token_string_t cmd_showqueue_type =
7915         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7916 cmdline_parse_token_string_t cmd_showqueue_what =
7917         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7918 cmdline_parse_token_num_t cmd_showqueue_portnum =
7919         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7920 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7921         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7922
7923 cmdline_parse_inst_t cmd_showqueue = {
7924         .f = cmd_showqueue_parsed,
7925         .data = NULL,
7926         .help_str = "show rxq|txq info <port_id> <queue_id>",
7927         .tokens = {
7928                 (void *)&cmd_showqueue_show,
7929                 (void *)&cmd_showqueue_type,
7930                 (void *)&cmd_showqueue_what,
7931                 (void *)&cmd_showqueue_portnum,
7932                 (void *)&cmd_showqueue_queuenum,
7933                 NULL,
7934         },
7935 };
7936
7937 /* show/clear fwd engine statistics */
7938 struct fwd_result {
7939         cmdline_fixed_string_t action;
7940         cmdline_fixed_string_t fwd;
7941         cmdline_fixed_string_t stats;
7942         cmdline_fixed_string_t all;
7943 };
7944
7945 cmdline_parse_token_string_t cmd_fwd_action =
7946         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7947 cmdline_parse_token_string_t cmd_fwd_fwd =
7948         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7949 cmdline_parse_token_string_t cmd_fwd_stats =
7950         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7951 cmdline_parse_token_string_t cmd_fwd_all =
7952         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7953
7954 static void
7955 cmd_showfwdall_parsed(void *parsed_result,
7956                       __rte_unused struct cmdline *cl,
7957                       __rte_unused void *data)
7958 {
7959         struct fwd_result *res = parsed_result;
7960
7961         if (!strcmp(res->action, "show"))
7962                 fwd_stats_display();
7963         else
7964                 fwd_stats_reset();
7965 }
7966
7967 static cmdline_parse_inst_t cmd_showfwdall = {
7968         .f = cmd_showfwdall_parsed,
7969         .data = NULL,
7970         .help_str = "show|clear fwd stats all",
7971         .tokens = {
7972                 (void *)&cmd_fwd_action,
7973                 (void *)&cmd_fwd_fwd,
7974                 (void *)&cmd_fwd_stats,
7975                 (void *)&cmd_fwd_all,
7976                 NULL,
7977         },
7978 };
7979
7980 /* *** READ PORT REGISTER *** */
7981 struct cmd_read_reg_result {
7982         cmdline_fixed_string_t read;
7983         cmdline_fixed_string_t reg;
7984         portid_t port_id;
7985         uint32_t reg_off;
7986 };
7987
7988 static void
7989 cmd_read_reg_parsed(void *parsed_result,
7990                     __rte_unused struct cmdline *cl,
7991                     __rte_unused void *data)
7992 {
7993         struct cmd_read_reg_result *res = parsed_result;
7994         port_reg_display(res->port_id, res->reg_off);
7995 }
7996
7997 cmdline_parse_token_string_t cmd_read_reg_read =
7998         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7999 cmdline_parse_token_string_t cmd_read_reg_reg =
8000         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8001 cmdline_parse_token_num_t cmd_read_reg_port_id =
8002         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
8003 cmdline_parse_token_num_t cmd_read_reg_reg_off =
8004         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
8005
8006 cmdline_parse_inst_t cmd_read_reg = {
8007         .f = cmd_read_reg_parsed,
8008         .data = NULL,
8009         .help_str = "read reg <port_id> <reg_off>",
8010         .tokens = {
8011                 (void *)&cmd_read_reg_read,
8012                 (void *)&cmd_read_reg_reg,
8013                 (void *)&cmd_read_reg_port_id,
8014                 (void *)&cmd_read_reg_reg_off,
8015                 NULL,
8016         },
8017 };
8018
8019 /* *** READ PORT REGISTER BIT FIELD *** */
8020 struct cmd_read_reg_bit_field_result {
8021         cmdline_fixed_string_t read;
8022         cmdline_fixed_string_t regfield;
8023         portid_t port_id;
8024         uint32_t reg_off;
8025         uint8_t bit1_pos;
8026         uint8_t bit2_pos;
8027 };
8028
8029 static void
8030 cmd_read_reg_bit_field_parsed(void *parsed_result,
8031                               __rte_unused struct cmdline *cl,
8032                               __rte_unused void *data)
8033 {
8034         struct cmd_read_reg_bit_field_result *res = parsed_result;
8035         port_reg_bit_field_display(res->port_id, res->reg_off,
8036                                    res->bit1_pos, res->bit2_pos);
8037 }
8038
8039 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8040         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8041                                  "read");
8042 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8043         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8044                                  regfield, "regfield");
8045 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8046         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8047                               UINT16);
8048 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8049         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8050                               UINT32);
8051 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8052         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8053                               UINT8);
8054 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8055         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8056                               UINT8);
8057
8058 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8059         .f = cmd_read_reg_bit_field_parsed,
8060         .data = NULL,
8061         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8062         "Read register bit field between bit_x and bit_y included",
8063         .tokens = {
8064                 (void *)&cmd_read_reg_bit_field_read,
8065                 (void *)&cmd_read_reg_bit_field_regfield,
8066                 (void *)&cmd_read_reg_bit_field_port_id,
8067                 (void *)&cmd_read_reg_bit_field_reg_off,
8068                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8069                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8070                 NULL,
8071         },
8072 };
8073
8074 /* *** READ PORT REGISTER BIT *** */
8075 struct cmd_read_reg_bit_result {
8076         cmdline_fixed_string_t read;
8077         cmdline_fixed_string_t regbit;
8078         portid_t port_id;
8079         uint32_t reg_off;
8080         uint8_t bit_pos;
8081 };
8082
8083 static void
8084 cmd_read_reg_bit_parsed(void *parsed_result,
8085                         __rte_unused struct cmdline *cl,
8086                         __rte_unused void *data)
8087 {
8088         struct cmd_read_reg_bit_result *res = parsed_result;
8089         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8090 }
8091
8092 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8093         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8094 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8095         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8096                                  regbit, "regbit");
8097 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8098         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
8099 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8100         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
8101 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8102         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
8103
8104 cmdline_parse_inst_t cmd_read_reg_bit = {
8105         .f = cmd_read_reg_bit_parsed,
8106         .data = NULL,
8107         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8108         .tokens = {
8109                 (void *)&cmd_read_reg_bit_read,
8110                 (void *)&cmd_read_reg_bit_regbit,
8111                 (void *)&cmd_read_reg_bit_port_id,
8112                 (void *)&cmd_read_reg_bit_reg_off,
8113                 (void *)&cmd_read_reg_bit_bit_pos,
8114                 NULL,
8115         },
8116 };
8117
8118 /* *** WRITE PORT REGISTER *** */
8119 struct cmd_write_reg_result {
8120         cmdline_fixed_string_t write;
8121         cmdline_fixed_string_t reg;
8122         portid_t port_id;
8123         uint32_t reg_off;
8124         uint32_t value;
8125 };
8126
8127 static void
8128 cmd_write_reg_parsed(void *parsed_result,
8129                      __rte_unused struct cmdline *cl,
8130                      __rte_unused void *data)
8131 {
8132         struct cmd_write_reg_result *res = parsed_result;
8133         port_reg_set(res->port_id, res->reg_off, res->value);
8134 }
8135
8136 cmdline_parse_token_string_t cmd_write_reg_write =
8137         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8138 cmdline_parse_token_string_t cmd_write_reg_reg =
8139         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8140 cmdline_parse_token_num_t cmd_write_reg_port_id =
8141         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
8142 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8143         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
8144 cmdline_parse_token_num_t cmd_write_reg_value =
8145         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
8146
8147 cmdline_parse_inst_t cmd_write_reg = {
8148         .f = cmd_write_reg_parsed,
8149         .data = NULL,
8150         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8151         .tokens = {
8152                 (void *)&cmd_write_reg_write,
8153                 (void *)&cmd_write_reg_reg,
8154                 (void *)&cmd_write_reg_port_id,
8155                 (void *)&cmd_write_reg_reg_off,
8156                 (void *)&cmd_write_reg_value,
8157                 NULL,
8158         },
8159 };
8160
8161 /* *** WRITE PORT REGISTER BIT FIELD *** */
8162 struct cmd_write_reg_bit_field_result {
8163         cmdline_fixed_string_t write;
8164         cmdline_fixed_string_t regfield;
8165         portid_t port_id;
8166         uint32_t reg_off;
8167         uint8_t bit1_pos;
8168         uint8_t bit2_pos;
8169         uint32_t value;
8170 };
8171
8172 static void
8173 cmd_write_reg_bit_field_parsed(void *parsed_result,
8174                                __rte_unused struct cmdline *cl,
8175                                __rte_unused void *data)
8176 {
8177         struct cmd_write_reg_bit_field_result *res = parsed_result;
8178         port_reg_bit_field_set(res->port_id, res->reg_off,
8179                           res->bit1_pos, res->bit2_pos, res->value);
8180 }
8181
8182 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8183         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8184                                  "write");
8185 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8186         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8187                                  regfield, "regfield");
8188 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8189         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8190                               UINT16);
8191 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8192         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8193                               UINT32);
8194 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8195         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8196                               UINT8);
8197 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8198         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8199                               UINT8);
8200 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8201         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8202                               UINT32);
8203
8204 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8205         .f = cmd_write_reg_bit_field_parsed,
8206         .data = NULL,
8207         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8208                 "<reg_value>: "
8209                 "Set register bit field between bit_x and bit_y included",
8210         .tokens = {
8211                 (void *)&cmd_write_reg_bit_field_write,
8212                 (void *)&cmd_write_reg_bit_field_regfield,
8213                 (void *)&cmd_write_reg_bit_field_port_id,
8214                 (void *)&cmd_write_reg_bit_field_reg_off,
8215                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8216                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8217                 (void *)&cmd_write_reg_bit_field_value,
8218                 NULL,
8219         },
8220 };
8221
8222 /* *** WRITE PORT REGISTER BIT *** */
8223 struct cmd_write_reg_bit_result {
8224         cmdline_fixed_string_t write;
8225         cmdline_fixed_string_t regbit;
8226         portid_t port_id;
8227         uint32_t reg_off;
8228         uint8_t bit_pos;
8229         uint8_t value;
8230 };
8231
8232 static void
8233 cmd_write_reg_bit_parsed(void *parsed_result,
8234                          __rte_unused struct cmdline *cl,
8235                          __rte_unused void *data)
8236 {
8237         struct cmd_write_reg_bit_result *res = parsed_result;
8238         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8239 }
8240
8241 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8242         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8243                                  "write");
8244 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8245         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8246                                  regbit, "regbit");
8247 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8248         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8249 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8250         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8251 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8252         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8253 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8254         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8255
8256 cmdline_parse_inst_t cmd_write_reg_bit = {
8257         .f = cmd_write_reg_bit_parsed,
8258         .data = NULL,
8259         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8260                 "0 <= bit_x <= 31",
8261         .tokens = {
8262                 (void *)&cmd_write_reg_bit_write,
8263                 (void *)&cmd_write_reg_bit_regbit,
8264                 (void *)&cmd_write_reg_bit_port_id,
8265                 (void *)&cmd_write_reg_bit_reg_off,
8266                 (void *)&cmd_write_reg_bit_bit_pos,
8267                 (void *)&cmd_write_reg_bit_value,
8268                 NULL,
8269         },
8270 };
8271
8272 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8273 struct cmd_read_rxd_txd_result {
8274         cmdline_fixed_string_t read;
8275         cmdline_fixed_string_t rxd_txd;
8276         portid_t port_id;
8277         uint16_t queue_id;
8278         uint16_t desc_id;
8279 };
8280
8281 static void
8282 cmd_read_rxd_txd_parsed(void *parsed_result,
8283                         __rte_unused struct cmdline *cl,
8284                         __rte_unused void *data)
8285 {
8286         struct cmd_read_rxd_txd_result *res = parsed_result;
8287
8288         if (!strcmp(res->rxd_txd, "rxd"))
8289                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8290         else if (!strcmp(res->rxd_txd, "txd"))
8291                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8292 }
8293
8294 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8295         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8296 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8297         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8298                                  "rxd#txd");
8299 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8300         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8301 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8302         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8303 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8304         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8305
8306 cmdline_parse_inst_t cmd_read_rxd_txd = {
8307         .f = cmd_read_rxd_txd_parsed,
8308         .data = NULL,
8309         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8310         .tokens = {
8311                 (void *)&cmd_read_rxd_txd_read,
8312                 (void *)&cmd_read_rxd_txd_rxd_txd,
8313                 (void *)&cmd_read_rxd_txd_port_id,
8314                 (void *)&cmd_read_rxd_txd_queue_id,
8315                 (void *)&cmd_read_rxd_txd_desc_id,
8316                 NULL,
8317         },
8318 };
8319
8320 /* *** QUIT *** */
8321 struct cmd_quit_result {
8322         cmdline_fixed_string_t quit;
8323 };
8324
8325 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8326                             struct cmdline *cl,
8327                             __rte_unused void *data)
8328 {
8329         cmdline_quit(cl);
8330 }
8331
8332 cmdline_parse_token_string_t cmd_quit_quit =
8333         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8334
8335 cmdline_parse_inst_t cmd_quit = {
8336         .f = cmd_quit_parsed,
8337         .data = NULL,
8338         .help_str = "quit: Exit application",
8339         .tokens = {
8340                 (void *)&cmd_quit_quit,
8341                 NULL,
8342         },
8343 };
8344
8345 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8346 struct cmd_mac_addr_result {
8347         cmdline_fixed_string_t mac_addr_cmd;
8348         cmdline_fixed_string_t what;
8349         uint16_t port_num;
8350         struct rte_ether_addr address;
8351 };
8352
8353 static void cmd_mac_addr_parsed(void *parsed_result,
8354                 __rte_unused struct cmdline *cl,
8355                 __rte_unused void *data)
8356 {
8357         struct cmd_mac_addr_result *res = parsed_result;
8358         int ret;
8359
8360         if (strcmp(res->what, "add") == 0)
8361                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8362         else if (strcmp(res->what, "set") == 0)
8363                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8364                                                        &res->address);
8365         else
8366                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8367
8368         /* check the return value and print it if is < 0 */
8369         if(ret < 0)
8370                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8371
8372 }
8373
8374 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8375         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8376                                 "mac_addr");
8377 cmdline_parse_token_string_t cmd_mac_addr_what =
8378         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8379                                 "add#remove#set");
8380 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8381                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8382                                         UINT16);
8383 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8384                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8385
8386 cmdline_parse_inst_t cmd_mac_addr = {
8387         .f = cmd_mac_addr_parsed,
8388         .data = (void *)0,
8389         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8390                         "Add/Remove/Set MAC address on port_id",
8391         .tokens = {
8392                 (void *)&cmd_mac_addr_cmd,
8393                 (void *)&cmd_mac_addr_what,
8394                 (void *)&cmd_mac_addr_portnum,
8395                 (void *)&cmd_mac_addr_addr,
8396                 NULL,
8397         },
8398 };
8399
8400 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8401 struct cmd_eth_peer_result {
8402         cmdline_fixed_string_t set;
8403         cmdline_fixed_string_t eth_peer;
8404         portid_t port_id;
8405         cmdline_fixed_string_t peer_addr;
8406 };
8407
8408 static void cmd_set_eth_peer_parsed(void *parsed_result,
8409                         __rte_unused struct cmdline *cl,
8410                         __rte_unused void *data)
8411 {
8412                 struct cmd_eth_peer_result *res = parsed_result;
8413
8414                 if (test_done == 0) {
8415                         printf("Please stop forwarding first\n");
8416                         return;
8417                 }
8418                 if (!strcmp(res->eth_peer, "eth-peer")) {
8419                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8420                         fwd_config_setup();
8421                 }
8422 }
8423 cmdline_parse_token_string_t cmd_eth_peer_set =
8424         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8425 cmdline_parse_token_string_t cmd_eth_peer =
8426         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8427 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8428         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8429 cmdline_parse_token_string_t cmd_eth_peer_addr =
8430         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8431
8432 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8433         .f = cmd_set_eth_peer_parsed,
8434         .data = NULL,
8435         .help_str = "set eth-peer <port_id> <peer_mac>",
8436         .tokens = {
8437                 (void *)&cmd_eth_peer_set,
8438                 (void *)&cmd_eth_peer,
8439                 (void *)&cmd_eth_peer_port_id,
8440                 (void *)&cmd_eth_peer_addr,
8441                 NULL,
8442         },
8443 };
8444
8445 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8446 struct cmd_set_qmap_result {
8447         cmdline_fixed_string_t set;
8448         cmdline_fixed_string_t qmap;
8449         cmdline_fixed_string_t what;
8450         portid_t port_id;
8451         uint16_t queue_id;
8452         uint8_t map_value;
8453 };
8454
8455 static void
8456 cmd_set_qmap_parsed(void *parsed_result,
8457                        __rte_unused struct cmdline *cl,
8458                        __rte_unused void *data)
8459 {
8460         struct cmd_set_qmap_result *res = parsed_result;
8461         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8462
8463         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8464 }
8465
8466 cmdline_parse_token_string_t cmd_setqmap_set =
8467         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8468                                  set, "set");
8469 cmdline_parse_token_string_t cmd_setqmap_qmap =
8470         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8471                                  qmap, "stat_qmap");
8472 cmdline_parse_token_string_t cmd_setqmap_what =
8473         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8474                                  what, "tx#rx");
8475 cmdline_parse_token_num_t cmd_setqmap_portid =
8476         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8477                               port_id, UINT16);
8478 cmdline_parse_token_num_t cmd_setqmap_queueid =
8479         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8480                               queue_id, UINT16);
8481 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8482         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8483                               map_value, UINT8);
8484
8485 cmdline_parse_inst_t cmd_set_qmap = {
8486         .f = cmd_set_qmap_parsed,
8487         .data = NULL,
8488         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8489                 "Set statistics mapping value on tx|rx queue_id of port_id",
8490         .tokens = {
8491                 (void *)&cmd_setqmap_set,
8492                 (void *)&cmd_setqmap_qmap,
8493                 (void *)&cmd_setqmap_what,
8494                 (void *)&cmd_setqmap_portid,
8495                 (void *)&cmd_setqmap_queueid,
8496                 (void *)&cmd_setqmap_mapvalue,
8497                 NULL,
8498         },
8499 };
8500
8501 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8502 struct cmd_set_xstats_hide_zero_result {
8503         cmdline_fixed_string_t keyword;
8504         cmdline_fixed_string_t name;
8505         cmdline_fixed_string_t on_off;
8506 };
8507
8508 static void
8509 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8510                         __rte_unused struct cmdline *cl,
8511                         __rte_unused void *data)
8512 {
8513         struct cmd_set_xstats_hide_zero_result *res;
8514         uint16_t on_off = 0;
8515
8516         res = parsed_result;
8517         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8518         set_xstats_hide_zero(on_off);
8519 }
8520
8521 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8522         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8523                                  keyword, "set");
8524 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8525         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8526                                  name, "xstats-hide-zero");
8527 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8528         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8529                                  on_off, "on#off");
8530
8531 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8532         .f = cmd_set_xstats_hide_zero_parsed,
8533         .data = NULL,
8534         .help_str = "set xstats-hide-zero on|off",
8535         .tokens = {
8536                 (void *)&cmd_set_xstats_hide_zero_keyword,
8537                 (void *)&cmd_set_xstats_hide_zero_name,
8538                 (void *)&cmd_set_xstats_hide_zero_on_off,
8539                 NULL,
8540         },
8541 };
8542
8543 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8544 struct cmd_set_record_core_cycles_result {
8545         cmdline_fixed_string_t keyword;
8546         cmdline_fixed_string_t name;
8547         cmdline_fixed_string_t on_off;
8548 };
8549
8550 static void
8551 cmd_set_record_core_cycles_parsed(void *parsed_result,
8552                         __rte_unused struct cmdline *cl,
8553                         __rte_unused void *data)
8554 {
8555         struct cmd_set_record_core_cycles_result *res;
8556         uint16_t on_off = 0;
8557
8558         res = parsed_result;
8559         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8560         set_record_core_cycles(on_off);
8561 }
8562
8563 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8564         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8565                                  keyword, "set");
8566 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8567         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8568                                  name, "record-core-cycles");
8569 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8570         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8571                                  on_off, "on#off");
8572
8573 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8574         .f = cmd_set_record_core_cycles_parsed,
8575         .data = NULL,
8576         .help_str = "set record-core-cycles on|off",
8577         .tokens = {
8578                 (void *)&cmd_set_record_core_cycles_keyword,
8579                 (void *)&cmd_set_record_core_cycles_name,
8580                 (void *)&cmd_set_record_core_cycles_on_off,
8581                 NULL,
8582         },
8583 };
8584
8585 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8586 struct cmd_set_record_burst_stats_result {
8587         cmdline_fixed_string_t keyword;
8588         cmdline_fixed_string_t name;
8589         cmdline_fixed_string_t on_off;
8590 };
8591
8592 static void
8593 cmd_set_record_burst_stats_parsed(void *parsed_result,
8594                         __rte_unused struct cmdline *cl,
8595                         __rte_unused void *data)
8596 {
8597         struct cmd_set_record_burst_stats_result *res;
8598         uint16_t on_off = 0;
8599
8600         res = parsed_result;
8601         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8602         set_record_burst_stats(on_off);
8603 }
8604
8605 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8606         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8607                                  keyword, "set");
8608 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8609         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8610                                  name, "record-burst-stats");
8611 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8612         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8613                                  on_off, "on#off");
8614
8615 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8616         .f = cmd_set_record_burst_stats_parsed,
8617         .data = NULL,
8618         .help_str = "set record-burst-stats on|off",
8619         .tokens = {
8620                 (void *)&cmd_set_record_burst_stats_keyword,
8621                 (void *)&cmd_set_record_burst_stats_name,
8622                 (void *)&cmd_set_record_burst_stats_on_off,
8623                 NULL,
8624         },
8625 };
8626
8627 /* *** CONFIGURE UNICAST HASH TABLE *** */
8628 struct cmd_set_uc_hash_table {
8629         cmdline_fixed_string_t set;
8630         cmdline_fixed_string_t port;
8631         portid_t port_id;
8632         cmdline_fixed_string_t what;
8633         struct rte_ether_addr address;
8634         cmdline_fixed_string_t mode;
8635 };
8636
8637 static void
8638 cmd_set_uc_hash_parsed(void *parsed_result,
8639                        __rte_unused struct cmdline *cl,
8640                        __rte_unused void *data)
8641 {
8642         int ret=0;
8643         struct cmd_set_uc_hash_table *res = parsed_result;
8644
8645         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8646
8647         if (strcmp(res->what, "uta") == 0)
8648                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8649                                                 &res->address,(uint8_t)is_on);
8650         if (ret < 0)
8651                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8652
8653 }
8654
8655 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8656         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8657                                  set, "set");
8658 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8659         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8660                                  port, "port");
8661 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8662         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8663                               port_id, UINT16);
8664 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8665         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8666                                  what, "uta");
8667 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8668         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8669                                 address);
8670 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8671         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8672                                  mode, "on#off");
8673
8674 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8675         .f = cmd_set_uc_hash_parsed,
8676         .data = NULL,
8677         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8678         .tokens = {
8679                 (void *)&cmd_set_uc_hash_set,
8680                 (void *)&cmd_set_uc_hash_port,
8681                 (void *)&cmd_set_uc_hash_portid,
8682                 (void *)&cmd_set_uc_hash_what,
8683                 (void *)&cmd_set_uc_hash_mac,
8684                 (void *)&cmd_set_uc_hash_mode,
8685                 NULL,
8686         },
8687 };
8688
8689 struct cmd_set_uc_all_hash_table {
8690         cmdline_fixed_string_t set;
8691         cmdline_fixed_string_t port;
8692         portid_t port_id;
8693         cmdline_fixed_string_t what;
8694         cmdline_fixed_string_t value;
8695         cmdline_fixed_string_t mode;
8696 };
8697
8698 static void
8699 cmd_set_uc_all_hash_parsed(void *parsed_result,
8700                        __rte_unused struct cmdline *cl,
8701                        __rte_unused void *data)
8702 {
8703         int ret=0;
8704         struct cmd_set_uc_all_hash_table *res = parsed_result;
8705
8706         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8707
8708         if ((strcmp(res->what, "uta") == 0) &&
8709                 (strcmp(res->value, "all") == 0))
8710                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8711         if (ret < 0)
8712                 printf("bad unicast hash table parameter,"
8713                         "return code = %d \n", ret);
8714 }
8715
8716 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8717         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8718                                  set, "set");
8719 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8720         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8721                                  port, "port");
8722 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8723         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8724                               port_id, UINT16);
8725 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8726         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8727                                  what, "uta");
8728 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8729         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8730                                 value,"all");
8731 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8732         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8733                                  mode, "on#off");
8734
8735 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8736         .f = cmd_set_uc_all_hash_parsed,
8737         .data = NULL,
8738         .help_str = "set port <port_id> uta all on|off",
8739         .tokens = {
8740                 (void *)&cmd_set_uc_all_hash_set,
8741                 (void *)&cmd_set_uc_all_hash_port,
8742                 (void *)&cmd_set_uc_all_hash_portid,
8743                 (void *)&cmd_set_uc_all_hash_what,
8744                 (void *)&cmd_set_uc_all_hash_value,
8745                 (void *)&cmd_set_uc_all_hash_mode,
8746                 NULL,
8747         },
8748 };
8749
8750 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8751 struct cmd_set_vf_traffic {
8752         cmdline_fixed_string_t set;
8753         cmdline_fixed_string_t port;
8754         portid_t port_id;
8755         cmdline_fixed_string_t vf;
8756         uint8_t vf_id;
8757         cmdline_fixed_string_t what;
8758         cmdline_fixed_string_t mode;
8759 };
8760
8761 static void
8762 cmd_set_vf_traffic_parsed(void *parsed_result,
8763                        __rte_unused struct cmdline *cl,
8764                        __rte_unused void *data)
8765 {
8766         struct cmd_set_vf_traffic *res = parsed_result;
8767         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8768         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8769
8770         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8771 }
8772
8773 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8774         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8775                                  set, "set");
8776 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8777         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8778                                  port, "port");
8779 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8780         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8781                               port_id, UINT16);
8782 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8783         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8784                                  vf, "vf");
8785 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8786         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8787                               vf_id, UINT8);
8788 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8789         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8790                                  what, "tx#rx");
8791 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8792         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8793                                  mode, "on#off");
8794
8795 cmdline_parse_inst_t cmd_set_vf_traffic = {
8796         .f = cmd_set_vf_traffic_parsed,
8797         .data = NULL,
8798         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8799         .tokens = {
8800                 (void *)&cmd_setvf_traffic_set,
8801                 (void *)&cmd_setvf_traffic_port,
8802                 (void *)&cmd_setvf_traffic_portid,
8803                 (void *)&cmd_setvf_traffic_vf,
8804                 (void *)&cmd_setvf_traffic_vfid,
8805                 (void *)&cmd_setvf_traffic_what,
8806                 (void *)&cmd_setvf_traffic_mode,
8807                 NULL,
8808         },
8809 };
8810
8811 /* *** CONFIGURE VF RECEIVE MODE *** */
8812 struct cmd_set_vf_rxmode {
8813         cmdline_fixed_string_t set;
8814         cmdline_fixed_string_t port;
8815         portid_t port_id;
8816         cmdline_fixed_string_t vf;
8817         uint8_t vf_id;
8818         cmdline_fixed_string_t what;
8819         cmdline_fixed_string_t mode;
8820         cmdline_fixed_string_t on;
8821 };
8822
8823 static void
8824 cmd_set_vf_rxmode_parsed(void *parsed_result,
8825                        __rte_unused struct cmdline *cl,
8826                        __rte_unused void *data)
8827 {
8828         int ret = -ENOTSUP;
8829         uint16_t vf_rxmode = 0;
8830         struct cmd_set_vf_rxmode *res = parsed_result;
8831
8832         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8833         if (!strcmp(res->what,"rxmode")) {
8834                 if (!strcmp(res->mode, "AUPE"))
8835                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8836                 else if (!strcmp(res->mode, "ROPE"))
8837                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8838                 else if (!strcmp(res->mode, "BAM"))
8839                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8840                 else if (!strncmp(res->mode, "MPE",3))
8841                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8842         }
8843
8844         RTE_SET_USED(is_on);
8845
8846 #ifdef RTE_NET_IXGBE
8847         if (ret == -ENOTSUP)
8848                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8849                                                   vf_rxmode, (uint8_t)is_on);
8850 #endif
8851 #ifdef RTE_NET_BNXT
8852         if (ret == -ENOTSUP)
8853                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8854                                                  vf_rxmode, (uint8_t)is_on);
8855 #endif
8856         if (ret < 0)
8857                 printf("bad VF receive mode parameter, return code = %d \n",
8858                 ret);
8859 }
8860
8861 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8862         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8863                                  set, "set");
8864 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8865         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8866                                  port, "port");
8867 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8868         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8869                               port_id, UINT16);
8870 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8871         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8872                                  vf, "vf");
8873 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8874         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8875                               vf_id, UINT8);
8876 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8877         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8878                                  what, "rxmode");
8879 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8880         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8881                                  mode, "AUPE#ROPE#BAM#MPE");
8882 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8883         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8884                                  on, "on#off");
8885
8886 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8887         .f = cmd_set_vf_rxmode_parsed,
8888         .data = NULL,
8889         .help_str = "set port <port_id> vf <vf_id> rxmode "
8890                 "AUPE|ROPE|BAM|MPE on|off",
8891         .tokens = {
8892                 (void *)&cmd_set_vf_rxmode_set,
8893                 (void *)&cmd_set_vf_rxmode_port,
8894                 (void *)&cmd_set_vf_rxmode_portid,
8895                 (void *)&cmd_set_vf_rxmode_vf,
8896                 (void *)&cmd_set_vf_rxmode_vfid,
8897                 (void *)&cmd_set_vf_rxmode_what,
8898                 (void *)&cmd_set_vf_rxmode_mode,
8899                 (void *)&cmd_set_vf_rxmode_on,
8900                 NULL,
8901         },
8902 };
8903
8904 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8905 struct cmd_vf_mac_addr_result {
8906         cmdline_fixed_string_t mac_addr_cmd;
8907         cmdline_fixed_string_t what;
8908         cmdline_fixed_string_t port;
8909         uint16_t port_num;
8910         cmdline_fixed_string_t vf;
8911         uint8_t vf_num;
8912         struct rte_ether_addr address;
8913 };
8914
8915 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8916                 __rte_unused struct cmdline *cl,
8917                 __rte_unused void *data)
8918 {
8919         struct cmd_vf_mac_addr_result *res = parsed_result;
8920         int ret = -ENOTSUP;
8921
8922         if (strcmp(res->what, "add") != 0)
8923                 return;
8924
8925 #ifdef RTE_NET_I40E
8926         if (ret == -ENOTSUP)
8927                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8928                                                    &res->address);
8929 #endif
8930 #ifdef RTE_NET_BNXT
8931         if (ret == -ENOTSUP)
8932                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8933                                                 res->vf_num);
8934 #endif
8935
8936         if(ret < 0)
8937                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8938
8939 }
8940
8941 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8942         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8943                                 mac_addr_cmd,"mac_addr");
8944 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8945         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8946                                 what,"add");
8947 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8948         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8949                                 port,"port");
8950 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8951         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8952                                 port_num, UINT16);
8953 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8954         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8955                                 vf,"vf");
8956 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8957         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8958                                 vf_num, UINT8);
8959 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8960         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8961                                 address);
8962
8963 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8964         .f = cmd_vf_mac_addr_parsed,
8965         .data = (void *)0,
8966         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8967                 "Add MAC address filtering for a VF on port_id",
8968         .tokens = {
8969                 (void *)&cmd_vf_mac_addr_cmd,
8970                 (void *)&cmd_vf_mac_addr_what,
8971                 (void *)&cmd_vf_mac_addr_port,
8972                 (void *)&cmd_vf_mac_addr_portnum,
8973                 (void *)&cmd_vf_mac_addr_vf,
8974                 (void *)&cmd_vf_mac_addr_vfnum,
8975                 (void *)&cmd_vf_mac_addr_addr,
8976                 NULL,
8977         },
8978 };
8979
8980 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8981 struct cmd_vf_rx_vlan_filter {
8982         cmdline_fixed_string_t rx_vlan;
8983         cmdline_fixed_string_t what;
8984         uint16_t vlan_id;
8985         cmdline_fixed_string_t port;
8986         portid_t port_id;
8987         cmdline_fixed_string_t vf;
8988         uint64_t vf_mask;
8989 };
8990
8991 static void
8992 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8993                           __rte_unused struct cmdline *cl,
8994                           __rte_unused void *data)
8995 {
8996         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8997         int ret = -ENOTSUP;
8998
8999         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9000
9001 #ifdef RTE_NET_IXGBE
9002         if (ret == -ENOTSUP)
9003                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9004                                 res->vlan_id, res->vf_mask, is_add);
9005 #endif
9006 #ifdef RTE_NET_I40E
9007         if (ret == -ENOTSUP)
9008                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9009                                 res->vlan_id, res->vf_mask, is_add);
9010 #endif
9011 #ifdef RTE_NET_BNXT
9012         if (ret == -ENOTSUP)
9013                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9014                                 res->vlan_id, res->vf_mask, is_add);
9015 #endif
9016
9017         switch (ret) {
9018         case 0:
9019                 break;
9020         case -EINVAL:
9021                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
9022                                 res->vlan_id, res->vf_mask);
9023                 break;
9024         case -ENODEV:
9025                 printf("invalid port_id %d\n", res->port_id);
9026                 break;
9027         case -ENOTSUP:
9028                 printf("function not implemented or supported\n");
9029                 break;
9030         default:
9031                 printf("programming error: (%s)\n", strerror(-ret));
9032         }
9033 }
9034
9035 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9036         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9037                                  rx_vlan, "rx_vlan");
9038 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9039         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9040                                  what, "add#rm");
9041 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9042         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9043                               vlan_id, UINT16);
9044 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9045         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9046                                  port, "port");
9047 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9048         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9049                               port_id, UINT16);
9050 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9051         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9052                                  vf, "vf");
9053 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9054         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9055                               vf_mask, UINT64);
9056
9057 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9058         .f = cmd_vf_rx_vlan_filter_parsed,
9059         .data = NULL,
9060         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9061                 "(vf_mask = hexadecimal VF mask)",
9062         .tokens = {
9063                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9064                 (void *)&cmd_vf_rx_vlan_filter_what,
9065                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9066                 (void *)&cmd_vf_rx_vlan_filter_port,
9067                 (void *)&cmd_vf_rx_vlan_filter_portid,
9068                 (void *)&cmd_vf_rx_vlan_filter_vf,
9069                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9070                 NULL,
9071         },
9072 };
9073
9074 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9075 struct cmd_queue_rate_limit_result {
9076         cmdline_fixed_string_t set;
9077         cmdline_fixed_string_t port;
9078         uint16_t port_num;
9079         cmdline_fixed_string_t queue;
9080         uint8_t queue_num;
9081         cmdline_fixed_string_t rate;
9082         uint16_t rate_num;
9083 };
9084
9085 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9086                 __rte_unused struct cmdline *cl,
9087                 __rte_unused void *data)
9088 {
9089         struct cmd_queue_rate_limit_result *res = parsed_result;
9090         int ret = 0;
9091
9092         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9093                 && (strcmp(res->queue, "queue") == 0)
9094                 && (strcmp(res->rate, "rate") == 0))
9095                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9096                                         res->rate_num);
9097         if (ret < 0)
9098                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9099
9100 }
9101
9102 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9103         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9104                                 set, "set");
9105 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9106         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9107                                 port, "port");
9108 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9109         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9110                                 port_num, UINT16);
9111 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9112         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9113                                 queue, "queue");
9114 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9115         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9116                                 queue_num, UINT8);
9117 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9118         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9119                                 rate, "rate");
9120 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9121         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9122                                 rate_num, UINT16);
9123
9124 cmdline_parse_inst_t cmd_queue_rate_limit = {
9125         .f = cmd_queue_rate_limit_parsed,
9126         .data = (void *)0,
9127         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9128                 "Set rate limit for a queue on port_id",
9129         .tokens = {
9130                 (void *)&cmd_queue_rate_limit_set,
9131                 (void *)&cmd_queue_rate_limit_port,
9132                 (void *)&cmd_queue_rate_limit_portnum,
9133                 (void *)&cmd_queue_rate_limit_queue,
9134                 (void *)&cmd_queue_rate_limit_queuenum,
9135                 (void *)&cmd_queue_rate_limit_rate,
9136                 (void *)&cmd_queue_rate_limit_ratenum,
9137                 NULL,
9138         },
9139 };
9140
9141 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9142 struct cmd_vf_rate_limit_result {
9143         cmdline_fixed_string_t set;
9144         cmdline_fixed_string_t port;
9145         uint16_t port_num;
9146         cmdline_fixed_string_t vf;
9147         uint8_t vf_num;
9148         cmdline_fixed_string_t rate;
9149         uint16_t rate_num;
9150         cmdline_fixed_string_t q_msk;
9151         uint64_t q_msk_val;
9152 };
9153
9154 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9155                 __rte_unused struct cmdline *cl,
9156                 __rte_unused void *data)
9157 {
9158         struct cmd_vf_rate_limit_result *res = parsed_result;
9159         int ret = 0;
9160
9161         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9162                 && (strcmp(res->vf, "vf") == 0)
9163                 && (strcmp(res->rate, "rate") == 0)
9164                 && (strcmp(res->q_msk, "queue_mask") == 0))
9165                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9166                                         res->rate_num, res->q_msk_val);
9167         if (ret < 0)
9168                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9169
9170 }
9171
9172 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9173         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9174                                 set, "set");
9175 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9176         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9177                                 port, "port");
9178 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9179         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9180                                 port_num, UINT16);
9181 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9182         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9183                                 vf, "vf");
9184 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9185         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9186                                 vf_num, UINT8);
9187 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9188         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9189                                 rate, "rate");
9190 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9191         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9192                                 rate_num, UINT16);
9193 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9194         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9195                                 q_msk, "queue_mask");
9196 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9197         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9198                                 q_msk_val, UINT64);
9199
9200 cmdline_parse_inst_t cmd_vf_rate_limit = {
9201         .f = cmd_vf_rate_limit_parsed,
9202         .data = (void *)0,
9203         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9204                 "queue_mask <queue_mask_value>: "
9205                 "Set rate limit for queues of VF on port_id",
9206         .tokens = {
9207                 (void *)&cmd_vf_rate_limit_set,
9208                 (void *)&cmd_vf_rate_limit_port,
9209                 (void *)&cmd_vf_rate_limit_portnum,
9210                 (void *)&cmd_vf_rate_limit_vf,
9211                 (void *)&cmd_vf_rate_limit_vfnum,
9212                 (void *)&cmd_vf_rate_limit_rate,
9213                 (void *)&cmd_vf_rate_limit_ratenum,
9214                 (void *)&cmd_vf_rate_limit_q_msk,
9215                 (void *)&cmd_vf_rate_limit_q_msk_val,
9216                 NULL,
9217         },
9218 };
9219
9220 /* *** ADD TUNNEL FILTER OF A PORT *** */
9221 struct cmd_tunnel_filter_result {
9222         cmdline_fixed_string_t cmd;
9223         cmdline_fixed_string_t what;
9224         portid_t port_id;
9225         struct rte_ether_addr outer_mac;
9226         struct rte_ether_addr inner_mac;
9227         cmdline_ipaddr_t ip_value;
9228         uint16_t inner_vlan;
9229         cmdline_fixed_string_t tunnel_type;
9230         cmdline_fixed_string_t filter_type;
9231         uint32_t tenant_id;
9232         uint16_t queue_num;
9233 };
9234
9235 static void
9236 cmd_tunnel_filter_parsed(void *parsed_result,
9237                           __rte_unused struct cmdline *cl,
9238                           __rte_unused void *data)
9239 {
9240         struct cmd_tunnel_filter_result *res = parsed_result;
9241         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9242         int ret = 0;
9243
9244         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9245
9246         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9247         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9248         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9249
9250         if (res->ip_value.family == AF_INET) {
9251                 tunnel_filter_conf.ip_addr.ipv4_addr =
9252                         res->ip_value.addr.ipv4.s_addr;
9253                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9254         } else {
9255                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9256                         &(res->ip_value.addr.ipv6),
9257                         sizeof(struct in6_addr));
9258                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9259         }
9260
9261         if (!strcmp(res->filter_type, "imac-ivlan"))
9262                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9263         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9264                 tunnel_filter_conf.filter_type =
9265                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9266         else if (!strcmp(res->filter_type, "imac-tenid"))
9267                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9268         else if (!strcmp(res->filter_type, "imac"))
9269                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9270         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9271                 tunnel_filter_conf.filter_type =
9272                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9273         else if (!strcmp(res->filter_type, "oip"))
9274                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9275         else if (!strcmp(res->filter_type, "iip"))
9276                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9277         else {
9278                 printf("The filter type is not supported");
9279                 return;
9280         }
9281
9282         if (!strcmp(res->tunnel_type, "vxlan"))
9283                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9284         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9285                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9286         else if (!strcmp(res->tunnel_type, "nvgre"))
9287                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9288         else if (!strcmp(res->tunnel_type, "ipingre"))
9289                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9290         else {
9291                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9292                 return;
9293         }
9294
9295         tunnel_filter_conf.tenant_id = res->tenant_id;
9296         tunnel_filter_conf.queue_id = res->queue_num;
9297         if (!strcmp(res->what, "add"))
9298                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9299                                         RTE_ETH_FILTER_TUNNEL,
9300                                         RTE_ETH_FILTER_ADD,
9301                                         &tunnel_filter_conf);
9302         else
9303                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9304                                         RTE_ETH_FILTER_TUNNEL,
9305                                         RTE_ETH_FILTER_DELETE,
9306                                         &tunnel_filter_conf);
9307         if (ret < 0)
9308                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9309                                 strerror(-ret));
9310
9311 }
9312 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9313         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9314         cmd, "tunnel_filter");
9315 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9316         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9317         what, "add#rm");
9318 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9319         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9320         port_id, UINT16);
9321 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9322         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9323         outer_mac);
9324 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9325         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9326         inner_mac);
9327 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9328         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9329         inner_vlan, UINT16);
9330 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9331         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9332         ip_value);
9333 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9334         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9335         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9336
9337 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9338         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9339         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9340                 "imac#omac-imac-tenid");
9341 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9342         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9343         tenant_id, UINT32);
9344 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9345         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9346         queue_num, UINT16);
9347
9348 cmdline_parse_inst_t cmd_tunnel_filter = {
9349         .f = cmd_tunnel_filter_parsed,
9350         .data = (void *)0,
9351         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9352                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9353                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9354                 "<queue_id>: Add/Rm tunnel filter of a port",
9355         .tokens = {
9356                 (void *)&cmd_tunnel_filter_cmd,
9357                 (void *)&cmd_tunnel_filter_what,
9358                 (void *)&cmd_tunnel_filter_port_id,
9359                 (void *)&cmd_tunnel_filter_outer_mac,
9360                 (void *)&cmd_tunnel_filter_inner_mac,
9361                 (void *)&cmd_tunnel_filter_ip_value,
9362                 (void *)&cmd_tunnel_filter_innner_vlan,
9363                 (void *)&cmd_tunnel_filter_tunnel_type,
9364                 (void *)&cmd_tunnel_filter_filter_type,
9365                 (void *)&cmd_tunnel_filter_tenant_id,
9366                 (void *)&cmd_tunnel_filter_queue_num,
9367                 NULL,
9368         },
9369 };
9370
9371 /* *** CONFIGURE TUNNEL UDP PORT *** */
9372 struct cmd_tunnel_udp_config {
9373         cmdline_fixed_string_t cmd;
9374         cmdline_fixed_string_t what;
9375         uint16_t udp_port;
9376         portid_t port_id;
9377 };
9378
9379 static void
9380 cmd_tunnel_udp_config_parsed(void *parsed_result,
9381                           __rte_unused struct cmdline *cl,
9382                           __rte_unused void *data)
9383 {
9384         struct cmd_tunnel_udp_config *res = parsed_result;
9385         struct rte_eth_udp_tunnel tunnel_udp;
9386         int ret;
9387
9388         tunnel_udp.udp_port = res->udp_port;
9389
9390         if (!strcmp(res->cmd, "rx_vxlan_port"))
9391                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9392
9393         if (!strcmp(res->what, "add"))
9394                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9395                                                       &tunnel_udp);
9396         else
9397                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9398                                                          &tunnel_udp);
9399
9400         if (ret < 0)
9401                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9402 }
9403
9404 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9405         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9406                                 cmd, "rx_vxlan_port");
9407 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9408         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9409                                 what, "add#rm");
9410 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9411         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9412                                 udp_port, UINT16);
9413 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9414         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9415                                 port_id, UINT16);
9416
9417 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9418         .f = cmd_tunnel_udp_config_parsed,
9419         .data = (void *)0,
9420         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9421                 "Add/Remove a tunneling UDP port filter",
9422         .tokens = {
9423                 (void *)&cmd_tunnel_udp_config_cmd,
9424                 (void *)&cmd_tunnel_udp_config_what,
9425                 (void *)&cmd_tunnel_udp_config_udp_port,
9426                 (void *)&cmd_tunnel_udp_config_port_id,
9427                 NULL,
9428         },
9429 };
9430
9431 struct cmd_config_tunnel_udp_port {
9432         cmdline_fixed_string_t port;
9433         cmdline_fixed_string_t config;
9434         portid_t port_id;
9435         cmdline_fixed_string_t udp_tunnel_port;
9436         cmdline_fixed_string_t action;
9437         cmdline_fixed_string_t tunnel_type;
9438         uint16_t udp_port;
9439 };
9440
9441 static void
9442 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9443                                __rte_unused struct cmdline *cl,
9444                                __rte_unused void *data)
9445 {
9446         struct cmd_config_tunnel_udp_port *res = parsed_result;
9447         struct rte_eth_udp_tunnel tunnel_udp;
9448         int ret = 0;
9449
9450         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9451                 return;
9452
9453         tunnel_udp.udp_port = res->udp_port;
9454
9455         if (!strcmp(res->tunnel_type, "vxlan")) {
9456                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9457         } else if (!strcmp(res->tunnel_type, "geneve")) {
9458                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9459         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9460                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9461         } else {
9462                 printf("Invalid tunnel type\n");
9463                 return;
9464         }
9465
9466         if (!strcmp(res->action, "add"))
9467                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9468                                                       &tunnel_udp);
9469         else
9470                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9471                                                          &tunnel_udp);
9472
9473         if (ret < 0)
9474                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9475 }
9476
9477 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9478         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9479                                  "port");
9480 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9481         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9482                                  "config");
9483 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9484         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9485                               UINT16);
9486 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9487         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9488                                  udp_tunnel_port,
9489                                  "udp_tunnel_port");
9490 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9491         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9492                                  "add#rm");
9493 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9494         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9495                                  "vxlan#geneve#vxlan-gpe");
9496 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9497         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9498                               UINT16);
9499
9500 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9501         .f = cmd_cfg_tunnel_udp_port_parsed,
9502         .data = NULL,
9503         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9504         .tokens = {
9505                 (void *)&cmd_config_tunnel_udp_port_port,
9506                 (void *)&cmd_config_tunnel_udp_port_config,
9507                 (void *)&cmd_config_tunnel_udp_port_port_id,
9508                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9509                 (void *)&cmd_config_tunnel_udp_port_action,
9510                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9511                 (void *)&cmd_config_tunnel_udp_port_value,
9512                 NULL,
9513         },
9514 };
9515
9516 /* *** GLOBAL CONFIG *** */
9517 struct cmd_global_config_result {
9518         cmdline_fixed_string_t cmd;
9519         portid_t port_id;
9520         cmdline_fixed_string_t cfg_type;
9521         uint8_t len;
9522 };
9523
9524 static void
9525 cmd_global_config_parsed(void *parsed_result,
9526                          __rte_unused struct cmdline *cl,
9527                          __rte_unused void *data)
9528 {
9529         struct cmd_global_config_result *res = parsed_result;
9530         struct rte_eth_global_cfg conf;
9531         int ret;
9532
9533         memset(&conf, 0, sizeof(conf));
9534         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9535         conf.cfg.gre_key_len = res->len;
9536         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9537                                       RTE_ETH_FILTER_SET, &conf);
9538 #ifdef RTE_NET_I40E
9539         if (ret == -ENOTSUP)
9540                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9541 #endif
9542         if (ret != 0)
9543                 printf("Global config error\n");
9544 }
9545
9546 cmdline_parse_token_string_t cmd_global_config_cmd =
9547         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9548                 "global_config");
9549 cmdline_parse_token_num_t cmd_global_config_port_id =
9550         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9551                                UINT16);
9552 cmdline_parse_token_string_t cmd_global_config_type =
9553         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9554                 cfg_type, "gre-key-len");
9555 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9556         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9557                 len, UINT8);
9558
9559 cmdline_parse_inst_t cmd_global_config = {
9560         .f = cmd_global_config_parsed,
9561         .data = (void *)NULL,
9562         .help_str = "global_config <port_id> gre-key-len <key_len>",
9563         .tokens = {
9564                 (void *)&cmd_global_config_cmd,
9565                 (void *)&cmd_global_config_port_id,
9566                 (void *)&cmd_global_config_type,
9567                 (void *)&cmd_global_config_gre_key_len,
9568                 NULL,
9569         },
9570 };
9571
9572 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9573 struct cmd_set_mirror_mask_result {
9574         cmdline_fixed_string_t set;
9575         cmdline_fixed_string_t port;
9576         portid_t port_id;
9577         cmdline_fixed_string_t mirror;
9578         uint8_t rule_id;
9579         cmdline_fixed_string_t what;
9580         cmdline_fixed_string_t value;
9581         cmdline_fixed_string_t dstpool;
9582         uint8_t dstpool_id;
9583         cmdline_fixed_string_t on;
9584 };
9585
9586 cmdline_parse_token_string_t cmd_mirror_mask_set =
9587         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9588                                 set, "set");
9589 cmdline_parse_token_string_t cmd_mirror_mask_port =
9590         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9591                                 port, "port");
9592 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9593         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9594                                 port_id, UINT16);
9595 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9596         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9597                                 mirror, "mirror-rule");
9598 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9599         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9600                                 rule_id, UINT8);
9601 cmdline_parse_token_string_t cmd_mirror_mask_what =
9602         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9603                                 what, "pool-mirror-up#pool-mirror-down"
9604                                       "#vlan-mirror");
9605 cmdline_parse_token_string_t cmd_mirror_mask_value =
9606         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9607                                 value, NULL);
9608 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9609         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9610                                 dstpool, "dst-pool");
9611 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9612         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9613                                 dstpool_id, UINT8);
9614 cmdline_parse_token_string_t cmd_mirror_mask_on =
9615         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9616                                 on, "on#off");
9617
9618 static void
9619 cmd_set_mirror_mask_parsed(void *parsed_result,
9620                        __rte_unused struct cmdline *cl,
9621                        __rte_unused void *data)
9622 {
9623         int ret,nb_item,i;
9624         struct cmd_set_mirror_mask_result *res = parsed_result;
9625         struct rte_eth_mirror_conf mr_conf;
9626
9627         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9628
9629         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9630
9631         mr_conf.dst_pool = res->dstpool_id;
9632
9633         if (!strcmp(res->what, "pool-mirror-up")) {
9634                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9635                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9636         } else if (!strcmp(res->what, "pool-mirror-down")) {
9637                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9638                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9639         } else if (!strcmp(res->what, "vlan-mirror")) {
9640                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9641                 nb_item = parse_item_list(res->value, "vlan",
9642                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9643                 if (nb_item <= 0)
9644                         return;
9645
9646                 for (i = 0; i < nb_item; i++) {
9647                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9648                                 printf("Invalid vlan_id: must be < 4096\n");
9649                                 return;
9650                         }
9651
9652                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9653                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9654                 }
9655         }
9656
9657         if (!strcmp(res->on, "on"))
9658                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9659                                                 res->rule_id, 1);
9660         else
9661                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9662                                                 res->rule_id, 0);
9663         if (ret < 0)
9664                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9665 }
9666
9667 cmdline_parse_inst_t cmd_set_mirror_mask = {
9668                 .f = cmd_set_mirror_mask_parsed,
9669                 .data = NULL,
9670                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9671                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9672                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9673                 .tokens = {
9674                         (void *)&cmd_mirror_mask_set,
9675                         (void *)&cmd_mirror_mask_port,
9676                         (void *)&cmd_mirror_mask_portid,
9677                         (void *)&cmd_mirror_mask_mirror,
9678                         (void *)&cmd_mirror_mask_ruleid,
9679                         (void *)&cmd_mirror_mask_what,
9680                         (void *)&cmd_mirror_mask_value,
9681                         (void *)&cmd_mirror_mask_dstpool,
9682                         (void *)&cmd_mirror_mask_poolid,
9683                         (void *)&cmd_mirror_mask_on,
9684                         NULL,
9685                 },
9686 };
9687
9688 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9689 struct cmd_set_mirror_link_result {
9690         cmdline_fixed_string_t set;
9691         cmdline_fixed_string_t port;
9692         portid_t port_id;
9693         cmdline_fixed_string_t mirror;
9694         uint8_t rule_id;
9695         cmdline_fixed_string_t what;
9696         cmdline_fixed_string_t dstpool;
9697         uint8_t dstpool_id;
9698         cmdline_fixed_string_t on;
9699 };
9700
9701 cmdline_parse_token_string_t cmd_mirror_link_set =
9702         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9703                                  set, "set");
9704 cmdline_parse_token_string_t cmd_mirror_link_port =
9705         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9706                                 port, "port");
9707 cmdline_parse_token_num_t cmd_mirror_link_portid =
9708         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9709                                 port_id, UINT16);
9710 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9711         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9712                                 mirror, "mirror-rule");
9713 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9714         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9715                             rule_id, UINT8);
9716 cmdline_parse_token_string_t cmd_mirror_link_what =
9717         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9718                                 what, "uplink-mirror#downlink-mirror");
9719 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9720         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9721                                 dstpool, "dst-pool");
9722 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9723         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9724                                 dstpool_id, UINT8);
9725 cmdline_parse_token_string_t cmd_mirror_link_on =
9726         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9727                                 on, "on#off");
9728
9729 static void
9730 cmd_set_mirror_link_parsed(void *parsed_result,
9731                        __rte_unused struct cmdline *cl,
9732                        __rte_unused void *data)
9733 {
9734         int ret;
9735         struct cmd_set_mirror_link_result *res = parsed_result;
9736         struct rte_eth_mirror_conf mr_conf;
9737
9738         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9739         if (!strcmp(res->what, "uplink-mirror"))
9740                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9741         else
9742                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9743
9744         mr_conf.dst_pool = res->dstpool_id;
9745
9746         if (!strcmp(res->on, "on"))
9747                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9748                                                 res->rule_id, 1);
9749         else
9750                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9751                                                 res->rule_id, 0);
9752
9753         /* check the return value and print it if is < 0 */
9754         if (ret < 0)
9755                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9756
9757 }
9758
9759 cmdline_parse_inst_t cmd_set_mirror_link = {
9760                 .f = cmd_set_mirror_link_parsed,
9761                 .data = NULL,
9762                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9763                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9764                 .tokens = {
9765                         (void *)&cmd_mirror_link_set,
9766                         (void *)&cmd_mirror_link_port,
9767                         (void *)&cmd_mirror_link_portid,
9768                         (void *)&cmd_mirror_link_mirror,
9769                         (void *)&cmd_mirror_link_ruleid,
9770                         (void *)&cmd_mirror_link_what,
9771                         (void *)&cmd_mirror_link_dstpool,
9772                         (void *)&cmd_mirror_link_poolid,
9773                         (void *)&cmd_mirror_link_on,
9774                         NULL,
9775                 },
9776 };
9777
9778 /* *** RESET VM MIRROR RULE *** */
9779 struct cmd_rm_mirror_rule_result {
9780         cmdline_fixed_string_t reset;
9781         cmdline_fixed_string_t port;
9782         portid_t port_id;
9783         cmdline_fixed_string_t mirror;
9784         uint8_t rule_id;
9785 };
9786
9787 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9788         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9789                                  reset, "reset");
9790 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9791         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9792                                 port, "port");
9793 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9794         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9795                                 port_id, UINT16);
9796 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9797         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9798                                 mirror, "mirror-rule");
9799 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9800         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9801                                 rule_id, UINT8);
9802
9803 static void
9804 cmd_reset_mirror_rule_parsed(void *parsed_result,
9805                        __rte_unused struct cmdline *cl,
9806                        __rte_unused void *data)
9807 {
9808         int ret;
9809         struct cmd_set_mirror_link_result *res = parsed_result;
9810         /* check rule_id */
9811         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9812         if(ret < 0)
9813                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9814 }
9815
9816 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9817                 .f = cmd_reset_mirror_rule_parsed,
9818                 .data = NULL,
9819                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9820                 .tokens = {
9821                         (void *)&cmd_rm_mirror_rule_reset,
9822                         (void *)&cmd_rm_mirror_rule_port,
9823                         (void *)&cmd_rm_mirror_rule_portid,
9824                         (void *)&cmd_rm_mirror_rule_mirror,
9825                         (void *)&cmd_rm_mirror_rule_ruleid,
9826                         NULL,
9827                 },
9828 };
9829
9830 /* ******************************************************************************** */
9831
9832 struct cmd_dump_result {
9833         cmdline_fixed_string_t dump;
9834 };
9835
9836 static void
9837 dump_struct_sizes(void)
9838 {
9839 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9840         DUMP_SIZE(struct rte_mbuf);
9841         DUMP_SIZE(struct rte_mempool);
9842         DUMP_SIZE(struct rte_ring);
9843 #undef DUMP_SIZE
9844 }
9845
9846
9847 /* Dump the socket memory statistics on console */
9848 static void
9849 dump_socket_mem(FILE *f)
9850 {
9851         struct rte_malloc_socket_stats socket_stats;
9852         unsigned int i;
9853         size_t total = 0;
9854         size_t alloc = 0;
9855         size_t free = 0;
9856         unsigned int n_alloc = 0;
9857         unsigned int n_free = 0;
9858         static size_t last_allocs;
9859         static size_t last_total;
9860
9861
9862         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9863                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9864                     !socket_stats.heap_totalsz_bytes)
9865                         continue;
9866                 total += socket_stats.heap_totalsz_bytes;
9867                 alloc += socket_stats.heap_allocsz_bytes;
9868                 free += socket_stats.heap_freesz_bytes;
9869                 n_alloc += socket_stats.alloc_count;
9870                 n_free += socket_stats.free_count;
9871                 fprintf(f,
9872                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9873                         i,
9874                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9875                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9876                         (double)socket_stats.heap_allocsz_bytes * 100 /
9877                         (double)socket_stats.heap_totalsz_bytes,
9878                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9879                         socket_stats.alloc_count,
9880                         socket_stats.free_count);
9881         }
9882         fprintf(f,
9883                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9884                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9885                 (double)alloc * 100 / (double)total,
9886                 (double)free / (1024 * 1024),
9887                 n_alloc, n_free);
9888         if (last_allocs)
9889                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9890                         ((double)total - (double)last_total) / (1024 * 1024),
9891                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9892         last_allocs = alloc;
9893         last_total = total;
9894 }
9895
9896 static void cmd_dump_parsed(void *parsed_result,
9897                             __rte_unused struct cmdline *cl,
9898                             __rte_unused void *data)
9899 {
9900         struct cmd_dump_result *res = parsed_result;
9901
9902         if (!strcmp(res->dump, "dump_physmem"))
9903                 rte_dump_physmem_layout(stdout);
9904         else if (!strcmp(res->dump, "dump_socket_mem"))
9905                 dump_socket_mem(stdout);
9906         else if (!strcmp(res->dump, "dump_memzone"))
9907                 rte_memzone_dump(stdout);
9908         else if (!strcmp(res->dump, "dump_struct_sizes"))
9909                 dump_struct_sizes();
9910         else if (!strcmp(res->dump, "dump_ring"))
9911                 rte_ring_list_dump(stdout);
9912         else if (!strcmp(res->dump, "dump_mempool"))
9913                 rte_mempool_list_dump(stdout);
9914         else if (!strcmp(res->dump, "dump_devargs"))
9915                 rte_devargs_dump(stdout);
9916         else if (!strcmp(res->dump, "dump_log_types"))
9917                 rte_log_dump(stdout);
9918 }
9919
9920 cmdline_parse_token_string_t cmd_dump_dump =
9921         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9922                 "dump_physmem#"
9923                 "dump_memzone#"
9924                 "dump_socket_mem#"
9925                 "dump_struct_sizes#"
9926                 "dump_ring#"
9927                 "dump_mempool#"
9928                 "dump_devargs#"
9929                 "dump_log_types");
9930
9931 cmdline_parse_inst_t cmd_dump = {
9932         .f = cmd_dump_parsed,  /* function to call */
9933         .data = NULL,      /* 2nd arg of func */
9934         .help_str = "Dump status",
9935         .tokens = {        /* token list, NULL terminated */
9936                 (void *)&cmd_dump_dump,
9937                 NULL,
9938         },
9939 };
9940
9941 /* ******************************************************************************** */
9942
9943 struct cmd_dump_one_result {
9944         cmdline_fixed_string_t dump;
9945         cmdline_fixed_string_t name;
9946 };
9947
9948 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9949                                 __rte_unused void *data)
9950 {
9951         struct cmd_dump_one_result *res = parsed_result;
9952
9953         if (!strcmp(res->dump, "dump_ring")) {
9954                 struct rte_ring *r;
9955                 r = rte_ring_lookup(res->name);
9956                 if (r == NULL) {
9957                         cmdline_printf(cl, "Cannot find ring\n");
9958                         return;
9959                 }
9960                 rte_ring_dump(stdout, r);
9961         } else if (!strcmp(res->dump, "dump_mempool")) {
9962                 struct rte_mempool *mp;
9963                 mp = rte_mempool_lookup(res->name);
9964                 if (mp == NULL) {
9965                         cmdline_printf(cl, "Cannot find mempool\n");
9966                         return;
9967                 }
9968                 rte_mempool_dump(stdout, mp);
9969         }
9970 }
9971
9972 cmdline_parse_token_string_t cmd_dump_one_dump =
9973         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9974                                  "dump_ring#dump_mempool");
9975
9976 cmdline_parse_token_string_t cmd_dump_one_name =
9977         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9978
9979 cmdline_parse_inst_t cmd_dump_one = {
9980         .f = cmd_dump_one_parsed,  /* function to call */
9981         .data = NULL,      /* 2nd arg of func */
9982         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9983         .tokens = {        /* token list, NULL terminated */
9984                 (void *)&cmd_dump_one_dump,
9985                 (void *)&cmd_dump_one_name,
9986                 NULL,
9987         },
9988 };
9989
9990 /* *** Add/Del syn filter *** */
9991 struct cmd_syn_filter_result {
9992         cmdline_fixed_string_t filter;
9993         portid_t port_id;
9994         cmdline_fixed_string_t ops;
9995         cmdline_fixed_string_t priority;
9996         cmdline_fixed_string_t high;
9997         cmdline_fixed_string_t queue;
9998         uint16_t queue_id;
9999 };
10000
10001 static void
10002 cmd_syn_filter_parsed(void *parsed_result,
10003                         __rte_unused struct cmdline *cl,
10004                         __rte_unused void *data)
10005 {
10006         struct cmd_syn_filter_result *res = parsed_result;
10007         struct rte_eth_syn_filter syn_filter;
10008         int ret = 0;
10009
10010         ret = rte_eth_dev_filter_supported(res->port_id,
10011                                         RTE_ETH_FILTER_SYN);
10012         if (ret < 0) {
10013                 printf("syn filter is not supported on port %u.\n",
10014                                 res->port_id);
10015                 return;
10016         }
10017
10018         memset(&syn_filter, 0, sizeof(syn_filter));
10019
10020         if (!strcmp(res->ops, "add")) {
10021                 if (!strcmp(res->high, "high"))
10022                         syn_filter.hig_pri = 1;
10023                 else
10024                         syn_filter.hig_pri = 0;
10025
10026                 syn_filter.queue = res->queue_id;
10027                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10028                                                 RTE_ETH_FILTER_SYN,
10029                                                 RTE_ETH_FILTER_ADD,
10030                                                 &syn_filter);
10031         } else
10032                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10033                                                 RTE_ETH_FILTER_SYN,
10034                                                 RTE_ETH_FILTER_DELETE,
10035                                                 &syn_filter);
10036
10037         if (ret < 0)
10038                 printf("syn filter programming error: (%s)\n",
10039                                 strerror(-ret));
10040 }
10041
10042 cmdline_parse_token_string_t cmd_syn_filter_filter =
10043         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10044         filter, "syn_filter");
10045 cmdline_parse_token_num_t cmd_syn_filter_port_id =
10046         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10047         port_id, UINT16);
10048 cmdline_parse_token_string_t cmd_syn_filter_ops =
10049         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10050         ops, "add#del");
10051 cmdline_parse_token_string_t cmd_syn_filter_priority =
10052         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10053                                 priority, "priority");
10054 cmdline_parse_token_string_t cmd_syn_filter_high =
10055         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10056                                 high, "high#low");
10057 cmdline_parse_token_string_t cmd_syn_filter_queue =
10058         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10059                                 queue, "queue");
10060 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
10061         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10062                                 queue_id, UINT16);
10063
10064 cmdline_parse_inst_t cmd_syn_filter = {
10065         .f = cmd_syn_filter_parsed,
10066         .data = NULL,
10067         .help_str = "syn_filter <port_id> add|del priority high|low queue "
10068                 "<queue_id>: Add/Delete syn filter",
10069         .tokens = {
10070                 (void *)&cmd_syn_filter_filter,
10071                 (void *)&cmd_syn_filter_port_id,
10072                 (void *)&cmd_syn_filter_ops,
10073                 (void *)&cmd_syn_filter_priority,
10074                 (void *)&cmd_syn_filter_high,
10075                 (void *)&cmd_syn_filter_queue,
10076                 (void *)&cmd_syn_filter_queue_id,
10077                 NULL,
10078         },
10079 };
10080
10081 /* *** queue region set *** */
10082 struct cmd_queue_region_result {
10083         cmdline_fixed_string_t set;
10084         cmdline_fixed_string_t port;
10085         portid_t port_id;
10086         cmdline_fixed_string_t cmd;
10087         cmdline_fixed_string_t region;
10088         uint8_t  region_id;
10089         cmdline_fixed_string_t queue_start_index;
10090         uint8_t  queue_id;
10091         cmdline_fixed_string_t queue_num;
10092         uint8_t  queue_num_value;
10093 };
10094
10095 static void
10096 cmd_queue_region_parsed(void *parsed_result,
10097                         __rte_unused struct cmdline *cl,
10098                         __rte_unused void *data)
10099 {
10100         struct cmd_queue_region_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         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10113         region_conf.region_id = res->region_id;
10114         region_conf.queue_num = res->queue_num_value;
10115         region_conf.queue_start_index = res->queue_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("queue region config error: (%s)\n", strerror(-ret));
10129         }
10130 }
10131
10132 cmdline_parse_token_string_t cmd_queue_region_set =
10133 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10134                 set, "set");
10135 cmdline_parse_token_string_t cmd_queue_region_port =
10136         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10137 cmdline_parse_token_num_t cmd_queue_region_port_id =
10138         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10139                                 port_id, UINT16);
10140 cmdline_parse_token_string_t cmd_queue_region_cmd =
10141         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10142                                  cmd, "queue-region");
10143 cmdline_parse_token_string_t cmd_queue_region_id =
10144         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10145                                 region, "region_id");
10146 cmdline_parse_token_num_t cmd_queue_region_index =
10147         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10148                                 region_id, UINT8);
10149 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10150         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10151                                 queue_start_index, "queue_start_index");
10152 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10153         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10154                                 queue_id, UINT8);
10155 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10156         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10157                                 queue_num, "queue_num");
10158 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10159         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10160                                 queue_num_value, UINT8);
10161
10162 cmdline_parse_inst_t cmd_queue_region = {
10163         .f = cmd_queue_region_parsed,
10164         .data = NULL,
10165         .help_str = "set port <port_id> queue-region region_id <value> "
10166                 "queue_start_index <value> queue_num <value>: Set a queue region",
10167         .tokens = {
10168                 (void *)&cmd_queue_region_set,
10169                 (void *)&cmd_queue_region_port,
10170                 (void *)&cmd_queue_region_port_id,
10171                 (void *)&cmd_queue_region_cmd,
10172                 (void *)&cmd_queue_region_id,
10173                 (void *)&cmd_queue_region_index,
10174                 (void *)&cmd_queue_region_queue_start_index,
10175                 (void *)&cmd_queue_region_queue_id,
10176                 (void *)&cmd_queue_region_queue_num,
10177                 (void *)&cmd_queue_region_queue_num_value,
10178                 NULL,
10179         },
10180 };
10181
10182 /* *** queue region and flowtype set *** */
10183 struct cmd_region_flowtype_result {
10184         cmdline_fixed_string_t set;
10185         cmdline_fixed_string_t port;
10186         portid_t port_id;
10187         cmdline_fixed_string_t cmd;
10188         cmdline_fixed_string_t region;
10189         uint8_t  region_id;
10190         cmdline_fixed_string_t flowtype;
10191         uint8_t  flowtype_id;
10192 };
10193
10194 static void
10195 cmd_region_flowtype_parsed(void *parsed_result,
10196                         __rte_unused struct cmdline *cl,
10197                         __rte_unused void *data)
10198 {
10199         struct cmd_region_flowtype_result *res = parsed_result;
10200         int ret = -ENOTSUP;
10201 #ifdef RTE_NET_I40E
10202         struct rte_pmd_i40e_queue_region_conf region_conf;
10203         enum rte_pmd_i40e_queue_region_op op_type;
10204 #endif
10205
10206         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10207                 return;
10208
10209 #ifdef RTE_NET_I40E
10210         memset(&region_conf, 0, sizeof(region_conf));
10211
10212         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10213         region_conf.region_id = res->region_id;
10214         region_conf.hw_flowtype = res->flowtype_id;
10215
10216         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10217                         op_type, &region_conf);
10218 #endif
10219
10220         switch (ret) {
10221         case 0:
10222                 break;
10223         case -ENOTSUP:
10224                 printf("function not implemented or supported\n");
10225                 break;
10226         default:
10227                 printf("region flowtype config error: (%s)\n", strerror(-ret));
10228         }
10229 }
10230
10231 cmdline_parse_token_string_t cmd_region_flowtype_set =
10232 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10233                                 set, "set");
10234 cmdline_parse_token_string_t cmd_region_flowtype_port =
10235         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10236                                 port, "port");
10237 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10238         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10239                                 port_id, UINT16);
10240 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10241         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10242                                 cmd, "queue-region");
10243 cmdline_parse_token_string_t cmd_region_flowtype_index =
10244         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10245                                 region, "region_id");
10246 cmdline_parse_token_num_t cmd_region_flowtype_id =
10247         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10248                                 region_id, UINT8);
10249 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10250         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10251                                 flowtype, "flowtype");
10252 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10253         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10254                                 flowtype_id, UINT8);
10255 cmdline_parse_inst_t cmd_region_flowtype = {
10256         .f = cmd_region_flowtype_parsed,
10257         .data = NULL,
10258         .help_str = "set port <port_id> queue-region region_id <value> "
10259                 "flowtype <value>: Set a flowtype region index",
10260         .tokens = {
10261                 (void *)&cmd_region_flowtype_set,
10262                 (void *)&cmd_region_flowtype_port,
10263                 (void *)&cmd_region_flowtype_port_index,
10264                 (void *)&cmd_region_flowtype_cmd,
10265                 (void *)&cmd_region_flowtype_index,
10266                 (void *)&cmd_region_flowtype_id,
10267                 (void *)&cmd_region_flowtype_flow_index,
10268                 (void *)&cmd_region_flowtype_flow_id,
10269                 NULL,
10270         },
10271 };
10272
10273 /* *** User Priority (UP) to queue region (region_id) set *** */
10274 struct cmd_user_priority_region_result {
10275         cmdline_fixed_string_t set;
10276         cmdline_fixed_string_t port;
10277         portid_t port_id;
10278         cmdline_fixed_string_t cmd;
10279         cmdline_fixed_string_t user_priority;
10280         uint8_t  user_priority_id;
10281         cmdline_fixed_string_t region;
10282         uint8_t  region_id;
10283 };
10284
10285 static void
10286 cmd_user_priority_region_parsed(void *parsed_result,
10287                         __rte_unused struct cmdline *cl,
10288                         __rte_unused void *data)
10289 {
10290         struct cmd_user_priority_region_result *res = parsed_result;
10291         int ret = -ENOTSUP;
10292 #ifdef RTE_NET_I40E
10293         struct rte_pmd_i40e_queue_region_conf region_conf;
10294         enum rte_pmd_i40e_queue_region_op op_type;
10295 #endif
10296
10297         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10298                 return;
10299
10300 #ifdef RTE_NET_I40E
10301         memset(&region_conf, 0, sizeof(region_conf));
10302         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10303         region_conf.user_priority = res->user_priority_id;
10304         region_conf.region_id = res->region_id;
10305
10306         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10307                                 op_type, &region_conf);
10308 #endif
10309
10310         switch (ret) {
10311         case 0:
10312                 break;
10313         case -ENOTSUP:
10314                 printf("function not implemented or supported\n");
10315                 break;
10316         default:
10317                 printf("user_priority region config error: (%s)\n",
10318                                 strerror(-ret));
10319         }
10320 }
10321
10322 cmdline_parse_token_string_t cmd_user_priority_region_set =
10323         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10324                                 set, "set");
10325 cmdline_parse_token_string_t cmd_user_priority_region_port =
10326         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10327                                 port, "port");
10328 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10329         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10330                                 port_id, UINT16);
10331 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10332         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10333                                 cmd, "queue-region");
10334 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10335         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10336                                 user_priority, "UP");
10337 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10338         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10339                                 user_priority_id, UINT8);
10340 cmdline_parse_token_string_t cmd_user_priority_region_region =
10341         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10342                                 region, "region_id");
10343 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10344         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10345                                 region_id, UINT8);
10346
10347 cmdline_parse_inst_t cmd_user_priority_region = {
10348         .f = cmd_user_priority_region_parsed,
10349         .data = NULL,
10350         .help_str = "set port <port_id> queue-region UP <value> "
10351                 "region_id <value>: Set the mapping of User Priority (UP) "
10352                 "to queue region (region_id) ",
10353         .tokens = {
10354                 (void *)&cmd_user_priority_region_set,
10355                 (void *)&cmd_user_priority_region_port,
10356                 (void *)&cmd_user_priority_region_port_index,
10357                 (void *)&cmd_user_priority_region_cmd,
10358                 (void *)&cmd_user_priority_region_UP,
10359                 (void *)&cmd_user_priority_region_UP_id,
10360                 (void *)&cmd_user_priority_region_region,
10361                 (void *)&cmd_user_priority_region_region_id,
10362                 NULL,
10363         },
10364 };
10365
10366 /* *** flush all queue region related configuration *** */
10367 struct cmd_flush_queue_region_result {
10368         cmdline_fixed_string_t set;
10369         cmdline_fixed_string_t port;
10370         portid_t port_id;
10371         cmdline_fixed_string_t cmd;
10372         cmdline_fixed_string_t flush;
10373         cmdline_fixed_string_t what;
10374 };
10375
10376 static void
10377 cmd_flush_queue_region_parsed(void *parsed_result,
10378                         __rte_unused struct cmdline *cl,
10379                         __rte_unused void *data)
10380 {
10381         struct cmd_flush_queue_region_result *res = parsed_result;
10382         int ret = -ENOTSUP;
10383 #ifdef RTE_NET_I40E
10384         struct rte_pmd_i40e_queue_region_conf region_conf;
10385         enum rte_pmd_i40e_queue_region_op op_type;
10386 #endif
10387
10388         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10389                 return;
10390
10391 #ifdef RTE_NET_I40E
10392         memset(&region_conf, 0, sizeof(region_conf));
10393
10394         if (strcmp(res->what, "on") == 0)
10395                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10396         else
10397                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10398
10399         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10400                                 op_type, &region_conf);
10401 #endif
10402
10403         switch (ret) {
10404         case 0:
10405                 break;
10406         case -ENOTSUP:
10407                 printf("function not implemented or supported\n");
10408                 break;
10409         default:
10410                 printf("queue region config flush error: (%s)\n",
10411                                 strerror(-ret));
10412         }
10413 }
10414
10415 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10416         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10417                                 set, "set");
10418 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10419         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10420                                 port, "port");
10421 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10422         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10423                                 port_id, UINT16);
10424 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10425         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10426                                 cmd, "queue-region");
10427 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10428         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10429                                 flush, "flush");
10430 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10431         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10432                                 what, "on#off");
10433
10434 cmdline_parse_inst_t cmd_flush_queue_region = {
10435         .f = cmd_flush_queue_region_parsed,
10436         .data = NULL,
10437         .help_str = "set port <port_id> queue-region flush on|off"
10438                 ": flush all queue region related configuration",
10439         .tokens = {
10440                 (void *)&cmd_flush_queue_region_set,
10441                 (void *)&cmd_flush_queue_region_port,
10442                 (void *)&cmd_flush_queue_region_port_index,
10443                 (void *)&cmd_flush_queue_region_cmd,
10444                 (void *)&cmd_flush_queue_region_flush,
10445                 (void *)&cmd_flush_queue_region_what,
10446                 NULL,
10447         },
10448 };
10449
10450 /* *** get all queue region related configuration info *** */
10451 struct cmd_show_queue_region_info {
10452         cmdline_fixed_string_t show;
10453         cmdline_fixed_string_t port;
10454         portid_t port_id;
10455         cmdline_fixed_string_t cmd;
10456 };
10457
10458 static void
10459 cmd_show_queue_region_info_parsed(void *parsed_result,
10460                         __rte_unused struct cmdline *cl,
10461                         __rte_unused void *data)
10462 {
10463         struct cmd_show_queue_region_info *res = parsed_result;
10464         int ret = -ENOTSUP;
10465 #ifdef RTE_NET_I40E
10466         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10467         enum rte_pmd_i40e_queue_region_op op_type;
10468 #endif
10469
10470         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10471                 return;
10472
10473 #ifdef RTE_NET_I40E
10474         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10475
10476         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10477
10478         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10479                                         op_type, &rte_pmd_regions);
10480
10481         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10482 #endif
10483
10484         switch (ret) {
10485         case 0:
10486                 break;
10487         case -ENOTSUP:
10488                 printf("function not implemented or supported\n");
10489                 break;
10490         default:
10491                 printf("queue region config info show error: (%s)\n",
10492                                 strerror(-ret));
10493         }
10494 }
10495
10496 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10497 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10498                                 show, "show");
10499 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10500         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10501                                 port, "port");
10502 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10503         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10504                                 port_id, UINT16);
10505 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10506         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10507                                 cmd, "queue-region");
10508
10509 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10510         .f = cmd_show_queue_region_info_parsed,
10511         .data = NULL,
10512         .help_str = "show port <port_id> queue-region"
10513                 ": show all queue region related configuration info",
10514         .tokens = {
10515                 (void *)&cmd_show_queue_region_info_get,
10516                 (void *)&cmd_show_queue_region_info_port,
10517                 (void *)&cmd_show_queue_region_info_port_index,
10518                 (void *)&cmd_show_queue_region_info_cmd,
10519                 NULL,
10520         },
10521 };
10522
10523 /* *** ADD/REMOVE A 2tuple FILTER *** */
10524 struct cmd_2tuple_filter_result {
10525         cmdline_fixed_string_t filter;
10526         portid_t port_id;
10527         cmdline_fixed_string_t ops;
10528         cmdline_fixed_string_t dst_port;
10529         uint16_t dst_port_value;
10530         cmdline_fixed_string_t protocol;
10531         uint8_t protocol_value;
10532         cmdline_fixed_string_t mask;
10533         uint8_t  mask_value;
10534         cmdline_fixed_string_t tcp_flags;
10535         uint8_t tcp_flags_value;
10536         cmdline_fixed_string_t priority;
10537         uint8_t  priority_value;
10538         cmdline_fixed_string_t queue;
10539         uint16_t  queue_id;
10540 };
10541
10542 static void
10543 cmd_2tuple_filter_parsed(void *parsed_result,
10544                         __rte_unused struct cmdline *cl,
10545                         __rte_unused void *data)
10546 {
10547         struct rte_eth_ntuple_filter filter;
10548         struct cmd_2tuple_filter_result *res = parsed_result;
10549         int ret = 0;
10550
10551         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10552         if (ret < 0) {
10553                 printf("ntuple filter is not supported on port %u.\n",
10554                         res->port_id);
10555                 return;
10556         }
10557
10558         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10559
10560         filter.flags = RTE_2TUPLE_FLAGS;
10561         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10562         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10563         filter.proto = res->protocol_value;
10564         filter.priority = res->priority_value;
10565         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10566                 printf("nonzero tcp_flags is only meaningful"
10567                         " when protocol is TCP.\n");
10568                 return;
10569         }
10570         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10571                 printf("invalid TCP flags.\n");
10572                 return;
10573         }
10574
10575         if (res->tcp_flags_value != 0) {
10576                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10577                 filter.tcp_flags = res->tcp_flags_value;
10578         }
10579
10580         /* need convert to big endian. */
10581         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10582         filter.queue = res->queue_id;
10583
10584         if (!strcmp(res->ops, "add"))
10585                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10586                                 RTE_ETH_FILTER_NTUPLE,
10587                                 RTE_ETH_FILTER_ADD,
10588                                 &filter);
10589         else
10590                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10591                                 RTE_ETH_FILTER_NTUPLE,
10592                                 RTE_ETH_FILTER_DELETE,
10593                                 &filter);
10594         if (ret < 0)
10595                 printf("2tuple filter programming error: (%s)\n",
10596                         strerror(-ret));
10597
10598 }
10599
10600 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10601         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10602                                  filter, "2tuple_filter");
10603 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10604         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10605                                 port_id, UINT16);
10606 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10607         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10608                                  ops, "add#del");
10609 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10610         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10611                                 dst_port, "dst_port");
10612 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10613         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10614                                 dst_port_value, UINT16);
10615 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10616         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10617                                 protocol, "protocol");
10618 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10619         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10620                                 protocol_value, UINT8);
10621 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10622         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10623                                 mask, "mask");
10624 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10625         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10626                                 mask_value, INT8);
10627 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10628         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10629                                 tcp_flags, "tcp_flags");
10630 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10631         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10632                                 tcp_flags_value, UINT8);
10633 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10634         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10635                                 priority, "priority");
10636 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10637         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10638                                 priority_value, UINT8);
10639 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10640         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10641                                 queue, "queue");
10642 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10643         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10644                                 queue_id, UINT16);
10645
10646 cmdline_parse_inst_t cmd_2tuple_filter = {
10647         .f = cmd_2tuple_filter_parsed,
10648         .data = NULL,
10649         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10650                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10651                 "<queue_id>: Add a 2tuple filter",
10652         .tokens = {
10653                 (void *)&cmd_2tuple_filter_filter,
10654                 (void *)&cmd_2tuple_filter_port_id,
10655                 (void *)&cmd_2tuple_filter_ops,
10656                 (void *)&cmd_2tuple_filter_dst_port,
10657                 (void *)&cmd_2tuple_filter_dst_port_value,
10658                 (void *)&cmd_2tuple_filter_protocol,
10659                 (void *)&cmd_2tuple_filter_protocol_value,
10660                 (void *)&cmd_2tuple_filter_mask,
10661                 (void *)&cmd_2tuple_filter_mask_value,
10662                 (void *)&cmd_2tuple_filter_tcp_flags,
10663                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10664                 (void *)&cmd_2tuple_filter_priority,
10665                 (void *)&cmd_2tuple_filter_priority_value,
10666                 (void *)&cmd_2tuple_filter_queue,
10667                 (void *)&cmd_2tuple_filter_queue_id,
10668                 NULL,
10669         },
10670 };
10671
10672 /* *** ADD/REMOVE A 5tuple FILTER *** */
10673 struct cmd_5tuple_filter_result {
10674         cmdline_fixed_string_t filter;
10675         portid_t port_id;
10676         cmdline_fixed_string_t ops;
10677         cmdline_fixed_string_t dst_ip;
10678         cmdline_ipaddr_t dst_ip_value;
10679         cmdline_fixed_string_t src_ip;
10680         cmdline_ipaddr_t src_ip_value;
10681         cmdline_fixed_string_t dst_port;
10682         uint16_t dst_port_value;
10683         cmdline_fixed_string_t src_port;
10684         uint16_t src_port_value;
10685         cmdline_fixed_string_t protocol;
10686         uint8_t protocol_value;
10687         cmdline_fixed_string_t mask;
10688         uint8_t  mask_value;
10689         cmdline_fixed_string_t tcp_flags;
10690         uint8_t tcp_flags_value;
10691         cmdline_fixed_string_t priority;
10692         uint8_t  priority_value;
10693         cmdline_fixed_string_t queue;
10694         uint16_t  queue_id;
10695 };
10696
10697 static void
10698 cmd_5tuple_filter_parsed(void *parsed_result,
10699                         __rte_unused struct cmdline *cl,
10700                         __rte_unused void *data)
10701 {
10702         struct rte_eth_ntuple_filter filter;
10703         struct cmd_5tuple_filter_result *res = parsed_result;
10704         int ret = 0;
10705
10706         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10707         if (ret < 0) {
10708                 printf("ntuple filter is not supported on port %u.\n",
10709                         res->port_id);
10710                 return;
10711         }
10712
10713         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10714
10715         filter.flags = RTE_5TUPLE_FLAGS;
10716         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10717         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10718         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10719         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10720         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10721         filter.proto = res->protocol_value;
10722         filter.priority = res->priority_value;
10723         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10724                 printf("nonzero tcp_flags is only meaningful"
10725                         " when protocol is TCP.\n");
10726                 return;
10727         }
10728         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10729                 printf("invalid TCP flags.\n");
10730                 return;
10731         }
10732
10733         if (res->tcp_flags_value != 0) {
10734                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10735                 filter.tcp_flags = res->tcp_flags_value;
10736         }
10737
10738         if (res->dst_ip_value.family == AF_INET)
10739                 /* no need to convert, already big endian. */
10740                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10741         else {
10742                 if (filter.dst_ip_mask == 0) {
10743                         printf("can not support ipv6 involved compare.\n");
10744                         return;
10745                 }
10746                 filter.dst_ip = 0;
10747         }
10748
10749         if (res->src_ip_value.family == AF_INET)
10750                 /* no need to convert, already big endian. */
10751                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10752         else {
10753                 if (filter.src_ip_mask == 0) {
10754                         printf("can not support ipv6 involved compare.\n");
10755                         return;
10756                 }
10757                 filter.src_ip = 0;
10758         }
10759         /* need convert to big endian. */
10760         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10761         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10762         filter.queue = res->queue_id;
10763
10764         if (!strcmp(res->ops, "add"))
10765                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10766                                 RTE_ETH_FILTER_NTUPLE,
10767                                 RTE_ETH_FILTER_ADD,
10768                                 &filter);
10769         else
10770                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10771                                 RTE_ETH_FILTER_NTUPLE,
10772                                 RTE_ETH_FILTER_DELETE,
10773                                 &filter);
10774         if (ret < 0)
10775                 printf("5tuple filter programming error: (%s)\n",
10776                         strerror(-ret));
10777 }
10778
10779 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10780         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10781                                  filter, "5tuple_filter");
10782 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10783         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10784                                 port_id, UINT16);
10785 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10786         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10787                                  ops, "add#del");
10788 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10789         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10790                                 dst_ip, "dst_ip");
10791 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10792         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10793                                 dst_ip_value);
10794 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10795         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10796                                 src_ip, "src_ip");
10797 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10798         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10799                                 src_ip_value);
10800 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10801         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10802                                 dst_port, "dst_port");
10803 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10804         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10805                                 dst_port_value, UINT16);
10806 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10807         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10808                                 src_port, "src_port");
10809 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10810         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10811                                 src_port_value, UINT16);
10812 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10813         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10814                                 protocol, "protocol");
10815 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10816         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10817                                 protocol_value, UINT8);
10818 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10819         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10820                                 mask, "mask");
10821 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10822         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10823                                 mask_value, INT8);
10824 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10825         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10826                                 tcp_flags, "tcp_flags");
10827 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10828         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10829                                 tcp_flags_value, UINT8);
10830 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10831         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10832                                 priority, "priority");
10833 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10834         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10835                                 priority_value, UINT8);
10836 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10837         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10838                                 queue, "queue");
10839 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10840         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10841                                 queue_id, UINT16);
10842
10843 cmdline_parse_inst_t cmd_5tuple_filter = {
10844         .f = cmd_5tuple_filter_parsed,
10845         .data = NULL,
10846         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10847                 "src_ip <value> dst_port <value> src_port <value> "
10848                 "protocol <value>  mask <value> tcp_flags <value> "
10849                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10850         .tokens = {
10851                 (void *)&cmd_5tuple_filter_filter,
10852                 (void *)&cmd_5tuple_filter_port_id,
10853                 (void *)&cmd_5tuple_filter_ops,
10854                 (void *)&cmd_5tuple_filter_dst_ip,
10855                 (void *)&cmd_5tuple_filter_dst_ip_value,
10856                 (void *)&cmd_5tuple_filter_src_ip,
10857                 (void *)&cmd_5tuple_filter_src_ip_value,
10858                 (void *)&cmd_5tuple_filter_dst_port,
10859                 (void *)&cmd_5tuple_filter_dst_port_value,
10860                 (void *)&cmd_5tuple_filter_src_port,
10861                 (void *)&cmd_5tuple_filter_src_port_value,
10862                 (void *)&cmd_5tuple_filter_protocol,
10863                 (void *)&cmd_5tuple_filter_protocol_value,
10864                 (void *)&cmd_5tuple_filter_mask,
10865                 (void *)&cmd_5tuple_filter_mask_value,
10866                 (void *)&cmd_5tuple_filter_tcp_flags,
10867                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10868                 (void *)&cmd_5tuple_filter_priority,
10869                 (void *)&cmd_5tuple_filter_priority_value,
10870                 (void *)&cmd_5tuple_filter_queue,
10871                 (void *)&cmd_5tuple_filter_queue_id,
10872                 NULL,
10873         },
10874 };
10875
10876 /* *** ADD/REMOVE A flex FILTER *** */
10877 struct cmd_flex_filter_result {
10878         cmdline_fixed_string_t filter;
10879         cmdline_fixed_string_t ops;
10880         portid_t port_id;
10881         cmdline_fixed_string_t len;
10882         uint8_t len_value;
10883         cmdline_fixed_string_t bytes;
10884         cmdline_fixed_string_t bytes_value;
10885         cmdline_fixed_string_t mask;
10886         cmdline_fixed_string_t mask_value;
10887         cmdline_fixed_string_t priority;
10888         uint8_t priority_value;
10889         cmdline_fixed_string_t queue;
10890         uint16_t queue_id;
10891 };
10892
10893 static int xdigit2val(unsigned char c)
10894 {
10895         int val;
10896         if (isdigit(c))
10897                 val = c - '0';
10898         else if (isupper(c))
10899                 val = c - 'A' + 10;
10900         else
10901                 val = c - 'a' + 10;
10902         return val;
10903 }
10904
10905 static void
10906 cmd_flex_filter_parsed(void *parsed_result,
10907                           __rte_unused struct cmdline *cl,
10908                           __rte_unused void *data)
10909 {
10910         int ret = 0;
10911         struct rte_eth_flex_filter filter;
10912         struct cmd_flex_filter_result *res = parsed_result;
10913         char *bytes_ptr, *mask_ptr;
10914         uint16_t len, i, j = 0;
10915         char c;
10916         int val;
10917         uint8_t byte = 0;
10918
10919         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10920                 printf("the len exceed the max length 128\n");
10921                 return;
10922         }
10923         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10924         filter.len = res->len_value;
10925         filter.priority = res->priority_value;
10926         filter.queue = res->queue_id;
10927         bytes_ptr = res->bytes_value;
10928         mask_ptr = res->mask_value;
10929
10930          /* translate bytes string to array. */
10931         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10932                 (bytes_ptr[1] == 'X')))
10933                 bytes_ptr += 2;
10934         len = strnlen(bytes_ptr, res->len_value * 2);
10935         if (len == 0 || (len % 8 != 0)) {
10936                 printf("please check len and bytes input\n");
10937                 return;
10938         }
10939         for (i = 0; i < len; i++) {
10940                 c = bytes_ptr[i];
10941                 if (isxdigit(c) == 0) {
10942                         /* invalid characters. */
10943                         printf("invalid input\n");
10944                         return;
10945                 }
10946                 val = xdigit2val(c);
10947                 if (i % 2) {
10948                         byte |= val;
10949                         filter.bytes[j] = byte;
10950                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10951                         j++;
10952                         byte = 0;
10953                 } else
10954                         byte |= val << 4;
10955         }
10956         printf("\n");
10957          /* translate mask string to uint8_t array. */
10958         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10959                 (mask_ptr[1] == 'X')))
10960                 mask_ptr += 2;
10961         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10962         if (len == 0) {
10963                 printf("invalid input\n");
10964                 return;
10965         }
10966         j = 0;
10967         byte = 0;
10968         for (i = 0; i < len; i++) {
10969                 c = mask_ptr[i];
10970                 if (isxdigit(c) == 0) {
10971                         /* invalid characters. */
10972                         printf("invalid input\n");
10973                         return;
10974                 }
10975                 val = xdigit2val(c);
10976                 if (i % 2) {
10977                         byte |= val;
10978                         filter.mask[j] = byte;
10979                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10980                         j++;
10981                         byte = 0;
10982                 } else
10983                         byte |= val << 4;
10984         }
10985         printf("\n");
10986
10987         if (!strcmp(res->ops, "add"))
10988                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10989                                 RTE_ETH_FILTER_FLEXIBLE,
10990                                 RTE_ETH_FILTER_ADD,
10991                                 &filter);
10992         else
10993                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10994                                 RTE_ETH_FILTER_FLEXIBLE,
10995                                 RTE_ETH_FILTER_DELETE,
10996                                 &filter);
10997
10998         if (ret < 0)
10999                 printf("flex filter setting error: (%s)\n", strerror(-ret));
11000 }
11001
11002 cmdline_parse_token_string_t cmd_flex_filter_filter =
11003         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11004                                 filter, "flex_filter");
11005 cmdline_parse_token_num_t cmd_flex_filter_port_id =
11006         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11007                                 port_id, UINT16);
11008 cmdline_parse_token_string_t cmd_flex_filter_ops =
11009         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11010                                 ops, "add#del");
11011 cmdline_parse_token_string_t cmd_flex_filter_len =
11012         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11013                                 len, "len");
11014 cmdline_parse_token_num_t cmd_flex_filter_len_value =
11015         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11016                                 len_value, UINT8);
11017 cmdline_parse_token_string_t cmd_flex_filter_bytes =
11018         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11019                                 bytes, "bytes");
11020 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
11021         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11022                                 bytes_value, NULL);
11023 cmdline_parse_token_string_t cmd_flex_filter_mask =
11024         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11025                                 mask, "mask");
11026 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
11027         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11028                                 mask_value, NULL);
11029 cmdline_parse_token_string_t cmd_flex_filter_priority =
11030         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11031                                 priority, "priority");
11032 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
11033         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11034                                 priority_value, UINT8);
11035 cmdline_parse_token_string_t cmd_flex_filter_queue =
11036         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11037                                 queue, "queue");
11038 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
11039         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11040                                 queue_id, UINT16);
11041 cmdline_parse_inst_t cmd_flex_filter = {
11042         .f = cmd_flex_filter_parsed,
11043         .data = NULL,
11044         .help_str = "flex_filter <port_id> add|del len <value> bytes "
11045                 "<value> mask <value> priority <value> queue <queue_id>: "
11046                 "Add/Del a flex filter",
11047         .tokens = {
11048                 (void *)&cmd_flex_filter_filter,
11049                 (void *)&cmd_flex_filter_port_id,
11050                 (void *)&cmd_flex_filter_ops,
11051                 (void *)&cmd_flex_filter_len,
11052                 (void *)&cmd_flex_filter_len_value,
11053                 (void *)&cmd_flex_filter_bytes,
11054                 (void *)&cmd_flex_filter_bytes_value,
11055                 (void *)&cmd_flex_filter_mask,
11056                 (void *)&cmd_flex_filter_mask_value,
11057                 (void *)&cmd_flex_filter_priority,
11058                 (void *)&cmd_flex_filter_priority_value,
11059                 (void *)&cmd_flex_filter_queue,
11060                 (void *)&cmd_flex_filter_queue_id,
11061                 NULL,
11062         },
11063 };
11064
11065 /* *** Filters Control *** */
11066
11067 /* *** deal with flow director filter *** */
11068 struct cmd_flow_director_result {
11069         cmdline_fixed_string_t flow_director_filter;
11070         portid_t port_id;
11071         cmdline_fixed_string_t mode;
11072         cmdline_fixed_string_t mode_value;
11073         cmdline_fixed_string_t ops;
11074         cmdline_fixed_string_t flow;
11075         cmdline_fixed_string_t flow_type;
11076         cmdline_fixed_string_t ether;
11077         uint16_t ether_type;
11078         cmdline_fixed_string_t src;
11079         cmdline_ipaddr_t ip_src;
11080         uint16_t port_src;
11081         cmdline_fixed_string_t dst;
11082         cmdline_ipaddr_t ip_dst;
11083         uint16_t port_dst;
11084         cmdline_fixed_string_t verify_tag;
11085         uint32_t verify_tag_value;
11086         cmdline_fixed_string_t tos;
11087         uint8_t tos_value;
11088         cmdline_fixed_string_t proto;
11089         uint8_t proto_value;
11090         cmdline_fixed_string_t ttl;
11091         uint8_t ttl_value;
11092         cmdline_fixed_string_t vlan;
11093         uint16_t vlan_value;
11094         cmdline_fixed_string_t flexbytes;
11095         cmdline_fixed_string_t flexbytes_value;
11096         cmdline_fixed_string_t pf_vf;
11097         cmdline_fixed_string_t drop;
11098         cmdline_fixed_string_t queue;
11099         uint16_t  queue_id;
11100         cmdline_fixed_string_t fd_id;
11101         uint32_t  fd_id_value;
11102         cmdline_fixed_string_t mac;
11103         struct rte_ether_addr mac_addr;
11104         cmdline_fixed_string_t tunnel;
11105         cmdline_fixed_string_t tunnel_type;
11106         cmdline_fixed_string_t tunnel_id;
11107         uint32_t tunnel_id_value;
11108         cmdline_fixed_string_t packet;
11109         char filepath[];
11110 };
11111
11112 static inline int
11113 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
11114 {
11115         char s[256];
11116         const char *p, *p0 = q_arg;
11117         char *end;
11118         unsigned long int_fld;
11119         char *str_fld[max_num];
11120         int i;
11121         unsigned size;
11122         int ret = -1;
11123
11124         p = strchr(p0, '(');
11125         if (p == NULL)
11126                 return -1;
11127         ++p;
11128         p0 = strchr(p, ')');
11129         if (p0 == NULL)
11130                 return -1;
11131
11132         size = p0 - p;
11133         if (size >= sizeof(s))
11134                 return -1;
11135
11136         snprintf(s, sizeof(s), "%.*s", size, p);
11137         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11138         if (ret < 0 || ret > max_num)
11139                 return -1;
11140         for (i = 0; i < ret; i++) {
11141                 errno = 0;
11142                 int_fld = strtoul(str_fld[i], &end, 0);
11143                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11144                         return -1;
11145                 flexbytes[i] = (uint8_t)int_fld;
11146         }
11147         return ret;
11148 }
11149
11150 static uint16_t
11151 str2flowtype(char *string)
11152 {
11153         uint8_t i = 0;
11154         static const struct {
11155                 char str[32];
11156                 uint16_t type;
11157         } flowtype_str[] = {
11158                 {"raw", RTE_ETH_FLOW_RAW},
11159                 {"ipv4", RTE_ETH_FLOW_IPV4},
11160                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11161                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11162                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11163                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11164                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11165                 {"ipv6", RTE_ETH_FLOW_IPV6},
11166                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11167                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11168                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11169                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11170                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11171                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11172         };
11173
11174         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11175                 if (!strcmp(flowtype_str[i].str, string))
11176                         return flowtype_str[i].type;
11177         }
11178
11179         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11180                 return (uint16_t)atoi(string);
11181
11182         return RTE_ETH_FLOW_UNKNOWN;
11183 }
11184
11185 static enum rte_eth_fdir_tunnel_type
11186 str2fdir_tunneltype(char *string)
11187 {
11188         uint8_t i = 0;
11189
11190         static const struct {
11191                 char str[32];
11192                 enum rte_eth_fdir_tunnel_type type;
11193         } tunneltype_str[] = {
11194                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11195                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11196         };
11197
11198         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11199                 if (!strcmp(tunneltype_str[i].str, string))
11200                         return tunneltype_str[i].type;
11201         }
11202         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11203 }
11204
11205 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11206 do { \
11207         if ((ip_addr).family == AF_INET) \
11208                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11209         else { \
11210                 printf("invalid parameter.\n"); \
11211                 return; \
11212         } \
11213 } while (0)
11214
11215 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11216 do { \
11217         if ((ip_addr).family == AF_INET6) \
11218                 rte_memcpy(&(ip), \
11219                                  &((ip_addr).addr.ipv6), \
11220                                  sizeof(struct in6_addr)); \
11221         else { \
11222                 printf("invalid parameter.\n"); \
11223                 return; \
11224         } \
11225 } while (0)
11226
11227 static void
11228 cmd_flow_director_filter_parsed(void *parsed_result,
11229                           __rte_unused struct cmdline *cl,
11230                           __rte_unused void *data)
11231 {
11232         struct cmd_flow_director_result *res = parsed_result;
11233         struct rte_eth_fdir_filter entry;
11234         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11235         char *end;
11236         unsigned long vf_id;
11237         int ret = 0;
11238
11239         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11240         if (ret < 0) {
11241                 printf("flow director is not supported on port %u.\n",
11242                         res->port_id);
11243                 return;
11244         }
11245         memset(flexbytes, 0, sizeof(flexbytes));
11246         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11247
11248         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11249                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11250                         printf("Please set mode to MAC-VLAN.\n");
11251                         return;
11252                 }
11253         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11254                 if (strcmp(res->mode_value, "Tunnel")) {
11255                         printf("Please set mode to Tunnel.\n");
11256                         return;
11257                 }
11258         } else {
11259                 if (!strcmp(res->mode_value, "raw")) {
11260 #ifdef RTE_NET_I40E
11261                         struct rte_pmd_i40e_flow_type_mapping
11262                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11263                         struct rte_pmd_i40e_pkt_template_conf conf;
11264                         uint16_t flow_type = str2flowtype(res->flow_type);
11265                         uint16_t i, port = res->port_id;
11266                         uint8_t add;
11267
11268                         memset(&conf, 0, sizeof(conf));
11269
11270                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11271                                 printf("Invalid flow type specified.\n");
11272                                 return;
11273                         }
11274                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11275                                                                  mapping);
11276                         if (ret)
11277                                 return;
11278                         if (mapping[flow_type].pctype == 0ULL) {
11279                                 printf("Invalid flow type specified.\n");
11280                                 return;
11281                         }
11282                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11283                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11284                                         conf.input.pctype = i;
11285                                         break;
11286                                 }
11287                         }
11288
11289                         conf.input.packet = open_file(res->filepath,
11290                                                 &conf.input.length);
11291                         if (!conf.input.packet)
11292                                 return;
11293                         if (!strcmp(res->drop, "drop"))
11294                                 conf.action.behavior =
11295                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11296                         else
11297                                 conf.action.behavior =
11298                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11299                         conf.action.report_status =
11300                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11301                         conf.action.rx_queue = res->queue_id;
11302                         conf.soft_id = res->fd_id_value;
11303                         add  = strcmp(res->ops, "del") ? 1 : 0;
11304                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11305                                                                         &conf,
11306                                                                         add);
11307                         if (ret < 0)
11308                                 printf("flow director config error: (%s)\n",
11309                                        strerror(-ret));
11310                         close_file(conf.input.packet);
11311 #endif
11312                         return;
11313                 } else if (strcmp(res->mode_value, "IP")) {
11314                         printf("Please set mode to IP or raw.\n");
11315                         return;
11316                 }
11317                 entry.input.flow_type = str2flowtype(res->flow_type);
11318         }
11319
11320         ret = parse_flexbytes(res->flexbytes_value,
11321                                         flexbytes,
11322                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11323         if (ret < 0) {
11324                 printf("error: Cannot parse flexbytes input.\n");
11325                 return;
11326         }
11327
11328         switch (entry.input.flow_type) {
11329         case RTE_ETH_FLOW_FRAG_IPV4:
11330         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11331                 entry.input.flow.ip4_flow.proto = res->proto_value;
11332                 /* fall-through */
11333         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11334         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11335                 IPV4_ADDR_TO_UINT(res->ip_dst,
11336                         entry.input.flow.ip4_flow.dst_ip);
11337                 IPV4_ADDR_TO_UINT(res->ip_src,
11338                         entry.input.flow.ip4_flow.src_ip);
11339                 entry.input.flow.ip4_flow.tos = res->tos_value;
11340                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11341                 /* need convert to big endian. */
11342                 entry.input.flow.udp4_flow.dst_port =
11343                                 rte_cpu_to_be_16(res->port_dst);
11344                 entry.input.flow.udp4_flow.src_port =
11345                                 rte_cpu_to_be_16(res->port_src);
11346                 break;
11347         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11348                 IPV4_ADDR_TO_UINT(res->ip_dst,
11349                         entry.input.flow.sctp4_flow.ip.dst_ip);
11350                 IPV4_ADDR_TO_UINT(res->ip_src,
11351                         entry.input.flow.sctp4_flow.ip.src_ip);
11352                 entry.input.flow.ip4_flow.tos = res->tos_value;
11353                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11354                 /* need convert to big endian. */
11355                 entry.input.flow.sctp4_flow.dst_port =
11356                                 rte_cpu_to_be_16(res->port_dst);
11357                 entry.input.flow.sctp4_flow.src_port =
11358                                 rte_cpu_to_be_16(res->port_src);
11359                 entry.input.flow.sctp4_flow.verify_tag =
11360                                 rte_cpu_to_be_32(res->verify_tag_value);
11361                 break;
11362         case RTE_ETH_FLOW_FRAG_IPV6:
11363         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11364                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11365                 /* fall-through */
11366         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11367         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11368                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11369                         entry.input.flow.ipv6_flow.dst_ip);
11370                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11371                         entry.input.flow.ipv6_flow.src_ip);
11372                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11373                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11374                 /* need convert to big endian. */
11375                 entry.input.flow.udp6_flow.dst_port =
11376                                 rte_cpu_to_be_16(res->port_dst);
11377                 entry.input.flow.udp6_flow.src_port =
11378                                 rte_cpu_to_be_16(res->port_src);
11379                 break;
11380         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11381                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11382                         entry.input.flow.sctp6_flow.ip.dst_ip);
11383                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11384                         entry.input.flow.sctp6_flow.ip.src_ip);
11385                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11386                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11387                 /* need convert to big endian. */
11388                 entry.input.flow.sctp6_flow.dst_port =
11389                                 rte_cpu_to_be_16(res->port_dst);
11390                 entry.input.flow.sctp6_flow.src_port =
11391                                 rte_cpu_to_be_16(res->port_src);
11392                 entry.input.flow.sctp6_flow.verify_tag =
11393                                 rte_cpu_to_be_32(res->verify_tag_value);
11394                 break;
11395         case RTE_ETH_FLOW_L2_PAYLOAD:
11396                 entry.input.flow.l2_flow.ether_type =
11397                         rte_cpu_to_be_16(res->ether_type);
11398                 break;
11399         default:
11400                 break;
11401         }
11402
11403         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11404                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11405                                  &res->mac_addr,
11406                                  sizeof(struct rte_ether_addr));
11407
11408         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11409                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11410                                  &res->mac_addr,
11411                                  sizeof(struct rte_ether_addr));
11412                 entry.input.flow.tunnel_flow.tunnel_type =
11413                         str2fdir_tunneltype(res->tunnel_type);
11414                 entry.input.flow.tunnel_flow.tunnel_id =
11415                         rte_cpu_to_be_32(res->tunnel_id_value);
11416         }
11417
11418         rte_memcpy(entry.input.flow_ext.flexbytes,
11419                    flexbytes,
11420                    RTE_ETH_FDIR_MAX_FLEXLEN);
11421
11422         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11423
11424         entry.action.flex_off = 0;  /*use 0 by default */
11425         if (!strcmp(res->drop, "drop"))
11426                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11427         else
11428                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11429
11430         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11431             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11432                 if (!strcmp(res->pf_vf, "pf"))
11433                         entry.input.flow_ext.is_vf = 0;
11434                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11435                         struct rte_eth_dev_info dev_info;
11436
11437                         ret = eth_dev_info_get_print_err(res->port_id,
11438                                                 &dev_info);
11439                         if (ret != 0)
11440                                 return;
11441
11442                         errno = 0;
11443                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11444                         if (errno != 0 || *end != '\0' ||
11445                             vf_id >= dev_info.max_vfs) {
11446                                 printf("invalid parameter %s.\n", res->pf_vf);
11447                                 return;
11448                         }
11449                         entry.input.flow_ext.is_vf = 1;
11450                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11451                 } else {
11452                         printf("invalid parameter %s.\n", res->pf_vf);
11453                         return;
11454                 }
11455         }
11456
11457         /* set to report FD ID by default */
11458         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11459         entry.action.rx_queue = res->queue_id;
11460         entry.soft_id = res->fd_id_value;
11461         if (!strcmp(res->ops, "add"))
11462                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11463                                              RTE_ETH_FILTER_ADD, &entry);
11464         else if (!strcmp(res->ops, "del"))
11465                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11466                                              RTE_ETH_FILTER_DELETE, &entry);
11467         else
11468                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11469                                              RTE_ETH_FILTER_UPDATE, &entry);
11470         if (ret < 0)
11471                 printf("flow director programming error: (%s)\n",
11472                         strerror(-ret));
11473 }
11474
11475 cmdline_parse_token_string_t cmd_flow_director_filter =
11476         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11477                                  flow_director_filter, "flow_director_filter");
11478 cmdline_parse_token_num_t cmd_flow_director_port_id =
11479         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11480                               port_id, UINT16);
11481 cmdline_parse_token_string_t cmd_flow_director_ops =
11482         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11483                                  ops, "add#del#update");
11484 cmdline_parse_token_string_t cmd_flow_director_flow =
11485         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11486                                  flow, "flow");
11487 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11488         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11489                 flow_type, NULL);
11490 cmdline_parse_token_string_t cmd_flow_director_ether =
11491         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11492                                  ether, "ether");
11493 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11494         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11495                               ether_type, UINT16);
11496 cmdline_parse_token_string_t cmd_flow_director_src =
11497         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11498                                  src, "src");
11499 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11500         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11501                                  ip_src);
11502 cmdline_parse_token_num_t cmd_flow_director_port_src =
11503         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11504                               port_src, UINT16);
11505 cmdline_parse_token_string_t cmd_flow_director_dst =
11506         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11507                                  dst, "dst");
11508 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11509         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11510                                  ip_dst);
11511 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11512         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11513                               port_dst, UINT16);
11514 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11515         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11516                                   verify_tag, "verify_tag");
11517 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11518         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11519                               verify_tag_value, UINT32);
11520 cmdline_parse_token_string_t cmd_flow_director_tos =
11521         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11522                                  tos, "tos");
11523 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11524         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11525                               tos_value, UINT8);
11526 cmdline_parse_token_string_t cmd_flow_director_proto =
11527         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11528                                  proto, "proto");
11529 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11530         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11531                               proto_value, UINT8);
11532 cmdline_parse_token_string_t cmd_flow_director_ttl =
11533         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11534                                  ttl, "ttl");
11535 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11536         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11537                               ttl_value, UINT8);
11538 cmdline_parse_token_string_t cmd_flow_director_vlan =
11539         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11540                                  vlan, "vlan");
11541 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11542         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11543                               vlan_value, UINT16);
11544 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11545         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11546                                  flexbytes, "flexbytes");
11547 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11548         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11549                               flexbytes_value, NULL);
11550 cmdline_parse_token_string_t cmd_flow_director_drop =
11551         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11552                                  drop, "drop#fwd");
11553 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11554         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11555                               pf_vf, NULL);
11556 cmdline_parse_token_string_t cmd_flow_director_queue =
11557         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11558                                  queue, "queue");
11559 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11560         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11561                               queue_id, UINT16);
11562 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11563         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11564                                  fd_id, "fd_id");
11565 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11566         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11567                               fd_id_value, UINT32);
11568
11569 cmdline_parse_token_string_t cmd_flow_director_mode =
11570         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11571                                  mode, "mode");
11572 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11573         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11574                                  mode_value, "IP");
11575 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11576         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11577                                  mode_value, "MAC-VLAN");
11578 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11579         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11580                                  mode_value, "Tunnel");
11581 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11582         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11583                                  mode_value, "raw");
11584 cmdline_parse_token_string_t cmd_flow_director_mac =
11585         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11586                                  mac, "mac");
11587 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11588         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11589                                     mac_addr);
11590 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11591         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11592                                  tunnel, "tunnel");
11593 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11594         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11595                                  tunnel_type, "NVGRE#VxLAN");
11596 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11597         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11598                                  tunnel_id, "tunnel-id");
11599 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11600         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11601                               tunnel_id_value, UINT32);
11602 cmdline_parse_token_string_t cmd_flow_director_packet =
11603         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11604                                  packet, "packet");
11605 cmdline_parse_token_string_t cmd_flow_director_filepath =
11606         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11607                                  filepath, NULL);
11608
11609 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11610         .f = cmd_flow_director_filter_parsed,
11611         .data = NULL,
11612         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11613                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11614                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11615                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11616                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11617                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11618                 "fd_id <fd_id_value>: "
11619                 "Add or delete an ip flow director entry on NIC",
11620         .tokens = {
11621                 (void *)&cmd_flow_director_filter,
11622                 (void *)&cmd_flow_director_port_id,
11623                 (void *)&cmd_flow_director_mode,
11624                 (void *)&cmd_flow_director_mode_ip,
11625                 (void *)&cmd_flow_director_ops,
11626                 (void *)&cmd_flow_director_flow,
11627                 (void *)&cmd_flow_director_flow_type,
11628                 (void *)&cmd_flow_director_src,
11629                 (void *)&cmd_flow_director_ip_src,
11630                 (void *)&cmd_flow_director_dst,
11631                 (void *)&cmd_flow_director_ip_dst,
11632                 (void *)&cmd_flow_director_tos,
11633                 (void *)&cmd_flow_director_tos_value,
11634                 (void *)&cmd_flow_director_proto,
11635                 (void *)&cmd_flow_director_proto_value,
11636                 (void *)&cmd_flow_director_ttl,
11637                 (void *)&cmd_flow_director_ttl_value,
11638                 (void *)&cmd_flow_director_vlan,
11639                 (void *)&cmd_flow_director_vlan_value,
11640                 (void *)&cmd_flow_director_flexbytes,
11641                 (void *)&cmd_flow_director_flexbytes_value,
11642                 (void *)&cmd_flow_director_drop,
11643                 (void *)&cmd_flow_director_pf_vf,
11644                 (void *)&cmd_flow_director_queue,
11645                 (void *)&cmd_flow_director_queue_id,
11646                 (void *)&cmd_flow_director_fd_id,
11647                 (void *)&cmd_flow_director_fd_id_value,
11648                 NULL,
11649         },
11650 };
11651
11652 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11653         .f = cmd_flow_director_filter_parsed,
11654         .data = NULL,
11655         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11656                 "director entry on NIC",
11657         .tokens = {
11658                 (void *)&cmd_flow_director_filter,
11659                 (void *)&cmd_flow_director_port_id,
11660                 (void *)&cmd_flow_director_mode,
11661                 (void *)&cmd_flow_director_mode_ip,
11662                 (void *)&cmd_flow_director_ops,
11663                 (void *)&cmd_flow_director_flow,
11664                 (void *)&cmd_flow_director_flow_type,
11665                 (void *)&cmd_flow_director_src,
11666                 (void *)&cmd_flow_director_ip_src,
11667                 (void *)&cmd_flow_director_port_src,
11668                 (void *)&cmd_flow_director_dst,
11669                 (void *)&cmd_flow_director_ip_dst,
11670                 (void *)&cmd_flow_director_port_dst,
11671                 (void *)&cmd_flow_director_tos,
11672                 (void *)&cmd_flow_director_tos_value,
11673                 (void *)&cmd_flow_director_ttl,
11674                 (void *)&cmd_flow_director_ttl_value,
11675                 (void *)&cmd_flow_director_vlan,
11676                 (void *)&cmd_flow_director_vlan_value,
11677                 (void *)&cmd_flow_director_flexbytes,
11678                 (void *)&cmd_flow_director_flexbytes_value,
11679                 (void *)&cmd_flow_director_drop,
11680                 (void *)&cmd_flow_director_pf_vf,
11681                 (void *)&cmd_flow_director_queue,
11682                 (void *)&cmd_flow_director_queue_id,
11683                 (void *)&cmd_flow_director_fd_id,
11684                 (void *)&cmd_flow_director_fd_id_value,
11685                 NULL,
11686         },
11687 };
11688
11689 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11690         .f = cmd_flow_director_filter_parsed,
11691         .data = NULL,
11692         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11693                 "director entry on NIC",
11694         .tokens = {
11695                 (void *)&cmd_flow_director_filter,
11696                 (void *)&cmd_flow_director_port_id,
11697                 (void *)&cmd_flow_director_mode,
11698                 (void *)&cmd_flow_director_mode_ip,
11699                 (void *)&cmd_flow_director_ops,
11700                 (void *)&cmd_flow_director_flow,
11701                 (void *)&cmd_flow_director_flow_type,
11702                 (void *)&cmd_flow_director_src,
11703                 (void *)&cmd_flow_director_ip_src,
11704                 (void *)&cmd_flow_director_port_src,
11705                 (void *)&cmd_flow_director_dst,
11706                 (void *)&cmd_flow_director_ip_dst,
11707                 (void *)&cmd_flow_director_port_dst,
11708                 (void *)&cmd_flow_director_verify_tag,
11709                 (void *)&cmd_flow_director_verify_tag_value,
11710                 (void *)&cmd_flow_director_tos,
11711                 (void *)&cmd_flow_director_tos_value,
11712                 (void *)&cmd_flow_director_ttl,
11713                 (void *)&cmd_flow_director_ttl_value,
11714                 (void *)&cmd_flow_director_vlan,
11715                 (void *)&cmd_flow_director_vlan_value,
11716                 (void *)&cmd_flow_director_flexbytes,
11717                 (void *)&cmd_flow_director_flexbytes_value,
11718                 (void *)&cmd_flow_director_drop,
11719                 (void *)&cmd_flow_director_pf_vf,
11720                 (void *)&cmd_flow_director_queue,
11721                 (void *)&cmd_flow_director_queue_id,
11722                 (void *)&cmd_flow_director_fd_id,
11723                 (void *)&cmd_flow_director_fd_id_value,
11724                 NULL,
11725         },
11726 };
11727
11728 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11729         .f = cmd_flow_director_filter_parsed,
11730         .data = NULL,
11731         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11732                 "director entry on NIC",
11733         .tokens = {
11734                 (void *)&cmd_flow_director_filter,
11735                 (void *)&cmd_flow_director_port_id,
11736                 (void *)&cmd_flow_director_mode,
11737                 (void *)&cmd_flow_director_mode_ip,
11738                 (void *)&cmd_flow_director_ops,
11739                 (void *)&cmd_flow_director_flow,
11740                 (void *)&cmd_flow_director_flow_type,
11741                 (void *)&cmd_flow_director_ether,
11742                 (void *)&cmd_flow_director_ether_type,
11743                 (void *)&cmd_flow_director_flexbytes,
11744                 (void *)&cmd_flow_director_flexbytes_value,
11745                 (void *)&cmd_flow_director_drop,
11746                 (void *)&cmd_flow_director_pf_vf,
11747                 (void *)&cmd_flow_director_queue,
11748                 (void *)&cmd_flow_director_queue_id,
11749                 (void *)&cmd_flow_director_fd_id,
11750                 (void *)&cmd_flow_director_fd_id_value,
11751                 NULL,
11752         },
11753 };
11754
11755 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11756         .f = cmd_flow_director_filter_parsed,
11757         .data = NULL,
11758         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11759                 "director entry on NIC",
11760         .tokens = {
11761                 (void *)&cmd_flow_director_filter,
11762                 (void *)&cmd_flow_director_port_id,
11763                 (void *)&cmd_flow_director_mode,
11764                 (void *)&cmd_flow_director_mode_mac_vlan,
11765                 (void *)&cmd_flow_director_ops,
11766                 (void *)&cmd_flow_director_mac,
11767                 (void *)&cmd_flow_director_mac_addr,
11768                 (void *)&cmd_flow_director_vlan,
11769                 (void *)&cmd_flow_director_vlan_value,
11770                 (void *)&cmd_flow_director_flexbytes,
11771                 (void *)&cmd_flow_director_flexbytes_value,
11772                 (void *)&cmd_flow_director_drop,
11773                 (void *)&cmd_flow_director_queue,
11774                 (void *)&cmd_flow_director_queue_id,
11775                 (void *)&cmd_flow_director_fd_id,
11776                 (void *)&cmd_flow_director_fd_id_value,
11777                 NULL,
11778         },
11779 };
11780
11781 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11782         .f = cmd_flow_director_filter_parsed,
11783         .data = NULL,
11784         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11785                 "director entry on NIC",
11786         .tokens = {
11787                 (void *)&cmd_flow_director_filter,
11788                 (void *)&cmd_flow_director_port_id,
11789                 (void *)&cmd_flow_director_mode,
11790                 (void *)&cmd_flow_director_mode_tunnel,
11791                 (void *)&cmd_flow_director_ops,
11792                 (void *)&cmd_flow_director_mac,
11793                 (void *)&cmd_flow_director_mac_addr,
11794                 (void *)&cmd_flow_director_vlan,
11795                 (void *)&cmd_flow_director_vlan_value,
11796                 (void *)&cmd_flow_director_tunnel,
11797                 (void *)&cmd_flow_director_tunnel_type,
11798                 (void *)&cmd_flow_director_tunnel_id,
11799                 (void *)&cmd_flow_director_tunnel_id_value,
11800                 (void *)&cmd_flow_director_flexbytes,
11801                 (void *)&cmd_flow_director_flexbytes_value,
11802                 (void *)&cmd_flow_director_drop,
11803                 (void *)&cmd_flow_director_queue,
11804                 (void *)&cmd_flow_director_queue_id,
11805                 (void *)&cmd_flow_director_fd_id,
11806                 (void *)&cmd_flow_director_fd_id_value,
11807                 NULL,
11808         },
11809 };
11810
11811 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11812         .f = cmd_flow_director_filter_parsed,
11813         .data = NULL,
11814         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11815                 "director entry on NIC",
11816         .tokens = {
11817                 (void *)&cmd_flow_director_filter,
11818                 (void *)&cmd_flow_director_port_id,
11819                 (void *)&cmd_flow_director_mode,
11820                 (void *)&cmd_flow_director_mode_raw,
11821                 (void *)&cmd_flow_director_ops,
11822                 (void *)&cmd_flow_director_flow,
11823                 (void *)&cmd_flow_director_flow_type,
11824                 (void *)&cmd_flow_director_drop,
11825                 (void *)&cmd_flow_director_queue,
11826                 (void *)&cmd_flow_director_queue_id,
11827                 (void *)&cmd_flow_director_fd_id,
11828                 (void *)&cmd_flow_director_fd_id_value,
11829                 (void *)&cmd_flow_director_packet,
11830                 (void *)&cmd_flow_director_filepath,
11831                 NULL,
11832         },
11833 };
11834
11835 struct cmd_flush_flow_director_result {
11836         cmdline_fixed_string_t flush_flow_director;
11837         portid_t port_id;
11838 };
11839
11840 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11841         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11842                                  flush_flow_director, "flush_flow_director");
11843 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11844         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11845                               port_id, UINT16);
11846
11847 static void
11848 cmd_flush_flow_director_parsed(void *parsed_result,
11849                           __rte_unused struct cmdline *cl,
11850                           __rte_unused void *data)
11851 {
11852         struct cmd_flow_director_result *res = parsed_result;
11853         int ret = 0;
11854
11855         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11856         if (ret < 0) {
11857                 printf("flow director is not supported on port %u.\n",
11858                         res->port_id);
11859                 return;
11860         }
11861
11862         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11863                         RTE_ETH_FILTER_FLUSH, NULL);
11864         if (ret < 0)
11865                 printf("flow director table flushing error: (%s)\n",
11866                         strerror(-ret));
11867 }
11868
11869 cmdline_parse_inst_t cmd_flush_flow_director = {
11870         .f = cmd_flush_flow_director_parsed,
11871         .data = NULL,
11872         .help_str = "flush_flow_director <port_id>: "
11873                 "Flush all flow director entries of a device on NIC",
11874         .tokens = {
11875                 (void *)&cmd_flush_flow_director_flush,
11876                 (void *)&cmd_flush_flow_director_port_id,
11877                 NULL,
11878         },
11879 };
11880
11881 /* *** deal with flow director mask *** */
11882 struct cmd_flow_director_mask_result {
11883         cmdline_fixed_string_t flow_director_mask;
11884         portid_t port_id;
11885         cmdline_fixed_string_t mode;
11886         cmdline_fixed_string_t mode_value;
11887         cmdline_fixed_string_t vlan;
11888         uint16_t vlan_mask;
11889         cmdline_fixed_string_t src_mask;
11890         cmdline_ipaddr_t ipv4_src;
11891         cmdline_ipaddr_t ipv6_src;
11892         uint16_t port_src;
11893         cmdline_fixed_string_t dst_mask;
11894         cmdline_ipaddr_t ipv4_dst;
11895         cmdline_ipaddr_t ipv6_dst;
11896         uint16_t port_dst;
11897         cmdline_fixed_string_t mac;
11898         uint8_t mac_addr_byte_mask;
11899         cmdline_fixed_string_t tunnel_id;
11900         uint32_t tunnel_id_mask;
11901         cmdline_fixed_string_t tunnel_type;
11902         uint8_t tunnel_type_mask;
11903 };
11904
11905 static void
11906 cmd_flow_director_mask_parsed(void *parsed_result,
11907                           __rte_unused struct cmdline *cl,
11908                           __rte_unused void *data)
11909 {
11910         struct cmd_flow_director_mask_result *res = parsed_result;
11911         struct rte_eth_fdir_masks *mask;
11912         struct rte_port *port;
11913
11914         port = &ports[res->port_id];
11915         /** Check if the port is not started **/
11916         if (port->port_status != RTE_PORT_STOPPED) {
11917                 printf("Please stop port %d first\n", res->port_id);
11918                 return;
11919         }
11920
11921         mask = &port->dev_conf.fdir_conf.mask;
11922
11923         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11924                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11925                         printf("Please set mode to MAC-VLAN.\n");
11926                         return;
11927                 }
11928
11929                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11930         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11931                 if (strcmp(res->mode_value, "Tunnel")) {
11932                         printf("Please set mode to Tunnel.\n");
11933                         return;
11934                 }
11935
11936                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11937                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11938                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11939                 mask->tunnel_type_mask = res->tunnel_type_mask;
11940         } else {
11941                 if (strcmp(res->mode_value, "IP")) {
11942                         printf("Please set mode to IP.\n");
11943                         return;
11944                 }
11945
11946                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11947                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11948                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11949                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11950                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11951                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11952                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11953         }
11954
11955         cmd_reconfig_device_queue(res->port_id, 1, 1);
11956 }
11957
11958 cmdline_parse_token_string_t cmd_flow_director_mask =
11959         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11960                                  flow_director_mask, "flow_director_mask");
11961 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11962         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11963                               port_id, UINT16);
11964 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11965         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11966                                  vlan, "vlan");
11967 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11968         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11969                               vlan_mask, UINT16);
11970 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11971         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11972                                  src_mask, "src_mask");
11973 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11974         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11975                                  ipv4_src);
11976 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11977         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11978                                  ipv6_src);
11979 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11980         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11981                               port_src, UINT16);
11982 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11983         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11984                                  dst_mask, "dst_mask");
11985 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11986         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11987                                  ipv4_dst);
11988 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11989         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11990                                  ipv6_dst);
11991 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11992         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11993                               port_dst, UINT16);
11994
11995 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11996         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11997                                  mode, "mode");
11998 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11999         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12000                                  mode_value, "IP");
12001 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
12002         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12003                                  mode_value, "MAC-VLAN");
12004 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
12005         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12006                                  mode_value, "Tunnel");
12007 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
12008         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12009                                  mac, "mac");
12010 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
12011         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12012                               mac_addr_byte_mask, UINT8);
12013 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
12014         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12015                                  tunnel_type, "tunnel-type");
12016 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
12017         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12018                               tunnel_type_mask, UINT8);
12019 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
12020         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12021                                  tunnel_id, "tunnel-id");
12022 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
12023         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12024                               tunnel_id_mask, UINT32);
12025
12026 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
12027         .f = cmd_flow_director_mask_parsed,
12028         .data = NULL,
12029         .help_str = "flow_director_mask ... : "
12030                 "Set IP mode flow director's mask on NIC",
12031         .tokens = {
12032                 (void *)&cmd_flow_director_mask,
12033                 (void *)&cmd_flow_director_mask_port_id,
12034                 (void *)&cmd_flow_director_mask_mode,
12035                 (void *)&cmd_flow_director_mask_mode_ip,
12036                 (void *)&cmd_flow_director_mask_vlan,
12037                 (void *)&cmd_flow_director_mask_vlan_value,
12038                 (void *)&cmd_flow_director_mask_src,
12039                 (void *)&cmd_flow_director_mask_ipv4_src,
12040                 (void *)&cmd_flow_director_mask_ipv6_src,
12041                 (void *)&cmd_flow_director_mask_port_src,
12042                 (void *)&cmd_flow_director_mask_dst,
12043                 (void *)&cmd_flow_director_mask_ipv4_dst,
12044                 (void *)&cmd_flow_director_mask_ipv6_dst,
12045                 (void *)&cmd_flow_director_mask_port_dst,
12046                 NULL,
12047         },
12048 };
12049
12050 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
12051         .f = cmd_flow_director_mask_parsed,
12052         .data = NULL,
12053         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
12054                 "flow director's mask on NIC",
12055         .tokens = {
12056                 (void *)&cmd_flow_director_mask,
12057                 (void *)&cmd_flow_director_mask_port_id,
12058                 (void *)&cmd_flow_director_mask_mode,
12059                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
12060                 (void *)&cmd_flow_director_mask_vlan,
12061                 (void *)&cmd_flow_director_mask_vlan_value,
12062                 NULL,
12063         },
12064 };
12065
12066 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
12067         .f = cmd_flow_director_mask_parsed,
12068         .data = NULL,
12069         .help_str = "flow_director_mask ... : Set tunnel mode "
12070                 "flow director's mask on NIC",
12071         .tokens = {
12072                 (void *)&cmd_flow_director_mask,
12073                 (void *)&cmd_flow_director_mask_port_id,
12074                 (void *)&cmd_flow_director_mask_mode,
12075                 (void *)&cmd_flow_director_mask_mode_tunnel,
12076                 (void *)&cmd_flow_director_mask_vlan,
12077                 (void *)&cmd_flow_director_mask_vlan_value,
12078                 (void *)&cmd_flow_director_mask_mac,
12079                 (void *)&cmd_flow_director_mask_mac_value,
12080                 (void *)&cmd_flow_director_mask_tunnel_type,
12081                 (void *)&cmd_flow_director_mask_tunnel_type_value,
12082                 (void *)&cmd_flow_director_mask_tunnel_id,
12083                 (void *)&cmd_flow_director_mask_tunnel_id_value,
12084                 NULL,
12085         },
12086 };
12087
12088 /* *** deal with flow director mask on flexible payload *** */
12089 struct cmd_flow_director_flex_mask_result {
12090         cmdline_fixed_string_t flow_director_flexmask;
12091         portid_t port_id;
12092         cmdline_fixed_string_t flow;
12093         cmdline_fixed_string_t flow_type;
12094         cmdline_fixed_string_t mask;
12095 };
12096
12097 static void
12098 cmd_flow_director_flex_mask_parsed(void *parsed_result,
12099                           __rte_unused struct cmdline *cl,
12100                           __rte_unused void *data)
12101 {
12102         struct cmd_flow_director_flex_mask_result *res = parsed_result;
12103         struct rte_eth_fdir_info fdir_info;
12104         struct rte_eth_fdir_flex_mask flex_mask;
12105         struct rte_port *port;
12106         uint64_t flow_type_mask;
12107         uint16_t i;
12108         int ret;
12109
12110         port = &ports[res->port_id];
12111         /** Check if the port is not started **/
12112         if (port->port_status != RTE_PORT_STOPPED) {
12113                 printf("Please stop port %d first\n", res->port_id);
12114                 return;
12115         }
12116
12117         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
12118         ret = parse_flexbytes(res->mask,
12119                         flex_mask.mask,
12120                         RTE_ETH_FDIR_MAX_FLEXLEN);
12121         if (ret < 0) {
12122                 printf("error: Cannot parse mask input.\n");
12123                 return;
12124         }
12125
12126         memset(&fdir_info, 0, sizeof(fdir_info));
12127         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12128                                 RTE_ETH_FILTER_INFO, &fdir_info);
12129         if (ret < 0) {
12130                 printf("Cannot get FDir filter info\n");
12131                 return;
12132         }
12133
12134         if (!strcmp(res->flow_type, "none")) {
12135                 /* means don't specify the flow type */
12136                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
12137                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
12138                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12139                                0, sizeof(struct rte_eth_fdir_flex_mask));
12140                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12141                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12142                                  &flex_mask,
12143                                  sizeof(struct rte_eth_fdir_flex_mask));
12144                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12145                 return;
12146         }
12147         flow_type_mask = fdir_info.flow_types_mask[0];
12148         if (!strcmp(res->flow_type, "all")) {
12149                 if (!flow_type_mask) {
12150                         printf("No flow type supported\n");
12151                         return;
12152                 }
12153                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12154                         if (flow_type_mask & (1ULL << i)) {
12155                                 flex_mask.flow_type = i;
12156                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12157                         }
12158                 }
12159                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12160                 return;
12161         }
12162         flex_mask.flow_type = str2flowtype(res->flow_type);
12163         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12164                 printf("Flow type %s not supported on port %d\n",
12165                                 res->flow_type, res->port_id);
12166                 return;
12167         }
12168         fdir_set_flex_mask(res->port_id, &flex_mask);
12169         cmd_reconfig_device_queue(res->port_id, 1, 1);
12170 }
12171
12172 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12173         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12174                                  flow_director_flexmask,
12175                                  "flow_director_flex_mask");
12176 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12177         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12178                               port_id, UINT16);
12179 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12180         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12181                                  flow, "flow");
12182 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12183         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12184                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12185                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12186 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12187         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12188                                  mask, NULL);
12189
12190 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12191         .f = cmd_flow_director_flex_mask_parsed,
12192         .data = NULL,
12193         .help_str = "flow_director_flex_mask ... : "
12194                 "Set flow director's flex mask on NIC",
12195         .tokens = {
12196                 (void *)&cmd_flow_director_flexmask,
12197                 (void *)&cmd_flow_director_flexmask_port_id,
12198                 (void *)&cmd_flow_director_flexmask_flow,
12199                 (void *)&cmd_flow_director_flexmask_flow_type,
12200                 (void *)&cmd_flow_director_flexmask_mask,
12201                 NULL,
12202         },
12203 };
12204
12205 /* *** deal with flow director flexible payload configuration *** */
12206 struct cmd_flow_director_flexpayload_result {
12207         cmdline_fixed_string_t flow_director_flexpayload;
12208         portid_t port_id;
12209         cmdline_fixed_string_t payload_layer;
12210         cmdline_fixed_string_t payload_cfg;
12211 };
12212
12213 static inline int
12214 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12215 {
12216         char s[256];
12217         const char *p, *p0 = q_arg;
12218         char *end;
12219         unsigned long int_fld;
12220         char *str_fld[max_num];
12221         int i;
12222         unsigned size;
12223         int ret = -1;
12224
12225         p = strchr(p0, '(');
12226         if (p == NULL)
12227                 return -1;
12228         ++p;
12229         p0 = strchr(p, ')');
12230         if (p0 == NULL)
12231                 return -1;
12232
12233         size = p0 - p;
12234         if (size >= sizeof(s))
12235                 return -1;
12236
12237         snprintf(s, sizeof(s), "%.*s", size, p);
12238         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12239         if (ret < 0 || ret > max_num)
12240                 return -1;
12241         for (i = 0; i < ret; i++) {
12242                 errno = 0;
12243                 int_fld = strtoul(str_fld[i], &end, 0);
12244                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12245                         return -1;
12246                 offsets[i] = (uint16_t)int_fld;
12247         }
12248         return ret;
12249 }
12250
12251 static void
12252 cmd_flow_director_flxpld_parsed(void *parsed_result,
12253                           __rte_unused struct cmdline *cl,
12254                           __rte_unused void *data)
12255 {
12256         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12257         struct rte_eth_flex_payload_cfg flex_cfg;
12258         struct rte_port *port;
12259         int ret = 0;
12260
12261         port = &ports[res->port_id];
12262         /** Check if the port is not started **/
12263         if (port->port_status != RTE_PORT_STOPPED) {
12264                 printf("Please stop port %d first\n", res->port_id);
12265                 return;
12266         }
12267
12268         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12269
12270         if (!strcmp(res->payload_layer, "raw"))
12271                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12272         else if (!strcmp(res->payload_layer, "l2"))
12273                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12274         else if (!strcmp(res->payload_layer, "l3"))
12275                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12276         else if (!strcmp(res->payload_layer, "l4"))
12277                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12278
12279         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12280                             RTE_ETH_FDIR_MAX_FLEXLEN);
12281         if (ret < 0) {
12282                 printf("error: Cannot parse flex payload input.\n");
12283                 return;
12284         }
12285
12286         fdir_set_flex_payload(res->port_id, &flex_cfg);
12287         cmd_reconfig_device_queue(res->port_id, 1, 1);
12288 }
12289
12290 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12291         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12292                                  flow_director_flexpayload,
12293                                  "flow_director_flex_payload");
12294 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12295         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12296                               port_id, UINT16);
12297 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12298         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12299                                  payload_layer, "raw#l2#l3#l4");
12300 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12301         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12302                                  payload_cfg, NULL);
12303
12304 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12305         .f = cmd_flow_director_flxpld_parsed,
12306         .data = NULL,
12307         .help_str = "flow_director_flexpayload ... : "
12308                 "Set flow director's flex payload on NIC",
12309         .tokens = {
12310                 (void *)&cmd_flow_director_flexpayload,
12311                 (void *)&cmd_flow_director_flexpayload_port_id,
12312                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12313                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12314                 NULL,
12315         },
12316 };
12317
12318 /* Generic flow interface command. */
12319 extern cmdline_parse_inst_t cmd_flow;
12320
12321 /* *** Classification Filters Control *** */
12322 /* *** Get symmetric hash enable per port *** */
12323 struct cmd_get_sym_hash_ena_per_port_result {
12324         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12325         portid_t port_id;
12326 };
12327
12328 static void
12329 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12330                                  __rte_unused struct cmdline *cl,
12331                                  __rte_unused void *data)
12332 {
12333         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12334         struct rte_eth_hash_filter_info info;
12335         int ret;
12336
12337         if (rte_eth_dev_filter_supported(res->port_id,
12338                                 RTE_ETH_FILTER_HASH) < 0) {
12339                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12340                                                         res->port_id);
12341                 return;
12342         }
12343
12344         memset(&info, 0, sizeof(info));
12345         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12346         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12347                                                 RTE_ETH_FILTER_GET, &info);
12348
12349         if (ret < 0) {
12350                 printf("Cannot get symmetric hash enable per port "
12351                                         "on port %u\n", res->port_id);
12352                 return;
12353         }
12354
12355         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12356                                 "enabled" : "disabled", res->port_id);
12357 }
12358
12359 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12360         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12361                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12362 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12363         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12364                 port_id, UINT16);
12365
12366 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12367         .f = cmd_get_sym_hash_per_port_parsed,
12368         .data = NULL,
12369         .help_str = "get_sym_hash_ena_per_port <port_id>",
12370         .tokens = {
12371                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12372                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12373                 NULL,
12374         },
12375 };
12376
12377 /* *** Set symmetric hash enable per port *** */
12378 struct cmd_set_sym_hash_ena_per_port_result {
12379         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12380         cmdline_fixed_string_t enable;
12381         portid_t port_id;
12382 };
12383
12384 static void
12385 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12386                                  __rte_unused struct cmdline *cl,
12387                                  __rte_unused void *data)
12388 {
12389         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12390         struct rte_eth_hash_filter_info info;
12391         int ret;
12392
12393         if (rte_eth_dev_filter_supported(res->port_id,
12394                                 RTE_ETH_FILTER_HASH) < 0) {
12395                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12396                                                         res->port_id);
12397                 return;
12398         }
12399
12400         memset(&info, 0, sizeof(info));
12401         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12402         if (!strcmp(res->enable, "enable"))
12403                 info.info.enable = 1;
12404         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12405                                         RTE_ETH_FILTER_SET, &info);
12406         if (ret < 0) {
12407                 printf("Cannot set symmetric hash enable per port on "
12408                                         "port %u\n", res->port_id);
12409                 return;
12410         }
12411         printf("Symmetric hash has been set to %s on port %u\n",
12412                                         res->enable, res->port_id);
12413 }
12414
12415 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12416         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12417                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12418 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12419         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12420                 port_id, UINT16);
12421 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12422         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12423                 enable, "enable#disable");
12424
12425 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12426         .f = cmd_set_sym_hash_per_port_parsed,
12427         .data = NULL,
12428         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12429         .tokens = {
12430                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12431                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12432                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12433                 NULL,
12434         },
12435 };
12436
12437 /* Get global config of hash function */
12438 struct cmd_get_hash_global_config_result {
12439         cmdline_fixed_string_t get_hash_global_config;
12440         portid_t port_id;
12441 };
12442
12443 static char *
12444 flowtype_to_str(uint16_t ftype)
12445 {
12446         uint16_t i;
12447         static struct {
12448                 char str[16];
12449                 uint16_t ftype;
12450         } ftype_table[] = {
12451                 {"ipv4", RTE_ETH_FLOW_IPV4},
12452                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12453                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12454                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12455                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12456                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12457                 {"ipv6", RTE_ETH_FLOW_IPV6},
12458                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12459                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12460                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12461                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12462                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12463                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12464                 {"port", RTE_ETH_FLOW_PORT},
12465                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12466                 {"geneve", RTE_ETH_FLOW_GENEVE},
12467                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12468                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12469         };
12470
12471         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12472                 if (ftype_table[i].ftype == ftype)
12473                         return ftype_table[i].str;
12474         }
12475
12476         return NULL;
12477 }
12478
12479 static void
12480 cmd_get_hash_global_config_parsed(void *parsed_result,
12481                                   __rte_unused struct cmdline *cl,
12482                                   __rte_unused void *data)
12483 {
12484         struct cmd_get_hash_global_config_result *res = parsed_result;
12485         struct rte_eth_hash_filter_info info;
12486         uint32_t idx, offset;
12487         uint16_t i;
12488         char *str;
12489         int ret;
12490
12491         if (rte_eth_dev_filter_supported(res->port_id,
12492                         RTE_ETH_FILTER_HASH) < 0) {
12493                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12494                                                         res->port_id);
12495                 return;
12496         }
12497
12498         memset(&info, 0, sizeof(info));
12499         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12500         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12501                                         RTE_ETH_FILTER_GET, &info);
12502         if (ret < 0) {
12503                 printf("Cannot get hash global configurations by port %d\n",
12504                                                         res->port_id);
12505                 return;
12506         }
12507
12508         switch (info.info.global_conf.hash_func) {
12509         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12510                 printf("Hash function is Toeplitz\n");
12511                 break;
12512         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12513                 printf("Hash function is Simple XOR\n");
12514                 break;
12515         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12516                 printf("Hash function is Symmetric Toeplitz\n");
12517                 break;
12518         default:
12519                 printf("Unknown hash function\n");
12520                 break;
12521         }
12522
12523         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12524                 idx = i / UINT64_BIT;
12525                 offset = i % UINT64_BIT;
12526                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12527                                                 (1ULL << offset)))
12528                         continue;
12529                 str = flowtype_to_str(i);
12530                 if (!str)
12531                         continue;
12532                 printf("Symmetric hash is %s globally for flow type %s "
12533                                                         "by port %d\n",
12534                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12535                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12536                                                         res->port_id);
12537         }
12538 }
12539
12540 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12541         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12542                 get_hash_global_config, "get_hash_global_config");
12543 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12544         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12545                 port_id, UINT16);
12546
12547 cmdline_parse_inst_t cmd_get_hash_global_config = {
12548         .f = cmd_get_hash_global_config_parsed,
12549         .data = NULL,
12550         .help_str = "get_hash_global_config <port_id>",
12551         .tokens = {
12552                 (void *)&cmd_get_hash_global_config_all,
12553                 (void *)&cmd_get_hash_global_config_port_id,
12554                 NULL,
12555         },
12556 };
12557
12558 /* Set global config of hash function */
12559 struct cmd_set_hash_global_config_result {
12560         cmdline_fixed_string_t set_hash_global_config;
12561         portid_t port_id;
12562         cmdline_fixed_string_t hash_func;
12563         cmdline_fixed_string_t flow_type;
12564         cmdline_fixed_string_t enable;
12565 };
12566
12567 static void
12568 cmd_set_hash_global_config_parsed(void *parsed_result,
12569                                   __rte_unused struct cmdline *cl,
12570                                   __rte_unused void *data)
12571 {
12572         struct cmd_set_hash_global_config_result *res = parsed_result;
12573         struct rte_eth_hash_filter_info info;
12574         uint32_t ftype, idx, offset;
12575         int ret;
12576
12577         if (rte_eth_dev_filter_supported(res->port_id,
12578                                 RTE_ETH_FILTER_HASH) < 0) {
12579                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12580                                                         res->port_id);
12581                 return;
12582         }
12583         memset(&info, 0, sizeof(info));
12584         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12585         if (!strcmp(res->hash_func, "toeplitz"))
12586                 info.info.global_conf.hash_func =
12587                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12588         else if (!strcmp(res->hash_func, "simple_xor"))
12589                 info.info.global_conf.hash_func =
12590                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12591         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12592                 info.info.global_conf.hash_func =
12593                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12594         else if (!strcmp(res->hash_func, "default"))
12595                 info.info.global_conf.hash_func =
12596                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12597
12598         ftype = str2flowtype(res->flow_type);
12599         idx = ftype / UINT64_BIT;
12600         offset = ftype % UINT64_BIT;
12601         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12602         if (!strcmp(res->enable, "enable"))
12603                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12604                                                 (1ULL << offset);
12605         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12606                                         RTE_ETH_FILTER_SET, &info);
12607         if (ret < 0)
12608                 printf("Cannot set global hash configurations by port %d\n",
12609                                                         res->port_id);
12610         else
12611                 printf("Global hash configurations have been set "
12612                         "successfully by port %d\n", res->port_id);
12613 }
12614
12615 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12616         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12617                 set_hash_global_config, "set_hash_global_config");
12618 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12619         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12620                 port_id, UINT16);
12621 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12622         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12623                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12624 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12625         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12626                 flow_type,
12627                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12628                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12629 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12630         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12631                 enable, "enable#disable");
12632
12633 cmdline_parse_inst_t cmd_set_hash_global_config = {
12634         .f = cmd_set_hash_global_config_parsed,
12635         .data = NULL,
12636         .help_str = "set_hash_global_config <port_id> "
12637                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12638                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12639                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12640                 "l2_payload enable|disable",
12641         .tokens = {
12642                 (void *)&cmd_set_hash_global_config_all,
12643                 (void *)&cmd_set_hash_global_config_port_id,
12644                 (void *)&cmd_set_hash_global_config_hash_func,
12645                 (void *)&cmd_set_hash_global_config_flow_type,
12646                 (void *)&cmd_set_hash_global_config_enable,
12647                 NULL,
12648         },
12649 };
12650
12651 /* Set hash input set */
12652 struct cmd_set_hash_input_set_result {
12653         cmdline_fixed_string_t set_hash_input_set;
12654         portid_t port_id;
12655         cmdline_fixed_string_t flow_type;
12656         cmdline_fixed_string_t inset_field;
12657         cmdline_fixed_string_t select;
12658 };
12659
12660 static enum rte_eth_input_set_field
12661 str2inset(char *string)
12662 {
12663         uint16_t i;
12664
12665         static const struct {
12666                 char str[32];
12667                 enum rte_eth_input_set_field inset;
12668         } inset_table[] = {
12669                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12670                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12671                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12672                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12673                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12674                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12675                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12676                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12677                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12678                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12679                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12680                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12681                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12682                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12683                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12684                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12685                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12686                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12687                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12688                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12689                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12690                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12691                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12692                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12693                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12694                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12695                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12696                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12697                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12698                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12699                 {"none", RTE_ETH_INPUT_SET_NONE},
12700         };
12701
12702         for (i = 0; i < RTE_DIM(inset_table); i++) {
12703                 if (!strcmp(string, inset_table[i].str))
12704                         return inset_table[i].inset;
12705         }
12706
12707         return RTE_ETH_INPUT_SET_UNKNOWN;
12708 }
12709
12710 static void
12711 cmd_set_hash_input_set_parsed(void *parsed_result,
12712                               __rte_unused struct cmdline *cl,
12713                               __rte_unused void *data)
12714 {
12715         struct cmd_set_hash_input_set_result *res = parsed_result;
12716         struct rte_eth_hash_filter_info info;
12717
12718         memset(&info, 0, sizeof(info));
12719         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12720         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12721         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12722         info.info.input_set_conf.inset_size = 1;
12723         if (!strcmp(res->select, "select"))
12724                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12725         else if (!strcmp(res->select, "add"))
12726                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12727         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12728                                 RTE_ETH_FILTER_SET, &info);
12729 }
12730
12731 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12732         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12733                 set_hash_input_set, "set_hash_input_set");
12734 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12735         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12736                 port_id, UINT16);
12737 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12738         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12739                 flow_type, NULL);
12740 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12741         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12742                 inset_field,
12743                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12744                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12745                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12746                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12747                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12748                 "fld-8th#none");
12749 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12750         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12751                 select, "select#add");
12752
12753 cmdline_parse_inst_t cmd_set_hash_input_set = {
12754         .f = cmd_set_hash_input_set_parsed,
12755         .data = NULL,
12756         .help_str = "set_hash_input_set <port_id> "
12757         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12758         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12759         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12760         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12761         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12762         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12763         "fld-7th|fld-8th|none select|add",
12764         .tokens = {
12765                 (void *)&cmd_set_hash_input_set_cmd,
12766                 (void *)&cmd_set_hash_input_set_port_id,
12767                 (void *)&cmd_set_hash_input_set_flow_type,
12768                 (void *)&cmd_set_hash_input_set_field,
12769                 (void *)&cmd_set_hash_input_set_select,
12770                 NULL,
12771         },
12772 };
12773
12774 /* Set flow director input set */
12775 struct cmd_set_fdir_input_set_result {
12776         cmdline_fixed_string_t set_fdir_input_set;
12777         portid_t port_id;
12778         cmdline_fixed_string_t flow_type;
12779         cmdline_fixed_string_t inset_field;
12780         cmdline_fixed_string_t select;
12781 };
12782
12783 static void
12784 cmd_set_fdir_input_set_parsed(void *parsed_result,
12785         __rte_unused struct cmdline *cl,
12786         __rte_unused void *data)
12787 {
12788         struct cmd_set_fdir_input_set_result *res = parsed_result;
12789         struct rte_eth_fdir_filter_info info;
12790
12791         memset(&info, 0, sizeof(info));
12792         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12793         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12794         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12795         info.info.input_set_conf.inset_size = 1;
12796         if (!strcmp(res->select, "select"))
12797                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12798         else if (!strcmp(res->select, "add"))
12799                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12800         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12801                 RTE_ETH_FILTER_SET, &info);
12802 }
12803
12804 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12805         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12806         set_fdir_input_set, "set_fdir_input_set");
12807 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12808         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12809         port_id, UINT16);
12810 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12811         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12812         flow_type,
12813         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12814         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12815 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12816         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12817         inset_field,
12818         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12819         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12820         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12821         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12822         "sctp-veri-tag#none");
12823 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12824         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12825         select, "select#add");
12826
12827 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12828         .f = cmd_set_fdir_input_set_parsed,
12829         .data = NULL,
12830         .help_str = "set_fdir_input_set <port_id> "
12831         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12832         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12833         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12834         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12835         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12836         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12837         "sctp-veri-tag|none select|add",
12838         .tokens = {
12839                 (void *)&cmd_set_fdir_input_set_cmd,
12840                 (void *)&cmd_set_fdir_input_set_port_id,
12841                 (void *)&cmd_set_fdir_input_set_flow_type,
12842                 (void *)&cmd_set_fdir_input_set_field,
12843                 (void *)&cmd_set_fdir_input_set_select,
12844                 NULL,
12845         },
12846 };
12847
12848 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12849 struct cmd_mcast_addr_result {
12850         cmdline_fixed_string_t mcast_addr_cmd;
12851         cmdline_fixed_string_t what;
12852         uint16_t port_num;
12853         struct rte_ether_addr mc_addr;
12854 };
12855
12856 static void cmd_mcast_addr_parsed(void *parsed_result,
12857                 __rte_unused struct cmdline *cl,
12858                 __rte_unused void *data)
12859 {
12860         struct cmd_mcast_addr_result *res = parsed_result;
12861
12862         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12863                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12864                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12865                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12866                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12867                 return;
12868         }
12869         if (strcmp(res->what, "add") == 0)
12870                 mcast_addr_add(res->port_num, &res->mc_addr);
12871         else
12872                 mcast_addr_remove(res->port_num, &res->mc_addr);
12873 }
12874
12875 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12876         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12877                                  mcast_addr_cmd, "mcast_addr");
12878 cmdline_parse_token_string_t cmd_mcast_addr_what =
12879         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12880                                  "add#remove");
12881 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12882         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12883 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12884         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12885
12886 cmdline_parse_inst_t cmd_mcast_addr = {
12887         .f = cmd_mcast_addr_parsed,
12888         .data = (void *)0,
12889         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12890                 "Add/Remove multicast MAC address on port_id",
12891         .tokens = {
12892                 (void *)&cmd_mcast_addr_cmd,
12893                 (void *)&cmd_mcast_addr_what,
12894                 (void *)&cmd_mcast_addr_portnum,
12895                 (void *)&cmd_mcast_addr_addr,
12896                 NULL,
12897         },
12898 };
12899
12900 /* l2 tunnel config
12901  * only support E-tag now.
12902  */
12903
12904 /* Ether type config */
12905 struct cmd_config_l2_tunnel_eth_type_result {
12906         cmdline_fixed_string_t port;
12907         cmdline_fixed_string_t config;
12908         cmdline_fixed_string_t all;
12909         portid_t id;
12910         cmdline_fixed_string_t l2_tunnel;
12911         cmdline_fixed_string_t l2_tunnel_type;
12912         cmdline_fixed_string_t eth_type;
12913         uint16_t eth_type_val;
12914 };
12915
12916 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12917         TOKEN_STRING_INITIALIZER
12918                 (struct cmd_config_l2_tunnel_eth_type_result,
12919                  port, "port");
12920 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12921         TOKEN_STRING_INITIALIZER
12922                 (struct cmd_config_l2_tunnel_eth_type_result,
12923                  config, "config");
12924 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12925         TOKEN_STRING_INITIALIZER
12926                 (struct cmd_config_l2_tunnel_eth_type_result,
12927                  all, "all");
12928 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12929         TOKEN_NUM_INITIALIZER
12930                 (struct cmd_config_l2_tunnel_eth_type_result,
12931                  id, UINT16);
12932 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12933         TOKEN_STRING_INITIALIZER
12934                 (struct cmd_config_l2_tunnel_eth_type_result,
12935                  l2_tunnel, "l2-tunnel");
12936 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12937         TOKEN_STRING_INITIALIZER
12938                 (struct cmd_config_l2_tunnel_eth_type_result,
12939                  l2_tunnel_type, "E-tag");
12940 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12941         TOKEN_STRING_INITIALIZER
12942                 (struct cmd_config_l2_tunnel_eth_type_result,
12943                  eth_type, "ether-type");
12944 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12945         TOKEN_NUM_INITIALIZER
12946                 (struct cmd_config_l2_tunnel_eth_type_result,
12947                  eth_type_val, UINT16);
12948
12949 static enum rte_eth_tunnel_type
12950 str2fdir_l2_tunnel_type(char *string)
12951 {
12952         uint32_t i = 0;
12953
12954         static const struct {
12955                 char str[32];
12956                 enum rte_eth_tunnel_type type;
12957         } l2_tunnel_type_str[] = {
12958                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12959         };
12960
12961         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12962                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12963                         return l2_tunnel_type_str[i].type;
12964         }
12965         return RTE_TUNNEL_TYPE_NONE;
12966 }
12967
12968 /* ether type config for all ports */
12969 static void
12970 cmd_config_l2_tunnel_eth_type_all_parsed
12971         (void *parsed_result,
12972          __rte_unused struct cmdline *cl,
12973          __rte_unused void *data)
12974 {
12975         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12976         struct rte_eth_l2_tunnel_conf entry;
12977         portid_t pid;
12978
12979         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12980         entry.ether_type = res->eth_type_val;
12981
12982         RTE_ETH_FOREACH_DEV(pid) {
12983                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12984         }
12985 }
12986
12987 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12988         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12989         .data = NULL,
12990         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12991         .tokens = {
12992                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12993                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12994                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12995                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12996                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12997                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12998                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12999                 NULL,
13000         },
13001 };
13002
13003 /* ether type config for a specific port */
13004 static void
13005 cmd_config_l2_tunnel_eth_type_specific_parsed(
13006         void *parsed_result,
13007         __rte_unused struct cmdline *cl,
13008         __rte_unused void *data)
13009 {
13010         struct cmd_config_l2_tunnel_eth_type_result *res =
13011                  parsed_result;
13012         struct rte_eth_l2_tunnel_conf entry;
13013
13014         if (port_id_is_invalid(res->id, ENABLED_WARN))
13015                 return;
13016
13017         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13018         entry.ether_type = res->eth_type_val;
13019
13020         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
13021 }
13022
13023 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
13024         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
13025         .data = NULL,
13026         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
13027         .tokens = {
13028                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13029                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13030                 (void *)&cmd_config_l2_tunnel_eth_type_id,
13031                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13032                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13033                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13034                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13035                 NULL,
13036         },
13037 };
13038
13039 /* Enable/disable l2 tunnel */
13040 struct cmd_config_l2_tunnel_en_dis_result {
13041         cmdline_fixed_string_t port;
13042         cmdline_fixed_string_t config;
13043         cmdline_fixed_string_t all;
13044         portid_t id;
13045         cmdline_fixed_string_t l2_tunnel;
13046         cmdline_fixed_string_t l2_tunnel_type;
13047         cmdline_fixed_string_t en_dis;
13048 };
13049
13050 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
13051         TOKEN_STRING_INITIALIZER
13052                 (struct cmd_config_l2_tunnel_en_dis_result,
13053                  port, "port");
13054 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
13055         TOKEN_STRING_INITIALIZER
13056                 (struct cmd_config_l2_tunnel_en_dis_result,
13057                  config, "config");
13058 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
13059         TOKEN_STRING_INITIALIZER
13060                 (struct cmd_config_l2_tunnel_en_dis_result,
13061                  all, "all");
13062 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
13063         TOKEN_NUM_INITIALIZER
13064                 (struct cmd_config_l2_tunnel_en_dis_result,
13065                  id, UINT16);
13066 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
13067         TOKEN_STRING_INITIALIZER
13068                 (struct cmd_config_l2_tunnel_en_dis_result,
13069                  l2_tunnel, "l2-tunnel");
13070 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
13071         TOKEN_STRING_INITIALIZER
13072                 (struct cmd_config_l2_tunnel_en_dis_result,
13073                  l2_tunnel_type, "E-tag");
13074 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
13075         TOKEN_STRING_INITIALIZER
13076                 (struct cmd_config_l2_tunnel_en_dis_result,
13077                  en_dis, "enable#disable");
13078
13079 /* enable/disable l2 tunnel for all ports */
13080 static void
13081 cmd_config_l2_tunnel_en_dis_all_parsed(
13082         void *parsed_result,
13083         __rte_unused struct cmdline *cl,
13084         __rte_unused void *data)
13085 {
13086         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
13087         struct rte_eth_l2_tunnel_conf entry;
13088         portid_t pid;
13089         uint8_t en;
13090
13091         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13092
13093         if (!strcmp("enable", res->en_dis))
13094                 en = 1;
13095         else
13096                 en = 0;
13097
13098         RTE_ETH_FOREACH_DEV(pid) {
13099                 rte_eth_dev_l2_tunnel_offload_set(pid,
13100                                                   &entry,
13101                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13102                                                   en);
13103         }
13104 }
13105
13106 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
13107         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
13108         .data = NULL,
13109         .help_str = "port config all l2-tunnel E-tag enable|disable",
13110         .tokens = {
13111                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13112                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13113                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
13114                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13115                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13116                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13117                 NULL,
13118         },
13119 };
13120
13121 /* enable/disable l2 tunnel for a port */
13122 static void
13123 cmd_config_l2_tunnel_en_dis_specific_parsed(
13124         void *parsed_result,
13125         __rte_unused struct cmdline *cl,
13126         __rte_unused void *data)
13127 {
13128         struct cmd_config_l2_tunnel_en_dis_result *res =
13129                 parsed_result;
13130         struct rte_eth_l2_tunnel_conf entry;
13131
13132         if (port_id_is_invalid(res->id, ENABLED_WARN))
13133                 return;
13134
13135         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13136
13137         if (!strcmp("enable", res->en_dis))
13138                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13139                                                   &entry,
13140                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13141                                                   1);
13142         else
13143                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13144                                                   &entry,
13145                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13146                                                   0);
13147 }
13148
13149 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13150         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13151         .data = NULL,
13152         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13153         .tokens = {
13154                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13155                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13156                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13157                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13158                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13159                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13160                 NULL,
13161         },
13162 };
13163
13164 /* E-tag configuration */
13165
13166 /* Common result structure for all E-tag configuration */
13167 struct cmd_config_e_tag_result {
13168         cmdline_fixed_string_t e_tag;
13169         cmdline_fixed_string_t set;
13170         cmdline_fixed_string_t insertion;
13171         cmdline_fixed_string_t stripping;
13172         cmdline_fixed_string_t forwarding;
13173         cmdline_fixed_string_t filter;
13174         cmdline_fixed_string_t add;
13175         cmdline_fixed_string_t del;
13176         cmdline_fixed_string_t on;
13177         cmdline_fixed_string_t off;
13178         cmdline_fixed_string_t on_off;
13179         cmdline_fixed_string_t port_tag_id;
13180         uint32_t port_tag_id_val;
13181         cmdline_fixed_string_t e_tag_id;
13182         uint16_t e_tag_id_val;
13183         cmdline_fixed_string_t dst_pool;
13184         uint8_t dst_pool_val;
13185         cmdline_fixed_string_t port;
13186         portid_t port_id;
13187         cmdline_fixed_string_t vf;
13188         uint8_t vf_id;
13189 };
13190
13191 /* Common CLI fields for all E-tag configuration */
13192 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13193         TOKEN_STRING_INITIALIZER
13194                 (struct cmd_config_e_tag_result,
13195                  e_tag, "E-tag");
13196 cmdline_parse_token_string_t cmd_config_e_tag_set =
13197         TOKEN_STRING_INITIALIZER
13198                 (struct cmd_config_e_tag_result,
13199                  set, "set");
13200 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13201         TOKEN_STRING_INITIALIZER
13202                 (struct cmd_config_e_tag_result,
13203                  insertion, "insertion");
13204 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13205         TOKEN_STRING_INITIALIZER
13206                 (struct cmd_config_e_tag_result,
13207                  stripping, "stripping");
13208 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13209         TOKEN_STRING_INITIALIZER
13210                 (struct cmd_config_e_tag_result,
13211                  forwarding, "forwarding");
13212 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13213         TOKEN_STRING_INITIALIZER
13214                 (struct cmd_config_e_tag_result,
13215                  filter, "filter");
13216 cmdline_parse_token_string_t cmd_config_e_tag_add =
13217         TOKEN_STRING_INITIALIZER
13218                 (struct cmd_config_e_tag_result,
13219                  add, "add");
13220 cmdline_parse_token_string_t cmd_config_e_tag_del =
13221         TOKEN_STRING_INITIALIZER
13222                 (struct cmd_config_e_tag_result,
13223                  del, "del");
13224 cmdline_parse_token_string_t cmd_config_e_tag_on =
13225         TOKEN_STRING_INITIALIZER
13226                 (struct cmd_config_e_tag_result,
13227                  on, "on");
13228 cmdline_parse_token_string_t cmd_config_e_tag_off =
13229         TOKEN_STRING_INITIALIZER
13230                 (struct cmd_config_e_tag_result,
13231                  off, "off");
13232 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13233         TOKEN_STRING_INITIALIZER
13234                 (struct cmd_config_e_tag_result,
13235                  on_off, "on#off");
13236 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13237         TOKEN_STRING_INITIALIZER
13238                 (struct cmd_config_e_tag_result,
13239                  port_tag_id, "port-tag-id");
13240 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13241         TOKEN_NUM_INITIALIZER
13242                 (struct cmd_config_e_tag_result,
13243                  port_tag_id_val, UINT32);
13244 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13245         TOKEN_STRING_INITIALIZER
13246                 (struct cmd_config_e_tag_result,
13247                  e_tag_id, "e-tag-id");
13248 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13249         TOKEN_NUM_INITIALIZER
13250                 (struct cmd_config_e_tag_result,
13251                  e_tag_id_val, UINT16);
13252 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13253         TOKEN_STRING_INITIALIZER
13254                 (struct cmd_config_e_tag_result,
13255                  dst_pool, "dst-pool");
13256 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13257         TOKEN_NUM_INITIALIZER
13258                 (struct cmd_config_e_tag_result,
13259                  dst_pool_val, UINT8);
13260 cmdline_parse_token_string_t cmd_config_e_tag_port =
13261         TOKEN_STRING_INITIALIZER
13262                 (struct cmd_config_e_tag_result,
13263                  port, "port");
13264 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13265         TOKEN_NUM_INITIALIZER
13266                 (struct cmd_config_e_tag_result,
13267                  port_id, UINT16);
13268 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13269         TOKEN_STRING_INITIALIZER
13270                 (struct cmd_config_e_tag_result,
13271                  vf, "vf");
13272 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13273         TOKEN_NUM_INITIALIZER
13274                 (struct cmd_config_e_tag_result,
13275                  vf_id, UINT8);
13276
13277 /* E-tag insertion configuration */
13278 static void
13279 cmd_config_e_tag_insertion_en_parsed(
13280         void *parsed_result,
13281         __rte_unused struct cmdline *cl,
13282         __rte_unused void *data)
13283 {
13284         struct cmd_config_e_tag_result *res =
13285                 parsed_result;
13286         struct rte_eth_l2_tunnel_conf entry;
13287
13288         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13289                 return;
13290
13291         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13292         entry.tunnel_id = res->port_tag_id_val;
13293         entry.vf_id = res->vf_id;
13294         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13295                                           &entry,
13296                                           ETH_L2_TUNNEL_INSERTION_MASK,
13297                                           1);
13298 }
13299
13300 static void
13301 cmd_config_e_tag_insertion_dis_parsed(
13302         void *parsed_result,
13303         __rte_unused struct cmdline *cl,
13304         __rte_unused void *data)
13305 {
13306         struct cmd_config_e_tag_result *res =
13307                 parsed_result;
13308         struct rte_eth_l2_tunnel_conf entry;
13309
13310         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13311                 return;
13312
13313         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13314         entry.vf_id = res->vf_id;
13315
13316         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13317                                           &entry,
13318                                           ETH_L2_TUNNEL_INSERTION_MASK,
13319                                           0);
13320 }
13321
13322 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13323         .f = cmd_config_e_tag_insertion_en_parsed,
13324         .data = NULL,
13325         .help_str = "E-tag ... : E-tag insertion enable",
13326         .tokens = {
13327                 (void *)&cmd_config_e_tag_e_tag,
13328                 (void *)&cmd_config_e_tag_set,
13329                 (void *)&cmd_config_e_tag_insertion,
13330                 (void *)&cmd_config_e_tag_on,
13331                 (void *)&cmd_config_e_tag_port_tag_id,
13332                 (void *)&cmd_config_e_tag_port_tag_id_val,
13333                 (void *)&cmd_config_e_tag_port,
13334                 (void *)&cmd_config_e_tag_port_id,
13335                 (void *)&cmd_config_e_tag_vf,
13336                 (void *)&cmd_config_e_tag_vf_id,
13337                 NULL,
13338         },
13339 };
13340
13341 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13342         .f = cmd_config_e_tag_insertion_dis_parsed,
13343         .data = NULL,
13344         .help_str = "E-tag ... : E-tag insertion disable",
13345         .tokens = {
13346                 (void *)&cmd_config_e_tag_e_tag,
13347                 (void *)&cmd_config_e_tag_set,
13348                 (void *)&cmd_config_e_tag_insertion,
13349                 (void *)&cmd_config_e_tag_off,
13350                 (void *)&cmd_config_e_tag_port,
13351                 (void *)&cmd_config_e_tag_port_id,
13352                 (void *)&cmd_config_e_tag_vf,
13353                 (void *)&cmd_config_e_tag_vf_id,
13354                 NULL,
13355         },
13356 };
13357
13358 /* E-tag stripping configuration */
13359 static void
13360 cmd_config_e_tag_stripping_parsed(
13361         void *parsed_result,
13362         __rte_unused struct cmdline *cl,
13363         __rte_unused void *data)
13364 {
13365         struct cmd_config_e_tag_result *res =
13366                 parsed_result;
13367         struct rte_eth_l2_tunnel_conf entry;
13368
13369         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13370                 return;
13371
13372         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13373
13374         if (!strcmp(res->on_off, "on"))
13375                 rte_eth_dev_l2_tunnel_offload_set
13376                         (res->port_id,
13377                          &entry,
13378                          ETH_L2_TUNNEL_STRIPPING_MASK,
13379                          1);
13380         else
13381                 rte_eth_dev_l2_tunnel_offload_set
13382                         (res->port_id,
13383                          &entry,
13384                          ETH_L2_TUNNEL_STRIPPING_MASK,
13385                          0);
13386 }
13387
13388 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13389         .f = cmd_config_e_tag_stripping_parsed,
13390         .data = NULL,
13391         .help_str = "E-tag ... : E-tag stripping enable/disable",
13392         .tokens = {
13393                 (void *)&cmd_config_e_tag_e_tag,
13394                 (void *)&cmd_config_e_tag_set,
13395                 (void *)&cmd_config_e_tag_stripping,
13396                 (void *)&cmd_config_e_tag_on_off,
13397                 (void *)&cmd_config_e_tag_port,
13398                 (void *)&cmd_config_e_tag_port_id,
13399                 NULL,
13400         },
13401 };
13402
13403 /* E-tag forwarding configuration */
13404 static void
13405 cmd_config_e_tag_forwarding_parsed(
13406         void *parsed_result,
13407         __rte_unused struct cmdline *cl,
13408         __rte_unused void *data)
13409 {
13410         struct cmd_config_e_tag_result *res = parsed_result;
13411         struct rte_eth_l2_tunnel_conf entry;
13412
13413         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13414                 return;
13415
13416         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13417
13418         if (!strcmp(res->on_off, "on"))
13419                 rte_eth_dev_l2_tunnel_offload_set
13420                         (res->port_id,
13421                          &entry,
13422                          ETH_L2_TUNNEL_FORWARDING_MASK,
13423                          1);
13424         else
13425                 rte_eth_dev_l2_tunnel_offload_set
13426                         (res->port_id,
13427                          &entry,
13428                          ETH_L2_TUNNEL_FORWARDING_MASK,
13429                          0);
13430 }
13431
13432 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13433         .f = cmd_config_e_tag_forwarding_parsed,
13434         .data = NULL,
13435         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13436         .tokens = {
13437                 (void *)&cmd_config_e_tag_e_tag,
13438                 (void *)&cmd_config_e_tag_set,
13439                 (void *)&cmd_config_e_tag_forwarding,
13440                 (void *)&cmd_config_e_tag_on_off,
13441                 (void *)&cmd_config_e_tag_port,
13442                 (void *)&cmd_config_e_tag_port_id,
13443                 NULL,
13444         },
13445 };
13446
13447 /* E-tag filter configuration */
13448 static void
13449 cmd_config_e_tag_filter_add_parsed(
13450         void *parsed_result,
13451         __rte_unused struct cmdline *cl,
13452         __rte_unused void *data)
13453 {
13454         struct cmd_config_e_tag_result *res = parsed_result;
13455         struct rte_eth_l2_tunnel_conf entry;
13456         int ret = 0;
13457
13458         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13459                 return;
13460
13461         if (res->e_tag_id_val > 0x3fff) {
13462                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13463                 return;
13464         }
13465
13466         ret = rte_eth_dev_filter_supported(res->port_id,
13467                                            RTE_ETH_FILTER_L2_TUNNEL);
13468         if (ret < 0) {
13469                 printf("E-tag filter is not supported on port %u.\n",
13470                        res->port_id);
13471                 return;
13472         }
13473
13474         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13475         entry.tunnel_id = res->e_tag_id_val;
13476         entry.pool = res->dst_pool_val;
13477
13478         ret = rte_eth_dev_filter_ctrl(res->port_id,
13479                                       RTE_ETH_FILTER_L2_TUNNEL,
13480                                       RTE_ETH_FILTER_ADD,
13481                                       &entry);
13482         if (ret < 0)
13483                 printf("E-tag filter programming error: (%s)\n",
13484                        strerror(-ret));
13485 }
13486
13487 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13488         .f = cmd_config_e_tag_filter_add_parsed,
13489         .data = NULL,
13490         .help_str = "E-tag ... : E-tag filter add",
13491         .tokens = {
13492                 (void *)&cmd_config_e_tag_e_tag,
13493                 (void *)&cmd_config_e_tag_set,
13494                 (void *)&cmd_config_e_tag_filter,
13495                 (void *)&cmd_config_e_tag_add,
13496                 (void *)&cmd_config_e_tag_e_tag_id,
13497                 (void *)&cmd_config_e_tag_e_tag_id_val,
13498                 (void *)&cmd_config_e_tag_dst_pool,
13499                 (void *)&cmd_config_e_tag_dst_pool_val,
13500                 (void *)&cmd_config_e_tag_port,
13501                 (void *)&cmd_config_e_tag_port_id,
13502                 NULL,
13503         },
13504 };
13505
13506 static void
13507 cmd_config_e_tag_filter_del_parsed(
13508         void *parsed_result,
13509         __rte_unused struct cmdline *cl,
13510         __rte_unused void *data)
13511 {
13512         struct cmd_config_e_tag_result *res = parsed_result;
13513         struct rte_eth_l2_tunnel_conf entry;
13514         int ret = 0;
13515
13516         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13517                 return;
13518
13519         if (res->e_tag_id_val > 0x3fff) {
13520                 printf("e-tag-id must be less than 0x3fff.\n");
13521                 return;
13522         }
13523
13524         ret = rte_eth_dev_filter_supported(res->port_id,
13525                                            RTE_ETH_FILTER_L2_TUNNEL);
13526         if (ret < 0) {
13527                 printf("E-tag filter is not supported on port %u.\n",
13528                        res->port_id);
13529                 return;
13530         }
13531
13532         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13533         entry.tunnel_id = res->e_tag_id_val;
13534
13535         ret = rte_eth_dev_filter_ctrl(res->port_id,
13536                                       RTE_ETH_FILTER_L2_TUNNEL,
13537                                       RTE_ETH_FILTER_DELETE,
13538                                       &entry);
13539         if (ret < 0)
13540                 printf("E-tag filter programming error: (%s)\n",
13541                        strerror(-ret));
13542 }
13543
13544 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13545         .f = cmd_config_e_tag_filter_del_parsed,
13546         .data = NULL,
13547         .help_str = "E-tag ... : E-tag filter delete",
13548         .tokens = {
13549                 (void *)&cmd_config_e_tag_e_tag,
13550                 (void *)&cmd_config_e_tag_set,
13551                 (void *)&cmd_config_e_tag_filter,
13552                 (void *)&cmd_config_e_tag_del,
13553                 (void *)&cmd_config_e_tag_e_tag_id,
13554                 (void *)&cmd_config_e_tag_e_tag_id_val,
13555                 (void *)&cmd_config_e_tag_port,
13556                 (void *)&cmd_config_e_tag_port_id,
13557                 NULL,
13558         },
13559 };
13560
13561 /* vf vlan anti spoof configuration */
13562
13563 /* Common result structure for vf vlan anti spoof */
13564 struct cmd_vf_vlan_anti_spoof_result {
13565         cmdline_fixed_string_t set;
13566         cmdline_fixed_string_t vf;
13567         cmdline_fixed_string_t vlan;
13568         cmdline_fixed_string_t antispoof;
13569         portid_t port_id;
13570         uint32_t vf_id;
13571         cmdline_fixed_string_t on_off;
13572 };
13573
13574 /* Common CLI fields for vf vlan anti spoof enable disable */
13575 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13576         TOKEN_STRING_INITIALIZER
13577                 (struct cmd_vf_vlan_anti_spoof_result,
13578                  set, "set");
13579 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13580         TOKEN_STRING_INITIALIZER
13581                 (struct cmd_vf_vlan_anti_spoof_result,
13582                  vf, "vf");
13583 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13584         TOKEN_STRING_INITIALIZER
13585                 (struct cmd_vf_vlan_anti_spoof_result,
13586                  vlan, "vlan");
13587 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13588         TOKEN_STRING_INITIALIZER
13589                 (struct cmd_vf_vlan_anti_spoof_result,
13590                  antispoof, "antispoof");
13591 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13592         TOKEN_NUM_INITIALIZER
13593                 (struct cmd_vf_vlan_anti_spoof_result,
13594                  port_id, UINT16);
13595 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13596         TOKEN_NUM_INITIALIZER
13597                 (struct cmd_vf_vlan_anti_spoof_result,
13598                  vf_id, UINT32);
13599 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13600         TOKEN_STRING_INITIALIZER
13601                 (struct cmd_vf_vlan_anti_spoof_result,
13602                  on_off, "on#off");
13603
13604 static void
13605 cmd_set_vf_vlan_anti_spoof_parsed(
13606         void *parsed_result,
13607         __rte_unused struct cmdline *cl,
13608         __rte_unused void *data)
13609 {
13610         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13611         int ret = -ENOTSUP;
13612
13613         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13614
13615         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13616                 return;
13617
13618 #ifdef RTE_NET_IXGBE
13619         if (ret == -ENOTSUP)
13620                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13621                                 res->vf_id, is_on);
13622 #endif
13623 #ifdef RTE_NET_I40E
13624         if (ret == -ENOTSUP)
13625                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13626                                 res->vf_id, is_on);
13627 #endif
13628 #ifdef RTE_NET_BNXT
13629         if (ret == -ENOTSUP)
13630                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13631                                 res->vf_id, is_on);
13632 #endif
13633
13634         switch (ret) {
13635         case 0:
13636                 break;
13637         case -EINVAL:
13638                 printf("invalid vf_id %d\n", res->vf_id);
13639                 break;
13640         case -ENODEV:
13641                 printf("invalid port_id %d\n", res->port_id);
13642                 break;
13643         case -ENOTSUP:
13644                 printf("function not implemented\n");
13645                 break;
13646         default:
13647                 printf("programming error: (%s)\n", strerror(-ret));
13648         }
13649 }
13650
13651 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13652         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13653         .data = NULL,
13654         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13655         .tokens = {
13656                 (void *)&cmd_vf_vlan_anti_spoof_set,
13657                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13658                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13659                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13660                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13661                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13662                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13663                 NULL,
13664         },
13665 };
13666
13667 /* vf mac anti spoof configuration */
13668
13669 /* Common result structure for vf mac anti spoof */
13670 struct cmd_vf_mac_anti_spoof_result {
13671         cmdline_fixed_string_t set;
13672         cmdline_fixed_string_t vf;
13673         cmdline_fixed_string_t mac;
13674         cmdline_fixed_string_t antispoof;
13675         portid_t port_id;
13676         uint32_t vf_id;
13677         cmdline_fixed_string_t on_off;
13678 };
13679
13680 /* Common CLI fields for vf mac anti spoof enable disable */
13681 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13682         TOKEN_STRING_INITIALIZER
13683                 (struct cmd_vf_mac_anti_spoof_result,
13684                  set, "set");
13685 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13686         TOKEN_STRING_INITIALIZER
13687                 (struct cmd_vf_mac_anti_spoof_result,
13688                  vf, "vf");
13689 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13690         TOKEN_STRING_INITIALIZER
13691                 (struct cmd_vf_mac_anti_spoof_result,
13692                  mac, "mac");
13693 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13694         TOKEN_STRING_INITIALIZER
13695                 (struct cmd_vf_mac_anti_spoof_result,
13696                  antispoof, "antispoof");
13697 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13698         TOKEN_NUM_INITIALIZER
13699                 (struct cmd_vf_mac_anti_spoof_result,
13700                  port_id, UINT16);
13701 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13702         TOKEN_NUM_INITIALIZER
13703                 (struct cmd_vf_mac_anti_spoof_result,
13704                  vf_id, UINT32);
13705 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13706         TOKEN_STRING_INITIALIZER
13707                 (struct cmd_vf_mac_anti_spoof_result,
13708                  on_off, "on#off");
13709
13710 static void
13711 cmd_set_vf_mac_anti_spoof_parsed(
13712         void *parsed_result,
13713         __rte_unused struct cmdline *cl,
13714         __rte_unused void *data)
13715 {
13716         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13717         int ret = -ENOTSUP;
13718
13719         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13720
13721         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13722                 return;
13723
13724 #ifdef RTE_NET_IXGBE
13725         if (ret == -ENOTSUP)
13726                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13727                         res->vf_id, is_on);
13728 #endif
13729 #ifdef RTE_NET_I40E
13730         if (ret == -ENOTSUP)
13731                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13732                         res->vf_id, is_on);
13733 #endif
13734 #ifdef RTE_NET_BNXT
13735         if (ret == -ENOTSUP)
13736                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13737                         res->vf_id, is_on);
13738 #endif
13739
13740         switch (ret) {
13741         case 0:
13742                 break;
13743         case -EINVAL:
13744                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13745                 break;
13746         case -ENODEV:
13747                 printf("invalid port_id %d\n", res->port_id);
13748                 break;
13749         case -ENOTSUP:
13750                 printf("function not implemented\n");
13751                 break;
13752         default:
13753                 printf("programming error: (%s)\n", strerror(-ret));
13754         }
13755 }
13756
13757 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13758         .f = cmd_set_vf_mac_anti_spoof_parsed,
13759         .data = NULL,
13760         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13761         .tokens = {
13762                 (void *)&cmd_vf_mac_anti_spoof_set,
13763                 (void *)&cmd_vf_mac_anti_spoof_vf,
13764                 (void *)&cmd_vf_mac_anti_spoof_mac,
13765                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13766                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13767                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13768                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13769                 NULL,
13770         },
13771 };
13772
13773 /* vf vlan strip queue configuration */
13774
13775 /* Common result structure for vf mac anti spoof */
13776 struct cmd_vf_vlan_stripq_result {
13777         cmdline_fixed_string_t set;
13778         cmdline_fixed_string_t vf;
13779         cmdline_fixed_string_t vlan;
13780         cmdline_fixed_string_t stripq;
13781         portid_t port_id;
13782         uint16_t vf_id;
13783         cmdline_fixed_string_t on_off;
13784 };
13785
13786 /* Common CLI fields for vf vlan strip enable disable */
13787 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13788         TOKEN_STRING_INITIALIZER
13789                 (struct cmd_vf_vlan_stripq_result,
13790                  set, "set");
13791 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13792         TOKEN_STRING_INITIALIZER
13793                 (struct cmd_vf_vlan_stripq_result,
13794                  vf, "vf");
13795 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13796         TOKEN_STRING_INITIALIZER
13797                 (struct cmd_vf_vlan_stripq_result,
13798                  vlan, "vlan");
13799 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13800         TOKEN_STRING_INITIALIZER
13801                 (struct cmd_vf_vlan_stripq_result,
13802                  stripq, "stripq");
13803 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13804         TOKEN_NUM_INITIALIZER
13805                 (struct cmd_vf_vlan_stripq_result,
13806                  port_id, UINT16);
13807 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13808         TOKEN_NUM_INITIALIZER
13809                 (struct cmd_vf_vlan_stripq_result,
13810                  vf_id, UINT16);
13811 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13812         TOKEN_STRING_INITIALIZER
13813                 (struct cmd_vf_vlan_stripq_result,
13814                  on_off, "on#off");
13815
13816 static void
13817 cmd_set_vf_vlan_stripq_parsed(
13818         void *parsed_result,
13819         __rte_unused struct cmdline *cl,
13820         __rte_unused void *data)
13821 {
13822         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13823         int ret = -ENOTSUP;
13824
13825         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13826
13827         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13828                 return;
13829
13830 #ifdef RTE_NET_IXGBE
13831         if (ret == -ENOTSUP)
13832                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13833                         res->vf_id, is_on);
13834 #endif
13835 #ifdef RTE_NET_I40E
13836         if (ret == -ENOTSUP)
13837                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13838                         res->vf_id, is_on);
13839 #endif
13840 #ifdef RTE_NET_BNXT
13841         if (ret == -ENOTSUP)
13842                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13843                         res->vf_id, is_on);
13844 #endif
13845
13846         switch (ret) {
13847         case 0:
13848                 break;
13849         case -EINVAL:
13850                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13851                 break;
13852         case -ENODEV:
13853                 printf("invalid port_id %d\n", res->port_id);
13854                 break;
13855         case -ENOTSUP:
13856                 printf("function not implemented\n");
13857                 break;
13858         default:
13859                 printf("programming error: (%s)\n", strerror(-ret));
13860         }
13861 }
13862
13863 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13864         .f = cmd_set_vf_vlan_stripq_parsed,
13865         .data = NULL,
13866         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13867         .tokens = {
13868                 (void *)&cmd_vf_vlan_stripq_set,
13869                 (void *)&cmd_vf_vlan_stripq_vf,
13870                 (void *)&cmd_vf_vlan_stripq_vlan,
13871                 (void *)&cmd_vf_vlan_stripq_stripq,
13872                 (void *)&cmd_vf_vlan_stripq_port_id,
13873                 (void *)&cmd_vf_vlan_stripq_vf_id,
13874                 (void *)&cmd_vf_vlan_stripq_on_off,
13875                 NULL,
13876         },
13877 };
13878
13879 /* vf vlan insert configuration */
13880
13881 /* Common result structure for vf vlan insert */
13882 struct cmd_vf_vlan_insert_result {
13883         cmdline_fixed_string_t set;
13884         cmdline_fixed_string_t vf;
13885         cmdline_fixed_string_t vlan;
13886         cmdline_fixed_string_t insert;
13887         portid_t port_id;
13888         uint16_t vf_id;
13889         uint16_t vlan_id;
13890 };
13891
13892 /* Common CLI fields for vf vlan insert enable disable */
13893 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13894         TOKEN_STRING_INITIALIZER
13895                 (struct cmd_vf_vlan_insert_result,
13896                  set, "set");
13897 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13898         TOKEN_STRING_INITIALIZER
13899                 (struct cmd_vf_vlan_insert_result,
13900                  vf, "vf");
13901 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13902         TOKEN_STRING_INITIALIZER
13903                 (struct cmd_vf_vlan_insert_result,
13904                  vlan, "vlan");
13905 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13906         TOKEN_STRING_INITIALIZER
13907                 (struct cmd_vf_vlan_insert_result,
13908                  insert, "insert");
13909 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13910         TOKEN_NUM_INITIALIZER
13911                 (struct cmd_vf_vlan_insert_result,
13912                  port_id, UINT16);
13913 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13914         TOKEN_NUM_INITIALIZER
13915                 (struct cmd_vf_vlan_insert_result,
13916                  vf_id, UINT16);
13917 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13918         TOKEN_NUM_INITIALIZER
13919                 (struct cmd_vf_vlan_insert_result,
13920                  vlan_id, UINT16);
13921
13922 static void
13923 cmd_set_vf_vlan_insert_parsed(
13924         void *parsed_result,
13925         __rte_unused struct cmdline *cl,
13926         __rte_unused void *data)
13927 {
13928         struct cmd_vf_vlan_insert_result *res = parsed_result;
13929         int ret = -ENOTSUP;
13930
13931         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13932                 return;
13933
13934 #ifdef RTE_NET_IXGBE
13935         if (ret == -ENOTSUP)
13936                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13937                         res->vlan_id);
13938 #endif
13939 #ifdef RTE_NET_I40E
13940         if (ret == -ENOTSUP)
13941                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13942                         res->vlan_id);
13943 #endif
13944 #ifdef RTE_NET_BNXT
13945         if (ret == -ENOTSUP)
13946                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13947                         res->vlan_id);
13948 #endif
13949
13950         switch (ret) {
13951         case 0:
13952                 break;
13953         case -EINVAL:
13954                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13955                 break;
13956         case -ENODEV:
13957                 printf("invalid port_id %d\n", res->port_id);
13958                 break;
13959         case -ENOTSUP:
13960                 printf("function not implemented\n");
13961                 break;
13962         default:
13963                 printf("programming error: (%s)\n", strerror(-ret));
13964         }
13965 }
13966
13967 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13968         .f = cmd_set_vf_vlan_insert_parsed,
13969         .data = NULL,
13970         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13971         .tokens = {
13972                 (void *)&cmd_vf_vlan_insert_set,
13973                 (void *)&cmd_vf_vlan_insert_vf,
13974                 (void *)&cmd_vf_vlan_insert_vlan,
13975                 (void *)&cmd_vf_vlan_insert_insert,
13976                 (void *)&cmd_vf_vlan_insert_port_id,
13977                 (void *)&cmd_vf_vlan_insert_vf_id,
13978                 (void *)&cmd_vf_vlan_insert_vlan_id,
13979                 NULL,
13980         },
13981 };
13982
13983 /* tx loopback configuration */
13984
13985 /* Common result structure for tx loopback */
13986 struct cmd_tx_loopback_result {
13987         cmdline_fixed_string_t set;
13988         cmdline_fixed_string_t tx;
13989         cmdline_fixed_string_t loopback;
13990         portid_t port_id;
13991         cmdline_fixed_string_t on_off;
13992 };
13993
13994 /* Common CLI fields for tx loopback enable disable */
13995 cmdline_parse_token_string_t cmd_tx_loopback_set =
13996         TOKEN_STRING_INITIALIZER
13997                 (struct cmd_tx_loopback_result,
13998                  set, "set");
13999 cmdline_parse_token_string_t cmd_tx_loopback_tx =
14000         TOKEN_STRING_INITIALIZER
14001                 (struct cmd_tx_loopback_result,
14002                  tx, "tx");
14003 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
14004         TOKEN_STRING_INITIALIZER
14005                 (struct cmd_tx_loopback_result,
14006                  loopback, "loopback");
14007 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
14008         TOKEN_NUM_INITIALIZER
14009                 (struct cmd_tx_loopback_result,
14010                  port_id, UINT16);
14011 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
14012         TOKEN_STRING_INITIALIZER
14013                 (struct cmd_tx_loopback_result,
14014                  on_off, "on#off");
14015
14016 static void
14017 cmd_set_tx_loopback_parsed(
14018         void *parsed_result,
14019         __rte_unused struct cmdline *cl,
14020         __rte_unused void *data)
14021 {
14022         struct cmd_tx_loopback_result *res = parsed_result;
14023         int ret = -ENOTSUP;
14024
14025         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14026
14027         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14028                 return;
14029
14030 #ifdef RTE_NET_IXGBE
14031         if (ret == -ENOTSUP)
14032                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
14033 #endif
14034 #ifdef RTE_NET_I40E
14035         if (ret == -ENOTSUP)
14036                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
14037 #endif
14038 #ifdef RTE_NET_BNXT
14039         if (ret == -ENOTSUP)
14040                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
14041 #endif
14042 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
14043         if (ret == -ENOTSUP)
14044                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
14045 #endif
14046
14047         switch (ret) {
14048         case 0:
14049                 break;
14050         case -EINVAL:
14051                 printf("invalid is_on %d\n", is_on);
14052                 break;
14053         case -ENODEV:
14054                 printf("invalid port_id %d\n", res->port_id);
14055                 break;
14056         case -ENOTSUP:
14057                 printf("function not implemented\n");
14058                 break;
14059         default:
14060                 printf("programming error: (%s)\n", strerror(-ret));
14061         }
14062 }
14063
14064 cmdline_parse_inst_t cmd_set_tx_loopback = {
14065         .f = cmd_set_tx_loopback_parsed,
14066         .data = NULL,
14067         .help_str = "set tx loopback <port_id> on|off",
14068         .tokens = {
14069                 (void *)&cmd_tx_loopback_set,
14070                 (void *)&cmd_tx_loopback_tx,
14071                 (void *)&cmd_tx_loopback_loopback,
14072                 (void *)&cmd_tx_loopback_port_id,
14073                 (void *)&cmd_tx_loopback_on_off,
14074                 NULL,
14075         },
14076 };
14077
14078 /* all queues drop enable configuration */
14079
14080 /* Common result structure for all queues drop enable */
14081 struct cmd_all_queues_drop_en_result {
14082         cmdline_fixed_string_t set;
14083         cmdline_fixed_string_t all;
14084         cmdline_fixed_string_t queues;
14085         cmdline_fixed_string_t drop;
14086         portid_t port_id;
14087         cmdline_fixed_string_t on_off;
14088 };
14089
14090 /* Common CLI fields for tx loopback enable disable */
14091 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
14092         TOKEN_STRING_INITIALIZER
14093                 (struct cmd_all_queues_drop_en_result,
14094                  set, "set");
14095 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
14096         TOKEN_STRING_INITIALIZER
14097                 (struct cmd_all_queues_drop_en_result,
14098                  all, "all");
14099 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
14100         TOKEN_STRING_INITIALIZER
14101                 (struct cmd_all_queues_drop_en_result,
14102                  queues, "queues");
14103 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
14104         TOKEN_STRING_INITIALIZER
14105                 (struct cmd_all_queues_drop_en_result,
14106                  drop, "drop");
14107 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
14108         TOKEN_NUM_INITIALIZER
14109                 (struct cmd_all_queues_drop_en_result,
14110                  port_id, UINT16);
14111 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
14112         TOKEN_STRING_INITIALIZER
14113                 (struct cmd_all_queues_drop_en_result,
14114                  on_off, "on#off");
14115
14116 static void
14117 cmd_set_all_queues_drop_en_parsed(
14118         void *parsed_result,
14119         __rte_unused struct cmdline *cl,
14120         __rte_unused void *data)
14121 {
14122         struct cmd_all_queues_drop_en_result *res = parsed_result;
14123         int ret = -ENOTSUP;
14124         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14125
14126         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14127                 return;
14128
14129 #ifdef RTE_NET_IXGBE
14130         if (ret == -ENOTSUP)
14131                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
14132 #endif
14133 #ifdef RTE_NET_BNXT
14134         if (ret == -ENOTSUP)
14135                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
14136 #endif
14137         switch (ret) {
14138         case 0:
14139                 break;
14140         case -EINVAL:
14141                 printf("invalid is_on %d\n", is_on);
14142                 break;
14143         case -ENODEV:
14144                 printf("invalid port_id %d\n", res->port_id);
14145                 break;
14146         case -ENOTSUP:
14147                 printf("function not implemented\n");
14148                 break;
14149         default:
14150                 printf("programming error: (%s)\n", strerror(-ret));
14151         }
14152 }
14153
14154 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14155         .f = cmd_set_all_queues_drop_en_parsed,
14156         .data = NULL,
14157         .help_str = "set all queues drop <port_id> on|off",
14158         .tokens = {
14159                 (void *)&cmd_all_queues_drop_en_set,
14160                 (void *)&cmd_all_queues_drop_en_all,
14161                 (void *)&cmd_all_queues_drop_en_queues,
14162                 (void *)&cmd_all_queues_drop_en_drop,
14163                 (void *)&cmd_all_queues_drop_en_port_id,
14164                 (void *)&cmd_all_queues_drop_en_on_off,
14165                 NULL,
14166         },
14167 };
14168
14169 /* vf split drop enable configuration */
14170
14171 /* Common result structure for vf split drop enable */
14172 struct cmd_vf_split_drop_en_result {
14173         cmdline_fixed_string_t set;
14174         cmdline_fixed_string_t vf;
14175         cmdline_fixed_string_t split;
14176         cmdline_fixed_string_t drop;
14177         portid_t port_id;
14178         uint16_t vf_id;
14179         cmdline_fixed_string_t on_off;
14180 };
14181
14182 /* Common CLI fields for vf split drop enable disable */
14183 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14184         TOKEN_STRING_INITIALIZER
14185                 (struct cmd_vf_split_drop_en_result,
14186                  set, "set");
14187 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14188         TOKEN_STRING_INITIALIZER
14189                 (struct cmd_vf_split_drop_en_result,
14190                  vf, "vf");
14191 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14192         TOKEN_STRING_INITIALIZER
14193                 (struct cmd_vf_split_drop_en_result,
14194                  split, "split");
14195 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14196         TOKEN_STRING_INITIALIZER
14197                 (struct cmd_vf_split_drop_en_result,
14198                  drop, "drop");
14199 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14200         TOKEN_NUM_INITIALIZER
14201                 (struct cmd_vf_split_drop_en_result,
14202                  port_id, UINT16);
14203 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14204         TOKEN_NUM_INITIALIZER
14205                 (struct cmd_vf_split_drop_en_result,
14206                  vf_id, UINT16);
14207 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14208         TOKEN_STRING_INITIALIZER
14209                 (struct cmd_vf_split_drop_en_result,
14210                  on_off, "on#off");
14211
14212 static void
14213 cmd_set_vf_split_drop_en_parsed(
14214         void *parsed_result,
14215         __rte_unused struct cmdline *cl,
14216         __rte_unused void *data)
14217 {
14218         struct cmd_vf_split_drop_en_result *res = parsed_result;
14219         int ret = -ENOTSUP;
14220         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14221
14222         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14223                 return;
14224
14225 #ifdef RTE_NET_IXGBE
14226         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14227                         is_on);
14228 #endif
14229         switch (ret) {
14230         case 0:
14231                 break;
14232         case -EINVAL:
14233                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14234                 break;
14235         case -ENODEV:
14236                 printf("invalid port_id %d\n", res->port_id);
14237                 break;
14238         case -ENOTSUP:
14239                 printf("not supported on port %d\n", res->port_id);
14240                 break;
14241         default:
14242                 printf("programming error: (%s)\n", strerror(-ret));
14243         }
14244 }
14245
14246 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14247         .f = cmd_set_vf_split_drop_en_parsed,
14248         .data = NULL,
14249         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14250         .tokens = {
14251                 (void *)&cmd_vf_split_drop_en_set,
14252                 (void *)&cmd_vf_split_drop_en_vf,
14253                 (void *)&cmd_vf_split_drop_en_split,
14254                 (void *)&cmd_vf_split_drop_en_drop,
14255                 (void *)&cmd_vf_split_drop_en_port_id,
14256                 (void *)&cmd_vf_split_drop_en_vf_id,
14257                 (void *)&cmd_vf_split_drop_en_on_off,
14258                 NULL,
14259         },
14260 };
14261
14262 /* vf mac address configuration */
14263
14264 /* Common result structure for vf mac address */
14265 struct cmd_set_vf_mac_addr_result {
14266         cmdline_fixed_string_t set;
14267         cmdline_fixed_string_t vf;
14268         cmdline_fixed_string_t mac;
14269         cmdline_fixed_string_t addr;
14270         portid_t port_id;
14271         uint16_t vf_id;
14272         struct rte_ether_addr mac_addr;
14273
14274 };
14275
14276 /* Common CLI fields for vf split drop enable disable */
14277 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14278         TOKEN_STRING_INITIALIZER
14279                 (struct cmd_set_vf_mac_addr_result,
14280                  set, "set");
14281 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14282         TOKEN_STRING_INITIALIZER
14283                 (struct cmd_set_vf_mac_addr_result,
14284                  vf, "vf");
14285 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14286         TOKEN_STRING_INITIALIZER
14287                 (struct cmd_set_vf_mac_addr_result,
14288                  mac, "mac");
14289 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14290         TOKEN_STRING_INITIALIZER
14291                 (struct cmd_set_vf_mac_addr_result,
14292                  addr, "addr");
14293 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14294         TOKEN_NUM_INITIALIZER
14295                 (struct cmd_set_vf_mac_addr_result,
14296                  port_id, UINT16);
14297 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14298         TOKEN_NUM_INITIALIZER
14299                 (struct cmd_set_vf_mac_addr_result,
14300                  vf_id, UINT16);
14301 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14302         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14303                  mac_addr);
14304
14305 static void
14306 cmd_set_vf_mac_addr_parsed(
14307         void *parsed_result,
14308         __rte_unused struct cmdline *cl,
14309         __rte_unused void *data)
14310 {
14311         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14312         int ret = -ENOTSUP;
14313
14314         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14315                 return;
14316
14317 #ifdef RTE_NET_IXGBE
14318         if (ret == -ENOTSUP)
14319                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14320                                 &res->mac_addr);
14321 #endif
14322 #ifdef RTE_NET_I40E
14323         if (ret == -ENOTSUP)
14324                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14325                                 &res->mac_addr);
14326 #endif
14327 #ifdef RTE_NET_BNXT
14328         if (ret == -ENOTSUP)
14329                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14330                                 &res->mac_addr);
14331 #endif
14332
14333         switch (ret) {
14334         case 0:
14335                 break;
14336         case -EINVAL:
14337                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14338                 break;
14339         case -ENODEV:
14340                 printf("invalid port_id %d\n", res->port_id);
14341                 break;
14342         case -ENOTSUP:
14343                 printf("function not implemented\n");
14344                 break;
14345         default:
14346                 printf("programming error: (%s)\n", strerror(-ret));
14347         }
14348 }
14349
14350 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14351         .f = cmd_set_vf_mac_addr_parsed,
14352         .data = NULL,
14353         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14354         .tokens = {
14355                 (void *)&cmd_set_vf_mac_addr_set,
14356                 (void *)&cmd_set_vf_mac_addr_vf,
14357                 (void *)&cmd_set_vf_mac_addr_mac,
14358                 (void *)&cmd_set_vf_mac_addr_addr,
14359                 (void *)&cmd_set_vf_mac_addr_port_id,
14360                 (void *)&cmd_set_vf_mac_addr_vf_id,
14361                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14362                 NULL,
14363         },
14364 };
14365
14366 /* MACsec configuration */
14367
14368 /* Common result structure for MACsec offload enable */
14369 struct cmd_macsec_offload_on_result {
14370         cmdline_fixed_string_t set;
14371         cmdline_fixed_string_t macsec;
14372         cmdline_fixed_string_t offload;
14373         portid_t port_id;
14374         cmdline_fixed_string_t on;
14375         cmdline_fixed_string_t encrypt;
14376         cmdline_fixed_string_t en_on_off;
14377         cmdline_fixed_string_t replay_protect;
14378         cmdline_fixed_string_t rp_on_off;
14379 };
14380
14381 /* Common CLI fields for MACsec offload disable */
14382 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14383         TOKEN_STRING_INITIALIZER
14384                 (struct cmd_macsec_offload_on_result,
14385                  set, "set");
14386 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14387         TOKEN_STRING_INITIALIZER
14388                 (struct cmd_macsec_offload_on_result,
14389                  macsec, "macsec");
14390 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14391         TOKEN_STRING_INITIALIZER
14392                 (struct cmd_macsec_offload_on_result,
14393                  offload, "offload");
14394 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14395         TOKEN_NUM_INITIALIZER
14396                 (struct cmd_macsec_offload_on_result,
14397                  port_id, UINT16);
14398 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14399         TOKEN_STRING_INITIALIZER
14400                 (struct cmd_macsec_offload_on_result,
14401                  on, "on");
14402 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14403         TOKEN_STRING_INITIALIZER
14404                 (struct cmd_macsec_offload_on_result,
14405                  encrypt, "encrypt");
14406 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14407         TOKEN_STRING_INITIALIZER
14408                 (struct cmd_macsec_offload_on_result,
14409                  en_on_off, "on#off");
14410 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14411         TOKEN_STRING_INITIALIZER
14412                 (struct cmd_macsec_offload_on_result,
14413                  replay_protect, "replay-protect");
14414 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14415         TOKEN_STRING_INITIALIZER
14416                 (struct cmd_macsec_offload_on_result,
14417                  rp_on_off, "on#off");
14418
14419 static void
14420 cmd_set_macsec_offload_on_parsed(
14421         void *parsed_result,
14422         __rte_unused struct cmdline *cl,
14423         __rte_unused void *data)
14424 {
14425         struct cmd_macsec_offload_on_result *res = parsed_result;
14426         int ret = -ENOTSUP;
14427         portid_t port_id = res->port_id;
14428         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14429         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14430         struct rte_eth_dev_info dev_info;
14431
14432         if (port_id_is_invalid(port_id, ENABLED_WARN))
14433                 return;
14434         if (!port_is_stopped(port_id)) {
14435                 printf("Please stop port %d first\n", port_id);
14436                 return;
14437         }
14438
14439         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14440         if (ret != 0)
14441                 return;
14442
14443         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14444 #ifdef RTE_NET_IXGBE
14445                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14446 #endif
14447         }
14448         RTE_SET_USED(en);
14449         RTE_SET_USED(rp);
14450
14451         switch (ret) {
14452         case 0:
14453                 ports[port_id].dev_conf.txmode.offloads |=
14454                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14455                 cmd_reconfig_device_queue(port_id, 1, 1);
14456                 break;
14457         case -ENODEV:
14458                 printf("invalid port_id %d\n", port_id);
14459                 break;
14460         case -ENOTSUP:
14461                 printf("not supported on port %d\n", port_id);
14462                 break;
14463         default:
14464                 printf("programming error: (%s)\n", strerror(-ret));
14465         }
14466 }
14467
14468 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14469         .f = cmd_set_macsec_offload_on_parsed,
14470         .data = NULL,
14471         .help_str = "set macsec offload <port_id> on "
14472                 "encrypt on|off replay-protect on|off",
14473         .tokens = {
14474                 (void *)&cmd_macsec_offload_on_set,
14475                 (void *)&cmd_macsec_offload_on_macsec,
14476                 (void *)&cmd_macsec_offload_on_offload,
14477                 (void *)&cmd_macsec_offload_on_port_id,
14478                 (void *)&cmd_macsec_offload_on_on,
14479                 (void *)&cmd_macsec_offload_on_encrypt,
14480                 (void *)&cmd_macsec_offload_on_en_on_off,
14481                 (void *)&cmd_macsec_offload_on_replay_protect,
14482                 (void *)&cmd_macsec_offload_on_rp_on_off,
14483                 NULL,
14484         },
14485 };
14486
14487 /* Common result structure for MACsec offload disable */
14488 struct cmd_macsec_offload_off_result {
14489         cmdline_fixed_string_t set;
14490         cmdline_fixed_string_t macsec;
14491         cmdline_fixed_string_t offload;
14492         portid_t port_id;
14493         cmdline_fixed_string_t off;
14494 };
14495
14496 /* Common CLI fields for MACsec offload disable */
14497 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14498         TOKEN_STRING_INITIALIZER
14499                 (struct cmd_macsec_offload_off_result,
14500                  set, "set");
14501 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14502         TOKEN_STRING_INITIALIZER
14503                 (struct cmd_macsec_offload_off_result,
14504                  macsec, "macsec");
14505 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14506         TOKEN_STRING_INITIALIZER
14507                 (struct cmd_macsec_offload_off_result,
14508                  offload, "offload");
14509 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14510         TOKEN_NUM_INITIALIZER
14511                 (struct cmd_macsec_offload_off_result,
14512                  port_id, UINT16);
14513 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14514         TOKEN_STRING_INITIALIZER
14515                 (struct cmd_macsec_offload_off_result,
14516                  off, "off");
14517
14518 static void
14519 cmd_set_macsec_offload_off_parsed(
14520         void *parsed_result,
14521         __rte_unused struct cmdline *cl,
14522         __rte_unused void *data)
14523 {
14524         struct cmd_macsec_offload_off_result *res = parsed_result;
14525         int ret = -ENOTSUP;
14526         struct rte_eth_dev_info dev_info;
14527         portid_t port_id = res->port_id;
14528
14529         if (port_id_is_invalid(port_id, ENABLED_WARN))
14530                 return;
14531         if (!port_is_stopped(port_id)) {
14532                 printf("Please stop port %d first\n", port_id);
14533                 return;
14534         }
14535
14536         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14537         if (ret != 0)
14538                 return;
14539
14540         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14541 #ifdef RTE_NET_IXGBE
14542                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14543 #endif
14544         }
14545         switch (ret) {
14546         case 0:
14547                 ports[port_id].dev_conf.txmode.offloads &=
14548                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14549                 cmd_reconfig_device_queue(port_id, 1, 1);
14550                 break;
14551         case -ENODEV:
14552                 printf("invalid port_id %d\n", port_id);
14553                 break;
14554         case -ENOTSUP:
14555                 printf("not supported on port %d\n", port_id);
14556                 break;
14557         default:
14558                 printf("programming error: (%s)\n", strerror(-ret));
14559         }
14560 }
14561
14562 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14563         .f = cmd_set_macsec_offload_off_parsed,
14564         .data = NULL,
14565         .help_str = "set macsec offload <port_id> off",
14566         .tokens = {
14567                 (void *)&cmd_macsec_offload_off_set,
14568                 (void *)&cmd_macsec_offload_off_macsec,
14569                 (void *)&cmd_macsec_offload_off_offload,
14570                 (void *)&cmd_macsec_offload_off_port_id,
14571                 (void *)&cmd_macsec_offload_off_off,
14572                 NULL,
14573         },
14574 };
14575
14576 /* Common result structure for MACsec secure connection configure */
14577 struct cmd_macsec_sc_result {
14578         cmdline_fixed_string_t set;
14579         cmdline_fixed_string_t macsec;
14580         cmdline_fixed_string_t sc;
14581         cmdline_fixed_string_t tx_rx;
14582         portid_t port_id;
14583         struct rte_ether_addr mac;
14584         uint16_t pi;
14585 };
14586
14587 /* Common CLI fields for MACsec secure connection configure */
14588 cmdline_parse_token_string_t cmd_macsec_sc_set =
14589         TOKEN_STRING_INITIALIZER
14590                 (struct cmd_macsec_sc_result,
14591                  set, "set");
14592 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14593         TOKEN_STRING_INITIALIZER
14594                 (struct cmd_macsec_sc_result,
14595                  macsec, "macsec");
14596 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14597         TOKEN_STRING_INITIALIZER
14598                 (struct cmd_macsec_sc_result,
14599                  sc, "sc");
14600 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14601         TOKEN_STRING_INITIALIZER
14602                 (struct cmd_macsec_sc_result,
14603                  tx_rx, "tx#rx");
14604 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14605         TOKEN_NUM_INITIALIZER
14606                 (struct cmd_macsec_sc_result,
14607                  port_id, UINT16);
14608 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14609         TOKEN_ETHERADDR_INITIALIZER
14610                 (struct cmd_macsec_sc_result,
14611                  mac);
14612 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14613         TOKEN_NUM_INITIALIZER
14614                 (struct cmd_macsec_sc_result,
14615                  pi, UINT16);
14616
14617 static void
14618 cmd_set_macsec_sc_parsed(
14619         void *parsed_result,
14620         __rte_unused struct cmdline *cl,
14621         __rte_unused void *data)
14622 {
14623         struct cmd_macsec_sc_result *res = parsed_result;
14624         int ret = -ENOTSUP;
14625         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14626
14627 #ifdef RTE_NET_IXGBE
14628         ret = is_tx ?
14629                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14630                                 res->mac.addr_bytes) :
14631                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14632                                 res->mac.addr_bytes, res->pi);
14633 #endif
14634         RTE_SET_USED(is_tx);
14635
14636         switch (ret) {
14637         case 0:
14638                 break;
14639         case -ENODEV:
14640                 printf("invalid port_id %d\n", res->port_id);
14641                 break;
14642         case -ENOTSUP:
14643                 printf("not supported on port %d\n", res->port_id);
14644                 break;
14645         default:
14646                 printf("programming error: (%s)\n", strerror(-ret));
14647         }
14648 }
14649
14650 cmdline_parse_inst_t cmd_set_macsec_sc = {
14651         .f = cmd_set_macsec_sc_parsed,
14652         .data = NULL,
14653         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14654         .tokens = {
14655                 (void *)&cmd_macsec_sc_set,
14656                 (void *)&cmd_macsec_sc_macsec,
14657                 (void *)&cmd_macsec_sc_sc,
14658                 (void *)&cmd_macsec_sc_tx_rx,
14659                 (void *)&cmd_macsec_sc_port_id,
14660                 (void *)&cmd_macsec_sc_mac,
14661                 (void *)&cmd_macsec_sc_pi,
14662                 NULL,
14663         },
14664 };
14665
14666 /* Common result structure for MACsec secure connection configure */
14667 struct cmd_macsec_sa_result {
14668         cmdline_fixed_string_t set;
14669         cmdline_fixed_string_t macsec;
14670         cmdline_fixed_string_t sa;
14671         cmdline_fixed_string_t tx_rx;
14672         portid_t port_id;
14673         uint8_t idx;
14674         uint8_t an;
14675         uint32_t pn;
14676         cmdline_fixed_string_t key;
14677 };
14678
14679 /* Common CLI fields for MACsec secure connection configure */
14680 cmdline_parse_token_string_t cmd_macsec_sa_set =
14681         TOKEN_STRING_INITIALIZER
14682                 (struct cmd_macsec_sa_result,
14683                  set, "set");
14684 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14685         TOKEN_STRING_INITIALIZER
14686                 (struct cmd_macsec_sa_result,
14687                  macsec, "macsec");
14688 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14689         TOKEN_STRING_INITIALIZER
14690                 (struct cmd_macsec_sa_result,
14691                  sa, "sa");
14692 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14693         TOKEN_STRING_INITIALIZER
14694                 (struct cmd_macsec_sa_result,
14695                  tx_rx, "tx#rx");
14696 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14697         TOKEN_NUM_INITIALIZER
14698                 (struct cmd_macsec_sa_result,
14699                  port_id, UINT16);
14700 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14701         TOKEN_NUM_INITIALIZER
14702                 (struct cmd_macsec_sa_result,
14703                  idx, UINT8);
14704 cmdline_parse_token_num_t cmd_macsec_sa_an =
14705         TOKEN_NUM_INITIALIZER
14706                 (struct cmd_macsec_sa_result,
14707                  an, UINT8);
14708 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14709         TOKEN_NUM_INITIALIZER
14710                 (struct cmd_macsec_sa_result,
14711                  pn, UINT32);
14712 cmdline_parse_token_string_t cmd_macsec_sa_key =
14713         TOKEN_STRING_INITIALIZER
14714                 (struct cmd_macsec_sa_result,
14715                  key, NULL);
14716
14717 static void
14718 cmd_set_macsec_sa_parsed(
14719         void *parsed_result,
14720         __rte_unused struct cmdline *cl,
14721         __rte_unused void *data)
14722 {
14723         struct cmd_macsec_sa_result *res = parsed_result;
14724         int ret = -ENOTSUP;
14725         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14726         uint8_t key[16] = { 0 };
14727         uint8_t xdgt0;
14728         uint8_t xdgt1;
14729         int key_len;
14730         int i;
14731
14732         key_len = strlen(res->key) / 2;
14733         if (key_len > 16)
14734                 key_len = 16;
14735
14736         for (i = 0; i < key_len; i++) {
14737                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14738                 if (xdgt0 == 0xFF)
14739                         return;
14740                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14741                 if (xdgt1 == 0xFF)
14742                         return;
14743                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14744         }
14745
14746 #ifdef RTE_NET_IXGBE
14747         ret = is_tx ?
14748                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14749                         res->idx, res->an, res->pn, key) :
14750                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14751                         res->idx, res->an, res->pn, key);
14752 #endif
14753         RTE_SET_USED(is_tx);
14754         RTE_SET_USED(key);
14755
14756         switch (ret) {
14757         case 0:
14758                 break;
14759         case -EINVAL:
14760                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14761                 break;
14762         case -ENODEV:
14763                 printf("invalid port_id %d\n", res->port_id);
14764                 break;
14765         case -ENOTSUP:
14766                 printf("not supported on port %d\n", res->port_id);
14767                 break;
14768         default:
14769                 printf("programming error: (%s)\n", strerror(-ret));
14770         }
14771 }
14772
14773 cmdline_parse_inst_t cmd_set_macsec_sa = {
14774         .f = cmd_set_macsec_sa_parsed,
14775         .data = NULL,
14776         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14777         .tokens = {
14778                 (void *)&cmd_macsec_sa_set,
14779                 (void *)&cmd_macsec_sa_macsec,
14780                 (void *)&cmd_macsec_sa_sa,
14781                 (void *)&cmd_macsec_sa_tx_rx,
14782                 (void *)&cmd_macsec_sa_port_id,
14783                 (void *)&cmd_macsec_sa_idx,
14784                 (void *)&cmd_macsec_sa_an,
14785                 (void *)&cmd_macsec_sa_pn,
14786                 (void *)&cmd_macsec_sa_key,
14787                 NULL,
14788         },
14789 };
14790
14791 /* VF unicast promiscuous mode configuration */
14792
14793 /* Common result structure for VF unicast promiscuous mode */
14794 struct cmd_vf_promisc_result {
14795         cmdline_fixed_string_t set;
14796         cmdline_fixed_string_t vf;
14797         cmdline_fixed_string_t promisc;
14798         portid_t port_id;
14799         uint32_t vf_id;
14800         cmdline_fixed_string_t on_off;
14801 };
14802
14803 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14804 cmdline_parse_token_string_t cmd_vf_promisc_set =
14805         TOKEN_STRING_INITIALIZER
14806                 (struct cmd_vf_promisc_result,
14807                  set, "set");
14808 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14809         TOKEN_STRING_INITIALIZER
14810                 (struct cmd_vf_promisc_result,
14811                  vf, "vf");
14812 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14813         TOKEN_STRING_INITIALIZER
14814                 (struct cmd_vf_promisc_result,
14815                  promisc, "promisc");
14816 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14817         TOKEN_NUM_INITIALIZER
14818                 (struct cmd_vf_promisc_result,
14819                  port_id, UINT16);
14820 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14821         TOKEN_NUM_INITIALIZER
14822                 (struct cmd_vf_promisc_result,
14823                  vf_id, UINT32);
14824 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14825         TOKEN_STRING_INITIALIZER
14826                 (struct cmd_vf_promisc_result,
14827                  on_off, "on#off");
14828
14829 static void
14830 cmd_set_vf_promisc_parsed(
14831         void *parsed_result,
14832         __rte_unused struct cmdline *cl,
14833         __rte_unused void *data)
14834 {
14835         struct cmd_vf_promisc_result *res = parsed_result;
14836         int ret = -ENOTSUP;
14837
14838         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14839
14840         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14841                 return;
14842
14843 #ifdef RTE_NET_I40E
14844         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14845                                                   res->vf_id, is_on);
14846 #endif
14847
14848         switch (ret) {
14849         case 0:
14850                 break;
14851         case -EINVAL:
14852                 printf("invalid vf_id %d\n", res->vf_id);
14853                 break;
14854         case -ENODEV:
14855                 printf("invalid port_id %d\n", res->port_id);
14856                 break;
14857         case -ENOTSUP:
14858                 printf("function not implemented\n");
14859                 break;
14860         default:
14861                 printf("programming error: (%s)\n", strerror(-ret));
14862         }
14863 }
14864
14865 cmdline_parse_inst_t cmd_set_vf_promisc = {
14866         .f = cmd_set_vf_promisc_parsed,
14867         .data = NULL,
14868         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14869                 "Set unicast promiscuous mode for a VF from the PF",
14870         .tokens = {
14871                 (void *)&cmd_vf_promisc_set,
14872                 (void *)&cmd_vf_promisc_vf,
14873                 (void *)&cmd_vf_promisc_promisc,
14874                 (void *)&cmd_vf_promisc_port_id,
14875                 (void *)&cmd_vf_promisc_vf_id,
14876                 (void *)&cmd_vf_promisc_on_off,
14877                 NULL,
14878         },
14879 };
14880
14881 /* VF multicast promiscuous mode configuration */
14882
14883 /* Common result structure for VF multicast promiscuous mode */
14884 struct cmd_vf_allmulti_result {
14885         cmdline_fixed_string_t set;
14886         cmdline_fixed_string_t vf;
14887         cmdline_fixed_string_t allmulti;
14888         portid_t port_id;
14889         uint32_t vf_id;
14890         cmdline_fixed_string_t on_off;
14891 };
14892
14893 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14894 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14895         TOKEN_STRING_INITIALIZER
14896                 (struct cmd_vf_allmulti_result,
14897                  set, "set");
14898 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14899         TOKEN_STRING_INITIALIZER
14900                 (struct cmd_vf_allmulti_result,
14901                  vf, "vf");
14902 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14903         TOKEN_STRING_INITIALIZER
14904                 (struct cmd_vf_allmulti_result,
14905                  allmulti, "allmulti");
14906 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14907         TOKEN_NUM_INITIALIZER
14908                 (struct cmd_vf_allmulti_result,
14909                  port_id, UINT16);
14910 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14911         TOKEN_NUM_INITIALIZER
14912                 (struct cmd_vf_allmulti_result,
14913                  vf_id, UINT32);
14914 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14915         TOKEN_STRING_INITIALIZER
14916                 (struct cmd_vf_allmulti_result,
14917                  on_off, "on#off");
14918
14919 static void
14920 cmd_set_vf_allmulti_parsed(
14921         void *parsed_result,
14922         __rte_unused struct cmdline *cl,
14923         __rte_unused void *data)
14924 {
14925         struct cmd_vf_allmulti_result *res = parsed_result;
14926         int ret = -ENOTSUP;
14927
14928         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14929
14930         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14931                 return;
14932
14933 #ifdef RTE_NET_I40E
14934         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14935                                                     res->vf_id, is_on);
14936 #endif
14937
14938         switch (ret) {
14939         case 0:
14940                 break;
14941         case -EINVAL:
14942                 printf("invalid vf_id %d\n", res->vf_id);
14943                 break;
14944         case -ENODEV:
14945                 printf("invalid port_id %d\n", res->port_id);
14946                 break;
14947         case -ENOTSUP:
14948                 printf("function not implemented\n");
14949                 break;
14950         default:
14951                 printf("programming error: (%s)\n", strerror(-ret));
14952         }
14953 }
14954
14955 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14956         .f = cmd_set_vf_allmulti_parsed,
14957         .data = NULL,
14958         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14959                 "Set multicast promiscuous mode for a VF from the PF",
14960         .tokens = {
14961                 (void *)&cmd_vf_allmulti_set,
14962                 (void *)&cmd_vf_allmulti_vf,
14963                 (void *)&cmd_vf_allmulti_allmulti,
14964                 (void *)&cmd_vf_allmulti_port_id,
14965                 (void *)&cmd_vf_allmulti_vf_id,
14966                 (void *)&cmd_vf_allmulti_on_off,
14967                 NULL,
14968         },
14969 };
14970
14971 /* vf broadcast mode configuration */
14972
14973 /* Common result structure for vf broadcast */
14974 struct cmd_set_vf_broadcast_result {
14975         cmdline_fixed_string_t set;
14976         cmdline_fixed_string_t vf;
14977         cmdline_fixed_string_t broadcast;
14978         portid_t port_id;
14979         uint16_t vf_id;
14980         cmdline_fixed_string_t on_off;
14981 };
14982
14983 /* Common CLI fields for vf broadcast enable disable */
14984 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14985         TOKEN_STRING_INITIALIZER
14986                 (struct cmd_set_vf_broadcast_result,
14987                  set, "set");
14988 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14989         TOKEN_STRING_INITIALIZER
14990                 (struct cmd_set_vf_broadcast_result,
14991                  vf, "vf");
14992 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14993         TOKEN_STRING_INITIALIZER
14994                 (struct cmd_set_vf_broadcast_result,
14995                  broadcast, "broadcast");
14996 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14997         TOKEN_NUM_INITIALIZER
14998                 (struct cmd_set_vf_broadcast_result,
14999                  port_id, UINT16);
15000 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
15001         TOKEN_NUM_INITIALIZER
15002                 (struct cmd_set_vf_broadcast_result,
15003                  vf_id, UINT16);
15004 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
15005         TOKEN_STRING_INITIALIZER
15006                 (struct cmd_set_vf_broadcast_result,
15007                  on_off, "on#off");
15008
15009 static void
15010 cmd_set_vf_broadcast_parsed(
15011         void *parsed_result,
15012         __rte_unused struct cmdline *cl,
15013         __rte_unused void *data)
15014 {
15015         struct cmd_set_vf_broadcast_result *res = parsed_result;
15016         int ret = -ENOTSUP;
15017
15018         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15019
15020         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15021                 return;
15022
15023 #ifdef RTE_NET_I40E
15024         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
15025                                             res->vf_id, is_on);
15026 #endif
15027
15028         switch (ret) {
15029         case 0:
15030                 break;
15031         case -EINVAL:
15032                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15033                 break;
15034         case -ENODEV:
15035                 printf("invalid port_id %d\n", res->port_id);
15036                 break;
15037         case -ENOTSUP:
15038                 printf("function not implemented\n");
15039                 break;
15040         default:
15041                 printf("programming error: (%s)\n", strerror(-ret));
15042         }
15043 }
15044
15045 cmdline_parse_inst_t cmd_set_vf_broadcast = {
15046         .f = cmd_set_vf_broadcast_parsed,
15047         .data = NULL,
15048         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
15049         .tokens = {
15050                 (void *)&cmd_set_vf_broadcast_set,
15051                 (void *)&cmd_set_vf_broadcast_vf,
15052                 (void *)&cmd_set_vf_broadcast_broadcast,
15053                 (void *)&cmd_set_vf_broadcast_port_id,
15054                 (void *)&cmd_set_vf_broadcast_vf_id,
15055                 (void *)&cmd_set_vf_broadcast_on_off,
15056                 NULL,
15057         },
15058 };
15059
15060 /* vf vlan tag configuration */
15061
15062 /* Common result structure for vf vlan tag */
15063 struct cmd_set_vf_vlan_tag_result {
15064         cmdline_fixed_string_t set;
15065         cmdline_fixed_string_t vf;
15066         cmdline_fixed_string_t vlan;
15067         cmdline_fixed_string_t tag;
15068         portid_t port_id;
15069         uint16_t vf_id;
15070         cmdline_fixed_string_t on_off;
15071 };
15072
15073 /* Common CLI fields for vf vlan tag enable disable */
15074 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
15075         TOKEN_STRING_INITIALIZER
15076                 (struct cmd_set_vf_vlan_tag_result,
15077                  set, "set");
15078 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
15079         TOKEN_STRING_INITIALIZER
15080                 (struct cmd_set_vf_vlan_tag_result,
15081                  vf, "vf");
15082 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
15083         TOKEN_STRING_INITIALIZER
15084                 (struct cmd_set_vf_vlan_tag_result,
15085                  vlan, "vlan");
15086 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
15087         TOKEN_STRING_INITIALIZER
15088                 (struct cmd_set_vf_vlan_tag_result,
15089                  tag, "tag");
15090 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
15091         TOKEN_NUM_INITIALIZER
15092                 (struct cmd_set_vf_vlan_tag_result,
15093                  port_id, UINT16);
15094 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
15095         TOKEN_NUM_INITIALIZER
15096                 (struct cmd_set_vf_vlan_tag_result,
15097                  vf_id, UINT16);
15098 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
15099         TOKEN_STRING_INITIALIZER
15100                 (struct cmd_set_vf_vlan_tag_result,
15101                  on_off, "on#off");
15102
15103 static void
15104 cmd_set_vf_vlan_tag_parsed(
15105         void *parsed_result,
15106         __rte_unused struct cmdline *cl,
15107         __rte_unused void *data)
15108 {
15109         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
15110         int ret = -ENOTSUP;
15111
15112         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15113
15114         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15115                 return;
15116
15117 #ifdef RTE_NET_I40E
15118         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
15119                                            res->vf_id, is_on);
15120 #endif
15121
15122         switch (ret) {
15123         case 0:
15124                 break;
15125         case -EINVAL:
15126                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15127                 break;
15128         case -ENODEV:
15129                 printf("invalid port_id %d\n", res->port_id);
15130                 break;
15131         case -ENOTSUP:
15132                 printf("function not implemented\n");
15133                 break;
15134         default:
15135                 printf("programming error: (%s)\n", strerror(-ret));
15136         }
15137 }
15138
15139 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15140         .f = cmd_set_vf_vlan_tag_parsed,
15141         .data = NULL,
15142         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15143         .tokens = {
15144                 (void *)&cmd_set_vf_vlan_tag_set,
15145                 (void *)&cmd_set_vf_vlan_tag_vf,
15146                 (void *)&cmd_set_vf_vlan_tag_vlan,
15147                 (void *)&cmd_set_vf_vlan_tag_tag,
15148                 (void *)&cmd_set_vf_vlan_tag_port_id,
15149                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15150                 (void *)&cmd_set_vf_vlan_tag_on_off,
15151                 NULL,
15152         },
15153 };
15154
15155 /* Common definition of VF and TC TX bandwidth configuration */
15156 struct cmd_vf_tc_bw_result {
15157         cmdline_fixed_string_t set;
15158         cmdline_fixed_string_t vf;
15159         cmdline_fixed_string_t tc;
15160         cmdline_fixed_string_t tx;
15161         cmdline_fixed_string_t min_bw;
15162         cmdline_fixed_string_t max_bw;
15163         cmdline_fixed_string_t strict_link_prio;
15164         portid_t port_id;
15165         uint16_t vf_id;
15166         uint8_t tc_no;
15167         uint32_t bw;
15168         cmdline_fixed_string_t bw_list;
15169         uint8_t tc_map;
15170 };
15171
15172 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15173         TOKEN_STRING_INITIALIZER
15174                 (struct cmd_vf_tc_bw_result,
15175                  set, "set");
15176 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15177         TOKEN_STRING_INITIALIZER
15178                 (struct cmd_vf_tc_bw_result,
15179                  vf, "vf");
15180 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15181         TOKEN_STRING_INITIALIZER
15182                 (struct cmd_vf_tc_bw_result,
15183                  tc, "tc");
15184 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15185         TOKEN_STRING_INITIALIZER
15186                 (struct cmd_vf_tc_bw_result,
15187                  tx, "tx");
15188 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15189         TOKEN_STRING_INITIALIZER
15190                 (struct cmd_vf_tc_bw_result,
15191                  strict_link_prio, "strict-link-priority");
15192 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15193         TOKEN_STRING_INITIALIZER
15194                 (struct cmd_vf_tc_bw_result,
15195                  min_bw, "min-bandwidth");
15196 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15197         TOKEN_STRING_INITIALIZER
15198                 (struct cmd_vf_tc_bw_result,
15199                  max_bw, "max-bandwidth");
15200 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15201         TOKEN_NUM_INITIALIZER
15202                 (struct cmd_vf_tc_bw_result,
15203                  port_id, UINT16);
15204 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15205         TOKEN_NUM_INITIALIZER
15206                 (struct cmd_vf_tc_bw_result,
15207                  vf_id, UINT16);
15208 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15209         TOKEN_NUM_INITIALIZER
15210                 (struct cmd_vf_tc_bw_result,
15211                  tc_no, UINT8);
15212 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15213         TOKEN_NUM_INITIALIZER
15214                 (struct cmd_vf_tc_bw_result,
15215                  bw, UINT32);
15216 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15217         TOKEN_STRING_INITIALIZER
15218                 (struct cmd_vf_tc_bw_result,
15219                  bw_list, NULL);
15220 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15221         TOKEN_NUM_INITIALIZER
15222                 (struct cmd_vf_tc_bw_result,
15223                  tc_map, UINT8);
15224
15225 /* VF max bandwidth setting */
15226 static void
15227 cmd_vf_max_bw_parsed(
15228         void *parsed_result,
15229         __rte_unused struct cmdline *cl,
15230         __rte_unused void *data)
15231 {
15232         struct cmd_vf_tc_bw_result *res = parsed_result;
15233         int ret = -ENOTSUP;
15234
15235         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15236                 return;
15237
15238 #ifdef RTE_NET_I40E
15239         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15240                                          res->vf_id, res->bw);
15241 #endif
15242
15243         switch (ret) {
15244         case 0:
15245                 break;
15246         case -EINVAL:
15247                 printf("invalid vf_id %d or bandwidth %d\n",
15248                        res->vf_id, res->bw);
15249                 break;
15250         case -ENODEV:
15251                 printf("invalid port_id %d\n", res->port_id);
15252                 break;
15253         case -ENOTSUP:
15254                 printf("function not implemented\n");
15255                 break;
15256         default:
15257                 printf("programming error: (%s)\n", strerror(-ret));
15258         }
15259 }
15260
15261 cmdline_parse_inst_t cmd_vf_max_bw = {
15262         .f = cmd_vf_max_bw_parsed,
15263         .data = NULL,
15264         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15265         .tokens = {
15266                 (void *)&cmd_vf_tc_bw_set,
15267                 (void *)&cmd_vf_tc_bw_vf,
15268                 (void *)&cmd_vf_tc_bw_tx,
15269                 (void *)&cmd_vf_tc_bw_max_bw,
15270                 (void *)&cmd_vf_tc_bw_port_id,
15271                 (void *)&cmd_vf_tc_bw_vf_id,
15272                 (void *)&cmd_vf_tc_bw_bw,
15273                 NULL,
15274         },
15275 };
15276
15277 static int
15278 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15279                            uint8_t *tc_num,
15280                            char *str)
15281 {
15282         uint32_t size;
15283         const char *p, *p0 = str;
15284         char s[256];
15285         char *end;
15286         char *str_fld[16];
15287         uint16_t i;
15288         int ret;
15289
15290         p = strchr(p0, '(');
15291         if (p == NULL) {
15292                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15293                 return -1;
15294         }
15295         p++;
15296         p0 = strchr(p, ')');
15297         if (p0 == NULL) {
15298                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15299                 return -1;
15300         }
15301         size = p0 - p;
15302         if (size >= sizeof(s)) {
15303                 printf("The string size exceeds the internal buffer size\n");
15304                 return -1;
15305         }
15306         snprintf(s, sizeof(s), "%.*s", size, p);
15307         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15308         if (ret <= 0) {
15309                 printf("Failed to get the bandwidth list. ");
15310                 return -1;
15311         }
15312         *tc_num = ret;
15313         for (i = 0; i < ret; i++)
15314                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15315
15316         return 0;
15317 }
15318
15319 /* TC min bandwidth setting */
15320 static void
15321 cmd_vf_tc_min_bw_parsed(
15322         void *parsed_result,
15323         __rte_unused struct cmdline *cl,
15324         __rte_unused void *data)
15325 {
15326         struct cmd_vf_tc_bw_result *res = parsed_result;
15327         uint8_t tc_num;
15328         uint8_t bw[16];
15329         int ret = -ENOTSUP;
15330
15331         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15332                 return;
15333
15334         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15335         if (ret)
15336                 return;
15337
15338 #ifdef RTE_NET_I40E
15339         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15340                                               tc_num, bw);
15341 #endif
15342
15343         switch (ret) {
15344         case 0:
15345                 break;
15346         case -EINVAL:
15347                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15348                 break;
15349         case -ENODEV:
15350                 printf("invalid port_id %d\n", res->port_id);
15351                 break;
15352         case -ENOTSUP:
15353                 printf("function not implemented\n");
15354                 break;
15355         default:
15356                 printf("programming error: (%s)\n", strerror(-ret));
15357         }
15358 }
15359
15360 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15361         .f = cmd_vf_tc_min_bw_parsed,
15362         .data = NULL,
15363         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15364                     " <bw1, bw2, ...>",
15365         .tokens = {
15366                 (void *)&cmd_vf_tc_bw_set,
15367                 (void *)&cmd_vf_tc_bw_vf,
15368                 (void *)&cmd_vf_tc_bw_tc,
15369                 (void *)&cmd_vf_tc_bw_tx,
15370                 (void *)&cmd_vf_tc_bw_min_bw,
15371                 (void *)&cmd_vf_tc_bw_port_id,
15372                 (void *)&cmd_vf_tc_bw_vf_id,
15373                 (void *)&cmd_vf_tc_bw_bw_list,
15374                 NULL,
15375         },
15376 };
15377
15378 static void
15379 cmd_tc_min_bw_parsed(
15380         void *parsed_result,
15381         __rte_unused struct cmdline *cl,
15382         __rte_unused void *data)
15383 {
15384         struct cmd_vf_tc_bw_result *res = parsed_result;
15385         struct rte_port *port;
15386         uint8_t tc_num;
15387         uint8_t bw[16];
15388         int ret = -ENOTSUP;
15389
15390         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15391                 return;
15392
15393         port = &ports[res->port_id];
15394         /** Check if the port is not started **/
15395         if (port->port_status != RTE_PORT_STOPPED) {
15396                 printf("Please stop port %d first\n", res->port_id);
15397                 return;
15398         }
15399
15400         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15401         if (ret)
15402                 return;
15403
15404 #ifdef RTE_NET_IXGBE
15405         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15406 #endif
15407
15408         switch (ret) {
15409         case 0:
15410                 break;
15411         case -EINVAL:
15412                 printf("invalid bandwidth\n");
15413                 break;
15414         case -ENODEV:
15415                 printf("invalid port_id %d\n", res->port_id);
15416                 break;
15417         case -ENOTSUP:
15418                 printf("function not implemented\n");
15419                 break;
15420         default:
15421                 printf("programming error: (%s)\n", strerror(-ret));
15422         }
15423 }
15424
15425 cmdline_parse_inst_t cmd_tc_min_bw = {
15426         .f = cmd_tc_min_bw_parsed,
15427         .data = NULL,
15428         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15429         .tokens = {
15430                 (void *)&cmd_vf_tc_bw_set,
15431                 (void *)&cmd_vf_tc_bw_tc,
15432                 (void *)&cmd_vf_tc_bw_tx,
15433                 (void *)&cmd_vf_tc_bw_min_bw,
15434                 (void *)&cmd_vf_tc_bw_port_id,
15435                 (void *)&cmd_vf_tc_bw_bw_list,
15436                 NULL,
15437         },
15438 };
15439
15440 /* TC max bandwidth setting */
15441 static void
15442 cmd_vf_tc_max_bw_parsed(
15443         void *parsed_result,
15444         __rte_unused struct cmdline *cl,
15445         __rte_unused void *data)
15446 {
15447         struct cmd_vf_tc_bw_result *res = parsed_result;
15448         int ret = -ENOTSUP;
15449
15450         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15451                 return;
15452
15453 #ifdef RTE_NET_I40E
15454         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15455                                             res->tc_no, res->bw);
15456 #endif
15457
15458         switch (ret) {
15459         case 0:
15460                 break;
15461         case -EINVAL:
15462                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15463                        res->vf_id, res->tc_no, res->bw);
15464                 break;
15465         case -ENODEV:
15466                 printf("invalid port_id %d\n", res->port_id);
15467                 break;
15468         case -ENOTSUP:
15469                 printf("function not implemented\n");
15470                 break;
15471         default:
15472                 printf("programming error: (%s)\n", strerror(-ret));
15473         }
15474 }
15475
15476 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15477         .f = cmd_vf_tc_max_bw_parsed,
15478         .data = NULL,
15479         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15480                     " <bandwidth>",
15481         .tokens = {
15482                 (void *)&cmd_vf_tc_bw_set,
15483                 (void *)&cmd_vf_tc_bw_vf,
15484                 (void *)&cmd_vf_tc_bw_tc,
15485                 (void *)&cmd_vf_tc_bw_tx,
15486                 (void *)&cmd_vf_tc_bw_max_bw,
15487                 (void *)&cmd_vf_tc_bw_port_id,
15488                 (void *)&cmd_vf_tc_bw_vf_id,
15489                 (void *)&cmd_vf_tc_bw_tc_no,
15490                 (void *)&cmd_vf_tc_bw_bw,
15491                 NULL,
15492         },
15493 };
15494
15495 /** Set VXLAN encapsulation details */
15496 struct cmd_set_vxlan_result {
15497         cmdline_fixed_string_t set;
15498         cmdline_fixed_string_t vxlan;
15499         cmdline_fixed_string_t pos_token;
15500         cmdline_fixed_string_t ip_version;
15501         uint32_t vlan_present:1;
15502         uint32_t vni;
15503         uint16_t udp_src;
15504         uint16_t udp_dst;
15505         cmdline_ipaddr_t ip_src;
15506         cmdline_ipaddr_t ip_dst;
15507         uint16_t tci;
15508         uint8_t tos;
15509         uint8_t ttl;
15510         struct rte_ether_addr eth_src;
15511         struct rte_ether_addr eth_dst;
15512 };
15513
15514 cmdline_parse_token_string_t cmd_set_vxlan_set =
15515         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15516 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15517         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15518 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15519         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15520                                  "vxlan-tos-ttl");
15521 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15522         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15523                                  "vxlan-with-vlan");
15524 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15525         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15526                                  "ip-version");
15527 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15528         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15529                                  "ipv4#ipv6");
15530 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15531         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15532                                  "vni");
15533 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15534         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15535 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15536         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15537                                  "udp-src");
15538 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15539         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15540 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15541         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15542                                  "udp-dst");
15543 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15544         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15545 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15546         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15547                                  "ip-tos");
15548 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15549         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15550 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15551         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15552                                  "ip-ttl");
15553 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15554         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15555 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15556         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15557                                  "ip-src");
15558 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15559         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15560 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15561         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15562                                  "ip-dst");
15563 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15564         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15565 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15566         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15567                                  "vlan-tci");
15568 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15569         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15570 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15571         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15572                                  "eth-src");
15573 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15574         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15575 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15576         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15577                                  "eth-dst");
15578 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15579         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15580
15581 static void cmd_set_vxlan_parsed(void *parsed_result,
15582         __rte_unused struct cmdline *cl,
15583         __rte_unused void *data)
15584 {
15585         struct cmd_set_vxlan_result *res = parsed_result;
15586         union {
15587                 uint32_t vxlan_id;
15588                 uint8_t vni[4];
15589         } id = {
15590                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15591         };
15592
15593         vxlan_encap_conf.select_tos_ttl = 0;
15594         if (strcmp(res->vxlan, "vxlan") == 0)
15595                 vxlan_encap_conf.select_vlan = 0;
15596         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15597                 vxlan_encap_conf.select_vlan = 1;
15598         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15599                 vxlan_encap_conf.select_vlan = 0;
15600                 vxlan_encap_conf.select_tos_ttl = 1;
15601         }
15602         if (strcmp(res->ip_version, "ipv4") == 0)
15603                 vxlan_encap_conf.select_ipv4 = 1;
15604         else if (strcmp(res->ip_version, "ipv6") == 0)
15605                 vxlan_encap_conf.select_ipv4 = 0;
15606         else
15607                 return;
15608         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15609         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15610         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15611         vxlan_encap_conf.ip_tos = res->tos;
15612         vxlan_encap_conf.ip_ttl = res->ttl;
15613         if (vxlan_encap_conf.select_ipv4) {
15614                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15615                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15616         } else {
15617                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15618                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15619         }
15620         if (vxlan_encap_conf.select_vlan)
15621                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15622         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15623                    RTE_ETHER_ADDR_LEN);
15624         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15625                    RTE_ETHER_ADDR_LEN);
15626 }
15627
15628 cmdline_parse_inst_t cmd_set_vxlan = {
15629         .f = cmd_set_vxlan_parsed,
15630         .data = NULL,
15631         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15632                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15633                 " eth-src <eth-src> eth-dst <eth-dst>",
15634         .tokens = {
15635                 (void *)&cmd_set_vxlan_set,
15636                 (void *)&cmd_set_vxlan_vxlan,
15637                 (void *)&cmd_set_vxlan_ip_version,
15638                 (void *)&cmd_set_vxlan_ip_version_value,
15639                 (void *)&cmd_set_vxlan_vni,
15640                 (void *)&cmd_set_vxlan_vni_value,
15641                 (void *)&cmd_set_vxlan_udp_src,
15642                 (void *)&cmd_set_vxlan_udp_src_value,
15643                 (void *)&cmd_set_vxlan_udp_dst,
15644                 (void *)&cmd_set_vxlan_udp_dst_value,
15645                 (void *)&cmd_set_vxlan_ip_src,
15646                 (void *)&cmd_set_vxlan_ip_src_value,
15647                 (void *)&cmd_set_vxlan_ip_dst,
15648                 (void *)&cmd_set_vxlan_ip_dst_value,
15649                 (void *)&cmd_set_vxlan_eth_src,
15650                 (void *)&cmd_set_vxlan_eth_src_value,
15651                 (void *)&cmd_set_vxlan_eth_dst,
15652                 (void *)&cmd_set_vxlan_eth_dst_value,
15653                 NULL,
15654         },
15655 };
15656
15657 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15658         .f = cmd_set_vxlan_parsed,
15659         .data = NULL,
15660         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15661                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15662                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15663                 " eth-dst <eth-dst>",
15664         .tokens = {
15665                 (void *)&cmd_set_vxlan_set,
15666                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15667                 (void *)&cmd_set_vxlan_ip_version,
15668                 (void *)&cmd_set_vxlan_ip_version_value,
15669                 (void *)&cmd_set_vxlan_vni,
15670                 (void *)&cmd_set_vxlan_vni_value,
15671                 (void *)&cmd_set_vxlan_udp_src,
15672                 (void *)&cmd_set_vxlan_udp_src_value,
15673                 (void *)&cmd_set_vxlan_udp_dst,
15674                 (void *)&cmd_set_vxlan_udp_dst_value,
15675                 (void *)&cmd_set_vxlan_ip_tos,
15676                 (void *)&cmd_set_vxlan_ip_tos_value,
15677                 (void *)&cmd_set_vxlan_ip_ttl,
15678                 (void *)&cmd_set_vxlan_ip_ttl_value,
15679                 (void *)&cmd_set_vxlan_ip_src,
15680                 (void *)&cmd_set_vxlan_ip_src_value,
15681                 (void *)&cmd_set_vxlan_ip_dst,
15682                 (void *)&cmd_set_vxlan_ip_dst_value,
15683                 (void *)&cmd_set_vxlan_eth_src,
15684                 (void *)&cmd_set_vxlan_eth_src_value,
15685                 (void *)&cmd_set_vxlan_eth_dst,
15686                 (void *)&cmd_set_vxlan_eth_dst_value,
15687                 NULL,
15688         },
15689 };
15690
15691 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15692         .f = cmd_set_vxlan_parsed,
15693         .data = NULL,
15694         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15695                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15696                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15697                 " <eth-dst>",
15698         .tokens = {
15699                 (void *)&cmd_set_vxlan_set,
15700                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15701                 (void *)&cmd_set_vxlan_ip_version,
15702                 (void *)&cmd_set_vxlan_ip_version_value,
15703                 (void *)&cmd_set_vxlan_vni,
15704                 (void *)&cmd_set_vxlan_vni_value,
15705                 (void *)&cmd_set_vxlan_udp_src,
15706                 (void *)&cmd_set_vxlan_udp_src_value,
15707                 (void *)&cmd_set_vxlan_udp_dst,
15708                 (void *)&cmd_set_vxlan_udp_dst_value,
15709                 (void *)&cmd_set_vxlan_ip_src,
15710                 (void *)&cmd_set_vxlan_ip_src_value,
15711                 (void *)&cmd_set_vxlan_ip_dst,
15712                 (void *)&cmd_set_vxlan_ip_dst_value,
15713                 (void *)&cmd_set_vxlan_vlan,
15714                 (void *)&cmd_set_vxlan_vlan_value,
15715                 (void *)&cmd_set_vxlan_eth_src,
15716                 (void *)&cmd_set_vxlan_eth_src_value,
15717                 (void *)&cmd_set_vxlan_eth_dst,
15718                 (void *)&cmd_set_vxlan_eth_dst_value,
15719                 NULL,
15720         },
15721 };
15722
15723 /** Set NVGRE encapsulation details */
15724 struct cmd_set_nvgre_result {
15725         cmdline_fixed_string_t set;
15726         cmdline_fixed_string_t nvgre;
15727         cmdline_fixed_string_t pos_token;
15728         cmdline_fixed_string_t ip_version;
15729         uint32_t tni;
15730         cmdline_ipaddr_t ip_src;
15731         cmdline_ipaddr_t ip_dst;
15732         uint16_t tci;
15733         struct rte_ether_addr eth_src;
15734         struct rte_ether_addr eth_dst;
15735 };
15736
15737 cmdline_parse_token_string_t cmd_set_nvgre_set =
15738         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15739 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15740         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15741 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15742         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15743                                  "nvgre-with-vlan");
15744 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15745         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15746                                  "ip-version");
15747 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15748         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15749                                  "ipv4#ipv6");
15750 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15751         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15752                                  "tni");
15753 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15754         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15755 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15756         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15757                                  "ip-src");
15758 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15759         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15760 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15761         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15762                                  "ip-dst");
15763 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15764         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15765 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15766         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15767                                  "vlan-tci");
15768 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15769         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15770 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15771         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15772                                  "eth-src");
15773 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15774         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15775 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15776         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15777                                  "eth-dst");
15778 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15779         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15780
15781 static void cmd_set_nvgre_parsed(void *parsed_result,
15782         __rte_unused struct cmdline *cl,
15783         __rte_unused void *data)
15784 {
15785         struct cmd_set_nvgre_result *res = parsed_result;
15786         union {
15787                 uint32_t nvgre_tni;
15788                 uint8_t tni[4];
15789         } id = {
15790                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15791         };
15792
15793         if (strcmp(res->nvgre, "nvgre") == 0)
15794                 nvgre_encap_conf.select_vlan = 0;
15795         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15796                 nvgre_encap_conf.select_vlan = 1;
15797         if (strcmp(res->ip_version, "ipv4") == 0)
15798                 nvgre_encap_conf.select_ipv4 = 1;
15799         else if (strcmp(res->ip_version, "ipv6") == 0)
15800                 nvgre_encap_conf.select_ipv4 = 0;
15801         else
15802                 return;
15803         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15804         if (nvgre_encap_conf.select_ipv4) {
15805                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15806                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15807         } else {
15808                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15809                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15810         }
15811         if (nvgre_encap_conf.select_vlan)
15812                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15813         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15814                    RTE_ETHER_ADDR_LEN);
15815         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15816                    RTE_ETHER_ADDR_LEN);
15817 }
15818
15819 cmdline_parse_inst_t cmd_set_nvgre = {
15820         .f = cmd_set_nvgre_parsed,
15821         .data = NULL,
15822         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15823                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15824                 " eth-dst <eth-dst>",
15825         .tokens = {
15826                 (void *)&cmd_set_nvgre_set,
15827                 (void *)&cmd_set_nvgre_nvgre,
15828                 (void *)&cmd_set_nvgre_ip_version,
15829                 (void *)&cmd_set_nvgre_ip_version_value,
15830                 (void *)&cmd_set_nvgre_tni,
15831                 (void *)&cmd_set_nvgre_tni_value,
15832                 (void *)&cmd_set_nvgre_ip_src,
15833                 (void *)&cmd_set_nvgre_ip_src_value,
15834                 (void *)&cmd_set_nvgre_ip_dst,
15835                 (void *)&cmd_set_nvgre_ip_dst_value,
15836                 (void *)&cmd_set_nvgre_eth_src,
15837                 (void *)&cmd_set_nvgre_eth_src_value,
15838                 (void *)&cmd_set_nvgre_eth_dst,
15839                 (void *)&cmd_set_nvgre_eth_dst_value,
15840                 NULL,
15841         },
15842 };
15843
15844 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15845         .f = cmd_set_nvgre_parsed,
15846         .data = NULL,
15847         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15848                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15849                 " eth-src <eth-src> eth-dst <eth-dst>",
15850         .tokens = {
15851                 (void *)&cmd_set_nvgre_set,
15852                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15853                 (void *)&cmd_set_nvgre_ip_version,
15854                 (void *)&cmd_set_nvgre_ip_version_value,
15855                 (void *)&cmd_set_nvgre_tni,
15856                 (void *)&cmd_set_nvgre_tni_value,
15857                 (void *)&cmd_set_nvgre_ip_src,
15858                 (void *)&cmd_set_nvgre_ip_src_value,
15859                 (void *)&cmd_set_nvgre_ip_dst,
15860                 (void *)&cmd_set_nvgre_ip_dst_value,
15861                 (void *)&cmd_set_nvgre_vlan,
15862                 (void *)&cmd_set_nvgre_vlan_value,
15863                 (void *)&cmd_set_nvgre_eth_src,
15864                 (void *)&cmd_set_nvgre_eth_src_value,
15865                 (void *)&cmd_set_nvgre_eth_dst,
15866                 (void *)&cmd_set_nvgre_eth_dst_value,
15867                 NULL,
15868         },
15869 };
15870
15871 /** Set L2 encapsulation details */
15872 struct cmd_set_l2_encap_result {
15873         cmdline_fixed_string_t set;
15874         cmdline_fixed_string_t l2_encap;
15875         cmdline_fixed_string_t pos_token;
15876         cmdline_fixed_string_t ip_version;
15877         uint32_t vlan_present:1;
15878         uint16_t tci;
15879         struct rte_ether_addr eth_src;
15880         struct rte_ether_addr eth_dst;
15881 };
15882
15883 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15884         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15885 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15886         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15887 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15888         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15889                                  "l2_encap-with-vlan");
15890 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15891         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15892                                  "ip-version");
15893 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15894         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15895                                  "ipv4#ipv6");
15896 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15897         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15898                                  "vlan-tci");
15899 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15900         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15901 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15902         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15903                                  "eth-src");
15904 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15905         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15906 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15907         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15908                                  "eth-dst");
15909 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15910         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15911
15912 static void cmd_set_l2_encap_parsed(void *parsed_result,
15913         __rte_unused struct cmdline *cl,
15914         __rte_unused void *data)
15915 {
15916         struct cmd_set_l2_encap_result *res = parsed_result;
15917
15918         if (strcmp(res->l2_encap, "l2_encap") == 0)
15919                 l2_encap_conf.select_vlan = 0;
15920         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15921                 l2_encap_conf.select_vlan = 1;
15922         if (strcmp(res->ip_version, "ipv4") == 0)
15923                 l2_encap_conf.select_ipv4 = 1;
15924         else if (strcmp(res->ip_version, "ipv6") == 0)
15925                 l2_encap_conf.select_ipv4 = 0;
15926         else
15927                 return;
15928         if (l2_encap_conf.select_vlan)
15929                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15930         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15931                    RTE_ETHER_ADDR_LEN);
15932         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15933                    RTE_ETHER_ADDR_LEN);
15934 }
15935
15936 cmdline_parse_inst_t cmd_set_l2_encap = {
15937         .f = cmd_set_l2_encap_parsed,
15938         .data = NULL,
15939         .help_str = "set l2_encap ip-version ipv4|ipv6"
15940                 " eth-src <eth-src> eth-dst <eth-dst>",
15941         .tokens = {
15942                 (void *)&cmd_set_l2_encap_set,
15943                 (void *)&cmd_set_l2_encap_l2_encap,
15944                 (void *)&cmd_set_l2_encap_ip_version,
15945                 (void *)&cmd_set_l2_encap_ip_version_value,
15946                 (void *)&cmd_set_l2_encap_eth_src,
15947                 (void *)&cmd_set_l2_encap_eth_src_value,
15948                 (void *)&cmd_set_l2_encap_eth_dst,
15949                 (void *)&cmd_set_l2_encap_eth_dst_value,
15950                 NULL,
15951         },
15952 };
15953
15954 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15955         .f = cmd_set_l2_encap_parsed,
15956         .data = NULL,
15957         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15958                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15959         .tokens = {
15960                 (void *)&cmd_set_l2_encap_set,
15961                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15962                 (void *)&cmd_set_l2_encap_ip_version,
15963                 (void *)&cmd_set_l2_encap_ip_version_value,
15964                 (void *)&cmd_set_l2_encap_vlan,
15965                 (void *)&cmd_set_l2_encap_vlan_value,
15966                 (void *)&cmd_set_l2_encap_eth_src,
15967                 (void *)&cmd_set_l2_encap_eth_src_value,
15968                 (void *)&cmd_set_l2_encap_eth_dst,
15969                 (void *)&cmd_set_l2_encap_eth_dst_value,
15970                 NULL,
15971         },
15972 };
15973
15974 /** Set L2 decapsulation details */
15975 struct cmd_set_l2_decap_result {
15976         cmdline_fixed_string_t set;
15977         cmdline_fixed_string_t l2_decap;
15978         cmdline_fixed_string_t pos_token;
15979         uint32_t vlan_present:1;
15980 };
15981
15982 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15983         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15984 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15985         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15986                                  "l2_decap");
15987 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15988         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15989                                  "l2_decap-with-vlan");
15990
15991 static void cmd_set_l2_decap_parsed(void *parsed_result,
15992         __rte_unused struct cmdline *cl,
15993         __rte_unused void *data)
15994 {
15995         struct cmd_set_l2_decap_result *res = parsed_result;
15996
15997         if (strcmp(res->l2_decap, "l2_decap") == 0)
15998                 l2_decap_conf.select_vlan = 0;
15999         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
16000                 l2_decap_conf.select_vlan = 1;
16001 }
16002
16003 cmdline_parse_inst_t cmd_set_l2_decap = {
16004         .f = cmd_set_l2_decap_parsed,
16005         .data = NULL,
16006         .help_str = "set l2_decap",
16007         .tokens = {
16008                 (void *)&cmd_set_l2_decap_set,
16009                 (void *)&cmd_set_l2_decap_l2_decap,
16010                 NULL,
16011         },
16012 };
16013
16014 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
16015         .f = cmd_set_l2_decap_parsed,
16016         .data = NULL,
16017         .help_str = "set l2_decap-with-vlan",
16018         .tokens = {
16019                 (void *)&cmd_set_l2_decap_set,
16020                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
16021                 NULL,
16022         },
16023 };
16024
16025 /** Set MPLSoGRE encapsulation details */
16026 struct cmd_set_mplsogre_encap_result {
16027         cmdline_fixed_string_t set;
16028         cmdline_fixed_string_t mplsogre;
16029         cmdline_fixed_string_t pos_token;
16030         cmdline_fixed_string_t ip_version;
16031         uint32_t vlan_present:1;
16032         uint32_t label;
16033         cmdline_ipaddr_t ip_src;
16034         cmdline_ipaddr_t ip_dst;
16035         uint16_t tci;
16036         struct rte_ether_addr eth_src;
16037         struct rte_ether_addr eth_dst;
16038 };
16039
16040 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
16041         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
16042                                  "set");
16043 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
16044         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
16045                                  "mplsogre_encap");
16046 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
16047         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16048                                  mplsogre, "mplsogre_encap-with-vlan");
16049 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
16050         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16051                                  pos_token, "ip-version");
16052 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
16053         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16054                                  ip_version, "ipv4#ipv6");
16055 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
16056         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16057                                  pos_token, "label");
16058 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
16059         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
16060                               UINT32);
16061 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
16062         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16063                                  pos_token, "ip-src");
16064 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
16065         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
16066 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
16067         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16068                                  pos_token, "ip-dst");
16069 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16070         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16071 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16072         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16073                                  pos_token, "vlan-tci");
16074 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16075         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16076                               UINT16);
16077 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16078         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16079                                  pos_token, "eth-src");
16080 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16081         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16082                                     eth_src);
16083 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16084         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16085                                  pos_token, "eth-dst");
16086 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16087         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16088                                     eth_dst);
16089
16090 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16091         __rte_unused struct cmdline *cl,
16092         __rte_unused void *data)
16093 {
16094         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16095         union {
16096                 uint32_t mplsogre_label;
16097                 uint8_t label[4];
16098         } id = {
16099                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16100         };
16101
16102         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16103                 mplsogre_encap_conf.select_vlan = 0;
16104         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16105                 mplsogre_encap_conf.select_vlan = 1;
16106         if (strcmp(res->ip_version, "ipv4") == 0)
16107                 mplsogre_encap_conf.select_ipv4 = 1;
16108         else if (strcmp(res->ip_version, "ipv6") == 0)
16109                 mplsogre_encap_conf.select_ipv4 = 0;
16110         else
16111                 return;
16112         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16113         if (mplsogre_encap_conf.select_ipv4) {
16114                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16115                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16116         } else {
16117                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16118                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16119         }
16120         if (mplsogre_encap_conf.select_vlan)
16121                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16122         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16123                    RTE_ETHER_ADDR_LEN);
16124         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16125                    RTE_ETHER_ADDR_LEN);
16126 }
16127
16128 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16129         .f = cmd_set_mplsogre_encap_parsed,
16130         .data = NULL,
16131         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16132                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16133                 " eth-dst <eth-dst>",
16134         .tokens = {
16135                 (void *)&cmd_set_mplsogre_encap_set,
16136                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16137                 (void *)&cmd_set_mplsogre_encap_ip_version,
16138                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16139                 (void *)&cmd_set_mplsogre_encap_label,
16140                 (void *)&cmd_set_mplsogre_encap_label_value,
16141                 (void *)&cmd_set_mplsogre_encap_ip_src,
16142                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16143                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16144                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16145                 (void *)&cmd_set_mplsogre_encap_eth_src,
16146                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16147                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16148                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16149                 NULL,
16150         },
16151 };
16152
16153 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16154         .f = cmd_set_mplsogre_encap_parsed,
16155         .data = NULL,
16156         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16157                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16158                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16159         .tokens = {
16160                 (void *)&cmd_set_mplsogre_encap_set,
16161                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16162                 (void *)&cmd_set_mplsogre_encap_ip_version,
16163                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16164                 (void *)&cmd_set_mplsogre_encap_label,
16165                 (void *)&cmd_set_mplsogre_encap_label_value,
16166                 (void *)&cmd_set_mplsogre_encap_ip_src,
16167                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16168                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16169                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16170                 (void *)&cmd_set_mplsogre_encap_vlan,
16171                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16172                 (void *)&cmd_set_mplsogre_encap_eth_src,
16173                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16174                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16175                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16176                 NULL,
16177         },
16178 };
16179
16180 /** Set MPLSoGRE decapsulation details */
16181 struct cmd_set_mplsogre_decap_result {
16182         cmdline_fixed_string_t set;
16183         cmdline_fixed_string_t mplsogre;
16184         cmdline_fixed_string_t pos_token;
16185         cmdline_fixed_string_t ip_version;
16186         uint32_t vlan_present:1;
16187 };
16188
16189 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16190         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16191                                  "set");
16192 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16193         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16194                                  "mplsogre_decap");
16195 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16196         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16197                                  mplsogre, "mplsogre_decap-with-vlan");
16198 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16199         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16200                                  pos_token, "ip-version");
16201 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16202         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16203                                  ip_version, "ipv4#ipv6");
16204
16205 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16206         __rte_unused struct cmdline *cl,
16207         __rte_unused void *data)
16208 {
16209         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16210
16211         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16212                 mplsogre_decap_conf.select_vlan = 0;
16213         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16214                 mplsogre_decap_conf.select_vlan = 1;
16215         if (strcmp(res->ip_version, "ipv4") == 0)
16216                 mplsogre_decap_conf.select_ipv4 = 1;
16217         else if (strcmp(res->ip_version, "ipv6") == 0)
16218                 mplsogre_decap_conf.select_ipv4 = 0;
16219 }
16220
16221 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16222         .f = cmd_set_mplsogre_decap_parsed,
16223         .data = NULL,
16224         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16225         .tokens = {
16226                 (void *)&cmd_set_mplsogre_decap_set,
16227                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16228                 (void *)&cmd_set_mplsogre_decap_ip_version,
16229                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16230                 NULL,
16231         },
16232 };
16233
16234 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16235         .f = cmd_set_mplsogre_decap_parsed,
16236         .data = NULL,
16237         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16238         .tokens = {
16239                 (void *)&cmd_set_mplsogre_decap_set,
16240                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16241                 (void *)&cmd_set_mplsogre_decap_ip_version,
16242                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16243                 NULL,
16244         },
16245 };
16246
16247 /** Set MPLSoUDP encapsulation details */
16248 struct cmd_set_mplsoudp_encap_result {
16249         cmdline_fixed_string_t set;
16250         cmdline_fixed_string_t mplsoudp;
16251         cmdline_fixed_string_t pos_token;
16252         cmdline_fixed_string_t ip_version;
16253         uint32_t vlan_present:1;
16254         uint32_t label;
16255         uint16_t udp_src;
16256         uint16_t udp_dst;
16257         cmdline_ipaddr_t ip_src;
16258         cmdline_ipaddr_t ip_dst;
16259         uint16_t tci;
16260         struct rte_ether_addr eth_src;
16261         struct rte_ether_addr eth_dst;
16262 };
16263
16264 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16265         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16266                                  "set");
16267 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16268         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16269                                  "mplsoudp_encap");
16270 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16271         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16272                                  mplsoudp, "mplsoudp_encap-with-vlan");
16273 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16274         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16275                                  pos_token, "ip-version");
16276 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16277         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16278                                  ip_version, "ipv4#ipv6");
16279 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16280         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16281                                  pos_token, "label");
16282 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16283         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16284                               UINT32);
16285 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16286         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16287                                  pos_token, "udp-src");
16288 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16289         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16290                               UINT16);
16291 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16292         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16293                                  pos_token, "udp-dst");
16294 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16295         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16296                               UINT16);
16297 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16298         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16299                                  pos_token, "ip-src");
16300 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16301         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16302 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16303         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16304                                  pos_token, "ip-dst");
16305 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16306         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16307 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16308         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16309                                  pos_token, "vlan-tci");
16310 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16311         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16312                               UINT16);
16313 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16314         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16315                                  pos_token, "eth-src");
16316 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16317         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16318                                     eth_src);
16319 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16320         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16321                                  pos_token, "eth-dst");
16322 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16323         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16324                                     eth_dst);
16325
16326 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16327         __rte_unused struct cmdline *cl,
16328         __rte_unused void *data)
16329 {
16330         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16331         union {
16332                 uint32_t mplsoudp_label;
16333                 uint8_t label[4];
16334         } id = {
16335                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16336         };
16337
16338         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16339                 mplsoudp_encap_conf.select_vlan = 0;
16340         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16341                 mplsoudp_encap_conf.select_vlan = 1;
16342         if (strcmp(res->ip_version, "ipv4") == 0)
16343                 mplsoudp_encap_conf.select_ipv4 = 1;
16344         else if (strcmp(res->ip_version, "ipv6") == 0)
16345                 mplsoudp_encap_conf.select_ipv4 = 0;
16346         else
16347                 return;
16348         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16349         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16350         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16351         if (mplsoudp_encap_conf.select_ipv4) {
16352                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16353                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16354         } else {
16355                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16356                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16357         }
16358         if (mplsoudp_encap_conf.select_vlan)
16359                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16360         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16361                    RTE_ETHER_ADDR_LEN);
16362         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16363                    RTE_ETHER_ADDR_LEN);
16364 }
16365
16366 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16367         .f = cmd_set_mplsoudp_encap_parsed,
16368         .data = NULL,
16369         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16370                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16371                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16372         .tokens = {
16373                 (void *)&cmd_set_mplsoudp_encap_set,
16374                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16375                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16376                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16377                 (void *)&cmd_set_mplsoudp_encap_label,
16378                 (void *)&cmd_set_mplsoudp_encap_label_value,
16379                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16380                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16381                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16382                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16383                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16384                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16385                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16386                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16387                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16388                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16389                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16390                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16391                 NULL,
16392         },
16393 };
16394
16395 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16396         .f = cmd_set_mplsoudp_encap_parsed,
16397         .data = NULL,
16398         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16399                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16400                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16401                 " eth-src <eth-src> eth-dst <eth-dst>",
16402         .tokens = {
16403                 (void *)&cmd_set_mplsoudp_encap_set,
16404                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16405                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16406                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16407                 (void *)&cmd_set_mplsoudp_encap_label,
16408                 (void *)&cmd_set_mplsoudp_encap_label_value,
16409                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16410                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16411                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16412                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16413                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16414                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16415                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16416                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16417                 (void *)&cmd_set_mplsoudp_encap_vlan,
16418                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16419                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16420                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16421                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16422                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16423                 NULL,
16424         },
16425 };
16426
16427 /** Set MPLSoUDP decapsulation details */
16428 struct cmd_set_mplsoudp_decap_result {
16429         cmdline_fixed_string_t set;
16430         cmdline_fixed_string_t mplsoudp;
16431         cmdline_fixed_string_t pos_token;
16432         cmdline_fixed_string_t ip_version;
16433         uint32_t vlan_present:1;
16434 };
16435
16436 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16437         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16438                                  "set");
16439 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16440         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16441                                  "mplsoudp_decap");
16442 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16443         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16444                                  mplsoudp, "mplsoudp_decap-with-vlan");
16445 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16446         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16447                                  pos_token, "ip-version");
16448 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16449         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16450                                  ip_version, "ipv4#ipv6");
16451
16452 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16453         __rte_unused struct cmdline *cl,
16454         __rte_unused void *data)
16455 {
16456         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16457
16458         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16459                 mplsoudp_decap_conf.select_vlan = 0;
16460         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16461                 mplsoudp_decap_conf.select_vlan = 1;
16462         if (strcmp(res->ip_version, "ipv4") == 0)
16463                 mplsoudp_decap_conf.select_ipv4 = 1;
16464         else if (strcmp(res->ip_version, "ipv6") == 0)
16465                 mplsoudp_decap_conf.select_ipv4 = 0;
16466 }
16467
16468 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16469         .f = cmd_set_mplsoudp_decap_parsed,
16470         .data = NULL,
16471         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16472         .tokens = {
16473                 (void *)&cmd_set_mplsoudp_decap_set,
16474                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16475                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16476                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16477                 NULL,
16478         },
16479 };
16480
16481 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16482         .f = cmd_set_mplsoudp_decap_parsed,
16483         .data = NULL,
16484         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16485         .tokens = {
16486                 (void *)&cmd_set_mplsoudp_decap_set,
16487                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16488                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16489                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16490                 NULL,
16491         },
16492 };
16493
16494 /* Strict link priority scheduling mode setting */
16495 static void
16496 cmd_strict_link_prio_parsed(
16497         void *parsed_result,
16498         __rte_unused struct cmdline *cl,
16499         __rte_unused void *data)
16500 {
16501         struct cmd_vf_tc_bw_result *res = parsed_result;
16502         int ret = -ENOTSUP;
16503
16504         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16505                 return;
16506
16507 #ifdef RTE_NET_I40E
16508         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16509 #endif
16510
16511         switch (ret) {
16512         case 0:
16513                 break;
16514         case -EINVAL:
16515                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16516                 break;
16517         case -ENODEV:
16518                 printf("invalid port_id %d\n", res->port_id);
16519                 break;
16520         case -ENOTSUP:
16521                 printf("function not implemented\n");
16522                 break;
16523         default:
16524                 printf("programming error: (%s)\n", strerror(-ret));
16525         }
16526 }
16527
16528 cmdline_parse_inst_t cmd_strict_link_prio = {
16529         .f = cmd_strict_link_prio_parsed,
16530         .data = NULL,
16531         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16532         .tokens = {
16533                 (void *)&cmd_vf_tc_bw_set,
16534                 (void *)&cmd_vf_tc_bw_tx,
16535                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16536                 (void *)&cmd_vf_tc_bw_port_id,
16537                 (void *)&cmd_vf_tc_bw_tc_map,
16538                 NULL,
16539         },
16540 };
16541
16542 /* Load dynamic device personalization*/
16543 struct cmd_ddp_add_result {
16544         cmdline_fixed_string_t ddp;
16545         cmdline_fixed_string_t add;
16546         portid_t port_id;
16547         char filepath[];
16548 };
16549
16550 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16551         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16552 cmdline_parse_token_string_t cmd_ddp_add_add =
16553         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16554 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16555         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16556 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16557         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16558
16559 static void
16560 cmd_ddp_add_parsed(
16561         void *parsed_result,
16562         __rte_unused struct cmdline *cl,
16563         __rte_unused void *data)
16564 {
16565         struct cmd_ddp_add_result *res = parsed_result;
16566         uint8_t *buff;
16567         uint32_t size;
16568         char *filepath;
16569         char *file_fld[2];
16570         int file_num;
16571         int ret = -ENOTSUP;
16572
16573         if (!all_ports_stopped()) {
16574                 printf("Please stop all ports first\n");
16575                 return;
16576         }
16577
16578         filepath = strdup(res->filepath);
16579         if (filepath == NULL) {
16580                 printf("Failed to allocate memory\n");
16581                 return;
16582         }
16583         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16584
16585         buff = open_file(file_fld[0], &size);
16586         if (!buff) {
16587                 free((void *)filepath);
16588                 return;
16589         }
16590
16591 #ifdef RTE_NET_I40E
16592         if (ret == -ENOTSUP)
16593                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16594                                                buff, size,
16595                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16596 #endif
16597
16598         if (ret == -EEXIST)
16599                 printf("Profile has already existed.\n");
16600         else if (ret < 0)
16601                 printf("Failed to load profile.\n");
16602         else if (file_num == 2)
16603                 save_file(file_fld[1], buff, size);
16604
16605         close_file(buff);
16606         free((void *)filepath);
16607 }
16608
16609 cmdline_parse_inst_t cmd_ddp_add = {
16610         .f = cmd_ddp_add_parsed,
16611         .data = NULL,
16612         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16613         .tokens = {
16614                 (void *)&cmd_ddp_add_ddp,
16615                 (void *)&cmd_ddp_add_add,
16616                 (void *)&cmd_ddp_add_port_id,
16617                 (void *)&cmd_ddp_add_filepath,
16618                 NULL,
16619         },
16620 };
16621
16622 /* Delete dynamic device personalization*/
16623 struct cmd_ddp_del_result {
16624         cmdline_fixed_string_t ddp;
16625         cmdline_fixed_string_t del;
16626         portid_t port_id;
16627         char filepath[];
16628 };
16629
16630 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16631         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16632 cmdline_parse_token_string_t cmd_ddp_del_del =
16633         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16634 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16635         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16636 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16637         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16638
16639 static void
16640 cmd_ddp_del_parsed(
16641         void *parsed_result,
16642         __rte_unused struct cmdline *cl,
16643         __rte_unused void *data)
16644 {
16645         struct cmd_ddp_del_result *res = parsed_result;
16646         uint8_t *buff;
16647         uint32_t size;
16648         int ret = -ENOTSUP;
16649
16650         if (!all_ports_stopped()) {
16651                 printf("Please stop all ports first\n");
16652                 return;
16653         }
16654
16655         buff = open_file(res->filepath, &size);
16656         if (!buff)
16657                 return;
16658
16659 #ifdef RTE_NET_I40E
16660         if (ret == -ENOTSUP)
16661                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16662                                                buff, size,
16663                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16664 #endif
16665
16666         if (ret == -EACCES)
16667                 printf("Profile does not exist.\n");
16668         else if (ret < 0)
16669                 printf("Failed to delete profile.\n");
16670
16671         close_file(buff);
16672 }
16673
16674 cmdline_parse_inst_t cmd_ddp_del = {
16675         .f = cmd_ddp_del_parsed,
16676         .data = NULL,
16677         .help_str = "ddp del <port_id> <backup_profile_path>",
16678         .tokens = {
16679                 (void *)&cmd_ddp_del_ddp,
16680                 (void *)&cmd_ddp_del_del,
16681                 (void *)&cmd_ddp_del_port_id,
16682                 (void *)&cmd_ddp_del_filepath,
16683                 NULL,
16684         },
16685 };
16686
16687 /* Get dynamic device personalization profile info */
16688 struct cmd_ddp_info_result {
16689         cmdline_fixed_string_t ddp;
16690         cmdline_fixed_string_t get;
16691         cmdline_fixed_string_t info;
16692         char filepath[];
16693 };
16694
16695 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16696         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16697 cmdline_parse_token_string_t cmd_ddp_info_get =
16698         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16699 cmdline_parse_token_string_t cmd_ddp_info_info =
16700         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16701 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16702         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16703
16704 static void
16705 cmd_ddp_info_parsed(
16706         void *parsed_result,
16707         __rte_unused struct cmdline *cl,
16708         __rte_unused void *data)
16709 {
16710         struct cmd_ddp_info_result *res = parsed_result;
16711         uint8_t *pkg;
16712         uint32_t pkg_size;
16713         int ret = -ENOTSUP;
16714 #ifdef RTE_NET_I40E
16715         uint32_t i, j, n;
16716         uint8_t *buff;
16717         uint32_t buff_size = 0;
16718         struct rte_pmd_i40e_profile_info info;
16719         uint32_t dev_num = 0;
16720         struct rte_pmd_i40e_ddp_device_id *devs;
16721         uint32_t proto_num = 0;
16722         struct rte_pmd_i40e_proto_info *proto = NULL;
16723         uint32_t pctype_num = 0;
16724         struct rte_pmd_i40e_ptype_info *pctype;
16725         uint32_t ptype_num = 0;
16726         struct rte_pmd_i40e_ptype_info *ptype;
16727         uint8_t proto_id;
16728
16729 #endif
16730
16731         pkg = open_file(res->filepath, &pkg_size);
16732         if (!pkg)
16733                 return;
16734
16735 #ifdef RTE_NET_I40E
16736         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16737                                 (uint8_t *)&info, sizeof(info),
16738                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16739         if (!ret) {
16740                 printf("Global Track id:       0x%x\n", info.track_id);
16741                 printf("Global Version:        %d.%d.%d.%d\n",
16742                         info.version.major,
16743                         info.version.minor,
16744                         info.version.update,
16745                         info.version.draft);
16746                 printf("Global Package name:   %s\n\n", info.name);
16747         }
16748
16749         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16750                                 (uint8_t *)&info, sizeof(info),
16751                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16752         if (!ret) {
16753                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16754                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16755                         info.version.major,
16756                         info.version.minor,
16757                         info.version.update,
16758                         info.version.draft);
16759                 printf("i40e Profile name:     %s\n\n", info.name);
16760         }
16761
16762         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16763                                 (uint8_t *)&buff_size, sizeof(buff_size),
16764                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16765         if (!ret && buff_size) {
16766                 buff = (uint8_t *)malloc(buff_size);
16767                 if (buff) {
16768                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16769                                                 buff, buff_size,
16770                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16771                         if (!ret)
16772                                 printf("Package Notes:\n%s\n\n", buff);
16773                         free(buff);
16774                 }
16775         }
16776
16777         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16778                                 (uint8_t *)&dev_num, sizeof(dev_num),
16779                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16780         if (!ret && dev_num) {
16781                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16782                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16783                 if (devs) {
16784                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16785                                                 (uint8_t *)devs, buff_size,
16786                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16787                         if (!ret) {
16788                                 printf("List of supported devices:\n");
16789                                 for (i = 0; i < dev_num; i++) {
16790                                         printf("  %04X:%04X %04X:%04X\n",
16791                                                 devs[i].vendor_dev_id >> 16,
16792                                                 devs[i].vendor_dev_id & 0xFFFF,
16793                                                 devs[i].sub_vendor_dev_id >> 16,
16794                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16795                                 }
16796                                 printf("\n");
16797                         }
16798                         free(devs);
16799                 }
16800         }
16801
16802         /* get information about protocols and packet types */
16803         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16804                 (uint8_t *)&proto_num, sizeof(proto_num),
16805                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16806         if (ret || !proto_num)
16807                 goto no_print_return;
16808
16809         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16810         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16811         if (!proto)
16812                 goto no_print_return;
16813
16814         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16815                                         buff_size,
16816                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16817         if (!ret) {
16818                 printf("List of used protocols:\n");
16819                 for (i = 0; i < proto_num; i++)
16820                         printf("  %2u: %s\n", proto[i].proto_id,
16821                                proto[i].name);
16822                 printf("\n");
16823         }
16824         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16825                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16826                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16827         if (ret || !pctype_num)
16828                 goto no_print_pctypes;
16829
16830         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16831         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16832         if (!pctype)
16833                 goto no_print_pctypes;
16834
16835         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16836                                         buff_size,
16837                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16838         if (ret) {
16839                 free(pctype);
16840                 goto no_print_pctypes;
16841         }
16842
16843         printf("List of defined packet classification types:\n");
16844         for (i = 0; i < pctype_num; i++) {
16845                 printf("  %2u:", pctype[i].ptype_id);
16846                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16847                         proto_id = pctype[i].protocols[j];
16848                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16849                                 for (n = 0; n < proto_num; n++) {
16850                                         if (proto[n].proto_id == proto_id) {
16851                                                 printf(" %s", proto[n].name);
16852                                                 break;
16853                                         }
16854                                 }
16855                         }
16856                 }
16857                 printf("\n");
16858         }
16859         printf("\n");
16860         free(pctype);
16861
16862 no_print_pctypes:
16863
16864         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16865                                         sizeof(ptype_num),
16866                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16867         if (ret || !ptype_num)
16868                 goto no_print_return;
16869
16870         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16871         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16872         if (!ptype)
16873                 goto no_print_return;
16874
16875         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16876                                         buff_size,
16877                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16878         if (ret) {
16879                 free(ptype);
16880                 goto no_print_return;
16881         }
16882         printf("List of defined packet types:\n");
16883         for (i = 0; i < ptype_num; i++) {
16884                 printf("  %2u:", ptype[i].ptype_id);
16885                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16886                         proto_id = ptype[i].protocols[j];
16887                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16888                                 for (n = 0; n < proto_num; n++) {
16889                                         if (proto[n].proto_id == proto_id) {
16890                                                 printf(" %s", proto[n].name);
16891                                                 break;
16892                                         }
16893                                 }
16894                         }
16895                 }
16896                 printf("\n");
16897         }
16898         free(ptype);
16899         printf("\n");
16900
16901         ret = 0;
16902 no_print_return:
16903         if (proto)
16904                 free(proto);
16905 #endif
16906         if (ret == -ENOTSUP)
16907                 printf("Function not supported in PMD driver\n");
16908         close_file(pkg);
16909 }
16910
16911 cmdline_parse_inst_t cmd_ddp_get_info = {
16912         .f = cmd_ddp_info_parsed,
16913         .data = NULL,
16914         .help_str = "ddp get info <profile_path>",
16915         .tokens = {
16916                 (void *)&cmd_ddp_info_ddp,
16917                 (void *)&cmd_ddp_info_get,
16918                 (void *)&cmd_ddp_info_info,
16919                 (void *)&cmd_ddp_info_filepath,
16920                 NULL,
16921         },
16922 };
16923
16924 /* Get dynamic device personalization profile info list*/
16925 #define PROFILE_INFO_SIZE 48
16926 #define MAX_PROFILE_NUM 16
16927
16928 struct cmd_ddp_get_list_result {
16929         cmdline_fixed_string_t ddp;
16930         cmdline_fixed_string_t get;
16931         cmdline_fixed_string_t list;
16932         portid_t port_id;
16933 };
16934
16935 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16936         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16937 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16938         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16939 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16940         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16941 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16942         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16943
16944 static void
16945 cmd_ddp_get_list_parsed(
16946         __rte_unused void *parsed_result,
16947         __rte_unused struct cmdline *cl,
16948         __rte_unused void *data)
16949 {
16950 #ifdef RTE_NET_I40E
16951         struct cmd_ddp_get_list_result *res = parsed_result;
16952         struct rte_pmd_i40e_profile_list *p_list;
16953         struct rte_pmd_i40e_profile_info *p_info;
16954         uint32_t p_num;
16955         uint32_t size;
16956         uint32_t i;
16957 #endif
16958         int ret = -ENOTSUP;
16959
16960 #ifdef RTE_NET_I40E
16961         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16962         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16963         if (!p_list) {
16964                 printf("%s: Failed to malloc buffer\n", __func__);
16965                 return;
16966         }
16967
16968         if (ret == -ENOTSUP)
16969                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16970                                                 (uint8_t *)p_list, size);
16971
16972         if (!ret) {
16973                 p_num = p_list->p_count;
16974                 printf("Profile number is: %d\n\n", p_num);
16975
16976                 for (i = 0; i < p_num; i++) {
16977                         p_info = &p_list->p_info[i];
16978                         printf("Profile %d:\n", i);
16979                         printf("Track id:     0x%x\n", p_info->track_id);
16980                         printf("Version:      %d.%d.%d.%d\n",
16981                                p_info->version.major,
16982                                p_info->version.minor,
16983                                p_info->version.update,
16984                                p_info->version.draft);
16985                         printf("Profile name: %s\n\n", p_info->name);
16986                 }
16987         }
16988
16989         free(p_list);
16990 #endif
16991
16992         if (ret < 0)
16993                 printf("Failed to get ddp list\n");
16994 }
16995
16996 cmdline_parse_inst_t cmd_ddp_get_list = {
16997         .f = cmd_ddp_get_list_parsed,
16998         .data = NULL,
16999         .help_str = "ddp get list <port_id>",
17000         .tokens = {
17001                 (void *)&cmd_ddp_get_list_ddp,
17002                 (void *)&cmd_ddp_get_list_get,
17003                 (void *)&cmd_ddp_get_list_list,
17004                 (void *)&cmd_ddp_get_list_port_id,
17005                 NULL,
17006         },
17007 };
17008
17009 /* Configure input set */
17010 struct cmd_cfg_input_set_result {
17011         cmdline_fixed_string_t port;
17012         cmdline_fixed_string_t cfg;
17013         portid_t port_id;
17014         cmdline_fixed_string_t pctype;
17015         uint8_t pctype_id;
17016         cmdline_fixed_string_t inset_type;
17017         cmdline_fixed_string_t opt;
17018         cmdline_fixed_string_t field;
17019         uint8_t field_idx;
17020 };
17021
17022 static void
17023 cmd_cfg_input_set_parsed(
17024         __rte_unused void *parsed_result,
17025         __rte_unused struct cmdline *cl,
17026         __rte_unused void *data)
17027 {
17028 #ifdef RTE_NET_I40E
17029         struct cmd_cfg_input_set_result *res = parsed_result;
17030         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17031         struct rte_pmd_i40e_inset inset;
17032 #endif
17033         int ret = -ENOTSUP;
17034
17035         if (!all_ports_stopped()) {
17036                 printf("Please stop all ports first\n");
17037                 return;
17038         }
17039
17040 #ifdef RTE_NET_I40E
17041         if (!strcmp(res->inset_type, "hash_inset"))
17042                 inset_type = INSET_HASH;
17043         else if (!strcmp(res->inset_type, "fdir_inset"))
17044                 inset_type = INSET_FDIR;
17045         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17046                 inset_type = INSET_FDIR_FLX;
17047         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
17048                                      &inset, inset_type);
17049         if (ret) {
17050                 printf("Failed to get input set.\n");
17051                 return;
17052         }
17053
17054         if (!strcmp(res->opt, "get")) {
17055                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
17056                                                    res->field_idx);
17057                 if (ret)
17058                         printf("Field index %d is enabled.\n", res->field_idx);
17059                 else
17060                         printf("Field index %d is disabled.\n", res->field_idx);
17061                 return;
17062         } else if (!strcmp(res->opt, "set"))
17063                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
17064                                                    res->field_idx);
17065         else if (!strcmp(res->opt, "clear"))
17066                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
17067                                                      res->field_idx);
17068         if (ret) {
17069                 printf("Failed to configure input set field.\n");
17070                 return;
17071         }
17072
17073         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17074                                      &inset, inset_type);
17075         if (ret) {
17076                 printf("Failed to set input set.\n");
17077                 return;
17078         }
17079 #endif
17080
17081         if (ret == -ENOTSUP)
17082                 printf("Function not supported\n");
17083 }
17084
17085 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17086         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17087                                  port, "port");
17088 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17089         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17090                                  cfg, "config");
17091 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17092         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17093                               port_id, UINT16);
17094 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17095         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17096                                  pctype, "pctype");
17097 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17098         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17099                               pctype_id, UINT8);
17100 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17101         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17102                                  inset_type,
17103                                  "hash_inset#fdir_inset#fdir_flx_inset");
17104 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17105         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17106                                  opt, "get#set#clear");
17107 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17108         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17109                                  field, "field");
17110 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17111         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17112                               field_idx, UINT8);
17113
17114 cmdline_parse_inst_t cmd_cfg_input_set = {
17115         .f = cmd_cfg_input_set_parsed,
17116         .data = NULL,
17117         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17118                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17119         .tokens = {
17120                 (void *)&cmd_cfg_input_set_port,
17121                 (void *)&cmd_cfg_input_set_cfg,
17122                 (void *)&cmd_cfg_input_set_port_id,
17123                 (void *)&cmd_cfg_input_set_pctype,
17124                 (void *)&cmd_cfg_input_set_pctype_id,
17125                 (void *)&cmd_cfg_input_set_inset_type,
17126                 (void *)&cmd_cfg_input_set_opt,
17127                 (void *)&cmd_cfg_input_set_field,
17128                 (void *)&cmd_cfg_input_set_field_idx,
17129                 NULL,
17130         },
17131 };
17132
17133 /* Clear input set */
17134 struct cmd_clear_input_set_result {
17135         cmdline_fixed_string_t port;
17136         cmdline_fixed_string_t cfg;
17137         portid_t port_id;
17138         cmdline_fixed_string_t pctype;
17139         uint8_t pctype_id;
17140         cmdline_fixed_string_t inset_type;
17141         cmdline_fixed_string_t clear;
17142         cmdline_fixed_string_t all;
17143 };
17144
17145 static void
17146 cmd_clear_input_set_parsed(
17147         __rte_unused void *parsed_result,
17148         __rte_unused struct cmdline *cl,
17149         __rte_unused void *data)
17150 {
17151 #ifdef RTE_NET_I40E
17152         struct cmd_clear_input_set_result *res = parsed_result;
17153         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17154         struct rte_pmd_i40e_inset inset;
17155 #endif
17156         int ret = -ENOTSUP;
17157
17158         if (!all_ports_stopped()) {
17159                 printf("Please stop all ports first\n");
17160                 return;
17161         }
17162
17163 #ifdef RTE_NET_I40E
17164         if (!strcmp(res->inset_type, "hash_inset"))
17165                 inset_type = INSET_HASH;
17166         else if (!strcmp(res->inset_type, "fdir_inset"))
17167                 inset_type = INSET_FDIR;
17168         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17169                 inset_type = INSET_FDIR_FLX;
17170
17171         memset(&inset, 0, sizeof(inset));
17172
17173         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17174                                      &inset, inset_type);
17175         if (ret) {
17176                 printf("Failed to clear input set.\n");
17177                 return;
17178         }
17179
17180 #endif
17181
17182         if (ret == -ENOTSUP)
17183                 printf("Function not supported\n");
17184 }
17185
17186 cmdline_parse_token_string_t cmd_clear_input_set_port =
17187         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17188                                  port, "port");
17189 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17190         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17191                                  cfg, "config");
17192 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17193         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17194                               port_id, UINT16);
17195 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17196         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17197                                  pctype, "pctype");
17198 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17199         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17200                               pctype_id, UINT8);
17201 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17202         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17203                                  inset_type,
17204                                  "hash_inset#fdir_inset#fdir_flx_inset");
17205 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17206         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17207                                  clear, "clear");
17208 cmdline_parse_token_string_t cmd_clear_input_set_all =
17209         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17210                                  all, "all");
17211
17212 cmdline_parse_inst_t cmd_clear_input_set = {
17213         .f = cmd_clear_input_set_parsed,
17214         .data = NULL,
17215         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17216                     "fdir_inset|fdir_flx_inset clear all",
17217         .tokens = {
17218                 (void *)&cmd_clear_input_set_port,
17219                 (void *)&cmd_clear_input_set_cfg,
17220                 (void *)&cmd_clear_input_set_port_id,
17221                 (void *)&cmd_clear_input_set_pctype,
17222                 (void *)&cmd_clear_input_set_pctype_id,
17223                 (void *)&cmd_clear_input_set_inset_type,
17224                 (void *)&cmd_clear_input_set_clear,
17225                 (void *)&cmd_clear_input_set_all,
17226                 NULL,
17227         },
17228 };
17229
17230 /* show vf stats */
17231
17232 /* Common result structure for show vf stats */
17233 struct cmd_show_vf_stats_result {
17234         cmdline_fixed_string_t show;
17235         cmdline_fixed_string_t vf;
17236         cmdline_fixed_string_t stats;
17237         portid_t port_id;
17238         uint16_t vf_id;
17239 };
17240
17241 /* Common CLI fields show vf stats*/
17242 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17243         TOKEN_STRING_INITIALIZER
17244                 (struct cmd_show_vf_stats_result,
17245                  show, "show");
17246 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17247         TOKEN_STRING_INITIALIZER
17248                 (struct cmd_show_vf_stats_result,
17249                  vf, "vf");
17250 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17251         TOKEN_STRING_INITIALIZER
17252                 (struct cmd_show_vf_stats_result,
17253                  stats, "stats");
17254 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17255         TOKEN_NUM_INITIALIZER
17256                 (struct cmd_show_vf_stats_result,
17257                  port_id, UINT16);
17258 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17259         TOKEN_NUM_INITIALIZER
17260                 (struct cmd_show_vf_stats_result,
17261                  vf_id, UINT16);
17262
17263 static void
17264 cmd_show_vf_stats_parsed(
17265         void *parsed_result,
17266         __rte_unused struct cmdline *cl,
17267         __rte_unused void *data)
17268 {
17269         struct cmd_show_vf_stats_result *res = parsed_result;
17270         struct rte_eth_stats stats;
17271         int ret = -ENOTSUP;
17272         static const char *nic_stats_border = "########################";
17273
17274         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17275                 return;
17276
17277         memset(&stats, 0, sizeof(stats));
17278
17279 #ifdef RTE_NET_I40E
17280         if (ret == -ENOTSUP)
17281                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17282                                                 res->vf_id,
17283                                                 &stats);
17284 #endif
17285 #ifdef RTE_NET_BNXT
17286         if (ret == -ENOTSUP)
17287                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17288                                                 res->vf_id,
17289                                                 &stats);
17290 #endif
17291
17292         switch (ret) {
17293         case 0:
17294                 break;
17295         case -EINVAL:
17296                 printf("invalid vf_id %d\n", res->vf_id);
17297                 break;
17298         case -ENODEV:
17299                 printf("invalid port_id %d\n", res->port_id);
17300                 break;
17301         case -ENOTSUP:
17302                 printf("function not implemented\n");
17303                 break;
17304         default:
17305                 printf("programming error: (%s)\n", strerror(-ret));
17306         }
17307
17308         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17309                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17310
17311         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17312                "%-"PRIu64"\n",
17313                stats.ipackets, stats.imissed, stats.ibytes);
17314         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17315         printf("  RX-nombuf:  %-10"PRIu64"\n",
17316                stats.rx_nombuf);
17317         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17318                "%-"PRIu64"\n",
17319                stats.opackets, stats.oerrors, stats.obytes);
17320
17321         printf("  %s############################%s\n",
17322                                nic_stats_border, nic_stats_border);
17323 }
17324
17325 cmdline_parse_inst_t cmd_show_vf_stats = {
17326         .f = cmd_show_vf_stats_parsed,
17327         .data = NULL,
17328         .help_str = "show vf stats <port_id> <vf_id>",
17329         .tokens = {
17330                 (void *)&cmd_show_vf_stats_show,
17331                 (void *)&cmd_show_vf_stats_vf,
17332                 (void *)&cmd_show_vf_stats_stats,
17333                 (void *)&cmd_show_vf_stats_port_id,
17334                 (void *)&cmd_show_vf_stats_vf_id,
17335                 NULL,
17336         },
17337 };
17338
17339 /* clear vf stats */
17340
17341 /* Common result structure for clear vf stats */
17342 struct cmd_clear_vf_stats_result {
17343         cmdline_fixed_string_t clear;
17344         cmdline_fixed_string_t vf;
17345         cmdline_fixed_string_t stats;
17346         portid_t port_id;
17347         uint16_t vf_id;
17348 };
17349
17350 /* Common CLI fields clear vf stats*/
17351 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17352         TOKEN_STRING_INITIALIZER
17353                 (struct cmd_clear_vf_stats_result,
17354                  clear, "clear");
17355 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17356         TOKEN_STRING_INITIALIZER
17357                 (struct cmd_clear_vf_stats_result,
17358                  vf, "vf");
17359 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17360         TOKEN_STRING_INITIALIZER
17361                 (struct cmd_clear_vf_stats_result,
17362                  stats, "stats");
17363 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17364         TOKEN_NUM_INITIALIZER
17365                 (struct cmd_clear_vf_stats_result,
17366                  port_id, UINT16);
17367 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17368         TOKEN_NUM_INITIALIZER
17369                 (struct cmd_clear_vf_stats_result,
17370                  vf_id, UINT16);
17371
17372 static void
17373 cmd_clear_vf_stats_parsed(
17374         void *parsed_result,
17375         __rte_unused struct cmdline *cl,
17376         __rte_unused void *data)
17377 {
17378         struct cmd_clear_vf_stats_result *res = parsed_result;
17379         int ret = -ENOTSUP;
17380
17381         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17382                 return;
17383
17384 #ifdef RTE_NET_I40E
17385         if (ret == -ENOTSUP)
17386                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17387                                                   res->vf_id);
17388 #endif
17389 #ifdef RTE_NET_BNXT
17390         if (ret == -ENOTSUP)
17391                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17392                                                   res->vf_id);
17393 #endif
17394
17395         switch (ret) {
17396         case 0:
17397                 break;
17398         case -EINVAL:
17399                 printf("invalid vf_id %d\n", res->vf_id);
17400                 break;
17401         case -ENODEV:
17402                 printf("invalid port_id %d\n", res->port_id);
17403                 break;
17404         case -ENOTSUP:
17405                 printf("function not implemented\n");
17406                 break;
17407         default:
17408                 printf("programming error: (%s)\n", strerror(-ret));
17409         }
17410 }
17411
17412 cmdline_parse_inst_t cmd_clear_vf_stats = {
17413         .f = cmd_clear_vf_stats_parsed,
17414         .data = NULL,
17415         .help_str = "clear vf stats <port_id> <vf_id>",
17416         .tokens = {
17417                 (void *)&cmd_clear_vf_stats_clear,
17418                 (void *)&cmd_clear_vf_stats_vf,
17419                 (void *)&cmd_clear_vf_stats_stats,
17420                 (void *)&cmd_clear_vf_stats_port_id,
17421                 (void *)&cmd_clear_vf_stats_vf_id,
17422                 NULL,
17423         },
17424 };
17425
17426 /* port config pctype mapping reset */
17427
17428 /* Common result structure for port config pctype mapping reset */
17429 struct cmd_pctype_mapping_reset_result {
17430         cmdline_fixed_string_t port;
17431         cmdline_fixed_string_t config;
17432         portid_t port_id;
17433         cmdline_fixed_string_t pctype;
17434         cmdline_fixed_string_t mapping;
17435         cmdline_fixed_string_t reset;
17436 };
17437
17438 /* Common CLI fields for port config pctype mapping reset*/
17439 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17440         TOKEN_STRING_INITIALIZER
17441                 (struct cmd_pctype_mapping_reset_result,
17442                  port, "port");
17443 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17444         TOKEN_STRING_INITIALIZER
17445                 (struct cmd_pctype_mapping_reset_result,
17446                  config, "config");
17447 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17448         TOKEN_NUM_INITIALIZER
17449                 (struct cmd_pctype_mapping_reset_result,
17450                  port_id, UINT16);
17451 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17452         TOKEN_STRING_INITIALIZER
17453                 (struct cmd_pctype_mapping_reset_result,
17454                  pctype, "pctype");
17455 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17456         TOKEN_STRING_INITIALIZER
17457                 (struct cmd_pctype_mapping_reset_result,
17458                  mapping, "mapping");
17459 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17460         TOKEN_STRING_INITIALIZER
17461                 (struct cmd_pctype_mapping_reset_result,
17462                  reset, "reset");
17463
17464 static void
17465 cmd_pctype_mapping_reset_parsed(
17466         void *parsed_result,
17467         __rte_unused struct cmdline *cl,
17468         __rte_unused void *data)
17469 {
17470         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17471         int ret = -ENOTSUP;
17472
17473         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17474                 return;
17475
17476 #ifdef RTE_NET_I40E
17477         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17478 #endif
17479
17480         switch (ret) {
17481         case 0:
17482                 break;
17483         case -ENODEV:
17484                 printf("invalid port_id %d\n", res->port_id);
17485                 break;
17486         case -ENOTSUP:
17487                 printf("function not implemented\n");
17488                 break;
17489         default:
17490                 printf("programming error: (%s)\n", strerror(-ret));
17491         }
17492 }
17493
17494 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17495         .f = cmd_pctype_mapping_reset_parsed,
17496         .data = NULL,
17497         .help_str = "port config <port_id> pctype mapping reset",
17498         .tokens = {
17499                 (void *)&cmd_pctype_mapping_reset_port,
17500                 (void *)&cmd_pctype_mapping_reset_config,
17501                 (void *)&cmd_pctype_mapping_reset_port_id,
17502                 (void *)&cmd_pctype_mapping_reset_pctype,
17503                 (void *)&cmd_pctype_mapping_reset_mapping,
17504                 (void *)&cmd_pctype_mapping_reset_reset,
17505                 NULL,
17506         },
17507 };
17508
17509 /* show port pctype mapping */
17510
17511 /* Common result structure for show port pctype mapping */
17512 struct cmd_pctype_mapping_get_result {
17513         cmdline_fixed_string_t show;
17514         cmdline_fixed_string_t port;
17515         portid_t port_id;
17516         cmdline_fixed_string_t pctype;
17517         cmdline_fixed_string_t mapping;
17518 };
17519
17520 /* Common CLI fields for pctype mapping get */
17521 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17522         TOKEN_STRING_INITIALIZER
17523                 (struct cmd_pctype_mapping_get_result,
17524                  show, "show");
17525 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17526         TOKEN_STRING_INITIALIZER
17527                 (struct cmd_pctype_mapping_get_result,
17528                  port, "port");
17529 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17530         TOKEN_NUM_INITIALIZER
17531                 (struct cmd_pctype_mapping_get_result,
17532                  port_id, UINT16);
17533 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17534         TOKEN_STRING_INITIALIZER
17535                 (struct cmd_pctype_mapping_get_result,
17536                  pctype, "pctype");
17537 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17538         TOKEN_STRING_INITIALIZER
17539                 (struct cmd_pctype_mapping_get_result,
17540                  mapping, "mapping");
17541
17542 static void
17543 cmd_pctype_mapping_get_parsed(
17544         void *parsed_result,
17545         __rte_unused struct cmdline *cl,
17546         __rte_unused void *data)
17547 {
17548         struct cmd_pctype_mapping_get_result *res = parsed_result;
17549         int ret = -ENOTSUP;
17550 #ifdef RTE_NET_I40E
17551         struct rte_pmd_i40e_flow_type_mapping
17552                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17553         int i, j, first_pctype;
17554 #endif
17555
17556         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17557                 return;
17558
17559 #ifdef RTE_NET_I40E
17560         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17561 #endif
17562
17563         switch (ret) {
17564         case 0:
17565                 break;
17566         case -ENODEV:
17567                 printf("invalid port_id %d\n", res->port_id);
17568                 return;
17569         case -ENOTSUP:
17570                 printf("function not implemented\n");
17571                 return;
17572         default:
17573                 printf("programming error: (%s)\n", strerror(-ret));
17574                 return;
17575         }
17576
17577 #ifdef RTE_NET_I40E
17578         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17579                 if (mapping[i].pctype != 0ULL) {
17580                         first_pctype = 1;
17581
17582                         printf("pctype: ");
17583                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17584                                 if (mapping[i].pctype & (1ULL << j)) {
17585                                         printf(first_pctype ?
17586                                                "%02d" : ",%02d", j);
17587                                         first_pctype = 0;
17588                                 }
17589                         }
17590                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17591                 }
17592         }
17593 #endif
17594 }
17595
17596 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17597         .f = cmd_pctype_mapping_get_parsed,
17598         .data = NULL,
17599         .help_str = "show port <port_id> pctype mapping",
17600         .tokens = {
17601                 (void *)&cmd_pctype_mapping_get_show,
17602                 (void *)&cmd_pctype_mapping_get_port,
17603                 (void *)&cmd_pctype_mapping_get_port_id,
17604                 (void *)&cmd_pctype_mapping_get_pctype,
17605                 (void *)&cmd_pctype_mapping_get_mapping,
17606                 NULL,
17607         },
17608 };
17609
17610 /* port config pctype mapping update */
17611
17612 /* Common result structure for port config pctype mapping update */
17613 struct cmd_pctype_mapping_update_result {
17614         cmdline_fixed_string_t port;
17615         cmdline_fixed_string_t config;
17616         portid_t port_id;
17617         cmdline_fixed_string_t pctype;
17618         cmdline_fixed_string_t mapping;
17619         cmdline_fixed_string_t update;
17620         cmdline_fixed_string_t pctype_list;
17621         uint16_t flow_type;
17622 };
17623
17624 /* Common CLI fields for pctype mapping update*/
17625 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17626         TOKEN_STRING_INITIALIZER
17627                 (struct cmd_pctype_mapping_update_result,
17628                  port, "port");
17629 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17630         TOKEN_STRING_INITIALIZER
17631                 (struct cmd_pctype_mapping_update_result,
17632                  config, "config");
17633 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17634         TOKEN_NUM_INITIALIZER
17635                 (struct cmd_pctype_mapping_update_result,
17636                  port_id, UINT16);
17637 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17638         TOKEN_STRING_INITIALIZER
17639                 (struct cmd_pctype_mapping_update_result,
17640                  pctype, "pctype");
17641 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17642         TOKEN_STRING_INITIALIZER
17643                 (struct cmd_pctype_mapping_update_result,
17644                  mapping, "mapping");
17645 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17646         TOKEN_STRING_INITIALIZER
17647                 (struct cmd_pctype_mapping_update_result,
17648                  update, "update");
17649 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17650         TOKEN_STRING_INITIALIZER
17651                 (struct cmd_pctype_mapping_update_result,
17652                  pctype_list, NULL);
17653 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17654         TOKEN_NUM_INITIALIZER
17655                 (struct cmd_pctype_mapping_update_result,
17656                  flow_type, UINT16);
17657
17658 static void
17659 cmd_pctype_mapping_update_parsed(
17660         void *parsed_result,
17661         __rte_unused struct cmdline *cl,
17662         __rte_unused void *data)
17663 {
17664         struct cmd_pctype_mapping_update_result *res = parsed_result;
17665         int ret = -ENOTSUP;
17666 #ifdef RTE_NET_I40E
17667         struct rte_pmd_i40e_flow_type_mapping mapping;
17668         unsigned int i;
17669         unsigned int nb_item;
17670         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17671 #endif
17672
17673         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17674                 return;
17675
17676 #ifdef RTE_NET_I40E
17677         nb_item = parse_item_list(res->pctype_list, "pctypes",
17678                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17679         mapping.flow_type = res->flow_type;
17680         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17681                 mapping.pctype |= (1ULL << pctype_list[i]);
17682         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17683                                                 &mapping,
17684                                                 1,
17685                                                 0);
17686 #endif
17687
17688         switch (ret) {
17689         case 0:
17690                 break;
17691         case -EINVAL:
17692                 printf("invalid pctype or flow type\n");
17693                 break;
17694         case -ENODEV:
17695                 printf("invalid port_id %d\n", res->port_id);
17696                 break;
17697         case -ENOTSUP:
17698                 printf("function not implemented\n");
17699                 break;
17700         default:
17701                 printf("programming error: (%s)\n", strerror(-ret));
17702         }
17703 }
17704
17705 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17706         .f = cmd_pctype_mapping_update_parsed,
17707         .data = NULL,
17708         .help_str = "port config <port_id> pctype mapping update"
17709         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17710         .tokens = {
17711                 (void *)&cmd_pctype_mapping_update_port,
17712                 (void *)&cmd_pctype_mapping_update_config,
17713                 (void *)&cmd_pctype_mapping_update_port_id,
17714                 (void *)&cmd_pctype_mapping_update_pctype,
17715                 (void *)&cmd_pctype_mapping_update_mapping,
17716                 (void *)&cmd_pctype_mapping_update_update,
17717                 (void *)&cmd_pctype_mapping_update_pc_type,
17718                 (void *)&cmd_pctype_mapping_update_flow_type,
17719                 NULL,
17720         },
17721 };
17722
17723 /* ptype mapping get */
17724
17725 /* Common result structure for ptype mapping get */
17726 struct cmd_ptype_mapping_get_result {
17727         cmdline_fixed_string_t ptype;
17728         cmdline_fixed_string_t mapping;
17729         cmdline_fixed_string_t get;
17730         portid_t port_id;
17731         uint8_t valid_only;
17732 };
17733
17734 /* Common CLI fields for ptype mapping get */
17735 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17736         TOKEN_STRING_INITIALIZER
17737                 (struct cmd_ptype_mapping_get_result,
17738                  ptype, "ptype");
17739 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17740         TOKEN_STRING_INITIALIZER
17741                 (struct cmd_ptype_mapping_get_result,
17742                  mapping, "mapping");
17743 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17744         TOKEN_STRING_INITIALIZER
17745                 (struct cmd_ptype_mapping_get_result,
17746                  get, "get");
17747 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17748         TOKEN_NUM_INITIALIZER
17749                 (struct cmd_ptype_mapping_get_result,
17750                  port_id, UINT16);
17751 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17752         TOKEN_NUM_INITIALIZER
17753                 (struct cmd_ptype_mapping_get_result,
17754                  valid_only, UINT8);
17755
17756 static void
17757 cmd_ptype_mapping_get_parsed(
17758         void *parsed_result,
17759         __rte_unused struct cmdline *cl,
17760         __rte_unused void *data)
17761 {
17762         struct cmd_ptype_mapping_get_result *res = parsed_result;
17763         int ret = -ENOTSUP;
17764 #ifdef RTE_NET_I40E
17765         int max_ptype_num = 256;
17766         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17767         uint16_t count;
17768         int i;
17769 #endif
17770
17771         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17772                 return;
17773
17774 #ifdef RTE_NET_I40E
17775         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17776                                         mapping,
17777                                         max_ptype_num,
17778                                         &count,
17779                                         res->valid_only);
17780 #endif
17781
17782         switch (ret) {
17783         case 0:
17784                 break;
17785         case -ENODEV:
17786                 printf("invalid port_id %d\n", res->port_id);
17787                 break;
17788         case -ENOTSUP:
17789                 printf("function not implemented\n");
17790                 break;
17791         default:
17792                 printf("programming error: (%s)\n", strerror(-ret));
17793         }
17794
17795 #ifdef RTE_NET_I40E
17796         if (!ret) {
17797                 for (i = 0; i < count; i++)
17798                         printf("%3d\t0x%08x\n",
17799                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17800         }
17801 #endif
17802 }
17803
17804 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17805         .f = cmd_ptype_mapping_get_parsed,
17806         .data = NULL,
17807         .help_str = "ptype mapping get <port_id> <valid_only>",
17808         .tokens = {
17809                 (void *)&cmd_ptype_mapping_get_ptype,
17810                 (void *)&cmd_ptype_mapping_get_mapping,
17811                 (void *)&cmd_ptype_mapping_get_get,
17812                 (void *)&cmd_ptype_mapping_get_port_id,
17813                 (void *)&cmd_ptype_mapping_get_valid_only,
17814                 NULL,
17815         },
17816 };
17817
17818 /* ptype mapping replace */
17819
17820 /* Common result structure for ptype mapping replace */
17821 struct cmd_ptype_mapping_replace_result {
17822         cmdline_fixed_string_t ptype;
17823         cmdline_fixed_string_t mapping;
17824         cmdline_fixed_string_t replace;
17825         portid_t port_id;
17826         uint32_t target;
17827         uint8_t mask;
17828         uint32_t pkt_type;
17829 };
17830
17831 /* Common CLI fields for ptype mapping replace */
17832 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17833         TOKEN_STRING_INITIALIZER
17834                 (struct cmd_ptype_mapping_replace_result,
17835                  ptype, "ptype");
17836 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17837         TOKEN_STRING_INITIALIZER
17838                 (struct cmd_ptype_mapping_replace_result,
17839                  mapping, "mapping");
17840 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17841         TOKEN_STRING_INITIALIZER
17842                 (struct cmd_ptype_mapping_replace_result,
17843                  replace, "replace");
17844 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17845         TOKEN_NUM_INITIALIZER
17846                 (struct cmd_ptype_mapping_replace_result,
17847                  port_id, UINT16);
17848 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17849         TOKEN_NUM_INITIALIZER
17850                 (struct cmd_ptype_mapping_replace_result,
17851                  target, UINT32);
17852 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17853         TOKEN_NUM_INITIALIZER
17854                 (struct cmd_ptype_mapping_replace_result,
17855                  mask, UINT8);
17856 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17857         TOKEN_NUM_INITIALIZER
17858                 (struct cmd_ptype_mapping_replace_result,
17859                  pkt_type, UINT32);
17860
17861 static void
17862 cmd_ptype_mapping_replace_parsed(
17863         void *parsed_result,
17864         __rte_unused struct cmdline *cl,
17865         __rte_unused void *data)
17866 {
17867         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17868         int ret = -ENOTSUP;
17869
17870         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17871                 return;
17872
17873 #ifdef RTE_NET_I40E
17874         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17875                                         res->target,
17876                                         res->mask,
17877                                         res->pkt_type);
17878 #endif
17879
17880         switch (ret) {
17881         case 0:
17882                 break;
17883         case -EINVAL:
17884                 printf("invalid ptype 0x%8x or 0x%8x\n",
17885                                 res->target, res->pkt_type);
17886                 break;
17887         case -ENODEV:
17888                 printf("invalid port_id %d\n", res->port_id);
17889                 break;
17890         case -ENOTSUP:
17891                 printf("function not implemented\n");
17892                 break;
17893         default:
17894                 printf("programming error: (%s)\n", strerror(-ret));
17895         }
17896 }
17897
17898 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17899         .f = cmd_ptype_mapping_replace_parsed,
17900         .data = NULL,
17901         .help_str =
17902                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17903         .tokens = {
17904                 (void *)&cmd_ptype_mapping_replace_ptype,
17905                 (void *)&cmd_ptype_mapping_replace_mapping,
17906                 (void *)&cmd_ptype_mapping_replace_replace,
17907                 (void *)&cmd_ptype_mapping_replace_port_id,
17908                 (void *)&cmd_ptype_mapping_replace_target,
17909                 (void *)&cmd_ptype_mapping_replace_mask,
17910                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17911                 NULL,
17912         },
17913 };
17914
17915 /* ptype mapping reset */
17916
17917 /* Common result structure for ptype mapping reset */
17918 struct cmd_ptype_mapping_reset_result {
17919         cmdline_fixed_string_t ptype;
17920         cmdline_fixed_string_t mapping;
17921         cmdline_fixed_string_t reset;
17922         portid_t port_id;
17923 };
17924
17925 /* Common CLI fields for ptype mapping reset*/
17926 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17927         TOKEN_STRING_INITIALIZER
17928                 (struct cmd_ptype_mapping_reset_result,
17929                  ptype, "ptype");
17930 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17931         TOKEN_STRING_INITIALIZER
17932                 (struct cmd_ptype_mapping_reset_result,
17933                  mapping, "mapping");
17934 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17935         TOKEN_STRING_INITIALIZER
17936                 (struct cmd_ptype_mapping_reset_result,
17937                  reset, "reset");
17938 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17939         TOKEN_NUM_INITIALIZER
17940                 (struct cmd_ptype_mapping_reset_result,
17941                  port_id, UINT16);
17942
17943 static void
17944 cmd_ptype_mapping_reset_parsed(
17945         void *parsed_result,
17946         __rte_unused struct cmdline *cl,
17947         __rte_unused void *data)
17948 {
17949         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17950         int ret = -ENOTSUP;
17951
17952         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17953                 return;
17954
17955 #ifdef RTE_NET_I40E
17956         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17957 #endif
17958
17959         switch (ret) {
17960         case 0:
17961                 break;
17962         case -ENODEV:
17963                 printf("invalid port_id %d\n", res->port_id);
17964                 break;
17965         case -ENOTSUP:
17966                 printf("function not implemented\n");
17967                 break;
17968         default:
17969                 printf("programming error: (%s)\n", strerror(-ret));
17970         }
17971 }
17972
17973 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17974         .f = cmd_ptype_mapping_reset_parsed,
17975         .data = NULL,
17976         .help_str = "ptype mapping reset <port_id>",
17977         .tokens = {
17978                 (void *)&cmd_ptype_mapping_reset_ptype,
17979                 (void *)&cmd_ptype_mapping_reset_mapping,
17980                 (void *)&cmd_ptype_mapping_reset_reset,
17981                 (void *)&cmd_ptype_mapping_reset_port_id,
17982                 NULL,
17983         },
17984 };
17985
17986 /* ptype mapping update */
17987
17988 /* Common result structure for ptype mapping update */
17989 struct cmd_ptype_mapping_update_result {
17990         cmdline_fixed_string_t ptype;
17991         cmdline_fixed_string_t mapping;
17992         cmdline_fixed_string_t reset;
17993         portid_t port_id;
17994         uint8_t hw_ptype;
17995         uint32_t sw_ptype;
17996 };
17997
17998 /* Common CLI fields for ptype mapping update*/
17999 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
18000         TOKEN_STRING_INITIALIZER
18001                 (struct cmd_ptype_mapping_update_result,
18002                  ptype, "ptype");
18003 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
18004         TOKEN_STRING_INITIALIZER
18005                 (struct cmd_ptype_mapping_update_result,
18006                  mapping, "mapping");
18007 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
18008         TOKEN_STRING_INITIALIZER
18009                 (struct cmd_ptype_mapping_update_result,
18010                  reset, "update");
18011 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
18012         TOKEN_NUM_INITIALIZER
18013                 (struct cmd_ptype_mapping_update_result,
18014                  port_id, UINT16);
18015 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
18016         TOKEN_NUM_INITIALIZER
18017                 (struct cmd_ptype_mapping_update_result,
18018                  hw_ptype, UINT8);
18019 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
18020         TOKEN_NUM_INITIALIZER
18021                 (struct cmd_ptype_mapping_update_result,
18022                  sw_ptype, UINT32);
18023
18024 static void
18025 cmd_ptype_mapping_update_parsed(
18026         void *parsed_result,
18027         __rte_unused struct cmdline *cl,
18028         __rte_unused void *data)
18029 {
18030         struct cmd_ptype_mapping_update_result *res = parsed_result;
18031         int ret = -ENOTSUP;
18032 #ifdef RTE_NET_I40E
18033         struct rte_pmd_i40e_ptype_mapping mapping;
18034 #endif
18035         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18036                 return;
18037
18038 #ifdef RTE_NET_I40E
18039         mapping.hw_ptype = res->hw_ptype;
18040         mapping.sw_ptype = res->sw_ptype;
18041         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
18042                                                 &mapping,
18043                                                 1,
18044                                                 0);
18045 #endif
18046
18047         switch (ret) {
18048         case 0:
18049                 break;
18050         case -EINVAL:
18051                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
18052                 break;
18053         case -ENODEV:
18054                 printf("invalid port_id %d\n", res->port_id);
18055                 break;
18056         case -ENOTSUP:
18057                 printf("function not implemented\n");
18058                 break;
18059         default:
18060                 printf("programming error: (%s)\n", strerror(-ret));
18061         }
18062 }
18063
18064 cmdline_parse_inst_t cmd_ptype_mapping_update = {
18065         .f = cmd_ptype_mapping_update_parsed,
18066         .data = NULL,
18067         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
18068         .tokens = {
18069                 (void *)&cmd_ptype_mapping_update_ptype,
18070                 (void *)&cmd_ptype_mapping_update_mapping,
18071                 (void *)&cmd_ptype_mapping_update_update,
18072                 (void *)&cmd_ptype_mapping_update_port_id,
18073                 (void *)&cmd_ptype_mapping_update_hw_ptype,
18074                 (void *)&cmd_ptype_mapping_update_sw_ptype,
18075                 NULL,
18076         },
18077 };
18078
18079 /* Common result structure for file commands */
18080 struct cmd_cmdfile_result {
18081         cmdline_fixed_string_t load;
18082         cmdline_fixed_string_t filename;
18083 };
18084
18085 /* Common CLI fields for file commands */
18086 cmdline_parse_token_string_t cmd_load_cmdfile =
18087         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18088 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18089         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18090
18091 static void
18092 cmd_load_from_file_parsed(
18093         void *parsed_result,
18094         __rte_unused struct cmdline *cl,
18095         __rte_unused void *data)
18096 {
18097         struct cmd_cmdfile_result *res = parsed_result;
18098
18099         cmdline_read_from_file(res->filename);
18100 }
18101
18102 cmdline_parse_inst_t cmd_load_from_file = {
18103         .f = cmd_load_from_file_parsed,
18104         .data = NULL,
18105         .help_str = "load <filename>",
18106         .tokens = {
18107                 (void *)&cmd_load_cmdfile,
18108                 (void *)&cmd_load_cmdfile_filename,
18109                 NULL,
18110         },
18111 };
18112
18113 /* Get Rx offloads capabilities */
18114 struct cmd_rx_offload_get_capa_result {
18115         cmdline_fixed_string_t show;
18116         cmdline_fixed_string_t port;
18117         portid_t port_id;
18118         cmdline_fixed_string_t rx_offload;
18119         cmdline_fixed_string_t capabilities;
18120 };
18121
18122 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18123         TOKEN_STRING_INITIALIZER
18124                 (struct cmd_rx_offload_get_capa_result,
18125                  show, "show");
18126 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18127         TOKEN_STRING_INITIALIZER
18128                 (struct cmd_rx_offload_get_capa_result,
18129                  port, "port");
18130 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18131         TOKEN_NUM_INITIALIZER
18132                 (struct cmd_rx_offload_get_capa_result,
18133                  port_id, UINT16);
18134 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18135         TOKEN_STRING_INITIALIZER
18136                 (struct cmd_rx_offload_get_capa_result,
18137                  rx_offload, "rx_offload");
18138 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18139         TOKEN_STRING_INITIALIZER
18140                 (struct cmd_rx_offload_get_capa_result,
18141                  capabilities, "capabilities");
18142
18143 static void
18144 print_rx_offloads(uint64_t offloads)
18145 {
18146         uint64_t single_offload;
18147         int begin;
18148         int end;
18149         int bit;
18150
18151         if (offloads == 0)
18152                 return;
18153
18154         begin = __builtin_ctzll(offloads);
18155         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18156
18157         single_offload = 1ULL << begin;
18158         for (bit = begin; bit < end; bit++) {
18159                 if (offloads & single_offload)
18160                         printf(" %s",
18161                                rte_eth_dev_rx_offload_name(single_offload));
18162                 single_offload <<= 1;
18163         }
18164 }
18165
18166 static void
18167 cmd_rx_offload_get_capa_parsed(
18168         void *parsed_result,
18169         __rte_unused struct cmdline *cl,
18170         __rte_unused void *data)
18171 {
18172         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18173         struct rte_eth_dev_info dev_info;
18174         portid_t port_id = res->port_id;
18175         uint64_t queue_offloads;
18176         uint64_t port_offloads;
18177         int ret;
18178
18179         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18180         if (ret != 0)
18181                 return;
18182
18183         queue_offloads = dev_info.rx_queue_offload_capa;
18184         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18185
18186         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18187         printf("  Per Queue :");
18188         print_rx_offloads(queue_offloads);
18189
18190         printf("\n");
18191         printf("  Per Port  :");
18192         print_rx_offloads(port_offloads);
18193         printf("\n\n");
18194 }
18195
18196 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18197         .f = cmd_rx_offload_get_capa_parsed,
18198         .data = NULL,
18199         .help_str = "show port <port_id> rx_offload capabilities",
18200         .tokens = {
18201                 (void *)&cmd_rx_offload_get_capa_show,
18202                 (void *)&cmd_rx_offload_get_capa_port,
18203                 (void *)&cmd_rx_offload_get_capa_port_id,
18204                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18205                 (void *)&cmd_rx_offload_get_capa_capabilities,
18206                 NULL,
18207         }
18208 };
18209
18210 /* Get Rx offloads configuration */
18211 struct cmd_rx_offload_get_configuration_result {
18212         cmdline_fixed_string_t show;
18213         cmdline_fixed_string_t port;
18214         portid_t port_id;
18215         cmdline_fixed_string_t rx_offload;
18216         cmdline_fixed_string_t configuration;
18217 };
18218
18219 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18220         TOKEN_STRING_INITIALIZER
18221                 (struct cmd_rx_offload_get_configuration_result,
18222                  show, "show");
18223 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18224         TOKEN_STRING_INITIALIZER
18225                 (struct cmd_rx_offload_get_configuration_result,
18226                  port, "port");
18227 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18228         TOKEN_NUM_INITIALIZER
18229                 (struct cmd_rx_offload_get_configuration_result,
18230                  port_id, UINT16);
18231 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18232         TOKEN_STRING_INITIALIZER
18233                 (struct cmd_rx_offload_get_configuration_result,
18234                  rx_offload, "rx_offload");
18235 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18236         TOKEN_STRING_INITIALIZER
18237                 (struct cmd_rx_offload_get_configuration_result,
18238                  configuration, "configuration");
18239
18240 static void
18241 cmd_rx_offload_get_configuration_parsed(
18242         void *parsed_result,
18243         __rte_unused struct cmdline *cl,
18244         __rte_unused void *data)
18245 {
18246         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18247         struct rte_eth_dev_info dev_info;
18248         portid_t port_id = res->port_id;
18249         struct rte_port *port = &ports[port_id];
18250         uint64_t port_offloads;
18251         uint64_t queue_offloads;
18252         uint16_t nb_rx_queues;
18253         int q;
18254         int ret;
18255
18256         printf("Rx Offloading Configuration of port %d :\n", port_id);
18257
18258         port_offloads = port->dev_conf.rxmode.offloads;
18259         printf("  Port :");
18260         print_rx_offloads(port_offloads);
18261         printf("\n");
18262
18263         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18264         if (ret != 0)
18265                 return;
18266
18267         nb_rx_queues = dev_info.nb_rx_queues;
18268         for (q = 0; q < nb_rx_queues; q++) {
18269                 queue_offloads = port->rx_conf[q].offloads;
18270                 printf("  Queue[%2d] :", q);
18271                 print_rx_offloads(queue_offloads);
18272                 printf("\n");
18273         }
18274         printf("\n");
18275 }
18276
18277 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18278         .f = cmd_rx_offload_get_configuration_parsed,
18279         .data = NULL,
18280         .help_str = "show port <port_id> rx_offload configuration",
18281         .tokens = {
18282                 (void *)&cmd_rx_offload_get_configuration_show,
18283                 (void *)&cmd_rx_offload_get_configuration_port,
18284                 (void *)&cmd_rx_offload_get_configuration_port_id,
18285                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18286                 (void *)&cmd_rx_offload_get_configuration_configuration,
18287                 NULL,
18288         }
18289 };
18290
18291 /* Enable/Disable a per port offloading */
18292 struct cmd_config_per_port_rx_offload_result {
18293         cmdline_fixed_string_t port;
18294         cmdline_fixed_string_t config;
18295         portid_t port_id;
18296         cmdline_fixed_string_t rx_offload;
18297         cmdline_fixed_string_t offload;
18298         cmdline_fixed_string_t on_off;
18299 };
18300
18301 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18302         TOKEN_STRING_INITIALIZER
18303                 (struct cmd_config_per_port_rx_offload_result,
18304                  port, "port");
18305 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18306         TOKEN_STRING_INITIALIZER
18307                 (struct cmd_config_per_port_rx_offload_result,
18308                  config, "config");
18309 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18310         TOKEN_NUM_INITIALIZER
18311                 (struct cmd_config_per_port_rx_offload_result,
18312                  port_id, UINT16);
18313 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18314         TOKEN_STRING_INITIALIZER
18315                 (struct cmd_config_per_port_rx_offload_result,
18316                  rx_offload, "rx_offload");
18317 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18318         TOKEN_STRING_INITIALIZER
18319                 (struct cmd_config_per_port_rx_offload_result,
18320                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18321                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18322                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18323                            "scatter#buffer_split#timestamp#security#"
18324                            "keep_crc#rss_hash");
18325 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18326         TOKEN_STRING_INITIALIZER
18327                 (struct cmd_config_per_port_rx_offload_result,
18328                  on_off, "on#off");
18329
18330 static uint64_t
18331 search_rx_offload(const char *name)
18332 {
18333         uint64_t single_offload;
18334         const char *single_name;
18335         int found = 0;
18336         unsigned int bit;
18337
18338         single_offload = 1;
18339         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18340                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18341                 if (!strcasecmp(single_name, name)) {
18342                         found = 1;
18343                         break;
18344                 }
18345                 single_offload <<= 1;
18346         }
18347
18348         if (found)
18349                 return single_offload;
18350
18351         return 0;
18352 }
18353
18354 static void
18355 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18356                                 __rte_unused struct cmdline *cl,
18357                                 __rte_unused void *data)
18358 {
18359         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18360         portid_t port_id = res->port_id;
18361         struct rte_eth_dev_info dev_info;
18362         struct rte_port *port = &ports[port_id];
18363         uint64_t single_offload;
18364         uint16_t nb_rx_queues;
18365         int q;
18366         int ret;
18367
18368         if (port->port_status != RTE_PORT_STOPPED) {
18369                 printf("Error: Can't config offload when Port %d "
18370                        "is not stopped\n", port_id);
18371                 return;
18372         }
18373
18374         single_offload = search_rx_offload(res->offload);
18375         if (single_offload == 0) {
18376                 printf("Unknown offload name: %s\n", res->offload);
18377                 return;
18378         }
18379
18380         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18381         if (ret != 0)
18382                 return;
18383
18384         nb_rx_queues = dev_info.nb_rx_queues;
18385         if (!strcmp(res->on_off, "on")) {
18386                 port->dev_conf.rxmode.offloads |= single_offload;
18387                 for (q = 0; q < nb_rx_queues; q++)
18388                         port->rx_conf[q].offloads |= single_offload;
18389         } else {
18390                 port->dev_conf.rxmode.offloads &= ~single_offload;
18391                 for (q = 0; q < nb_rx_queues; q++)
18392                         port->rx_conf[q].offloads &= ~single_offload;
18393         }
18394
18395         cmd_reconfig_device_queue(port_id, 1, 1);
18396 }
18397
18398 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18399         .f = cmd_config_per_port_rx_offload_parsed,
18400         .data = NULL,
18401         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18402                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18403                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18404                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
18405                     "keep_crc|rss_hash on|off",
18406         .tokens = {
18407                 (void *)&cmd_config_per_port_rx_offload_result_port,
18408                 (void *)&cmd_config_per_port_rx_offload_result_config,
18409                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18410                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18411                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18412                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18413                 NULL,
18414         }
18415 };
18416
18417 /* Enable/Disable a per queue offloading */
18418 struct cmd_config_per_queue_rx_offload_result {
18419         cmdline_fixed_string_t port;
18420         portid_t port_id;
18421         cmdline_fixed_string_t rxq;
18422         uint16_t queue_id;
18423         cmdline_fixed_string_t rx_offload;
18424         cmdline_fixed_string_t offload;
18425         cmdline_fixed_string_t on_off;
18426 };
18427
18428 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18429         TOKEN_STRING_INITIALIZER
18430                 (struct cmd_config_per_queue_rx_offload_result,
18431                  port, "port");
18432 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18433         TOKEN_NUM_INITIALIZER
18434                 (struct cmd_config_per_queue_rx_offload_result,
18435                  port_id, UINT16);
18436 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18437         TOKEN_STRING_INITIALIZER
18438                 (struct cmd_config_per_queue_rx_offload_result,
18439                  rxq, "rxq");
18440 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18441         TOKEN_NUM_INITIALIZER
18442                 (struct cmd_config_per_queue_rx_offload_result,
18443                  queue_id, UINT16);
18444 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18445         TOKEN_STRING_INITIALIZER
18446                 (struct cmd_config_per_queue_rx_offload_result,
18447                  rx_offload, "rx_offload");
18448 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18449         TOKEN_STRING_INITIALIZER
18450                 (struct cmd_config_per_queue_rx_offload_result,
18451                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18452                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18453                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18454                            "scatter#buffer_split#timestamp#security#keep_crc");
18455 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18456         TOKEN_STRING_INITIALIZER
18457                 (struct cmd_config_per_queue_rx_offload_result,
18458                  on_off, "on#off");
18459
18460 static void
18461 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18462                                 __rte_unused struct cmdline *cl,
18463                                 __rte_unused void *data)
18464 {
18465         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18466         struct rte_eth_dev_info dev_info;
18467         portid_t port_id = res->port_id;
18468         uint16_t queue_id = res->queue_id;
18469         struct rte_port *port = &ports[port_id];
18470         uint64_t single_offload;
18471         int ret;
18472
18473         if (port->port_status != RTE_PORT_STOPPED) {
18474                 printf("Error: Can't config offload when Port %d "
18475                        "is not stopped\n", port_id);
18476                 return;
18477         }
18478
18479         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18480         if (ret != 0)
18481                 return;
18482
18483         if (queue_id >= dev_info.nb_rx_queues) {
18484                 printf("Error: input queue_id should be 0 ... "
18485                        "%d\n", dev_info.nb_rx_queues - 1);
18486                 return;
18487         }
18488
18489         single_offload = search_rx_offload(res->offload);
18490         if (single_offload == 0) {
18491                 printf("Unknown offload name: %s\n", res->offload);
18492                 return;
18493         }
18494
18495         if (!strcmp(res->on_off, "on"))
18496                 port->rx_conf[queue_id].offloads |= single_offload;
18497         else
18498                 port->rx_conf[queue_id].offloads &= ~single_offload;
18499
18500         cmd_reconfig_device_queue(port_id, 1, 1);
18501 }
18502
18503 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18504         .f = cmd_config_per_queue_rx_offload_parsed,
18505         .data = NULL,
18506         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18507                     "vlan_strip|ipv4_cksum|"
18508                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18509                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18510                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
18511                     "keep_crc on|off",
18512         .tokens = {
18513                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18514                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18515                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18516                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18517                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18518                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18519                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18520                 NULL,
18521         }
18522 };
18523
18524 /* Get Tx offloads capabilities */
18525 struct cmd_tx_offload_get_capa_result {
18526         cmdline_fixed_string_t show;
18527         cmdline_fixed_string_t port;
18528         portid_t port_id;
18529         cmdline_fixed_string_t tx_offload;
18530         cmdline_fixed_string_t capabilities;
18531 };
18532
18533 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18534         TOKEN_STRING_INITIALIZER
18535                 (struct cmd_tx_offload_get_capa_result,
18536                  show, "show");
18537 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18538         TOKEN_STRING_INITIALIZER
18539                 (struct cmd_tx_offload_get_capa_result,
18540                  port, "port");
18541 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18542         TOKEN_NUM_INITIALIZER
18543                 (struct cmd_tx_offload_get_capa_result,
18544                  port_id, UINT16);
18545 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18546         TOKEN_STRING_INITIALIZER
18547                 (struct cmd_tx_offload_get_capa_result,
18548                  tx_offload, "tx_offload");
18549 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18550         TOKEN_STRING_INITIALIZER
18551                 (struct cmd_tx_offload_get_capa_result,
18552                  capabilities, "capabilities");
18553
18554 static void
18555 print_tx_offloads(uint64_t offloads)
18556 {
18557         uint64_t single_offload;
18558         int begin;
18559         int end;
18560         int bit;
18561
18562         if (offloads == 0)
18563                 return;
18564
18565         begin = __builtin_ctzll(offloads);
18566         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18567
18568         single_offload = 1ULL << begin;
18569         for (bit = begin; bit < end; bit++) {
18570                 if (offloads & single_offload)
18571                         printf(" %s",
18572                                rte_eth_dev_tx_offload_name(single_offload));
18573                 single_offload <<= 1;
18574         }
18575 }
18576
18577 static void
18578 cmd_tx_offload_get_capa_parsed(
18579         void *parsed_result,
18580         __rte_unused struct cmdline *cl,
18581         __rte_unused void *data)
18582 {
18583         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18584         struct rte_eth_dev_info dev_info;
18585         portid_t port_id = res->port_id;
18586         uint64_t queue_offloads;
18587         uint64_t port_offloads;
18588         int ret;
18589
18590         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18591         if (ret != 0)
18592                 return;
18593
18594         queue_offloads = dev_info.tx_queue_offload_capa;
18595         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18596
18597         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18598         printf("  Per Queue :");
18599         print_tx_offloads(queue_offloads);
18600
18601         printf("\n");
18602         printf("  Per Port  :");
18603         print_tx_offloads(port_offloads);
18604         printf("\n\n");
18605 }
18606
18607 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18608         .f = cmd_tx_offload_get_capa_parsed,
18609         .data = NULL,
18610         .help_str = "show port <port_id> tx_offload capabilities",
18611         .tokens = {
18612                 (void *)&cmd_tx_offload_get_capa_show,
18613                 (void *)&cmd_tx_offload_get_capa_port,
18614                 (void *)&cmd_tx_offload_get_capa_port_id,
18615                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18616                 (void *)&cmd_tx_offload_get_capa_capabilities,
18617                 NULL,
18618         }
18619 };
18620
18621 /* Get Tx offloads configuration */
18622 struct cmd_tx_offload_get_configuration_result {
18623         cmdline_fixed_string_t show;
18624         cmdline_fixed_string_t port;
18625         portid_t port_id;
18626         cmdline_fixed_string_t tx_offload;
18627         cmdline_fixed_string_t configuration;
18628 };
18629
18630 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18631         TOKEN_STRING_INITIALIZER
18632                 (struct cmd_tx_offload_get_configuration_result,
18633                  show, "show");
18634 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18635         TOKEN_STRING_INITIALIZER
18636                 (struct cmd_tx_offload_get_configuration_result,
18637                  port, "port");
18638 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18639         TOKEN_NUM_INITIALIZER
18640                 (struct cmd_tx_offload_get_configuration_result,
18641                  port_id, UINT16);
18642 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18643         TOKEN_STRING_INITIALIZER
18644                 (struct cmd_tx_offload_get_configuration_result,
18645                  tx_offload, "tx_offload");
18646 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18647         TOKEN_STRING_INITIALIZER
18648                 (struct cmd_tx_offload_get_configuration_result,
18649                  configuration, "configuration");
18650
18651 static void
18652 cmd_tx_offload_get_configuration_parsed(
18653         void *parsed_result,
18654         __rte_unused struct cmdline *cl,
18655         __rte_unused void *data)
18656 {
18657         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18658         struct rte_eth_dev_info dev_info;
18659         portid_t port_id = res->port_id;
18660         struct rte_port *port = &ports[port_id];
18661         uint64_t port_offloads;
18662         uint64_t queue_offloads;
18663         uint16_t nb_tx_queues;
18664         int q;
18665         int ret;
18666
18667         printf("Tx Offloading Configuration of port %d :\n", port_id);
18668
18669         port_offloads = port->dev_conf.txmode.offloads;
18670         printf("  Port :");
18671         print_tx_offloads(port_offloads);
18672         printf("\n");
18673
18674         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18675         if (ret != 0)
18676                 return;
18677
18678         nb_tx_queues = dev_info.nb_tx_queues;
18679         for (q = 0; q < nb_tx_queues; q++) {
18680                 queue_offloads = port->tx_conf[q].offloads;
18681                 printf("  Queue[%2d] :", q);
18682                 print_tx_offloads(queue_offloads);
18683                 printf("\n");
18684         }
18685         printf("\n");
18686 }
18687
18688 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18689         .f = cmd_tx_offload_get_configuration_parsed,
18690         .data = NULL,
18691         .help_str = "show port <port_id> tx_offload configuration",
18692         .tokens = {
18693                 (void *)&cmd_tx_offload_get_configuration_show,
18694                 (void *)&cmd_tx_offload_get_configuration_port,
18695                 (void *)&cmd_tx_offload_get_configuration_port_id,
18696                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18697                 (void *)&cmd_tx_offload_get_configuration_configuration,
18698                 NULL,
18699         }
18700 };
18701
18702 /* Enable/Disable a per port offloading */
18703 struct cmd_config_per_port_tx_offload_result {
18704         cmdline_fixed_string_t port;
18705         cmdline_fixed_string_t config;
18706         portid_t port_id;
18707         cmdline_fixed_string_t tx_offload;
18708         cmdline_fixed_string_t offload;
18709         cmdline_fixed_string_t on_off;
18710 };
18711
18712 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18713         TOKEN_STRING_INITIALIZER
18714                 (struct cmd_config_per_port_tx_offload_result,
18715                  port, "port");
18716 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18717         TOKEN_STRING_INITIALIZER
18718                 (struct cmd_config_per_port_tx_offload_result,
18719                  config, "config");
18720 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18721         TOKEN_NUM_INITIALIZER
18722                 (struct cmd_config_per_port_tx_offload_result,
18723                  port_id, UINT16);
18724 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18725         TOKEN_STRING_INITIALIZER
18726                 (struct cmd_config_per_port_tx_offload_result,
18727                  tx_offload, "tx_offload");
18728 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18729         TOKEN_STRING_INITIALIZER
18730                 (struct cmd_config_per_port_tx_offload_result,
18731                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18732                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18733                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18734                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18735                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18736                           "send_on_timestamp");
18737 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18738         TOKEN_STRING_INITIALIZER
18739                 (struct cmd_config_per_port_tx_offload_result,
18740                  on_off, "on#off");
18741
18742 static uint64_t
18743 search_tx_offload(const char *name)
18744 {
18745         uint64_t single_offload;
18746         const char *single_name;
18747         int found = 0;
18748         unsigned int bit;
18749
18750         single_offload = 1;
18751         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18752                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18753                 if (single_name == NULL)
18754                         break;
18755                 if (!strcasecmp(single_name, name)) {
18756                         found = 1;
18757                         break;
18758                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18759                         break;
18760                 single_offload <<= 1;
18761         }
18762
18763         if (found)
18764                 return single_offload;
18765
18766         return 0;
18767 }
18768
18769 static void
18770 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18771                                 __rte_unused struct cmdline *cl,
18772                                 __rte_unused void *data)
18773 {
18774         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18775         portid_t port_id = res->port_id;
18776         struct rte_eth_dev_info dev_info;
18777         struct rte_port *port = &ports[port_id];
18778         uint64_t single_offload;
18779         uint16_t nb_tx_queues;
18780         int q;
18781         int ret;
18782
18783         if (port->port_status != RTE_PORT_STOPPED) {
18784                 printf("Error: Can't config offload when Port %d "
18785                        "is not stopped\n", port_id);
18786                 return;
18787         }
18788
18789         single_offload = search_tx_offload(res->offload);
18790         if (single_offload == 0) {
18791                 printf("Unknown offload name: %s\n", res->offload);
18792                 return;
18793         }
18794
18795         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18796         if (ret != 0)
18797                 return;
18798
18799         nb_tx_queues = dev_info.nb_tx_queues;
18800         if (!strcmp(res->on_off, "on")) {
18801                 port->dev_conf.txmode.offloads |= single_offload;
18802                 for (q = 0; q < nb_tx_queues; q++)
18803                         port->tx_conf[q].offloads |= single_offload;
18804         } else {
18805                 port->dev_conf.txmode.offloads &= ~single_offload;
18806                 for (q = 0; q < nb_tx_queues; q++)
18807                         port->tx_conf[q].offloads &= ~single_offload;
18808         }
18809
18810         cmd_reconfig_device_queue(port_id, 1, 1);
18811 }
18812
18813 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18814         .f = cmd_config_per_port_tx_offload_parsed,
18815         .data = NULL,
18816         .help_str = "port config <port_id> tx_offload "
18817                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18818                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18819                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18820                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18821                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18822                     "send_on_timestamp on|off",
18823         .tokens = {
18824                 (void *)&cmd_config_per_port_tx_offload_result_port,
18825                 (void *)&cmd_config_per_port_tx_offload_result_config,
18826                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18827                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18828                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18829                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18830                 NULL,
18831         }
18832 };
18833
18834 /* Enable/Disable a per queue offloading */
18835 struct cmd_config_per_queue_tx_offload_result {
18836         cmdline_fixed_string_t port;
18837         portid_t port_id;
18838         cmdline_fixed_string_t txq;
18839         uint16_t queue_id;
18840         cmdline_fixed_string_t tx_offload;
18841         cmdline_fixed_string_t offload;
18842         cmdline_fixed_string_t on_off;
18843 };
18844
18845 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18846         TOKEN_STRING_INITIALIZER
18847                 (struct cmd_config_per_queue_tx_offload_result,
18848                  port, "port");
18849 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18850         TOKEN_NUM_INITIALIZER
18851                 (struct cmd_config_per_queue_tx_offload_result,
18852                  port_id, UINT16);
18853 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18854         TOKEN_STRING_INITIALIZER
18855                 (struct cmd_config_per_queue_tx_offload_result,
18856                  txq, "txq");
18857 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18858         TOKEN_NUM_INITIALIZER
18859                 (struct cmd_config_per_queue_tx_offload_result,
18860                  queue_id, UINT16);
18861 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18862         TOKEN_STRING_INITIALIZER
18863                 (struct cmd_config_per_queue_tx_offload_result,
18864                  tx_offload, "tx_offload");
18865 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18866         TOKEN_STRING_INITIALIZER
18867                 (struct cmd_config_per_queue_tx_offload_result,
18868                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18869                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18870                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18871                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18872                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18873 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18874         TOKEN_STRING_INITIALIZER
18875                 (struct cmd_config_per_queue_tx_offload_result,
18876                  on_off, "on#off");
18877
18878 static void
18879 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18880                                 __rte_unused struct cmdline *cl,
18881                                 __rte_unused void *data)
18882 {
18883         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18884         struct rte_eth_dev_info dev_info;
18885         portid_t port_id = res->port_id;
18886         uint16_t queue_id = res->queue_id;
18887         struct rte_port *port = &ports[port_id];
18888         uint64_t single_offload;
18889         int ret;
18890
18891         if (port->port_status != RTE_PORT_STOPPED) {
18892                 printf("Error: Can't config offload when Port %d "
18893                        "is not stopped\n", port_id);
18894                 return;
18895         }
18896
18897         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18898         if (ret != 0)
18899                 return;
18900
18901         if (queue_id >= dev_info.nb_tx_queues) {
18902                 printf("Error: input queue_id should be 0 ... "
18903                        "%d\n", dev_info.nb_tx_queues - 1);
18904                 return;
18905         }
18906
18907         single_offload = search_tx_offload(res->offload);
18908         if (single_offload == 0) {
18909                 printf("Unknown offload name: %s\n", res->offload);
18910                 return;
18911         }
18912
18913         if (!strcmp(res->on_off, "on"))
18914                 port->tx_conf[queue_id].offloads |= single_offload;
18915         else
18916                 port->tx_conf[queue_id].offloads &= ~single_offload;
18917
18918         cmd_reconfig_device_queue(port_id, 1, 1);
18919 }
18920
18921 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18922         .f = cmd_config_per_queue_tx_offload_parsed,
18923         .data = NULL,
18924         .help_str = "port <port_id> txq <queue_id> tx_offload "
18925                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18926                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18927                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18928                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18929                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18930                     "on|off",
18931         .tokens = {
18932                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18933                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18934                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18935                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18936                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18937                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18938                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18939                 NULL,
18940         }
18941 };
18942
18943 /* *** configure tx_metadata for specific port *** */
18944 struct cmd_config_tx_metadata_specific_result {
18945         cmdline_fixed_string_t port;
18946         cmdline_fixed_string_t keyword;
18947         uint16_t port_id;
18948         cmdline_fixed_string_t item;
18949         uint32_t value;
18950 };
18951
18952 static void
18953 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18954                                 __rte_unused struct cmdline *cl,
18955                                 __rte_unused void *data)
18956 {
18957         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18958
18959         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18960                 return;
18961         ports[res->port_id].tx_metadata = res->value;
18962         /* Add/remove callback to insert valid metadata in every Tx packet. */
18963         if (ports[res->port_id].tx_metadata)
18964                 add_tx_md_callback(res->port_id);
18965         else
18966                 remove_tx_md_callback(res->port_id);
18967         rte_flow_dynf_metadata_register();
18968 }
18969
18970 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18971         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18972                         port, "port");
18973 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18974         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18975                         keyword, "config");
18976 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18977         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18978                         port_id, UINT16);
18979 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18980         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18981                         item, "tx_metadata");
18982 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18983         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18984                         value, UINT32);
18985
18986 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18987         .f = cmd_config_tx_metadata_specific_parsed,
18988         .data = NULL,
18989         .help_str = "port config <port_id> tx_metadata <value>",
18990         .tokens = {
18991                 (void *)&cmd_config_tx_metadata_specific_port,
18992                 (void *)&cmd_config_tx_metadata_specific_keyword,
18993                 (void *)&cmd_config_tx_metadata_specific_id,
18994                 (void *)&cmd_config_tx_metadata_specific_item,
18995                 (void *)&cmd_config_tx_metadata_specific_value,
18996                 NULL,
18997         },
18998 };
18999
19000 /* *** set dynf *** */
19001 struct cmd_config_tx_dynf_specific_result {
19002         cmdline_fixed_string_t port;
19003         cmdline_fixed_string_t keyword;
19004         uint16_t port_id;
19005         cmdline_fixed_string_t item;
19006         cmdline_fixed_string_t name;
19007         cmdline_fixed_string_t value;
19008 };
19009
19010 static void
19011 cmd_config_dynf_specific_parsed(void *parsed_result,
19012                                 __rte_unused struct cmdline *cl,
19013                                 __rte_unused void *data)
19014 {
19015         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
19016         struct rte_mbuf_dynflag desc_flag;
19017         int flag;
19018         uint64_t old_port_flags;
19019
19020         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19021                 return;
19022         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
19023         if (flag <= 0) {
19024                 if (strlcpy(desc_flag.name, res->name,
19025                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
19026                         printf("Flag name too long\n");
19027                         return;
19028                 }
19029                 desc_flag.flags = 0;
19030                 flag = rte_mbuf_dynflag_register(&desc_flag);
19031                 if (flag < 0) {
19032                         printf("Can't register flag\n");
19033                         return;
19034                 }
19035                 strcpy(dynf_names[flag], desc_flag.name);
19036         }
19037         old_port_flags = ports[res->port_id].mbuf_dynf;
19038         if (!strcmp(res->value, "set")) {
19039                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
19040                 if (old_port_flags == 0)
19041                         add_tx_dynf_callback(res->port_id);
19042         } else {
19043                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
19044                 if (ports[res->port_id].mbuf_dynf == 0)
19045                         remove_tx_dynf_callback(res->port_id);
19046         }
19047 }
19048
19049 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
19050         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19051                         keyword, "port");
19052 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
19053         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19054                         keyword, "config");
19055 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
19056         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19057                         port_id, UINT16);
19058 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
19059         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19060                         item, "dynf");
19061 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
19062         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19063                         name, NULL);
19064 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
19065         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19066                         value, "set#clear");
19067
19068 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
19069         .f = cmd_config_dynf_specific_parsed,
19070         .data = NULL,
19071         .help_str = "port config <port id> dynf <name> set|clear",
19072         .tokens = {
19073                 (void *)&cmd_config_tx_dynf_specific_port,
19074                 (void *)&cmd_config_tx_dynf_specific_keyword,
19075                 (void *)&cmd_config_tx_dynf_specific_port_id,
19076                 (void *)&cmd_config_tx_dynf_specific_item,
19077                 (void *)&cmd_config_tx_dynf_specific_name,
19078                 (void *)&cmd_config_tx_dynf_specific_value,
19079                 NULL,
19080         },
19081 };
19082
19083 /* *** display tx_metadata per port configuration *** */
19084 struct cmd_show_tx_metadata_result {
19085         cmdline_fixed_string_t cmd_show;
19086         cmdline_fixed_string_t cmd_port;
19087         cmdline_fixed_string_t cmd_keyword;
19088         portid_t cmd_pid;
19089 };
19090
19091 static void
19092 cmd_show_tx_metadata_parsed(void *parsed_result,
19093                 __rte_unused struct cmdline *cl,
19094                 __rte_unused void *data)
19095 {
19096         struct cmd_show_tx_metadata_result *res = parsed_result;
19097
19098         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19099                 printf("invalid port id %u\n", res->cmd_pid);
19100                 return;
19101         }
19102         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19103                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19104                        ports[res->cmd_pid].tx_metadata);
19105         }
19106 }
19107
19108 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19109         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19110                         cmd_show, "show");
19111 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19112         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19113                         cmd_port, "port");
19114 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19115         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19116                         cmd_pid, UINT16);
19117 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19118         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19119                         cmd_keyword, "tx_metadata");
19120
19121 cmdline_parse_inst_t cmd_show_tx_metadata = {
19122         .f = cmd_show_tx_metadata_parsed,
19123         .data = NULL,
19124         .help_str = "show port <port_id> tx_metadata",
19125         .tokens = {
19126                 (void *)&cmd_show_tx_metadata_show,
19127                 (void *)&cmd_show_tx_metadata_port,
19128                 (void *)&cmd_show_tx_metadata_pid,
19129                 (void *)&cmd_show_tx_metadata_keyword,
19130                 NULL,
19131         },
19132 };
19133
19134 /* *** show fec capability per port configuration *** */
19135 struct cmd_show_fec_capability_result {
19136         cmdline_fixed_string_t cmd_show;
19137         cmdline_fixed_string_t cmd_port;
19138         cmdline_fixed_string_t cmd_fec;
19139         cmdline_fixed_string_t cmd_keyword;
19140         portid_t cmd_pid;
19141 };
19142
19143 static void
19144 cmd_show_fec_capability_parsed(void *parsed_result,
19145                 __rte_unused struct cmdline *cl,
19146                 __rte_unused void *data)
19147 {
19148 #define FEC_CAP_NUM 2
19149         struct cmd_show_fec_capability_result *res = parsed_result;
19150         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
19151         unsigned int num = FEC_CAP_NUM;
19152         unsigned int ret_num;
19153         int ret;
19154
19155         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19156                 printf("Invalid port id %u\n", res->cmd_pid);
19157                 return;
19158         }
19159
19160         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
19161         if (ret == -ENOTSUP) {
19162                 printf("Function not implemented\n");
19163                 return;
19164         } else if (ret < 0) {
19165                 printf("Get FEC capability failed\n");
19166                 return;
19167         }
19168
19169         ret_num = (unsigned int)ret;
19170         show_fec_capability(ret_num, speed_fec_capa);
19171 }
19172
19173 cmdline_parse_token_string_t cmd_show_fec_capability_show =
19174         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19175                         cmd_show, "show");
19176 cmdline_parse_token_string_t cmd_show_fec_capability_port =
19177         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19178                         cmd_port, "port");
19179 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
19180         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
19181                         cmd_pid, UINT16);
19182 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
19183         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19184                         cmd_fec, "fec");
19185 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
19186         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19187                         cmd_keyword, "capabilities");
19188
19189 cmdline_parse_inst_t cmd_show_capability = {
19190         .f = cmd_show_fec_capability_parsed,
19191         .data = NULL,
19192         .help_str = "show port <port_id> fec capabilities",
19193         .tokens = {
19194                 (void *)&cmd_show_fec_capability_show,
19195                 (void *)&cmd_show_fec_capability_port,
19196                 (void *)&cmd_show_fec_capability_pid,
19197                 (void *)&cmd_show_fec_capability_fec,
19198                 (void *)&cmd_show_fec_capability_keyword,
19199                 NULL,
19200         },
19201 };
19202
19203 /* *** show fec mode per port configuration *** */
19204 struct cmd_show_fec_metadata_result {
19205         cmdline_fixed_string_t cmd_show;
19206         cmdline_fixed_string_t cmd_port;
19207         cmdline_fixed_string_t cmd_keyword;
19208         portid_t cmd_pid;
19209 };
19210
19211 static void
19212 cmd_show_fec_mode_parsed(void *parsed_result,
19213                 __rte_unused struct cmdline *cl,
19214                 __rte_unused void *data)
19215 {
19216 #define FEC_NAME_SIZE 16
19217         struct cmd_show_fec_metadata_result *res = parsed_result;
19218         uint32_t mode;
19219         char buf[FEC_NAME_SIZE];
19220         int ret;
19221
19222         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19223                 printf("Invalid port id %u\n", res->cmd_pid);
19224                 return;
19225         }
19226         ret = rte_eth_fec_get(res->cmd_pid, &mode);
19227         if (ret == -ENOTSUP) {
19228                 printf("Function not implemented\n");
19229                 return;
19230         } else if (ret < 0) {
19231                 printf("Get FEC mode failed\n");
19232                 return;
19233         }
19234
19235         switch (mode) {
19236         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
19237                 strlcpy(buf, "off", sizeof(buf));
19238                 break;
19239         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
19240                 strlcpy(buf, "auto", sizeof(buf));
19241                 break;
19242         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
19243                 strlcpy(buf, "baser", sizeof(buf));
19244                 break;
19245         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
19246                 strlcpy(buf, "rs", sizeof(buf));
19247                 break;
19248         default:
19249                 return;
19250         }
19251
19252         printf("%s\n", buf);
19253 }
19254
19255 cmdline_parse_token_string_t cmd_show_fec_mode_show =
19256         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19257                         cmd_show, "show");
19258 cmdline_parse_token_string_t cmd_show_fec_mode_port =
19259         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19260                         cmd_port, "port");
19261 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
19262         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
19263                         cmd_pid, UINT16);
19264 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
19265         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19266                         cmd_keyword, "fec_mode");
19267
19268 cmdline_parse_inst_t cmd_show_fec_mode = {
19269         .f = cmd_show_fec_mode_parsed,
19270         .data = NULL,
19271         .help_str = "show port <port_id> fec_mode",
19272         .tokens = {
19273                 (void *)&cmd_show_fec_mode_show,
19274                 (void *)&cmd_show_fec_mode_port,
19275                 (void *)&cmd_show_fec_mode_pid,
19276                 (void *)&cmd_show_fec_mode_keyword,
19277                 NULL,
19278         },
19279 };
19280
19281 /* *** set fec mode per port configuration *** */
19282 struct cmd_set_port_fec_mode {
19283         cmdline_fixed_string_t set;
19284         cmdline_fixed_string_t port;
19285         portid_t port_id;
19286         cmdline_fixed_string_t fec_mode;
19287         cmdline_fixed_string_t fec_value;
19288 };
19289
19290 /* Common CLI fields for set fec mode */
19291 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
19292         TOKEN_STRING_INITIALIZER
19293                 (struct cmd_set_port_fec_mode,
19294                  set, "set");
19295 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
19296         TOKEN_STRING_INITIALIZER
19297                 (struct cmd_set_port_fec_mode,
19298                  port, "port");
19299 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
19300         TOKEN_NUM_INITIALIZER
19301                 (struct cmd_set_port_fec_mode,
19302                  port_id, UINT16);
19303 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
19304         TOKEN_STRING_INITIALIZER
19305                 (struct cmd_set_port_fec_mode,
19306                  fec_mode, "fec_mode");
19307 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
19308         TOKEN_STRING_INITIALIZER
19309                 (struct cmd_set_port_fec_mode,
19310                  fec_value, NULL);
19311
19312 static void
19313 cmd_set_port_fec_mode_parsed(
19314         void *parsed_result,
19315         __rte_unused struct cmdline *cl,
19316         __rte_unused void *data)
19317 {
19318         struct cmd_set_port_fec_mode *res = parsed_result;
19319         uint16_t port_id = res->port_id;
19320         uint32_t mode;
19321         int ret;
19322
19323         ret = parse_fec_mode(res->fec_value, &mode);
19324         if (ret < 0) {
19325                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
19326                         port_id);
19327                 return;
19328         }
19329
19330         ret = rte_eth_fec_set(port_id, mode);
19331         if (ret == -ENOTSUP) {
19332                 printf("Function not implemented\n");
19333                 return;
19334         } else if (ret < 0) {
19335                 printf("Set FEC mode failed\n");
19336                 return;
19337         }
19338 }
19339
19340 cmdline_parse_inst_t cmd_set_fec_mode = {
19341         .f = cmd_set_port_fec_mode_parsed,
19342         .data = NULL,
19343         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
19344         .tokens = {
19345                 (void *)&cmd_set_port_fec_mode_set,
19346                 (void *)&cmd_set_port_fec_mode_port,
19347                 (void *)&cmd_set_port_fec_mode_port_id,
19348                 (void *)&cmd_set_port_fec_mode_str,
19349                 (void *)&cmd_set_port_fec_mode_value,
19350                 NULL,
19351         },
19352 };
19353
19354 /* show port supported ptypes */
19355
19356 /* Common result structure for show port ptypes */
19357 struct cmd_show_port_supported_ptypes_result {
19358         cmdline_fixed_string_t show;
19359         cmdline_fixed_string_t port;
19360         portid_t port_id;
19361         cmdline_fixed_string_t ptypes;
19362 };
19363
19364 /* Common CLI fields for show port ptypes */
19365 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19366         TOKEN_STRING_INITIALIZER
19367                 (struct cmd_show_port_supported_ptypes_result,
19368                  show, "show");
19369 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19370         TOKEN_STRING_INITIALIZER
19371                 (struct cmd_show_port_supported_ptypes_result,
19372                  port, "port");
19373 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19374         TOKEN_NUM_INITIALIZER
19375                 (struct cmd_show_port_supported_ptypes_result,
19376                  port_id, UINT16);
19377 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19378         TOKEN_STRING_INITIALIZER
19379                 (struct cmd_show_port_supported_ptypes_result,
19380                  ptypes, "ptypes");
19381
19382 static void
19383 cmd_show_port_supported_ptypes_parsed(
19384         void *parsed_result,
19385         __rte_unused struct cmdline *cl,
19386         __rte_unused void *data)
19387 {
19388 #define RSVD_PTYPE_MASK       0xf0000000
19389 #define MAX_PTYPES_PER_LAYER  16
19390 #define LTYPE_NAMESIZE        32
19391 #define PTYPE_NAMESIZE        256
19392         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19393         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19394         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19395         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19396         uint16_t port_id = res->port_id;
19397         int ret, i;
19398
19399         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19400         if (ret < 0)
19401                 return;
19402
19403         while (ptype_mask != RSVD_PTYPE_MASK) {
19404
19405                 switch (ptype_mask) {
19406                 case RTE_PTYPE_L2_MASK:
19407                         strlcpy(ltype, "L2", sizeof(ltype));
19408                         break;
19409                 case RTE_PTYPE_L3_MASK:
19410                         strlcpy(ltype, "L3", sizeof(ltype));
19411                         break;
19412                 case RTE_PTYPE_L4_MASK:
19413                         strlcpy(ltype, "L4", sizeof(ltype));
19414                         break;
19415                 case RTE_PTYPE_TUNNEL_MASK:
19416                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19417                         break;
19418                 case RTE_PTYPE_INNER_L2_MASK:
19419                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19420                         break;
19421                 case RTE_PTYPE_INNER_L3_MASK:
19422                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19423                         break;
19424                 case RTE_PTYPE_INNER_L4_MASK:
19425                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19426                         break;
19427                 default:
19428                         return;
19429                 }
19430
19431                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19432                                                        ptype_mask, ptypes,
19433                                                        MAX_PTYPES_PER_LAYER);
19434
19435                 if (ret > 0)
19436                         printf("Supported %s ptypes:\n", ltype);
19437                 else
19438                         printf("%s ptypes unsupported\n", ltype);
19439
19440                 for (i = 0; i < ret; ++i) {
19441                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19442                         printf("%s\n", buf);
19443                 }
19444
19445                 ptype_mask <<= 4;
19446         }
19447 }
19448
19449 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19450         .f = cmd_show_port_supported_ptypes_parsed,
19451         .data = NULL,
19452         .help_str = "show port <port_id> ptypes",
19453         .tokens = {
19454                 (void *)&cmd_show_port_supported_ptypes_show,
19455                 (void *)&cmd_show_port_supported_ptypes_port,
19456                 (void *)&cmd_show_port_supported_ptypes_port_id,
19457                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19458                 NULL,
19459         },
19460 };
19461
19462 /* *** display rx/tx descriptor status *** */
19463 struct cmd_show_rx_tx_desc_status_result {
19464         cmdline_fixed_string_t cmd_show;
19465         cmdline_fixed_string_t cmd_port;
19466         cmdline_fixed_string_t cmd_keyword;
19467         cmdline_fixed_string_t cmd_desc;
19468         cmdline_fixed_string_t cmd_status;
19469         portid_t cmd_pid;
19470         portid_t cmd_qid;
19471         portid_t cmd_did;
19472 };
19473
19474 static void
19475 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19476                 __rte_unused struct cmdline *cl,
19477                 __rte_unused void *data)
19478 {
19479         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19480         int rc;
19481
19482         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19483                 printf("invalid port id %u\n", res->cmd_pid);
19484                 return;
19485         }
19486
19487         if (!strcmp(res->cmd_keyword, "rxq")) {
19488                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19489                                              res->cmd_did);
19490                 if (rc < 0) {
19491                         printf("Invalid queueid = %d\n", res->cmd_qid);
19492                         return;
19493                 }
19494                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19495                         printf("Desc status = AVAILABLE\n");
19496                 else if (rc == RTE_ETH_RX_DESC_DONE)
19497                         printf("Desc status = DONE\n");
19498                 else
19499                         printf("Desc status = UNAVAILABLE\n");
19500         } else if (!strcmp(res->cmd_keyword, "txq")) {
19501                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19502                                              res->cmd_did);
19503                 if (rc < 0) {
19504                         printf("Invalid queueid = %d\n", res->cmd_qid);
19505                         return;
19506                 }
19507                 if (rc == RTE_ETH_TX_DESC_FULL)
19508                         printf("Desc status = FULL\n");
19509                 else if (rc == RTE_ETH_TX_DESC_DONE)
19510                         printf("Desc status = DONE\n");
19511                 else
19512                         printf("Desc status = UNAVAILABLE\n");
19513         }
19514 }
19515
19516 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19517         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19518                         cmd_show, "show");
19519 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19520         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19521                         cmd_port, "port");
19522 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19523         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19524                         cmd_pid, UINT16);
19525 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19526         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19527                         cmd_keyword, "rxq#txq");
19528 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19529         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19530                         cmd_qid, UINT16);
19531 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19532         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19533                         cmd_desc, "desc");
19534 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19535         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19536                         cmd_did, UINT16);
19537 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19538         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19539                         cmd_status, "status");
19540 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19541         .f = cmd_show_rx_tx_desc_status_parsed,
19542         .data = NULL,
19543         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19544                 "status",
19545         .tokens = {
19546                 (void *)&cmd_show_rx_tx_desc_status_show,
19547                 (void *)&cmd_show_rx_tx_desc_status_port,
19548                 (void *)&cmd_show_rx_tx_desc_status_pid,
19549                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19550                 (void *)&cmd_show_rx_tx_desc_status_qid,
19551                 (void *)&cmd_show_rx_tx_desc_status_desc,
19552                 (void *)&cmd_show_rx_tx_desc_status_did,
19553                 (void *)&cmd_show_rx_tx_desc_status_status,
19554                 NULL,
19555         },
19556 };
19557
19558 /* Common result structure for set port ptypes */
19559 struct cmd_set_port_ptypes_result {
19560         cmdline_fixed_string_t set;
19561         cmdline_fixed_string_t port;
19562         portid_t port_id;
19563         cmdline_fixed_string_t ptype_mask;
19564         uint32_t mask;
19565 };
19566
19567 /* Common CLI fields for set port ptypes */
19568 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19569         TOKEN_STRING_INITIALIZER
19570                 (struct cmd_set_port_ptypes_result,
19571                  set, "set");
19572 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19573         TOKEN_STRING_INITIALIZER
19574                 (struct cmd_set_port_ptypes_result,
19575                  port, "port");
19576 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19577         TOKEN_NUM_INITIALIZER
19578                 (struct cmd_set_port_ptypes_result,
19579                  port_id, UINT16);
19580 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19581         TOKEN_STRING_INITIALIZER
19582                 (struct cmd_set_port_ptypes_result,
19583                  ptype_mask, "ptype_mask");
19584 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19585         TOKEN_NUM_INITIALIZER
19586                 (struct cmd_set_port_ptypes_result,
19587                  mask, UINT32);
19588
19589 static void
19590 cmd_set_port_ptypes_parsed(
19591         void *parsed_result,
19592         __rte_unused struct cmdline *cl,
19593         __rte_unused void *data)
19594 {
19595         struct cmd_set_port_ptypes_result *res = parsed_result;
19596 #define PTYPE_NAMESIZE        256
19597         char ptype_name[PTYPE_NAMESIZE];
19598         uint16_t port_id = res->port_id;
19599         uint32_t ptype_mask = res->mask;
19600         int ret, i;
19601
19602         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19603                                                NULL, 0);
19604         if (ret <= 0) {
19605                 printf("Port %d doesn't support any ptypes.\n", port_id);
19606                 return;
19607         }
19608
19609         uint32_t ptypes[ret];
19610
19611         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19612         if (ret < 0) {
19613                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19614                 return;
19615         }
19616
19617         printf("Successfully set following ptypes for Port %d\n", port_id);
19618         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19619                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19620                 printf("%s\n", ptype_name);
19621         }
19622
19623         clear_ptypes = false;
19624 }
19625
19626 cmdline_parse_inst_t cmd_set_port_ptypes = {
19627         .f = cmd_set_port_ptypes_parsed,
19628         .data = NULL,
19629         .help_str = "set port <port_id> ptype_mask <mask>",
19630         .tokens = {
19631                 (void *)&cmd_set_port_ptypes_set,
19632                 (void *)&cmd_set_port_ptypes_port,
19633                 (void *)&cmd_set_port_ptypes_port_id,
19634                 (void *)&cmd_set_port_ptypes_mask_str,
19635                 (void *)&cmd_set_port_ptypes_mask_u32,
19636                 NULL,
19637         },
19638 };
19639
19640 /* *** display mac addresses added to a port *** */
19641 struct cmd_showport_macs_result {
19642         cmdline_fixed_string_t cmd_show;
19643         cmdline_fixed_string_t cmd_port;
19644         cmdline_fixed_string_t cmd_keyword;
19645         portid_t cmd_pid;
19646 };
19647
19648 static void
19649 cmd_showport_macs_parsed(void *parsed_result,
19650                 __rte_unused struct cmdline *cl,
19651                 __rte_unused void *data)
19652 {
19653         struct cmd_showport_macs_result *res = parsed_result;
19654
19655         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19656                 return;
19657
19658         if (!strcmp(res->cmd_keyword, "macs"))
19659                 show_macs(res->cmd_pid);
19660         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19661                 show_mcast_macs(res->cmd_pid);
19662 }
19663
19664 cmdline_parse_token_string_t cmd_showport_macs_show =
19665         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19666                         cmd_show, "show");
19667 cmdline_parse_token_string_t cmd_showport_macs_port =
19668         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19669                         cmd_port, "port");
19670 cmdline_parse_token_num_t cmd_showport_macs_pid =
19671         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19672                         cmd_pid, UINT16);
19673 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19674         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19675                         cmd_keyword, "macs#mcast_macs");
19676
19677 cmdline_parse_inst_t cmd_showport_macs = {
19678         .f = cmd_showport_macs_parsed,
19679         .data = NULL,
19680         .help_str = "show port <port_id> macs|mcast_macs",
19681         .tokens = {
19682                 (void *)&cmd_showport_macs_show,
19683                 (void *)&cmd_showport_macs_port,
19684                 (void *)&cmd_showport_macs_pid,
19685                 (void *)&cmd_showport_macs_keyword,
19686                 NULL,
19687         },
19688 };
19689
19690 /* ******************************************************************************** */
19691
19692 /* list of instructions */
19693 cmdline_parse_ctx_t main_ctx[] = {
19694         (cmdline_parse_inst_t *)&cmd_help_brief,
19695         (cmdline_parse_inst_t *)&cmd_help_long,
19696         (cmdline_parse_inst_t *)&cmd_quit,
19697         (cmdline_parse_inst_t *)&cmd_load_from_file,
19698         (cmdline_parse_inst_t *)&cmd_showport,
19699         (cmdline_parse_inst_t *)&cmd_showqueue,
19700         (cmdline_parse_inst_t *)&cmd_showeeprom,
19701         (cmdline_parse_inst_t *)&cmd_showportall,
19702         (cmdline_parse_inst_t *)&cmd_showdevice,
19703         (cmdline_parse_inst_t *)&cmd_showcfg,
19704         (cmdline_parse_inst_t *)&cmd_showfwdall,
19705         (cmdline_parse_inst_t *)&cmd_start,
19706         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19707         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19708         (cmdline_parse_inst_t *)&cmd_set_link_up,
19709         (cmdline_parse_inst_t *)&cmd_set_link_down,
19710         (cmdline_parse_inst_t *)&cmd_reset,
19711         (cmdline_parse_inst_t *)&cmd_set_numbers,
19712         (cmdline_parse_inst_t *)&cmd_set_log,
19713         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
19714         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
19715         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19716         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19717         (cmdline_parse_inst_t *)&cmd_set_txtimes,
19718         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19719         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19720         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19721         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19722         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19723         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19724         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19725         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19726         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19727         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19728         (cmdline_parse_inst_t *)&cmd_set_link_check,
19729         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19730         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19731         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19732         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19733 #ifdef RTE_NET_BOND
19734         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19735         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19736         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19737         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19738         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19739         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19740         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19741         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19742         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19743         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19744         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19745 #endif
19746         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19747         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19748         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19749         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19750         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19751         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19752         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19753         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19754         (cmdline_parse_inst_t *)&cmd_csum_set,
19755         (cmdline_parse_inst_t *)&cmd_csum_show,
19756         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19757         (cmdline_parse_inst_t *)&cmd_tso_set,
19758         (cmdline_parse_inst_t *)&cmd_tso_show,
19759         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19760         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19761         (cmdline_parse_inst_t *)&cmd_gro_enable,
19762         (cmdline_parse_inst_t *)&cmd_gro_flush,
19763         (cmdline_parse_inst_t *)&cmd_gro_show,
19764         (cmdline_parse_inst_t *)&cmd_gso_enable,
19765         (cmdline_parse_inst_t *)&cmd_gso_size,
19766         (cmdline_parse_inst_t *)&cmd_gso_show,
19767         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19768         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19769         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19770         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19771         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19772         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19773         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19774         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19775         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19776         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19777         (cmdline_parse_inst_t *)&cmd_config_dcb,
19778         (cmdline_parse_inst_t *)&cmd_read_reg,
19779         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19780         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19781         (cmdline_parse_inst_t *)&cmd_write_reg,
19782         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19783         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19784         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19785         (cmdline_parse_inst_t *)&cmd_stop,
19786         (cmdline_parse_inst_t *)&cmd_mac_addr,
19787         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19788         (cmdline_parse_inst_t *)&cmd_set_qmap,
19789         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19790         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
19791         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
19792         (cmdline_parse_inst_t *)&cmd_operate_port,
19793         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19794         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19795         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19796         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19797         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19798         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19799         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19800         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19801         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19802         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19803         (cmdline_parse_inst_t *)&cmd_config_mtu,
19804         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19805         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19806         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19807         (cmdline_parse_inst_t *)&cmd_config_rss,
19808         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19809         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19810         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19811         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19812         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19813         (cmdline_parse_inst_t *)&cmd_showport_reta,
19814         (cmdline_parse_inst_t *)&cmd_showport_macs,
19815         (cmdline_parse_inst_t *)&cmd_config_burst,
19816         (cmdline_parse_inst_t *)&cmd_config_thresh,
19817         (cmdline_parse_inst_t *)&cmd_config_threshold,
19818         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19819         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19820         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19821         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19822         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19823         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19824         (cmdline_parse_inst_t *)&cmd_global_config,
19825         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19826         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19827         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19828         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19829         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19830         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19831         (cmdline_parse_inst_t *)&cmd_dump,
19832         (cmdline_parse_inst_t *)&cmd_dump_one,
19833         (cmdline_parse_inst_t *)&cmd_syn_filter,
19834         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19835         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19836         (cmdline_parse_inst_t *)&cmd_flex_filter,
19837         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19838         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19839         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19840         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19841         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19842         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19843         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19844         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19845         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19846         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19847         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19848         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19849         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19850         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19851         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19852         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19853         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19854         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19855         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19856         (cmdline_parse_inst_t *)&cmd_flow,
19857         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19858         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19859         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19860         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19861         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19862         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19863         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19864         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19865         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19866         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19867         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19868         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19869         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19870         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19871         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19872         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19873         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19874         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19875         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19876         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19877         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19878         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19879         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19880         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19881         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19882         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19883         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19884         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19885         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19886         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19887         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19888         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19889         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19890         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19891         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19892         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19893         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19894         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19895         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19896         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19897         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19898         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19899         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19900         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19901         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19902         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19903         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19904         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19905         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19906         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19907         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19908         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19909         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19910         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19911         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19912         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19913         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19914         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19915         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19916         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19917         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19918         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19919         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19920         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19921         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19922         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19923         (cmdline_parse_inst_t *)&cmd_ddp_add,
19924         (cmdline_parse_inst_t *)&cmd_ddp_del,
19925         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19926         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19927         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19928         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19929         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19930         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19931         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19932         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19933         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19934         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19935         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19936         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19937
19938         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19939         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19940         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19941         (cmdline_parse_inst_t *)&cmd_queue_region,
19942         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19943         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19944         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19945         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19946         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19947         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19948         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19949         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19950         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19951         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19952         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19953         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19954         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19955         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19956         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19957         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19958         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19959         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
19960         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19961         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19962         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19963         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19964         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19965         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19966         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19967         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19968         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19969         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19970         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19971         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19972         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19973         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19974         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19975         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19976         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19977         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19978 #ifdef RTE_LIB_BPF
19979         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19980         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19981 #endif
19982         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19983         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19984         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19985         (cmdline_parse_inst_t *)&cmd_set_raw,
19986         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19987         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19988         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19989         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
19990         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
19991         (cmdline_parse_inst_t *)&cmd_show_capability,
19992         NULL,
19993 };
19994
19995 /* read cmdline commands from file */
19996 void
19997 cmdline_read_from_file(const char *filename)
19998 {
19999         struct cmdline *cl;
20000
20001         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
20002         if (cl == NULL) {
20003                 printf("Failed to create file based cmdline context: %s\n",
20004                        filename);
20005                 return;
20006         }
20007
20008         cmdline_interact(cl);
20009         cmdline_quit(cl);
20010
20011         cmdline_free(cl);
20012
20013         printf("Read CLI commands from %s\n", filename);
20014 }
20015
20016 /* prompt function, called from main on MAIN lcore */
20017 void
20018 prompt(void)
20019 {
20020         /* initialize non-constant commands */
20021         cmd_set_fwd_mode_init();
20022         cmd_set_fwd_retry_mode_init();
20023
20024         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
20025         if (testpmd_cl == NULL)
20026                 return;
20027         cmdline_interact(testpmd_cl);
20028         cmdline_stdin_exit(testpmd_cl);
20029 }
20030
20031 void
20032 prompt_exit(void)
20033 {
20034         if (testpmd_cl != NULL)
20035                 cmdline_quit(testpmd_cl);
20036 }
20037
20038 static void
20039 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
20040 {
20041         if (id == (portid_t)RTE_PORT_ALL) {
20042                 portid_t pid;
20043
20044                 RTE_ETH_FOREACH_DEV(pid) {
20045                         /* check if need_reconfig has been set to 1 */
20046                         if (ports[pid].need_reconfig == 0)
20047                                 ports[pid].need_reconfig = dev;
20048                         /* check if need_reconfig_queues has been set to 1 */
20049                         if (ports[pid].need_reconfig_queues == 0)
20050                                 ports[pid].need_reconfig_queues = queue;
20051                 }
20052         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
20053                 /* check if need_reconfig has been set to 1 */
20054                 if (ports[id].need_reconfig == 0)
20055                         ports[id].need_reconfig = dev;
20056                 /* check if need_reconfig_queues has been set to 1 */
20057                 if (ports[id].need_reconfig_queues == 0)
20058                         ports[id].need_reconfig_queues = queue;
20059         }
20060 }