ethdev: remove legacy flexible filter type support
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_NET_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_NET_IXGBE
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_NET_I40E
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_NET_BNXT
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related cmds.\n"
100                 "    help all                        : All of the above sections.\n\n"
101         );
102
103 }
104
105 cmdline_parse_token_string_t cmd_help_brief_help =
106         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107
108 cmdline_parse_inst_t cmd_help_brief = {
109         .f = cmd_help_brief_parsed,
110         .data = NULL,
111         .help_str = "help: Show help",
112         .tokens = {
113                 (void *)&cmd_help_brief_help,
114                 NULL,
115         },
116 };
117
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120         cmdline_fixed_string_t help;
121         cmdline_fixed_string_t section;
122 };
123
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port port_id (module_eeprom|eeprom)\n"
170                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port (port_id) rss-hash [key]\n"
178                         "    Display the RSS hash functions and RSS hash key of port\n\n"
179
180                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
181                         "    Clear information for port_id, or all.\n\n"
182
183                         "show (rxq|txq) info (port_id) (queue_id)\n"
184                         "    Display information for configured RX/TX queue.\n\n"
185
186                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
187                         "    Display the given configuration.\n\n"
188
189                         "read rxd (port_id) (queue_id) (rxd_id)\n"
190                         "    Display an RX descriptor of a port RX queue.\n\n"
191
192                         "read txd (port_id) (queue_id) (txd_id)\n"
193                         "    Display a TX descriptor of a port TX queue.\n\n"
194
195                         "ddp get list (port_id)\n"
196                         "    Get ddp profile info list\n\n"
197
198                         "ddp get info (profile_path)\n"
199                         "    Get ddp profile information.\n\n"
200
201                         "show vf stats (port_id) (vf_id)\n"
202                         "    Display a VF's statistics.\n\n"
203
204                         "clear vf stats (port_id) (vf_id)\n"
205                         "    Reset a VF's statistics.\n\n"
206
207                         "show port (port_id) pctype mapping\n"
208                         "    Get flow ptype to pctype mapping on a port\n\n"
209
210                         "show port meter stats (port_id) (meter_id) (clear)\n"
211                         "    Get meter stats on a port\n\n"
212
213                         "show fwd stats all\n"
214                         "    Display statistics for all fwd engines.\n\n"
215
216                         "clear fwd stats all\n"
217                         "    Clear statistics for all fwd engines.\n\n"
218
219                         "show port (port_id) rx_offload capabilities\n"
220                         "    List all per queue and per port Rx offloading"
221                         " capabilities of a port\n\n"
222
223                         "show port (port_id) rx_offload configuration\n"
224                         "    List port level and all queue level"
225                         " Rx offloading configuration\n\n"
226
227                         "show port (port_id) tx_offload capabilities\n"
228                         "    List all per queue and per port"
229                         " Tx offloading capabilities of a port\n\n"
230
231                         "show port (port_id) tx_offload configuration\n"
232                         "    List port level and all queue level"
233                         " Tx offloading configuration\n\n"
234
235                         "show port (port_id) tx_metadata\n"
236                         "    Show Tx metadata value set"
237                         " for a specific port\n\n"
238
239                         "show port (port_id) ptypes\n"
240                         "    Show port supported ptypes"
241                         " for a specific port\n\n"
242
243                         "show device info (<identifier>|all)"
244                         "       Show general information about devices probed.\n\n"
245
246                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
247                         "       Show status of rx|tx descriptor.\n\n"
248
249                         "show port (port_id) macs|mcast_macs"
250                         "       Display list of mac addresses added to port.\n\n"
251
252                         "show port (port_id) fec capabilities"
253                         "       Show fec capabilities of a port.\n\n"
254
255                         "show port (port_id) fec_mode"
256                         "       Show fec mode of a port.\n\n"
257                 );
258         }
259
260         if (show_all || !strcmp(res->section, "config")) {
261                 cmdline_printf(
262                         cl,
263                         "\n"
264                         "Configuration:\n"
265                         "--------------\n"
266                         "Configuration changes only become active when"
267                         " forwarding is started/restarted.\n\n"
268
269                         "set default\n"
270                         "    Reset forwarding to the default configuration.\n\n"
271
272                         "set verbose (level)\n"
273                         "    Set the debug verbosity level X.\n\n"
274
275                         "set log global|(type) (level)\n"
276                         "    Set the log level.\n\n"
277
278                         "set nbport (num)\n"
279                         "    Set number of ports.\n\n"
280
281                         "set nbcore (num)\n"
282                         "    Set number of cores.\n\n"
283
284                         "set coremask (mask)\n"
285                         "    Set the forwarding cores hexadecimal mask.\n\n"
286
287                         "set portmask (mask)\n"
288                         "    Set the forwarding ports hexadecimal mask.\n\n"
289
290                         "set burst (num)\n"
291                         "    Set number of packets per burst.\n\n"
292
293                         "set burst tx delay (microseconds) retry (num)\n"
294                         "    Set the transmit delay time and number of retries,"
295                         " effective when retry is enabled.\n\n"
296
297                         "set rxoffs (x[,y]*)\n"
298                         "    Set the offset of each packet segment on"
299                         " receiving if split feature is engaged."
300                         " Affects only the queues configured with split"
301                         " offloads.\n\n"
302
303                         "set rxpkts (x[,y]*)\n"
304                         "    Set the length of each segment to scatter"
305                         " packets on receiving if split feature is engaged."
306                         " Affects only the queues configured with split"
307                         " offloads.\n\n"
308
309                         "set txpkts (x[,y]*)\n"
310                         "    Set the length of each segment of TXONLY"
311                         " and optionally CSUM packets.\n\n"
312
313                         "set txsplit (off|on|rand)\n"
314                         "    Set the split policy for the TX packets."
315                         " Right now only applicable for CSUM and TXONLY"
316                         " modes\n\n"
317
318                         "set txtimes (x, y)\n"
319                         "    Set the scheduling on timestamps"
320                         " timings for the TXONLY mode\n\n"
321
322                         "set corelist (x[,y]*)\n"
323                         "    Set the list of forwarding cores.\n\n"
324
325                         "set portlist (x[,y]*)\n"
326                         "    Set the list of forwarding ports.\n\n"
327
328                         "set port setup on (iterator|event)\n"
329                         "    Select how attached port is retrieved for setup.\n\n"
330
331                         "set tx loopback (port_id) (on|off)\n"
332                         "    Enable or disable tx loopback.\n\n"
333
334                         "set all queues drop (port_id) (on|off)\n"
335                         "    Set drop enable bit for all queues.\n\n"
336
337                         "set vf split drop (port_id) (vf_id) (on|off)\n"
338                         "    Set split drop enable bit for a VF from the PF.\n\n"
339
340                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
341                         "    Set MAC antispoof for a VF from the PF.\n\n"
342
343                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
344                         "    Enable MACsec offload.\n\n"
345
346                         "set macsec offload (port_id) off\n"
347                         "    Disable MACsec offload.\n\n"
348
349                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
350                         "    Configure MACsec secure connection (SC).\n\n"
351
352                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
353                         "    Configure MACsec secure association (SA).\n\n"
354
355                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
356                         "    Set VF broadcast for a VF from the PF.\n\n"
357
358                         "vlan set stripq (on|off) (port_id,queue_id)\n"
359                         "    Set the VLAN strip for a queue on a port.\n\n"
360
361                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
362                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
363
364                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
365                         "    Set VLAN insert for a VF from the PF.\n\n"
366
367                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
368                         "    Set VLAN antispoof for a VF from the PF.\n\n"
369
370                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
371                         "    Set VLAN tag for a VF from the PF.\n\n"
372
373                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
374                         "    Set a VF's max bandwidth(Mbps).\n\n"
375
376                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
377                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
378
379                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
380                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
381
382                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
383                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
384
385                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
386                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
387
388                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
389                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
390
391                         "vlan set (inner|outer) tpid (value) (port_id)\n"
392                         "    Set the VLAN TPID for Packet Filtering on"
393                         " a port\n\n"
394
395                         "rx_vlan add (vlan_id|all) (port_id)\n"
396                         "    Add a vlan_id, or all identifiers, to the set"
397                         " of VLAN identifiers filtered by port_id.\n\n"
398
399                         "rx_vlan rm (vlan_id|all) (port_id)\n"
400                         "    Remove a vlan_id, or all identifiers, from the set"
401                         " of VLAN identifiers filtered by port_id.\n\n"
402
403                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
404                         "    Add a vlan_id, to the set of VLAN identifiers"
405                         "filtered for VF(s) from port_id.\n\n"
406
407                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
408                         "    Remove a vlan_id, to the set of VLAN identifiers"
409                         "filtered for VF(s) from port_id.\n\n"
410
411                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
412                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
413                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
414                         "   add a tunnel filter of a port.\n\n"
415
416                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
417                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
418                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
419                         "   remove a tunnel filter of a port.\n\n"
420
421                         "rx_vxlan_port add (udp_port) (port_id)\n"
422                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
423
424                         "rx_vxlan_port rm (udp_port) (port_id)\n"
425                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
426
427                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
428                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
429                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
430
431                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
432                         "    Set port based TX VLAN insertion.\n\n"
433
434                         "tx_vlan reset (port_id)\n"
435                         "    Disable hardware insertion of a VLAN header in"
436                         " packets sent on a port.\n\n"
437
438                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
439                         "    Select hardware or software calculation of the"
440                         " checksum when transmitting a packet using the"
441                         " csum forward engine.\n"
442                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
443                         "    outer-ip concerns the outer IP layer in"
444                         "    outer-udp concerns the outer UDP layer in"
445                         " case the packet is recognized as a tunnel packet by"
446                         " the forward engine (vxlan, gre and ipip are supported)\n"
447                         "    Please check the NIC datasheet for HW limits.\n\n"
448
449                         "csum parse-tunnel (on|off) (tx_port_id)\n"
450                         "    If disabled, treat tunnel packets as non-tunneled"
451                         " packets (treat inner headers as payload). The port\n"
452                         "    argument is the port used for TX in csum forward"
453                         " engine.\n\n"
454
455                         "csum show (port_id)\n"
456                         "    Display tx checksum offload configuration\n\n"
457
458                         "tso set (segsize) (portid)\n"
459                         "    Enable TCP Segmentation Offload in csum forward"
460                         " engine.\n"
461                         "    Please check the NIC datasheet for HW limits.\n\n"
462
463                         "tso show (portid)"
464                         "    Display the status of TCP Segmentation Offload.\n\n"
465
466                         "set port (port_id) gro on|off\n"
467                         "    Enable or disable Generic Receive Offload in"
468                         " csum forwarding engine.\n\n"
469
470                         "show port (port_id) gro\n"
471                         "    Display GRO configuration.\n\n"
472
473                         "set gro flush (cycles)\n"
474                         "    Set the cycle to flush GROed packets from"
475                         " reassembly tables.\n\n"
476
477                         "set port (port_id) gso (on|off)"
478                         "    Enable or disable Generic Segmentation Offload in"
479                         " csum forwarding engine.\n\n"
480
481                         "set gso segsz (length)\n"
482                         "    Set max packet length for output GSO segments,"
483                         " including packet header and payload.\n\n"
484
485                         "show port (port_id) gso\n"
486                         "    Show GSO configuration.\n\n"
487
488                         "set fwd (%s)\n"
489                         "    Set packet forwarding mode.\n\n"
490
491                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
492                         "    Add a MAC address on port_id.\n\n"
493
494                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
495                         "    Remove a MAC address from port_id.\n\n"
496
497                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
498                         "    Set the default MAC address for port_id.\n\n"
499
500                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
501                         "    Add a MAC address for a VF on the port.\n\n"
502
503                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
504                         "    Set the MAC address for a VF from the PF.\n\n"
505
506                         "set eth-peer (port_id) (peer_addr)\n"
507                         "    set the peer address for certain port.\n\n"
508
509                         "set port (port_id) uta (mac_address|all) (on|off)\n"
510                         "    Add/Remove a or all unicast hash filter(s)"
511                         "from port X.\n\n"
512
513                         "set promisc (port_id|all) (on|off)\n"
514                         "    Set the promiscuous mode on port_id, or all.\n\n"
515
516                         "set allmulti (port_id|all) (on|off)\n"
517                         "    Set the allmulti mode on port_id, or all.\n\n"
518
519                         "set vf promisc (port_id) (vf_id) (on|off)\n"
520                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
521
522                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
523                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
524
525                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
526                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
527                         " (on|off) autoneg (on|off) (port_id)\n"
528                         "set flow_ctrl rx (on|off) (portid)\n"
529                         "set flow_ctrl tx (on|off) (portid)\n"
530                         "set flow_ctrl high_water (high_water) (portid)\n"
531                         "set flow_ctrl low_water (low_water) (portid)\n"
532                         "set flow_ctrl pause_time (pause_time) (portid)\n"
533                         "set flow_ctrl send_xon (send_xon) (portid)\n"
534                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
535                         "set flow_ctrl autoneg (on|off) (port_id)\n"
536                         "    Set the link flow control parameter on a port.\n\n"
537
538                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
539                         " (low_water) (pause_time) (priority) (port_id)\n"
540                         "    Set the priority flow control parameter on a"
541                         " port.\n\n"
542
543                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
544                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
545                         " queue on port.\n"
546                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
547                         " on port 0 to mapping 5.\n\n"
548
549                         "set xstats-hide-zero on|off\n"
550                         "    Set the option to hide the zero values"
551                         " for xstats display.\n"
552
553                         "set record-core-cycles on|off\n"
554                         "    Set the option to enable measurement of CPU cycles.\n"
555
556                         "set record-burst-stats on|off\n"
557                         "    Set the option to enable display of RX and TX bursts.\n"
558
559                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
560                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
561
562                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
563                         "|MPE) (on|off)\n"
564                         "    AUPE:accepts untagged VLAN;"
565                         "ROPE:accept unicast hash\n\n"
566                         "    BAM:accepts broadcast packets;"
567                         "MPE:accepts all multicast packets\n\n"
568                         "    Enable/Disable a VF receive mode of a port\n\n"
569
570                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
571                         "    Set rate limit for a queue of a port\n\n"
572
573                         "set port (port_id) vf (vf_id) rate (rate_num) "
574                         "queue_mask (queue_mask_value)\n"
575                         "    Set rate limit for queues in VF of a port\n\n"
576
577                         "set port (port_id) mirror-rule (rule_id)"
578                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
579                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
580                         "   Set pool or vlan type mirror rule on a port.\n"
581                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
582                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
583                         " to pool 0.\n\n"
584
585                         "set port (port_id) mirror-rule (rule_id)"
586                         " (uplink-mirror|downlink-mirror) dst-pool"
587                         " (pool_id) (on|off)\n"
588                         "   Set uplink or downlink type mirror rule on a port.\n"
589                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
590                         " 0 on' enable mirror income traffic to pool 0.\n\n"
591
592                         "reset port (port_id) mirror-rule (rule_id)\n"
593                         "   Reset a mirror rule.\n\n"
594
595                         "set flush_rx (on|off)\n"
596                         "   Flush (default) or don't flush RX streams before"
597                         " forwarding. Mainly used with PCAP drivers.\n\n"
598
599                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
600                         "   Set the bypass mode for the lowest port on bypass enabled"
601                         " NIC.\n\n"
602
603                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
604                         "mode (normal|bypass|isolate) (port_id)\n"
605                         "   Set the event required to initiate specified bypass mode for"
606                         " the lowest port on a bypass enabled NIC where:\n"
607                         "       timeout   = enable bypass after watchdog timeout.\n"
608                         "       os_on     = enable bypass when OS/board is powered on.\n"
609                         "       os_off    = enable bypass when OS/board is powered off.\n"
610                         "       power_on  = enable bypass when power supply is turned on.\n"
611                         "       power_off = enable bypass when power supply is turned off."
612                         "\n\n"
613
614                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
615                         "   Set the bypass watchdog timeout to 'n' seconds"
616                         " where 0 = instant.\n\n"
617
618                         "show bypass config (port_id)\n"
619                         "   Show the bypass configuration for a bypass enabled NIC"
620                         " using the lowest port on the NIC.\n\n"
621
622 #ifdef RTE_NET_BOND
623                         "create bonded device (mode) (socket)\n"
624                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
625
626                         "add bonding slave (slave_id) (port_id)\n"
627                         "       Add a slave device to a bonded device.\n\n"
628
629                         "remove bonding slave (slave_id) (port_id)\n"
630                         "       Remove a slave device from a bonded device.\n\n"
631
632                         "set bonding mode (value) (port_id)\n"
633                         "       Set the bonding mode on a bonded device.\n\n"
634
635                         "set bonding primary (slave_id) (port_id)\n"
636                         "       Set the primary slave for a bonded device.\n\n"
637
638                         "show bonding config (port_id)\n"
639                         "       Show the bonding config for port_id.\n\n"
640
641                         "set bonding mac_addr (port_id) (address)\n"
642                         "       Set the MAC address of a bonded device.\n\n"
643
644                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
645                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
646
647                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
648                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
649
650                         "set bonding mon_period (port_id) (value)\n"
651                         "       Set the bonding link status monitoring polling period in ms.\n\n"
652
653                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
654                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
655
656 #endif
657                         "set link-up port (port_id)\n"
658                         "       Set link up for a port.\n\n"
659
660                         "set link-down port (port_id)\n"
661                         "       Set link down for a port.\n\n"
662
663                         "E-tag set insertion on port-tag-id (value)"
664                         " port (port_id) vf (vf_id)\n"
665                         "    Enable E-tag insertion for a VF on a port\n\n"
666
667                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
668                         "    Disable E-tag insertion for a VF on a port\n\n"
669
670                         "E-tag set stripping (on|off) port (port_id)\n"
671                         "    Enable/disable E-tag stripping on a port\n\n"
672
673                         "E-tag set forwarding (on|off) port (port_id)\n"
674                         "    Enable/disable E-tag based forwarding"
675                         " on a port\n\n"
676
677                         "E-tag set filter add e-tag-id (value) dst-pool"
678                         " (pool_id) port (port_id)\n"
679                         "    Add an E-tag forwarding filter on a port\n\n"
680
681                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
682                         "    Delete an E-tag forwarding filter on a port\n\n"
683
684                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
685                         "    Load a profile package on a port\n\n"
686
687                         "ddp del (port_id) (backup_profile_path)\n"
688                         "    Delete a profile package from a port\n\n"
689
690                         "ptype mapping get (port_id) (valid_only)\n"
691                         "    Get ptype mapping on a port\n\n"
692
693                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
694                         "    Replace target with the pkt_type in ptype mapping\n\n"
695
696                         "ptype mapping reset (port_id)\n"
697                         "    Reset ptype mapping on a port\n\n"
698
699                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
700                         "    Update a ptype mapping item on a port\n\n"
701
702                         "set port (port_id) ptype_mask (ptype_mask)\n"
703                         "    set packet types classification for a specific port\n\n"
704
705                         "set port (port_id) queue-region region_id (value) "
706                         "queue_start_index (value) queue_num (value)\n"
707                         "    Set a queue region on a port\n\n"
708
709                         "set port (port_id) queue-region region_id (value) "
710                         "flowtype (value)\n"
711                         "    Set a flowtype region index on a port\n\n"
712
713                         "set port (port_id) queue-region UP (value) region_id (value)\n"
714                         "    Set the mapping of User Priority to "
715                         "queue region on a port\n\n"
716
717                         "set port (port_id) queue-region flush (on|off)\n"
718                         "    flush all queue region related configuration\n\n"
719
720                         "show port meter cap (port_id)\n"
721                         "    Show port meter capability information\n\n"
722
723                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
724                         "    meter profile add - srtcm rfc 2697\n\n"
725
726                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
727                         "    meter profile add - trtcm rfc 2698\n\n"
728
729                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
730                         "    meter profile add - trtcm rfc 4115\n\n"
731
732                         "del port meter profile (port_id) (profile_id)\n"
733                         "    meter profile delete\n\n"
734
735                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
736                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
737                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
738                         "(dscp_tbl_entry63)]\n"
739                         "    meter create\n\n"
740
741                         "enable port meter (port_id) (mtr_id)\n"
742                         "    meter enable\n\n"
743
744                         "disable port meter (port_id) (mtr_id)\n"
745                         "    meter disable\n\n"
746
747                         "del port meter (port_id) (mtr_id)\n"
748                         "    meter delete\n\n"
749
750                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
751                         "    meter update meter profile\n\n"
752
753                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
754                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
755                         "    update meter dscp table entries\n\n"
756
757                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
758                         "(action0) [(action1) (action2)]\n"
759                         "    meter update policer action\n\n"
760
761                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
762                         "    meter update stats\n\n"
763
764                         "show port (port_id) queue-region\n"
765                         "    show all queue region related configuration info\n\n"
766
767                         "set port (port_id) fec_mode auto|off|rs|baser\n"
768                         "    set fec mode for a specific port\n\n"
769
770                         , list_pkt_forwarding_modes()
771                 );
772         }
773
774         if (show_all || !strcmp(res->section, "ports")) {
775
776                 cmdline_printf(
777                         cl,
778                         "\n"
779                         "Port Operations:\n"
780                         "----------------\n\n"
781
782                         "port start (port_id|all)\n"
783                         "    Start all ports or port_id.\n\n"
784
785                         "port stop (port_id|all)\n"
786                         "    Stop all ports or port_id.\n\n"
787
788                         "port close (port_id|all)\n"
789                         "    Close all ports or port_id.\n\n"
790
791                         "port reset (port_id|all)\n"
792                         "    Reset all ports or port_id.\n\n"
793
794                         "port attach (ident)\n"
795                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
796
797                         "port detach (port_id)\n"
798                         "    Detach physical or virtual dev by port_id\n\n"
799
800                         "port config (port_id|all)"
801                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
802                         " duplex (half|full|auto)\n"
803                         "    Set speed and duplex for all ports or port_id\n\n"
804
805                         "port config (port_id|all) loopback (mode)\n"
806                         "    Set loopback mode for all ports or port_id\n\n"
807
808                         "port config all (rxq|txq|rxd|txd) (value)\n"
809                         "    Set number for rxq/txq/rxd/txd.\n\n"
810
811                         "port config all max-pkt-len (value)\n"
812                         "    Set the max packet length.\n\n"
813
814                         "port config all max-lro-pkt-size (value)\n"
815                         "    Set the max LRO aggregated packet size.\n\n"
816
817                         "port config all drop-en (on|off)\n"
818                         "    Enable or disable packet drop on all RX queues of all ports when no "
819                         "receive buffers available.\n\n"
820
821                         "port config all rss (all|default|ip|tcp|udp|sctp|"
822                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|level-default|"
823                         "level-outer|level-inner|<flowtype_id>)\n"
824                         "    Set the RSS mode.\n\n"
825
826                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
827                         "    Set the RSS redirection table.\n\n"
828
829                         "port config (port_id) dcb vt (on|off) (traffic_class)"
830                         " pfc (on|off)\n"
831                         "    Set the DCB mode.\n\n"
832
833                         "port config all burst (value)\n"
834                         "    Set the number of packets per burst.\n\n"
835
836                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
837                         " (value)\n"
838                         "    Set the ring prefetch/host/writeback threshold"
839                         " for tx/rx queue.\n\n"
840
841                         "port config all (txfreet|txrst|rxfreet) (value)\n"
842                         "    Set free threshold for rx/tx, or set"
843                         " tx rs bit threshold.\n\n"
844                         "port config mtu X value\n"
845                         "    Set the MTU of port X to a given value\n\n"
846
847                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
848                         "    Set a rx/tx queue's ring size configuration, the new"
849                         " value will take effect after command that (re-)start the port"
850                         " or command that setup the specific queue\n\n"
851
852                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
853                         "    Start/stop a rx/tx queue of port X. Only take effect"
854                         " when port X is started\n\n"
855
856                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
857                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
858                         " take effect when port X is stopped.\n\n"
859
860                         "port (port_id) (rxq|txq) (queue_id) setup\n"
861                         "    Setup a rx/tx queue of port X.\n\n"
862
863                         "port config (port_id|all) l2-tunnel E-tag ether-type"
864                         " (value)\n"
865                         "    Set the value of E-tag ether-type.\n\n"
866
867                         "port config (port_id|all) l2-tunnel E-tag"
868                         " (enable|disable)\n"
869                         "    Enable/disable the E-tag support.\n\n"
870
871                         "port config (port_id) pctype mapping reset\n"
872                         "    Reset flow type to pctype mapping on a port\n\n"
873
874                         "port config (port_id) pctype mapping update"
875                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
876                         "    Update a flow type to pctype mapping item on a port\n\n"
877
878                         "port config (port_id) pctype (pctype_id) hash_inset|"
879                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
880                         " (field_idx)\n"
881                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
882
883                         "port config (port_id) pctype (pctype_id) hash_inset|"
884                         "fdir_inset|fdir_flx_inset clear all"
885                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
886
887                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
888                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
889
890                         "port config <port_id> rx_offload vlan_strip|"
891                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
892                         "outer_ipv4_cksum|macsec_strip|header_split|"
893                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
894                         "buffer_split|timestamp|security|keep_crc on|off\n"
895                         "     Enable or disable a per port Rx offloading"
896                         " on all Rx queues of a port\n\n"
897
898                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
899                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
900                         "outer_ipv4_cksum|macsec_strip|header_split|"
901                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
902                         "buffer_split|timestamp|security|keep_crc on|off\n"
903                         "    Enable or disable a per queue Rx offloading"
904                         " only on a specific Rx queue\n\n"
905
906                         "port config (port_id) tx_offload vlan_insert|"
907                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
908                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
909                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
910                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
911                         "security on|off\n"
912                         "    Enable or disable a per port Tx offloading"
913                         " on all Tx queues of a port\n\n"
914
915                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
916                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
917                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
918                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
919                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
920                         " on|off\n"
921                         "    Enable or disable a per queue Tx offloading"
922                         " only on a specific Tx queue\n\n"
923
924                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
925                         "    Load an eBPF program as a callback"
926                         " for particular RX/TX queue\n\n"
927
928                         "bpf-unload rx|tx (port) (queue)\n"
929                         "    Unload previously loaded eBPF program"
930                         " for particular RX/TX queue\n\n"
931
932                         "port config (port_id) tx_metadata (value)\n"
933                         "    Set Tx metadata value per port. Testpmd will add this value"
934                         " to any Tx packet sent from this port\n\n"
935
936                         "port config (port_id) dynf (name) set|clear\n"
937                         "    Register a dynf and Set/clear this flag on Tx. "
938                         "Testpmd will set this value to any Tx packet "
939                         "sent from this port\n\n"
940                 );
941         }
942
943         if (show_all || !strcmp(res->section, "registers")) {
944
945                 cmdline_printf(
946                         cl,
947                         "\n"
948                         "Registers:\n"
949                         "----------\n\n"
950
951                         "read reg (port_id) (address)\n"
952                         "    Display value of a port register.\n\n"
953
954                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
955                         "    Display a port register bit field.\n\n"
956
957                         "read regbit (port_id) (address) (bit_x)\n"
958                         "    Display a single port register bit.\n\n"
959
960                         "write reg (port_id) (address) (value)\n"
961                         "    Set value of a port register.\n\n"
962
963                         "write regfield (port_id) (address) (bit_x) (bit_y)"
964                         " (value)\n"
965                         "    Set bit field of a port register.\n\n"
966
967                         "write regbit (port_id) (address) (bit_x) (value)\n"
968                         "    Set single bit value of a port register.\n\n"
969                 );
970         }
971         if (show_all || !strcmp(res->section, "filters")) {
972
973                 cmdline_printf(
974                         cl,
975                         "\n"
976                         "filters:\n"
977                         "--------\n\n"
978
979                         "2tuple_filter (port_id) (add|del)"
980                         " dst_port (dst_port_value) protocol (protocol_value)"
981                         " mask (mask_value) tcp_flags (tcp_flags_value)"
982                         " priority (prio_value) queue (queue_id)\n"
983                         "    Add/Del a 2tuple filter.\n\n"
984
985                         "5tuple_filter (port_id) (add|del)"
986                         " dst_ip (dst_address) src_ip (src_address)"
987                         " dst_port (dst_port_value) src_port (src_port_value)"
988                         " protocol (protocol_value)"
989                         " mask (mask_value) tcp_flags (tcp_flags_value)"
990                         " priority (prio_value) queue (queue_id)\n"
991                         "    Add/Del a 5tuple filter.\n\n"
992
993                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
994                         "    Add/Del syn filter.\n\n"
995
996                         "flow_director_filter (port_id) mode IP (add|del|update)"
997                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
998                         " src (src_ip_address) dst (dst_ip_address)"
999                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
1000                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1001                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1002                         " fd_id (fd_id_value)\n"
1003                         "    Add/Del an IP type flow director filter.\n\n"
1004
1005                         "flow_director_filter (port_id) mode IP (add|del|update)"
1006                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
1007                         " src (src_ip_address) (src_port)"
1008                         " dst (dst_ip_address) (dst_port)"
1009                         " tos (tos_value) ttl (ttl_value)"
1010                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1011                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1012                         " fd_id (fd_id_value)\n"
1013                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1014
1015                         "flow_director_filter (port_id) mode IP (add|del|update)"
1016                         " flow (ipv4-sctp|ipv6-sctp)"
1017                         " src (src_ip_address) (src_port)"
1018                         " dst (dst_ip_address) (dst_port)"
1019                         " tag (verification_tag) "
1020                         " tos (tos_value) ttl (ttl_value)"
1021                         " vlan (vlan_value)"
1022                         " flexbytes (flexbytes_value) (drop|fwd)"
1023                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1024                         "    Add/Del a SCTP type flow director filter.\n\n"
1025
1026                         "flow_director_filter (port_id) mode IP (add|del|update)"
1027                         " flow l2_payload ether (ethertype)"
1028                         " flexbytes (flexbytes_value) (drop|fwd)"
1029                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1030                         "    Add/Del a l2 payload type flow director filter.\n\n"
1031
1032                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1033                         " mac (mac_address) vlan (vlan_value)"
1034                         " flexbytes (flexbytes_value) (drop|fwd)"
1035                         " queue (queue_id) fd_id (fd_id_value)\n"
1036                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1037
1038                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1039                         " mac (mac_address) vlan (vlan_value)"
1040                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1041                         " flexbytes (flexbytes_value) (drop|fwd)"
1042                         " queue (queue_id) fd_id (fd_id_value)\n"
1043                         "    Add/Del a Tunnel flow director filter.\n\n"
1044
1045                         "flow_director_filter (port_id) mode raw (add|del|update)"
1046                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1047                         " fd_id (fd_id_value) packet (packet file name)\n"
1048                         "    Add/Del a raw type flow director filter.\n\n"
1049
1050                         "flush_flow_director (port_id)\n"
1051                         "    Flush all flow director entries of a device.\n\n"
1052
1053                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1054                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1055                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1056                         "    Set flow director IP mask.\n\n"
1057
1058                         "flow_director_mask (port_id) mode MAC-VLAN"
1059                         " vlan (vlan_value)\n"
1060                         "    Set flow director MAC-VLAN mask.\n\n"
1061
1062                         "flow_director_mask (port_id) mode Tunnel"
1063                         " vlan (vlan_value) mac (mac_value)"
1064                         " tunnel-type (tunnel_type_value)"
1065                         " tunnel-id (tunnel_id_value)\n"
1066                         "    Set flow director Tunnel mask.\n\n"
1067
1068                         "flow_director_flex_mask (port_id)"
1069                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1070                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1071                         " (mask)\n"
1072                         "    Configure mask of flex payload.\n\n"
1073
1074                         "flow_director_flex_payload (port_id)"
1075                         " (raw|l2|l3|l4) (config)\n"
1076                         "    Configure flex payload selection.\n\n"
1077
1078                         "get_sym_hash_ena_per_port (port_id)\n"
1079                         "    get symmetric hash enable configuration per port.\n\n"
1080
1081                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1082                         "    set symmetric hash enable configuration per port"
1083                         " to enable or disable.\n\n"
1084
1085                         "get_hash_global_config (port_id)\n"
1086                         "    Get the global configurations of hash filters.\n\n"
1087
1088                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1089                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1090                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1091                         " (enable|disable)\n"
1092                         "    Set the global configurations of hash filters.\n\n"
1093
1094                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1095                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1096                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1097                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1098                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1099                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1100                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1101                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1102                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1103                         "fld-8th|none) (select|add)\n"
1104                         "    Set the input set for hash.\n\n"
1105
1106                         "set_fdir_input_set (port_id) "
1107                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1108                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1109                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1110                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1111                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1112                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1113                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1114                         " (select|add)\n"
1115                         "    Set the input set for FDir.\n\n"
1116
1117                         "flow validate {port_id}"
1118                         " [group {group_id}] [priority {level}]"
1119                         " [ingress] [egress]"
1120                         " pattern {item} [/ {item} [...]] / end"
1121                         " actions {action} [/ {action} [...]] / end\n"
1122                         "    Check whether a flow rule can be created.\n\n"
1123
1124                         "flow create {port_id}"
1125                         " [group {group_id}] [priority {level}]"
1126                         " [ingress] [egress]"
1127                         " pattern {item} [/ {item} [...]] / end"
1128                         " actions {action} [/ {action} [...]] / end\n"
1129                         "    Create a flow rule.\n\n"
1130
1131                         "flow destroy {port_id} rule {rule_id} [...]\n"
1132                         "    Destroy specific flow rules.\n\n"
1133
1134                         "flow flush {port_id}\n"
1135                         "    Destroy all flow rules.\n\n"
1136
1137                         "flow query {port_id} {rule_id} {action}\n"
1138                         "    Query an existing flow rule.\n\n"
1139
1140                         "flow list {port_id} [group {group_id}] [...]\n"
1141                         "    List existing flow rules sorted by priority,"
1142                         " filtered by group identifiers.\n\n"
1143
1144                         "flow isolate {port_id} {boolean}\n"
1145                         "    Restrict ingress traffic to the defined"
1146                         " flow rules\n\n"
1147
1148                         "flow aged {port_id} [destroy]\n"
1149                         "    List and destroy aged flows"
1150                         " flow rules\n\n"
1151
1152                         "flow shared_action {port_id} create"
1153                         " [action_id {shared_action_id}]"
1154                         " [ingress] [egress]"
1155                         " action {action} / end\n"
1156                         "    Create shared action.\n\n"
1157
1158                         "flow shared_action {port_id} update"
1159                         " {shared_action_id} action {action} / end\n"
1160                         "    Update shared action.\n\n"
1161
1162                         "flow shared_action {port_id} destroy"
1163                         " action_id {shared_action_id} [...]\n"
1164                         "    Destroy specific shared actions.\n\n"
1165
1166                         "flow shared_action {port_id} query"
1167                         " {shared_action_id}\n"
1168                         "    Query an existing shared action.\n\n"
1169
1170                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1171                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1172                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1173                         "       Configure the VXLAN encapsulation for flows.\n\n"
1174
1175                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1176                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1177                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1178                         " eth-dst (eth-dst)\n"
1179                         "       Configure the VXLAN encapsulation for flows.\n\n"
1180
1181                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1182                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1183                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1184                         " eth-dst (eth-dst)\n"
1185                         "       Configure the VXLAN encapsulation for flows.\n\n"
1186
1187                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1188                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1189                         " (eth-dst)\n"
1190                         "       Configure the NVGRE encapsulation for flows.\n\n"
1191
1192                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1193                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1194                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1195                         "       Configure the NVGRE encapsulation for flows.\n\n"
1196
1197                         "set raw_encap {flow items}\n"
1198                         "       Configure the encapsulation with raw data.\n\n"
1199
1200                         "set raw_decap {flow items}\n"
1201                         "       Configure the decapsulation with raw data.\n\n"
1202
1203                 );
1204         }
1205
1206         if (show_all || !strcmp(res->section, "traffic_management")) {
1207                 cmdline_printf(
1208                         cl,
1209                         "\n"
1210                         "Traffic Management:\n"
1211                         "--------------\n"
1212                         "show port tm cap (port_id)\n"
1213                         "       Display the port TM capability.\n\n"
1214
1215                         "show port tm level cap (port_id) (level_id)\n"
1216                         "       Display the port TM hierarchical level capability.\n\n"
1217
1218                         "show port tm node cap (port_id) (node_id)\n"
1219                         "       Display the port TM node capability.\n\n"
1220
1221                         "show port tm node type (port_id) (node_id)\n"
1222                         "       Display the port TM node type.\n\n"
1223
1224                         "show port tm node stats (port_id) (node_id) (clear)\n"
1225                         "       Display the port TM node stats.\n\n"
1226
1227                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1228                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1229                         " (packet_length_adjust) (packet_mode)\n"
1230                         "       Add port tm node private shaper profile.\n\n"
1231
1232                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1233                         "       Delete port tm node private shaper profile.\n\n"
1234
1235                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1236                         " (shaper_profile_id)\n"
1237                         "       Add/update port tm node shared shaper.\n\n"
1238
1239                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1240                         "       Delete port tm node shared shaper.\n\n"
1241
1242                         "set port tm node shaper profile (port_id) (node_id)"
1243                         " (shaper_profile_id)\n"
1244                         "       Set port tm node shaper profile.\n\n"
1245
1246                         "add port tm node wred profile (port_id) (wred_profile_id)"
1247                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1248                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1249                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1250                         "       Add port tm node wred profile.\n\n"
1251
1252                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1253                         "       Delete port tm node wred profile.\n\n"
1254
1255                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1256                         " (priority) (weight) (level_id) (shaper_profile_id)"
1257                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1258                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1259                         "       Add port tm nonleaf node.\n\n"
1260
1261                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1262                         " (priority) (weight) (level_id) (shaper_profile_id)"
1263                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1264                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1265                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1266
1267                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1268                         " (priority) (weight) (level_id) (shaper_profile_id)"
1269                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1270                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1271                         "       Add port tm leaf node.\n\n"
1272
1273                         "del port tm node (port_id) (node_id)\n"
1274                         "       Delete port tm node.\n\n"
1275
1276                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1277                         " (priority) (weight)\n"
1278                         "       Set port tm node parent.\n\n"
1279
1280                         "suspend port tm node (port_id) (node_id)"
1281                         "       Suspend tm node.\n\n"
1282
1283                         "resume port tm node (port_id) (node_id)"
1284                         "       Resume tm node.\n\n"
1285
1286                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1287                         "       Commit tm hierarchy.\n\n"
1288
1289                         "set port tm mark ip_ecn (port) (green) (yellow)"
1290                         " (red)\n"
1291                         "    Enables/Disables the traffic management marking"
1292                         " for IP ECN (Explicit Congestion Notification)"
1293                         " packets on a given port\n\n"
1294
1295                         "set port tm mark ip_dscp (port) (green) (yellow)"
1296                         " (red)\n"
1297                         "    Enables/Disables the traffic management marking"
1298                         " on the port for IP dscp packets\n\n"
1299
1300                         "set port tm mark vlan_dei (port) (green) (yellow)"
1301                         " (red)\n"
1302                         "    Enables/Disables the traffic management marking"
1303                         " on the port for VLAN packets with DEI enabled\n\n"
1304                 );
1305         }
1306
1307         if (show_all || !strcmp(res->section, "devices")) {
1308                 cmdline_printf(
1309                         cl,
1310                         "\n"
1311                         "Device Operations:\n"
1312                         "--------------\n"
1313                         "device detach (identifier)\n"
1314                         "       Detach device by identifier.\n\n"
1315                 );
1316         }
1317
1318 }
1319
1320 cmdline_parse_token_string_t cmd_help_long_help =
1321         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1322
1323 cmdline_parse_token_string_t cmd_help_long_section =
1324         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1325                         "all#control#display#config#"
1326                         "ports#registers#filters#traffic_management#devices");
1327
1328 cmdline_parse_inst_t cmd_help_long = {
1329         .f = cmd_help_long_parsed,
1330         .data = NULL,
1331         .help_str = "help all|control|display|config|ports|register|"
1332                 "filters|traffic_management|devices: "
1333                 "Show help",
1334         .tokens = {
1335                 (void *)&cmd_help_long_help,
1336                 (void *)&cmd_help_long_section,
1337                 NULL,
1338         },
1339 };
1340
1341
1342 /* *** start/stop/close all ports *** */
1343 struct cmd_operate_port_result {
1344         cmdline_fixed_string_t keyword;
1345         cmdline_fixed_string_t name;
1346         cmdline_fixed_string_t value;
1347 };
1348
1349 static void cmd_operate_port_parsed(void *parsed_result,
1350                                 __rte_unused struct cmdline *cl,
1351                                 __rte_unused void *data)
1352 {
1353         struct cmd_operate_port_result *res = parsed_result;
1354
1355         if (!strcmp(res->name, "start"))
1356                 start_port(RTE_PORT_ALL);
1357         else if (!strcmp(res->name, "stop"))
1358                 stop_port(RTE_PORT_ALL);
1359         else if (!strcmp(res->name, "close"))
1360                 close_port(RTE_PORT_ALL);
1361         else if (!strcmp(res->name, "reset"))
1362                 reset_port(RTE_PORT_ALL);
1363         else
1364                 printf("Unknown parameter\n");
1365 }
1366
1367 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1368         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1369                                                                 "port");
1370 cmdline_parse_token_string_t cmd_operate_port_all_port =
1371         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1372                                                 "start#stop#close#reset");
1373 cmdline_parse_token_string_t cmd_operate_port_all_all =
1374         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1375
1376 cmdline_parse_inst_t cmd_operate_port = {
1377         .f = cmd_operate_port_parsed,
1378         .data = NULL,
1379         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1380         .tokens = {
1381                 (void *)&cmd_operate_port_all_cmd,
1382                 (void *)&cmd_operate_port_all_port,
1383                 (void *)&cmd_operate_port_all_all,
1384                 NULL,
1385         },
1386 };
1387
1388 /* *** start/stop/close specific port *** */
1389 struct cmd_operate_specific_port_result {
1390         cmdline_fixed_string_t keyword;
1391         cmdline_fixed_string_t name;
1392         uint8_t value;
1393 };
1394
1395 static void cmd_operate_specific_port_parsed(void *parsed_result,
1396                         __rte_unused struct cmdline *cl,
1397                                 __rte_unused void *data)
1398 {
1399         struct cmd_operate_specific_port_result *res = parsed_result;
1400
1401         if (!strcmp(res->name, "start"))
1402                 start_port(res->value);
1403         else if (!strcmp(res->name, "stop"))
1404                 stop_port(res->value);
1405         else if (!strcmp(res->name, "close"))
1406                 close_port(res->value);
1407         else if (!strcmp(res->name, "reset"))
1408                 reset_port(res->value);
1409         else
1410                 printf("Unknown parameter\n");
1411 }
1412
1413 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1414         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1415                                                         keyword, "port");
1416 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1417         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1418                                                 name, "start#stop#close#reset");
1419 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1420         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1421                                                         value, UINT8);
1422
1423 cmdline_parse_inst_t cmd_operate_specific_port = {
1424         .f = cmd_operate_specific_port_parsed,
1425         .data = NULL,
1426         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1427         .tokens = {
1428                 (void *)&cmd_operate_specific_port_cmd,
1429                 (void *)&cmd_operate_specific_port_port,
1430                 (void *)&cmd_operate_specific_port_id,
1431                 NULL,
1432         },
1433 };
1434
1435 /* *** enable port setup (after attach) via iterator or event *** */
1436 struct cmd_set_port_setup_on_result {
1437         cmdline_fixed_string_t set;
1438         cmdline_fixed_string_t port;
1439         cmdline_fixed_string_t setup;
1440         cmdline_fixed_string_t on;
1441         cmdline_fixed_string_t mode;
1442 };
1443
1444 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1445                                 __rte_unused struct cmdline *cl,
1446                                 __rte_unused void *data)
1447 {
1448         struct cmd_set_port_setup_on_result *res = parsed_result;
1449
1450         if (strcmp(res->mode, "event") == 0)
1451                 setup_on_probe_event = true;
1452         else if (strcmp(res->mode, "iterator") == 0)
1453                 setup_on_probe_event = false;
1454         else
1455                 printf("Unknown mode\n");
1456 }
1457
1458 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1459         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1460                         set, "set");
1461 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1462         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1463                         port, "port");
1464 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1465         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1466                         setup, "setup");
1467 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1468         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1469                         on, "on");
1470 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1471         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1472                         mode, "iterator#event");
1473
1474 cmdline_parse_inst_t cmd_set_port_setup_on = {
1475         .f = cmd_set_port_setup_on_parsed,
1476         .data = NULL,
1477         .help_str = "set port setup on iterator|event",
1478         .tokens = {
1479                 (void *)&cmd_set_port_setup_on_set,
1480                 (void *)&cmd_set_port_setup_on_port,
1481                 (void *)&cmd_set_port_setup_on_setup,
1482                 (void *)&cmd_set_port_setup_on_on,
1483                 (void *)&cmd_set_port_setup_on_mode,
1484                 NULL,
1485         },
1486 };
1487
1488 /* *** attach a specified port *** */
1489 struct cmd_operate_attach_port_result {
1490         cmdline_fixed_string_t port;
1491         cmdline_fixed_string_t keyword;
1492         cmdline_multi_string_t identifier;
1493 };
1494
1495 static void cmd_operate_attach_port_parsed(void *parsed_result,
1496                                 __rte_unused struct cmdline *cl,
1497                                 __rte_unused void *data)
1498 {
1499         struct cmd_operate_attach_port_result *res = parsed_result;
1500
1501         if (!strcmp(res->keyword, "attach"))
1502                 attach_port(res->identifier);
1503         else
1504                 printf("Unknown parameter\n");
1505 }
1506
1507 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1508         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1509                         port, "port");
1510 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1511         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1512                         keyword, "attach");
1513 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1514         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1515                         identifier, TOKEN_STRING_MULTI);
1516
1517 cmdline_parse_inst_t cmd_operate_attach_port = {
1518         .f = cmd_operate_attach_port_parsed,
1519         .data = NULL,
1520         .help_str = "port attach <identifier>: "
1521                 "(identifier: pci address or virtual dev name)",
1522         .tokens = {
1523                 (void *)&cmd_operate_attach_port_port,
1524                 (void *)&cmd_operate_attach_port_keyword,
1525                 (void *)&cmd_operate_attach_port_identifier,
1526                 NULL,
1527         },
1528 };
1529
1530 /* *** detach a specified port *** */
1531 struct cmd_operate_detach_port_result {
1532         cmdline_fixed_string_t port;
1533         cmdline_fixed_string_t keyword;
1534         portid_t port_id;
1535 };
1536
1537 static void cmd_operate_detach_port_parsed(void *parsed_result,
1538                                 __rte_unused struct cmdline *cl,
1539                                 __rte_unused void *data)
1540 {
1541         struct cmd_operate_detach_port_result *res = parsed_result;
1542
1543         if (!strcmp(res->keyword, "detach")) {
1544                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1545                 detach_port_device(res->port_id);
1546         } else {
1547                 printf("Unknown parameter\n");
1548         }
1549 }
1550
1551 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1552         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1553                         port, "port");
1554 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1555         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1556                         keyword, "detach");
1557 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1558         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1559                         port_id, UINT16);
1560
1561 cmdline_parse_inst_t cmd_operate_detach_port = {
1562         .f = cmd_operate_detach_port_parsed,
1563         .data = NULL,
1564         .help_str = "port detach <port_id>",
1565         .tokens = {
1566                 (void *)&cmd_operate_detach_port_port,
1567                 (void *)&cmd_operate_detach_port_keyword,
1568                 (void *)&cmd_operate_detach_port_port_id,
1569                 NULL,
1570         },
1571 };
1572
1573 /* *** detach device by identifier *** */
1574 struct cmd_operate_detach_device_result {
1575         cmdline_fixed_string_t device;
1576         cmdline_fixed_string_t keyword;
1577         cmdline_fixed_string_t identifier;
1578 };
1579
1580 static void cmd_operate_detach_device_parsed(void *parsed_result,
1581                                 __rte_unused struct cmdline *cl,
1582                                 __rte_unused void *data)
1583 {
1584         struct cmd_operate_detach_device_result *res = parsed_result;
1585
1586         if (!strcmp(res->keyword, "detach"))
1587                 detach_devargs(res->identifier);
1588         else
1589                 printf("Unknown parameter\n");
1590 }
1591
1592 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1593         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1594                         device, "device");
1595 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1596         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1597                         keyword, "detach");
1598 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1599         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1600                         identifier, NULL);
1601
1602 cmdline_parse_inst_t cmd_operate_detach_device = {
1603         .f = cmd_operate_detach_device_parsed,
1604         .data = NULL,
1605         .help_str = "device detach <identifier>:"
1606                 "(identifier: pci address or virtual dev name)",
1607         .tokens = {
1608                 (void *)&cmd_operate_detach_device_device,
1609                 (void *)&cmd_operate_detach_device_keyword,
1610                 (void *)&cmd_operate_detach_device_identifier,
1611                 NULL,
1612         },
1613 };
1614 /* *** configure speed for all ports *** */
1615 struct cmd_config_speed_all {
1616         cmdline_fixed_string_t port;
1617         cmdline_fixed_string_t keyword;
1618         cmdline_fixed_string_t all;
1619         cmdline_fixed_string_t item1;
1620         cmdline_fixed_string_t item2;
1621         cmdline_fixed_string_t value1;
1622         cmdline_fixed_string_t value2;
1623 };
1624
1625 static int
1626 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1627 {
1628
1629         int duplex;
1630
1631         if (!strcmp(duplexstr, "half")) {
1632                 duplex = ETH_LINK_HALF_DUPLEX;
1633         } else if (!strcmp(duplexstr, "full")) {
1634                 duplex = ETH_LINK_FULL_DUPLEX;
1635         } else if (!strcmp(duplexstr, "auto")) {
1636                 duplex = ETH_LINK_FULL_DUPLEX;
1637         } else {
1638                 printf("Unknown duplex parameter\n");
1639                 return -1;
1640         }
1641
1642         if (!strcmp(speedstr, "10")) {
1643                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1644                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1645         } else if (!strcmp(speedstr, "100")) {
1646                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1647                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1648         } else {
1649                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1650                         printf("Invalid speed/duplex parameters\n");
1651                         return -1;
1652                 }
1653                 if (!strcmp(speedstr, "1000")) {
1654                         *speed = ETH_LINK_SPEED_1G;
1655                 } else if (!strcmp(speedstr, "10000")) {
1656                         *speed = ETH_LINK_SPEED_10G;
1657                 } else if (!strcmp(speedstr, "25000")) {
1658                         *speed = ETH_LINK_SPEED_25G;
1659                 } else if (!strcmp(speedstr, "40000")) {
1660                         *speed = ETH_LINK_SPEED_40G;
1661                 } else if (!strcmp(speedstr, "50000")) {
1662                         *speed = ETH_LINK_SPEED_50G;
1663                 } else if (!strcmp(speedstr, "100000")) {
1664                         *speed = ETH_LINK_SPEED_100G;
1665                 } else if (!strcmp(speedstr, "200000")) {
1666                         *speed = ETH_LINK_SPEED_200G;
1667                 } else if (!strcmp(speedstr, "auto")) {
1668                         *speed = ETH_LINK_SPEED_AUTONEG;
1669                 } else {
1670                         printf("Unknown speed parameter\n");
1671                         return -1;
1672                 }
1673         }
1674
1675         return 0;
1676 }
1677
1678 static void
1679 cmd_config_speed_all_parsed(void *parsed_result,
1680                         __rte_unused struct cmdline *cl,
1681                         __rte_unused void *data)
1682 {
1683         struct cmd_config_speed_all *res = parsed_result;
1684         uint32_t link_speed;
1685         portid_t pid;
1686
1687         if (!all_ports_stopped()) {
1688                 printf("Please stop all ports first\n");
1689                 return;
1690         }
1691
1692         if (parse_and_check_speed_duplex(res->value1, res->value2,
1693                         &link_speed) < 0)
1694                 return;
1695
1696         RTE_ETH_FOREACH_DEV(pid) {
1697                 ports[pid].dev_conf.link_speeds = link_speed;
1698         }
1699
1700         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1701 }
1702
1703 cmdline_parse_token_string_t cmd_config_speed_all_port =
1704         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1705 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1706         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1707                                                         "config");
1708 cmdline_parse_token_string_t cmd_config_speed_all_all =
1709         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1710 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1711         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1712 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1713         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1714                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1715 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1716         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1717 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1718         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1719                                                 "half#full#auto");
1720
1721 cmdline_parse_inst_t cmd_config_speed_all = {
1722         .f = cmd_config_speed_all_parsed,
1723         .data = NULL,
1724         .help_str = "port config all speed "
1725                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1726                                                         "half|full|auto",
1727         .tokens = {
1728                 (void *)&cmd_config_speed_all_port,
1729                 (void *)&cmd_config_speed_all_keyword,
1730                 (void *)&cmd_config_speed_all_all,
1731                 (void *)&cmd_config_speed_all_item1,
1732                 (void *)&cmd_config_speed_all_value1,
1733                 (void *)&cmd_config_speed_all_item2,
1734                 (void *)&cmd_config_speed_all_value2,
1735                 NULL,
1736         },
1737 };
1738
1739 /* *** configure speed for specific port *** */
1740 struct cmd_config_speed_specific {
1741         cmdline_fixed_string_t port;
1742         cmdline_fixed_string_t keyword;
1743         portid_t id;
1744         cmdline_fixed_string_t item1;
1745         cmdline_fixed_string_t item2;
1746         cmdline_fixed_string_t value1;
1747         cmdline_fixed_string_t value2;
1748 };
1749
1750 static void
1751 cmd_config_speed_specific_parsed(void *parsed_result,
1752                                 __rte_unused struct cmdline *cl,
1753                                 __rte_unused void *data)
1754 {
1755         struct cmd_config_speed_specific *res = parsed_result;
1756         uint32_t link_speed;
1757
1758         if (!all_ports_stopped()) {
1759                 printf("Please stop all ports first\n");
1760                 return;
1761         }
1762
1763         if (port_id_is_invalid(res->id, ENABLED_WARN))
1764                 return;
1765
1766         if (parse_and_check_speed_duplex(res->value1, res->value2,
1767                         &link_speed) < 0)
1768                 return;
1769
1770         ports[res->id].dev_conf.link_speeds = link_speed;
1771
1772         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1773 }
1774
1775
1776 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1777         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1778                                                                 "port");
1779 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1780         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1781                                                                 "config");
1782 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1783         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1784 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1785         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1786                                                                 "speed");
1787 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1788         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1789                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1790 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1791         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1792                                                                 "duplex");
1793 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1794         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1795                                                         "half#full#auto");
1796
1797 cmdline_parse_inst_t cmd_config_speed_specific = {
1798         .f = cmd_config_speed_specific_parsed,
1799         .data = NULL,
1800         .help_str = "port config <port_id> speed "
1801                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1802                                                         "half|full|auto",
1803         .tokens = {
1804                 (void *)&cmd_config_speed_specific_port,
1805                 (void *)&cmd_config_speed_specific_keyword,
1806                 (void *)&cmd_config_speed_specific_id,
1807                 (void *)&cmd_config_speed_specific_item1,
1808                 (void *)&cmd_config_speed_specific_value1,
1809                 (void *)&cmd_config_speed_specific_item2,
1810                 (void *)&cmd_config_speed_specific_value2,
1811                 NULL,
1812         },
1813 };
1814
1815 /* *** configure loopback for all ports *** */
1816 struct cmd_config_loopback_all {
1817         cmdline_fixed_string_t port;
1818         cmdline_fixed_string_t keyword;
1819         cmdline_fixed_string_t all;
1820         cmdline_fixed_string_t item;
1821         uint32_t mode;
1822 };
1823
1824 static void
1825 cmd_config_loopback_all_parsed(void *parsed_result,
1826                         __rte_unused struct cmdline *cl,
1827                         __rte_unused void *data)
1828 {
1829         struct cmd_config_loopback_all *res = parsed_result;
1830         portid_t pid;
1831
1832         if (!all_ports_stopped()) {
1833                 printf("Please stop all ports first\n");
1834                 return;
1835         }
1836
1837         RTE_ETH_FOREACH_DEV(pid) {
1838                 ports[pid].dev_conf.lpbk_mode = res->mode;
1839         }
1840
1841         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1842 }
1843
1844 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1845         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1846 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1847         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1848                                                         "config");
1849 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1850         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1851 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1852         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1853                                                         "loopback");
1854 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1855         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1856
1857 cmdline_parse_inst_t cmd_config_loopback_all = {
1858         .f = cmd_config_loopback_all_parsed,
1859         .data = NULL,
1860         .help_str = "port config all loopback <mode>",
1861         .tokens = {
1862                 (void *)&cmd_config_loopback_all_port,
1863                 (void *)&cmd_config_loopback_all_keyword,
1864                 (void *)&cmd_config_loopback_all_all,
1865                 (void *)&cmd_config_loopback_all_item,
1866                 (void *)&cmd_config_loopback_all_mode,
1867                 NULL,
1868         },
1869 };
1870
1871 /* *** configure loopback for specific port *** */
1872 struct cmd_config_loopback_specific {
1873         cmdline_fixed_string_t port;
1874         cmdline_fixed_string_t keyword;
1875         uint16_t port_id;
1876         cmdline_fixed_string_t item;
1877         uint32_t mode;
1878 };
1879
1880 static void
1881 cmd_config_loopback_specific_parsed(void *parsed_result,
1882                                 __rte_unused struct cmdline *cl,
1883                                 __rte_unused void *data)
1884 {
1885         struct cmd_config_loopback_specific *res = parsed_result;
1886
1887         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1888                 return;
1889
1890         if (!port_is_stopped(res->port_id)) {
1891                 printf("Please stop port %u first\n", res->port_id);
1892                 return;
1893         }
1894
1895         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1896
1897         cmd_reconfig_device_queue(res->port_id, 1, 1);
1898 }
1899
1900
1901 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1902         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1903                                                                 "port");
1904 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1905         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1906                                                                 "config");
1907 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1908         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1909                                                                 UINT16);
1910 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1911         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1912                                                                 "loopback");
1913 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1914         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1915                               UINT32);
1916
1917 cmdline_parse_inst_t cmd_config_loopback_specific = {
1918         .f = cmd_config_loopback_specific_parsed,
1919         .data = NULL,
1920         .help_str = "port config <port_id> loopback <mode>",
1921         .tokens = {
1922                 (void *)&cmd_config_loopback_specific_port,
1923                 (void *)&cmd_config_loopback_specific_keyword,
1924                 (void *)&cmd_config_loopback_specific_id,
1925                 (void *)&cmd_config_loopback_specific_item,
1926                 (void *)&cmd_config_loopback_specific_mode,
1927                 NULL,
1928         },
1929 };
1930
1931 /* *** configure txq/rxq, txd/rxd *** */
1932 struct cmd_config_rx_tx {
1933         cmdline_fixed_string_t port;
1934         cmdline_fixed_string_t keyword;
1935         cmdline_fixed_string_t all;
1936         cmdline_fixed_string_t name;
1937         uint16_t value;
1938 };
1939
1940 static void
1941 cmd_config_rx_tx_parsed(void *parsed_result,
1942                         __rte_unused struct cmdline *cl,
1943                         __rte_unused void *data)
1944 {
1945         struct cmd_config_rx_tx *res = parsed_result;
1946
1947         if (!all_ports_stopped()) {
1948                 printf("Please stop all ports first\n");
1949                 return;
1950         }
1951         if (!strcmp(res->name, "rxq")) {
1952                 if (!res->value && !nb_txq) {
1953                         printf("Warning: Either rx or tx queues should be non zero\n");
1954                         return;
1955                 }
1956                 if (check_nb_rxq(res->value) != 0)
1957                         return;
1958                 nb_rxq = res->value;
1959         }
1960         else if (!strcmp(res->name, "txq")) {
1961                 if (!res->value && !nb_rxq) {
1962                         printf("Warning: Either rx or tx queues should be non zero\n");
1963                         return;
1964                 }
1965                 if (check_nb_txq(res->value) != 0)
1966                         return;
1967                 nb_txq = res->value;
1968         }
1969         else if (!strcmp(res->name, "rxd")) {
1970                 if (check_nb_rxd(res->value) != 0)
1971                         return;
1972                 nb_rxd = res->value;
1973         } else if (!strcmp(res->name, "txd")) {
1974                 if (check_nb_txd(res->value) != 0)
1975                         return;
1976
1977                 nb_txd = res->value;
1978         } else {
1979                 printf("Unknown parameter\n");
1980                 return;
1981         }
1982
1983         fwd_config_setup();
1984
1985         init_port_config();
1986
1987         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1988 }
1989
1990 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1991         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1992 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1993         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1994 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1995         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1996 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1997         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1998                                                 "rxq#txq#rxd#txd");
1999 cmdline_parse_token_num_t cmd_config_rx_tx_value =
2000         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
2001
2002 cmdline_parse_inst_t cmd_config_rx_tx = {
2003         .f = cmd_config_rx_tx_parsed,
2004         .data = NULL,
2005         .help_str = "port config all rxq|txq|rxd|txd <value>",
2006         .tokens = {
2007                 (void *)&cmd_config_rx_tx_port,
2008                 (void *)&cmd_config_rx_tx_keyword,
2009                 (void *)&cmd_config_rx_tx_all,
2010                 (void *)&cmd_config_rx_tx_name,
2011                 (void *)&cmd_config_rx_tx_value,
2012                 NULL,
2013         },
2014 };
2015
2016 /* *** config max packet length *** */
2017 struct cmd_config_max_pkt_len_result {
2018         cmdline_fixed_string_t port;
2019         cmdline_fixed_string_t keyword;
2020         cmdline_fixed_string_t all;
2021         cmdline_fixed_string_t name;
2022         uint32_t value;
2023 };
2024
2025 static void
2026 cmd_config_max_pkt_len_parsed(void *parsed_result,
2027                                 __rte_unused struct cmdline *cl,
2028                                 __rte_unused void *data)
2029 {
2030         struct cmd_config_max_pkt_len_result *res = parsed_result;
2031         portid_t pid;
2032
2033         if (!all_ports_stopped()) {
2034                 printf("Please stop all ports first\n");
2035                 return;
2036         }
2037
2038         RTE_ETH_FOREACH_DEV(pid) {
2039                 struct rte_port *port = &ports[pid];
2040                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2041
2042                 if (!strcmp(res->name, "max-pkt-len")) {
2043                         if (res->value < RTE_ETHER_MIN_LEN) {
2044                                 printf("max-pkt-len can not be less than %d\n",
2045                                                 RTE_ETHER_MIN_LEN);
2046                                 return;
2047                         }
2048                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2049                                 return;
2050
2051                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2052                         if (res->value > RTE_ETHER_MAX_LEN)
2053                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2054                         else
2055                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2056                         port->dev_conf.rxmode.offloads = rx_offloads;
2057                 } else {
2058                         printf("Unknown parameter\n");
2059                         return;
2060                 }
2061         }
2062
2063         init_port_config();
2064
2065         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2066 }
2067
2068 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2069         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2070                                                                 "port");
2071 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2072         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2073                                                                 "config");
2074 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2075         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2076                                                                 "all");
2077 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2078         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2079                                                                 "max-pkt-len");
2080 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2081         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2082                                                                 UINT32);
2083
2084 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2085         .f = cmd_config_max_pkt_len_parsed,
2086         .data = NULL,
2087         .help_str = "port config all max-pkt-len <value>",
2088         .tokens = {
2089                 (void *)&cmd_config_max_pkt_len_port,
2090                 (void *)&cmd_config_max_pkt_len_keyword,
2091                 (void *)&cmd_config_max_pkt_len_all,
2092                 (void *)&cmd_config_max_pkt_len_name,
2093                 (void *)&cmd_config_max_pkt_len_value,
2094                 NULL,
2095         },
2096 };
2097
2098 /* *** config max LRO aggregated packet size *** */
2099 struct cmd_config_max_lro_pkt_size_result {
2100         cmdline_fixed_string_t port;
2101         cmdline_fixed_string_t keyword;
2102         cmdline_fixed_string_t all;
2103         cmdline_fixed_string_t name;
2104         uint32_t value;
2105 };
2106
2107 static void
2108 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2109                                 __rte_unused struct cmdline *cl,
2110                                 __rte_unused void *data)
2111 {
2112         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2113         portid_t pid;
2114
2115         if (!all_ports_stopped()) {
2116                 printf("Please stop all ports first\n");
2117                 return;
2118         }
2119
2120         RTE_ETH_FOREACH_DEV(pid) {
2121                 struct rte_port *port = &ports[pid];
2122
2123                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2124                         if (res->value ==
2125                                         port->dev_conf.rxmode.max_lro_pkt_size)
2126                                 return;
2127
2128                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2129                 } else {
2130                         printf("Unknown parameter\n");
2131                         return;
2132                 }
2133         }
2134
2135         init_port_config();
2136
2137         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2138 }
2139
2140 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2141         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2142                                  port, "port");
2143 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2144         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2145                                  keyword, "config");
2146 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2147         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2148                                  all, "all");
2149 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2150         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2151                                  name, "max-lro-pkt-size");
2152 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2153         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2154                               value, UINT32);
2155
2156 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2157         .f = cmd_config_max_lro_pkt_size_parsed,
2158         .data = NULL,
2159         .help_str = "port config all max-lro-pkt-size <value>",
2160         .tokens = {
2161                 (void *)&cmd_config_max_lro_pkt_size_port,
2162                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2163                 (void *)&cmd_config_max_lro_pkt_size_all,
2164                 (void *)&cmd_config_max_lro_pkt_size_name,
2165                 (void *)&cmd_config_max_lro_pkt_size_value,
2166                 NULL,
2167         },
2168 };
2169
2170 /* *** configure port MTU *** */
2171 struct cmd_config_mtu_result {
2172         cmdline_fixed_string_t port;
2173         cmdline_fixed_string_t keyword;
2174         cmdline_fixed_string_t mtu;
2175         portid_t port_id;
2176         uint16_t value;
2177 };
2178
2179 static void
2180 cmd_config_mtu_parsed(void *parsed_result,
2181                       __rte_unused struct cmdline *cl,
2182                       __rte_unused void *data)
2183 {
2184         struct cmd_config_mtu_result *res = parsed_result;
2185
2186         if (res->value < RTE_ETHER_MIN_LEN) {
2187                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2188                 return;
2189         }
2190         port_mtu_set(res->port_id, res->value);
2191 }
2192
2193 cmdline_parse_token_string_t cmd_config_mtu_port =
2194         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2195                                  "port");
2196 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2197         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2198                                  "config");
2199 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2200         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2201                                  "mtu");
2202 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2203         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2204 cmdline_parse_token_num_t cmd_config_mtu_value =
2205         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2206
2207 cmdline_parse_inst_t cmd_config_mtu = {
2208         .f = cmd_config_mtu_parsed,
2209         .data = NULL,
2210         .help_str = "port config mtu <port_id> <value>",
2211         .tokens = {
2212                 (void *)&cmd_config_mtu_port,
2213                 (void *)&cmd_config_mtu_keyword,
2214                 (void *)&cmd_config_mtu_mtu,
2215                 (void *)&cmd_config_mtu_port_id,
2216                 (void *)&cmd_config_mtu_value,
2217                 NULL,
2218         },
2219 };
2220
2221 /* *** configure rx mode *** */
2222 struct cmd_config_rx_mode_flag {
2223         cmdline_fixed_string_t port;
2224         cmdline_fixed_string_t keyword;
2225         cmdline_fixed_string_t all;
2226         cmdline_fixed_string_t name;
2227         cmdline_fixed_string_t value;
2228 };
2229
2230 static void
2231 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2232                                 __rte_unused struct cmdline *cl,
2233                                 __rte_unused void *data)
2234 {
2235         struct cmd_config_rx_mode_flag *res = parsed_result;
2236
2237         if (!all_ports_stopped()) {
2238                 printf("Please stop all ports first\n");
2239                 return;
2240         }
2241
2242         if (!strcmp(res->name, "drop-en")) {
2243                 if (!strcmp(res->value, "on"))
2244                         rx_drop_en = 1;
2245                 else if (!strcmp(res->value, "off"))
2246                         rx_drop_en = 0;
2247                 else {
2248                         printf("Unknown parameter\n");
2249                         return;
2250                 }
2251         } else {
2252                 printf("Unknown parameter\n");
2253                 return;
2254         }
2255
2256         init_port_config();
2257
2258         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2259 }
2260
2261 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2262         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2263 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2264         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2265                                                                 "config");
2266 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2267         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2268 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2269         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2270                                         "drop-en");
2271 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2272         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2273                                                         "on#off");
2274
2275 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2276         .f = cmd_config_rx_mode_flag_parsed,
2277         .data = NULL,
2278         .help_str = "port config all drop-en on|off",
2279         .tokens = {
2280                 (void *)&cmd_config_rx_mode_flag_port,
2281                 (void *)&cmd_config_rx_mode_flag_keyword,
2282                 (void *)&cmd_config_rx_mode_flag_all,
2283                 (void *)&cmd_config_rx_mode_flag_name,
2284                 (void *)&cmd_config_rx_mode_flag_value,
2285                 NULL,
2286         },
2287 };
2288
2289 /* *** configure rss *** */
2290 struct cmd_config_rss {
2291         cmdline_fixed_string_t port;
2292         cmdline_fixed_string_t keyword;
2293         cmdline_fixed_string_t all;
2294         cmdline_fixed_string_t name;
2295         cmdline_fixed_string_t value;
2296 };
2297
2298 static void
2299 cmd_config_rss_parsed(void *parsed_result,
2300                         __rte_unused struct cmdline *cl,
2301                         __rte_unused void *data)
2302 {
2303         struct cmd_config_rss *res = parsed_result;
2304         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2305         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2306         int use_default = 0;
2307         int all_updated = 1;
2308         int diag;
2309         uint16_t i;
2310         int ret;
2311
2312         if (!strcmp(res->value, "all"))
2313                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2314                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2315                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2316                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2317         else if (!strcmp(res->value, "eth"))
2318                 rss_conf.rss_hf = ETH_RSS_ETH;
2319         else if (!strcmp(res->value, "vlan"))
2320                 rss_conf.rss_hf = ETH_RSS_VLAN;
2321         else if (!strcmp(res->value, "ip"))
2322                 rss_conf.rss_hf = ETH_RSS_IP;
2323         else if (!strcmp(res->value, "udp"))
2324                 rss_conf.rss_hf = ETH_RSS_UDP;
2325         else if (!strcmp(res->value, "tcp"))
2326                 rss_conf.rss_hf = ETH_RSS_TCP;
2327         else if (!strcmp(res->value, "sctp"))
2328                 rss_conf.rss_hf = ETH_RSS_SCTP;
2329         else if (!strcmp(res->value, "ether"))
2330                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2331         else if (!strcmp(res->value, "port"))
2332                 rss_conf.rss_hf = ETH_RSS_PORT;
2333         else if (!strcmp(res->value, "vxlan"))
2334                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2335         else if (!strcmp(res->value, "geneve"))
2336                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2337         else if (!strcmp(res->value, "nvgre"))
2338                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2339         else if (!strcmp(res->value, "l3-pre32"))
2340                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2341         else if (!strcmp(res->value, "l3-pre40"))
2342                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2343         else if (!strcmp(res->value, "l3-pre48"))
2344                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2345         else if (!strcmp(res->value, "l3-pre56"))
2346                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2347         else if (!strcmp(res->value, "l3-pre64"))
2348                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2349         else if (!strcmp(res->value, "l3-pre96"))
2350                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2351         else if (!strcmp(res->value, "l3-src-only"))
2352                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2353         else if (!strcmp(res->value, "l3-dst-only"))
2354                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2355         else if (!strcmp(res->value, "l4-src-only"))
2356                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2357         else if (!strcmp(res->value, "l4-dst-only"))
2358                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2359         else if (!strcmp(res->value, "l2-src-only"))
2360                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2361         else if (!strcmp(res->value, "l2-dst-only"))
2362                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2363         else if (!strcmp(res->value, "l2tpv3"))
2364                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2365         else if (!strcmp(res->value, "esp"))
2366                 rss_conf.rss_hf = ETH_RSS_ESP;
2367         else if (!strcmp(res->value, "ah"))
2368                 rss_conf.rss_hf = ETH_RSS_AH;
2369         else if (!strcmp(res->value, "pfcp"))
2370                 rss_conf.rss_hf = ETH_RSS_PFCP;
2371         else if (!strcmp(res->value, "pppoe"))
2372                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2373         else if (!strcmp(res->value, "gtpu"))
2374                 rss_conf.rss_hf = ETH_RSS_GTPU;
2375         else if (!strcmp(res->value, "none"))
2376                 rss_conf.rss_hf = 0;
2377         else if (!strcmp(res->value, "level-default")) {
2378                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2379                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2380         } else if (!strcmp(res->value, "level-outer")) {
2381                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2382                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2383         } else if (!strcmp(res->value, "level-inner")) {
2384                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2385                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2386         } else if (!strcmp(res->value, "default"))
2387                 use_default = 1;
2388         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2389                                                 atoi(res->value) < 64)
2390                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2391         else {
2392                 printf("Unknown parameter\n");
2393                 return;
2394         }
2395         rss_conf.rss_key = NULL;
2396         /* Update global configuration for RSS types. */
2397         RTE_ETH_FOREACH_DEV(i) {
2398                 struct rte_eth_rss_conf local_rss_conf;
2399
2400                 ret = eth_dev_info_get_print_err(i, &dev_info);
2401                 if (ret != 0)
2402                         return;
2403
2404                 if (use_default)
2405                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2406
2407                 local_rss_conf = rss_conf;
2408                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2409                         dev_info.flow_type_rss_offloads;
2410                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2411                         printf("Port %u modified RSS hash function based on hardware support,"
2412                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2413                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2414                 }
2415                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2416                 if (diag < 0) {
2417                         all_updated = 0;
2418                         printf("Configuration of RSS hash at ethernet port %d "
2419                                 "failed with error (%d): %s.\n",
2420                                 i, -diag, strerror(-diag));
2421                 }
2422         }
2423         if (all_updated && !use_default) {
2424                 rss_hf = rss_conf.rss_hf;
2425                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2426         }
2427 }
2428
2429 cmdline_parse_token_string_t cmd_config_rss_port =
2430         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2431 cmdline_parse_token_string_t cmd_config_rss_keyword =
2432         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2433 cmdline_parse_token_string_t cmd_config_rss_all =
2434         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2435 cmdline_parse_token_string_t cmd_config_rss_name =
2436         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2437 cmdline_parse_token_string_t cmd_config_rss_value =
2438         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2439
2440 cmdline_parse_inst_t cmd_config_rss = {
2441         .f = cmd_config_rss_parsed,
2442         .data = NULL,
2443         .help_str = "port config all rss "
2444                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2445                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2446                 "level-outer|level-inner|<flowtype_id>",
2447         .tokens = {
2448                 (void *)&cmd_config_rss_port,
2449                 (void *)&cmd_config_rss_keyword,
2450                 (void *)&cmd_config_rss_all,
2451                 (void *)&cmd_config_rss_name,
2452                 (void *)&cmd_config_rss_value,
2453                 NULL,
2454         },
2455 };
2456
2457 /* *** configure rss hash key *** */
2458 struct cmd_config_rss_hash_key {
2459         cmdline_fixed_string_t port;
2460         cmdline_fixed_string_t config;
2461         portid_t port_id;
2462         cmdline_fixed_string_t rss_hash_key;
2463         cmdline_fixed_string_t rss_type;
2464         cmdline_fixed_string_t key;
2465 };
2466
2467 static uint8_t
2468 hexa_digit_to_value(char hexa_digit)
2469 {
2470         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2471                 return (uint8_t) (hexa_digit - '0');
2472         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2473                 return (uint8_t) ((hexa_digit - 'a') + 10);
2474         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2475                 return (uint8_t) ((hexa_digit - 'A') + 10);
2476         /* Invalid hexa digit */
2477         return 0xFF;
2478 }
2479
2480 static uint8_t
2481 parse_and_check_key_hexa_digit(char *key, int idx)
2482 {
2483         uint8_t hexa_v;
2484
2485         hexa_v = hexa_digit_to_value(key[idx]);
2486         if (hexa_v == 0xFF)
2487                 printf("invalid key: character %c at position %d is not a "
2488                        "valid hexa digit\n", key[idx], idx);
2489         return hexa_v;
2490 }
2491
2492 static void
2493 cmd_config_rss_hash_key_parsed(void *parsed_result,
2494                                __rte_unused struct cmdline *cl,
2495                                __rte_unused void *data)
2496 {
2497         struct cmd_config_rss_hash_key *res = parsed_result;
2498         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2499         uint8_t xdgt0;
2500         uint8_t xdgt1;
2501         int i;
2502         struct rte_eth_dev_info dev_info;
2503         uint8_t hash_key_size;
2504         uint32_t key_len;
2505         int ret;
2506
2507         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2508         if (ret != 0)
2509                 return;
2510
2511         if (dev_info.hash_key_size > 0 &&
2512                         dev_info.hash_key_size <= sizeof(hash_key))
2513                 hash_key_size = dev_info.hash_key_size;
2514         else {
2515                 printf("dev_info did not provide a valid hash key size\n");
2516                 return;
2517         }
2518         /* Check the length of the RSS hash key */
2519         key_len = strlen(res->key);
2520         if (key_len != (hash_key_size * 2)) {
2521                 printf("key length: %d invalid - key must be a string of %d"
2522                            " hexa-decimal numbers\n",
2523                            (int) key_len, hash_key_size * 2);
2524                 return;
2525         }
2526         /* Translate RSS hash key into binary representation */
2527         for (i = 0; i < hash_key_size; i++) {
2528                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2529                 if (xdgt0 == 0xFF)
2530                         return;
2531                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2532                 if (xdgt1 == 0xFF)
2533                         return;
2534                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2535         }
2536         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2537                         hash_key_size);
2538 }
2539
2540 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2541         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2542 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2543         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2544                                  "config");
2545 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2546         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2547 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2548         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2549                                  rss_hash_key, "rss-hash-key");
2550 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2551         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2552                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2553                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2554                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2555                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2556                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2557                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2558                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2559 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2560         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2561
2562 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2563         .f = cmd_config_rss_hash_key_parsed,
2564         .data = NULL,
2565         .help_str = "port config <port_id> rss-hash-key "
2566                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2567                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2568                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2569                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2570                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2571                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2572                 "<string of hex digits (variable length, NIC dependent)>",
2573         .tokens = {
2574                 (void *)&cmd_config_rss_hash_key_port,
2575                 (void *)&cmd_config_rss_hash_key_config,
2576                 (void *)&cmd_config_rss_hash_key_port_id,
2577                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2578                 (void *)&cmd_config_rss_hash_key_rss_type,
2579                 (void *)&cmd_config_rss_hash_key_value,
2580                 NULL,
2581         },
2582 };
2583
2584 /* *** configure port rxq/txq ring size *** */
2585 struct cmd_config_rxtx_ring_size {
2586         cmdline_fixed_string_t port;
2587         cmdline_fixed_string_t config;
2588         portid_t portid;
2589         cmdline_fixed_string_t rxtxq;
2590         uint16_t qid;
2591         cmdline_fixed_string_t rsize;
2592         uint16_t size;
2593 };
2594
2595 static void
2596 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2597                                  __rte_unused struct cmdline *cl,
2598                                  __rte_unused void *data)
2599 {
2600         struct cmd_config_rxtx_ring_size *res = parsed_result;
2601         struct rte_port *port;
2602         uint8_t isrx;
2603
2604         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2605                 return;
2606
2607         if (res->portid == (portid_t)RTE_PORT_ALL) {
2608                 printf("Invalid port id\n");
2609                 return;
2610         }
2611
2612         port = &ports[res->portid];
2613
2614         if (!strcmp(res->rxtxq, "rxq"))
2615                 isrx = 1;
2616         else if (!strcmp(res->rxtxq, "txq"))
2617                 isrx = 0;
2618         else {
2619                 printf("Unknown parameter\n");
2620                 return;
2621         }
2622
2623         if (isrx && rx_queue_id_is_invalid(res->qid))
2624                 return;
2625         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2626                 return;
2627
2628         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2629                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2630                        rx_free_thresh);
2631                 return;
2632         }
2633
2634         if (isrx)
2635                 port->nb_rx_desc[res->qid] = res->size;
2636         else
2637                 port->nb_tx_desc[res->qid] = res->size;
2638
2639         cmd_reconfig_device_queue(res->portid, 0, 1);
2640 }
2641
2642 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2643         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2644                                  port, "port");
2645 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2646         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2647                                  config, "config");
2648 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2649         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2650                                  portid, UINT16);
2651 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2652         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2653                                  rxtxq, "rxq#txq");
2654 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2655         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2656                               qid, UINT16);
2657 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2658         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2659                                  rsize, "ring_size");
2660 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2661         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2662                               size, UINT16);
2663
2664 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2665         .f = cmd_config_rxtx_ring_size_parsed,
2666         .data = NULL,
2667         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2668         .tokens = {
2669                 (void *)&cmd_config_rxtx_ring_size_port,
2670                 (void *)&cmd_config_rxtx_ring_size_config,
2671                 (void *)&cmd_config_rxtx_ring_size_portid,
2672                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2673                 (void *)&cmd_config_rxtx_ring_size_qid,
2674                 (void *)&cmd_config_rxtx_ring_size_rsize,
2675                 (void *)&cmd_config_rxtx_ring_size_size,
2676                 NULL,
2677         },
2678 };
2679
2680 /* *** configure port rxq/txq start/stop *** */
2681 struct cmd_config_rxtx_queue {
2682         cmdline_fixed_string_t port;
2683         portid_t portid;
2684         cmdline_fixed_string_t rxtxq;
2685         uint16_t qid;
2686         cmdline_fixed_string_t opname;
2687 };
2688
2689 static void
2690 cmd_config_rxtx_queue_parsed(void *parsed_result,
2691                         __rte_unused struct cmdline *cl,
2692                         __rte_unused void *data)
2693 {
2694         struct cmd_config_rxtx_queue *res = parsed_result;
2695         uint8_t isrx;
2696         uint8_t isstart;
2697         int ret = 0;
2698
2699         if (test_done == 0) {
2700                 printf("Please stop forwarding first\n");
2701                 return;
2702         }
2703
2704         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2705                 return;
2706
2707         if (port_is_started(res->portid) != 1) {
2708                 printf("Please start port %u first\n", res->portid);
2709                 return;
2710         }
2711
2712         if (!strcmp(res->rxtxq, "rxq"))
2713                 isrx = 1;
2714         else if (!strcmp(res->rxtxq, "txq"))
2715                 isrx = 0;
2716         else {
2717                 printf("Unknown parameter\n");
2718                 return;
2719         }
2720
2721         if (isrx && rx_queue_id_is_invalid(res->qid))
2722                 return;
2723         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2724                 return;
2725
2726         if (!strcmp(res->opname, "start"))
2727                 isstart = 1;
2728         else if (!strcmp(res->opname, "stop"))
2729                 isstart = 0;
2730         else {
2731                 printf("Unknown parameter\n");
2732                 return;
2733         }
2734
2735         if (isstart && isrx)
2736                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2737         else if (!isstart && isrx)
2738                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2739         else if (isstart && !isrx)
2740                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2741         else
2742                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2743
2744         if (ret == -ENOTSUP)
2745                 printf("Function not supported in PMD driver\n");
2746 }
2747
2748 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2749         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2750 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2751         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2752 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2753         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2754 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2755         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2756 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2757         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2758                                                 "start#stop");
2759
2760 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2761         .f = cmd_config_rxtx_queue_parsed,
2762         .data = NULL,
2763         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2764         .tokens = {
2765                 (void *)&cmd_config_rxtx_queue_port,
2766                 (void *)&cmd_config_rxtx_queue_portid,
2767                 (void *)&cmd_config_rxtx_queue_rxtxq,
2768                 (void *)&cmd_config_rxtx_queue_qid,
2769                 (void *)&cmd_config_rxtx_queue_opname,
2770                 NULL,
2771         },
2772 };
2773
2774 /* *** configure port rxq/txq deferred start on/off *** */
2775 struct cmd_config_deferred_start_rxtx_queue {
2776         cmdline_fixed_string_t port;
2777         portid_t port_id;
2778         cmdline_fixed_string_t rxtxq;
2779         uint16_t qid;
2780         cmdline_fixed_string_t opname;
2781         cmdline_fixed_string_t state;
2782 };
2783
2784 static void
2785 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2786                         __rte_unused struct cmdline *cl,
2787                         __rte_unused void *data)
2788 {
2789         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2790         struct rte_port *port;
2791         uint8_t isrx;
2792         uint8_t ison;
2793         uint8_t needreconfig = 0;
2794
2795         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2796                 return;
2797
2798         if (port_is_started(res->port_id) != 0) {
2799                 printf("Please stop port %u first\n", res->port_id);
2800                 return;
2801         }
2802
2803         port = &ports[res->port_id];
2804
2805         isrx = !strcmp(res->rxtxq, "rxq");
2806
2807         if (isrx && rx_queue_id_is_invalid(res->qid))
2808                 return;
2809         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2810                 return;
2811
2812         ison = !strcmp(res->state, "on");
2813
2814         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2815                 port->rx_conf[res->qid].rx_deferred_start = ison;
2816                 needreconfig = 1;
2817         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2818                 port->tx_conf[res->qid].tx_deferred_start = ison;
2819                 needreconfig = 1;
2820         }
2821
2822         if (needreconfig)
2823                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2824 }
2825
2826 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2827         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2828                                                 port, "port");
2829 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2830         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2831                                                 port_id, UINT16);
2832 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2833         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2834                                                 rxtxq, "rxq#txq");
2835 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2836         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2837                                                 qid, UINT16);
2838 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2839         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2840                                                 opname, "deferred_start");
2841 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2842         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2843                                                 state, "on#off");
2844
2845 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2846         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2847         .data = NULL,
2848         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2849         .tokens = {
2850                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2851                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2852                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2853                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2854                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2855                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2856                 NULL,
2857         },
2858 };
2859
2860 /* *** configure port rxq/txq setup *** */
2861 struct cmd_setup_rxtx_queue {
2862         cmdline_fixed_string_t port;
2863         portid_t portid;
2864         cmdline_fixed_string_t rxtxq;
2865         uint16_t qid;
2866         cmdline_fixed_string_t setup;
2867 };
2868
2869 /* Common CLI fields for queue setup */
2870 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2871         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2872 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2873         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2874 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2875         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2876 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2877         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2878 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2879         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2880
2881 static void
2882 cmd_setup_rxtx_queue_parsed(
2883         void *parsed_result,
2884         __rte_unused struct cmdline *cl,
2885         __rte_unused void *data)
2886 {
2887         struct cmd_setup_rxtx_queue *res = parsed_result;
2888         struct rte_port *port;
2889         struct rte_mempool *mp;
2890         unsigned int socket_id;
2891         uint8_t isrx = 0;
2892         int ret;
2893
2894         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2895                 return;
2896
2897         if (res->portid == (portid_t)RTE_PORT_ALL) {
2898                 printf("Invalid port id\n");
2899                 return;
2900         }
2901
2902         if (!strcmp(res->rxtxq, "rxq"))
2903                 isrx = 1;
2904         else if (!strcmp(res->rxtxq, "txq"))
2905                 isrx = 0;
2906         else {
2907                 printf("Unknown parameter\n");
2908                 return;
2909         }
2910
2911         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2912                 printf("Invalid rx queue\n");
2913                 return;
2914         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2915                 printf("Invalid tx queue\n");
2916                 return;
2917         }
2918
2919         port = &ports[res->portid];
2920         if (isrx) {
2921                 socket_id = rxring_numa[res->portid];
2922                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2923                         socket_id = port->socket_id;
2924
2925                 mp = mbuf_pool_find(socket_id, 0);
2926                 if (mp == NULL) {
2927                         printf("Failed to setup RX queue: "
2928                                 "No mempool allocation"
2929                                 " on the socket %d\n",
2930                                 rxring_numa[res->portid]);
2931                         return;
2932                 }
2933                 ret = rx_queue_setup(res->portid,
2934                                      res->qid,
2935                                      port->nb_rx_desc[res->qid],
2936                                      socket_id,
2937                                      &port->rx_conf[res->qid],
2938                                      mp);
2939                 if (ret)
2940                         printf("Failed to setup RX queue\n");
2941         } else {
2942                 socket_id = txring_numa[res->portid];
2943                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2944                         socket_id = port->socket_id;
2945
2946                 ret = rte_eth_tx_queue_setup(res->portid,
2947                                              res->qid,
2948                                              port->nb_tx_desc[res->qid],
2949                                              socket_id,
2950                                              &port->tx_conf[res->qid]);
2951                 if (ret)
2952                         printf("Failed to setup TX queue\n");
2953         }
2954 }
2955
2956 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2957         .f = cmd_setup_rxtx_queue_parsed,
2958         .data = NULL,
2959         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2960         .tokens = {
2961                 (void *)&cmd_setup_rxtx_queue_port,
2962                 (void *)&cmd_setup_rxtx_queue_portid,
2963                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2964                 (void *)&cmd_setup_rxtx_queue_qid,
2965                 (void *)&cmd_setup_rxtx_queue_setup,
2966                 NULL,
2967         },
2968 };
2969
2970
2971 /* *** Configure RSS RETA *** */
2972 struct cmd_config_rss_reta {
2973         cmdline_fixed_string_t port;
2974         cmdline_fixed_string_t keyword;
2975         portid_t port_id;
2976         cmdline_fixed_string_t name;
2977         cmdline_fixed_string_t list_name;
2978         cmdline_fixed_string_t list_of_items;
2979 };
2980
2981 static int
2982 parse_reta_config(const char *str,
2983                   struct rte_eth_rss_reta_entry64 *reta_conf,
2984                   uint16_t nb_entries)
2985 {
2986         int i;
2987         unsigned size;
2988         uint16_t hash_index, idx, shift;
2989         uint16_t nb_queue;
2990         char s[256];
2991         const char *p, *p0 = str;
2992         char *end;
2993         enum fieldnames {
2994                 FLD_HASH_INDEX = 0,
2995                 FLD_QUEUE,
2996                 _NUM_FLD
2997         };
2998         unsigned long int_fld[_NUM_FLD];
2999         char *str_fld[_NUM_FLD];
3000
3001         while ((p = strchr(p0,'(')) != NULL) {
3002                 ++p;
3003                 if((p0 = strchr(p,')')) == NULL)
3004                         return -1;
3005
3006                 size = p0 - p;
3007                 if(size >= sizeof(s))
3008                         return -1;
3009
3010                 snprintf(s, sizeof(s), "%.*s", size, p);
3011                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
3012                         return -1;
3013                 for (i = 0; i < _NUM_FLD; i++) {
3014                         errno = 0;
3015                         int_fld[i] = strtoul(str_fld[i], &end, 0);
3016                         if (errno != 0 || end == str_fld[i] ||
3017                                         int_fld[i] > 65535)
3018                                 return -1;
3019                 }
3020
3021                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
3022                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
3023
3024                 if (hash_index >= nb_entries) {
3025                         printf("Invalid RETA hash index=%d\n", hash_index);
3026                         return -1;
3027                 }
3028
3029                 idx = hash_index / RTE_RETA_GROUP_SIZE;
3030                 shift = hash_index % RTE_RETA_GROUP_SIZE;
3031                 reta_conf[idx].mask |= (1ULL << shift);
3032                 reta_conf[idx].reta[shift] = nb_queue;
3033         }
3034
3035         return 0;
3036 }
3037
3038 static void
3039 cmd_set_rss_reta_parsed(void *parsed_result,
3040                         __rte_unused struct cmdline *cl,
3041                         __rte_unused void *data)
3042 {
3043         int ret;
3044         struct rte_eth_dev_info dev_info;
3045         struct rte_eth_rss_reta_entry64 reta_conf[8];
3046         struct cmd_config_rss_reta *res = parsed_result;
3047
3048         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3049         if (ret != 0)
3050                 return;
3051
3052         if (dev_info.reta_size == 0) {
3053                 printf("Redirection table size is 0 which is "
3054                                         "invalid for RSS\n");
3055                 return;
3056         } else
3057                 printf("The reta size of port %d is %u\n",
3058                         res->port_id, dev_info.reta_size);
3059         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3060                 printf("Currently do not support more than %u entries of "
3061                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3062                 return;
3063         }
3064
3065         memset(reta_conf, 0, sizeof(reta_conf));
3066         if (!strcmp(res->list_name, "reta")) {
3067                 if (parse_reta_config(res->list_of_items, reta_conf,
3068                                                 dev_info.reta_size)) {
3069                         printf("Invalid RSS Redirection Table "
3070                                         "config entered\n");
3071                         return;
3072                 }
3073                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3074                                 reta_conf, dev_info.reta_size);
3075                 if (ret != 0)
3076                         printf("Bad redirection table parameter, "
3077                                         "return code = %d \n", ret);
3078         }
3079 }
3080
3081 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3082         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3083 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3084         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3085 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3086         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3087 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3088         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3089 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3090         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3091 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3092         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3093                                  NULL);
3094 cmdline_parse_inst_t cmd_config_rss_reta = {
3095         .f = cmd_set_rss_reta_parsed,
3096         .data = NULL,
3097         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3098         .tokens = {
3099                 (void *)&cmd_config_rss_reta_port,
3100                 (void *)&cmd_config_rss_reta_keyword,
3101                 (void *)&cmd_config_rss_reta_port_id,
3102                 (void *)&cmd_config_rss_reta_name,
3103                 (void *)&cmd_config_rss_reta_list_name,
3104                 (void *)&cmd_config_rss_reta_list_of_items,
3105                 NULL,
3106         },
3107 };
3108
3109 /* *** SHOW PORT RETA INFO *** */
3110 struct cmd_showport_reta {
3111         cmdline_fixed_string_t show;
3112         cmdline_fixed_string_t port;
3113         portid_t port_id;
3114         cmdline_fixed_string_t rss;
3115         cmdline_fixed_string_t reta;
3116         uint16_t size;
3117         cmdline_fixed_string_t list_of_items;
3118 };
3119
3120 static int
3121 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3122                            uint16_t nb_entries,
3123                            char *str)
3124 {
3125         uint32_t size;
3126         const char *p, *p0 = str;
3127         char s[256];
3128         char *end;
3129         char *str_fld[8];
3130         uint16_t i;
3131         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3132                         RTE_RETA_GROUP_SIZE;
3133         int ret;
3134
3135         p = strchr(p0, '(');
3136         if (p == NULL)
3137                 return -1;
3138         p++;
3139         p0 = strchr(p, ')');
3140         if (p0 == NULL)
3141                 return -1;
3142         size = p0 - p;
3143         if (size >= sizeof(s)) {
3144                 printf("The string size exceeds the internal buffer size\n");
3145                 return -1;
3146         }
3147         snprintf(s, sizeof(s), "%.*s", size, p);
3148         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3149         if (ret <= 0 || ret != num) {
3150                 printf("The bits of masks do not match the number of "
3151                                         "reta entries: %u\n", num);
3152                 return -1;
3153         }
3154         for (i = 0; i < ret; i++)
3155                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3156
3157         return 0;
3158 }
3159
3160 static void
3161 cmd_showport_reta_parsed(void *parsed_result,
3162                          __rte_unused struct cmdline *cl,
3163                          __rte_unused void *data)
3164 {
3165         struct cmd_showport_reta *res = parsed_result;
3166         struct rte_eth_rss_reta_entry64 reta_conf[8];
3167         struct rte_eth_dev_info dev_info;
3168         uint16_t max_reta_size;
3169         int ret;
3170
3171         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3172         if (ret != 0)
3173                 return;
3174
3175         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3176         if (res->size == 0 || res->size > max_reta_size) {
3177                 printf("Invalid redirection table size: %u (1-%u)\n",
3178                         res->size, max_reta_size);
3179                 return;
3180         }
3181
3182         memset(reta_conf, 0, sizeof(reta_conf));
3183         if (showport_parse_reta_config(reta_conf, res->size,
3184                                 res->list_of_items) < 0) {
3185                 printf("Invalid string: %s for reta masks\n",
3186                                         res->list_of_items);
3187                 return;
3188         }
3189         port_rss_reta_info(res->port_id, reta_conf, res->size);
3190 }
3191
3192 cmdline_parse_token_string_t cmd_showport_reta_show =
3193         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3194 cmdline_parse_token_string_t cmd_showport_reta_port =
3195         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3196 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3197         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3198 cmdline_parse_token_string_t cmd_showport_reta_rss =
3199         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3200 cmdline_parse_token_string_t cmd_showport_reta_reta =
3201         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3202 cmdline_parse_token_num_t cmd_showport_reta_size =
3203         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3204 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3205         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3206                                         list_of_items, NULL);
3207
3208 cmdline_parse_inst_t cmd_showport_reta = {
3209         .f = cmd_showport_reta_parsed,
3210         .data = NULL,
3211         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3212         .tokens = {
3213                 (void *)&cmd_showport_reta_show,
3214                 (void *)&cmd_showport_reta_port,
3215                 (void *)&cmd_showport_reta_port_id,
3216                 (void *)&cmd_showport_reta_rss,
3217                 (void *)&cmd_showport_reta_reta,
3218                 (void *)&cmd_showport_reta_size,
3219                 (void *)&cmd_showport_reta_list_of_items,
3220                 NULL,
3221         },
3222 };
3223
3224 /* *** Show RSS hash configuration *** */
3225 struct cmd_showport_rss_hash {
3226         cmdline_fixed_string_t show;
3227         cmdline_fixed_string_t port;
3228         portid_t port_id;
3229         cmdline_fixed_string_t rss_hash;
3230         cmdline_fixed_string_t rss_type;
3231         cmdline_fixed_string_t key; /* optional argument */
3232 };
3233
3234 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3235                                 __rte_unused struct cmdline *cl,
3236                                 void *show_rss_key)
3237 {
3238         struct cmd_showport_rss_hash *res = parsed_result;
3239
3240         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3241 }
3242
3243 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3244         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3245 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3246         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3247 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3248         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3249 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3250         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3251                                  "rss-hash");
3252 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3253         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3254
3255 cmdline_parse_inst_t cmd_showport_rss_hash = {
3256         .f = cmd_showport_rss_hash_parsed,
3257         .data = NULL,
3258         .help_str = "show port <port_id> rss-hash",
3259         .tokens = {
3260                 (void *)&cmd_showport_rss_hash_show,
3261                 (void *)&cmd_showport_rss_hash_port,
3262                 (void *)&cmd_showport_rss_hash_port_id,
3263                 (void *)&cmd_showport_rss_hash_rss_hash,
3264                 NULL,
3265         },
3266 };
3267
3268 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3269         .f = cmd_showport_rss_hash_parsed,
3270         .data = (void *)1,
3271         .help_str = "show port <port_id> rss-hash key",
3272         .tokens = {
3273                 (void *)&cmd_showport_rss_hash_show,
3274                 (void *)&cmd_showport_rss_hash_port,
3275                 (void *)&cmd_showport_rss_hash_port_id,
3276                 (void *)&cmd_showport_rss_hash_rss_hash,
3277                 (void *)&cmd_showport_rss_hash_rss_key,
3278                 NULL,
3279         },
3280 };
3281
3282 /* *** Configure DCB *** */
3283 struct cmd_config_dcb {
3284         cmdline_fixed_string_t port;
3285         cmdline_fixed_string_t config;
3286         portid_t port_id;
3287         cmdline_fixed_string_t dcb;
3288         cmdline_fixed_string_t vt;
3289         cmdline_fixed_string_t vt_en;
3290         uint8_t num_tcs;
3291         cmdline_fixed_string_t pfc;
3292         cmdline_fixed_string_t pfc_en;
3293 };
3294
3295 static void
3296 cmd_config_dcb_parsed(void *parsed_result,
3297                         __rte_unused struct cmdline *cl,
3298                         __rte_unused void *data)
3299 {
3300         struct cmd_config_dcb *res = parsed_result;
3301         portid_t port_id = res->port_id;
3302         struct rte_port *port;
3303         uint8_t pfc_en;
3304         int ret;
3305
3306         port = &ports[port_id];
3307         /** Check if the port is not started **/
3308         if (port->port_status != RTE_PORT_STOPPED) {
3309                 printf("Please stop port %d first\n", port_id);
3310                 return;
3311         }
3312
3313         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3314                 printf("The invalid number of traffic class,"
3315                         " only 4 or 8 allowed.\n");
3316                 return;
3317         }
3318
3319         if (nb_fwd_lcores < res->num_tcs) {
3320                 printf("nb_cores shouldn't be less than number of TCs.\n");
3321                 return;
3322         }
3323         if (!strncmp(res->pfc_en, "on", 2))
3324                 pfc_en = 1;
3325         else
3326                 pfc_en = 0;
3327
3328         /* DCB in VT mode */
3329         if (!strncmp(res->vt_en, "on", 2))
3330                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3331                                 (enum rte_eth_nb_tcs)res->num_tcs,
3332                                 pfc_en);
3333         else
3334                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3335                                 (enum rte_eth_nb_tcs)res->num_tcs,
3336                                 pfc_en);
3337
3338
3339         if (ret != 0) {
3340                 printf("Cannot initialize network ports.\n");
3341                 return;
3342         }
3343
3344         cmd_reconfig_device_queue(port_id, 1, 1);
3345 }
3346
3347 cmdline_parse_token_string_t cmd_config_dcb_port =
3348         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3349 cmdline_parse_token_string_t cmd_config_dcb_config =
3350         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3351 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3352         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3353 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3354         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3355 cmdline_parse_token_string_t cmd_config_dcb_vt =
3356         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3357 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3358         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3359 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3360         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3361 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3362         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3363 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3364         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3365
3366 cmdline_parse_inst_t cmd_config_dcb = {
3367         .f = cmd_config_dcb_parsed,
3368         .data = NULL,
3369         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3370         .tokens = {
3371                 (void *)&cmd_config_dcb_port,
3372                 (void *)&cmd_config_dcb_config,
3373                 (void *)&cmd_config_dcb_port_id,
3374                 (void *)&cmd_config_dcb_dcb,
3375                 (void *)&cmd_config_dcb_vt,
3376                 (void *)&cmd_config_dcb_vt_en,
3377                 (void *)&cmd_config_dcb_num_tcs,
3378                 (void *)&cmd_config_dcb_pfc,
3379                 (void *)&cmd_config_dcb_pfc_en,
3380                 NULL,
3381         },
3382 };
3383
3384 /* *** configure number of packets per burst *** */
3385 struct cmd_config_burst {
3386         cmdline_fixed_string_t port;
3387         cmdline_fixed_string_t keyword;
3388         cmdline_fixed_string_t all;
3389         cmdline_fixed_string_t name;
3390         uint16_t value;
3391 };
3392
3393 static void
3394 cmd_config_burst_parsed(void *parsed_result,
3395                         __rte_unused struct cmdline *cl,
3396                         __rte_unused void *data)
3397 {
3398         struct cmd_config_burst *res = parsed_result;
3399         struct rte_eth_dev_info dev_info;
3400         uint16_t rec_nb_pkts;
3401         int ret;
3402
3403         if (!all_ports_stopped()) {
3404                 printf("Please stop all ports first\n");
3405                 return;
3406         }
3407
3408         if (!strcmp(res->name, "burst")) {
3409                 if (res->value == 0) {
3410                         /* If user gives a value of zero, query the PMD for
3411                          * its recommended Rx burst size. Testpmd uses a single
3412                          * size for all ports, so assume all ports are the same
3413                          * NIC model and use the values from Port 0.
3414                          */
3415                         ret = eth_dev_info_get_print_err(0, &dev_info);
3416                         if (ret != 0)
3417                                 return;
3418
3419                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3420
3421                         if (rec_nb_pkts == 0) {
3422                                 printf("PMD does not recommend a burst size.\n"
3423                                         "User provided value must be between"
3424                                         " 1 and %d\n", MAX_PKT_BURST);
3425                                 return;
3426                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3427                                 printf("PMD recommended burst size of %d"
3428                                         " exceeds maximum value of %d\n",
3429                                         rec_nb_pkts, MAX_PKT_BURST);
3430                                 return;
3431                         }
3432                         printf("Using PMD-provided burst value of %d\n",
3433                                 rec_nb_pkts);
3434                         nb_pkt_per_burst = rec_nb_pkts;
3435                 } else if (res->value > MAX_PKT_BURST) {
3436                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3437                         return;
3438                 } else
3439                         nb_pkt_per_burst = res->value;
3440         } else {
3441                 printf("Unknown parameter\n");
3442                 return;
3443         }
3444
3445         init_port_config();
3446
3447         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3448 }
3449
3450 cmdline_parse_token_string_t cmd_config_burst_port =
3451         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3452 cmdline_parse_token_string_t cmd_config_burst_keyword =
3453         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3454 cmdline_parse_token_string_t cmd_config_burst_all =
3455         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3456 cmdline_parse_token_string_t cmd_config_burst_name =
3457         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3458 cmdline_parse_token_num_t cmd_config_burst_value =
3459         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3460
3461 cmdline_parse_inst_t cmd_config_burst = {
3462         .f = cmd_config_burst_parsed,
3463         .data = NULL,
3464         .help_str = "port config all burst <value>",
3465         .tokens = {
3466                 (void *)&cmd_config_burst_port,
3467                 (void *)&cmd_config_burst_keyword,
3468                 (void *)&cmd_config_burst_all,
3469                 (void *)&cmd_config_burst_name,
3470                 (void *)&cmd_config_burst_value,
3471                 NULL,
3472         },
3473 };
3474
3475 /* *** configure rx/tx queues *** */
3476 struct cmd_config_thresh {
3477         cmdline_fixed_string_t port;
3478         cmdline_fixed_string_t keyword;
3479         cmdline_fixed_string_t all;
3480         cmdline_fixed_string_t name;
3481         uint8_t value;
3482 };
3483
3484 static void
3485 cmd_config_thresh_parsed(void *parsed_result,
3486                         __rte_unused struct cmdline *cl,
3487                         __rte_unused void *data)
3488 {
3489         struct cmd_config_thresh *res = parsed_result;
3490
3491         if (!all_ports_stopped()) {
3492                 printf("Please stop all ports first\n");
3493                 return;
3494         }
3495
3496         if (!strcmp(res->name, "txpt"))
3497                 tx_pthresh = res->value;
3498         else if(!strcmp(res->name, "txht"))
3499                 tx_hthresh = res->value;
3500         else if(!strcmp(res->name, "txwt"))
3501                 tx_wthresh = res->value;
3502         else if(!strcmp(res->name, "rxpt"))
3503                 rx_pthresh = res->value;
3504         else if(!strcmp(res->name, "rxht"))
3505                 rx_hthresh = res->value;
3506         else if(!strcmp(res->name, "rxwt"))
3507                 rx_wthresh = res->value;
3508         else {
3509                 printf("Unknown parameter\n");
3510                 return;
3511         }
3512
3513         init_port_config();
3514
3515         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3516 }
3517
3518 cmdline_parse_token_string_t cmd_config_thresh_port =
3519         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3520 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3521         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3522 cmdline_parse_token_string_t cmd_config_thresh_all =
3523         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3524 cmdline_parse_token_string_t cmd_config_thresh_name =
3525         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3526                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3527 cmdline_parse_token_num_t cmd_config_thresh_value =
3528         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3529
3530 cmdline_parse_inst_t cmd_config_thresh = {
3531         .f = cmd_config_thresh_parsed,
3532         .data = NULL,
3533         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3534         .tokens = {
3535                 (void *)&cmd_config_thresh_port,
3536                 (void *)&cmd_config_thresh_keyword,
3537                 (void *)&cmd_config_thresh_all,
3538                 (void *)&cmd_config_thresh_name,
3539                 (void *)&cmd_config_thresh_value,
3540                 NULL,
3541         },
3542 };
3543
3544 /* *** configure free/rs threshold *** */
3545 struct cmd_config_threshold {
3546         cmdline_fixed_string_t port;
3547         cmdline_fixed_string_t keyword;
3548         cmdline_fixed_string_t all;
3549         cmdline_fixed_string_t name;
3550         uint16_t value;
3551 };
3552
3553 static void
3554 cmd_config_threshold_parsed(void *parsed_result,
3555                         __rte_unused struct cmdline *cl,
3556                         __rte_unused void *data)
3557 {
3558         struct cmd_config_threshold *res = parsed_result;
3559
3560         if (!all_ports_stopped()) {
3561                 printf("Please stop all ports first\n");
3562                 return;
3563         }
3564
3565         if (!strcmp(res->name, "txfreet"))
3566                 tx_free_thresh = res->value;
3567         else if (!strcmp(res->name, "txrst"))
3568                 tx_rs_thresh = res->value;
3569         else if (!strcmp(res->name, "rxfreet"))
3570                 rx_free_thresh = res->value;
3571         else {
3572                 printf("Unknown parameter\n");
3573                 return;
3574         }
3575
3576         init_port_config();
3577
3578         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3579 }
3580
3581 cmdline_parse_token_string_t cmd_config_threshold_port =
3582         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3583 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3584         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3585                                                                 "config");
3586 cmdline_parse_token_string_t cmd_config_threshold_all =
3587         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3588 cmdline_parse_token_string_t cmd_config_threshold_name =
3589         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3590                                                 "txfreet#txrst#rxfreet");
3591 cmdline_parse_token_num_t cmd_config_threshold_value =
3592         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3593
3594 cmdline_parse_inst_t cmd_config_threshold = {
3595         .f = cmd_config_threshold_parsed,
3596         .data = NULL,
3597         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3598         .tokens = {
3599                 (void *)&cmd_config_threshold_port,
3600                 (void *)&cmd_config_threshold_keyword,
3601                 (void *)&cmd_config_threshold_all,
3602                 (void *)&cmd_config_threshold_name,
3603                 (void *)&cmd_config_threshold_value,
3604                 NULL,
3605         },
3606 };
3607
3608 /* *** stop *** */
3609 struct cmd_stop_result {
3610         cmdline_fixed_string_t stop;
3611 };
3612
3613 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3614                             __rte_unused struct cmdline *cl,
3615                             __rte_unused void *data)
3616 {
3617         stop_packet_forwarding();
3618 }
3619
3620 cmdline_parse_token_string_t cmd_stop_stop =
3621         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3622
3623 cmdline_parse_inst_t cmd_stop = {
3624         .f = cmd_stop_parsed,
3625         .data = NULL,
3626         .help_str = "stop: Stop packet forwarding",
3627         .tokens = {
3628                 (void *)&cmd_stop_stop,
3629                 NULL,
3630         },
3631 };
3632
3633 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3634
3635 unsigned int
3636 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3637                 unsigned int *parsed_items, int check_unique_values)
3638 {
3639         unsigned int nb_item;
3640         unsigned int value;
3641         unsigned int i;
3642         unsigned int j;
3643         int value_ok;
3644         char c;
3645
3646         /*
3647          * First parse all items in the list and store their value.
3648          */
3649         value = 0;
3650         nb_item = 0;
3651         value_ok = 0;
3652         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3653                 c = str[i];
3654                 if ((c >= '0') && (c <= '9')) {
3655                         value = (unsigned int) (value * 10 + (c - '0'));
3656                         value_ok = 1;
3657                         continue;
3658                 }
3659                 if (c != ',') {
3660                         printf("character %c is not a decimal digit\n", c);
3661                         return 0;
3662                 }
3663                 if (! value_ok) {
3664                         printf("No valid value before comma\n");
3665                         return 0;
3666                 }
3667                 if (nb_item < max_items) {
3668                         parsed_items[nb_item] = value;
3669                         value_ok = 0;
3670                         value = 0;
3671                 }
3672                 nb_item++;
3673         }
3674         if (nb_item >= max_items) {
3675                 printf("Number of %s = %u > %u (maximum items)\n",
3676                        item_name, nb_item + 1, max_items);
3677                 return 0;
3678         }
3679         parsed_items[nb_item++] = value;
3680         if (! check_unique_values)
3681                 return nb_item;
3682
3683         /*
3684          * Then, check that all values in the list are differents.
3685          * No optimization here...
3686          */
3687         for (i = 0; i < nb_item; i++) {
3688                 for (j = i + 1; j < nb_item; j++) {
3689                         if (parsed_items[j] == parsed_items[i]) {
3690                                 printf("duplicated %s %u at index %u and %u\n",
3691                                        item_name, parsed_items[i], i, j);
3692                                 return 0;
3693                         }
3694                 }
3695         }
3696         return nb_item;
3697 }
3698
3699 struct cmd_set_list_result {
3700         cmdline_fixed_string_t cmd_keyword;
3701         cmdline_fixed_string_t list_name;
3702         cmdline_fixed_string_t list_of_items;
3703 };
3704
3705 static void cmd_set_list_parsed(void *parsed_result,
3706                                 __rte_unused struct cmdline *cl,
3707                                 __rte_unused void *data)
3708 {
3709         struct cmd_set_list_result *res;
3710         union {
3711                 unsigned int lcorelist[RTE_MAX_LCORE];
3712                 unsigned int portlist[RTE_MAX_ETHPORTS];
3713         } parsed_items;
3714         unsigned int nb_item;
3715
3716         if (test_done == 0) {
3717                 printf("Please stop forwarding first\n");
3718                 return;
3719         }
3720
3721         res = parsed_result;
3722         if (!strcmp(res->list_name, "corelist")) {
3723                 nb_item = parse_item_list(res->list_of_items, "core",
3724                                           RTE_MAX_LCORE,
3725                                           parsed_items.lcorelist, 1);
3726                 if (nb_item > 0) {
3727                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3728                         fwd_config_setup();
3729                 }
3730                 return;
3731         }
3732         if (!strcmp(res->list_name, "portlist")) {
3733                 nb_item = parse_item_list(res->list_of_items, "port",
3734                                           RTE_MAX_ETHPORTS,
3735                                           parsed_items.portlist, 1);
3736                 if (nb_item > 0) {
3737                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3738                         fwd_config_setup();
3739                 }
3740         }
3741 }
3742
3743 cmdline_parse_token_string_t cmd_set_list_keyword =
3744         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3745                                  "set");
3746 cmdline_parse_token_string_t cmd_set_list_name =
3747         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3748                                  "corelist#portlist");
3749 cmdline_parse_token_string_t cmd_set_list_of_items =
3750         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3751                                  NULL);
3752
3753 cmdline_parse_inst_t cmd_set_fwd_list = {
3754         .f = cmd_set_list_parsed,
3755         .data = NULL,
3756         .help_str = "set corelist|portlist <list0[,list1]*>",
3757         .tokens = {
3758                 (void *)&cmd_set_list_keyword,
3759                 (void *)&cmd_set_list_name,
3760                 (void *)&cmd_set_list_of_items,
3761                 NULL,
3762         },
3763 };
3764
3765 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3766
3767 struct cmd_setmask_result {
3768         cmdline_fixed_string_t set;
3769         cmdline_fixed_string_t mask;
3770         uint64_t hexavalue;
3771 };
3772
3773 static void cmd_set_mask_parsed(void *parsed_result,
3774                                 __rte_unused struct cmdline *cl,
3775                                 __rte_unused void *data)
3776 {
3777         struct cmd_setmask_result *res = parsed_result;
3778
3779         if (test_done == 0) {
3780                 printf("Please stop forwarding first\n");
3781                 return;
3782         }
3783         if (!strcmp(res->mask, "coremask")) {
3784                 set_fwd_lcores_mask(res->hexavalue);
3785                 fwd_config_setup();
3786         } else if (!strcmp(res->mask, "portmask")) {
3787                 set_fwd_ports_mask(res->hexavalue);
3788                 fwd_config_setup();
3789         }
3790 }
3791
3792 cmdline_parse_token_string_t cmd_setmask_set =
3793         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3794 cmdline_parse_token_string_t cmd_setmask_mask =
3795         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3796                                  "coremask#portmask");
3797 cmdline_parse_token_num_t cmd_setmask_value =
3798         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3799
3800 cmdline_parse_inst_t cmd_set_fwd_mask = {
3801         .f = cmd_set_mask_parsed,
3802         .data = NULL,
3803         .help_str = "set coremask|portmask <hexadecimal value>",
3804         .tokens = {
3805                 (void *)&cmd_setmask_set,
3806                 (void *)&cmd_setmask_mask,
3807                 (void *)&cmd_setmask_value,
3808                 NULL,
3809         },
3810 };
3811
3812 /*
3813  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3814  */
3815 struct cmd_set_result {
3816         cmdline_fixed_string_t set;
3817         cmdline_fixed_string_t what;
3818         uint16_t value;
3819 };
3820
3821 static void cmd_set_parsed(void *parsed_result,
3822                            __rte_unused struct cmdline *cl,
3823                            __rte_unused void *data)
3824 {
3825         struct cmd_set_result *res = parsed_result;
3826         if (!strcmp(res->what, "nbport")) {
3827                 set_fwd_ports_number(res->value);
3828                 fwd_config_setup();
3829         } else if (!strcmp(res->what, "nbcore")) {
3830                 set_fwd_lcores_number(res->value);
3831                 fwd_config_setup();
3832         } else if (!strcmp(res->what, "burst"))
3833                 set_nb_pkt_per_burst(res->value);
3834         else if (!strcmp(res->what, "verbose"))
3835                 set_verbose_level(res->value);
3836 }
3837
3838 cmdline_parse_token_string_t cmd_set_set =
3839         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3840 cmdline_parse_token_string_t cmd_set_what =
3841         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3842                                  "nbport#nbcore#burst#verbose");
3843 cmdline_parse_token_num_t cmd_set_value =
3844         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3845
3846 cmdline_parse_inst_t cmd_set_numbers = {
3847         .f = cmd_set_parsed,
3848         .data = NULL,
3849         .help_str = "set nbport|nbcore|burst|verbose <value>",
3850         .tokens = {
3851                 (void *)&cmd_set_set,
3852                 (void *)&cmd_set_what,
3853                 (void *)&cmd_set_value,
3854                 NULL,
3855         },
3856 };
3857
3858 /* *** SET LOG LEVEL CONFIGURATION *** */
3859
3860 struct cmd_set_log_result {
3861         cmdline_fixed_string_t set;
3862         cmdline_fixed_string_t log;
3863         cmdline_fixed_string_t type;
3864         uint32_t level;
3865 };
3866
3867 static void
3868 cmd_set_log_parsed(void *parsed_result,
3869                    __rte_unused struct cmdline *cl,
3870                    __rte_unused void *data)
3871 {
3872         struct cmd_set_log_result *res;
3873         int ret;
3874
3875         res = parsed_result;
3876         if (!strcmp(res->type, "global"))
3877                 rte_log_set_global_level(res->level);
3878         else {
3879                 ret = rte_log_set_level_regexp(res->type, res->level);
3880                 if (ret < 0)
3881                         printf("Unable to set log level\n");
3882         }
3883 }
3884
3885 cmdline_parse_token_string_t cmd_set_log_set =
3886         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3887 cmdline_parse_token_string_t cmd_set_log_log =
3888         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3889 cmdline_parse_token_string_t cmd_set_log_type =
3890         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3891 cmdline_parse_token_num_t cmd_set_log_level =
3892         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3893
3894 cmdline_parse_inst_t cmd_set_log = {
3895         .f = cmd_set_log_parsed,
3896         .data = NULL,
3897         .help_str = "set log global|<type> <level>",
3898         .tokens = {
3899                 (void *)&cmd_set_log_set,
3900                 (void *)&cmd_set_log_log,
3901                 (void *)&cmd_set_log_type,
3902                 (void *)&cmd_set_log_level,
3903                 NULL,
3904         },
3905 };
3906
3907 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3908
3909 struct cmd_set_rxoffs_result {
3910         cmdline_fixed_string_t cmd_keyword;
3911         cmdline_fixed_string_t rxoffs;
3912         cmdline_fixed_string_t seg_offsets;
3913 };
3914
3915 static void
3916 cmd_set_rxoffs_parsed(void *parsed_result,
3917                       __rte_unused struct cmdline *cl,
3918                       __rte_unused void *data)
3919 {
3920         struct cmd_set_rxoffs_result *res;
3921         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3922         unsigned int nb_segs;
3923
3924         res = parsed_result;
3925         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3926                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3927         if (nb_segs > 0)
3928                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3929 }
3930
3931 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3932         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3933                                  cmd_keyword, "set");
3934 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3935         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3936                                  rxoffs, "rxoffs");
3937 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3938         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3939                                  seg_offsets, NULL);
3940
3941 cmdline_parse_inst_t cmd_set_rxoffs = {
3942         .f = cmd_set_rxoffs_parsed,
3943         .data = NULL,
3944         .help_str = "set rxoffs <len0[,len1]*>",
3945         .tokens = {
3946                 (void *)&cmd_set_rxoffs_keyword,
3947                 (void *)&cmd_set_rxoffs_name,
3948                 (void *)&cmd_set_rxoffs_offsets,
3949                 NULL,
3950         },
3951 };
3952
3953 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3954
3955 struct cmd_set_rxpkts_result {
3956         cmdline_fixed_string_t cmd_keyword;
3957         cmdline_fixed_string_t rxpkts;
3958         cmdline_fixed_string_t seg_lengths;
3959 };
3960
3961 static void
3962 cmd_set_rxpkts_parsed(void *parsed_result,
3963                       __rte_unused struct cmdline *cl,
3964                       __rte_unused void *data)
3965 {
3966         struct cmd_set_rxpkts_result *res;
3967         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3968         unsigned int nb_segs;
3969
3970         res = parsed_result;
3971         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3972                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3973         if (nb_segs > 0)
3974                 set_rx_pkt_segments(seg_lengths, nb_segs);
3975 }
3976
3977 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3978         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3979                                  cmd_keyword, "set");
3980 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3981         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3982                                  rxpkts, "rxpkts");
3983 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3984         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3985                                  seg_lengths, NULL);
3986
3987 cmdline_parse_inst_t cmd_set_rxpkts = {
3988         .f = cmd_set_rxpkts_parsed,
3989         .data = NULL,
3990         .help_str = "set rxpkts <len0[,len1]*>",
3991         .tokens = {
3992                 (void *)&cmd_set_rxpkts_keyword,
3993                 (void *)&cmd_set_rxpkts_name,
3994                 (void *)&cmd_set_rxpkts_lengths,
3995                 NULL,
3996         },
3997 };
3998
3999 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
4000
4001 struct cmd_set_txpkts_result {
4002         cmdline_fixed_string_t cmd_keyword;
4003         cmdline_fixed_string_t txpkts;
4004         cmdline_fixed_string_t seg_lengths;
4005 };
4006
4007 static void
4008 cmd_set_txpkts_parsed(void *parsed_result,
4009                       __rte_unused struct cmdline *cl,
4010                       __rte_unused void *data)
4011 {
4012         struct cmd_set_txpkts_result *res;
4013         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4014         unsigned int nb_segs;
4015
4016         res = parsed_result;
4017         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4018                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4019         if (nb_segs > 0)
4020                 set_tx_pkt_segments(seg_lengths, nb_segs);
4021 }
4022
4023 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4024         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4025                                  cmd_keyword, "set");
4026 cmdline_parse_token_string_t cmd_set_txpkts_name =
4027         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4028                                  txpkts, "txpkts");
4029 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4030         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4031                                  seg_lengths, NULL);
4032
4033 cmdline_parse_inst_t cmd_set_txpkts = {
4034         .f = cmd_set_txpkts_parsed,
4035         .data = NULL,
4036         .help_str = "set txpkts <len0[,len1]*>",
4037         .tokens = {
4038                 (void *)&cmd_set_txpkts_keyword,
4039                 (void *)&cmd_set_txpkts_name,
4040                 (void *)&cmd_set_txpkts_lengths,
4041                 NULL,
4042         },
4043 };
4044
4045 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4046
4047 struct cmd_set_txsplit_result {
4048         cmdline_fixed_string_t cmd_keyword;
4049         cmdline_fixed_string_t txsplit;
4050         cmdline_fixed_string_t mode;
4051 };
4052
4053 static void
4054 cmd_set_txsplit_parsed(void *parsed_result,
4055                       __rte_unused struct cmdline *cl,
4056                       __rte_unused void *data)
4057 {
4058         struct cmd_set_txsplit_result *res;
4059
4060         res = parsed_result;
4061         set_tx_pkt_split(res->mode);
4062 }
4063
4064 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4065         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4066                                  cmd_keyword, "set");
4067 cmdline_parse_token_string_t cmd_set_txsplit_name =
4068         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4069                                  txsplit, "txsplit");
4070 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4071         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4072                                  mode, NULL);
4073
4074 cmdline_parse_inst_t cmd_set_txsplit = {
4075         .f = cmd_set_txsplit_parsed,
4076         .data = NULL,
4077         .help_str = "set txsplit on|off|rand",
4078         .tokens = {
4079                 (void *)&cmd_set_txsplit_keyword,
4080                 (void *)&cmd_set_txsplit_name,
4081                 (void *)&cmd_set_txsplit_mode,
4082                 NULL,
4083         },
4084 };
4085
4086 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4087
4088 struct cmd_set_txtimes_result {
4089         cmdline_fixed_string_t cmd_keyword;
4090         cmdline_fixed_string_t txtimes;
4091         cmdline_fixed_string_t tx_times;
4092 };
4093
4094 static void
4095 cmd_set_txtimes_parsed(void *parsed_result,
4096                        __rte_unused struct cmdline *cl,
4097                        __rte_unused void *data)
4098 {
4099         struct cmd_set_txtimes_result *res;
4100         unsigned int tx_times[2] = {0, 0};
4101         unsigned int n_times;
4102
4103         res = parsed_result;
4104         n_times = parse_item_list(res->tx_times, "tx times",
4105                                   2, tx_times, 0);
4106         if (n_times == 2)
4107                 set_tx_pkt_times(tx_times);
4108 }
4109
4110 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4111         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4112                                  cmd_keyword, "set");
4113 cmdline_parse_token_string_t cmd_set_txtimes_name =
4114         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4115                                  txtimes, "txtimes");
4116 cmdline_parse_token_string_t cmd_set_txtimes_value =
4117         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4118                                  tx_times, NULL);
4119
4120 cmdline_parse_inst_t cmd_set_txtimes = {
4121         .f = cmd_set_txtimes_parsed,
4122         .data = NULL,
4123         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4124         .tokens = {
4125                 (void *)&cmd_set_txtimes_keyword,
4126                 (void *)&cmd_set_txtimes_name,
4127                 (void *)&cmd_set_txtimes_value,
4128                 NULL,
4129         },
4130 };
4131
4132 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4133 struct cmd_rx_vlan_filter_all_result {
4134         cmdline_fixed_string_t rx_vlan;
4135         cmdline_fixed_string_t what;
4136         cmdline_fixed_string_t all;
4137         portid_t port_id;
4138 };
4139
4140 static void
4141 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4142                               __rte_unused struct cmdline *cl,
4143                               __rte_unused void *data)
4144 {
4145         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4146
4147         if (!strcmp(res->what, "add"))
4148                 rx_vlan_all_filter_set(res->port_id, 1);
4149         else
4150                 rx_vlan_all_filter_set(res->port_id, 0);
4151 }
4152
4153 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4154         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4155                                  rx_vlan, "rx_vlan");
4156 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4157         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4158                                  what, "add#rm");
4159 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4160         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4161                                  all, "all");
4162 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4163         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4164                               port_id, UINT16);
4165
4166 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4167         .f = cmd_rx_vlan_filter_all_parsed,
4168         .data = NULL,
4169         .help_str = "rx_vlan add|rm all <port_id>: "
4170                 "Add/Remove all identifiers to/from the set of VLAN "
4171                 "identifiers filtered by a port",
4172         .tokens = {
4173                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4174                 (void *)&cmd_rx_vlan_filter_all_what,
4175                 (void *)&cmd_rx_vlan_filter_all_all,
4176                 (void *)&cmd_rx_vlan_filter_all_portid,
4177                 NULL,
4178         },
4179 };
4180
4181 /* *** VLAN OFFLOAD SET ON A PORT *** */
4182 struct cmd_vlan_offload_result {
4183         cmdline_fixed_string_t vlan;
4184         cmdline_fixed_string_t set;
4185         cmdline_fixed_string_t vlan_type;
4186         cmdline_fixed_string_t what;
4187         cmdline_fixed_string_t on;
4188         cmdline_fixed_string_t port_id;
4189 };
4190
4191 static void
4192 cmd_vlan_offload_parsed(void *parsed_result,
4193                           __rte_unused struct cmdline *cl,
4194                           __rte_unused void *data)
4195 {
4196         int on;
4197         struct cmd_vlan_offload_result *res = parsed_result;
4198         char *str;
4199         int i, len = 0;
4200         portid_t port_id = 0;
4201         unsigned int tmp;
4202
4203         str = res->port_id;
4204         len = strnlen(str, STR_TOKEN_SIZE);
4205         i = 0;
4206         /* Get port_id first */
4207         while(i < len){
4208                 if(str[i] == ',')
4209                         break;
4210
4211                 i++;
4212         }
4213         str[i]='\0';
4214         tmp = strtoul(str, NULL, 0);
4215         /* If port_id greater that what portid_t can represent, return */
4216         if(tmp >= RTE_MAX_ETHPORTS)
4217                 return;
4218         port_id = (portid_t)tmp;
4219
4220         if (!strcmp(res->on, "on"))
4221                 on = 1;
4222         else
4223                 on = 0;
4224
4225         if (!strcmp(res->what, "strip"))
4226                 rx_vlan_strip_set(port_id,  on);
4227         else if(!strcmp(res->what, "stripq")){
4228                 uint16_t queue_id = 0;
4229
4230                 /* No queue_id, return */
4231                 if(i + 1 >= len) {
4232                         printf("must specify (port,queue_id)\n");
4233                         return;
4234                 }
4235                 tmp = strtoul(str + i + 1, NULL, 0);
4236                 /* If queue_id greater that what 16-bits can represent, return */
4237                 if(tmp > 0xffff)
4238                         return;
4239
4240                 queue_id = (uint16_t)tmp;
4241                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4242         }
4243         else if (!strcmp(res->what, "filter"))
4244                 rx_vlan_filter_set(port_id, on);
4245         else if (!strcmp(res->what, "qinq_strip"))
4246                 rx_vlan_qinq_strip_set(port_id, on);
4247         else
4248                 vlan_extend_set(port_id, on);
4249
4250         return;
4251 }
4252
4253 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4254         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4255                                  vlan, "vlan");
4256 cmdline_parse_token_string_t cmd_vlan_offload_set =
4257         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4258                                  set, "set");
4259 cmdline_parse_token_string_t cmd_vlan_offload_what =
4260         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4261                                 what, "strip#filter#qinq_strip#extend#stripq");
4262 cmdline_parse_token_string_t cmd_vlan_offload_on =
4263         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4264                               on, "on#off");
4265 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4266         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4267                               port_id, NULL);
4268
4269 cmdline_parse_inst_t cmd_vlan_offload = {
4270         .f = cmd_vlan_offload_parsed,
4271         .data = NULL,
4272         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4273                 "<port_id[,queue_id]>: "
4274                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4275         .tokens = {
4276                 (void *)&cmd_vlan_offload_vlan,
4277                 (void *)&cmd_vlan_offload_set,
4278                 (void *)&cmd_vlan_offload_what,
4279                 (void *)&cmd_vlan_offload_on,
4280                 (void *)&cmd_vlan_offload_portid,
4281                 NULL,
4282         },
4283 };
4284
4285 /* *** VLAN TPID SET ON A PORT *** */
4286 struct cmd_vlan_tpid_result {
4287         cmdline_fixed_string_t vlan;
4288         cmdline_fixed_string_t set;
4289         cmdline_fixed_string_t vlan_type;
4290         cmdline_fixed_string_t what;
4291         uint16_t tp_id;
4292         portid_t port_id;
4293 };
4294
4295 static void
4296 cmd_vlan_tpid_parsed(void *parsed_result,
4297                           __rte_unused struct cmdline *cl,
4298                           __rte_unused void *data)
4299 {
4300         struct cmd_vlan_tpid_result *res = parsed_result;
4301         enum rte_vlan_type vlan_type;
4302
4303         if (!strcmp(res->vlan_type, "inner"))
4304                 vlan_type = ETH_VLAN_TYPE_INNER;
4305         else if (!strcmp(res->vlan_type, "outer"))
4306                 vlan_type = ETH_VLAN_TYPE_OUTER;
4307         else {
4308                 printf("Unknown vlan type\n");
4309                 return;
4310         }
4311         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4312 }
4313
4314 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4315         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4316                                  vlan, "vlan");
4317 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4318         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4319                                  set, "set");
4320 cmdline_parse_token_string_t cmd_vlan_type =
4321         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4322                                  vlan_type, "inner#outer");
4323 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4324         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4325                                  what, "tpid");
4326 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4327         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4328                               tp_id, UINT16);
4329 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4330         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4331                               port_id, UINT16);
4332
4333 cmdline_parse_inst_t cmd_vlan_tpid = {
4334         .f = cmd_vlan_tpid_parsed,
4335         .data = NULL,
4336         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4337                 "Set the VLAN Ether type",
4338         .tokens = {
4339                 (void *)&cmd_vlan_tpid_vlan,
4340                 (void *)&cmd_vlan_tpid_set,
4341                 (void *)&cmd_vlan_type,
4342                 (void *)&cmd_vlan_tpid_what,
4343                 (void *)&cmd_vlan_tpid_tpid,
4344                 (void *)&cmd_vlan_tpid_portid,
4345                 NULL,
4346         },
4347 };
4348
4349 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4350 struct cmd_rx_vlan_filter_result {
4351         cmdline_fixed_string_t rx_vlan;
4352         cmdline_fixed_string_t what;
4353         uint16_t vlan_id;
4354         portid_t port_id;
4355 };
4356
4357 static void
4358 cmd_rx_vlan_filter_parsed(void *parsed_result,
4359                           __rte_unused struct cmdline *cl,
4360                           __rte_unused void *data)
4361 {
4362         struct cmd_rx_vlan_filter_result *res = parsed_result;
4363
4364         if (!strcmp(res->what, "add"))
4365                 rx_vft_set(res->port_id, res->vlan_id, 1);
4366         else
4367                 rx_vft_set(res->port_id, res->vlan_id, 0);
4368 }
4369
4370 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4371         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4372                                  rx_vlan, "rx_vlan");
4373 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4374         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4375                                  what, "add#rm");
4376 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4377         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4378                               vlan_id, UINT16);
4379 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4380         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4381                               port_id, UINT16);
4382
4383 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4384         .f = cmd_rx_vlan_filter_parsed,
4385         .data = NULL,
4386         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4387                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4388                 "identifiers filtered by a port",
4389         .tokens = {
4390                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4391                 (void *)&cmd_rx_vlan_filter_what,
4392                 (void *)&cmd_rx_vlan_filter_vlanid,
4393                 (void *)&cmd_rx_vlan_filter_portid,
4394                 NULL,
4395         },
4396 };
4397
4398 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4399 struct cmd_tx_vlan_set_result {
4400         cmdline_fixed_string_t tx_vlan;
4401         cmdline_fixed_string_t set;
4402         portid_t port_id;
4403         uint16_t vlan_id;
4404 };
4405
4406 static void
4407 cmd_tx_vlan_set_parsed(void *parsed_result,
4408                        __rte_unused struct cmdline *cl,
4409                        __rte_unused void *data)
4410 {
4411         struct cmd_tx_vlan_set_result *res = parsed_result;
4412
4413         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4414                 return;
4415
4416         if (!port_is_stopped(res->port_id)) {
4417                 printf("Please stop port %d first\n", res->port_id);
4418                 return;
4419         }
4420
4421         tx_vlan_set(res->port_id, res->vlan_id);
4422
4423         cmd_reconfig_device_queue(res->port_id, 1, 1);
4424 }
4425
4426 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4427         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4428                                  tx_vlan, "tx_vlan");
4429 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4430         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4431                                  set, "set");
4432 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4433         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4434                               port_id, UINT16);
4435 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4436         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4437                               vlan_id, UINT16);
4438
4439 cmdline_parse_inst_t cmd_tx_vlan_set = {
4440         .f = cmd_tx_vlan_set_parsed,
4441         .data = NULL,
4442         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4443                 "Enable hardware insertion of a single VLAN header "
4444                 "with a given TAG Identifier in packets sent on a port",
4445         .tokens = {
4446                 (void *)&cmd_tx_vlan_set_tx_vlan,
4447                 (void *)&cmd_tx_vlan_set_set,
4448                 (void *)&cmd_tx_vlan_set_portid,
4449                 (void *)&cmd_tx_vlan_set_vlanid,
4450                 NULL,
4451         },
4452 };
4453
4454 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4455 struct cmd_tx_vlan_set_qinq_result {
4456         cmdline_fixed_string_t tx_vlan;
4457         cmdline_fixed_string_t set;
4458         portid_t port_id;
4459         uint16_t vlan_id;
4460         uint16_t vlan_id_outer;
4461 };
4462
4463 static void
4464 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4465                             __rte_unused struct cmdline *cl,
4466                             __rte_unused void *data)
4467 {
4468         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4469
4470         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4471                 return;
4472
4473         if (!port_is_stopped(res->port_id)) {
4474                 printf("Please stop port %d first\n", res->port_id);
4475                 return;
4476         }
4477
4478         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4479
4480         cmd_reconfig_device_queue(res->port_id, 1, 1);
4481 }
4482
4483 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4484         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4485                 tx_vlan, "tx_vlan");
4486 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4487         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4488                 set, "set");
4489 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4490         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4491                 port_id, UINT16);
4492 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4493         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4494                 vlan_id, UINT16);
4495 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4496         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4497                 vlan_id_outer, UINT16);
4498
4499 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4500         .f = cmd_tx_vlan_set_qinq_parsed,
4501         .data = NULL,
4502         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4503                 "Enable hardware insertion of double VLAN header "
4504                 "with given TAG Identifiers in packets sent on a port",
4505         .tokens = {
4506                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4507                 (void *)&cmd_tx_vlan_set_qinq_set,
4508                 (void *)&cmd_tx_vlan_set_qinq_portid,
4509                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4510                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4511                 NULL,
4512         },
4513 };
4514
4515 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4516 struct cmd_tx_vlan_set_pvid_result {
4517         cmdline_fixed_string_t tx_vlan;
4518         cmdline_fixed_string_t set;
4519         cmdline_fixed_string_t pvid;
4520         portid_t port_id;
4521         uint16_t vlan_id;
4522         cmdline_fixed_string_t mode;
4523 };
4524
4525 static void
4526 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4527                             __rte_unused struct cmdline *cl,
4528                             __rte_unused void *data)
4529 {
4530         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4531
4532         if (strcmp(res->mode, "on") == 0)
4533                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4534         else
4535                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4536 }
4537
4538 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4539         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4540                                  tx_vlan, "tx_vlan");
4541 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4542         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4543                                  set, "set");
4544 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4545         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4546                                  pvid, "pvid");
4547 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4548         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4549                              port_id, UINT16);
4550 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4551         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4552                               vlan_id, UINT16);
4553 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4554         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4555                                  mode, "on#off");
4556
4557 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4558         .f = cmd_tx_vlan_set_pvid_parsed,
4559         .data = NULL,
4560         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4561         .tokens = {
4562                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4563                 (void *)&cmd_tx_vlan_set_pvid_set,
4564                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4565                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4566                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4567                 (void *)&cmd_tx_vlan_set_pvid_mode,
4568                 NULL,
4569         },
4570 };
4571
4572 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4573 struct cmd_tx_vlan_reset_result {
4574         cmdline_fixed_string_t tx_vlan;
4575         cmdline_fixed_string_t reset;
4576         portid_t port_id;
4577 };
4578
4579 static void
4580 cmd_tx_vlan_reset_parsed(void *parsed_result,
4581                          __rte_unused struct cmdline *cl,
4582                          __rte_unused void *data)
4583 {
4584         struct cmd_tx_vlan_reset_result *res = parsed_result;
4585
4586         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4587                 return;
4588
4589         if (!port_is_stopped(res->port_id)) {
4590                 printf("Please stop port %d first\n", res->port_id);
4591                 return;
4592         }
4593
4594         tx_vlan_reset(res->port_id);
4595
4596         cmd_reconfig_device_queue(res->port_id, 1, 1);
4597 }
4598
4599 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4600         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4601                                  tx_vlan, "tx_vlan");
4602 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4603         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4604                                  reset, "reset");
4605 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4606         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4607                               port_id, UINT16);
4608
4609 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4610         .f = cmd_tx_vlan_reset_parsed,
4611         .data = NULL,
4612         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4613                 "VLAN header in packets sent on a port",
4614         .tokens = {
4615                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4616                 (void *)&cmd_tx_vlan_reset_reset,
4617                 (void *)&cmd_tx_vlan_reset_portid,
4618                 NULL,
4619         },
4620 };
4621
4622
4623 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4624 struct cmd_csum_result {
4625         cmdline_fixed_string_t csum;
4626         cmdline_fixed_string_t mode;
4627         cmdline_fixed_string_t proto;
4628         cmdline_fixed_string_t hwsw;
4629         portid_t port_id;
4630 };
4631
4632 static void
4633 csum_show(int port_id)
4634 {
4635         struct rte_eth_dev_info dev_info;
4636         uint64_t tx_offloads;
4637         int ret;
4638
4639         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4640         printf("Parse tunnel is %s\n",
4641                 (ports[port_id].parse_tunnel) ? "on" : "off");
4642         printf("IP checksum offload is %s\n",
4643                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4644         printf("UDP checksum offload is %s\n",
4645                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4646         printf("TCP checksum offload is %s\n",
4647                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4648         printf("SCTP checksum offload is %s\n",
4649                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4650         printf("Outer-Ip checksum offload is %s\n",
4651                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4652         printf("Outer-Udp checksum offload is %s\n",
4653                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4654
4655         /* display warnings if configuration is not supported by the NIC */
4656         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4657         if (ret != 0)
4658                 return;
4659
4660         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4661                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4662                 printf("Warning: hardware IP checksum enabled but not "
4663                         "supported by port %d\n", port_id);
4664         }
4665         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4666                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4667                 printf("Warning: hardware UDP checksum enabled but not "
4668                         "supported by port %d\n", port_id);
4669         }
4670         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4671                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4672                 printf("Warning: hardware TCP checksum enabled but not "
4673                         "supported by port %d\n", port_id);
4674         }
4675         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4676                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4677                 printf("Warning: hardware SCTP checksum enabled but not "
4678                         "supported by port %d\n", port_id);
4679         }
4680         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4681                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4682                 printf("Warning: hardware outer IP checksum enabled but not "
4683                         "supported by port %d\n", port_id);
4684         }
4685         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4686                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4687                         == 0) {
4688                 printf("Warning: hardware outer UDP checksum enabled but not "
4689                         "supported by port %d\n", port_id);
4690         }
4691 }
4692
4693 static void
4694 cmd_config_queue_tx_offloads(struct rte_port *port)
4695 {
4696         int k;
4697
4698         /* Apply queue tx offloads configuration */
4699         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4700                 port->tx_conf[k].offloads =
4701                         port->dev_conf.txmode.offloads;
4702 }
4703
4704 static void
4705 cmd_csum_parsed(void *parsed_result,
4706                        __rte_unused struct cmdline *cl,
4707                        __rte_unused void *data)
4708 {
4709         struct cmd_csum_result *res = parsed_result;
4710         int hw = 0;
4711         uint64_t csum_offloads = 0;
4712         struct rte_eth_dev_info dev_info;
4713         int ret;
4714
4715         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4716                 printf("invalid port %d\n", res->port_id);
4717                 return;
4718         }
4719         if (!port_is_stopped(res->port_id)) {
4720                 printf("Please stop port %d first\n", res->port_id);
4721                 return;
4722         }
4723
4724         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4725         if (ret != 0)
4726                 return;
4727
4728         if (!strcmp(res->mode, "set")) {
4729
4730                 if (!strcmp(res->hwsw, "hw"))
4731                         hw = 1;
4732
4733                 if (!strcmp(res->proto, "ip")) {
4734                         if (hw == 0 || (dev_info.tx_offload_capa &
4735                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4736                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4737                         } else {
4738                                 printf("IP checksum offload is not supported "
4739                                        "by port %u\n", res->port_id);
4740                         }
4741                 } else if (!strcmp(res->proto, "udp")) {
4742                         if (hw == 0 || (dev_info.tx_offload_capa &
4743                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4744                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4745                         } else {
4746                                 printf("UDP checksum offload is not supported "
4747                                        "by port %u\n", res->port_id);
4748                         }
4749                 } else if (!strcmp(res->proto, "tcp")) {
4750                         if (hw == 0 || (dev_info.tx_offload_capa &
4751                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4752                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4753                         } else {
4754                                 printf("TCP checksum offload is not supported "
4755                                        "by port %u\n", res->port_id);
4756                         }
4757                 } else if (!strcmp(res->proto, "sctp")) {
4758                         if (hw == 0 || (dev_info.tx_offload_capa &
4759                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4760                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4761                         } else {
4762                                 printf("SCTP checksum offload is not supported "
4763                                        "by port %u\n", res->port_id);
4764                         }
4765                 } else if (!strcmp(res->proto, "outer-ip")) {
4766                         if (hw == 0 || (dev_info.tx_offload_capa &
4767                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4768                                 csum_offloads |=
4769                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4770                         } else {
4771                                 printf("Outer IP checksum offload is not "
4772                                        "supported by port %u\n", res->port_id);
4773                         }
4774                 } else if (!strcmp(res->proto, "outer-udp")) {
4775                         if (hw == 0 || (dev_info.tx_offload_capa &
4776                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4777                                 csum_offloads |=
4778                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4779                         } else {
4780                                 printf("Outer UDP checksum offload is not "
4781                                        "supported by port %u\n", res->port_id);
4782                         }
4783                 }
4784
4785                 if (hw) {
4786                         ports[res->port_id].dev_conf.txmode.offloads |=
4787                                                         csum_offloads;
4788                 } else {
4789                         ports[res->port_id].dev_conf.txmode.offloads &=
4790                                                         (~csum_offloads);
4791                 }
4792                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4793         }
4794         csum_show(res->port_id);
4795
4796         cmd_reconfig_device_queue(res->port_id, 1, 1);
4797 }
4798
4799 cmdline_parse_token_string_t cmd_csum_csum =
4800         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4801                                 csum, "csum");
4802 cmdline_parse_token_string_t cmd_csum_mode =
4803         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4804                                 mode, "set");
4805 cmdline_parse_token_string_t cmd_csum_proto =
4806         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4807                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4808 cmdline_parse_token_string_t cmd_csum_hwsw =
4809         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4810                                 hwsw, "hw#sw");
4811 cmdline_parse_token_num_t cmd_csum_portid =
4812         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4813                                 port_id, UINT16);
4814
4815 cmdline_parse_inst_t cmd_csum_set = {
4816         .f = cmd_csum_parsed,
4817         .data = NULL,
4818         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4819                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4820                 "using csum forward engine",
4821         .tokens = {
4822                 (void *)&cmd_csum_csum,
4823                 (void *)&cmd_csum_mode,
4824                 (void *)&cmd_csum_proto,
4825                 (void *)&cmd_csum_hwsw,
4826                 (void *)&cmd_csum_portid,
4827                 NULL,
4828         },
4829 };
4830
4831 cmdline_parse_token_string_t cmd_csum_mode_show =
4832         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4833                                 mode, "show");
4834
4835 cmdline_parse_inst_t cmd_csum_show = {
4836         .f = cmd_csum_parsed,
4837         .data = NULL,
4838         .help_str = "csum show <port_id>: Show checksum offload configuration",
4839         .tokens = {
4840                 (void *)&cmd_csum_csum,
4841                 (void *)&cmd_csum_mode_show,
4842                 (void *)&cmd_csum_portid,
4843                 NULL,
4844         },
4845 };
4846
4847 /* Enable/disable tunnel parsing */
4848 struct cmd_csum_tunnel_result {
4849         cmdline_fixed_string_t csum;
4850         cmdline_fixed_string_t parse;
4851         cmdline_fixed_string_t onoff;
4852         portid_t port_id;
4853 };
4854
4855 static void
4856 cmd_csum_tunnel_parsed(void *parsed_result,
4857                        __rte_unused struct cmdline *cl,
4858                        __rte_unused void *data)
4859 {
4860         struct cmd_csum_tunnel_result *res = parsed_result;
4861
4862         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4863                 return;
4864
4865         if (!strcmp(res->onoff, "on"))
4866                 ports[res->port_id].parse_tunnel = 1;
4867         else
4868                 ports[res->port_id].parse_tunnel = 0;
4869
4870         csum_show(res->port_id);
4871 }
4872
4873 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4874         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4875                                 csum, "csum");
4876 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4877         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4878                                 parse, "parse-tunnel");
4879 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4880         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4881                                 onoff, "on#off");
4882 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4883         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4884                                 port_id, UINT16);
4885
4886 cmdline_parse_inst_t cmd_csum_tunnel = {
4887         .f = cmd_csum_tunnel_parsed,
4888         .data = NULL,
4889         .help_str = "csum parse-tunnel on|off <port_id>: "
4890                 "Enable/Disable parsing of tunnels for csum engine",
4891         .tokens = {
4892                 (void *)&cmd_csum_tunnel_csum,
4893                 (void *)&cmd_csum_tunnel_parse,
4894                 (void *)&cmd_csum_tunnel_onoff,
4895                 (void *)&cmd_csum_tunnel_portid,
4896                 NULL,
4897         },
4898 };
4899
4900 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4901 struct cmd_tso_set_result {
4902         cmdline_fixed_string_t tso;
4903         cmdline_fixed_string_t mode;
4904         uint16_t tso_segsz;
4905         portid_t port_id;
4906 };
4907
4908 static void
4909 cmd_tso_set_parsed(void *parsed_result,
4910                        __rte_unused struct cmdline *cl,
4911                        __rte_unused void *data)
4912 {
4913         struct cmd_tso_set_result *res = parsed_result;
4914         struct rte_eth_dev_info dev_info;
4915         int ret;
4916
4917         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4918                 return;
4919         if (!port_is_stopped(res->port_id)) {
4920                 printf("Please stop port %d first\n", res->port_id);
4921                 return;
4922         }
4923
4924         if (!strcmp(res->mode, "set"))
4925                 ports[res->port_id].tso_segsz = res->tso_segsz;
4926
4927         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4928         if (ret != 0)
4929                 return;
4930
4931         if ((ports[res->port_id].tso_segsz != 0) &&
4932                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4933                 printf("Error: TSO is not supported by port %d\n",
4934                        res->port_id);
4935                 return;
4936         }
4937
4938         if (ports[res->port_id].tso_segsz == 0) {
4939                 ports[res->port_id].dev_conf.txmode.offloads &=
4940                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4941                 printf("TSO for non-tunneled packets is disabled\n");
4942         } else {
4943                 ports[res->port_id].dev_conf.txmode.offloads |=
4944                                                 DEV_TX_OFFLOAD_TCP_TSO;
4945                 printf("TSO segment size for non-tunneled packets is %d\n",
4946                         ports[res->port_id].tso_segsz);
4947         }
4948         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4949
4950         /* display warnings if configuration is not supported by the NIC */
4951         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4952         if (ret != 0)
4953                 return;
4954
4955         if ((ports[res->port_id].tso_segsz != 0) &&
4956                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4957                 printf("Warning: TSO enabled but not "
4958                         "supported by port %d\n", res->port_id);
4959         }
4960
4961         cmd_reconfig_device_queue(res->port_id, 1, 1);
4962 }
4963
4964 cmdline_parse_token_string_t cmd_tso_set_tso =
4965         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4966                                 tso, "tso");
4967 cmdline_parse_token_string_t cmd_tso_set_mode =
4968         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4969                                 mode, "set");
4970 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4971         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4972                                 tso_segsz, UINT16);
4973 cmdline_parse_token_num_t cmd_tso_set_portid =
4974         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4975                                 port_id, UINT16);
4976
4977 cmdline_parse_inst_t cmd_tso_set = {
4978         .f = cmd_tso_set_parsed,
4979         .data = NULL,
4980         .help_str = "tso set <tso_segsz> <port_id>: "
4981                 "Set TSO segment size of non-tunneled packets for csum engine "
4982                 "(0 to disable)",
4983         .tokens = {
4984                 (void *)&cmd_tso_set_tso,
4985                 (void *)&cmd_tso_set_mode,
4986                 (void *)&cmd_tso_set_tso_segsz,
4987                 (void *)&cmd_tso_set_portid,
4988                 NULL,
4989         },
4990 };
4991
4992 cmdline_parse_token_string_t cmd_tso_show_mode =
4993         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4994                                 mode, "show");
4995
4996
4997 cmdline_parse_inst_t cmd_tso_show = {
4998         .f = cmd_tso_set_parsed,
4999         .data = NULL,
5000         .help_str = "tso show <port_id>: "
5001                 "Show TSO segment size of non-tunneled packets for csum engine",
5002         .tokens = {
5003                 (void *)&cmd_tso_set_tso,
5004                 (void *)&cmd_tso_show_mode,
5005                 (void *)&cmd_tso_set_portid,
5006                 NULL,
5007         },
5008 };
5009
5010 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5011 struct cmd_tunnel_tso_set_result {
5012         cmdline_fixed_string_t tso;
5013         cmdline_fixed_string_t mode;
5014         uint16_t tso_segsz;
5015         portid_t port_id;
5016 };
5017
5018 static struct rte_eth_dev_info
5019 check_tunnel_tso_nic_support(portid_t port_id)
5020 {
5021         struct rte_eth_dev_info dev_info;
5022
5023         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5024                 return dev_info;
5025
5026         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
5027                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
5028                        "not enabled for port %d\n", port_id);
5029         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
5030                 printf("Warning: GRE TUNNEL TSO not supported therefore "
5031                        "not enabled for port %d\n", port_id);
5032         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
5033                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
5034                        "not enabled for port %d\n", port_id);
5035         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
5036                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
5037                        "not enabled for port %d\n", port_id);
5038         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
5039                 printf("Warning: IP TUNNEL TSO not supported therefore "
5040                        "not enabled for port %d\n", port_id);
5041         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
5042                 printf("Warning: UDP TUNNEL TSO not supported therefore "
5043                        "not enabled for port %d\n", port_id);
5044         return dev_info;
5045 }
5046
5047 static void
5048 cmd_tunnel_tso_set_parsed(void *parsed_result,
5049                           __rte_unused struct cmdline *cl,
5050                           __rte_unused void *data)
5051 {
5052         struct cmd_tunnel_tso_set_result *res = parsed_result;
5053         struct rte_eth_dev_info dev_info;
5054
5055         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5056                 return;
5057         if (!port_is_stopped(res->port_id)) {
5058                 printf("Please stop port %d first\n", res->port_id);
5059                 return;
5060         }
5061
5062         if (!strcmp(res->mode, "set"))
5063                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5064
5065         dev_info = check_tunnel_tso_nic_support(res->port_id);
5066         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5067                 ports[res->port_id].dev_conf.txmode.offloads &=
5068                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5069                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
5070                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5071                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5072                           DEV_TX_OFFLOAD_IP_TNL_TSO |
5073                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
5074                 printf("TSO for tunneled packets is disabled\n");
5075         } else {
5076                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5077                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
5078                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5079                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5080                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
5081                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
5082
5083                 ports[res->port_id].dev_conf.txmode.offloads |=
5084                         (tso_offloads & dev_info.tx_offload_capa);
5085                 printf("TSO segment size for tunneled packets is %d\n",
5086                         ports[res->port_id].tunnel_tso_segsz);
5087
5088                 /* Below conditions are needed to make it work:
5089                  * (1) tunnel TSO is supported by the NIC;
5090                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5091                  * are recognized;
5092                  * (3) for tunneled pkts with outer L3 of IPv4,
5093                  * "csum set outer-ip" must be set to hw, because after tso,
5094                  * total_len of outer IP header is changed, and the checksum
5095                  * of outer IP header calculated by sw should be wrong; that
5096                  * is not necessary for IPv6 tunneled pkts because there's no
5097                  * checksum in IP header anymore.
5098                  */
5099
5100                 if (!ports[res->port_id].parse_tunnel)
5101                         printf("Warning: csum parse_tunnel must be set "
5102                                 "so that tunneled packets are recognized\n");
5103                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5104                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5105                         printf("Warning: csum set outer-ip must be set to hw "
5106                                 "if outer L3 is IPv4; not necessary for IPv6\n");
5107         }
5108
5109         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5110         cmd_reconfig_device_queue(res->port_id, 1, 1);
5111 }
5112
5113 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5114         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5115                                 tso, "tunnel_tso");
5116 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5117         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5118                                 mode, "set");
5119 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5120         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5121                                 tso_segsz, UINT16);
5122 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5123         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5124                                 port_id, UINT16);
5125
5126 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5127         .f = cmd_tunnel_tso_set_parsed,
5128         .data = NULL,
5129         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5130                 "Set TSO segment size of tunneled packets for csum engine "
5131                 "(0 to disable)",
5132         .tokens = {
5133                 (void *)&cmd_tunnel_tso_set_tso,
5134                 (void *)&cmd_tunnel_tso_set_mode,
5135                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5136                 (void *)&cmd_tunnel_tso_set_portid,
5137                 NULL,
5138         },
5139 };
5140
5141 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5142         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5143                                 mode, "show");
5144
5145
5146 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5147         .f = cmd_tunnel_tso_set_parsed,
5148         .data = NULL,
5149         .help_str = "tunnel_tso show <port_id> "
5150                 "Show TSO segment size of tunneled packets for csum engine",
5151         .tokens = {
5152                 (void *)&cmd_tunnel_tso_set_tso,
5153                 (void *)&cmd_tunnel_tso_show_mode,
5154                 (void *)&cmd_tunnel_tso_set_portid,
5155                 NULL,
5156         },
5157 };
5158
5159 /* *** SET GRO FOR A PORT *** */
5160 struct cmd_gro_enable_result {
5161         cmdline_fixed_string_t cmd_set;
5162         cmdline_fixed_string_t cmd_port;
5163         cmdline_fixed_string_t cmd_keyword;
5164         cmdline_fixed_string_t cmd_onoff;
5165         portid_t cmd_pid;
5166 };
5167
5168 static void
5169 cmd_gro_enable_parsed(void *parsed_result,
5170                 __rte_unused struct cmdline *cl,
5171                 __rte_unused void *data)
5172 {
5173         struct cmd_gro_enable_result *res;
5174
5175         res = parsed_result;
5176         if (!strcmp(res->cmd_keyword, "gro"))
5177                 setup_gro(res->cmd_onoff, res->cmd_pid);
5178 }
5179
5180 cmdline_parse_token_string_t cmd_gro_enable_set =
5181         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5182                         cmd_set, "set");
5183 cmdline_parse_token_string_t cmd_gro_enable_port =
5184         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5185                         cmd_keyword, "port");
5186 cmdline_parse_token_num_t cmd_gro_enable_pid =
5187         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5188                         cmd_pid, UINT16);
5189 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5190         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5191                         cmd_keyword, "gro");
5192 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5193         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5194                         cmd_onoff, "on#off");
5195
5196 cmdline_parse_inst_t cmd_gro_enable = {
5197         .f = cmd_gro_enable_parsed,
5198         .data = NULL,
5199         .help_str = "set port <port_id> gro on|off",
5200         .tokens = {
5201                 (void *)&cmd_gro_enable_set,
5202                 (void *)&cmd_gro_enable_port,
5203                 (void *)&cmd_gro_enable_pid,
5204                 (void *)&cmd_gro_enable_keyword,
5205                 (void *)&cmd_gro_enable_onoff,
5206                 NULL,
5207         },
5208 };
5209
5210 /* *** DISPLAY GRO CONFIGURATION *** */
5211 struct cmd_gro_show_result {
5212         cmdline_fixed_string_t cmd_show;
5213         cmdline_fixed_string_t cmd_port;
5214         cmdline_fixed_string_t cmd_keyword;
5215         portid_t cmd_pid;
5216 };
5217
5218 static void
5219 cmd_gro_show_parsed(void *parsed_result,
5220                 __rte_unused struct cmdline *cl,
5221                 __rte_unused void *data)
5222 {
5223         struct cmd_gro_show_result *res;
5224
5225         res = parsed_result;
5226         if (!strcmp(res->cmd_keyword, "gro"))
5227                 show_gro(res->cmd_pid);
5228 }
5229
5230 cmdline_parse_token_string_t cmd_gro_show_show =
5231         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5232                         cmd_show, "show");
5233 cmdline_parse_token_string_t cmd_gro_show_port =
5234         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5235                         cmd_port, "port");
5236 cmdline_parse_token_num_t cmd_gro_show_pid =
5237         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5238                         cmd_pid, UINT16);
5239 cmdline_parse_token_string_t cmd_gro_show_keyword =
5240         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5241                         cmd_keyword, "gro");
5242
5243 cmdline_parse_inst_t cmd_gro_show = {
5244         .f = cmd_gro_show_parsed,
5245         .data = NULL,
5246         .help_str = "show port <port_id> gro",
5247         .tokens = {
5248                 (void *)&cmd_gro_show_show,
5249                 (void *)&cmd_gro_show_port,
5250                 (void *)&cmd_gro_show_pid,
5251                 (void *)&cmd_gro_show_keyword,
5252                 NULL,
5253         },
5254 };
5255
5256 /* *** SET FLUSH CYCLES FOR GRO *** */
5257 struct cmd_gro_flush_result {
5258         cmdline_fixed_string_t cmd_set;
5259         cmdline_fixed_string_t cmd_keyword;
5260         cmdline_fixed_string_t cmd_flush;
5261         uint8_t cmd_cycles;
5262 };
5263
5264 static void
5265 cmd_gro_flush_parsed(void *parsed_result,
5266                 __rte_unused struct cmdline *cl,
5267                 __rte_unused void *data)
5268 {
5269         struct cmd_gro_flush_result *res;
5270
5271         res = parsed_result;
5272         if ((!strcmp(res->cmd_keyword, "gro")) &&
5273                         (!strcmp(res->cmd_flush, "flush")))
5274                 setup_gro_flush_cycles(res->cmd_cycles);
5275 }
5276
5277 cmdline_parse_token_string_t cmd_gro_flush_set =
5278         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5279                         cmd_set, "set");
5280 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5281         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5282                         cmd_keyword, "gro");
5283 cmdline_parse_token_string_t cmd_gro_flush_flush =
5284         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5285                         cmd_flush, "flush");
5286 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5287         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5288                         cmd_cycles, UINT8);
5289
5290 cmdline_parse_inst_t cmd_gro_flush = {
5291         .f = cmd_gro_flush_parsed,
5292         .data = NULL,
5293         .help_str = "set gro flush <cycles>",
5294         .tokens = {
5295                 (void *)&cmd_gro_flush_set,
5296                 (void *)&cmd_gro_flush_keyword,
5297                 (void *)&cmd_gro_flush_flush,
5298                 (void *)&cmd_gro_flush_cycles,
5299                 NULL,
5300         },
5301 };
5302
5303 /* *** ENABLE/DISABLE GSO *** */
5304 struct cmd_gso_enable_result {
5305         cmdline_fixed_string_t cmd_set;
5306         cmdline_fixed_string_t cmd_port;
5307         cmdline_fixed_string_t cmd_keyword;
5308         cmdline_fixed_string_t cmd_mode;
5309         portid_t cmd_pid;
5310 };
5311
5312 static void
5313 cmd_gso_enable_parsed(void *parsed_result,
5314                 __rte_unused struct cmdline *cl,
5315                 __rte_unused void *data)
5316 {
5317         struct cmd_gso_enable_result *res;
5318
5319         res = parsed_result;
5320         if (!strcmp(res->cmd_keyword, "gso"))
5321                 setup_gso(res->cmd_mode, res->cmd_pid);
5322 }
5323
5324 cmdline_parse_token_string_t cmd_gso_enable_set =
5325         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5326                         cmd_set, "set");
5327 cmdline_parse_token_string_t cmd_gso_enable_port =
5328         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5329                         cmd_port, "port");
5330 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5331         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5332                         cmd_keyword, "gso");
5333 cmdline_parse_token_string_t cmd_gso_enable_mode =
5334         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5335                         cmd_mode, "on#off");
5336 cmdline_parse_token_num_t cmd_gso_enable_pid =
5337         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5338                         cmd_pid, UINT16);
5339
5340 cmdline_parse_inst_t cmd_gso_enable = {
5341         .f = cmd_gso_enable_parsed,
5342         .data = NULL,
5343         .help_str = "set port <port_id> gso on|off",
5344         .tokens = {
5345                 (void *)&cmd_gso_enable_set,
5346                 (void *)&cmd_gso_enable_port,
5347                 (void *)&cmd_gso_enable_pid,
5348                 (void *)&cmd_gso_enable_keyword,
5349                 (void *)&cmd_gso_enable_mode,
5350                 NULL,
5351         },
5352 };
5353
5354 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5355 struct cmd_gso_size_result {
5356         cmdline_fixed_string_t cmd_set;
5357         cmdline_fixed_string_t cmd_keyword;
5358         cmdline_fixed_string_t cmd_segsz;
5359         uint16_t cmd_size;
5360 };
5361
5362 static void
5363 cmd_gso_size_parsed(void *parsed_result,
5364                        __rte_unused struct cmdline *cl,
5365                        __rte_unused void *data)
5366 {
5367         struct cmd_gso_size_result *res = parsed_result;
5368
5369         if (test_done == 0) {
5370                 printf("Before setting GSO segsz, please first"
5371                                 " stop forwarding\n");
5372                 return;
5373         }
5374
5375         if (!strcmp(res->cmd_keyword, "gso") &&
5376                         !strcmp(res->cmd_segsz, "segsz")) {
5377                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5378                         printf("gso_size should be larger than %zu."
5379                                         " Please input a legal value\n",
5380                                         RTE_GSO_SEG_SIZE_MIN);
5381                 else
5382                         gso_max_segment_size = res->cmd_size;
5383         }
5384 }
5385
5386 cmdline_parse_token_string_t cmd_gso_size_set =
5387         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5388                                 cmd_set, "set");
5389 cmdline_parse_token_string_t cmd_gso_size_keyword =
5390         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5391                                 cmd_keyword, "gso");
5392 cmdline_parse_token_string_t cmd_gso_size_segsz =
5393         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5394                                 cmd_segsz, "segsz");
5395 cmdline_parse_token_num_t cmd_gso_size_size =
5396         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5397                                 cmd_size, UINT16);
5398
5399 cmdline_parse_inst_t cmd_gso_size = {
5400         .f = cmd_gso_size_parsed,
5401         .data = NULL,
5402         .help_str = "set gso segsz <length>",
5403         .tokens = {
5404                 (void *)&cmd_gso_size_set,
5405                 (void *)&cmd_gso_size_keyword,
5406                 (void *)&cmd_gso_size_segsz,
5407                 (void *)&cmd_gso_size_size,
5408                 NULL,
5409         },
5410 };
5411
5412 /* *** SHOW GSO CONFIGURATION *** */
5413 struct cmd_gso_show_result {
5414         cmdline_fixed_string_t cmd_show;
5415         cmdline_fixed_string_t cmd_port;
5416         cmdline_fixed_string_t cmd_keyword;
5417         portid_t cmd_pid;
5418 };
5419
5420 static void
5421 cmd_gso_show_parsed(void *parsed_result,
5422                        __rte_unused struct cmdline *cl,
5423                        __rte_unused void *data)
5424 {
5425         struct cmd_gso_show_result *res = parsed_result;
5426
5427         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5428                 printf("invalid port id %u\n", res->cmd_pid);
5429                 return;
5430         }
5431         if (!strcmp(res->cmd_keyword, "gso")) {
5432                 if (gso_ports[res->cmd_pid].enable) {
5433                         printf("Max GSO'd packet size: %uB\n"
5434                                         "Supported GSO types: TCP/IPv4, "
5435                                         "UDP/IPv4, VxLAN with inner "
5436                                         "TCP/IPv4 packet, GRE with inner "
5437                                         "TCP/IPv4 packet\n",
5438                                         gso_max_segment_size);
5439                 } else
5440                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5441         }
5442 }
5443
5444 cmdline_parse_token_string_t cmd_gso_show_show =
5445 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5446                 cmd_show, "show");
5447 cmdline_parse_token_string_t cmd_gso_show_port =
5448 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5449                 cmd_port, "port");
5450 cmdline_parse_token_string_t cmd_gso_show_keyword =
5451         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5452                                 cmd_keyword, "gso");
5453 cmdline_parse_token_num_t cmd_gso_show_pid =
5454         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5455                                 cmd_pid, UINT16);
5456
5457 cmdline_parse_inst_t cmd_gso_show = {
5458         .f = cmd_gso_show_parsed,
5459         .data = NULL,
5460         .help_str = "show port <port_id> gso",
5461         .tokens = {
5462                 (void *)&cmd_gso_show_show,
5463                 (void *)&cmd_gso_show_port,
5464                 (void *)&cmd_gso_show_pid,
5465                 (void *)&cmd_gso_show_keyword,
5466                 NULL,
5467         },
5468 };
5469
5470 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5471 struct cmd_set_flush_rx {
5472         cmdline_fixed_string_t set;
5473         cmdline_fixed_string_t flush_rx;
5474         cmdline_fixed_string_t mode;
5475 };
5476
5477 static void
5478 cmd_set_flush_rx_parsed(void *parsed_result,
5479                 __rte_unused struct cmdline *cl,
5480                 __rte_unused void *data)
5481 {
5482         struct cmd_set_flush_rx *res = parsed_result;
5483         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5484 }
5485
5486 cmdline_parse_token_string_t cmd_setflushrx_set =
5487         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5488                         set, "set");
5489 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5490         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5491                         flush_rx, "flush_rx");
5492 cmdline_parse_token_string_t cmd_setflushrx_mode =
5493         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5494                         mode, "on#off");
5495
5496
5497 cmdline_parse_inst_t cmd_set_flush_rx = {
5498         .f = cmd_set_flush_rx_parsed,
5499         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5500         .data = NULL,
5501         .tokens = {
5502                 (void *)&cmd_setflushrx_set,
5503                 (void *)&cmd_setflushrx_flush_rx,
5504                 (void *)&cmd_setflushrx_mode,
5505                 NULL,
5506         },
5507 };
5508
5509 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5510 struct cmd_set_link_check {
5511         cmdline_fixed_string_t set;
5512         cmdline_fixed_string_t link_check;
5513         cmdline_fixed_string_t mode;
5514 };
5515
5516 static void
5517 cmd_set_link_check_parsed(void *parsed_result,
5518                 __rte_unused struct cmdline *cl,
5519                 __rte_unused void *data)
5520 {
5521         struct cmd_set_link_check *res = parsed_result;
5522         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5523 }
5524
5525 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5526         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5527                         set, "set");
5528 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5529         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5530                         link_check, "link_check");
5531 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5532         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5533                         mode, "on#off");
5534
5535
5536 cmdline_parse_inst_t cmd_set_link_check = {
5537         .f = cmd_set_link_check_parsed,
5538         .help_str = "set link_check on|off: Enable/Disable link status check "
5539                     "when starting/stopping a port",
5540         .data = NULL,
5541         .tokens = {
5542                 (void *)&cmd_setlinkcheck_set,
5543                 (void *)&cmd_setlinkcheck_link_check,
5544                 (void *)&cmd_setlinkcheck_mode,
5545                 NULL,
5546         },
5547 };
5548
5549 /* *** SET NIC BYPASS MODE *** */
5550 struct cmd_set_bypass_mode_result {
5551         cmdline_fixed_string_t set;
5552         cmdline_fixed_string_t bypass;
5553         cmdline_fixed_string_t mode;
5554         cmdline_fixed_string_t value;
5555         portid_t port_id;
5556 };
5557
5558 static void
5559 cmd_set_bypass_mode_parsed(void *parsed_result,
5560                 __rte_unused struct cmdline *cl,
5561                 __rte_unused void *data)
5562 {
5563         struct cmd_set_bypass_mode_result *res = parsed_result;
5564         portid_t port_id = res->port_id;
5565         int32_t rc = -EINVAL;
5566
5567 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5568         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5569
5570         if (!strcmp(res->value, "bypass"))
5571                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5572         else if (!strcmp(res->value, "isolate"))
5573                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5574         else
5575                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5576
5577         /* Set the bypass mode for the relevant port. */
5578         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5579 #endif
5580         if (rc != 0)
5581                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5582 }
5583
5584 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5585         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5586                         set, "set");
5587 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5588         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5589                         bypass, "bypass");
5590 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5591         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5592                         mode, "mode");
5593 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5594         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5595                         value, "normal#bypass#isolate");
5596 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5597         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5598                                 port_id, UINT16);
5599
5600 cmdline_parse_inst_t cmd_set_bypass_mode = {
5601         .f = cmd_set_bypass_mode_parsed,
5602         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5603                     "Set the NIC bypass mode for port_id",
5604         .data = NULL,
5605         .tokens = {
5606                 (void *)&cmd_setbypass_mode_set,
5607                 (void *)&cmd_setbypass_mode_bypass,
5608                 (void *)&cmd_setbypass_mode_mode,
5609                 (void *)&cmd_setbypass_mode_value,
5610                 (void *)&cmd_setbypass_mode_port,
5611                 NULL,
5612         },
5613 };
5614
5615 /* *** SET NIC BYPASS EVENT *** */
5616 struct cmd_set_bypass_event_result {
5617         cmdline_fixed_string_t set;
5618         cmdline_fixed_string_t bypass;
5619         cmdline_fixed_string_t event;
5620         cmdline_fixed_string_t event_value;
5621         cmdline_fixed_string_t mode;
5622         cmdline_fixed_string_t mode_value;
5623         portid_t port_id;
5624 };
5625
5626 static void
5627 cmd_set_bypass_event_parsed(void *parsed_result,
5628                 __rte_unused struct cmdline *cl,
5629                 __rte_unused void *data)
5630 {
5631         int32_t rc = -EINVAL;
5632         struct cmd_set_bypass_event_result *res = parsed_result;
5633         portid_t port_id = res->port_id;
5634
5635 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5636         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5637         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5638
5639         if (!strcmp(res->event_value, "timeout"))
5640                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5641         else if (!strcmp(res->event_value, "os_on"))
5642                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5643         else if (!strcmp(res->event_value, "os_off"))
5644                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5645         else if (!strcmp(res->event_value, "power_on"))
5646                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5647         else if (!strcmp(res->event_value, "power_off"))
5648                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5649         else
5650                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5651
5652         if (!strcmp(res->mode_value, "bypass"))
5653                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5654         else if (!strcmp(res->mode_value, "isolate"))
5655                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5656         else
5657                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5658
5659         /* Set the watchdog timeout. */
5660         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5661
5662                 rc = -EINVAL;
5663                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5664                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5665                                                            bypass_timeout);
5666                 }
5667                 if (rc != 0) {
5668                         printf("Failed to set timeout value %u "
5669                         "for port %d, errto code: %d.\n",
5670                         bypass_timeout, port_id, rc);
5671                 }
5672         }
5673
5674         /* Set the bypass event to transition to bypass mode. */
5675         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5676                                               bypass_mode);
5677 #endif
5678
5679         if (rc != 0)
5680                 printf("\t Failed to set bypass event for port = %d.\n",
5681                        port_id);
5682 }
5683
5684 cmdline_parse_token_string_t cmd_setbypass_event_set =
5685         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5686                         set, "set");
5687 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5688         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5689                         bypass, "bypass");
5690 cmdline_parse_token_string_t cmd_setbypass_event_event =
5691         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5692                         event, "event");
5693 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5694         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5695                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5696 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5697         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5698                         mode, "mode");
5699 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5700         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5701                         mode_value, "normal#bypass#isolate");
5702 cmdline_parse_token_num_t cmd_setbypass_event_port =
5703         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5704                                 port_id, UINT16);
5705
5706 cmdline_parse_inst_t cmd_set_bypass_event = {
5707         .f = cmd_set_bypass_event_parsed,
5708         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5709                 "power_off mode normal|bypass|isolate <port_id>: "
5710                 "Set the NIC bypass event mode for port_id",
5711         .data = NULL,
5712         .tokens = {
5713                 (void *)&cmd_setbypass_event_set,
5714                 (void *)&cmd_setbypass_event_bypass,
5715                 (void *)&cmd_setbypass_event_event,
5716                 (void *)&cmd_setbypass_event_event_value,
5717                 (void *)&cmd_setbypass_event_mode,
5718                 (void *)&cmd_setbypass_event_mode_value,
5719                 (void *)&cmd_setbypass_event_port,
5720                 NULL,
5721         },
5722 };
5723
5724
5725 /* *** SET NIC BYPASS TIMEOUT *** */
5726 struct cmd_set_bypass_timeout_result {
5727         cmdline_fixed_string_t set;
5728         cmdline_fixed_string_t bypass;
5729         cmdline_fixed_string_t timeout;
5730         cmdline_fixed_string_t value;
5731 };
5732
5733 static void
5734 cmd_set_bypass_timeout_parsed(void *parsed_result,
5735                 __rte_unused struct cmdline *cl,
5736                 __rte_unused void *data)
5737 {
5738         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5739
5740 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5741         if (!strcmp(res->value, "1.5"))
5742                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5743         else if (!strcmp(res->value, "2"))
5744                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5745         else if (!strcmp(res->value, "3"))
5746                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5747         else if (!strcmp(res->value, "4"))
5748                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5749         else if (!strcmp(res->value, "8"))
5750                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5751         else if (!strcmp(res->value, "16"))
5752                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5753         else if (!strcmp(res->value, "32"))
5754                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5755         else
5756                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5757 #endif
5758 }
5759
5760 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5761         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5762                         set, "set");
5763 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5764         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5765                         bypass, "bypass");
5766 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5767         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5768                         timeout, "timeout");
5769 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5770         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5771                         value, "0#1.5#2#3#4#8#16#32");
5772
5773 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5774         .f = cmd_set_bypass_timeout_parsed,
5775         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5776                 "Set the NIC bypass watchdog timeout in seconds",
5777         .data = NULL,
5778         .tokens = {
5779                 (void *)&cmd_setbypass_timeout_set,
5780                 (void *)&cmd_setbypass_timeout_bypass,
5781                 (void *)&cmd_setbypass_timeout_timeout,
5782                 (void *)&cmd_setbypass_timeout_value,
5783                 NULL,
5784         },
5785 };
5786
5787 /* *** SHOW NIC BYPASS MODE *** */
5788 struct cmd_show_bypass_config_result {
5789         cmdline_fixed_string_t show;
5790         cmdline_fixed_string_t bypass;
5791         cmdline_fixed_string_t config;
5792         portid_t port_id;
5793 };
5794
5795 static void
5796 cmd_show_bypass_config_parsed(void *parsed_result,
5797                 __rte_unused struct cmdline *cl,
5798                 __rte_unused void *data)
5799 {
5800         struct cmd_show_bypass_config_result *res = parsed_result;
5801         portid_t port_id = res->port_id;
5802         int rc = -EINVAL;
5803 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5804         uint32_t event_mode;
5805         uint32_t bypass_mode;
5806         uint32_t timeout = bypass_timeout;
5807         unsigned int i;
5808
5809         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5810                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5811         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5812                 {"UNKNOWN", "normal", "bypass", "isolate"};
5813         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5814                 "NONE",
5815                 "OS/board on",
5816                 "power supply on",
5817                 "OS/board off",
5818                 "power supply off",
5819                 "timeout"};
5820
5821         /* Display the bypass mode.*/
5822         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5823                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5824                 return;
5825         }
5826         else {
5827                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5828                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5829
5830                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5831         }
5832
5833         /* Display the bypass timeout.*/
5834         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5835                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5836
5837         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5838
5839         /* Display the bypass events and associated modes. */
5840         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5841
5842                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5843                         printf("\tFailed to get bypass mode for event = %s\n",
5844                                 events[i]);
5845                 } else {
5846                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5847                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5848
5849                         printf("\tbypass event: %-16s = %s\n", events[i],
5850                                 modes[event_mode]);
5851                 }
5852         }
5853 #endif
5854         if (rc != 0)
5855                 printf("\tFailed to get bypass configuration for port = %d\n",
5856                        port_id);
5857 }
5858
5859 cmdline_parse_token_string_t cmd_showbypass_config_show =
5860         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5861                         show, "show");
5862 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5863         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5864                         bypass, "bypass");
5865 cmdline_parse_token_string_t cmd_showbypass_config_config =
5866         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5867                         config, "config");
5868 cmdline_parse_token_num_t cmd_showbypass_config_port =
5869         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5870                                 port_id, UINT16);
5871
5872 cmdline_parse_inst_t cmd_show_bypass_config = {
5873         .f = cmd_show_bypass_config_parsed,
5874         .help_str = "show bypass config <port_id>: "
5875                     "Show the NIC bypass config for port_id",
5876         .data = NULL,
5877         .tokens = {
5878                 (void *)&cmd_showbypass_config_show,
5879                 (void *)&cmd_showbypass_config_bypass,
5880                 (void *)&cmd_showbypass_config_config,
5881                 (void *)&cmd_showbypass_config_port,
5882                 NULL,
5883         },
5884 };
5885
5886 #ifdef RTE_NET_BOND
5887 /* *** SET BONDING MODE *** */
5888 struct cmd_set_bonding_mode_result {
5889         cmdline_fixed_string_t set;
5890         cmdline_fixed_string_t bonding;
5891         cmdline_fixed_string_t mode;
5892         uint8_t value;
5893         portid_t port_id;
5894 };
5895
5896 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5897                 __rte_unused  struct cmdline *cl,
5898                 __rte_unused void *data)
5899 {
5900         struct cmd_set_bonding_mode_result *res = parsed_result;
5901         portid_t port_id = res->port_id;
5902
5903         /* Set the bonding mode for the relevant port. */
5904         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5905                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5906 }
5907
5908 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5909 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5910                 set, "set");
5911 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5912 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5913                 bonding, "bonding");
5914 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5915 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5916                 mode, "mode");
5917 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5918 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5919                 value, UINT8);
5920 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5921 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5922                 port_id, UINT16);
5923
5924 cmdline_parse_inst_t cmd_set_bonding_mode = {
5925                 .f = cmd_set_bonding_mode_parsed,
5926                 .help_str = "set bonding mode <mode_value> <port_id>: "
5927                         "Set the bonding mode for port_id",
5928                 .data = NULL,
5929                 .tokens = {
5930                                 (void *) &cmd_setbonding_mode_set,
5931                                 (void *) &cmd_setbonding_mode_bonding,
5932                                 (void *) &cmd_setbonding_mode_mode,
5933                                 (void *) &cmd_setbonding_mode_value,
5934                                 (void *) &cmd_setbonding_mode_port,
5935                                 NULL
5936                 }
5937 };
5938
5939 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5940 struct cmd_set_bonding_lacp_dedicated_queues_result {
5941         cmdline_fixed_string_t set;
5942         cmdline_fixed_string_t bonding;
5943         cmdline_fixed_string_t lacp;
5944         cmdline_fixed_string_t dedicated_queues;
5945         portid_t port_id;
5946         cmdline_fixed_string_t mode;
5947 };
5948
5949 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5950                 __rte_unused  struct cmdline *cl,
5951                 __rte_unused void *data)
5952 {
5953         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5954         portid_t port_id = res->port_id;
5955         struct rte_port *port;
5956
5957         port = &ports[port_id];
5958
5959         /** Check if the port is not started **/
5960         if (port->port_status != RTE_PORT_STOPPED) {
5961                 printf("Please stop port %d first\n", port_id);
5962                 return;
5963         }
5964
5965         if (!strcmp(res->mode, "enable")) {
5966                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5967                         printf("Dedicate queues for LACP control packets"
5968                                         " enabled\n");
5969                 else
5970                         printf("Enabling dedicate queues for LACP control "
5971                                         "packets on port %d failed\n", port_id);
5972         } else if (!strcmp(res->mode, "disable")) {
5973                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5974                         printf("Dedicated queues for LACP control packets "
5975                                         "disabled\n");
5976                 else
5977                         printf("Disabling dedicated queues for LACP control "
5978                                         "traffic on port %d failed\n", port_id);
5979         }
5980 }
5981
5982 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5983 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5984                 set, "set");
5985 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5986 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5987                 bonding, "bonding");
5988 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5989 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5990                 lacp, "lacp");
5991 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5992 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5993                 dedicated_queues, "dedicated_queues");
5994 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5995 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5996                 port_id, UINT16);
5997 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5998 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5999                 mode, "enable#disable");
6000
6001 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6002                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6003                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6004                         "enable|disable: "
6005                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6006                 .data = NULL,
6007                 .tokens = {
6008                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6009                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6010                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6011                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6012                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6013                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6014                         NULL
6015                 }
6016 };
6017
6018 /* *** SET BALANCE XMIT POLICY *** */
6019 struct cmd_set_bonding_balance_xmit_policy_result {
6020         cmdline_fixed_string_t set;
6021         cmdline_fixed_string_t bonding;
6022         cmdline_fixed_string_t balance_xmit_policy;
6023         portid_t port_id;
6024         cmdline_fixed_string_t policy;
6025 };
6026
6027 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6028                 __rte_unused  struct cmdline *cl,
6029                 __rte_unused void *data)
6030 {
6031         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6032         portid_t port_id = res->port_id;
6033         uint8_t policy;
6034
6035         if (!strcmp(res->policy, "l2")) {
6036                 policy = BALANCE_XMIT_POLICY_LAYER2;
6037         } else if (!strcmp(res->policy, "l23")) {
6038                 policy = BALANCE_XMIT_POLICY_LAYER23;
6039         } else if (!strcmp(res->policy, "l34")) {
6040                 policy = BALANCE_XMIT_POLICY_LAYER34;
6041         } else {
6042                 printf("\t Invalid xmit policy selection");
6043                 return;
6044         }
6045
6046         /* Set the bonding mode for the relevant port. */
6047         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6048                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
6049                                 port_id);
6050         }
6051 }
6052
6053 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6054 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6055                 set, "set");
6056 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6057 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6058                 bonding, "bonding");
6059 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6060 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6061                 balance_xmit_policy, "balance_xmit_policy");
6062 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6063 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6064                 port_id, UINT16);
6065 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6066 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6067                 policy, "l2#l23#l34");
6068
6069 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6070                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6071                 .help_str = "set bonding balance_xmit_policy <port_id> "
6072                         "l2|l23|l34: "
6073                         "Set the bonding balance_xmit_policy for port_id",
6074                 .data = NULL,
6075                 .tokens = {
6076                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6077                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6078                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6079                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6080                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6081                                 NULL
6082                 }
6083 };
6084
6085 /* *** SHOW NIC BONDING CONFIGURATION *** */
6086 struct cmd_show_bonding_config_result {
6087         cmdline_fixed_string_t show;
6088         cmdline_fixed_string_t bonding;
6089         cmdline_fixed_string_t config;
6090         portid_t port_id;
6091 };
6092
6093 static void cmd_show_bonding_config_parsed(void *parsed_result,
6094                 __rte_unused  struct cmdline *cl,
6095                 __rte_unused void *data)
6096 {
6097         struct cmd_show_bonding_config_result *res = parsed_result;
6098         int bonding_mode, agg_mode;
6099         portid_t slaves[RTE_MAX_ETHPORTS];
6100         int num_slaves, num_active_slaves;
6101         int primary_id;
6102         int i;
6103         portid_t port_id = res->port_id;
6104
6105         /* Display the bonding mode.*/
6106         bonding_mode = rte_eth_bond_mode_get(port_id);
6107         if (bonding_mode < 0) {
6108                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
6109                 return;
6110         } else
6111                 printf("\tBonding mode: %d\n", bonding_mode);
6112
6113         if (bonding_mode == BONDING_MODE_BALANCE) {
6114                 int balance_xmit_policy;
6115
6116                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6117                 if (balance_xmit_policy < 0) {
6118                         printf("\tFailed to get balance xmit policy for port = %d\n",
6119                                         port_id);
6120                         return;
6121                 } else {
6122                         printf("\tBalance Xmit Policy: ");
6123
6124                         switch (balance_xmit_policy) {
6125                         case BALANCE_XMIT_POLICY_LAYER2:
6126                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6127                                 break;
6128                         case BALANCE_XMIT_POLICY_LAYER23:
6129                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6130                                 break;
6131                         case BALANCE_XMIT_POLICY_LAYER34:
6132                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6133                                 break;
6134                         }
6135                         printf("\n");
6136                 }
6137         }
6138
6139         if (bonding_mode == BONDING_MODE_8023AD) {
6140                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6141                 printf("\tIEEE802.3AD Aggregator Mode: ");
6142                 switch (agg_mode) {
6143                 case AGG_BANDWIDTH:
6144                         printf("bandwidth");
6145                         break;
6146                 case AGG_STABLE:
6147                         printf("stable");
6148                         break;
6149                 case AGG_COUNT:
6150                         printf("count");
6151                         break;
6152                 }
6153                 printf("\n");
6154         }
6155
6156         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6157
6158         if (num_slaves < 0) {
6159                 printf("\tFailed to get slave list for port = %d\n", port_id);
6160                 return;
6161         }
6162         if (num_slaves > 0) {
6163                 printf("\tSlaves (%d): [", num_slaves);
6164                 for (i = 0; i < num_slaves - 1; i++)
6165                         printf("%d ", slaves[i]);
6166
6167                 printf("%d]\n", slaves[num_slaves - 1]);
6168         } else {
6169                 printf("\tSlaves: []\n");
6170
6171         }
6172
6173         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6174                         RTE_MAX_ETHPORTS);
6175
6176         if (num_active_slaves < 0) {
6177                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6178                 return;
6179         }
6180         if (num_active_slaves > 0) {
6181                 printf("\tActive Slaves (%d): [", num_active_slaves);
6182                 for (i = 0; i < num_active_slaves - 1; i++)
6183                         printf("%d ", slaves[i]);
6184
6185                 printf("%d]\n", slaves[num_active_slaves - 1]);
6186
6187         } else {
6188                 printf("\tActive Slaves: []\n");
6189
6190         }
6191
6192         primary_id = rte_eth_bond_primary_get(port_id);
6193         if (primary_id < 0) {
6194                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6195                 return;
6196         } else
6197                 printf("\tPrimary: [%d]\n", primary_id);
6198
6199 }
6200
6201 cmdline_parse_token_string_t cmd_showbonding_config_show =
6202 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6203                 show, "show");
6204 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6205 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6206                 bonding, "bonding");
6207 cmdline_parse_token_string_t cmd_showbonding_config_config =
6208 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6209                 config, "config");
6210 cmdline_parse_token_num_t cmd_showbonding_config_port =
6211 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6212                 port_id, UINT16);
6213
6214 cmdline_parse_inst_t cmd_show_bonding_config = {
6215                 .f = cmd_show_bonding_config_parsed,
6216                 .help_str = "show bonding config <port_id>: "
6217                         "Show the bonding config for port_id",
6218                 .data = NULL,
6219                 .tokens = {
6220                                 (void *)&cmd_showbonding_config_show,
6221                                 (void *)&cmd_showbonding_config_bonding,
6222                                 (void *)&cmd_showbonding_config_config,
6223                                 (void *)&cmd_showbonding_config_port,
6224                                 NULL
6225                 }
6226 };
6227
6228 /* *** SET BONDING PRIMARY *** */
6229 struct cmd_set_bonding_primary_result {
6230         cmdline_fixed_string_t set;
6231         cmdline_fixed_string_t bonding;
6232         cmdline_fixed_string_t primary;
6233         portid_t slave_id;
6234         portid_t port_id;
6235 };
6236
6237 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6238                 __rte_unused  struct cmdline *cl,
6239                 __rte_unused void *data)
6240 {
6241         struct cmd_set_bonding_primary_result *res = parsed_result;
6242         portid_t master_port_id = res->port_id;
6243         portid_t slave_port_id = res->slave_id;
6244
6245         /* Set the primary slave for a bonded device. */
6246         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6247                 printf("\t Failed to set primary slave for port = %d.\n",
6248                                 master_port_id);
6249                 return;
6250         }
6251         init_port_config();
6252 }
6253
6254 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6255 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6256                 set, "set");
6257 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6258 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6259                 bonding, "bonding");
6260 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6261 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6262                 primary, "primary");
6263 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6264 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6265                 slave_id, UINT16);
6266 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6267 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6268                 port_id, UINT16);
6269
6270 cmdline_parse_inst_t cmd_set_bonding_primary = {
6271                 .f = cmd_set_bonding_primary_parsed,
6272                 .help_str = "set bonding primary <slave_id> <port_id>: "
6273                         "Set the primary slave for port_id",
6274                 .data = NULL,
6275                 .tokens = {
6276                                 (void *)&cmd_setbonding_primary_set,
6277                                 (void *)&cmd_setbonding_primary_bonding,
6278                                 (void *)&cmd_setbonding_primary_primary,
6279                                 (void *)&cmd_setbonding_primary_slave,
6280                                 (void *)&cmd_setbonding_primary_port,
6281                                 NULL
6282                 }
6283 };
6284
6285 /* *** ADD SLAVE *** */
6286 struct cmd_add_bonding_slave_result {
6287         cmdline_fixed_string_t add;
6288         cmdline_fixed_string_t bonding;
6289         cmdline_fixed_string_t slave;
6290         portid_t slave_id;
6291         portid_t port_id;
6292 };
6293
6294 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6295                 __rte_unused  struct cmdline *cl,
6296                 __rte_unused void *data)
6297 {
6298         struct cmd_add_bonding_slave_result *res = parsed_result;
6299         portid_t master_port_id = res->port_id;
6300         portid_t slave_port_id = res->slave_id;
6301
6302         /* add the slave for a bonded device. */
6303         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6304                 printf("\t Failed to add slave %d to master port = %d.\n",
6305                                 slave_port_id, master_port_id);
6306                 return;
6307         }
6308         init_port_config();
6309         set_port_slave_flag(slave_port_id);
6310 }
6311
6312 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6313 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6314                 add, "add");
6315 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6316 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6317                 bonding, "bonding");
6318 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6319 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6320                 slave, "slave");
6321 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6322 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6323                 slave_id, UINT16);
6324 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6325 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6326                 port_id, UINT16);
6327
6328 cmdline_parse_inst_t cmd_add_bonding_slave = {
6329                 .f = cmd_add_bonding_slave_parsed,
6330                 .help_str = "add bonding slave <slave_id> <port_id>: "
6331                         "Add a slave device to a bonded device",
6332                 .data = NULL,
6333                 .tokens = {
6334                                 (void *)&cmd_addbonding_slave_add,
6335                                 (void *)&cmd_addbonding_slave_bonding,
6336                                 (void *)&cmd_addbonding_slave_slave,
6337                                 (void *)&cmd_addbonding_slave_slaveid,
6338                                 (void *)&cmd_addbonding_slave_port,
6339                                 NULL
6340                 }
6341 };
6342
6343 /* *** REMOVE SLAVE *** */
6344 struct cmd_remove_bonding_slave_result {
6345         cmdline_fixed_string_t remove;
6346         cmdline_fixed_string_t bonding;
6347         cmdline_fixed_string_t slave;
6348         portid_t slave_id;
6349         portid_t port_id;
6350 };
6351
6352 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6353                 __rte_unused  struct cmdline *cl,
6354                 __rte_unused void *data)
6355 {
6356         struct cmd_remove_bonding_slave_result *res = parsed_result;
6357         portid_t master_port_id = res->port_id;
6358         portid_t slave_port_id = res->slave_id;
6359
6360         /* remove the slave from a bonded device. */
6361         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6362                 printf("\t Failed to remove slave %d from master port = %d.\n",
6363                                 slave_port_id, master_port_id);
6364                 return;
6365         }
6366         init_port_config();
6367         clear_port_slave_flag(slave_port_id);
6368 }
6369
6370 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6371                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6372                                 remove, "remove");
6373 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6374                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6375                                 bonding, "bonding");
6376 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6377                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6378                                 slave, "slave");
6379 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6380                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6381                                 slave_id, UINT16);
6382 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6383                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6384                                 port_id, UINT16);
6385
6386 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6387                 .f = cmd_remove_bonding_slave_parsed,
6388                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6389                         "Remove a slave device from a bonded device",
6390                 .data = NULL,
6391                 .tokens = {
6392                                 (void *)&cmd_removebonding_slave_remove,
6393                                 (void *)&cmd_removebonding_slave_bonding,
6394                                 (void *)&cmd_removebonding_slave_slave,
6395                                 (void *)&cmd_removebonding_slave_slaveid,
6396                                 (void *)&cmd_removebonding_slave_port,
6397                                 NULL
6398                 }
6399 };
6400
6401 /* *** CREATE BONDED DEVICE *** */
6402 struct cmd_create_bonded_device_result {
6403         cmdline_fixed_string_t create;
6404         cmdline_fixed_string_t bonded;
6405         cmdline_fixed_string_t device;
6406         uint8_t mode;
6407         uint8_t socket;
6408 };
6409
6410 static int bond_dev_num = 0;
6411
6412 static void cmd_create_bonded_device_parsed(void *parsed_result,
6413                 __rte_unused  struct cmdline *cl,
6414                 __rte_unused void *data)
6415 {
6416         struct cmd_create_bonded_device_result *res = parsed_result;
6417         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6418         int port_id;
6419         int ret;
6420
6421         if (test_done == 0) {
6422                 printf("Please stop forwarding first\n");
6423                 return;
6424         }
6425
6426         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6427                         bond_dev_num++);
6428
6429         /* Create a new bonded device. */
6430         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6431         if (port_id < 0) {
6432                 printf("\t Failed to create bonded device.\n");
6433                 return;
6434         } else {
6435                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6436                                 port_id);
6437
6438                 /* Update number of ports */
6439                 nb_ports = rte_eth_dev_count_avail();
6440                 reconfig(port_id, res->socket);
6441                 ret = rte_eth_promiscuous_enable(port_id);
6442                 if (ret != 0)
6443                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6444                                 port_id, rte_strerror(-ret));
6445
6446                 ports[port_id].need_setup = 0;
6447                 ports[port_id].port_status = RTE_PORT_STOPPED;
6448         }
6449
6450 }
6451
6452 cmdline_parse_token_string_t cmd_createbonded_device_create =
6453                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6454                                 create, "create");
6455 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6456                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6457                                 bonded, "bonded");
6458 cmdline_parse_token_string_t cmd_createbonded_device_device =
6459                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6460                                 device, "device");
6461 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6462                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6463                                 mode, UINT8);
6464 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6465                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6466                                 socket, UINT8);
6467
6468 cmdline_parse_inst_t cmd_create_bonded_device = {
6469                 .f = cmd_create_bonded_device_parsed,
6470                 .help_str = "create bonded device <mode> <socket>: "
6471                         "Create a new bonded device with specific bonding mode and socket",
6472                 .data = NULL,
6473                 .tokens = {
6474                                 (void *)&cmd_createbonded_device_create,
6475                                 (void *)&cmd_createbonded_device_bonded,
6476                                 (void *)&cmd_createbonded_device_device,
6477                                 (void *)&cmd_createbonded_device_mode,
6478                                 (void *)&cmd_createbonded_device_socket,
6479                                 NULL
6480                 }
6481 };
6482
6483 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6484 struct cmd_set_bond_mac_addr_result {
6485         cmdline_fixed_string_t set;
6486         cmdline_fixed_string_t bonding;
6487         cmdline_fixed_string_t mac_addr;
6488         uint16_t port_num;
6489         struct rte_ether_addr address;
6490 };
6491
6492 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6493                 __rte_unused  struct cmdline *cl,
6494                 __rte_unused void *data)
6495 {
6496         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6497         int ret;
6498
6499         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6500                 return;
6501
6502         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6503
6504         /* check the return value and print it if is < 0 */
6505         if (ret < 0)
6506                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6507 }
6508
6509 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6510                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6511 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6512                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6513                                 "bonding");
6514 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6515                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6516                                 "mac_addr");
6517 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6518                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6519                                 port_num, UINT16);
6520 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6521                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6522
6523 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6524                 .f = cmd_set_bond_mac_addr_parsed,
6525                 .data = (void *) 0,
6526                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6527                 .tokens = {
6528                                 (void *)&cmd_set_bond_mac_addr_set,
6529                                 (void *)&cmd_set_bond_mac_addr_bonding,
6530                                 (void *)&cmd_set_bond_mac_addr_mac,
6531                                 (void *)&cmd_set_bond_mac_addr_portnum,
6532                                 (void *)&cmd_set_bond_mac_addr_addr,
6533                                 NULL
6534                 }
6535 };
6536
6537
6538 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6539 struct cmd_set_bond_mon_period_result {
6540         cmdline_fixed_string_t set;
6541         cmdline_fixed_string_t bonding;
6542         cmdline_fixed_string_t mon_period;
6543         uint16_t port_num;
6544         uint32_t period_ms;
6545 };
6546
6547 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6548                 __rte_unused  struct cmdline *cl,
6549                 __rte_unused void *data)
6550 {
6551         struct cmd_set_bond_mon_period_result *res = parsed_result;
6552         int ret;
6553
6554         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6555
6556         /* check the return value and print it if is < 0 */
6557         if (ret < 0)
6558                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6559 }
6560
6561 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6562                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6563                                 set, "set");
6564 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6565                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6566                                 bonding, "bonding");
6567 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6568                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6569                                 mon_period,     "mon_period");
6570 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6571                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6572                                 port_num, UINT16);
6573 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6574                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6575                                 period_ms, UINT32);
6576
6577 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6578                 .f = cmd_set_bond_mon_period_parsed,
6579                 .data = (void *) 0,
6580                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6581                 .tokens = {
6582                                 (void *)&cmd_set_bond_mon_period_set,
6583                                 (void *)&cmd_set_bond_mon_period_bonding,
6584                                 (void *)&cmd_set_bond_mon_period_mon_period,
6585                                 (void *)&cmd_set_bond_mon_period_portnum,
6586                                 (void *)&cmd_set_bond_mon_period_period_ms,
6587                                 NULL
6588                 }
6589 };
6590
6591
6592
6593 struct cmd_set_bonding_agg_mode_policy_result {
6594         cmdline_fixed_string_t set;
6595         cmdline_fixed_string_t bonding;
6596         cmdline_fixed_string_t agg_mode;
6597         uint16_t port_num;
6598         cmdline_fixed_string_t policy;
6599 };
6600
6601
6602 static void
6603 cmd_set_bonding_agg_mode(void *parsed_result,
6604                 __rte_unused struct cmdline *cl,
6605                 __rte_unused void *data)
6606 {
6607         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6608         uint8_t policy = AGG_BANDWIDTH;
6609
6610         if (!strcmp(res->policy, "bandwidth"))
6611                 policy = AGG_BANDWIDTH;
6612         else if (!strcmp(res->policy, "stable"))
6613                 policy = AGG_STABLE;
6614         else if (!strcmp(res->policy, "count"))
6615                 policy = AGG_COUNT;
6616
6617         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6618 }
6619
6620
6621 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6622         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6623                                 set, "set");
6624 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6625         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6626                                 bonding, "bonding");
6627
6628 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6629         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6630                                 agg_mode, "agg_mode");
6631
6632 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6633         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6634                                 port_num, UINT16);
6635
6636 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6637         TOKEN_STRING_INITIALIZER(
6638                         struct cmd_set_bonding_balance_xmit_policy_result,
6639                 policy, "stable#bandwidth#count");
6640
6641 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6642         .f = cmd_set_bonding_agg_mode,
6643         .data = (void *) 0,
6644         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6645         .tokens = {
6646                         (void *)&cmd_set_bonding_agg_mode_set,
6647                         (void *)&cmd_set_bonding_agg_mode_bonding,
6648                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6649                         (void *)&cmd_set_bonding_agg_mode_portnum,
6650                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6651                         NULL
6652                 }
6653 };
6654
6655
6656 #endif /* RTE_NET_BOND */
6657
6658 /* *** SET FORWARDING MODE *** */
6659 struct cmd_set_fwd_mode_result {
6660         cmdline_fixed_string_t set;
6661         cmdline_fixed_string_t fwd;
6662         cmdline_fixed_string_t mode;
6663 };
6664
6665 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6666                                     __rte_unused struct cmdline *cl,
6667                                     __rte_unused void *data)
6668 {
6669         struct cmd_set_fwd_mode_result *res = parsed_result;
6670
6671         retry_enabled = 0;
6672         set_pkt_forwarding_mode(res->mode);
6673 }
6674
6675 cmdline_parse_token_string_t cmd_setfwd_set =
6676         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6677 cmdline_parse_token_string_t cmd_setfwd_fwd =
6678         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6679 cmdline_parse_token_string_t cmd_setfwd_mode =
6680         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6681                 "" /* defined at init */);
6682
6683 cmdline_parse_inst_t cmd_set_fwd_mode = {
6684         .f = cmd_set_fwd_mode_parsed,
6685         .data = NULL,
6686         .help_str = NULL, /* defined at init */
6687         .tokens = {
6688                 (void *)&cmd_setfwd_set,
6689                 (void *)&cmd_setfwd_fwd,
6690                 (void *)&cmd_setfwd_mode,
6691                 NULL,
6692         },
6693 };
6694
6695 static void cmd_set_fwd_mode_init(void)
6696 {
6697         char *modes, *c;
6698         static char token[128];
6699         static char help[256];
6700         cmdline_parse_token_string_t *token_struct;
6701
6702         modes = list_pkt_forwarding_modes();
6703         snprintf(help, sizeof(help), "set fwd %s: "
6704                 "Set packet forwarding mode", modes);
6705         cmd_set_fwd_mode.help_str = help;
6706
6707         /* string token separator is # */
6708         for (c = token; *modes != '\0'; modes++)
6709                 if (*modes == '|')
6710                         *c++ = '#';
6711                 else
6712                         *c++ = *modes;
6713         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6714         token_struct->string_data.str = token;
6715 }
6716
6717 /* *** SET RETRY FORWARDING MODE *** */
6718 struct cmd_set_fwd_retry_mode_result {
6719         cmdline_fixed_string_t set;
6720         cmdline_fixed_string_t fwd;
6721         cmdline_fixed_string_t mode;
6722         cmdline_fixed_string_t retry;
6723 };
6724
6725 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6726                             __rte_unused struct cmdline *cl,
6727                             __rte_unused void *data)
6728 {
6729         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6730
6731         retry_enabled = 1;
6732         set_pkt_forwarding_mode(res->mode);
6733 }
6734
6735 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6736         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6737                         set, "set");
6738 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6739         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6740                         fwd, "fwd");
6741 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6742         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6743                         mode,
6744                 "" /* defined at init */);
6745 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6746         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6747                         retry, "retry");
6748
6749 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6750         .f = cmd_set_fwd_retry_mode_parsed,
6751         .data = NULL,
6752         .help_str = NULL, /* defined at init */
6753         .tokens = {
6754                 (void *)&cmd_setfwd_retry_set,
6755                 (void *)&cmd_setfwd_retry_fwd,
6756                 (void *)&cmd_setfwd_retry_mode,
6757                 (void *)&cmd_setfwd_retry_retry,
6758                 NULL,
6759         },
6760 };
6761
6762 static void cmd_set_fwd_retry_mode_init(void)
6763 {
6764         char *modes, *c;
6765         static char token[128];
6766         static char help[256];
6767         cmdline_parse_token_string_t *token_struct;
6768
6769         modes = list_pkt_forwarding_retry_modes();
6770         snprintf(help, sizeof(help), "set fwd %s retry: "
6771                 "Set packet forwarding mode with retry", modes);
6772         cmd_set_fwd_retry_mode.help_str = help;
6773
6774         /* string token separator is # */
6775         for (c = token; *modes != '\0'; modes++)
6776                 if (*modes == '|')
6777                         *c++ = '#';
6778                 else
6779                         *c++ = *modes;
6780         token_struct = (cmdline_parse_token_string_t *)
6781                 cmd_set_fwd_retry_mode.tokens[2];
6782         token_struct->string_data.str = token;
6783 }
6784
6785 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6786 struct cmd_set_burst_tx_retry_result {
6787         cmdline_fixed_string_t set;
6788         cmdline_fixed_string_t burst;
6789         cmdline_fixed_string_t tx;
6790         cmdline_fixed_string_t delay;
6791         uint32_t time;
6792         cmdline_fixed_string_t retry;
6793         uint32_t retry_num;
6794 };
6795
6796 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6797                                         __rte_unused struct cmdline *cl,
6798                                         __rte_unused void *data)
6799 {
6800         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6801
6802         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6803                 && !strcmp(res->tx, "tx")) {
6804                 if (!strcmp(res->delay, "delay"))
6805                         burst_tx_delay_time = res->time;
6806                 if (!strcmp(res->retry, "retry"))
6807                         burst_tx_retry_num = res->retry_num;
6808         }
6809
6810 }
6811
6812 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6813         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6814 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6815         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6816                                  "burst");
6817 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6818         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6819 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6820         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6821 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6822         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6823 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6824         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6825 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6826         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6827
6828 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6829         .f = cmd_set_burst_tx_retry_parsed,
6830         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6831         .tokens = {
6832                 (void *)&cmd_set_burst_tx_retry_set,
6833                 (void *)&cmd_set_burst_tx_retry_burst,
6834                 (void *)&cmd_set_burst_tx_retry_tx,
6835                 (void *)&cmd_set_burst_tx_retry_delay,
6836                 (void *)&cmd_set_burst_tx_retry_time,
6837                 (void *)&cmd_set_burst_tx_retry_retry,
6838                 (void *)&cmd_set_burst_tx_retry_retry_num,
6839                 NULL,
6840         },
6841 };
6842
6843 /* *** SET PROMISC MODE *** */
6844 struct cmd_set_promisc_mode_result {
6845         cmdline_fixed_string_t set;
6846         cmdline_fixed_string_t promisc;
6847         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6848         uint16_t port_num;               /* valid if "allports" argument == 0 */
6849         cmdline_fixed_string_t mode;
6850 };
6851
6852 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6853                                         __rte_unused struct cmdline *cl,
6854                                         void *allports)
6855 {
6856         struct cmd_set_promisc_mode_result *res = parsed_result;
6857         int enable;
6858         portid_t i;
6859
6860         if (!strcmp(res->mode, "on"))
6861                 enable = 1;
6862         else
6863                 enable = 0;
6864
6865         /* all ports */
6866         if (allports) {
6867                 RTE_ETH_FOREACH_DEV(i)
6868                         eth_set_promisc_mode(i, enable);
6869         } else {
6870                 eth_set_promisc_mode(res->port_num, enable);
6871         }
6872 }
6873
6874 cmdline_parse_token_string_t cmd_setpromisc_set =
6875         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6876 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6877         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6878                                  "promisc");
6879 cmdline_parse_token_string_t cmd_setpromisc_portall =
6880         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6881                                  "all");
6882 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6883         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6884                               UINT16);
6885 cmdline_parse_token_string_t cmd_setpromisc_mode =
6886         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6887                                  "on#off");
6888
6889 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6890         .f = cmd_set_promisc_mode_parsed,
6891         .data = (void *)1,
6892         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6893         .tokens = {
6894                 (void *)&cmd_setpromisc_set,
6895                 (void *)&cmd_setpromisc_promisc,
6896                 (void *)&cmd_setpromisc_portall,
6897                 (void *)&cmd_setpromisc_mode,
6898                 NULL,
6899         },
6900 };
6901
6902 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6903         .f = cmd_set_promisc_mode_parsed,
6904         .data = (void *)0,
6905         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6906         .tokens = {
6907                 (void *)&cmd_setpromisc_set,
6908                 (void *)&cmd_setpromisc_promisc,
6909                 (void *)&cmd_setpromisc_portnum,
6910                 (void *)&cmd_setpromisc_mode,
6911                 NULL,
6912         },
6913 };
6914
6915 /* *** SET ALLMULTI MODE *** */
6916 struct cmd_set_allmulti_mode_result {
6917         cmdline_fixed_string_t set;
6918         cmdline_fixed_string_t allmulti;
6919         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6920         uint16_t port_num;               /* valid if "allports" argument == 0 */
6921         cmdline_fixed_string_t mode;
6922 };
6923
6924 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6925                                         __rte_unused struct cmdline *cl,
6926                                         void *allports)
6927 {
6928         struct cmd_set_allmulti_mode_result *res = parsed_result;
6929         int enable;
6930         portid_t i;
6931
6932         if (!strcmp(res->mode, "on"))
6933                 enable = 1;
6934         else
6935                 enable = 0;
6936
6937         /* all ports */
6938         if (allports) {
6939                 RTE_ETH_FOREACH_DEV(i) {
6940                         eth_set_allmulticast_mode(i, enable);
6941                 }
6942         }
6943         else {
6944                 eth_set_allmulticast_mode(res->port_num, enable);
6945         }
6946 }
6947
6948 cmdline_parse_token_string_t cmd_setallmulti_set =
6949         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6950 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6951         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6952                                  "allmulti");
6953 cmdline_parse_token_string_t cmd_setallmulti_portall =
6954         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6955                                  "all");
6956 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6957         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6958                               UINT16);
6959 cmdline_parse_token_string_t cmd_setallmulti_mode =
6960         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6961                                  "on#off");
6962
6963 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6964         .f = cmd_set_allmulti_mode_parsed,
6965         .data = (void *)1,
6966         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6967         .tokens = {
6968                 (void *)&cmd_setallmulti_set,
6969                 (void *)&cmd_setallmulti_allmulti,
6970                 (void *)&cmd_setallmulti_portall,
6971                 (void *)&cmd_setallmulti_mode,
6972                 NULL,
6973         },
6974 };
6975
6976 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6977         .f = cmd_set_allmulti_mode_parsed,
6978         .data = (void *)0,
6979         .help_str = "set allmulti <port_id> on|off: "
6980                 "Set allmulti mode on port_id",
6981         .tokens = {
6982                 (void *)&cmd_setallmulti_set,
6983                 (void *)&cmd_setallmulti_allmulti,
6984                 (void *)&cmd_setallmulti_portnum,
6985                 (void *)&cmd_setallmulti_mode,
6986                 NULL,
6987         },
6988 };
6989
6990 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6991 struct cmd_link_flow_ctrl_set_result {
6992         cmdline_fixed_string_t set;
6993         cmdline_fixed_string_t flow_ctrl;
6994         cmdline_fixed_string_t rx;
6995         cmdline_fixed_string_t rx_lfc_mode;
6996         cmdline_fixed_string_t tx;
6997         cmdline_fixed_string_t tx_lfc_mode;
6998         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6999         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7000         cmdline_fixed_string_t autoneg_str;
7001         cmdline_fixed_string_t autoneg;
7002         cmdline_fixed_string_t hw_str;
7003         uint32_t high_water;
7004         cmdline_fixed_string_t lw_str;
7005         uint32_t low_water;
7006         cmdline_fixed_string_t pt_str;
7007         uint16_t pause_time;
7008         cmdline_fixed_string_t xon_str;
7009         uint16_t send_xon;
7010         portid_t port_id;
7011 };
7012
7013 cmdline_parse_token_string_t cmd_lfc_set_set =
7014         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7015                                 set, "set");
7016 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7017         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7018                                 flow_ctrl, "flow_ctrl");
7019 cmdline_parse_token_string_t cmd_lfc_set_rx =
7020         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7021                                 rx, "rx");
7022 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7023         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7024                                 rx_lfc_mode, "on#off");
7025 cmdline_parse_token_string_t cmd_lfc_set_tx =
7026         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7027                                 tx, "tx");
7028 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7029         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7030                                 tx_lfc_mode, "on#off");
7031 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7032         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7033                                 hw_str, "high_water");
7034 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7035         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7036                                 high_water, UINT32);
7037 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7038         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7039                                 lw_str, "low_water");
7040 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7041         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7042                                 low_water, UINT32);
7043 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7044         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7045                                 pt_str, "pause_time");
7046 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7047         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7048                                 pause_time, UINT16);
7049 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7050         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7051                                 xon_str, "send_xon");
7052 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7053         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7054                                 send_xon, UINT16);
7055 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7056         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7057                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7058 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7059         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7060                                 mac_ctrl_frame_fwd_mode, "on#off");
7061 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7062         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7063                                 autoneg_str, "autoneg");
7064 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7065         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7066                                 autoneg, "on#off");
7067 cmdline_parse_token_num_t cmd_lfc_set_portid =
7068         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7069                                 port_id, UINT16);
7070
7071 /* forward declaration */
7072 static void
7073 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7074                               void *data);
7075
7076 cmdline_parse_inst_t cmd_link_flow_control_set = {
7077         .f = cmd_link_flow_ctrl_set_parsed,
7078         .data = NULL,
7079         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7080                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7081                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7082         .tokens = {
7083                 (void *)&cmd_lfc_set_set,
7084                 (void *)&cmd_lfc_set_flow_ctrl,
7085                 (void *)&cmd_lfc_set_rx,
7086                 (void *)&cmd_lfc_set_rx_mode,
7087                 (void *)&cmd_lfc_set_tx,
7088                 (void *)&cmd_lfc_set_tx_mode,
7089                 (void *)&cmd_lfc_set_high_water,
7090                 (void *)&cmd_lfc_set_low_water,
7091                 (void *)&cmd_lfc_set_pause_time,
7092                 (void *)&cmd_lfc_set_send_xon,
7093                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7094                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7095                 (void *)&cmd_lfc_set_autoneg_str,
7096                 (void *)&cmd_lfc_set_autoneg,
7097                 (void *)&cmd_lfc_set_portid,
7098                 NULL,
7099         },
7100 };
7101
7102 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7103         .f = cmd_link_flow_ctrl_set_parsed,
7104         .data = (void *)&cmd_link_flow_control_set_rx,
7105         .help_str = "set flow_ctrl rx on|off <port_id>: "
7106                 "Change rx flow control parameter",
7107         .tokens = {
7108                 (void *)&cmd_lfc_set_set,
7109                 (void *)&cmd_lfc_set_flow_ctrl,
7110                 (void *)&cmd_lfc_set_rx,
7111                 (void *)&cmd_lfc_set_rx_mode,
7112                 (void *)&cmd_lfc_set_portid,
7113                 NULL,
7114         },
7115 };
7116
7117 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7118         .f = cmd_link_flow_ctrl_set_parsed,
7119         .data = (void *)&cmd_link_flow_control_set_tx,
7120         .help_str = "set flow_ctrl tx on|off <port_id>: "
7121                 "Change tx flow control parameter",
7122         .tokens = {
7123                 (void *)&cmd_lfc_set_set,
7124                 (void *)&cmd_lfc_set_flow_ctrl,
7125                 (void *)&cmd_lfc_set_tx,
7126                 (void *)&cmd_lfc_set_tx_mode,
7127                 (void *)&cmd_lfc_set_portid,
7128                 NULL,
7129         },
7130 };
7131
7132 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7133         .f = cmd_link_flow_ctrl_set_parsed,
7134         .data = (void *)&cmd_link_flow_control_set_hw,
7135         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7136                 "Change high water flow control parameter",
7137         .tokens = {
7138                 (void *)&cmd_lfc_set_set,
7139                 (void *)&cmd_lfc_set_flow_ctrl,
7140                 (void *)&cmd_lfc_set_high_water_str,
7141                 (void *)&cmd_lfc_set_high_water,
7142                 (void *)&cmd_lfc_set_portid,
7143                 NULL,
7144         },
7145 };
7146
7147 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7148         .f = cmd_link_flow_ctrl_set_parsed,
7149         .data = (void *)&cmd_link_flow_control_set_lw,
7150         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7151                 "Change low water flow control parameter",
7152         .tokens = {
7153                 (void *)&cmd_lfc_set_set,
7154                 (void *)&cmd_lfc_set_flow_ctrl,
7155                 (void *)&cmd_lfc_set_low_water_str,
7156                 (void *)&cmd_lfc_set_low_water,
7157                 (void *)&cmd_lfc_set_portid,
7158                 NULL,
7159         },
7160 };
7161
7162 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7163         .f = cmd_link_flow_ctrl_set_parsed,
7164         .data = (void *)&cmd_link_flow_control_set_pt,
7165         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7166                 "Change pause time flow control parameter",
7167         .tokens = {
7168                 (void *)&cmd_lfc_set_set,
7169                 (void *)&cmd_lfc_set_flow_ctrl,
7170                 (void *)&cmd_lfc_set_pause_time_str,
7171                 (void *)&cmd_lfc_set_pause_time,
7172                 (void *)&cmd_lfc_set_portid,
7173                 NULL,
7174         },
7175 };
7176
7177 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7178         .f = cmd_link_flow_ctrl_set_parsed,
7179         .data = (void *)&cmd_link_flow_control_set_xon,
7180         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7181                 "Change send_xon flow control parameter",
7182         .tokens = {
7183                 (void *)&cmd_lfc_set_set,
7184                 (void *)&cmd_lfc_set_flow_ctrl,
7185                 (void *)&cmd_lfc_set_send_xon_str,
7186                 (void *)&cmd_lfc_set_send_xon,
7187                 (void *)&cmd_lfc_set_portid,
7188                 NULL,
7189         },
7190 };
7191
7192 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7193         .f = cmd_link_flow_ctrl_set_parsed,
7194         .data = (void *)&cmd_link_flow_control_set_macfwd,
7195         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7196                 "Change mac ctrl fwd flow control parameter",
7197         .tokens = {
7198                 (void *)&cmd_lfc_set_set,
7199                 (void *)&cmd_lfc_set_flow_ctrl,
7200                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7201                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7202                 (void *)&cmd_lfc_set_portid,
7203                 NULL,
7204         },
7205 };
7206
7207 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7208         .f = cmd_link_flow_ctrl_set_parsed,
7209         .data = (void *)&cmd_link_flow_control_set_autoneg,
7210         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7211                 "Change autoneg flow control parameter",
7212         .tokens = {
7213                 (void *)&cmd_lfc_set_set,
7214                 (void *)&cmd_lfc_set_flow_ctrl,
7215                 (void *)&cmd_lfc_set_autoneg_str,
7216                 (void *)&cmd_lfc_set_autoneg,
7217                 (void *)&cmd_lfc_set_portid,
7218                 NULL,
7219         },
7220 };
7221
7222 static void
7223 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7224                               __rte_unused struct cmdline *cl,
7225                               void *data)
7226 {
7227         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7228         cmdline_parse_inst_t *cmd = data;
7229         struct rte_eth_fc_conf fc_conf;
7230         int rx_fc_en = 0;
7231         int tx_fc_en = 0;
7232         int ret;
7233
7234         /*
7235          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7236          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7237          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7238          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7239          */
7240         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7241                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7242         };
7243
7244         /* Partial command line, retrieve current configuration */
7245         if (cmd) {
7246                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7247                 if (ret != 0) {
7248                         printf("cannot get current flow ctrl parameters, return"
7249                                "code = %d\n", ret);
7250                         return;
7251                 }
7252
7253                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7254                     (fc_conf.mode == RTE_FC_FULL))
7255                         rx_fc_en = 1;
7256                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7257                     (fc_conf.mode == RTE_FC_FULL))
7258                         tx_fc_en = 1;
7259         }
7260
7261         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7262                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7263
7264         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7265                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7266
7267         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7268
7269         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7270                 fc_conf.high_water = res->high_water;
7271
7272         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7273                 fc_conf.low_water = res->low_water;
7274
7275         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7276                 fc_conf.pause_time = res->pause_time;
7277
7278         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7279                 fc_conf.send_xon = res->send_xon;
7280
7281         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7282                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7283                         fc_conf.mac_ctrl_frame_fwd = 1;
7284                 else
7285                         fc_conf.mac_ctrl_frame_fwd = 0;
7286         }
7287
7288         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7289                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7290
7291         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7292         if (ret != 0)
7293                 printf("bad flow contrl parameter, return code = %d \n", ret);
7294 }
7295
7296 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7297 struct cmd_priority_flow_ctrl_set_result {
7298         cmdline_fixed_string_t set;
7299         cmdline_fixed_string_t pfc_ctrl;
7300         cmdline_fixed_string_t rx;
7301         cmdline_fixed_string_t rx_pfc_mode;
7302         cmdline_fixed_string_t tx;
7303         cmdline_fixed_string_t tx_pfc_mode;
7304         uint32_t high_water;
7305         uint32_t low_water;
7306         uint16_t pause_time;
7307         uint8_t  priority;
7308         portid_t port_id;
7309 };
7310
7311 static void
7312 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7313                        __rte_unused struct cmdline *cl,
7314                        __rte_unused void *data)
7315 {
7316         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7317         struct rte_eth_pfc_conf pfc_conf;
7318         int rx_fc_enable, tx_fc_enable;
7319         int ret;
7320
7321         /*
7322          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7323          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7324          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7325          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7326          */
7327         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7328                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7329         };
7330
7331         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7332         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7333         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7334         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7335         pfc_conf.fc.high_water = res->high_water;
7336         pfc_conf.fc.low_water  = res->low_water;
7337         pfc_conf.fc.pause_time = res->pause_time;
7338         pfc_conf.priority      = res->priority;
7339
7340         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7341         if (ret != 0)
7342                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7343 }
7344
7345 cmdline_parse_token_string_t cmd_pfc_set_set =
7346         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7347                                 set, "set");
7348 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7349         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7350                                 pfc_ctrl, "pfc_ctrl");
7351 cmdline_parse_token_string_t cmd_pfc_set_rx =
7352         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7353                                 rx, "rx");
7354 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7355         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7356                                 rx_pfc_mode, "on#off");
7357 cmdline_parse_token_string_t cmd_pfc_set_tx =
7358         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7359                                 tx, "tx");
7360 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7361         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7362                                 tx_pfc_mode, "on#off");
7363 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7364         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7365                                 high_water, UINT32);
7366 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7367         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7368                                 low_water, UINT32);
7369 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7370         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7371                                 pause_time, UINT16);
7372 cmdline_parse_token_num_t cmd_pfc_set_priority =
7373         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7374                                 priority, UINT8);
7375 cmdline_parse_token_num_t cmd_pfc_set_portid =
7376         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7377                                 port_id, UINT16);
7378
7379 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7380         .f = cmd_priority_flow_ctrl_set_parsed,
7381         .data = NULL,
7382         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7383                 "<pause_time> <priority> <port_id>: "
7384                 "Configure the Ethernet priority flow control",
7385         .tokens = {
7386                 (void *)&cmd_pfc_set_set,
7387                 (void *)&cmd_pfc_set_flow_ctrl,
7388                 (void *)&cmd_pfc_set_rx,
7389                 (void *)&cmd_pfc_set_rx_mode,
7390                 (void *)&cmd_pfc_set_tx,
7391                 (void *)&cmd_pfc_set_tx_mode,
7392                 (void *)&cmd_pfc_set_high_water,
7393                 (void *)&cmd_pfc_set_low_water,
7394                 (void *)&cmd_pfc_set_pause_time,
7395                 (void *)&cmd_pfc_set_priority,
7396                 (void *)&cmd_pfc_set_portid,
7397                 NULL,
7398         },
7399 };
7400
7401 /* *** RESET CONFIGURATION *** */
7402 struct cmd_reset_result {
7403         cmdline_fixed_string_t reset;
7404         cmdline_fixed_string_t def;
7405 };
7406
7407 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7408                              struct cmdline *cl,
7409                              __rte_unused void *data)
7410 {
7411         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7412         set_def_fwd_config();
7413 }
7414
7415 cmdline_parse_token_string_t cmd_reset_set =
7416         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7417 cmdline_parse_token_string_t cmd_reset_def =
7418         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7419                                  "default");
7420
7421 cmdline_parse_inst_t cmd_reset = {
7422         .f = cmd_reset_parsed,
7423         .data = NULL,
7424         .help_str = "set default: Reset default forwarding configuration",
7425         .tokens = {
7426                 (void *)&cmd_reset_set,
7427                 (void *)&cmd_reset_def,
7428                 NULL,
7429         },
7430 };
7431
7432 /* *** START FORWARDING *** */
7433 struct cmd_start_result {
7434         cmdline_fixed_string_t start;
7435 };
7436
7437 cmdline_parse_token_string_t cmd_start_start =
7438         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7439
7440 static void cmd_start_parsed(__rte_unused void *parsed_result,
7441                              __rte_unused struct cmdline *cl,
7442                              __rte_unused void *data)
7443 {
7444         start_packet_forwarding(0);
7445 }
7446
7447 cmdline_parse_inst_t cmd_start = {
7448         .f = cmd_start_parsed,
7449         .data = NULL,
7450         .help_str = "start: Start packet forwarding",
7451         .tokens = {
7452                 (void *)&cmd_start_start,
7453                 NULL,
7454         },
7455 };
7456
7457 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7458 struct cmd_start_tx_first_result {
7459         cmdline_fixed_string_t start;
7460         cmdline_fixed_string_t tx_first;
7461 };
7462
7463 static void
7464 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7465                           __rte_unused struct cmdline *cl,
7466                           __rte_unused void *data)
7467 {
7468         start_packet_forwarding(1);
7469 }
7470
7471 cmdline_parse_token_string_t cmd_start_tx_first_start =
7472         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7473                                  "start");
7474 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7475         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7476                                  tx_first, "tx_first");
7477
7478 cmdline_parse_inst_t cmd_start_tx_first = {
7479         .f = cmd_start_tx_first_parsed,
7480         .data = NULL,
7481         .help_str = "start tx_first: Start packet forwarding, "
7482                 "after sending 1 burst of packets",
7483         .tokens = {
7484                 (void *)&cmd_start_tx_first_start,
7485                 (void *)&cmd_start_tx_first_tx_first,
7486                 NULL,
7487         },
7488 };
7489
7490 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7491 struct cmd_start_tx_first_n_result {
7492         cmdline_fixed_string_t start;
7493         cmdline_fixed_string_t tx_first;
7494         uint32_t tx_num;
7495 };
7496
7497 static void
7498 cmd_start_tx_first_n_parsed(void *parsed_result,
7499                           __rte_unused struct cmdline *cl,
7500                           __rte_unused void *data)
7501 {
7502         struct cmd_start_tx_first_n_result *res = parsed_result;
7503
7504         start_packet_forwarding(res->tx_num);
7505 }
7506
7507 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7508         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7509                         start, "start");
7510 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7511         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7512                         tx_first, "tx_first");
7513 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7514         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7515                         tx_num, UINT32);
7516
7517 cmdline_parse_inst_t cmd_start_tx_first_n = {
7518         .f = cmd_start_tx_first_n_parsed,
7519         .data = NULL,
7520         .help_str = "start tx_first <num>: "
7521                 "packet forwarding, after sending <num> bursts of packets",
7522         .tokens = {
7523                 (void *)&cmd_start_tx_first_n_start,
7524                 (void *)&cmd_start_tx_first_n_tx_first,
7525                 (void *)&cmd_start_tx_first_n_tx_num,
7526                 NULL,
7527         },
7528 };
7529
7530 /* *** SET LINK UP *** */
7531 struct cmd_set_link_up_result {
7532         cmdline_fixed_string_t set;
7533         cmdline_fixed_string_t link_up;
7534         cmdline_fixed_string_t port;
7535         portid_t port_id;
7536 };
7537
7538 cmdline_parse_token_string_t cmd_set_link_up_set =
7539         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7540 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7541         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7542                                 "link-up");
7543 cmdline_parse_token_string_t cmd_set_link_up_port =
7544         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7545 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7546         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7547
7548 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7549                              __rte_unused struct cmdline *cl,
7550                              __rte_unused void *data)
7551 {
7552         struct cmd_set_link_up_result *res = parsed_result;
7553         dev_set_link_up(res->port_id);
7554 }
7555
7556 cmdline_parse_inst_t cmd_set_link_up = {
7557         .f = cmd_set_link_up_parsed,
7558         .data = NULL,
7559         .help_str = "set link-up port <port id>",
7560         .tokens = {
7561                 (void *)&cmd_set_link_up_set,
7562                 (void *)&cmd_set_link_up_link_up,
7563                 (void *)&cmd_set_link_up_port,
7564                 (void *)&cmd_set_link_up_port_id,
7565                 NULL,
7566         },
7567 };
7568
7569 /* *** SET LINK DOWN *** */
7570 struct cmd_set_link_down_result {
7571         cmdline_fixed_string_t set;
7572         cmdline_fixed_string_t link_down;
7573         cmdline_fixed_string_t port;
7574         portid_t port_id;
7575 };
7576
7577 cmdline_parse_token_string_t cmd_set_link_down_set =
7578         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7579 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7580         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7581                                 "link-down");
7582 cmdline_parse_token_string_t cmd_set_link_down_port =
7583         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7584 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7585         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7586
7587 static void cmd_set_link_down_parsed(
7588                                 __rte_unused void *parsed_result,
7589                                 __rte_unused struct cmdline *cl,
7590                                 __rte_unused void *data)
7591 {
7592         struct cmd_set_link_down_result *res = parsed_result;
7593         dev_set_link_down(res->port_id);
7594 }
7595
7596 cmdline_parse_inst_t cmd_set_link_down = {
7597         .f = cmd_set_link_down_parsed,
7598         .data = NULL,
7599         .help_str = "set link-down port <port id>",
7600         .tokens = {
7601                 (void *)&cmd_set_link_down_set,
7602                 (void *)&cmd_set_link_down_link_down,
7603                 (void *)&cmd_set_link_down_port,
7604                 (void *)&cmd_set_link_down_port_id,
7605                 NULL,
7606         },
7607 };
7608
7609 /* *** SHOW CFG *** */
7610 struct cmd_showcfg_result {
7611         cmdline_fixed_string_t show;
7612         cmdline_fixed_string_t cfg;
7613         cmdline_fixed_string_t what;
7614 };
7615
7616 static void cmd_showcfg_parsed(void *parsed_result,
7617                                __rte_unused struct cmdline *cl,
7618                                __rte_unused void *data)
7619 {
7620         struct cmd_showcfg_result *res = parsed_result;
7621         if (!strcmp(res->what, "rxtx"))
7622                 rxtx_config_display();
7623         else if (!strcmp(res->what, "cores"))
7624                 fwd_lcores_config_display();
7625         else if (!strcmp(res->what, "fwd"))
7626                 pkt_fwd_config_display(&cur_fwd_config);
7627         else if (!strcmp(res->what, "rxoffs"))
7628                 show_rx_pkt_offsets();
7629         else if (!strcmp(res->what, "rxpkts"))
7630                 show_rx_pkt_segments();
7631         else if (!strcmp(res->what, "txpkts"))
7632                 show_tx_pkt_segments();
7633         else if (!strcmp(res->what, "txtimes"))
7634                 show_tx_pkt_times();
7635 }
7636
7637 cmdline_parse_token_string_t cmd_showcfg_show =
7638         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7639 cmdline_parse_token_string_t cmd_showcfg_port =
7640         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7641 cmdline_parse_token_string_t cmd_showcfg_what =
7642         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7643                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7644
7645 cmdline_parse_inst_t cmd_showcfg = {
7646         .f = cmd_showcfg_parsed,
7647         .data = NULL,
7648         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7649         .tokens = {
7650                 (void *)&cmd_showcfg_show,
7651                 (void *)&cmd_showcfg_port,
7652                 (void *)&cmd_showcfg_what,
7653                 NULL,
7654         },
7655 };
7656
7657 /* *** SHOW ALL PORT INFO *** */
7658 struct cmd_showportall_result {
7659         cmdline_fixed_string_t show;
7660         cmdline_fixed_string_t port;
7661         cmdline_fixed_string_t what;
7662         cmdline_fixed_string_t all;
7663 };
7664
7665 static void cmd_showportall_parsed(void *parsed_result,
7666                                 __rte_unused struct cmdline *cl,
7667                                 __rte_unused void *data)
7668 {
7669         portid_t i;
7670
7671         struct cmd_showportall_result *res = parsed_result;
7672         if (!strcmp(res->show, "clear")) {
7673                 if (!strcmp(res->what, "stats"))
7674                         RTE_ETH_FOREACH_DEV(i)
7675                                 nic_stats_clear(i);
7676                 else if (!strcmp(res->what, "xstats"))
7677                         RTE_ETH_FOREACH_DEV(i)
7678                                 nic_xstats_clear(i);
7679         } else if (!strcmp(res->what, "info"))
7680                 RTE_ETH_FOREACH_DEV(i)
7681                         port_infos_display(i);
7682         else if (!strcmp(res->what, "summary")) {
7683                 port_summary_header_display();
7684                 RTE_ETH_FOREACH_DEV(i)
7685                         port_summary_display(i);
7686         }
7687         else if (!strcmp(res->what, "stats"))
7688                 RTE_ETH_FOREACH_DEV(i)
7689                         nic_stats_display(i);
7690         else if (!strcmp(res->what, "xstats"))
7691                 RTE_ETH_FOREACH_DEV(i)
7692                         nic_xstats_display(i);
7693         else if (!strcmp(res->what, "fdir"))
7694                 RTE_ETH_FOREACH_DEV(i)
7695                         fdir_get_infos(i);
7696         else if (!strcmp(res->what, "stat_qmap"))
7697                 RTE_ETH_FOREACH_DEV(i)
7698                         nic_stats_mapping_display(i);
7699         else if (!strcmp(res->what, "dcb_tc"))
7700                 RTE_ETH_FOREACH_DEV(i)
7701                         port_dcb_info_display(i);
7702         else if (!strcmp(res->what, "cap"))
7703                 RTE_ETH_FOREACH_DEV(i)
7704                         port_offload_cap_display(i);
7705 }
7706
7707 cmdline_parse_token_string_t cmd_showportall_show =
7708         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7709                                  "show#clear");
7710 cmdline_parse_token_string_t cmd_showportall_port =
7711         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7712 cmdline_parse_token_string_t cmd_showportall_what =
7713         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7714                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7715 cmdline_parse_token_string_t cmd_showportall_all =
7716         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7717 cmdline_parse_inst_t cmd_showportall = {
7718         .f = cmd_showportall_parsed,
7719         .data = NULL,
7720         .help_str = "show|clear port "
7721                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7722         .tokens = {
7723                 (void *)&cmd_showportall_show,
7724                 (void *)&cmd_showportall_port,
7725                 (void *)&cmd_showportall_what,
7726                 (void *)&cmd_showportall_all,
7727                 NULL,
7728         },
7729 };
7730
7731 /* *** SHOW PORT INFO *** */
7732 struct cmd_showport_result {
7733         cmdline_fixed_string_t show;
7734         cmdline_fixed_string_t port;
7735         cmdline_fixed_string_t what;
7736         uint16_t portnum;
7737 };
7738
7739 static void cmd_showport_parsed(void *parsed_result,
7740                                 __rte_unused struct cmdline *cl,
7741                                 __rte_unused void *data)
7742 {
7743         struct cmd_showport_result *res = parsed_result;
7744         if (!strcmp(res->show, "clear")) {
7745                 if (!strcmp(res->what, "stats"))
7746                         nic_stats_clear(res->portnum);
7747                 else if (!strcmp(res->what, "xstats"))
7748                         nic_xstats_clear(res->portnum);
7749         } else if (!strcmp(res->what, "info"))
7750                 port_infos_display(res->portnum);
7751         else if (!strcmp(res->what, "summary")) {
7752                 port_summary_header_display();
7753                 port_summary_display(res->portnum);
7754         }
7755         else if (!strcmp(res->what, "stats"))
7756                 nic_stats_display(res->portnum);
7757         else if (!strcmp(res->what, "xstats"))
7758                 nic_xstats_display(res->portnum);
7759         else if (!strcmp(res->what, "fdir"))
7760                  fdir_get_infos(res->portnum);
7761         else if (!strcmp(res->what, "stat_qmap"))
7762                 nic_stats_mapping_display(res->portnum);
7763         else if (!strcmp(res->what, "dcb_tc"))
7764                 port_dcb_info_display(res->portnum);
7765         else if (!strcmp(res->what, "cap"))
7766                 port_offload_cap_display(res->portnum);
7767 }
7768
7769 cmdline_parse_token_string_t cmd_showport_show =
7770         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7771                                  "show#clear");
7772 cmdline_parse_token_string_t cmd_showport_port =
7773         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7774 cmdline_parse_token_string_t cmd_showport_what =
7775         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7776                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7777 cmdline_parse_token_num_t cmd_showport_portnum =
7778         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7779
7780 cmdline_parse_inst_t cmd_showport = {
7781         .f = cmd_showport_parsed,
7782         .data = NULL,
7783         .help_str = "show|clear port "
7784                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7785                 "<port_id>",
7786         .tokens = {
7787                 (void *)&cmd_showport_show,
7788                 (void *)&cmd_showport_port,
7789                 (void *)&cmd_showport_what,
7790                 (void *)&cmd_showport_portnum,
7791                 NULL,
7792         },
7793 };
7794
7795 /* *** SHOW DEVICE INFO *** */
7796 struct cmd_showdevice_result {
7797         cmdline_fixed_string_t show;
7798         cmdline_fixed_string_t device;
7799         cmdline_fixed_string_t what;
7800         cmdline_fixed_string_t identifier;
7801 };
7802
7803 static void cmd_showdevice_parsed(void *parsed_result,
7804                                 __rte_unused struct cmdline *cl,
7805                                 __rte_unused void *data)
7806 {
7807         struct cmd_showdevice_result *res = parsed_result;
7808         if (!strcmp(res->what, "info")) {
7809                 if (!strcmp(res->identifier, "all"))
7810                         device_infos_display(NULL);
7811                 else
7812                         device_infos_display(res->identifier);
7813         }
7814 }
7815
7816 cmdline_parse_token_string_t cmd_showdevice_show =
7817         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7818                                  "show");
7819 cmdline_parse_token_string_t cmd_showdevice_device =
7820         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7821 cmdline_parse_token_string_t cmd_showdevice_what =
7822         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7823                                  "info");
7824 cmdline_parse_token_string_t cmd_showdevice_identifier =
7825         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7826                         identifier, NULL);
7827
7828 cmdline_parse_inst_t cmd_showdevice = {
7829         .f = cmd_showdevice_parsed,
7830         .data = NULL,
7831         .help_str = "show device info <identifier>|all",
7832         .tokens = {
7833                 (void *)&cmd_showdevice_show,
7834                 (void *)&cmd_showdevice_device,
7835                 (void *)&cmd_showdevice_what,
7836                 (void *)&cmd_showdevice_identifier,
7837                 NULL,
7838         },
7839 };
7840
7841 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7842 struct cmd_showeeprom_result {
7843         cmdline_fixed_string_t show;
7844         cmdline_fixed_string_t port;
7845         uint16_t portnum;
7846         cmdline_fixed_string_t type;
7847 };
7848
7849 static void cmd_showeeprom_parsed(void *parsed_result,
7850                 __rte_unused struct cmdline *cl,
7851                 __rte_unused void *data)
7852 {
7853         struct cmd_showeeprom_result *res = parsed_result;
7854
7855         if (!strcmp(res->type, "eeprom"))
7856                 port_eeprom_display(res->portnum);
7857         else if (!strcmp(res->type, "module_eeprom"))
7858                 port_module_eeprom_display(res->portnum);
7859         else
7860                 printf("Unknown argument\n");
7861 }
7862
7863 cmdline_parse_token_string_t cmd_showeeprom_show =
7864         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7865 cmdline_parse_token_string_t cmd_showeeprom_port =
7866         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7867 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7868         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7869 cmdline_parse_token_string_t cmd_showeeprom_type =
7870         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7871
7872 cmdline_parse_inst_t cmd_showeeprom = {
7873         .f = cmd_showeeprom_parsed,
7874         .data = NULL,
7875         .help_str = "show port <port_id> module_eeprom|eeprom",
7876         .tokens = {
7877                 (void *)&cmd_showeeprom_show,
7878                 (void *)&cmd_showeeprom_port,
7879                 (void *)&cmd_showeeprom_portnum,
7880                 (void *)&cmd_showeeprom_type,
7881                 NULL,
7882         },
7883 };
7884
7885 /* *** SHOW QUEUE INFO *** */
7886 struct cmd_showqueue_result {
7887         cmdline_fixed_string_t show;
7888         cmdline_fixed_string_t type;
7889         cmdline_fixed_string_t what;
7890         uint16_t portnum;
7891         uint16_t queuenum;
7892 };
7893
7894 static void
7895 cmd_showqueue_parsed(void *parsed_result,
7896         __rte_unused struct cmdline *cl,
7897         __rte_unused void *data)
7898 {
7899         struct cmd_showqueue_result *res = parsed_result;
7900
7901         if (!strcmp(res->type, "rxq"))
7902                 rx_queue_infos_display(res->portnum, res->queuenum);
7903         else if (!strcmp(res->type, "txq"))
7904                 tx_queue_infos_display(res->portnum, res->queuenum);
7905 }
7906
7907 cmdline_parse_token_string_t cmd_showqueue_show =
7908         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7909 cmdline_parse_token_string_t cmd_showqueue_type =
7910         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7911 cmdline_parse_token_string_t cmd_showqueue_what =
7912         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7913 cmdline_parse_token_num_t cmd_showqueue_portnum =
7914         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7915 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7916         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7917
7918 cmdline_parse_inst_t cmd_showqueue = {
7919         .f = cmd_showqueue_parsed,
7920         .data = NULL,
7921         .help_str = "show rxq|txq info <port_id> <queue_id>",
7922         .tokens = {
7923                 (void *)&cmd_showqueue_show,
7924                 (void *)&cmd_showqueue_type,
7925                 (void *)&cmd_showqueue_what,
7926                 (void *)&cmd_showqueue_portnum,
7927                 (void *)&cmd_showqueue_queuenum,
7928                 NULL,
7929         },
7930 };
7931
7932 /* show/clear fwd engine statistics */
7933 struct fwd_result {
7934         cmdline_fixed_string_t action;
7935         cmdline_fixed_string_t fwd;
7936         cmdline_fixed_string_t stats;
7937         cmdline_fixed_string_t all;
7938 };
7939
7940 cmdline_parse_token_string_t cmd_fwd_action =
7941         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7942 cmdline_parse_token_string_t cmd_fwd_fwd =
7943         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7944 cmdline_parse_token_string_t cmd_fwd_stats =
7945         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7946 cmdline_parse_token_string_t cmd_fwd_all =
7947         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7948
7949 static void
7950 cmd_showfwdall_parsed(void *parsed_result,
7951                       __rte_unused struct cmdline *cl,
7952                       __rte_unused void *data)
7953 {
7954         struct fwd_result *res = parsed_result;
7955
7956         if (!strcmp(res->action, "show"))
7957                 fwd_stats_display();
7958         else
7959                 fwd_stats_reset();
7960 }
7961
7962 static cmdline_parse_inst_t cmd_showfwdall = {
7963         .f = cmd_showfwdall_parsed,
7964         .data = NULL,
7965         .help_str = "show|clear fwd stats all",
7966         .tokens = {
7967                 (void *)&cmd_fwd_action,
7968                 (void *)&cmd_fwd_fwd,
7969                 (void *)&cmd_fwd_stats,
7970                 (void *)&cmd_fwd_all,
7971                 NULL,
7972         },
7973 };
7974
7975 /* *** READ PORT REGISTER *** */
7976 struct cmd_read_reg_result {
7977         cmdline_fixed_string_t read;
7978         cmdline_fixed_string_t reg;
7979         portid_t port_id;
7980         uint32_t reg_off;
7981 };
7982
7983 static void
7984 cmd_read_reg_parsed(void *parsed_result,
7985                     __rte_unused struct cmdline *cl,
7986                     __rte_unused void *data)
7987 {
7988         struct cmd_read_reg_result *res = parsed_result;
7989         port_reg_display(res->port_id, res->reg_off);
7990 }
7991
7992 cmdline_parse_token_string_t cmd_read_reg_read =
7993         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7994 cmdline_parse_token_string_t cmd_read_reg_reg =
7995         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7996 cmdline_parse_token_num_t cmd_read_reg_port_id =
7997         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7998 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7999         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
8000
8001 cmdline_parse_inst_t cmd_read_reg = {
8002         .f = cmd_read_reg_parsed,
8003         .data = NULL,
8004         .help_str = "read reg <port_id> <reg_off>",
8005         .tokens = {
8006                 (void *)&cmd_read_reg_read,
8007                 (void *)&cmd_read_reg_reg,
8008                 (void *)&cmd_read_reg_port_id,
8009                 (void *)&cmd_read_reg_reg_off,
8010                 NULL,
8011         },
8012 };
8013
8014 /* *** READ PORT REGISTER BIT FIELD *** */
8015 struct cmd_read_reg_bit_field_result {
8016         cmdline_fixed_string_t read;
8017         cmdline_fixed_string_t regfield;
8018         portid_t port_id;
8019         uint32_t reg_off;
8020         uint8_t bit1_pos;
8021         uint8_t bit2_pos;
8022 };
8023
8024 static void
8025 cmd_read_reg_bit_field_parsed(void *parsed_result,
8026                               __rte_unused struct cmdline *cl,
8027                               __rte_unused void *data)
8028 {
8029         struct cmd_read_reg_bit_field_result *res = parsed_result;
8030         port_reg_bit_field_display(res->port_id, res->reg_off,
8031                                    res->bit1_pos, res->bit2_pos);
8032 }
8033
8034 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8035         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8036                                  "read");
8037 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8038         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8039                                  regfield, "regfield");
8040 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8041         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8042                               UINT16);
8043 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8044         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8045                               UINT32);
8046 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8047         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8048                               UINT8);
8049 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8050         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8051                               UINT8);
8052
8053 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8054         .f = cmd_read_reg_bit_field_parsed,
8055         .data = NULL,
8056         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8057         "Read register bit field between bit_x and bit_y included",
8058         .tokens = {
8059                 (void *)&cmd_read_reg_bit_field_read,
8060                 (void *)&cmd_read_reg_bit_field_regfield,
8061                 (void *)&cmd_read_reg_bit_field_port_id,
8062                 (void *)&cmd_read_reg_bit_field_reg_off,
8063                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8064                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8065                 NULL,
8066         },
8067 };
8068
8069 /* *** READ PORT REGISTER BIT *** */
8070 struct cmd_read_reg_bit_result {
8071         cmdline_fixed_string_t read;
8072         cmdline_fixed_string_t regbit;
8073         portid_t port_id;
8074         uint32_t reg_off;
8075         uint8_t bit_pos;
8076 };
8077
8078 static void
8079 cmd_read_reg_bit_parsed(void *parsed_result,
8080                         __rte_unused struct cmdline *cl,
8081                         __rte_unused void *data)
8082 {
8083         struct cmd_read_reg_bit_result *res = parsed_result;
8084         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8085 }
8086
8087 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8088         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8089 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8090         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8091                                  regbit, "regbit");
8092 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8093         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
8094 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8095         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
8096 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8097         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
8098
8099 cmdline_parse_inst_t cmd_read_reg_bit = {
8100         .f = cmd_read_reg_bit_parsed,
8101         .data = NULL,
8102         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8103         .tokens = {
8104                 (void *)&cmd_read_reg_bit_read,
8105                 (void *)&cmd_read_reg_bit_regbit,
8106                 (void *)&cmd_read_reg_bit_port_id,
8107                 (void *)&cmd_read_reg_bit_reg_off,
8108                 (void *)&cmd_read_reg_bit_bit_pos,
8109                 NULL,
8110         },
8111 };
8112
8113 /* *** WRITE PORT REGISTER *** */
8114 struct cmd_write_reg_result {
8115         cmdline_fixed_string_t write;
8116         cmdline_fixed_string_t reg;
8117         portid_t port_id;
8118         uint32_t reg_off;
8119         uint32_t value;
8120 };
8121
8122 static void
8123 cmd_write_reg_parsed(void *parsed_result,
8124                      __rte_unused struct cmdline *cl,
8125                      __rte_unused void *data)
8126 {
8127         struct cmd_write_reg_result *res = parsed_result;
8128         port_reg_set(res->port_id, res->reg_off, res->value);
8129 }
8130
8131 cmdline_parse_token_string_t cmd_write_reg_write =
8132         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8133 cmdline_parse_token_string_t cmd_write_reg_reg =
8134         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8135 cmdline_parse_token_num_t cmd_write_reg_port_id =
8136         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
8137 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8138         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
8139 cmdline_parse_token_num_t cmd_write_reg_value =
8140         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
8141
8142 cmdline_parse_inst_t cmd_write_reg = {
8143         .f = cmd_write_reg_parsed,
8144         .data = NULL,
8145         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8146         .tokens = {
8147                 (void *)&cmd_write_reg_write,
8148                 (void *)&cmd_write_reg_reg,
8149                 (void *)&cmd_write_reg_port_id,
8150                 (void *)&cmd_write_reg_reg_off,
8151                 (void *)&cmd_write_reg_value,
8152                 NULL,
8153         },
8154 };
8155
8156 /* *** WRITE PORT REGISTER BIT FIELD *** */
8157 struct cmd_write_reg_bit_field_result {
8158         cmdline_fixed_string_t write;
8159         cmdline_fixed_string_t regfield;
8160         portid_t port_id;
8161         uint32_t reg_off;
8162         uint8_t bit1_pos;
8163         uint8_t bit2_pos;
8164         uint32_t value;
8165 };
8166
8167 static void
8168 cmd_write_reg_bit_field_parsed(void *parsed_result,
8169                                __rte_unused struct cmdline *cl,
8170                                __rte_unused void *data)
8171 {
8172         struct cmd_write_reg_bit_field_result *res = parsed_result;
8173         port_reg_bit_field_set(res->port_id, res->reg_off,
8174                           res->bit1_pos, res->bit2_pos, res->value);
8175 }
8176
8177 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8178         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8179                                  "write");
8180 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8181         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8182                                  regfield, "regfield");
8183 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8184         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8185                               UINT16);
8186 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8187         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8188                               UINT32);
8189 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8190         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8191                               UINT8);
8192 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8193         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8194                               UINT8);
8195 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8196         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8197                               UINT32);
8198
8199 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8200         .f = cmd_write_reg_bit_field_parsed,
8201         .data = NULL,
8202         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8203                 "<reg_value>: "
8204                 "Set register bit field between bit_x and bit_y included",
8205         .tokens = {
8206                 (void *)&cmd_write_reg_bit_field_write,
8207                 (void *)&cmd_write_reg_bit_field_regfield,
8208                 (void *)&cmd_write_reg_bit_field_port_id,
8209                 (void *)&cmd_write_reg_bit_field_reg_off,
8210                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8211                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8212                 (void *)&cmd_write_reg_bit_field_value,
8213                 NULL,
8214         },
8215 };
8216
8217 /* *** WRITE PORT REGISTER BIT *** */
8218 struct cmd_write_reg_bit_result {
8219         cmdline_fixed_string_t write;
8220         cmdline_fixed_string_t regbit;
8221         portid_t port_id;
8222         uint32_t reg_off;
8223         uint8_t bit_pos;
8224         uint8_t value;
8225 };
8226
8227 static void
8228 cmd_write_reg_bit_parsed(void *parsed_result,
8229                          __rte_unused struct cmdline *cl,
8230                          __rte_unused void *data)
8231 {
8232         struct cmd_write_reg_bit_result *res = parsed_result;
8233         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8234 }
8235
8236 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8237         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8238                                  "write");
8239 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8240         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8241                                  regbit, "regbit");
8242 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8243         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8244 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8245         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8246 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8247         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8248 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8249         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8250
8251 cmdline_parse_inst_t cmd_write_reg_bit = {
8252         .f = cmd_write_reg_bit_parsed,
8253         .data = NULL,
8254         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8255                 "0 <= bit_x <= 31",
8256         .tokens = {
8257                 (void *)&cmd_write_reg_bit_write,
8258                 (void *)&cmd_write_reg_bit_regbit,
8259                 (void *)&cmd_write_reg_bit_port_id,
8260                 (void *)&cmd_write_reg_bit_reg_off,
8261                 (void *)&cmd_write_reg_bit_bit_pos,
8262                 (void *)&cmd_write_reg_bit_value,
8263                 NULL,
8264         },
8265 };
8266
8267 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8268 struct cmd_read_rxd_txd_result {
8269         cmdline_fixed_string_t read;
8270         cmdline_fixed_string_t rxd_txd;
8271         portid_t port_id;
8272         uint16_t queue_id;
8273         uint16_t desc_id;
8274 };
8275
8276 static void
8277 cmd_read_rxd_txd_parsed(void *parsed_result,
8278                         __rte_unused struct cmdline *cl,
8279                         __rte_unused void *data)
8280 {
8281         struct cmd_read_rxd_txd_result *res = parsed_result;
8282
8283         if (!strcmp(res->rxd_txd, "rxd"))
8284                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8285         else if (!strcmp(res->rxd_txd, "txd"))
8286                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8287 }
8288
8289 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8290         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8291 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8292         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8293                                  "rxd#txd");
8294 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8295         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8296 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8297         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8298 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8299         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8300
8301 cmdline_parse_inst_t cmd_read_rxd_txd = {
8302         .f = cmd_read_rxd_txd_parsed,
8303         .data = NULL,
8304         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8305         .tokens = {
8306                 (void *)&cmd_read_rxd_txd_read,
8307                 (void *)&cmd_read_rxd_txd_rxd_txd,
8308                 (void *)&cmd_read_rxd_txd_port_id,
8309                 (void *)&cmd_read_rxd_txd_queue_id,
8310                 (void *)&cmd_read_rxd_txd_desc_id,
8311                 NULL,
8312         },
8313 };
8314
8315 /* *** QUIT *** */
8316 struct cmd_quit_result {
8317         cmdline_fixed_string_t quit;
8318 };
8319
8320 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8321                             struct cmdline *cl,
8322                             __rte_unused void *data)
8323 {
8324         cmdline_quit(cl);
8325 }
8326
8327 cmdline_parse_token_string_t cmd_quit_quit =
8328         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8329
8330 cmdline_parse_inst_t cmd_quit = {
8331         .f = cmd_quit_parsed,
8332         .data = NULL,
8333         .help_str = "quit: Exit application",
8334         .tokens = {
8335                 (void *)&cmd_quit_quit,
8336                 NULL,
8337         },
8338 };
8339
8340 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8341 struct cmd_mac_addr_result {
8342         cmdline_fixed_string_t mac_addr_cmd;
8343         cmdline_fixed_string_t what;
8344         uint16_t port_num;
8345         struct rte_ether_addr address;
8346 };
8347
8348 static void cmd_mac_addr_parsed(void *parsed_result,
8349                 __rte_unused struct cmdline *cl,
8350                 __rte_unused void *data)
8351 {
8352         struct cmd_mac_addr_result *res = parsed_result;
8353         int ret;
8354
8355         if (strcmp(res->what, "add") == 0)
8356                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8357         else if (strcmp(res->what, "set") == 0)
8358                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8359                                                        &res->address);
8360         else
8361                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8362
8363         /* check the return value and print it if is < 0 */
8364         if(ret < 0)
8365                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8366
8367 }
8368
8369 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8370         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8371                                 "mac_addr");
8372 cmdline_parse_token_string_t cmd_mac_addr_what =
8373         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8374                                 "add#remove#set");
8375 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8376                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8377                                         UINT16);
8378 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8379                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8380
8381 cmdline_parse_inst_t cmd_mac_addr = {
8382         .f = cmd_mac_addr_parsed,
8383         .data = (void *)0,
8384         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8385                         "Add/Remove/Set MAC address on port_id",
8386         .tokens = {
8387                 (void *)&cmd_mac_addr_cmd,
8388                 (void *)&cmd_mac_addr_what,
8389                 (void *)&cmd_mac_addr_portnum,
8390                 (void *)&cmd_mac_addr_addr,
8391                 NULL,
8392         },
8393 };
8394
8395 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8396 struct cmd_eth_peer_result {
8397         cmdline_fixed_string_t set;
8398         cmdline_fixed_string_t eth_peer;
8399         portid_t port_id;
8400         cmdline_fixed_string_t peer_addr;
8401 };
8402
8403 static void cmd_set_eth_peer_parsed(void *parsed_result,
8404                         __rte_unused struct cmdline *cl,
8405                         __rte_unused void *data)
8406 {
8407                 struct cmd_eth_peer_result *res = parsed_result;
8408
8409                 if (test_done == 0) {
8410                         printf("Please stop forwarding first\n");
8411                         return;
8412                 }
8413                 if (!strcmp(res->eth_peer, "eth-peer")) {
8414                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8415                         fwd_config_setup();
8416                 }
8417 }
8418 cmdline_parse_token_string_t cmd_eth_peer_set =
8419         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8420 cmdline_parse_token_string_t cmd_eth_peer =
8421         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8422 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8423         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8424 cmdline_parse_token_string_t cmd_eth_peer_addr =
8425         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8426
8427 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8428         .f = cmd_set_eth_peer_parsed,
8429         .data = NULL,
8430         .help_str = "set eth-peer <port_id> <peer_mac>",
8431         .tokens = {
8432                 (void *)&cmd_eth_peer_set,
8433                 (void *)&cmd_eth_peer,
8434                 (void *)&cmd_eth_peer_port_id,
8435                 (void *)&cmd_eth_peer_addr,
8436                 NULL,
8437         },
8438 };
8439
8440 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8441 struct cmd_set_qmap_result {
8442         cmdline_fixed_string_t set;
8443         cmdline_fixed_string_t qmap;
8444         cmdline_fixed_string_t what;
8445         portid_t port_id;
8446         uint16_t queue_id;
8447         uint8_t map_value;
8448 };
8449
8450 static void
8451 cmd_set_qmap_parsed(void *parsed_result,
8452                        __rte_unused struct cmdline *cl,
8453                        __rte_unused void *data)
8454 {
8455         struct cmd_set_qmap_result *res = parsed_result;
8456         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8457
8458         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8459 }
8460
8461 cmdline_parse_token_string_t cmd_setqmap_set =
8462         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8463                                  set, "set");
8464 cmdline_parse_token_string_t cmd_setqmap_qmap =
8465         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8466                                  qmap, "stat_qmap");
8467 cmdline_parse_token_string_t cmd_setqmap_what =
8468         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8469                                  what, "tx#rx");
8470 cmdline_parse_token_num_t cmd_setqmap_portid =
8471         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8472                               port_id, UINT16);
8473 cmdline_parse_token_num_t cmd_setqmap_queueid =
8474         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8475                               queue_id, UINT16);
8476 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8477         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8478                               map_value, UINT8);
8479
8480 cmdline_parse_inst_t cmd_set_qmap = {
8481         .f = cmd_set_qmap_parsed,
8482         .data = NULL,
8483         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8484                 "Set statistics mapping value on tx|rx queue_id of port_id",
8485         .tokens = {
8486                 (void *)&cmd_setqmap_set,
8487                 (void *)&cmd_setqmap_qmap,
8488                 (void *)&cmd_setqmap_what,
8489                 (void *)&cmd_setqmap_portid,
8490                 (void *)&cmd_setqmap_queueid,
8491                 (void *)&cmd_setqmap_mapvalue,
8492                 NULL,
8493         },
8494 };
8495
8496 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8497 struct cmd_set_xstats_hide_zero_result {
8498         cmdline_fixed_string_t keyword;
8499         cmdline_fixed_string_t name;
8500         cmdline_fixed_string_t on_off;
8501 };
8502
8503 static void
8504 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8505                         __rte_unused struct cmdline *cl,
8506                         __rte_unused void *data)
8507 {
8508         struct cmd_set_xstats_hide_zero_result *res;
8509         uint16_t on_off = 0;
8510
8511         res = parsed_result;
8512         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8513         set_xstats_hide_zero(on_off);
8514 }
8515
8516 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8517         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8518                                  keyword, "set");
8519 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8520         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8521                                  name, "xstats-hide-zero");
8522 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8523         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8524                                  on_off, "on#off");
8525
8526 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8527         .f = cmd_set_xstats_hide_zero_parsed,
8528         .data = NULL,
8529         .help_str = "set xstats-hide-zero on|off",
8530         .tokens = {
8531                 (void *)&cmd_set_xstats_hide_zero_keyword,
8532                 (void *)&cmd_set_xstats_hide_zero_name,
8533                 (void *)&cmd_set_xstats_hide_zero_on_off,
8534                 NULL,
8535         },
8536 };
8537
8538 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8539 struct cmd_set_record_core_cycles_result {
8540         cmdline_fixed_string_t keyword;
8541         cmdline_fixed_string_t name;
8542         cmdline_fixed_string_t on_off;
8543 };
8544
8545 static void
8546 cmd_set_record_core_cycles_parsed(void *parsed_result,
8547                         __rte_unused struct cmdline *cl,
8548                         __rte_unused void *data)
8549 {
8550         struct cmd_set_record_core_cycles_result *res;
8551         uint16_t on_off = 0;
8552
8553         res = parsed_result;
8554         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8555         set_record_core_cycles(on_off);
8556 }
8557
8558 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8559         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8560                                  keyword, "set");
8561 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8562         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8563                                  name, "record-core-cycles");
8564 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8565         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8566                                  on_off, "on#off");
8567
8568 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8569         .f = cmd_set_record_core_cycles_parsed,
8570         .data = NULL,
8571         .help_str = "set record-core-cycles on|off",
8572         .tokens = {
8573                 (void *)&cmd_set_record_core_cycles_keyword,
8574                 (void *)&cmd_set_record_core_cycles_name,
8575                 (void *)&cmd_set_record_core_cycles_on_off,
8576                 NULL,
8577         },
8578 };
8579
8580 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8581 struct cmd_set_record_burst_stats_result {
8582         cmdline_fixed_string_t keyword;
8583         cmdline_fixed_string_t name;
8584         cmdline_fixed_string_t on_off;
8585 };
8586
8587 static void
8588 cmd_set_record_burst_stats_parsed(void *parsed_result,
8589                         __rte_unused struct cmdline *cl,
8590                         __rte_unused void *data)
8591 {
8592         struct cmd_set_record_burst_stats_result *res;
8593         uint16_t on_off = 0;
8594
8595         res = parsed_result;
8596         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8597         set_record_burst_stats(on_off);
8598 }
8599
8600 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8601         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8602                                  keyword, "set");
8603 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8604         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8605                                  name, "record-burst-stats");
8606 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8607         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8608                                  on_off, "on#off");
8609
8610 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8611         .f = cmd_set_record_burst_stats_parsed,
8612         .data = NULL,
8613         .help_str = "set record-burst-stats on|off",
8614         .tokens = {
8615                 (void *)&cmd_set_record_burst_stats_keyword,
8616                 (void *)&cmd_set_record_burst_stats_name,
8617                 (void *)&cmd_set_record_burst_stats_on_off,
8618                 NULL,
8619         },
8620 };
8621
8622 /* *** CONFIGURE UNICAST HASH TABLE *** */
8623 struct cmd_set_uc_hash_table {
8624         cmdline_fixed_string_t set;
8625         cmdline_fixed_string_t port;
8626         portid_t port_id;
8627         cmdline_fixed_string_t what;
8628         struct rte_ether_addr address;
8629         cmdline_fixed_string_t mode;
8630 };
8631
8632 static void
8633 cmd_set_uc_hash_parsed(void *parsed_result,
8634                        __rte_unused struct cmdline *cl,
8635                        __rte_unused void *data)
8636 {
8637         int ret=0;
8638         struct cmd_set_uc_hash_table *res = parsed_result;
8639
8640         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8641
8642         if (strcmp(res->what, "uta") == 0)
8643                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8644                                                 &res->address,(uint8_t)is_on);
8645         if (ret < 0)
8646                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8647
8648 }
8649
8650 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8651         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8652                                  set, "set");
8653 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8654         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8655                                  port, "port");
8656 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8657         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8658                               port_id, UINT16);
8659 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8660         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8661                                  what, "uta");
8662 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8663         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8664                                 address);
8665 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8666         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8667                                  mode, "on#off");
8668
8669 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8670         .f = cmd_set_uc_hash_parsed,
8671         .data = NULL,
8672         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8673         .tokens = {
8674                 (void *)&cmd_set_uc_hash_set,
8675                 (void *)&cmd_set_uc_hash_port,
8676                 (void *)&cmd_set_uc_hash_portid,
8677                 (void *)&cmd_set_uc_hash_what,
8678                 (void *)&cmd_set_uc_hash_mac,
8679                 (void *)&cmd_set_uc_hash_mode,
8680                 NULL,
8681         },
8682 };
8683
8684 struct cmd_set_uc_all_hash_table {
8685         cmdline_fixed_string_t set;
8686         cmdline_fixed_string_t port;
8687         portid_t port_id;
8688         cmdline_fixed_string_t what;
8689         cmdline_fixed_string_t value;
8690         cmdline_fixed_string_t mode;
8691 };
8692
8693 static void
8694 cmd_set_uc_all_hash_parsed(void *parsed_result,
8695                        __rte_unused struct cmdline *cl,
8696                        __rte_unused void *data)
8697 {
8698         int ret=0;
8699         struct cmd_set_uc_all_hash_table *res = parsed_result;
8700
8701         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8702
8703         if ((strcmp(res->what, "uta") == 0) &&
8704                 (strcmp(res->value, "all") == 0))
8705                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8706         if (ret < 0)
8707                 printf("bad unicast hash table parameter,"
8708                         "return code = %d \n", ret);
8709 }
8710
8711 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8712         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8713                                  set, "set");
8714 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8715         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8716                                  port, "port");
8717 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8718         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8719                               port_id, UINT16);
8720 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8721         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8722                                  what, "uta");
8723 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8724         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8725                                 value,"all");
8726 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8727         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8728                                  mode, "on#off");
8729
8730 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8731         .f = cmd_set_uc_all_hash_parsed,
8732         .data = NULL,
8733         .help_str = "set port <port_id> uta all on|off",
8734         .tokens = {
8735                 (void *)&cmd_set_uc_all_hash_set,
8736                 (void *)&cmd_set_uc_all_hash_port,
8737                 (void *)&cmd_set_uc_all_hash_portid,
8738                 (void *)&cmd_set_uc_all_hash_what,
8739                 (void *)&cmd_set_uc_all_hash_value,
8740                 (void *)&cmd_set_uc_all_hash_mode,
8741                 NULL,
8742         },
8743 };
8744
8745 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8746 struct cmd_set_vf_traffic {
8747         cmdline_fixed_string_t set;
8748         cmdline_fixed_string_t port;
8749         portid_t port_id;
8750         cmdline_fixed_string_t vf;
8751         uint8_t vf_id;
8752         cmdline_fixed_string_t what;
8753         cmdline_fixed_string_t mode;
8754 };
8755
8756 static void
8757 cmd_set_vf_traffic_parsed(void *parsed_result,
8758                        __rte_unused struct cmdline *cl,
8759                        __rte_unused void *data)
8760 {
8761         struct cmd_set_vf_traffic *res = parsed_result;
8762         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8763         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8764
8765         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8766 }
8767
8768 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8769         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8770                                  set, "set");
8771 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8772         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8773                                  port, "port");
8774 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8775         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8776                               port_id, UINT16);
8777 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8778         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8779                                  vf, "vf");
8780 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8781         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8782                               vf_id, UINT8);
8783 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8784         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8785                                  what, "tx#rx");
8786 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8787         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8788                                  mode, "on#off");
8789
8790 cmdline_parse_inst_t cmd_set_vf_traffic = {
8791         .f = cmd_set_vf_traffic_parsed,
8792         .data = NULL,
8793         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8794         .tokens = {
8795                 (void *)&cmd_setvf_traffic_set,
8796                 (void *)&cmd_setvf_traffic_port,
8797                 (void *)&cmd_setvf_traffic_portid,
8798                 (void *)&cmd_setvf_traffic_vf,
8799                 (void *)&cmd_setvf_traffic_vfid,
8800                 (void *)&cmd_setvf_traffic_what,
8801                 (void *)&cmd_setvf_traffic_mode,
8802                 NULL,
8803         },
8804 };
8805
8806 /* *** CONFIGURE VF RECEIVE MODE *** */
8807 struct cmd_set_vf_rxmode {
8808         cmdline_fixed_string_t set;
8809         cmdline_fixed_string_t port;
8810         portid_t port_id;
8811         cmdline_fixed_string_t vf;
8812         uint8_t vf_id;
8813         cmdline_fixed_string_t what;
8814         cmdline_fixed_string_t mode;
8815         cmdline_fixed_string_t on;
8816 };
8817
8818 static void
8819 cmd_set_vf_rxmode_parsed(void *parsed_result,
8820                        __rte_unused struct cmdline *cl,
8821                        __rte_unused void *data)
8822 {
8823         int ret = -ENOTSUP;
8824         uint16_t vf_rxmode = 0;
8825         struct cmd_set_vf_rxmode *res = parsed_result;
8826
8827         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8828         if (!strcmp(res->what,"rxmode")) {
8829                 if (!strcmp(res->mode, "AUPE"))
8830                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8831                 else if (!strcmp(res->mode, "ROPE"))
8832                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8833                 else if (!strcmp(res->mode, "BAM"))
8834                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8835                 else if (!strncmp(res->mode, "MPE",3))
8836                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8837         }
8838
8839         RTE_SET_USED(is_on);
8840
8841 #ifdef RTE_NET_IXGBE
8842         if (ret == -ENOTSUP)
8843                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8844                                                   vf_rxmode, (uint8_t)is_on);
8845 #endif
8846 #ifdef RTE_NET_BNXT
8847         if (ret == -ENOTSUP)
8848                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8849                                                  vf_rxmode, (uint8_t)is_on);
8850 #endif
8851         if (ret < 0)
8852                 printf("bad VF receive mode parameter, return code = %d \n",
8853                 ret);
8854 }
8855
8856 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8857         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8858                                  set, "set");
8859 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8860         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8861                                  port, "port");
8862 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8863         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8864                               port_id, UINT16);
8865 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8866         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8867                                  vf, "vf");
8868 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8869         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8870                               vf_id, UINT8);
8871 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8872         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8873                                  what, "rxmode");
8874 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8875         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8876                                  mode, "AUPE#ROPE#BAM#MPE");
8877 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8878         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8879                                  on, "on#off");
8880
8881 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8882         .f = cmd_set_vf_rxmode_parsed,
8883         .data = NULL,
8884         .help_str = "set port <port_id> vf <vf_id> rxmode "
8885                 "AUPE|ROPE|BAM|MPE on|off",
8886         .tokens = {
8887                 (void *)&cmd_set_vf_rxmode_set,
8888                 (void *)&cmd_set_vf_rxmode_port,
8889                 (void *)&cmd_set_vf_rxmode_portid,
8890                 (void *)&cmd_set_vf_rxmode_vf,
8891                 (void *)&cmd_set_vf_rxmode_vfid,
8892                 (void *)&cmd_set_vf_rxmode_what,
8893                 (void *)&cmd_set_vf_rxmode_mode,
8894                 (void *)&cmd_set_vf_rxmode_on,
8895                 NULL,
8896         },
8897 };
8898
8899 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8900 struct cmd_vf_mac_addr_result {
8901         cmdline_fixed_string_t mac_addr_cmd;
8902         cmdline_fixed_string_t what;
8903         cmdline_fixed_string_t port;
8904         uint16_t port_num;
8905         cmdline_fixed_string_t vf;
8906         uint8_t vf_num;
8907         struct rte_ether_addr address;
8908 };
8909
8910 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8911                 __rte_unused struct cmdline *cl,
8912                 __rte_unused void *data)
8913 {
8914         struct cmd_vf_mac_addr_result *res = parsed_result;
8915         int ret = -ENOTSUP;
8916
8917         if (strcmp(res->what, "add") != 0)
8918                 return;
8919
8920 #ifdef RTE_NET_I40E
8921         if (ret == -ENOTSUP)
8922                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8923                                                    &res->address);
8924 #endif
8925 #ifdef RTE_NET_BNXT
8926         if (ret == -ENOTSUP)
8927                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8928                                                 res->vf_num);
8929 #endif
8930
8931         if(ret < 0)
8932                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8933
8934 }
8935
8936 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8937         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8938                                 mac_addr_cmd,"mac_addr");
8939 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8940         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8941                                 what,"add");
8942 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8943         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8944                                 port,"port");
8945 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8946         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8947                                 port_num, UINT16);
8948 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8949         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8950                                 vf,"vf");
8951 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8952         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8953                                 vf_num, UINT8);
8954 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8955         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8956                                 address);
8957
8958 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8959         .f = cmd_vf_mac_addr_parsed,
8960         .data = (void *)0,
8961         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8962                 "Add MAC address filtering for a VF on port_id",
8963         .tokens = {
8964                 (void *)&cmd_vf_mac_addr_cmd,
8965                 (void *)&cmd_vf_mac_addr_what,
8966                 (void *)&cmd_vf_mac_addr_port,
8967                 (void *)&cmd_vf_mac_addr_portnum,
8968                 (void *)&cmd_vf_mac_addr_vf,
8969                 (void *)&cmd_vf_mac_addr_vfnum,
8970                 (void *)&cmd_vf_mac_addr_addr,
8971                 NULL,
8972         },
8973 };
8974
8975 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8976 struct cmd_vf_rx_vlan_filter {
8977         cmdline_fixed_string_t rx_vlan;
8978         cmdline_fixed_string_t what;
8979         uint16_t vlan_id;
8980         cmdline_fixed_string_t port;
8981         portid_t port_id;
8982         cmdline_fixed_string_t vf;
8983         uint64_t vf_mask;
8984 };
8985
8986 static void
8987 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8988                           __rte_unused struct cmdline *cl,
8989                           __rte_unused void *data)
8990 {
8991         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8992         int ret = -ENOTSUP;
8993
8994         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8995
8996 #ifdef RTE_NET_IXGBE
8997         if (ret == -ENOTSUP)
8998                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8999                                 res->vlan_id, res->vf_mask, is_add);
9000 #endif
9001 #ifdef RTE_NET_I40E
9002         if (ret == -ENOTSUP)
9003                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9004                                 res->vlan_id, res->vf_mask, is_add);
9005 #endif
9006 #ifdef RTE_NET_BNXT
9007         if (ret == -ENOTSUP)
9008                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9009                                 res->vlan_id, res->vf_mask, is_add);
9010 #endif
9011
9012         switch (ret) {
9013         case 0:
9014                 break;
9015         case -EINVAL:
9016                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
9017                                 res->vlan_id, res->vf_mask);
9018                 break;
9019         case -ENODEV:
9020                 printf("invalid port_id %d\n", res->port_id);
9021                 break;
9022         case -ENOTSUP:
9023                 printf("function not implemented or supported\n");
9024                 break;
9025         default:
9026                 printf("programming error: (%s)\n", strerror(-ret));
9027         }
9028 }
9029
9030 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9031         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9032                                  rx_vlan, "rx_vlan");
9033 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9034         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9035                                  what, "add#rm");
9036 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9037         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9038                               vlan_id, UINT16);
9039 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9040         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9041                                  port, "port");
9042 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9043         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9044                               port_id, UINT16);
9045 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9046         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9047                                  vf, "vf");
9048 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9049         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9050                               vf_mask, UINT64);
9051
9052 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9053         .f = cmd_vf_rx_vlan_filter_parsed,
9054         .data = NULL,
9055         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9056                 "(vf_mask = hexadecimal VF mask)",
9057         .tokens = {
9058                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9059                 (void *)&cmd_vf_rx_vlan_filter_what,
9060                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9061                 (void *)&cmd_vf_rx_vlan_filter_port,
9062                 (void *)&cmd_vf_rx_vlan_filter_portid,
9063                 (void *)&cmd_vf_rx_vlan_filter_vf,
9064                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9065                 NULL,
9066         },
9067 };
9068
9069 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9070 struct cmd_queue_rate_limit_result {
9071         cmdline_fixed_string_t set;
9072         cmdline_fixed_string_t port;
9073         uint16_t port_num;
9074         cmdline_fixed_string_t queue;
9075         uint8_t queue_num;
9076         cmdline_fixed_string_t rate;
9077         uint16_t rate_num;
9078 };
9079
9080 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9081                 __rte_unused struct cmdline *cl,
9082                 __rte_unused void *data)
9083 {
9084         struct cmd_queue_rate_limit_result *res = parsed_result;
9085         int ret = 0;
9086
9087         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9088                 && (strcmp(res->queue, "queue") == 0)
9089                 && (strcmp(res->rate, "rate") == 0))
9090                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9091                                         res->rate_num);
9092         if (ret < 0)
9093                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9094
9095 }
9096
9097 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9098         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9099                                 set, "set");
9100 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9101         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9102                                 port, "port");
9103 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9104         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9105                                 port_num, UINT16);
9106 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9107         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9108                                 queue, "queue");
9109 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9110         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9111                                 queue_num, UINT8);
9112 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9113         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9114                                 rate, "rate");
9115 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9116         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9117                                 rate_num, UINT16);
9118
9119 cmdline_parse_inst_t cmd_queue_rate_limit = {
9120         .f = cmd_queue_rate_limit_parsed,
9121         .data = (void *)0,
9122         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9123                 "Set rate limit for a queue on port_id",
9124         .tokens = {
9125                 (void *)&cmd_queue_rate_limit_set,
9126                 (void *)&cmd_queue_rate_limit_port,
9127                 (void *)&cmd_queue_rate_limit_portnum,
9128                 (void *)&cmd_queue_rate_limit_queue,
9129                 (void *)&cmd_queue_rate_limit_queuenum,
9130                 (void *)&cmd_queue_rate_limit_rate,
9131                 (void *)&cmd_queue_rate_limit_ratenum,
9132                 NULL,
9133         },
9134 };
9135
9136 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9137 struct cmd_vf_rate_limit_result {
9138         cmdline_fixed_string_t set;
9139         cmdline_fixed_string_t port;
9140         uint16_t port_num;
9141         cmdline_fixed_string_t vf;
9142         uint8_t vf_num;
9143         cmdline_fixed_string_t rate;
9144         uint16_t rate_num;
9145         cmdline_fixed_string_t q_msk;
9146         uint64_t q_msk_val;
9147 };
9148
9149 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9150                 __rte_unused struct cmdline *cl,
9151                 __rte_unused void *data)
9152 {
9153         struct cmd_vf_rate_limit_result *res = parsed_result;
9154         int ret = 0;
9155
9156         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9157                 && (strcmp(res->vf, "vf") == 0)
9158                 && (strcmp(res->rate, "rate") == 0)
9159                 && (strcmp(res->q_msk, "queue_mask") == 0))
9160                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9161                                         res->rate_num, res->q_msk_val);
9162         if (ret < 0)
9163                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9164
9165 }
9166
9167 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9168         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9169                                 set, "set");
9170 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9171         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9172                                 port, "port");
9173 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9174         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9175                                 port_num, UINT16);
9176 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9177         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9178                                 vf, "vf");
9179 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9180         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9181                                 vf_num, UINT8);
9182 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9183         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9184                                 rate, "rate");
9185 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9186         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9187                                 rate_num, UINT16);
9188 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9189         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9190                                 q_msk, "queue_mask");
9191 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9192         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9193                                 q_msk_val, UINT64);
9194
9195 cmdline_parse_inst_t cmd_vf_rate_limit = {
9196         .f = cmd_vf_rate_limit_parsed,
9197         .data = (void *)0,
9198         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9199                 "queue_mask <queue_mask_value>: "
9200                 "Set rate limit for queues of VF on port_id",
9201         .tokens = {
9202                 (void *)&cmd_vf_rate_limit_set,
9203                 (void *)&cmd_vf_rate_limit_port,
9204                 (void *)&cmd_vf_rate_limit_portnum,
9205                 (void *)&cmd_vf_rate_limit_vf,
9206                 (void *)&cmd_vf_rate_limit_vfnum,
9207                 (void *)&cmd_vf_rate_limit_rate,
9208                 (void *)&cmd_vf_rate_limit_ratenum,
9209                 (void *)&cmd_vf_rate_limit_q_msk,
9210                 (void *)&cmd_vf_rate_limit_q_msk_val,
9211                 NULL,
9212         },
9213 };
9214
9215 /* *** ADD TUNNEL FILTER OF A PORT *** */
9216 struct cmd_tunnel_filter_result {
9217         cmdline_fixed_string_t cmd;
9218         cmdline_fixed_string_t what;
9219         portid_t port_id;
9220         struct rte_ether_addr outer_mac;
9221         struct rte_ether_addr inner_mac;
9222         cmdline_ipaddr_t ip_value;
9223         uint16_t inner_vlan;
9224         cmdline_fixed_string_t tunnel_type;
9225         cmdline_fixed_string_t filter_type;
9226         uint32_t tenant_id;
9227         uint16_t queue_num;
9228 };
9229
9230 static void
9231 cmd_tunnel_filter_parsed(void *parsed_result,
9232                           __rte_unused struct cmdline *cl,
9233                           __rte_unused void *data)
9234 {
9235         struct cmd_tunnel_filter_result *res = parsed_result;
9236         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9237         int ret = 0;
9238
9239         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9240
9241         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9242         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9243         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9244
9245         if (res->ip_value.family == AF_INET) {
9246                 tunnel_filter_conf.ip_addr.ipv4_addr =
9247                         res->ip_value.addr.ipv4.s_addr;
9248                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9249         } else {
9250                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9251                         &(res->ip_value.addr.ipv6),
9252                         sizeof(struct in6_addr));
9253                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9254         }
9255
9256         if (!strcmp(res->filter_type, "imac-ivlan"))
9257                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9258         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9259                 tunnel_filter_conf.filter_type =
9260                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9261         else if (!strcmp(res->filter_type, "imac-tenid"))
9262                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9263         else if (!strcmp(res->filter_type, "imac"))
9264                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9265         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9266                 tunnel_filter_conf.filter_type =
9267                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9268         else if (!strcmp(res->filter_type, "oip"))
9269                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9270         else if (!strcmp(res->filter_type, "iip"))
9271                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9272         else {
9273                 printf("The filter type is not supported");
9274                 return;
9275         }
9276
9277         if (!strcmp(res->tunnel_type, "vxlan"))
9278                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9279         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9280                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9281         else if (!strcmp(res->tunnel_type, "nvgre"))
9282                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9283         else if (!strcmp(res->tunnel_type, "ipingre"))
9284                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9285         else {
9286                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9287                 return;
9288         }
9289
9290         tunnel_filter_conf.tenant_id = res->tenant_id;
9291         tunnel_filter_conf.queue_id = res->queue_num;
9292         if (!strcmp(res->what, "add"))
9293                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9294                                         RTE_ETH_FILTER_TUNNEL,
9295                                         RTE_ETH_FILTER_ADD,
9296                                         &tunnel_filter_conf);
9297         else
9298                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9299                                         RTE_ETH_FILTER_TUNNEL,
9300                                         RTE_ETH_FILTER_DELETE,
9301                                         &tunnel_filter_conf);
9302         if (ret < 0)
9303                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9304                                 strerror(-ret));
9305
9306 }
9307 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9308         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9309         cmd, "tunnel_filter");
9310 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9311         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9312         what, "add#rm");
9313 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9314         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9315         port_id, UINT16);
9316 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9317         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9318         outer_mac);
9319 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9320         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9321         inner_mac);
9322 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9323         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9324         inner_vlan, UINT16);
9325 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9326         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9327         ip_value);
9328 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9329         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9330         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9331
9332 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9333         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9334         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9335                 "imac#omac-imac-tenid");
9336 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9337         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9338         tenant_id, UINT32);
9339 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9340         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9341         queue_num, UINT16);
9342
9343 cmdline_parse_inst_t cmd_tunnel_filter = {
9344         .f = cmd_tunnel_filter_parsed,
9345         .data = (void *)0,
9346         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9347                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9348                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9349                 "<queue_id>: Add/Rm tunnel filter of a port",
9350         .tokens = {
9351                 (void *)&cmd_tunnel_filter_cmd,
9352                 (void *)&cmd_tunnel_filter_what,
9353                 (void *)&cmd_tunnel_filter_port_id,
9354                 (void *)&cmd_tunnel_filter_outer_mac,
9355                 (void *)&cmd_tunnel_filter_inner_mac,
9356                 (void *)&cmd_tunnel_filter_ip_value,
9357                 (void *)&cmd_tunnel_filter_innner_vlan,
9358                 (void *)&cmd_tunnel_filter_tunnel_type,
9359                 (void *)&cmd_tunnel_filter_filter_type,
9360                 (void *)&cmd_tunnel_filter_tenant_id,
9361                 (void *)&cmd_tunnel_filter_queue_num,
9362                 NULL,
9363         },
9364 };
9365
9366 /* *** CONFIGURE TUNNEL UDP PORT *** */
9367 struct cmd_tunnel_udp_config {
9368         cmdline_fixed_string_t cmd;
9369         cmdline_fixed_string_t what;
9370         uint16_t udp_port;
9371         portid_t port_id;
9372 };
9373
9374 static void
9375 cmd_tunnel_udp_config_parsed(void *parsed_result,
9376                           __rte_unused struct cmdline *cl,
9377                           __rte_unused void *data)
9378 {
9379         struct cmd_tunnel_udp_config *res = parsed_result;
9380         struct rte_eth_udp_tunnel tunnel_udp;
9381         int ret;
9382
9383         tunnel_udp.udp_port = res->udp_port;
9384
9385         if (!strcmp(res->cmd, "rx_vxlan_port"))
9386                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9387
9388         if (!strcmp(res->what, "add"))
9389                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9390                                                       &tunnel_udp);
9391         else
9392                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9393                                                          &tunnel_udp);
9394
9395         if (ret < 0)
9396                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9397 }
9398
9399 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9400         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9401                                 cmd, "rx_vxlan_port");
9402 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9403         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9404                                 what, "add#rm");
9405 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9406         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9407                                 udp_port, UINT16);
9408 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9409         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9410                                 port_id, UINT16);
9411
9412 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9413         .f = cmd_tunnel_udp_config_parsed,
9414         .data = (void *)0,
9415         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9416                 "Add/Remove a tunneling UDP port filter",
9417         .tokens = {
9418                 (void *)&cmd_tunnel_udp_config_cmd,
9419                 (void *)&cmd_tunnel_udp_config_what,
9420                 (void *)&cmd_tunnel_udp_config_udp_port,
9421                 (void *)&cmd_tunnel_udp_config_port_id,
9422                 NULL,
9423         },
9424 };
9425
9426 struct cmd_config_tunnel_udp_port {
9427         cmdline_fixed_string_t port;
9428         cmdline_fixed_string_t config;
9429         portid_t port_id;
9430         cmdline_fixed_string_t udp_tunnel_port;
9431         cmdline_fixed_string_t action;
9432         cmdline_fixed_string_t tunnel_type;
9433         uint16_t udp_port;
9434 };
9435
9436 static void
9437 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9438                                __rte_unused struct cmdline *cl,
9439                                __rte_unused void *data)
9440 {
9441         struct cmd_config_tunnel_udp_port *res = parsed_result;
9442         struct rte_eth_udp_tunnel tunnel_udp;
9443         int ret = 0;
9444
9445         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9446                 return;
9447
9448         tunnel_udp.udp_port = res->udp_port;
9449
9450         if (!strcmp(res->tunnel_type, "vxlan")) {
9451                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9452         } else if (!strcmp(res->tunnel_type, "geneve")) {
9453                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9454         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9455                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9456         } else {
9457                 printf("Invalid tunnel type\n");
9458                 return;
9459         }
9460
9461         if (!strcmp(res->action, "add"))
9462                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9463                                                       &tunnel_udp);
9464         else
9465                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9466                                                          &tunnel_udp);
9467
9468         if (ret < 0)
9469                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9470 }
9471
9472 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9473         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9474                                  "port");
9475 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9476         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9477                                  "config");
9478 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9479         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9480                               UINT16);
9481 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9482         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9483                                  udp_tunnel_port,
9484                                  "udp_tunnel_port");
9485 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9486         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9487                                  "add#rm");
9488 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9489         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9490                                  "vxlan#geneve#vxlan-gpe");
9491 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9492         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9493                               UINT16);
9494
9495 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9496         .f = cmd_cfg_tunnel_udp_port_parsed,
9497         .data = NULL,
9498         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9499         .tokens = {
9500                 (void *)&cmd_config_tunnel_udp_port_port,
9501                 (void *)&cmd_config_tunnel_udp_port_config,
9502                 (void *)&cmd_config_tunnel_udp_port_port_id,
9503                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9504                 (void *)&cmd_config_tunnel_udp_port_action,
9505                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9506                 (void *)&cmd_config_tunnel_udp_port_value,
9507                 NULL,
9508         },
9509 };
9510
9511 /* *** GLOBAL CONFIG *** */
9512 struct cmd_global_config_result {
9513         cmdline_fixed_string_t cmd;
9514         portid_t port_id;
9515         cmdline_fixed_string_t cfg_type;
9516         uint8_t len;
9517 };
9518
9519 static void
9520 cmd_global_config_parsed(void *parsed_result,
9521                          __rte_unused struct cmdline *cl,
9522                          __rte_unused void *data)
9523 {
9524         struct cmd_global_config_result *res = parsed_result;
9525         struct rte_eth_global_cfg conf;
9526         int ret;
9527
9528         memset(&conf, 0, sizeof(conf));
9529         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9530         conf.cfg.gre_key_len = res->len;
9531         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9532                                       RTE_ETH_FILTER_SET, &conf);
9533 #ifdef RTE_NET_I40E
9534         if (ret == -ENOTSUP)
9535                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9536 #endif
9537         if (ret != 0)
9538                 printf("Global config error\n");
9539 }
9540
9541 cmdline_parse_token_string_t cmd_global_config_cmd =
9542         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9543                 "global_config");
9544 cmdline_parse_token_num_t cmd_global_config_port_id =
9545         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9546                                UINT16);
9547 cmdline_parse_token_string_t cmd_global_config_type =
9548         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9549                 cfg_type, "gre-key-len");
9550 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9551         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9552                 len, UINT8);
9553
9554 cmdline_parse_inst_t cmd_global_config = {
9555         .f = cmd_global_config_parsed,
9556         .data = (void *)NULL,
9557         .help_str = "global_config <port_id> gre-key-len <key_len>",
9558         .tokens = {
9559                 (void *)&cmd_global_config_cmd,
9560                 (void *)&cmd_global_config_port_id,
9561                 (void *)&cmd_global_config_type,
9562                 (void *)&cmd_global_config_gre_key_len,
9563                 NULL,
9564         },
9565 };
9566
9567 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9568 struct cmd_set_mirror_mask_result {
9569         cmdline_fixed_string_t set;
9570         cmdline_fixed_string_t port;
9571         portid_t port_id;
9572         cmdline_fixed_string_t mirror;
9573         uint8_t rule_id;
9574         cmdline_fixed_string_t what;
9575         cmdline_fixed_string_t value;
9576         cmdline_fixed_string_t dstpool;
9577         uint8_t dstpool_id;
9578         cmdline_fixed_string_t on;
9579 };
9580
9581 cmdline_parse_token_string_t cmd_mirror_mask_set =
9582         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9583                                 set, "set");
9584 cmdline_parse_token_string_t cmd_mirror_mask_port =
9585         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9586                                 port, "port");
9587 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9588         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9589                                 port_id, UINT16);
9590 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9591         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9592                                 mirror, "mirror-rule");
9593 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9594         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9595                                 rule_id, UINT8);
9596 cmdline_parse_token_string_t cmd_mirror_mask_what =
9597         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9598                                 what, "pool-mirror-up#pool-mirror-down"
9599                                       "#vlan-mirror");
9600 cmdline_parse_token_string_t cmd_mirror_mask_value =
9601         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9602                                 value, NULL);
9603 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9604         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9605                                 dstpool, "dst-pool");
9606 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9607         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9608                                 dstpool_id, UINT8);
9609 cmdline_parse_token_string_t cmd_mirror_mask_on =
9610         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9611                                 on, "on#off");
9612
9613 static void
9614 cmd_set_mirror_mask_parsed(void *parsed_result,
9615                        __rte_unused struct cmdline *cl,
9616                        __rte_unused void *data)
9617 {
9618         int ret,nb_item,i;
9619         struct cmd_set_mirror_mask_result *res = parsed_result;
9620         struct rte_eth_mirror_conf mr_conf;
9621
9622         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9623
9624         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9625
9626         mr_conf.dst_pool = res->dstpool_id;
9627
9628         if (!strcmp(res->what, "pool-mirror-up")) {
9629                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9630                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9631         } else if (!strcmp(res->what, "pool-mirror-down")) {
9632                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9633                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9634         } else if (!strcmp(res->what, "vlan-mirror")) {
9635                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9636                 nb_item = parse_item_list(res->value, "vlan",
9637                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9638                 if (nb_item <= 0)
9639                         return;
9640
9641                 for (i = 0; i < nb_item; i++) {
9642                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9643                                 printf("Invalid vlan_id: must be < 4096\n");
9644                                 return;
9645                         }
9646
9647                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9648                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9649                 }
9650         }
9651
9652         if (!strcmp(res->on, "on"))
9653                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9654                                                 res->rule_id, 1);
9655         else
9656                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9657                                                 res->rule_id, 0);
9658         if (ret < 0)
9659                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9660 }
9661
9662 cmdline_parse_inst_t cmd_set_mirror_mask = {
9663                 .f = cmd_set_mirror_mask_parsed,
9664                 .data = NULL,
9665                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9666                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9667                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9668                 .tokens = {
9669                         (void *)&cmd_mirror_mask_set,
9670                         (void *)&cmd_mirror_mask_port,
9671                         (void *)&cmd_mirror_mask_portid,
9672                         (void *)&cmd_mirror_mask_mirror,
9673                         (void *)&cmd_mirror_mask_ruleid,
9674                         (void *)&cmd_mirror_mask_what,
9675                         (void *)&cmd_mirror_mask_value,
9676                         (void *)&cmd_mirror_mask_dstpool,
9677                         (void *)&cmd_mirror_mask_poolid,
9678                         (void *)&cmd_mirror_mask_on,
9679                         NULL,
9680                 },
9681 };
9682
9683 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9684 struct cmd_set_mirror_link_result {
9685         cmdline_fixed_string_t set;
9686         cmdline_fixed_string_t port;
9687         portid_t port_id;
9688         cmdline_fixed_string_t mirror;
9689         uint8_t rule_id;
9690         cmdline_fixed_string_t what;
9691         cmdline_fixed_string_t dstpool;
9692         uint8_t dstpool_id;
9693         cmdline_fixed_string_t on;
9694 };
9695
9696 cmdline_parse_token_string_t cmd_mirror_link_set =
9697         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9698                                  set, "set");
9699 cmdline_parse_token_string_t cmd_mirror_link_port =
9700         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9701                                 port, "port");
9702 cmdline_parse_token_num_t cmd_mirror_link_portid =
9703         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9704                                 port_id, UINT16);
9705 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9706         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9707                                 mirror, "mirror-rule");
9708 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9709         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9710                             rule_id, UINT8);
9711 cmdline_parse_token_string_t cmd_mirror_link_what =
9712         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9713                                 what, "uplink-mirror#downlink-mirror");
9714 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9715         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9716                                 dstpool, "dst-pool");
9717 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9718         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9719                                 dstpool_id, UINT8);
9720 cmdline_parse_token_string_t cmd_mirror_link_on =
9721         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9722                                 on, "on#off");
9723
9724 static void
9725 cmd_set_mirror_link_parsed(void *parsed_result,
9726                        __rte_unused struct cmdline *cl,
9727                        __rte_unused void *data)
9728 {
9729         int ret;
9730         struct cmd_set_mirror_link_result *res = parsed_result;
9731         struct rte_eth_mirror_conf mr_conf;
9732
9733         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9734         if (!strcmp(res->what, "uplink-mirror"))
9735                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9736         else
9737                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9738
9739         mr_conf.dst_pool = res->dstpool_id;
9740
9741         if (!strcmp(res->on, "on"))
9742                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9743                                                 res->rule_id, 1);
9744         else
9745                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9746                                                 res->rule_id, 0);
9747
9748         /* check the return value and print it if is < 0 */
9749         if (ret < 0)
9750                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9751
9752 }
9753
9754 cmdline_parse_inst_t cmd_set_mirror_link = {
9755                 .f = cmd_set_mirror_link_parsed,
9756                 .data = NULL,
9757                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9758                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9759                 .tokens = {
9760                         (void *)&cmd_mirror_link_set,
9761                         (void *)&cmd_mirror_link_port,
9762                         (void *)&cmd_mirror_link_portid,
9763                         (void *)&cmd_mirror_link_mirror,
9764                         (void *)&cmd_mirror_link_ruleid,
9765                         (void *)&cmd_mirror_link_what,
9766                         (void *)&cmd_mirror_link_dstpool,
9767                         (void *)&cmd_mirror_link_poolid,
9768                         (void *)&cmd_mirror_link_on,
9769                         NULL,
9770                 },
9771 };
9772
9773 /* *** RESET VM MIRROR RULE *** */
9774 struct cmd_rm_mirror_rule_result {
9775         cmdline_fixed_string_t reset;
9776         cmdline_fixed_string_t port;
9777         portid_t port_id;
9778         cmdline_fixed_string_t mirror;
9779         uint8_t rule_id;
9780 };
9781
9782 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9783         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9784                                  reset, "reset");
9785 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9786         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9787                                 port, "port");
9788 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9789         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9790                                 port_id, UINT16);
9791 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9792         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9793                                 mirror, "mirror-rule");
9794 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9795         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9796                                 rule_id, UINT8);
9797
9798 static void
9799 cmd_reset_mirror_rule_parsed(void *parsed_result,
9800                        __rte_unused struct cmdline *cl,
9801                        __rte_unused void *data)
9802 {
9803         int ret;
9804         struct cmd_set_mirror_link_result *res = parsed_result;
9805         /* check rule_id */
9806         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9807         if(ret < 0)
9808                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9809 }
9810
9811 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9812                 .f = cmd_reset_mirror_rule_parsed,
9813                 .data = NULL,
9814                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9815                 .tokens = {
9816                         (void *)&cmd_rm_mirror_rule_reset,
9817                         (void *)&cmd_rm_mirror_rule_port,
9818                         (void *)&cmd_rm_mirror_rule_portid,
9819                         (void *)&cmd_rm_mirror_rule_mirror,
9820                         (void *)&cmd_rm_mirror_rule_ruleid,
9821                         NULL,
9822                 },
9823 };
9824
9825 /* ******************************************************************************** */
9826
9827 struct cmd_dump_result {
9828         cmdline_fixed_string_t dump;
9829 };
9830
9831 static void
9832 dump_struct_sizes(void)
9833 {
9834 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9835         DUMP_SIZE(struct rte_mbuf);
9836         DUMP_SIZE(struct rte_mempool);
9837         DUMP_SIZE(struct rte_ring);
9838 #undef DUMP_SIZE
9839 }
9840
9841
9842 /* Dump the socket memory statistics on console */
9843 static void
9844 dump_socket_mem(FILE *f)
9845 {
9846         struct rte_malloc_socket_stats socket_stats;
9847         unsigned int i;
9848         size_t total = 0;
9849         size_t alloc = 0;
9850         size_t free = 0;
9851         unsigned int n_alloc = 0;
9852         unsigned int n_free = 0;
9853         static size_t last_allocs;
9854         static size_t last_total;
9855
9856
9857         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9858                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9859                     !socket_stats.heap_totalsz_bytes)
9860                         continue;
9861                 total += socket_stats.heap_totalsz_bytes;
9862                 alloc += socket_stats.heap_allocsz_bytes;
9863                 free += socket_stats.heap_freesz_bytes;
9864                 n_alloc += socket_stats.alloc_count;
9865                 n_free += socket_stats.free_count;
9866                 fprintf(f,
9867                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9868                         i,
9869                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9870                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9871                         (double)socket_stats.heap_allocsz_bytes * 100 /
9872                         (double)socket_stats.heap_totalsz_bytes,
9873                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9874                         socket_stats.alloc_count,
9875                         socket_stats.free_count);
9876         }
9877         fprintf(f,
9878                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9879                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9880                 (double)alloc * 100 / (double)total,
9881                 (double)free / (1024 * 1024),
9882                 n_alloc, n_free);
9883         if (last_allocs)
9884                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9885                         ((double)total - (double)last_total) / (1024 * 1024),
9886                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9887         last_allocs = alloc;
9888         last_total = total;
9889 }
9890
9891 static void cmd_dump_parsed(void *parsed_result,
9892                             __rte_unused struct cmdline *cl,
9893                             __rte_unused void *data)
9894 {
9895         struct cmd_dump_result *res = parsed_result;
9896
9897         if (!strcmp(res->dump, "dump_physmem"))
9898                 rte_dump_physmem_layout(stdout);
9899         else if (!strcmp(res->dump, "dump_socket_mem"))
9900                 dump_socket_mem(stdout);
9901         else if (!strcmp(res->dump, "dump_memzone"))
9902                 rte_memzone_dump(stdout);
9903         else if (!strcmp(res->dump, "dump_struct_sizes"))
9904                 dump_struct_sizes();
9905         else if (!strcmp(res->dump, "dump_ring"))
9906                 rte_ring_list_dump(stdout);
9907         else if (!strcmp(res->dump, "dump_mempool"))
9908                 rte_mempool_list_dump(stdout);
9909         else if (!strcmp(res->dump, "dump_devargs"))
9910                 rte_devargs_dump(stdout);
9911         else if (!strcmp(res->dump, "dump_log_types"))
9912                 rte_log_dump(stdout);
9913 }
9914
9915 cmdline_parse_token_string_t cmd_dump_dump =
9916         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9917                 "dump_physmem#"
9918                 "dump_memzone#"
9919                 "dump_socket_mem#"
9920                 "dump_struct_sizes#"
9921                 "dump_ring#"
9922                 "dump_mempool#"
9923                 "dump_devargs#"
9924                 "dump_log_types");
9925
9926 cmdline_parse_inst_t cmd_dump = {
9927         .f = cmd_dump_parsed,  /* function to call */
9928         .data = NULL,      /* 2nd arg of func */
9929         .help_str = "Dump status",
9930         .tokens = {        /* token list, NULL terminated */
9931                 (void *)&cmd_dump_dump,
9932                 NULL,
9933         },
9934 };
9935
9936 /* ******************************************************************************** */
9937
9938 struct cmd_dump_one_result {
9939         cmdline_fixed_string_t dump;
9940         cmdline_fixed_string_t name;
9941 };
9942
9943 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9944                                 __rte_unused void *data)
9945 {
9946         struct cmd_dump_one_result *res = parsed_result;
9947
9948         if (!strcmp(res->dump, "dump_ring")) {
9949                 struct rte_ring *r;
9950                 r = rte_ring_lookup(res->name);
9951                 if (r == NULL) {
9952                         cmdline_printf(cl, "Cannot find ring\n");
9953                         return;
9954                 }
9955                 rte_ring_dump(stdout, r);
9956         } else if (!strcmp(res->dump, "dump_mempool")) {
9957                 struct rte_mempool *mp;
9958                 mp = rte_mempool_lookup(res->name);
9959                 if (mp == NULL) {
9960                         cmdline_printf(cl, "Cannot find mempool\n");
9961                         return;
9962                 }
9963                 rte_mempool_dump(stdout, mp);
9964         }
9965 }
9966
9967 cmdline_parse_token_string_t cmd_dump_one_dump =
9968         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9969                                  "dump_ring#dump_mempool");
9970
9971 cmdline_parse_token_string_t cmd_dump_one_name =
9972         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9973
9974 cmdline_parse_inst_t cmd_dump_one = {
9975         .f = cmd_dump_one_parsed,  /* function to call */
9976         .data = NULL,      /* 2nd arg of func */
9977         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9978         .tokens = {        /* token list, NULL terminated */
9979                 (void *)&cmd_dump_one_dump,
9980                 (void *)&cmd_dump_one_name,
9981                 NULL,
9982         },
9983 };
9984
9985 /* *** Add/Del syn filter *** */
9986 struct cmd_syn_filter_result {
9987         cmdline_fixed_string_t filter;
9988         portid_t port_id;
9989         cmdline_fixed_string_t ops;
9990         cmdline_fixed_string_t priority;
9991         cmdline_fixed_string_t high;
9992         cmdline_fixed_string_t queue;
9993         uint16_t queue_id;
9994 };
9995
9996 static void
9997 cmd_syn_filter_parsed(void *parsed_result,
9998                         __rte_unused struct cmdline *cl,
9999                         __rte_unused void *data)
10000 {
10001         struct cmd_syn_filter_result *res = parsed_result;
10002         struct rte_eth_syn_filter syn_filter;
10003         int ret = 0;
10004
10005         ret = rte_eth_dev_filter_supported(res->port_id,
10006                                         RTE_ETH_FILTER_SYN);
10007         if (ret < 0) {
10008                 printf("syn filter is not supported on port %u.\n",
10009                                 res->port_id);
10010                 return;
10011         }
10012
10013         memset(&syn_filter, 0, sizeof(syn_filter));
10014
10015         if (!strcmp(res->ops, "add")) {
10016                 if (!strcmp(res->high, "high"))
10017                         syn_filter.hig_pri = 1;
10018                 else
10019                         syn_filter.hig_pri = 0;
10020
10021                 syn_filter.queue = res->queue_id;
10022                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10023                                                 RTE_ETH_FILTER_SYN,
10024                                                 RTE_ETH_FILTER_ADD,
10025                                                 &syn_filter);
10026         } else
10027                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10028                                                 RTE_ETH_FILTER_SYN,
10029                                                 RTE_ETH_FILTER_DELETE,
10030                                                 &syn_filter);
10031
10032         if (ret < 0)
10033                 printf("syn filter programming error: (%s)\n",
10034                                 strerror(-ret));
10035 }
10036
10037 cmdline_parse_token_string_t cmd_syn_filter_filter =
10038         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10039         filter, "syn_filter");
10040 cmdline_parse_token_num_t cmd_syn_filter_port_id =
10041         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10042         port_id, UINT16);
10043 cmdline_parse_token_string_t cmd_syn_filter_ops =
10044         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10045         ops, "add#del");
10046 cmdline_parse_token_string_t cmd_syn_filter_priority =
10047         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10048                                 priority, "priority");
10049 cmdline_parse_token_string_t cmd_syn_filter_high =
10050         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10051                                 high, "high#low");
10052 cmdline_parse_token_string_t cmd_syn_filter_queue =
10053         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10054                                 queue, "queue");
10055 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
10056         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10057                                 queue_id, UINT16);
10058
10059 cmdline_parse_inst_t cmd_syn_filter = {
10060         .f = cmd_syn_filter_parsed,
10061         .data = NULL,
10062         .help_str = "syn_filter <port_id> add|del priority high|low queue "
10063                 "<queue_id>: Add/Delete syn filter",
10064         .tokens = {
10065                 (void *)&cmd_syn_filter_filter,
10066                 (void *)&cmd_syn_filter_port_id,
10067                 (void *)&cmd_syn_filter_ops,
10068                 (void *)&cmd_syn_filter_priority,
10069                 (void *)&cmd_syn_filter_high,
10070                 (void *)&cmd_syn_filter_queue,
10071                 (void *)&cmd_syn_filter_queue_id,
10072                 NULL,
10073         },
10074 };
10075
10076 /* *** queue region set *** */
10077 struct cmd_queue_region_result {
10078         cmdline_fixed_string_t set;
10079         cmdline_fixed_string_t port;
10080         portid_t port_id;
10081         cmdline_fixed_string_t cmd;
10082         cmdline_fixed_string_t region;
10083         uint8_t  region_id;
10084         cmdline_fixed_string_t queue_start_index;
10085         uint8_t  queue_id;
10086         cmdline_fixed_string_t queue_num;
10087         uint8_t  queue_num_value;
10088 };
10089
10090 static void
10091 cmd_queue_region_parsed(void *parsed_result,
10092                         __rte_unused struct cmdline *cl,
10093                         __rte_unused void *data)
10094 {
10095         struct cmd_queue_region_result *res = parsed_result;
10096         int ret = -ENOTSUP;
10097 #ifdef RTE_NET_I40E
10098         struct rte_pmd_i40e_queue_region_conf region_conf;
10099         enum rte_pmd_i40e_queue_region_op op_type;
10100 #endif
10101
10102         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10103                 return;
10104
10105 #ifdef RTE_NET_I40E
10106         memset(&region_conf, 0, sizeof(region_conf));
10107         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10108         region_conf.region_id = res->region_id;
10109         region_conf.queue_num = res->queue_num_value;
10110         region_conf.queue_start_index = res->queue_id;
10111
10112         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10113                                 op_type, &region_conf);
10114 #endif
10115
10116         switch (ret) {
10117         case 0:
10118                 break;
10119         case -ENOTSUP:
10120                 printf("function not implemented or supported\n");
10121                 break;
10122         default:
10123                 printf("queue region config error: (%s)\n", strerror(-ret));
10124         }
10125 }
10126
10127 cmdline_parse_token_string_t cmd_queue_region_set =
10128 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10129                 set, "set");
10130 cmdline_parse_token_string_t cmd_queue_region_port =
10131         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10132 cmdline_parse_token_num_t cmd_queue_region_port_id =
10133         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10134                                 port_id, UINT16);
10135 cmdline_parse_token_string_t cmd_queue_region_cmd =
10136         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10137                                  cmd, "queue-region");
10138 cmdline_parse_token_string_t cmd_queue_region_id =
10139         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10140                                 region, "region_id");
10141 cmdline_parse_token_num_t cmd_queue_region_index =
10142         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10143                                 region_id, UINT8);
10144 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10145         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10146                                 queue_start_index, "queue_start_index");
10147 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10148         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10149                                 queue_id, UINT8);
10150 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10151         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10152                                 queue_num, "queue_num");
10153 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10154         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10155                                 queue_num_value, UINT8);
10156
10157 cmdline_parse_inst_t cmd_queue_region = {
10158         .f = cmd_queue_region_parsed,
10159         .data = NULL,
10160         .help_str = "set port <port_id> queue-region region_id <value> "
10161                 "queue_start_index <value> queue_num <value>: Set a queue region",
10162         .tokens = {
10163                 (void *)&cmd_queue_region_set,
10164                 (void *)&cmd_queue_region_port,
10165                 (void *)&cmd_queue_region_port_id,
10166                 (void *)&cmd_queue_region_cmd,
10167                 (void *)&cmd_queue_region_id,
10168                 (void *)&cmd_queue_region_index,
10169                 (void *)&cmd_queue_region_queue_start_index,
10170                 (void *)&cmd_queue_region_queue_id,
10171                 (void *)&cmd_queue_region_queue_num,
10172                 (void *)&cmd_queue_region_queue_num_value,
10173                 NULL,
10174         },
10175 };
10176
10177 /* *** queue region and flowtype set *** */
10178 struct cmd_region_flowtype_result {
10179         cmdline_fixed_string_t set;
10180         cmdline_fixed_string_t port;
10181         portid_t port_id;
10182         cmdline_fixed_string_t cmd;
10183         cmdline_fixed_string_t region;
10184         uint8_t  region_id;
10185         cmdline_fixed_string_t flowtype;
10186         uint8_t  flowtype_id;
10187 };
10188
10189 static void
10190 cmd_region_flowtype_parsed(void *parsed_result,
10191                         __rte_unused struct cmdline *cl,
10192                         __rte_unused void *data)
10193 {
10194         struct cmd_region_flowtype_result *res = parsed_result;
10195         int ret = -ENOTSUP;
10196 #ifdef RTE_NET_I40E
10197         struct rte_pmd_i40e_queue_region_conf region_conf;
10198         enum rte_pmd_i40e_queue_region_op op_type;
10199 #endif
10200
10201         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10202                 return;
10203
10204 #ifdef RTE_NET_I40E
10205         memset(&region_conf, 0, sizeof(region_conf));
10206
10207         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10208         region_conf.region_id = res->region_id;
10209         region_conf.hw_flowtype = res->flowtype_id;
10210
10211         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10212                         op_type, &region_conf);
10213 #endif
10214
10215         switch (ret) {
10216         case 0:
10217                 break;
10218         case -ENOTSUP:
10219                 printf("function not implemented or supported\n");
10220                 break;
10221         default:
10222                 printf("region flowtype config error: (%s)\n", strerror(-ret));
10223         }
10224 }
10225
10226 cmdline_parse_token_string_t cmd_region_flowtype_set =
10227 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10228                                 set, "set");
10229 cmdline_parse_token_string_t cmd_region_flowtype_port =
10230         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10231                                 port, "port");
10232 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10233         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10234                                 port_id, UINT16);
10235 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10236         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10237                                 cmd, "queue-region");
10238 cmdline_parse_token_string_t cmd_region_flowtype_index =
10239         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10240                                 region, "region_id");
10241 cmdline_parse_token_num_t cmd_region_flowtype_id =
10242         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10243                                 region_id, UINT8);
10244 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10245         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10246                                 flowtype, "flowtype");
10247 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10248         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10249                                 flowtype_id, UINT8);
10250 cmdline_parse_inst_t cmd_region_flowtype = {
10251         .f = cmd_region_flowtype_parsed,
10252         .data = NULL,
10253         .help_str = "set port <port_id> queue-region region_id <value> "
10254                 "flowtype <value>: Set a flowtype region index",
10255         .tokens = {
10256                 (void *)&cmd_region_flowtype_set,
10257                 (void *)&cmd_region_flowtype_port,
10258                 (void *)&cmd_region_flowtype_port_index,
10259                 (void *)&cmd_region_flowtype_cmd,
10260                 (void *)&cmd_region_flowtype_index,
10261                 (void *)&cmd_region_flowtype_id,
10262                 (void *)&cmd_region_flowtype_flow_index,
10263                 (void *)&cmd_region_flowtype_flow_id,
10264                 NULL,
10265         },
10266 };
10267
10268 /* *** User Priority (UP) to queue region (region_id) set *** */
10269 struct cmd_user_priority_region_result {
10270         cmdline_fixed_string_t set;
10271         cmdline_fixed_string_t port;
10272         portid_t port_id;
10273         cmdline_fixed_string_t cmd;
10274         cmdline_fixed_string_t user_priority;
10275         uint8_t  user_priority_id;
10276         cmdline_fixed_string_t region;
10277         uint8_t  region_id;
10278 };
10279
10280 static void
10281 cmd_user_priority_region_parsed(void *parsed_result,
10282                         __rte_unused struct cmdline *cl,
10283                         __rte_unused void *data)
10284 {
10285         struct cmd_user_priority_region_result *res = parsed_result;
10286         int ret = -ENOTSUP;
10287 #ifdef RTE_NET_I40E
10288         struct rte_pmd_i40e_queue_region_conf region_conf;
10289         enum rte_pmd_i40e_queue_region_op op_type;
10290 #endif
10291
10292         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10293                 return;
10294
10295 #ifdef RTE_NET_I40E
10296         memset(&region_conf, 0, sizeof(region_conf));
10297         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10298         region_conf.user_priority = res->user_priority_id;
10299         region_conf.region_id = res->region_id;
10300
10301         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10302                                 op_type, &region_conf);
10303 #endif
10304
10305         switch (ret) {
10306         case 0:
10307                 break;
10308         case -ENOTSUP:
10309                 printf("function not implemented or supported\n");
10310                 break;
10311         default:
10312                 printf("user_priority region config error: (%s)\n",
10313                                 strerror(-ret));
10314         }
10315 }
10316
10317 cmdline_parse_token_string_t cmd_user_priority_region_set =
10318         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10319                                 set, "set");
10320 cmdline_parse_token_string_t cmd_user_priority_region_port =
10321         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10322                                 port, "port");
10323 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10324         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10325                                 port_id, UINT16);
10326 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10327         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10328                                 cmd, "queue-region");
10329 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10330         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10331                                 user_priority, "UP");
10332 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10333         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10334                                 user_priority_id, UINT8);
10335 cmdline_parse_token_string_t cmd_user_priority_region_region =
10336         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10337                                 region, "region_id");
10338 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10339         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10340                                 region_id, UINT8);
10341
10342 cmdline_parse_inst_t cmd_user_priority_region = {
10343         .f = cmd_user_priority_region_parsed,
10344         .data = NULL,
10345         .help_str = "set port <port_id> queue-region UP <value> "
10346                 "region_id <value>: Set the mapping of User Priority (UP) "
10347                 "to queue region (region_id) ",
10348         .tokens = {
10349                 (void *)&cmd_user_priority_region_set,
10350                 (void *)&cmd_user_priority_region_port,
10351                 (void *)&cmd_user_priority_region_port_index,
10352                 (void *)&cmd_user_priority_region_cmd,
10353                 (void *)&cmd_user_priority_region_UP,
10354                 (void *)&cmd_user_priority_region_UP_id,
10355                 (void *)&cmd_user_priority_region_region,
10356                 (void *)&cmd_user_priority_region_region_id,
10357                 NULL,
10358         },
10359 };
10360
10361 /* *** flush all queue region related configuration *** */
10362 struct cmd_flush_queue_region_result {
10363         cmdline_fixed_string_t set;
10364         cmdline_fixed_string_t port;
10365         portid_t port_id;
10366         cmdline_fixed_string_t cmd;
10367         cmdline_fixed_string_t flush;
10368         cmdline_fixed_string_t what;
10369 };
10370
10371 static void
10372 cmd_flush_queue_region_parsed(void *parsed_result,
10373                         __rte_unused struct cmdline *cl,
10374                         __rte_unused void *data)
10375 {
10376         struct cmd_flush_queue_region_result *res = parsed_result;
10377         int ret = -ENOTSUP;
10378 #ifdef RTE_NET_I40E
10379         struct rte_pmd_i40e_queue_region_conf region_conf;
10380         enum rte_pmd_i40e_queue_region_op op_type;
10381 #endif
10382
10383         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10384                 return;
10385
10386 #ifdef RTE_NET_I40E
10387         memset(&region_conf, 0, sizeof(region_conf));
10388
10389         if (strcmp(res->what, "on") == 0)
10390                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10391         else
10392                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10393
10394         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10395                                 op_type, &region_conf);
10396 #endif
10397
10398         switch (ret) {
10399         case 0:
10400                 break;
10401         case -ENOTSUP:
10402                 printf("function not implemented or supported\n");
10403                 break;
10404         default:
10405                 printf("queue region config flush error: (%s)\n",
10406                                 strerror(-ret));
10407         }
10408 }
10409
10410 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10411         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10412                                 set, "set");
10413 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10414         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10415                                 port, "port");
10416 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10417         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10418                                 port_id, UINT16);
10419 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10420         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10421                                 cmd, "queue-region");
10422 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10423         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10424                                 flush, "flush");
10425 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10426         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10427                                 what, "on#off");
10428
10429 cmdline_parse_inst_t cmd_flush_queue_region = {
10430         .f = cmd_flush_queue_region_parsed,
10431         .data = NULL,
10432         .help_str = "set port <port_id> queue-region flush on|off"
10433                 ": flush all queue region related configuration",
10434         .tokens = {
10435                 (void *)&cmd_flush_queue_region_set,
10436                 (void *)&cmd_flush_queue_region_port,
10437                 (void *)&cmd_flush_queue_region_port_index,
10438                 (void *)&cmd_flush_queue_region_cmd,
10439                 (void *)&cmd_flush_queue_region_flush,
10440                 (void *)&cmd_flush_queue_region_what,
10441                 NULL,
10442         },
10443 };
10444
10445 /* *** get all queue region related configuration info *** */
10446 struct cmd_show_queue_region_info {
10447         cmdline_fixed_string_t show;
10448         cmdline_fixed_string_t port;
10449         portid_t port_id;
10450         cmdline_fixed_string_t cmd;
10451 };
10452
10453 static void
10454 cmd_show_queue_region_info_parsed(void *parsed_result,
10455                         __rte_unused struct cmdline *cl,
10456                         __rte_unused void *data)
10457 {
10458         struct cmd_show_queue_region_info *res = parsed_result;
10459         int ret = -ENOTSUP;
10460 #ifdef RTE_NET_I40E
10461         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10462         enum rte_pmd_i40e_queue_region_op op_type;
10463 #endif
10464
10465         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10466                 return;
10467
10468 #ifdef RTE_NET_I40E
10469         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10470
10471         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10472
10473         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10474                                         op_type, &rte_pmd_regions);
10475
10476         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10477 #endif
10478
10479         switch (ret) {
10480         case 0:
10481                 break;
10482         case -ENOTSUP:
10483                 printf("function not implemented or supported\n");
10484                 break;
10485         default:
10486                 printf("queue region config info show error: (%s)\n",
10487                                 strerror(-ret));
10488         }
10489 }
10490
10491 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10492 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10493                                 show, "show");
10494 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10495         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10496                                 port, "port");
10497 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10498         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10499                                 port_id, UINT16);
10500 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10501         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10502                                 cmd, "queue-region");
10503
10504 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10505         .f = cmd_show_queue_region_info_parsed,
10506         .data = NULL,
10507         .help_str = "show port <port_id> queue-region"
10508                 ": show all queue region related configuration info",
10509         .tokens = {
10510                 (void *)&cmd_show_queue_region_info_get,
10511                 (void *)&cmd_show_queue_region_info_port,
10512                 (void *)&cmd_show_queue_region_info_port_index,
10513                 (void *)&cmd_show_queue_region_info_cmd,
10514                 NULL,
10515         },
10516 };
10517
10518 /* *** ADD/REMOVE A 2tuple FILTER *** */
10519 struct cmd_2tuple_filter_result {
10520         cmdline_fixed_string_t filter;
10521         portid_t port_id;
10522         cmdline_fixed_string_t ops;
10523         cmdline_fixed_string_t dst_port;
10524         uint16_t dst_port_value;
10525         cmdline_fixed_string_t protocol;
10526         uint8_t protocol_value;
10527         cmdline_fixed_string_t mask;
10528         uint8_t  mask_value;
10529         cmdline_fixed_string_t tcp_flags;
10530         uint8_t tcp_flags_value;
10531         cmdline_fixed_string_t priority;
10532         uint8_t  priority_value;
10533         cmdline_fixed_string_t queue;
10534         uint16_t  queue_id;
10535 };
10536
10537 static void
10538 cmd_2tuple_filter_parsed(void *parsed_result,
10539                         __rte_unused struct cmdline *cl,
10540                         __rte_unused void *data)
10541 {
10542         struct rte_eth_ntuple_filter filter;
10543         struct cmd_2tuple_filter_result *res = parsed_result;
10544         int ret = 0;
10545
10546         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10547         if (ret < 0) {
10548                 printf("ntuple filter is not supported on port %u.\n",
10549                         res->port_id);
10550                 return;
10551         }
10552
10553         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10554
10555         filter.flags = RTE_2TUPLE_FLAGS;
10556         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10557         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10558         filter.proto = res->protocol_value;
10559         filter.priority = res->priority_value;
10560         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10561                 printf("nonzero tcp_flags is only meaningful"
10562                         " when protocol is TCP.\n");
10563                 return;
10564         }
10565         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10566                 printf("invalid TCP flags.\n");
10567                 return;
10568         }
10569
10570         if (res->tcp_flags_value != 0) {
10571                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10572                 filter.tcp_flags = res->tcp_flags_value;
10573         }
10574
10575         /* need convert to big endian. */
10576         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10577         filter.queue = res->queue_id;
10578
10579         if (!strcmp(res->ops, "add"))
10580                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10581                                 RTE_ETH_FILTER_NTUPLE,
10582                                 RTE_ETH_FILTER_ADD,
10583                                 &filter);
10584         else
10585                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10586                                 RTE_ETH_FILTER_NTUPLE,
10587                                 RTE_ETH_FILTER_DELETE,
10588                                 &filter);
10589         if (ret < 0)
10590                 printf("2tuple filter programming error: (%s)\n",
10591                         strerror(-ret));
10592
10593 }
10594
10595 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10596         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10597                                  filter, "2tuple_filter");
10598 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10599         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10600                                 port_id, UINT16);
10601 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10602         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10603                                  ops, "add#del");
10604 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10605         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10606                                 dst_port, "dst_port");
10607 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10608         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10609                                 dst_port_value, UINT16);
10610 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10611         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10612                                 protocol, "protocol");
10613 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10614         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10615                                 protocol_value, UINT8);
10616 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10617         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10618                                 mask, "mask");
10619 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10620         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10621                                 mask_value, INT8);
10622 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10623         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10624                                 tcp_flags, "tcp_flags");
10625 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10626         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10627                                 tcp_flags_value, UINT8);
10628 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10629         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10630                                 priority, "priority");
10631 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10632         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10633                                 priority_value, UINT8);
10634 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10635         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10636                                 queue, "queue");
10637 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10638         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10639                                 queue_id, UINT16);
10640
10641 cmdline_parse_inst_t cmd_2tuple_filter = {
10642         .f = cmd_2tuple_filter_parsed,
10643         .data = NULL,
10644         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10645                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10646                 "<queue_id>: Add a 2tuple filter",
10647         .tokens = {
10648                 (void *)&cmd_2tuple_filter_filter,
10649                 (void *)&cmd_2tuple_filter_port_id,
10650                 (void *)&cmd_2tuple_filter_ops,
10651                 (void *)&cmd_2tuple_filter_dst_port,
10652                 (void *)&cmd_2tuple_filter_dst_port_value,
10653                 (void *)&cmd_2tuple_filter_protocol,
10654                 (void *)&cmd_2tuple_filter_protocol_value,
10655                 (void *)&cmd_2tuple_filter_mask,
10656                 (void *)&cmd_2tuple_filter_mask_value,
10657                 (void *)&cmd_2tuple_filter_tcp_flags,
10658                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10659                 (void *)&cmd_2tuple_filter_priority,
10660                 (void *)&cmd_2tuple_filter_priority_value,
10661                 (void *)&cmd_2tuple_filter_queue,
10662                 (void *)&cmd_2tuple_filter_queue_id,
10663                 NULL,
10664         },
10665 };
10666
10667 /* *** ADD/REMOVE A 5tuple FILTER *** */
10668 struct cmd_5tuple_filter_result {
10669         cmdline_fixed_string_t filter;
10670         portid_t port_id;
10671         cmdline_fixed_string_t ops;
10672         cmdline_fixed_string_t dst_ip;
10673         cmdline_ipaddr_t dst_ip_value;
10674         cmdline_fixed_string_t src_ip;
10675         cmdline_ipaddr_t src_ip_value;
10676         cmdline_fixed_string_t dst_port;
10677         uint16_t dst_port_value;
10678         cmdline_fixed_string_t src_port;
10679         uint16_t src_port_value;
10680         cmdline_fixed_string_t protocol;
10681         uint8_t protocol_value;
10682         cmdline_fixed_string_t mask;
10683         uint8_t  mask_value;
10684         cmdline_fixed_string_t tcp_flags;
10685         uint8_t tcp_flags_value;
10686         cmdline_fixed_string_t priority;
10687         uint8_t  priority_value;
10688         cmdline_fixed_string_t queue;
10689         uint16_t  queue_id;
10690 };
10691
10692 static void
10693 cmd_5tuple_filter_parsed(void *parsed_result,
10694                         __rte_unused struct cmdline *cl,
10695                         __rte_unused void *data)
10696 {
10697         struct rte_eth_ntuple_filter filter;
10698         struct cmd_5tuple_filter_result *res = parsed_result;
10699         int ret = 0;
10700
10701         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10702         if (ret < 0) {
10703                 printf("ntuple filter is not supported on port %u.\n",
10704                         res->port_id);
10705                 return;
10706         }
10707
10708         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10709
10710         filter.flags = RTE_5TUPLE_FLAGS;
10711         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10712         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10713         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10714         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10715         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10716         filter.proto = res->protocol_value;
10717         filter.priority = res->priority_value;
10718         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10719                 printf("nonzero tcp_flags is only meaningful"
10720                         " when protocol is TCP.\n");
10721                 return;
10722         }
10723         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10724                 printf("invalid TCP flags.\n");
10725                 return;
10726         }
10727
10728         if (res->tcp_flags_value != 0) {
10729                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10730                 filter.tcp_flags = res->tcp_flags_value;
10731         }
10732
10733         if (res->dst_ip_value.family == AF_INET)
10734                 /* no need to convert, already big endian. */
10735                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10736         else {
10737                 if (filter.dst_ip_mask == 0) {
10738                         printf("can not support ipv6 involved compare.\n");
10739                         return;
10740                 }
10741                 filter.dst_ip = 0;
10742         }
10743
10744         if (res->src_ip_value.family == AF_INET)
10745                 /* no need to convert, already big endian. */
10746                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10747         else {
10748                 if (filter.src_ip_mask == 0) {
10749                         printf("can not support ipv6 involved compare.\n");
10750                         return;
10751                 }
10752                 filter.src_ip = 0;
10753         }
10754         /* need convert to big endian. */
10755         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10756         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10757         filter.queue = res->queue_id;
10758
10759         if (!strcmp(res->ops, "add"))
10760                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10761                                 RTE_ETH_FILTER_NTUPLE,
10762                                 RTE_ETH_FILTER_ADD,
10763                                 &filter);
10764         else
10765                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10766                                 RTE_ETH_FILTER_NTUPLE,
10767                                 RTE_ETH_FILTER_DELETE,
10768                                 &filter);
10769         if (ret < 0)
10770                 printf("5tuple filter programming error: (%s)\n",
10771                         strerror(-ret));
10772 }
10773
10774 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10775         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10776                                  filter, "5tuple_filter");
10777 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10778         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10779                                 port_id, UINT16);
10780 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10781         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10782                                  ops, "add#del");
10783 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10784         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10785                                 dst_ip, "dst_ip");
10786 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10787         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10788                                 dst_ip_value);
10789 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10790         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10791                                 src_ip, "src_ip");
10792 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10793         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10794                                 src_ip_value);
10795 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10796         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10797                                 dst_port, "dst_port");
10798 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10799         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10800                                 dst_port_value, UINT16);
10801 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10802         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10803                                 src_port, "src_port");
10804 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10805         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10806                                 src_port_value, UINT16);
10807 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10808         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10809                                 protocol, "protocol");
10810 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10811         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10812                                 protocol_value, UINT8);
10813 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10814         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10815                                 mask, "mask");
10816 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10817         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10818                                 mask_value, INT8);
10819 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10820         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10821                                 tcp_flags, "tcp_flags");
10822 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10823         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10824                                 tcp_flags_value, UINT8);
10825 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10826         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10827                                 priority, "priority");
10828 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10829         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10830                                 priority_value, UINT8);
10831 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10832         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10833                                 queue, "queue");
10834 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10835         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10836                                 queue_id, UINT16);
10837
10838 cmdline_parse_inst_t cmd_5tuple_filter = {
10839         .f = cmd_5tuple_filter_parsed,
10840         .data = NULL,
10841         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10842                 "src_ip <value> dst_port <value> src_port <value> "
10843                 "protocol <value>  mask <value> tcp_flags <value> "
10844                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10845         .tokens = {
10846                 (void *)&cmd_5tuple_filter_filter,
10847                 (void *)&cmd_5tuple_filter_port_id,
10848                 (void *)&cmd_5tuple_filter_ops,
10849                 (void *)&cmd_5tuple_filter_dst_ip,
10850                 (void *)&cmd_5tuple_filter_dst_ip_value,
10851                 (void *)&cmd_5tuple_filter_src_ip,
10852                 (void *)&cmd_5tuple_filter_src_ip_value,
10853                 (void *)&cmd_5tuple_filter_dst_port,
10854                 (void *)&cmd_5tuple_filter_dst_port_value,
10855                 (void *)&cmd_5tuple_filter_src_port,
10856                 (void *)&cmd_5tuple_filter_src_port_value,
10857                 (void *)&cmd_5tuple_filter_protocol,
10858                 (void *)&cmd_5tuple_filter_protocol_value,
10859                 (void *)&cmd_5tuple_filter_mask,
10860                 (void *)&cmd_5tuple_filter_mask_value,
10861                 (void *)&cmd_5tuple_filter_tcp_flags,
10862                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10863                 (void *)&cmd_5tuple_filter_priority,
10864                 (void *)&cmd_5tuple_filter_priority_value,
10865                 (void *)&cmd_5tuple_filter_queue,
10866                 (void *)&cmd_5tuple_filter_queue_id,
10867                 NULL,
10868         },
10869 };
10870
10871 /* *** Filters Control *** */
10872
10873 /* *** deal with flow director filter *** */
10874 struct cmd_flow_director_result {
10875         cmdline_fixed_string_t flow_director_filter;
10876         portid_t port_id;
10877         cmdline_fixed_string_t mode;
10878         cmdline_fixed_string_t mode_value;
10879         cmdline_fixed_string_t ops;
10880         cmdline_fixed_string_t flow;
10881         cmdline_fixed_string_t flow_type;
10882         cmdline_fixed_string_t ether;
10883         uint16_t ether_type;
10884         cmdline_fixed_string_t src;
10885         cmdline_ipaddr_t ip_src;
10886         uint16_t port_src;
10887         cmdline_fixed_string_t dst;
10888         cmdline_ipaddr_t ip_dst;
10889         uint16_t port_dst;
10890         cmdline_fixed_string_t verify_tag;
10891         uint32_t verify_tag_value;
10892         cmdline_fixed_string_t tos;
10893         uint8_t tos_value;
10894         cmdline_fixed_string_t proto;
10895         uint8_t proto_value;
10896         cmdline_fixed_string_t ttl;
10897         uint8_t ttl_value;
10898         cmdline_fixed_string_t vlan;
10899         uint16_t vlan_value;
10900         cmdline_fixed_string_t flexbytes;
10901         cmdline_fixed_string_t flexbytes_value;
10902         cmdline_fixed_string_t pf_vf;
10903         cmdline_fixed_string_t drop;
10904         cmdline_fixed_string_t queue;
10905         uint16_t  queue_id;
10906         cmdline_fixed_string_t fd_id;
10907         uint32_t  fd_id_value;
10908         cmdline_fixed_string_t mac;
10909         struct rte_ether_addr mac_addr;
10910         cmdline_fixed_string_t tunnel;
10911         cmdline_fixed_string_t tunnel_type;
10912         cmdline_fixed_string_t tunnel_id;
10913         uint32_t tunnel_id_value;
10914         cmdline_fixed_string_t packet;
10915         char filepath[];
10916 };
10917
10918 static inline int
10919 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10920 {
10921         char s[256];
10922         const char *p, *p0 = q_arg;
10923         char *end;
10924         unsigned long int_fld;
10925         char *str_fld[max_num];
10926         int i;
10927         unsigned size;
10928         int ret = -1;
10929
10930         p = strchr(p0, '(');
10931         if (p == NULL)
10932                 return -1;
10933         ++p;
10934         p0 = strchr(p, ')');
10935         if (p0 == NULL)
10936                 return -1;
10937
10938         size = p0 - p;
10939         if (size >= sizeof(s))
10940                 return -1;
10941
10942         snprintf(s, sizeof(s), "%.*s", size, p);
10943         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10944         if (ret < 0 || ret > max_num)
10945                 return -1;
10946         for (i = 0; i < ret; i++) {
10947                 errno = 0;
10948                 int_fld = strtoul(str_fld[i], &end, 0);
10949                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10950                         return -1;
10951                 flexbytes[i] = (uint8_t)int_fld;
10952         }
10953         return ret;
10954 }
10955
10956 static uint16_t
10957 str2flowtype(char *string)
10958 {
10959         uint8_t i = 0;
10960         static const struct {
10961                 char str[32];
10962                 uint16_t type;
10963         } flowtype_str[] = {
10964                 {"raw", RTE_ETH_FLOW_RAW},
10965                 {"ipv4", RTE_ETH_FLOW_IPV4},
10966                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10967                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10968                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10969                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10970                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10971                 {"ipv6", RTE_ETH_FLOW_IPV6},
10972                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10973                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10974                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10975                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10976                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10977                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10978         };
10979
10980         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10981                 if (!strcmp(flowtype_str[i].str, string))
10982                         return flowtype_str[i].type;
10983         }
10984
10985         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10986                 return (uint16_t)atoi(string);
10987
10988         return RTE_ETH_FLOW_UNKNOWN;
10989 }
10990
10991 static enum rte_eth_fdir_tunnel_type
10992 str2fdir_tunneltype(char *string)
10993 {
10994         uint8_t i = 0;
10995
10996         static const struct {
10997                 char str[32];
10998                 enum rte_eth_fdir_tunnel_type type;
10999         } tunneltype_str[] = {
11000                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11001                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11002         };
11003
11004         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11005                 if (!strcmp(tunneltype_str[i].str, string))
11006                         return tunneltype_str[i].type;
11007         }
11008         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11009 }
11010
11011 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11012 do { \
11013         if ((ip_addr).family == AF_INET) \
11014                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11015         else { \
11016                 printf("invalid parameter.\n"); \
11017                 return; \
11018         } \
11019 } while (0)
11020
11021 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11022 do { \
11023         if ((ip_addr).family == AF_INET6) \
11024                 rte_memcpy(&(ip), \
11025                                  &((ip_addr).addr.ipv6), \
11026                                  sizeof(struct in6_addr)); \
11027         else { \
11028                 printf("invalid parameter.\n"); \
11029                 return; \
11030         } \
11031 } while (0)
11032
11033 static void
11034 cmd_flow_director_filter_parsed(void *parsed_result,
11035                           __rte_unused struct cmdline *cl,
11036                           __rte_unused void *data)
11037 {
11038         struct cmd_flow_director_result *res = parsed_result;
11039         struct rte_eth_fdir_filter entry;
11040         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11041         char *end;
11042         unsigned long vf_id;
11043         int ret = 0;
11044
11045         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11046         if (ret < 0) {
11047                 printf("flow director is not supported on port %u.\n",
11048                         res->port_id);
11049                 return;
11050         }
11051         memset(flexbytes, 0, sizeof(flexbytes));
11052         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11053
11054         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11055                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11056                         printf("Please set mode to MAC-VLAN.\n");
11057                         return;
11058                 }
11059         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11060                 if (strcmp(res->mode_value, "Tunnel")) {
11061                         printf("Please set mode to Tunnel.\n");
11062                         return;
11063                 }
11064         } else {
11065                 if (!strcmp(res->mode_value, "raw")) {
11066 #ifdef RTE_NET_I40E
11067                         struct rte_pmd_i40e_flow_type_mapping
11068                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11069                         struct rte_pmd_i40e_pkt_template_conf conf;
11070                         uint16_t flow_type = str2flowtype(res->flow_type);
11071                         uint16_t i, port = res->port_id;
11072                         uint8_t add;
11073
11074                         memset(&conf, 0, sizeof(conf));
11075
11076                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11077                                 printf("Invalid flow type specified.\n");
11078                                 return;
11079                         }
11080                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11081                                                                  mapping);
11082                         if (ret)
11083                                 return;
11084                         if (mapping[flow_type].pctype == 0ULL) {
11085                                 printf("Invalid flow type specified.\n");
11086                                 return;
11087                         }
11088                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11089                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11090                                         conf.input.pctype = i;
11091                                         break;
11092                                 }
11093                         }
11094
11095                         conf.input.packet = open_file(res->filepath,
11096                                                 &conf.input.length);
11097                         if (!conf.input.packet)
11098                                 return;
11099                         if (!strcmp(res->drop, "drop"))
11100                                 conf.action.behavior =
11101                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11102                         else
11103                                 conf.action.behavior =
11104                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11105                         conf.action.report_status =
11106                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11107                         conf.action.rx_queue = res->queue_id;
11108                         conf.soft_id = res->fd_id_value;
11109                         add  = strcmp(res->ops, "del") ? 1 : 0;
11110                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11111                                                                         &conf,
11112                                                                         add);
11113                         if (ret < 0)
11114                                 printf("flow director config error: (%s)\n",
11115                                        strerror(-ret));
11116                         close_file(conf.input.packet);
11117 #endif
11118                         return;
11119                 } else if (strcmp(res->mode_value, "IP")) {
11120                         printf("Please set mode to IP or raw.\n");
11121                         return;
11122                 }
11123                 entry.input.flow_type = str2flowtype(res->flow_type);
11124         }
11125
11126         ret = parse_flexbytes(res->flexbytes_value,
11127                                         flexbytes,
11128                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11129         if (ret < 0) {
11130                 printf("error: Cannot parse flexbytes input.\n");
11131                 return;
11132         }
11133
11134         switch (entry.input.flow_type) {
11135         case RTE_ETH_FLOW_FRAG_IPV4:
11136         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11137                 entry.input.flow.ip4_flow.proto = res->proto_value;
11138                 /* fall-through */
11139         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11140         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11141                 IPV4_ADDR_TO_UINT(res->ip_dst,
11142                         entry.input.flow.ip4_flow.dst_ip);
11143                 IPV4_ADDR_TO_UINT(res->ip_src,
11144                         entry.input.flow.ip4_flow.src_ip);
11145                 entry.input.flow.ip4_flow.tos = res->tos_value;
11146                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11147                 /* need convert to big endian. */
11148                 entry.input.flow.udp4_flow.dst_port =
11149                                 rte_cpu_to_be_16(res->port_dst);
11150                 entry.input.flow.udp4_flow.src_port =
11151                                 rte_cpu_to_be_16(res->port_src);
11152                 break;
11153         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11154                 IPV4_ADDR_TO_UINT(res->ip_dst,
11155                         entry.input.flow.sctp4_flow.ip.dst_ip);
11156                 IPV4_ADDR_TO_UINT(res->ip_src,
11157                         entry.input.flow.sctp4_flow.ip.src_ip);
11158                 entry.input.flow.ip4_flow.tos = res->tos_value;
11159                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11160                 /* need convert to big endian. */
11161                 entry.input.flow.sctp4_flow.dst_port =
11162                                 rte_cpu_to_be_16(res->port_dst);
11163                 entry.input.flow.sctp4_flow.src_port =
11164                                 rte_cpu_to_be_16(res->port_src);
11165                 entry.input.flow.sctp4_flow.verify_tag =
11166                                 rte_cpu_to_be_32(res->verify_tag_value);
11167                 break;
11168         case RTE_ETH_FLOW_FRAG_IPV6:
11169         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11170                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11171                 /* fall-through */
11172         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11173         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11174                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11175                         entry.input.flow.ipv6_flow.dst_ip);
11176                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11177                         entry.input.flow.ipv6_flow.src_ip);
11178                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11179                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11180                 /* need convert to big endian. */
11181                 entry.input.flow.udp6_flow.dst_port =
11182                                 rte_cpu_to_be_16(res->port_dst);
11183                 entry.input.flow.udp6_flow.src_port =
11184                                 rte_cpu_to_be_16(res->port_src);
11185                 break;
11186         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11187                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11188                         entry.input.flow.sctp6_flow.ip.dst_ip);
11189                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11190                         entry.input.flow.sctp6_flow.ip.src_ip);
11191                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11192                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11193                 /* need convert to big endian. */
11194                 entry.input.flow.sctp6_flow.dst_port =
11195                                 rte_cpu_to_be_16(res->port_dst);
11196                 entry.input.flow.sctp6_flow.src_port =
11197                                 rte_cpu_to_be_16(res->port_src);
11198                 entry.input.flow.sctp6_flow.verify_tag =
11199                                 rte_cpu_to_be_32(res->verify_tag_value);
11200                 break;
11201         case RTE_ETH_FLOW_L2_PAYLOAD:
11202                 entry.input.flow.l2_flow.ether_type =
11203                         rte_cpu_to_be_16(res->ether_type);
11204                 break;
11205         default:
11206                 break;
11207         }
11208
11209         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11210                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11211                                  &res->mac_addr,
11212                                  sizeof(struct rte_ether_addr));
11213
11214         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11215                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11216                                  &res->mac_addr,
11217                                  sizeof(struct rte_ether_addr));
11218                 entry.input.flow.tunnel_flow.tunnel_type =
11219                         str2fdir_tunneltype(res->tunnel_type);
11220                 entry.input.flow.tunnel_flow.tunnel_id =
11221                         rte_cpu_to_be_32(res->tunnel_id_value);
11222         }
11223
11224         rte_memcpy(entry.input.flow_ext.flexbytes,
11225                    flexbytes,
11226                    RTE_ETH_FDIR_MAX_FLEXLEN);
11227
11228         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11229
11230         entry.action.flex_off = 0;  /*use 0 by default */
11231         if (!strcmp(res->drop, "drop"))
11232                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11233         else
11234                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11235
11236         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11237             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11238                 if (!strcmp(res->pf_vf, "pf"))
11239                         entry.input.flow_ext.is_vf = 0;
11240                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11241                         struct rte_eth_dev_info dev_info;
11242
11243                         ret = eth_dev_info_get_print_err(res->port_id,
11244                                                 &dev_info);
11245                         if (ret != 0)
11246                                 return;
11247
11248                         errno = 0;
11249                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11250                         if (errno != 0 || *end != '\0' ||
11251                             vf_id >= dev_info.max_vfs) {
11252                                 printf("invalid parameter %s.\n", res->pf_vf);
11253                                 return;
11254                         }
11255                         entry.input.flow_ext.is_vf = 1;
11256                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11257                 } else {
11258                         printf("invalid parameter %s.\n", res->pf_vf);
11259                         return;
11260                 }
11261         }
11262
11263         /* set to report FD ID by default */
11264         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11265         entry.action.rx_queue = res->queue_id;
11266         entry.soft_id = res->fd_id_value;
11267         if (!strcmp(res->ops, "add"))
11268                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11269                                              RTE_ETH_FILTER_ADD, &entry);
11270         else if (!strcmp(res->ops, "del"))
11271                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11272                                              RTE_ETH_FILTER_DELETE, &entry);
11273         else
11274                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11275                                              RTE_ETH_FILTER_UPDATE, &entry);
11276         if (ret < 0)
11277                 printf("flow director programming error: (%s)\n",
11278                         strerror(-ret));
11279 }
11280
11281 cmdline_parse_token_string_t cmd_flow_director_filter =
11282         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11283                                  flow_director_filter, "flow_director_filter");
11284 cmdline_parse_token_num_t cmd_flow_director_port_id =
11285         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11286                               port_id, UINT16);
11287 cmdline_parse_token_string_t cmd_flow_director_ops =
11288         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11289                                  ops, "add#del#update");
11290 cmdline_parse_token_string_t cmd_flow_director_flow =
11291         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11292                                  flow, "flow");
11293 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11294         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11295                 flow_type, NULL);
11296 cmdline_parse_token_string_t cmd_flow_director_ether =
11297         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11298                                  ether, "ether");
11299 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11300         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11301                               ether_type, UINT16);
11302 cmdline_parse_token_string_t cmd_flow_director_src =
11303         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11304                                  src, "src");
11305 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11306         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11307                                  ip_src);
11308 cmdline_parse_token_num_t cmd_flow_director_port_src =
11309         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11310                               port_src, UINT16);
11311 cmdline_parse_token_string_t cmd_flow_director_dst =
11312         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11313                                  dst, "dst");
11314 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11315         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11316                                  ip_dst);
11317 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11318         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11319                               port_dst, UINT16);
11320 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11321         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11322                                   verify_tag, "verify_tag");
11323 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11324         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11325                               verify_tag_value, UINT32);
11326 cmdline_parse_token_string_t cmd_flow_director_tos =
11327         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11328                                  tos, "tos");
11329 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11330         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11331                               tos_value, UINT8);
11332 cmdline_parse_token_string_t cmd_flow_director_proto =
11333         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11334                                  proto, "proto");
11335 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11336         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11337                               proto_value, UINT8);
11338 cmdline_parse_token_string_t cmd_flow_director_ttl =
11339         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11340                                  ttl, "ttl");
11341 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11342         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11343                               ttl_value, UINT8);
11344 cmdline_parse_token_string_t cmd_flow_director_vlan =
11345         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11346                                  vlan, "vlan");
11347 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11348         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11349                               vlan_value, UINT16);
11350 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11351         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11352                                  flexbytes, "flexbytes");
11353 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11354         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11355                               flexbytes_value, NULL);
11356 cmdline_parse_token_string_t cmd_flow_director_drop =
11357         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11358                                  drop, "drop#fwd");
11359 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11360         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11361                               pf_vf, NULL);
11362 cmdline_parse_token_string_t cmd_flow_director_queue =
11363         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11364                                  queue, "queue");
11365 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11366         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11367                               queue_id, UINT16);
11368 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11369         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11370                                  fd_id, "fd_id");
11371 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11372         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11373                               fd_id_value, UINT32);
11374
11375 cmdline_parse_token_string_t cmd_flow_director_mode =
11376         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11377                                  mode, "mode");
11378 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11379         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11380                                  mode_value, "IP");
11381 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11382         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11383                                  mode_value, "MAC-VLAN");
11384 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11385         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11386                                  mode_value, "Tunnel");
11387 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11388         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11389                                  mode_value, "raw");
11390 cmdline_parse_token_string_t cmd_flow_director_mac =
11391         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11392                                  mac, "mac");
11393 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11394         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11395                                     mac_addr);
11396 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11397         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11398                                  tunnel, "tunnel");
11399 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11400         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11401                                  tunnel_type, "NVGRE#VxLAN");
11402 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11403         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11404                                  tunnel_id, "tunnel-id");
11405 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11406         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11407                               tunnel_id_value, UINT32);
11408 cmdline_parse_token_string_t cmd_flow_director_packet =
11409         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11410                                  packet, "packet");
11411 cmdline_parse_token_string_t cmd_flow_director_filepath =
11412         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11413                                  filepath, NULL);
11414
11415 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11416         .f = cmd_flow_director_filter_parsed,
11417         .data = NULL,
11418         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11419                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11420                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11421                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11422                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11423                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11424                 "fd_id <fd_id_value>: "
11425                 "Add or delete an ip flow director entry on NIC",
11426         .tokens = {
11427                 (void *)&cmd_flow_director_filter,
11428                 (void *)&cmd_flow_director_port_id,
11429                 (void *)&cmd_flow_director_mode,
11430                 (void *)&cmd_flow_director_mode_ip,
11431                 (void *)&cmd_flow_director_ops,
11432                 (void *)&cmd_flow_director_flow,
11433                 (void *)&cmd_flow_director_flow_type,
11434                 (void *)&cmd_flow_director_src,
11435                 (void *)&cmd_flow_director_ip_src,
11436                 (void *)&cmd_flow_director_dst,
11437                 (void *)&cmd_flow_director_ip_dst,
11438                 (void *)&cmd_flow_director_tos,
11439                 (void *)&cmd_flow_director_tos_value,
11440                 (void *)&cmd_flow_director_proto,
11441                 (void *)&cmd_flow_director_proto_value,
11442                 (void *)&cmd_flow_director_ttl,
11443                 (void *)&cmd_flow_director_ttl_value,
11444                 (void *)&cmd_flow_director_vlan,
11445                 (void *)&cmd_flow_director_vlan_value,
11446                 (void *)&cmd_flow_director_flexbytes,
11447                 (void *)&cmd_flow_director_flexbytes_value,
11448                 (void *)&cmd_flow_director_drop,
11449                 (void *)&cmd_flow_director_pf_vf,
11450                 (void *)&cmd_flow_director_queue,
11451                 (void *)&cmd_flow_director_queue_id,
11452                 (void *)&cmd_flow_director_fd_id,
11453                 (void *)&cmd_flow_director_fd_id_value,
11454                 NULL,
11455         },
11456 };
11457
11458 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11459         .f = cmd_flow_director_filter_parsed,
11460         .data = NULL,
11461         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11462                 "director entry on NIC",
11463         .tokens = {
11464                 (void *)&cmd_flow_director_filter,
11465                 (void *)&cmd_flow_director_port_id,
11466                 (void *)&cmd_flow_director_mode,
11467                 (void *)&cmd_flow_director_mode_ip,
11468                 (void *)&cmd_flow_director_ops,
11469                 (void *)&cmd_flow_director_flow,
11470                 (void *)&cmd_flow_director_flow_type,
11471                 (void *)&cmd_flow_director_src,
11472                 (void *)&cmd_flow_director_ip_src,
11473                 (void *)&cmd_flow_director_port_src,
11474                 (void *)&cmd_flow_director_dst,
11475                 (void *)&cmd_flow_director_ip_dst,
11476                 (void *)&cmd_flow_director_port_dst,
11477                 (void *)&cmd_flow_director_tos,
11478                 (void *)&cmd_flow_director_tos_value,
11479                 (void *)&cmd_flow_director_ttl,
11480                 (void *)&cmd_flow_director_ttl_value,
11481                 (void *)&cmd_flow_director_vlan,
11482                 (void *)&cmd_flow_director_vlan_value,
11483                 (void *)&cmd_flow_director_flexbytes,
11484                 (void *)&cmd_flow_director_flexbytes_value,
11485                 (void *)&cmd_flow_director_drop,
11486                 (void *)&cmd_flow_director_pf_vf,
11487                 (void *)&cmd_flow_director_queue,
11488                 (void *)&cmd_flow_director_queue_id,
11489                 (void *)&cmd_flow_director_fd_id,
11490                 (void *)&cmd_flow_director_fd_id_value,
11491                 NULL,
11492         },
11493 };
11494
11495 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11496         .f = cmd_flow_director_filter_parsed,
11497         .data = NULL,
11498         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11499                 "director entry on NIC",
11500         .tokens = {
11501                 (void *)&cmd_flow_director_filter,
11502                 (void *)&cmd_flow_director_port_id,
11503                 (void *)&cmd_flow_director_mode,
11504                 (void *)&cmd_flow_director_mode_ip,
11505                 (void *)&cmd_flow_director_ops,
11506                 (void *)&cmd_flow_director_flow,
11507                 (void *)&cmd_flow_director_flow_type,
11508                 (void *)&cmd_flow_director_src,
11509                 (void *)&cmd_flow_director_ip_src,
11510                 (void *)&cmd_flow_director_port_src,
11511                 (void *)&cmd_flow_director_dst,
11512                 (void *)&cmd_flow_director_ip_dst,
11513                 (void *)&cmd_flow_director_port_dst,
11514                 (void *)&cmd_flow_director_verify_tag,
11515                 (void *)&cmd_flow_director_verify_tag_value,
11516                 (void *)&cmd_flow_director_tos,
11517                 (void *)&cmd_flow_director_tos_value,
11518                 (void *)&cmd_flow_director_ttl,
11519                 (void *)&cmd_flow_director_ttl_value,
11520                 (void *)&cmd_flow_director_vlan,
11521                 (void *)&cmd_flow_director_vlan_value,
11522                 (void *)&cmd_flow_director_flexbytes,
11523                 (void *)&cmd_flow_director_flexbytes_value,
11524                 (void *)&cmd_flow_director_drop,
11525                 (void *)&cmd_flow_director_pf_vf,
11526                 (void *)&cmd_flow_director_queue,
11527                 (void *)&cmd_flow_director_queue_id,
11528                 (void *)&cmd_flow_director_fd_id,
11529                 (void *)&cmd_flow_director_fd_id_value,
11530                 NULL,
11531         },
11532 };
11533
11534 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11535         .f = cmd_flow_director_filter_parsed,
11536         .data = NULL,
11537         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11538                 "director entry on NIC",
11539         .tokens = {
11540                 (void *)&cmd_flow_director_filter,
11541                 (void *)&cmd_flow_director_port_id,
11542                 (void *)&cmd_flow_director_mode,
11543                 (void *)&cmd_flow_director_mode_ip,
11544                 (void *)&cmd_flow_director_ops,
11545                 (void *)&cmd_flow_director_flow,
11546                 (void *)&cmd_flow_director_flow_type,
11547                 (void *)&cmd_flow_director_ether,
11548                 (void *)&cmd_flow_director_ether_type,
11549                 (void *)&cmd_flow_director_flexbytes,
11550                 (void *)&cmd_flow_director_flexbytes_value,
11551                 (void *)&cmd_flow_director_drop,
11552                 (void *)&cmd_flow_director_pf_vf,
11553                 (void *)&cmd_flow_director_queue,
11554                 (void *)&cmd_flow_director_queue_id,
11555                 (void *)&cmd_flow_director_fd_id,
11556                 (void *)&cmd_flow_director_fd_id_value,
11557                 NULL,
11558         },
11559 };
11560
11561 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11562         .f = cmd_flow_director_filter_parsed,
11563         .data = NULL,
11564         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11565                 "director entry on NIC",
11566         .tokens = {
11567                 (void *)&cmd_flow_director_filter,
11568                 (void *)&cmd_flow_director_port_id,
11569                 (void *)&cmd_flow_director_mode,
11570                 (void *)&cmd_flow_director_mode_mac_vlan,
11571                 (void *)&cmd_flow_director_ops,
11572                 (void *)&cmd_flow_director_mac,
11573                 (void *)&cmd_flow_director_mac_addr,
11574                 (void *)&cmd_flow_director_vlan,
11575                 (void *)&cmd_flow_director_vlan_value,
11576                 (void *)&cmd_flow_director_flexbytes,
11577                 (void *)&cmd_flow_director_flexbytes_value,
11578                 (void *)&cmd_flow_director_drop,
11579                 (void *)&cmd_flow_director_queue,
11580                 (void *)&cmd_flow_director_queue_id,
11581                 (void *)&cmd_flow_director_fd_id,
11582                 (void *)&cmd_flow_director_fd_id_value,
11583                 NULL,
11584         },
11585 };
11586
11587 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11588         .f = cmd_flow_director_filter_parsed,
11589         .data = NULL,
11590         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11591                 "director entry on NIC",
11592         .tokens = {
11593                 (void *)&cmd_flow_director_filter,
11594                 (void *)&cmd_flow_director_port_id,
11595                 (void *)&cmd_flow_director_mode,
11596                 (void *)&cmd_flow_director_mode_tunnel,
11597                 (void *)&cmd_flow_director_ops,
11598                 (void *)&cmd_flow_director_mac,
11599                 (void *)&cmd_flow_director_mac_addr,
11600                 (void *)&cmd_flow_director_vlan,
11601                 (void *)&cmd_flow_director_vlan_value,
11602                 (void *)&cmd_flow_director_tunnel,
11603                 (void *)&cmd_flow_director_tunnel_type,
11604                 (void *)&cmd_flow_director_tunnel_id,
11605                 (void *)&cmd_flow_director_tunnel_id_value,
11606                 (void *)&cmd_flow_director_flexbytes,
11607                 (void *)&cmd_flow_director_flexbytes_value,
11608                 (void *)&cmd_flow_director_drop,
11609                 (void *)&cmd_flow_director_queue,
11610                 (void *)&cmd_flow_director_queue_id,
11611                 (void *)&cmd_flow_director_fd_id,
11612                 (void *)&cmd_flow_director_fd_id_value,
11613                 NULL,
11614         },
11615 };
11616
11617 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11618         .f = cmd_flow_director_filter_parsed,
11619         .data = NULL,
11620         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11621                 "director entry on NIC",
11622         .tokens = {
11623                 (void *)&cmd_flow_director_filter,
11624                 (void *)&cmd_flow_director_port_id,
11625                 (void *)&cmd_flow_director_mode,
11626                 (void *)&cmd_flow_director_mode_raw,
11627                 (void *)&cmd_flow_director_ops,
11628                 (void *)&cmd_flow_director_flow,
11629                 (void *)&cmd_flow_director_flow_type,
11630                 (void *)&cmd_flow_director_drop,
11631                 (void *)&cmd_flow_director_queue,
11632                 (void *)&cmd_flow_director_queue_id,
11633                 (void *)&cmd_flow_director_fd_id,
11634                 (void *)&cmd_flow_director_fd_id_value,
11635                 (void *)&cmd_flow_director_packet,
11636                 (void *)&cmd_flow_director_filepath,
11637                 NULL,
11638         },
11639 };
11640
11641 struct cmd_flush_flow_director_result {
11642         cmdline_fixed_string_t flush_flow_director;
11643         portid_t port_id;
11644 };
11645
11646 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11647         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11648                                  flush_flow_director, "flush_flow_director");
11649 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11650         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11651                               port_id, UINT16);
11652
11653 static void
11654 cmd_flush_flow_director_parsed(void *parsed_result,
11655                           __rte_unused struct cmdline *cl,
11656                           __rte_unused void *data)
11657 {
11658         struct cmd_flow_director_result *res = parsed_result;
11659         int ret = 0;
11660
11661         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11662         if (ret < 0) {
11663                 printf("flow director is not supported on port %u.\n",
11664                         res->port_id);
11665                 return;
11666         }
11667
11668         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11669                         RTE_ETH_FILTER_FLUSH, NULL);
11670         if (ret < 0)
11671                 printf("flow director table flushing error: (%s)\n",
11672                         strerror(-ret));
11673 }
11674
11675 cmdline_parse_inst_t cmd_flush_flow_director = {
11676         .f = cmd_flush_flow_director_parsed,
11677         .data = NULL,
11678         .help_str = "flush_flow_director <port_id>: "
11679                 "Flush all flow director entries of a device on NIC",
11680         .tokens = {
11681                 (void *)&cmd_flush_flow_director_flush,
11682                 (void *)&cmd_flush_flow_director_port_id,
11683                 NULL,
11684         },
11685 };
11686
11687 /* *** deal with flow director mask *** */
11688 struct cmd_flow_director_mask_result {
11689         cmdline_fixed_string_t flow_director_mask;
11690         portid_t port_id;
11691         cmdline_fixed_string_t mode;
11692         cmdline_fixed_string_t mode_value;
11693         cmdline_fixed_string_t vlan;
11694         uint16_t vlan_mask;
11695         cmdline_fixed_string_t src_mask;
11696         cmdline_ipaddr_t ipv4_src;
11697         cmdline_ipaddr_t ipv6_src;
11698         uint16_t port_src;
11699         cmdline_fixed_string_t dst_mask;
11700         cmdline_ipaddr_t ipv4_dst;
11701         cmdline_ipaddr_t ipv6_dst;
11702         uint16_t port_dst;
11703         cmdline_fixed_string_t mac;
11704         uint8_t mac_addr_byte_mask;
11705         cmdline_fixed_string_t tunnel_id;
11706         uint32_t tunnel_id_mask;
11707         cmdline_fixed_string_t tunnel_type;
11708         uint8_t tunnel_type_mask;
11709 };
11710
11711 static void
11712 cmd_flow_director_mask_parsed(void *parsed_result,
11713                           __rte_unused struct cmdline *cl,
11714                           __rte_unused void *data)
11715 {
11716         struct cmd_flow_director_mask_result *res = parsed_result;
11717         struct rte_eth_fdir_masks *mask;
11718         struct rte_port *port;
11719
11720         port = &ports[res->port_id];
11721         /** Check if the port is not started **/
11722         if (port->port_status != RTE_PORT_STOPPED) {
11723                 printf("Please stop port %d first\n", res->port_id);
11724                 return;
11725         }
11726
11727         mask = &port->dev_conf.fdir_conf.mask;
11728
11729         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11730                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11731                         printf("Please set mode to MAC-VLAN.\n");
11732                         return;
11733                 }
11734
11735                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11736         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11737                 if (strcmp(res->mode_value, "Tunnel")) {
11738                         printf("Please set mode to Tunnel.\n");
11739                         return;
11740                 }
11741
11742                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11743                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11744                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11745                 mask->tunnel_type_mask = res->tunnel_type_mask;
11746         } else {
11747                 if (strcmp(res->mode_value, "IP")) {
11748                         printf("Please set mode to IP.\n");
11749                         return;
11750                 }
11751
11752                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11753                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11754                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11755                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11756                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11757                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11758                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11759         }
11760
11761         cmd_reconfig_device_queue(res->port_id, 1, 1);
11762 }
11763
11764 cmdline_parse_token_string_t cmd_flow_director_mask =
11765         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11766                                  flow_director_mask, "flow_director_mask");
11767 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11768         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11769                               port_id, UINT16);
11770 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11771         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11772                                  vlan, "vlan");
11773 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11774         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11775                               vlan_mask, UINT16);
11776 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11777         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11778                                  src_mask, "src_mask");
11779 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11780         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11781                                  ipv4_src);
11782 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11783         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11784                                  ipv6_src);
11785 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11786         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11787                               port_src, UINT16);
11788 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11789         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11790                                  dst_mask, "dst_mask");
11791 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11792         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11793                                  ipv4_dst);
11794 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11795         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11796                                  ipv6_dst);
11797 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11798         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11799                               port_dst, UINT16);
11800
11801 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11802         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11803                                  mode, "mode");
11804 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11805         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11806                                  mode_value, "IP");
11807 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11808         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11809                                  mode_value, "MAC-VLAN");
11810 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11811         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11812                                  mode_value, "Tunnel");
11813 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11814         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11815                                  mac, "mac");
11816 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11817         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11818                               mac_addr_byte_mask, UINT8);
11819 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11820         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11821                                  tunnel_type, "tunnel-type");
11822 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11823         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11824                               tunnel_type_mask, UINT8);
11825 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11826         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11827                                  tunnel_id, "tunnel-id");
11828 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11829         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11830                               tunnel_id_mask, UINT32);
11831
11832 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11833         .f = cmd_flow_director_mask_parsed,
11834         .data = NULL,
11835         .help_str = "flow_director_mask ... : "
11836                 "Set IP mode flow director's mask on NIC",
11837         .tokens = {
11838                 (void *)&cmd_flow_director_mask,
11839                 (void *)&cmd_flow_director_mask_port_id,
11840                 (void *)&cmd_flow_director_mask_mode,
11841                 (void *)&cmd_flow_director_mask_mode_ip,
11842                 (void *)&cmd_flow_director_mask_vlan,
11843                 (void *)&cmd_flow_director_mask_vlan_value,
11844                 (void *)&cmd_flow_director_mask_src,
11845                 (void *)&cmd_flow_director_mask_ipv4_src,
11846                 (void *)&cmd_flow_director_mask_ipv6_src,
11847                 (void *)&cmd_flow_director_mask_port_src,
11848                 (void *)&cmd_flow_director_mask_dst,
11849                 (void *)&cmd_flow_director_mask_ipv4_dst,
11850                 (void *)&cmd_flow_director_mask_ipv6_dst,
11851                 (void *)&cmd_flow_director_mask_port_dst,
11852                 NULL,
11853         },
11854 };
11855
11856 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11857         .f = cmd_flow_director_mask_parsed,
11858         .data = NULL,
11859         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11860                 "flow director's mask on NIC",
11861         .tokens = {
11862                 (void *)&cmd_flow_director_mask,
11863                 (void *)&cmd_flow_director_mask_port_id,
11864                 (void *)&cmd_flow_director_mask_mode,
11865                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11866                 (void *)&cmd_flow_director_mask_vlan,
11867                 (void *)&cmd_flow_director_mask_vlan_value,
11868                 NULL,
11869         },
11870 };
11871
11872 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11873         .f = cmd_flow_director_mask_parsed,
11874         .data = NULL,
11875         .help_str = "flow_director_mask ... : Set tunnel mode "
11876                 "flow director's mask on NIC",
11877         .tokens = {
11878                 (void *)&cmd_flow_director_mask,
11879                 (void *)&cmd_flow_director_mask_port_id,
11880                 (void *)&cmd_flow_director_mask_mode,
11881                 (void *)&cmd_flow_director_mask_mode_tunnel,
11882                 (void *)&cmd_flow_director_mask_vlan,
11883                 (void *)&cmd_flow_director_mask_vlan_value,
11884                 (void *)&cmd_flow_director_mask_mac,
11885                 (void *)&cmd_flow_director_mask_mac_value,
11886                 (void *)&cmd_flow_director_mask_tunnel_type,
11887                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11888                 (void *)&cmd_flow_director_mask_tunnel_id,
11889                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11890                 NULL,
11891         },
11892 };
11893
11894 /* *** deal with flow director mask on flexible payload *** */
11895 struct cmd_flow_director_flex_mask_result {
11896         cmdline_fixed_string_t flow_director_flexmask;
11897         portid_t port_id;
11898         cmdline_fixed_string_t flow;
11899         cmdline_fixed_string_t flow_type;
11900         cmdline_fixed_string_t mask;
11901 };
11902
11903 static void
11904 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11905                           __rte_unused struct cmdline *cl,
11906                           __rte_unused void *data)
11907 {
11908         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11909         struct rte_eth_fdir_info fdir_info;
11910         struct rte_eth_fdir_flex_mask flex_mask;
11911         struct rte_port *port;
11912         uint64_t flow_type_mask;
11913         uint16_t i;
11914         int ret;
11915
11916         port = &ports[res->port_id];
11917         /** Check if the port is not started **/
11918         if (port->port_status != RTE_PORT_STOPPED) {
11919                 printf("Please stop port %d first\n", res->port_id);
11920                 return;
11921         }
11922
11923         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11924         ret = parse_flexbytes(res->mask,
11925                         flex_mask.mask,
11926                         RTE_ETH_FDIR_MAX_FLEXLEN);
11927         if (ret < 0) {
11928                 printf("error: Cannot parse mask input.\n");
11929                 return;
11930         }
11931
11932         memset(&fdir_info, 0, sizeof(fdir_info));
11933         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11934                                 RTE_ETH_FILTER_INFO, &fdir_info);
11935         if (ret < 0) {
11936                 printf("Cannot get FDir filter info\n");
11937                 return;
11938         }
11939
11940         if (!strcmp(res->flow_type, "none")) {
11941                 /* means don't specify the flow type */
11942                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11943                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11944                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11945                                0, sizeof(struct rte_eth_fdir_flex_mask));
11946                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11947                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11948                                  &flex_mask,
11949                                  sizeof(struct rte_eth_fdir_flex_mask));
11950                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11951                 return;
11952         }
11953         flow_type_mask = fdir_info.flow_types_mask[0];
11954         if (!strcmp(res->flow_type, "all")) {
11955                 if (!flow_type_mask) {
11956                         printf("No flow type supported\n");
11957                         return;
11958                 }
11959                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11960                         if (flow_type_mask & (1ULL << i)) {
11961                                 flex_mask.flow_type = i;
11962                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11963                         }
11964                 }
11965                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11966                 return;
11967         }
11968         flex_mask.flow_type = str2flowtype(res->flow_type);
11969         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11970                 printf("Flow type %s not supported on port %d\n",
11971                                 res->flow_type, res->port_id);
11972                 return;
11973         }
11974         fdir_set_flex_mask(res->port_id, &flex_mask);
11975         cmd_reconfig_device_queue(res->port_id, 1, 1);
11976 }
11977
11978 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11979         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11980                                  flow_director_flexmask,
11981                                  "flow_director_flex_mask");
11982 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11983         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11984                               port_id, UINT16);
11985 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11986         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11987                                  flow, "flow");
11988 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11989         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11990                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11991                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11992 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11993         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11994                                  mask, NULL);
11995
11996 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11997         .f = cmd_flow_director_flex_mask_parsed,
11998         .data = NULL,
11999         .help_str = "flow_director_flex_mask ... : "
12000                 "Set flow director's flex mask on NIC",
12001         .tokens = {
12002                 (void *)&cmd_flow_director_flexmask,
12003                 (void *)&cmd_flow_director_flexmask_port_id,
12004                 (void *)&cmd_flow_director_flexmask_flow,
12005                 (void *)&cmd_flow_director_flexmask_flow_type,
12006                 (void *)&cmd_flow_director_flexmask_mask,
12007                 NULL,
12008         },
12009 };
12010
12011 /* *** deal with flow director flexible payload configuration *** */
12012 struct cmd_flow_director_flexpayload_result {
12013         cmdline_fixed_string_t flow_director_flexpayload;
12014         portid_t port_id;
12015         cmdline_fixed_string_t payload_layer;
12016         cmdline_fixed_string_t payload_cfg;
12017 };
12018
12019 static inline int
12020 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12021 {
12022         char s[256];
12023         const char *p, *p0 = q_arg;
12024         char *end;
12025         unsigned long int_fld;
12026         char *str_fld[max_num];
12027         int i;
12028         unsigned size;
12029         int ret = -1;
12030
12031         p = strchr(p0, '(');
12032         if (p == NULL)
12033                 return -1;
12034         ++p;
12035         p0 = strchr(p, ')');
12036         if (p0 == NULL)
12037                 return -1;
12038
12039         size = p0 - p;
12040         if (size >= sizeof(s))
12041                 return -1;
12042
12043         snprintf(s, sizeof(s), "%.*s", size, p);
12044         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12045         if (ret < 0 || ret > max_num)
12046                 return -1;
12047         for (i = 0; i < ret; i++) {
12048                 errno = 0;
12049                 int_fld = strtoul(str_fld[i], &end, 0);
12050                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12051                         return -1;
12052                 offsets[i] = (uint16_t)int_fld;
12053         }
12054         return ret;
12055 }
12056
12057 static void
12058 cmd_flow_director_flxpld_parsed(void *parsed_result,
12059                           __rte_unused struct cmdline *cl,
12060                           __rte_unused void *data)
12061 {
12062         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12063         struct rte_eth_flex_payload_cfg flex_cfg;
12064         struct rte_port *port;
12065         int ret = 0;
12066
12067         port = &ports[res->port_id];
12068         /** Check if the port is not started **/
12069         if (port->port_status != RTE_PORT_STOPPED) {
12070                 printf("Please stop port %d first\n", res->port_id);
12071                 return;
12072         }
12073
12074         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12075
12076         if (!strcmp(res->payload_layer, "raw"))
12077                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12078         else if (!strcmp(res->payload_layer, "l2"))
12079                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12080         else if (!strcmp(res->payload_layer, "l3"))
12081                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12082         else if (!strcmp(res->payload_layer, "l4"))
12083                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12084
12085         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12086                             RTE_ETH_FDIR_MAX_FLEXLEN);
12087         if (ret < 0) {
12088                 printf("error: Cannot parse flex payload input.\n");
12089                 return;
12090         }
12091
12092         fdir_set_flex_payload(res->port_id, &flex_cfg);
12093         cmd_reconfig_device_queue(res->port_id, 1, 1);
12094 }
12095
12096 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12097         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12098                                  flow_director_flexpayload,
12099                                  "flow_director_flex_payload");
12100 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12101         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12102                               port_id, UINT16);
12103 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12104         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12105                                  payload_layer, "raw#l2#l3#l4");
12106 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12107         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12108                                  payload_cfg, NULL);
12109
12110 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12111         .f = cmd_flow_director_flxpld_parsed,
12112         .data = NULL,
12113         .help_str = "flow_director_flexpayload ... : "
12114                 "Set flow director's flex payload on NIC",
12115         .tokens = {
12116                 (void *)&cmd_flow_director_flexpayload,
12117                 (void *)&cmd_flow_director_flexpayload_port_id,
12118                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12119                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12120                 NULL,
12121         },
12122 };
12123
12124 /* Generic flow interface command. */
12125 extern cmdline_parse_inst_t cmd_flow;
12126
12127 /* *** Classification Filters Control *** */
12128 /* *** Get symmetric hash enable per port *** */
12129 struct cmd_get_sym_hash_ena_per_port_result {
12130         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12131         portid_t port_id;
12132 };
12133
12134 static void
12135 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12136                                  __rte_unused struct cmdline *cl,
12137                                  __rte_unused void *data)
12138 {
12139         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12140         struct rte_eth_hash_filter_info info;
12141         int ret;
12142
12143         if (rte_eth_dev_filter_supported(res->port_id,
12144                                 RTE_ETH_FILTER_HASH) < 0) {
12145                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12146                                                         res->port_id);
12147                 return;
12148         }
12149
12150         memset(&info, 0, sizeof(info));
12151         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12152         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12153                                                 RTE_ETH_FILTER_GET, &info);
12154
12155         if (ret < 0) {
12156                 printf("Cannot get symmetric hash enable per port "
12157                                         "on port %u\n", res->port_id);
12158                 return;
12159         }
12160
12161         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12162                                 "enabled" : "disabled", res->port_id);
12163 }
12164
12165 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12166         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12167                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12168 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12169         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12170                 port_id, UINT16);
12171
12172 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12173         .f = cmd_get_sym_hash_per_port_parsed,
12174         .data = NULL,
12175         .help_str = "get_sym_hash_ena_per_port <port_id>",
12176         .tokens = {
12177                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12178                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12179                 NULL,
12180         },
12181 };
12182
12183 /* *** Set symmetric hash enable per port *** */
12184 struct cmd_set_sym_hash_ena_per_port_result {
12185         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12186         cmdline_fixed_string_t enable;
12187         portid_t port_id;
12188 };
12189
12190 static void
12191 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12192                                  __rte_unused struct cmdline *cl,
12193                                  __rte_unused void *data)
12194 {
12195         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12196         struct rte_eth_hash_filter_info info;
12197         int ret;
12198
12199         if (rte_eth_dev_filter_supported(res->port_id,
12200                                 RTE_ETH_FILTER_HASH) < 0) {
12201                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12202                                                         res->port_id);
12203                 return;
12204         }
12205
12206         memset(&info, 0, sizeof(info));
12207         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12208         if (!strcmp(res->enable, "enable"))
12209                 info.info.enable = 1;
12210         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12211                                         RTE_ETH_FILTER_SET, &info);
12212         if (ret < 0) {
12213                 printf("Cannot set symmetric hash enable per port on "
12214                                         "port %u\n", res->port_id);
12215                 return;
12216         }
12217         printf("Symmetric hash has been set to %s on port %u\n",
12218                                         res->enable, res->port_id);
12219 }
12220
12221 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12222         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12223                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12224 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12225         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12226                 port_id, UINT16);
12227 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12228         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12229                 enable, "enable#disable");
12230
12231 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12232         .f = cmd_set_sym_hash_per_port_parsed,
12233         .data = NULL,
12234         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12235         .tokens = {
12236                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12237                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12238                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12239                 NULL,
12240         },
12241 };
12242
12243 /* Get global config of hash function */
12244 struct cmd_get_hash_global_config_result {
12245         cmdline_fixed_string_t get_hash_global_config;
12246         portid_t port_id;
12247 };
12248
12249 static char *
12250 flowtype_to_str(uint16_t ftype)
12251 {
12252         uint16_t i;
12253         static struct {
12254                 char str[16];
12255                 uint16_t ftype;
12256         } ftype_table[] = {
12257                 {"ipv4", RTE_ETH_FLOW_IPV4},
12258                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12259                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12260                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12261                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12262                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12263                 {"ipv6", RTE_ETH_FLOW_IPV6},
12264                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12265                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12266                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12267                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12268                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12269                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12270                 {"port", RTE_ETH_FLOW_PORT},
12271                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12272                 {"geneve", RTE_ETH_FLOW_GENEVE},
12273                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12274                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12275         };
12276
12277         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12278                 if (ftype_table[i].ftype == ftype)
12279                         return ftype_table[i].str;
12280         }
12281
12282         return NULL;
12283 }
12284
12285 static void
12286 cmd_get_hash_global_config_parsed(void *parsed_result,
12287                                   __rte_unused struct cmdline *cl,
12288                                   __rte_unused void *data)
12289 {
12290         struct cmd_get_hash_global_config_result *res = parsed_result;
12291         struct rte_eth_hash_filter_info info;
12292         uint32_t idx, offset;
12293         uint16_t i;
12294         char *str;
12295         int ret;
12296
12297         if (rte_eth_dev_filter_supported(res->port_id,
12298                         RTE_ETH_FILTER_HASH) < 0) {
12299                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12300                                                         res->port_id);
12301                 return;
12302         }
12303
12304         memset(&info, 0, sizeof(info));
12305         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12306         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12307                                         RTE_ETH_FILTER_GET, &info);
12308         if (ret < 0) {
12309                 printf("Cannot get hash global configurations by port %d\n",
12310                                                         res->port_id);
12311                 return;
12312         }
12313
12314         switch (info.info.global_conf.hash_func) {
12315         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12316                 printf("Hash function is Toeplitz\n");
12317                 break;
12318         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12319                 printf("Hash function is Simple XOR\n");
12320                 break;
12321         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12322                 printf("Hash function is Symmetric Toeplitz\n");
12323                 break;
12324         default:
12325                 printf("Unknown hash function\n");
12326                 break;
12327         }
12328
12329         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12330                 idx = i / UINT64_BIT;
12331                 offset = i % UINT64_BIT;
12332                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12333                                                 (1ULL << offset)))
12334                         continue;
12335                 str = flowtype_to_str(i);
12336                 if (!str)
12337                         continue;
12338                 printf("Symmetric hash is %s globally for flow type %s "
12339                                                         "by port %d\n",
12340                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12341                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12342                                                         res->port_id);
12343         }
12344 }
12345
12346 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12347         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12348                 get_hash_global_config, "get_hash_global_config");
12349 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12350         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12351                 port_id, UINT16);
12352
12353 cmdline_parse_inst_t cmd_get_hash_global_config = {
12354         .f = cmd_get_hash_global_config_parsed,
12355         .data = NULL,
12356         .help_str = "get_hash_global_config <port_id>",
12357         .tokens = {
12358                 (void *)&cmd_get_hash_global_config_all,
12359                 (void *)&cmd_get_hash_global_config_port_id,
12360                 NULL,
12361         },
12362 };
12363
12364 /* Set global config of hash function */
12365 struct cmd_set_hash_global_config_result {
12366         cmdline_fixed_string_t set_hash_global_config;
12367         portid_t port_id;
12368         cmdline_fixed_string_t hash_func;
12369         cmdline_fixed_string_t flow_type;
12370         cmdline_fixed_string_t enable;
12371 };
12372
12373 static void
12374 cmd_set_hash_global_config_parsed(void *parsed_result,
12375                                   __rte_unused struct cmdline *cl,
12376                                   __rte_unused void *data)
12377 {
12378         struct cmd_set_hash_global_config_result *res = parsed_result;
12379         struct rte_eth_hash_filter_info info;
12380         uint32_t ftype, idx, offset;
12381         int ret;
12382
12383         if (rte_eth_dev_filter_supported(res->port_id,
12384                                 RTE_ETH_FILTER_HASH) < 0) {
12385                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12386                                                         res->port_id);
12387                 return;
12388         }
12389         memset(&info, 0, sizeof(info));
12390         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12391         if (!strcmp(res->hash_func, "toeplitz"))
12392                 info.info.global_conf.hash_func =
12393                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12394         else if (!strcmp(res->hash_func, "simple_xor"))
12395                 info.info.global_conf.hash_func =
12396                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12397         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12398                 info.info.global_conf.hash_func =
12399                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12400         else if (!strcmp(res->hash_func, "default"))
12401                 info.info.global_conf.hash_func =
12402                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12403
12404         ftype = str2flowtype(res->flow_type);
12405         idx = ftype / UINT64_BIT;
12406         offset = ftype % UINT64_BIT;
12407         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12408         if (!strcmp(res->enable, "enable"))
12409                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12410                                                 (1ULL << offset);
12411         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12412                                         RTE_ETH_FILTER_SET, &info);
12413         if (ret < 0)
12414                 printf("Cannot set global hash configurations by port %d\n",
12415                                                         res->port_id);
12416         else
12417                 printf("Global hash configurations have been set "
12418                         "successfully by port %d\n", res->port_id);
12419 }
12420
12421 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12422         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12423                 set_hash_global_config, "set_hash_global_config");
12424 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12425         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12426                 port_id, UINT16);
12427 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12428         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12429                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12430 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12431         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12432                 flow_type,
12433                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12434                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12435 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12436         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12437                 enable, "enable#disable");
12438
12439 cmdline_parse_inst_t cmd_set_hash_global_config = {
12440         .f = cmd_set_hash_global_config_parsed,
12441         .data = NULL,
12442         .help_str = "set_hash_global_config <port_id> "
12443                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12444                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12445                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12446                 "l2_payload enable|disable",
12447         .tokens = {
12448                 (void *)&cmd_set_hash_global_config_all,
12449                 (void *)&cmd_set_hash_global_config_port_id,
12450                 (void *)&cmd_set_hash_global_config_hash_func,
12451                 (void *)&cmd_set_hash_global_config_flow_type,
12452                 (void *)&cmd_set_hash_global_config_enable,
12453                 NULL,
12454         },
12455 };
12456
12457 /* Set hash input set */
12458 struct cmd_set_hash_input_set_result {
12459         cmdline_fixed_string_t set_hash_input_set;
12460         portid_t port_id;
12461         cmdline_fixed_string_t flow_type;
12462         cmdline_fixed_string_t inset_field;
12463         cmdline_fixed_string_t select;
12464 };
12465
12466 static enum rte_eth_input_set_field
12467 str2inset(char *string)
12468 {
12469         uint16_t i;
12470
12471         static const struct {
12472                 char str[32];
12473                 enum rte_eth_input_set_field inset;
12474         } inset_table[] = {
12475                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12476                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12477                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12478                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12479                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12480                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12481                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12482                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12483                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12484                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12485                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12486                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12487                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12488                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12489                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12490                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12491                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12492                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12493                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12494                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12495                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12496                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12497                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12498                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12499                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12500                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12501                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12502                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12503                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12504                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12505                 {"none", RTE_ETH_INPUT_SET_NONE},
12506         };
12507
12508         for (i = 0; i < RTE_DIM(inset_table); i++) {
12509                 if (!strcmp(string, inset_table[i].str))
12510                         return inset_table[i].inset;
12511         }
12512
12513         return RTE_ETH_INPUT_SET_UNKNOWN;
12514 }
12515
12516 static void
12517 cmd_set_hash_input_set_parsed(void *parsed_result,
12518                               __rte_unused struct cmdline *cl,
12519                               __rte_unused void *data)
12520 {
12521         struct cmd_set_hash_input_set_result *res = parsed_result;
12522         struct rte_eth_hash_filter_info info;
12523
12524         memset(&info, 0, sizeof(info));
12525         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12526         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12527         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12528         info.info.input_set_conf.inset_size = 1;
12529         if (!strcmp(res->select, "select"))
12530                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12531         else if (!strcmp(res->select, "add"))
12532                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12533         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12534                                 RTE_ETH_FILTER_SET, &info);
12535 }
12536
12537 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12538         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12539                 set_hash_input_set, "set_hash_input_set");
12540 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12541         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12542                 port_id, UINT16);
12543 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12544         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12545                 flow_type, NULL);
12546 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12547         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12548                 inset_field,
12549                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12550                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12551                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12552                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12553                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12554                 "fld-8th#none");
12555 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12556         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12557                 select, "select#add");
12558
12559 cmdline_parse_inst_t cmd_set_hash_input_set = {
12560         .f = cmd_set_hash_input_set_parsed,
12561         .data = NULL,
12562         .help_str = "set_hash_input_set <port_id> "
12563         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12564         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12565         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12566         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12567         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12568         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12569         "fld-7th|fld-8th|none select|add",
12570         .tokens = {
12571                 (void *)&cmd_set_hash_input_set_cmd,
12572                 (void *)&cmd_set_hash_input_set_port_id,
12573                 (void *)&cmd_set_hash_input_set_flow_type,
12574                 (void *)&cmd_set_hash_input_set_field,
12575                 (void *)&cmd_set_hash_input_set_select,
12576                 NULL,
12577         },
12578 };
12579
12580 /* Set flow director input set */
12581 struct cmd_set_fdir_input_set_result {
12582         cmdline_fixed_string_t set_fdir_input_set;
12583         portid_t port_id;
12584         cmdline_fixed_string_t flow_type;
12585         cmdline_fixed_string_t inset_field;
12586         cmdline_fixed_string_t select;
12587 };
12588
12589 static void
12590 cmd_set_fdir_input_set_parsed(void *parsed_result,
12591         __rte_unused struct cmdline *cl,
12592         __rte_unused void *data)
12593 {
12594         struct cmd_set_fdir_input_set_result *res = parsed_result;
12595         struct rte_eth_fdir_filter_info info;
12596
12597         memset(&info, 0, sizeof(info));
12598         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12599         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12600         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12601         info.info.input_set_conf.inset_size = 1;
12602         if (!strcmp(res->select, "select"))
12603                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12604         else if (!strcmp(res->select, "add"))
12605                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12606         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12607                 RTE_ETH_FILTER_SET, &info);
12608 }
12609
12610 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12611         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12612         set_fdir_input_set, "set_fdir_input_set");
12613 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12614         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12615         port_id, UINT16);
12616 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12617         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12618         flow_type,
12619         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12620         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12621 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12622         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12623         inset_field,
12624         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12625         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12626         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12627         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12628         "sctp-veri-tag#none");
12629 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12630         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12631         select, "select#add");
12632
12633 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12634         .f = cmd_set_fdir_input_set_parsed,
12635         .data = NULL,
12636         .help_str = "set_fdir_input_set <port_id> "
12637         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12638         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12639         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12640         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12641         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12642         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12643         "sctp-veri-tag|none select|add",
12644         .tokens = {
12645                 (void *)&cmd_set_fdir_input_set_cmd,
12646                 (void *)&cmd_set_fdir_input_set_port_id,
12647                 (void *)&cmd_set_fdir_input_set_flow_type,
12648                 (void *)&cmd_set_fdir_input_set_field,
12649                 (void *)&cmd_set_fdir_input_set_select,
12650                 NULL,
12651         },
12652 };
12653
12654 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12655 struct cmd_mcast_addr_result {
12656         cmdline_fixed_string_t mcast_addr_cmd;
12657         cmdline_fixed_string_t what;
12658         uint16_t port_num;
12659         struct rte_ether_addr mc_addr;
12660 };
12661
12662 static void cmd_mcast_addr_parsed(void *parsed_result,
12663                 __rte_unused struct cmdline *cl,
12664                 __rte_unused void *data)
12665 {
12666         struct cmd_mcast_addr_result *res = parsed_result;
12667
12668         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12669                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12670                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12671                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12672                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12673                 return;
12674         }
12675         if (strcmp(res->what, "add") == 0)
12676                 mcast_addr_add(res->port_num, &res->mc_addr);
12677         else
12678                 mcast_addr_remove(res->port_num, &res->mc_addr);
12679 }
12680
12681 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12682         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12683                                  mcast_addr_cmd, "mcast_addr");
12684 cmdline_parse_token_string_t cmd_mcast_addr_what =
12685         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12686                                  "add#remove");
12687 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12688         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12689 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12690         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12691
12692 cmdline_parse_inst_t cmd_mcast_addr = {
12693         .f = cmd_mcast_addr_parsed,
12694         .data = (void *)0,
12695         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12696                 "Add/Remove multicast MAC address on port_id",
12697         .tokens = {
12698                 (void *)&cmd_mcast_addr_cmd,
12699                 (void *)&cmd_mcast_addr_what,
12700                 (void *)&cmd_mcast_addr_portnum,
12701                 (void *)&cmd_mcast_addr_addr,
12702                 NULL,
12703         },
12704 };
12705
12706 /* l2 tunnel config
12707  * only support E-tag now.
12708  */
12709
12710 /* Ether type config */
12711 struct cmd_config_l2_tunnel_eth_type_result {
12712         cmdline_fixed_string_t port;
12713         cmdline_fixed_string_t config;
12714         cmdline_fixed_string_t all;
12715         portid_t id;
12716         cmdline_fixed_string_t l2_tunnel;
12717         cmdline_fixed_string_t l2_tunnel_type;
12718         cmdline_fixed_string_t eth_type;
12719         uint16_t eth_type_val;
12720 };
12721
12722 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12723         TOKEN_STRING_INITIALIZER
12724                 (struct cmd_config_l2_tunnel_eth_type_result,
12725                  port, "port");
12726 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12727         TOKEN_STRING_INITIALIZER
12728                 (struct cmd_config_l2_tunnel_eth_type_result,
12729                  config, "config");
12730 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12731         TOKEN_STRING_INITIALIZER
12732                 (struct cmd_config_l2_tunnel_eth_type_result,
12733                  all, "all");
12734 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12735         TOKEN_NUM_INITIALIZER
12736                 (struct cmd_config_l2_tunnel_eth_type_result,
12737                  id, UINT16);
12738 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12739         TOKEN_STRING_INITIALIZER
12740                 (struct cmd_config_l2_tunnel_eth_type_result,
12741                  l2_tunnel, "l2-tunnel");
12742 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12743         TOKEN_STRING_INITIALIZER
12744                 (struct cmd_config_l2_tunnel_eth_type_result,
12745                  l2_tunnel_type, "E-tag");
12746 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12747         TOKEN_STRING_INITIALIZER
12748                 (struct cmd_config_l2_tunnel_eth_type_result,
12749                  eth_type, "ether-type");
12750 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12751         TOKEN_NUM_INITIALIZER
12752                 (struct cmd_config_l2_tunnel_eth_type_result,
12753                  eth_type_val, UINT16);
12754
12755 static enum rte_eth_tunnel_type
12756 str2fdir_l2_tunnel_type(char *string)
12757 {
12758         uint32_t i = 0;
12759
12760         static const struct {
12761                 char str[32];
12762                 enum rte_eth_tunnel_type type;
12763         } l2_tunnel_type_str[] = {
12764                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12765         };
12766
12767         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12768                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12769                         return l2_tunnel_type_str[i].type;
12770         }
12771         return RTE_TUNNEL_TYPE_NONE;
12772 }
12773
12774 /* ether type config for all ports */
12775 static void
12776 cmd_config_l2_tunnel_eth_type_all_parsed
12777         (void *parsed_result,
12778          __rte_unused struct cmdline *cl,
12779          __rte_unused void *data)
12780 {
12781         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12782         struct rte_eth_l2_tunnel_conf entry;
12783         portid_t pid;
12784
12785         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12786         entry.ether_type = res->eth_type_val;
12787
12788         RTE_ETH_FOREACH_DEV(pid) {
12789                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12790         }
12791 }
12792
12793 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12794         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12795         .data = NULL,
12796         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12797         .tokens = {
12798                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12799                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12800                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12801                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12802                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12803                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12804                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12805                 NULL,
12806         },
12807 };
12808
12809 /* ether type config for a specific port */
12810 static void
12811 cmd_config_l2_tunnel_eth_type_specific_parsed(
12812         void *parsed_result,
12813         __rte_unused struct cmdline *cl,
12814         __rte_unused void *data)
12815 {
12816         struct cmd_config_l2_tunnel_eth_type_result *res =
12817                  parsed_result;
12818         struct rte_eth_l2_tunnel_conf entry;
12819
12820         if (port_id_is_invalid(res->id, ENABLED_WARN))
12821                 return;
12822
12823         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12824         entry.ether_type = res->eth_type_val;
12825
12826         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12827 }
12828
12829 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12830         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12831         .data = NULL,
12832         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12833         .tokens = {
12834                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12835                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12836                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12837                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12838                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12839                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12840                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12841                 NULL,
12842         },
12843 };
12844
12845 /* Enable/disable l2 tunnel */
12846 struct cmd_config_l2_tunnel_en_dis_result {
12847         cmdline_fixed_string_t port;
12848         cmdline_fixed_string_t config;
12849         cmdline_fixed_string_t all;
12850         portid_t id;
12851         cmdline_fixed_string_t l2_tunnel;
12852         cmdline_fixed_string_t l2_tunnel_type;
12853         cmdline_fixed_string_t en_dis;
12854 };
12855
12856 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12857         TOKEN_STRING_INITIALIZER
12858                 (struct cmd_config_l2_tunnel_en_dis_result,
12859                  port, "port");
12860 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12861         TOKEN_STRING_INITIALIZER
12862                 (struct cmd_config_l2_tunnel_en_dis_result,
12863                  config, "config");
12864 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12865         TOKEN_STRING_INITIALIZER
12866                 (struct cmd_config_l2_tunnel_en_dis_result,
12867                  all, "all");
12868 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12869         TOKEN_NUM_INITIALIZER
12870                 (struct cmd_config_l2_tunnel_en_dis_result,
12871                  id, UINT16);
12872 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12873         TOKEN_STRING_INITIALIZER
12874                 (struct cmd_config_l2_tunnel_en_dis_result,
12875                  l2_tunnel, "l2-tunnel");
12876 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12877         TOKEN_STRING_INITIALIZER
12878                 (struct cmd_config_l2_tunnel_en_dis_result,
12879                  l2_tunnel_type, "E-tag");
12880 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12881         TOKEN_STRING_INITIALIZER
12882                 (struct cmd_config_l2_tunnel_en_dis_result,
12883                  en_dis, "enable#disable");
12884
12885 /* enable/disable l2 tunnel for all ports */
12886 static void
12887 cmd_config_l2_tunnel_en_dis_all_parsed(
12888         void *parsed_result,
12889         __rte_unused struct cmdline *cl,
12890         __rte_unused void *data)
12891 {
12892         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12893         struct rte_eth_l2_tunnel_conf entry;
12894         portid_t pid;
12895         uint8_t en;
12896
12897         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12898
12899         if (!strcmp("enable", res->en_dis))
12900                 en = 1;
12901         else
12902                 en = 0;
12903
12904         RTE_ETH_FOREACH_DEV(pid) {
12905                 rte_eth_dev_l2_tunnel_offload_set(pid,
12906                                                   &entry,
12907                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12908                                                   en);
12909         }
12910 }
12911
12912 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12913         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12914         .data = NULL,
12915         .help_str = "port config all l2-tunnel E-tag enable|disable",
12916         .tokens = {
12917                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12918                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12919                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12920                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12921                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12922                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12923                 NULL,
12924         },
12925 };
12926
12927 /* enable/disable l2 tunnel for a port */
12928 static void
12929 cmd_config_l2_tunnel_en_dis_specific_parsed(
12930         void *parsed_result,
12931         __rte_unused struct cmdline *cl,
12932         __rte_unused void *data)
12933 {
12934         struct cmd_config_l2_tunnel_en_dis_result *res =
12935                 parsed_result;
12936         struct rte_eth_l2_tunnel_conf entry;
12937
12938         if (port_id_is_invalid(res->id, ENABLED_WARN))
12939                 return;
12940
12941         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12942
12943         if (!strcmp("enable", res->en_dis))
12944                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12945                                                   &entry,
12946                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12947                                                   1);
12948         else
12949                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12950                                                   &entry,
12951                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12952                                                   0);
12953 }
12954
12955 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12956         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12957         .data = NULL,
12958         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12959         .tokens = {
12960                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12961                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12962                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12963                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12964                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12965                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12966                 NULL,
12967         },
12968 };
12969
12970 /* E-tag configuration */
12971
12972 /* Common result structure for all E-tag configuration */
12973 struct cmd_config_e_tag_result {
12974         cmdline_fixed_string_t e_tag;
12975         cmdline_fixed_string_t set;
12976         cmdline_fixed_string_t insertion;
12977         cmdline_fixed_string_t stripping;
12978         cmdline_fixed_string_t forwarding;
12979         cmdline_fixed_string_t filter;
12980         cmdline_fixed_string_t add;
12981         cmdline_fixed_string_t del;
12982         cmdline_fixed_string_t on;
12983         cmdline_fixed_string_t off;
12984         cmdline_fixed_string_t on_off;
12985         cmdline_fixed_string_t port_tag_id;
12986         uint32_t port_tag_id_val;
12987         cmdline_fixed_string_t e_tag_id;
12988         uint16_t e_tag_id_val;
12989         cmdline_fixed_string_t dst_pool;
12990         uint8_t dst_pool_val;
12991         cmdline_fixed_string_t port;
12992         portid_t port_id;
12993         cmdline_fixed_string_t vf;
12994         uint8_t vf_id;
12995 };
12996
12997 /* Common CLI fields for all E-tag configuration */
12998 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
12999         TOKEN_STRING_INITIALIZER
13000                 (struct cmd_config_e_tag_result,
13001                  e_tag, "E-tag");
13002 cmdline_parse_token_string_t cmd_config_e_tag_set =
13003         TOKEN_STRING_INITIALIZER
13004                 (struct cmd_config_e_tag_result,
13005                  set, "set");
13006 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13007         TOKEN_STRING_INITIALIZER
13008                 (struct cmd_config_e_tag_result,
13009                  insertion, "insertion");
13010 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13011         TOKEN_STRING_INITIALIZER
13012                 (struct cmd_config_e_tag_result,
13013                  stripping, "stripping");
13014 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13015         TOKEN_STRING_INITIALIZER
13016                 (struct cmd_config_e_tag_result,
13017                  forwarding, "forwarding");
13018 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13019         TOKEN_STRING_INITIALIZER
13020                 (struct cmd_config_e_tag_result,
13021                  filter, "filter");
13022 cmdline_parse_token_string_t cmd_config_e_tag_add =
13023         TOKEN_STRING_INITIALIZER
13024                 (struct cmd_config_e_tag_result,
13025                  add, "add");
13026 cmdline_parse_token_string_t cmd_config_e_tag_del =
13027         TOKEN_STRING_INITIALIZER
13028                 (struct cmd_config_e_tag_result,
13029                  del, "del");
13030 cmdline_parse_token_string_t cmd_config_e_tag_on =
13031         TOKEN_STRING_INITIALIZER
13032                 (struct cmd_config_e_tag_result,
13033                  on, "on");
13034 cmdline_parse_token_string_t cmd_config_e_tag_off =
13035         TOKEN_STRING_INITIALIZER
13036                 (struct cmd_config_e_tag_result,
13037                  off, "off");
13038 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13039         TOKEN_STRING_INITIALIZER
13040                 (struct cmd_config_e_tag_result,
13041                  on_off, "on#off");
13042 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13043         TOKEN_STRING_INITIALIZER
13044                 (struct cmd_config_e_tag_result,
13045                  port_tag_id, "port-tag-id");
13046 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13047         TOKEN_NUM_INITIALIZER
13048                 (struct cmd_config_e_tag_result,
13049                  port_tag_id_val, UINT32);
13050 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13051         TOKEN_STRING_INITIALIZER
13052                 (struct cmd_config_e_tag_result,
13053                  e_tag_id, "e-tag-id");
13054 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13055         TOKEN_NUM_INITIALIZER
13056                 (struct cmd_config_e_tag_result,
13057                  e_tag_id_val, UINT16);
13058 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13059         TOKEN_STRING_INITIALIZER
13060                 (struct cmd_config_e_tag_result,
13061                  dst_pool, "dst-pool");
13062 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13063         TOKEN_NUM_INITIALIZER
13064                 (struct cmd_config_e_tag_result,
13065                  dst_pool_val, UINT8);
13066 cmdline_parse_token_string_t cmd_config_e_tag_port =
13067         TOKEN_STRING_INITIALIZER
13068                 (struct cmd_config_e_tag_result,
13069                  port, "port");
13070 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13071         TOKEN_NUM_INITIALIZER
13072                 (struct cmd_config_e_tag_result,
13073                  port_id, UINT16);
13074 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13075         TOKEN_STRING_INITIALIZER
13076                 (struct cmd_config_e_tag_result,
13077                  vf, "vf");
13078 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13079         TOKEN_NUM_INITIALIZER
13080                 (struct cmd_config_e_tag_result,
13081                  vf_id, UINT8);
13082
13083 /* E-tag insertion configuration */
13084 static void
13085 cmd_config_e_tag_insertion_en_parsed(
13086         void *parsed_result,
13087         __rte_unused struct cmdline *cl,
13088         __rte_unused void *data)
13089 {
13090         struct cmd_config_e_tag_result *res =
13091                 parsed_result;
13092         struct rte_eth_l2_tunnel_conf entry;
13093
13094         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13095                 return;
13096
13097         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13098         entry.tunnel_id = res->port_tag_id_val;
13099         entry.vf_id = res->vf_id;
13100         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13101                                           &entry,
13102                                           ETH_L2_TUNNEL_INSERTION_MASK,
13103                                           1);
13104 }
13105
13106 static void
13107 cmd_config_e_tag_insertion_dis_parsed(
13108         void *parsed_result,
13109         __rte_unused struct cmdline *cl,
13110         __rte_unused void *data)
13111 {
13112         struct cmd_config_e_tag_result *res =
13113                 parsed_result;
13114         struct rte_eth_l2_tunnel_conf entry;
13115
13116         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13117                 return;
13118
13119         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13120         entry.vf_id = res->vf_id;
13121
13122         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13123                                           &entry,
13124                                           ETH_L2_TUNNEL_INSERTION_MASK,
13125                                           0);
13126 }
13127
13128 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13129         .f = cmd_config_e_tag_insertion_en_parsed,
13130         .data = NULL,
13131         .help_str = "E-tag ... : E-tag insertion enable",
13132         .tokens = {
13133                 (void *)&cmd_config_e_tag_e_tag,
13134                 (void *)&cmd_config_e_tag_set,
13135                 (void *)&cmd_config_e_tag_insertion,
13136                 (void *)&cmd_config_e_tag_on,
13137                 (void *)&cmd_config_e_tag_port_tag_id,
13138                 (void *)&cmd_config_e_tag_port_tag_id_val,
13139                 (void *)&cmd_config_e_tag_port,
13140                 (void *)&cmd_config_e_tag_port_id,
13141                 (void *)&cmd_config_e_tag_vf,
13142                 (void *)&cmd_config_e_tag_vf_id,
13143                 NULL,
13144         },
13145 };
13146
13147 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13148         .f = cmd_config_e_tag_insertion_dis_parsed,
13149         .data = NULL,
13150         .help_str = "E-tag ... : E-tag insertion disable",
13151         .tokens = {
13152                 (void *)&cmd_config_e_tag_e_tag,
13153                 (void *)&cmd_config_e_tag_set,
13154                 (void *)&cmd_config_e_tag_insertion,
13155                 (void *)&cmd_config_e_tag_off,
13156                 (void *)&cmd_config_e_tag_port,
13157                 (void *)&cmd_config_e_tag_port_id,
13158                 (void *)&cmd_config_e_tag_vf,
13159                 (void *)&cmd_config_e_tag_vf_id,
13160                 NULL,
13161         },
13162 };
13163
13164 /* E-tag stripping configuration */
13165 static void
13166 cmd_config_e_tag_stripping_parsed(
13167         void *parsed_result,
13168         __rte_unused struct cmdline *cl,
13169         __rte_unused void *data)
13170 {
13171         struct cmd_config_e_tag_result *res =
13172                 parsed_result;
13173         struct rte_eth_l2_tunnel_conf entry;
13174
13175         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13176                 return;
13177
13178         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13179
13180         if (!strcmp(res->on_off, "on"))
13181                 rte_eth_dev_l2_tunnel_offload_set
13182                         (res->port_id,
13183                          &entry,
13184                          ETH_L2_TUNNEL_STRIPPING_MASK,
13185                          1);
13186         else
13187                 rte_eth_dev_l2_tunnel_offload_set
13188                         (res->port_id,
13189                          &entry,
13190                          ETH_L2_TUNNEL_STRIPPING_MASK,
13191                          0);
13192 }
13193
13194 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13195         .f = cmd_config_e_tag_stripping_parsed,
13196         .data = NULL,
13197         .help_str = "E-tag ... : E-tag stripping enable/disable",
13198         .tokens = {
13199                 (void *)&cmd_config_e_tag_e_tag,
13200                 (void *)&cmd_config_e_tag_set,
13201                 (void *)&cmd_config_e_tag_stripping,
13202                 (void *)&cmd_config_e_tag_on_off,
13203                 (void *)&cmd_config_e_tag_port,
13204                 (void *)&cmd_config_e_tag_port_id,
13205                 NULL,
13206         },
13207 };
13208
13209 /* E-tag forwarding configuration */
13210 static void
13211 cmd_config_e_tag_forwarding_parsed(
13212         void *parsed_result,
13213         __rte_unused struct cmdline *cl,
13214         __rte_unused void *data)
13215 {
13216         struct cmd_config_e_tag_result *res = parsed_result;
13217         struct rte_eth_l2_tunnel_conf entry;
13218
13219         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13220                 return;
13221
13222         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13223
13224         if (!strcmp(res->on_off, "on"))
13225                 rte_eth_dev_l2_tunnel_offload_set
13226                         (res->port_id,
13227                          &entry,
13228                          ETH_L2_TUNNEL_FORWARDING_MASK,
13229                          1);
13230         else
13231                 rte_eth_dev_l2_tunnel_offload_set
13232                         (res->port_id,
13233                          &entry,
13234                          ETH_L2_TUNNEL_FORWARDING_MASK,
13235                          0);
13236 }
13237
13238 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13239         .f = cmd_config_e_tag_forwarding_parsed,
13240         .data = NULL,
13241         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13242         .tokens = {
13243                 (void *)&cmd_config_e_tag_e_tag,
13244                 (void *)&cmd_config_e_tag_set,
13245                 (void *)&cmd_config_e_tag_forwarding,
13246                 (void *)&cmd_config_e_tag_on_off,
13247                 (void *)&cmd_config_e_tag_port,
13248                 (void *)&cmd_config_e_tag_port_id,
13249                 NULL,
13250         },
13251 };
13252
13253 /* E-tag filter configuration */
13254 static void
13255 cmd_config_e_tag_filter_add_parsed(
13256         void *parsed_result,
13257         __rte_unused struct cmdline *cl,
13258         __rte_unused void *data)
13259 {
13260         struct cmd_config_e_tag_result *res = parsed_result;
13261         struct rte_eth_l2_tunnel_conf entry;
13262         int ret = 0;
13263
13264         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13265                 return;
13266
13267         if (res->e_tag_id_val > 0x3fff) {
13268                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13269                 return;
13270         }
13271
13272         ret = rte_eth_dev_filter_supported(res->port_id,
13273                                            RTE_ETH_FILTER_L2_TUNNEL);
13274         if (ret < 0) {
13275                 printf("E-tag filter is not supported on port %u.\n",
13276                        res->port_id);
13277                 return;
13278         }
13279
13280         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13281         entry.tunnel_id = res->e_tag_id_val;
13282         entry.pool = res->dst_pool_val;
13283
13284         ret = rte_eth_dev_filter_ctrl(res->port_id,
13285                                       RTE_ETH_FILTER_L2_TUNNEL,
13286                                       RTE_ETH_FILTER_ADD,
13287                                       &entry);
13288         if (ret < 0)
13289                 printf("E-tag filter programming error: (%s)\n",
13290                        strerror(-ret));
13291 }
13292
13293 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13294         .f = cmd_config_e_tag_filter_add_parsed,
13295         .data = NULL,
13296         .help_str = "E-tag ... : E-tag filter add",
13297         .tokens = {
13298                 (void *)&cmd_config_e_tag_e_tag,
13299                 (void *)&cmd_config_e_tag_set,
13300                 (void *)&cmd_config_e_tag_filter,
13301                 (void *)&cmd_config_e_tag_add,
13302                 (void *)&cmd_config_e_tag_e_tag_id,
13303                 (void *)&cmd_config_e_tag_e_tag_id_val,
13304                 (void *)&cmd_config_e_tag_dst_pool,
13305                 (void *)&cmd_config_e_tag_dst_pool_val,
13306                 (void *)&cmd_config_e_tag_port,
13307                 (void *)&cmd_config_e_tag_port_id,
13308                 NULL,
13309         },
13310 };
13311
13312 static void
13313 cmd_config_e_tag_filter_del_parsed(
13314         void *parsed_result,
13315         __rte_unused struct cmdline *cl,
13316         __rte_unused void *data)
13317 {
13318         struct cmd_config_e_tag_result *res = parsed_result;
13319         struct rte_eth_l2_tunnel_conf entry;
13320         int ret = 0;
13321
13322         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13323                 return;
13324
13325         if (res->e_tag_id_val > 0x3fff) {
13326                 printf("e-tag-id must be less than 0x3fff.\n");
13327                 return;
13328         }
13329
13330         ret = rte_eth_dev_filter_supported(res->port_id,
13331                                            RTE_ETH_FILTER_L2_TUNNEL);
13332         if (ret < 0) {
13333                 printf("E-tag filter is not supported on port %u.\n",
13334                        res->port_id);
13335                 return;
13336         }
13337
13338         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13339         entry.tunnel_id = res->e_tag_id_val;
13340
13341         ret = rte_eth_dev_filter_ctrl(res->port_id,
13342                                       RTE_ETH_FILTER_L2_TUNNEL,
13343                                       RTE_ETH_FILTER_DELETE,
13344                                       &entry);
13345         if (ret < 0)
13346                 printf("E-tag filter programming error: (%s)\n",
13347                        strerror(-ret));
13348 }
13349
13350 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13351         .f = cmd_config_e_tag_filter_del_parsed,
13352         .data = NULL,
13353         .help_str = "E-tag ... : E-tag filter delete",
13354         .tokens = {
13355                 (void *)&cmd_config_e_tag_e_tag,
13356                 (void *)&cmd_config_e_tag_set,
13357                 (void *)&cmd_config_e_tag_filter,
13358                 (void *)&cmd_config_e_tag_del,
13359                 (void *)&cmd_config_e_tag_e_tag_id,
13360                 (void *)&cmd_config_e_tag_e_tag_id_val,
13361                 (void *)&cmd_config_e_tag_port,
13362                 (void *)&cmd_config_e_tag_port_id,
13363                 NULL,
13364         },
13365 };
13366
13367 /* vf vlan anti spoof configuration */
13368
13369 /* Common result structure for vf vlan anti spoof */
13370 struct cmd_vf_vlan_anti_spoof_result {
13371         cmdline_fixed_string_t set;
13372         cmdline_fixed_string_t vf;
13373         cmdline_fixed_string_t vlan;
13374         cmdline_fixed_string_t antispoof;
13375         portid_t port_id;
13376         uint32_t vf_id;
13377         cmdline_fixed_string_t on_off;
13378 };
13379
13380 /* Common CLI fields for vf vlan anti spoof enable disable */
13381 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13382         TOKEN_STRING_INITIALIZER
13383                 (struct cmd_vf_vlan_anti_spoof_result,
13384                  set, "set");
13385 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13386         TOKEN_STRING_INITIALIZER
13387                 (struct cmd_vf_vlan_anti_spoof_result,
13388                  vf, "vf");
13389 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13390         TOKEN_STRING_INITIALIZER
13391                 (struct cmd_vf_vlan_anti_spoof_result,
13392                  vlan, "vlan");
13393 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13394         TOKEN_STRING_INITIALIZER
13395                 (struct cmd_vf_vlan_anti_spoof_result,
13396                  antispoof, "antispoof");
13397 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13398         TOKEN_NUM_INITIALIZER
13399                 (struct cmd_vf_vlan_anti_spoof_result,
13400                  port_id, UINT16);
13401 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13402         TOKEN_NUM_INITIALIZER
13403                 (struct cmd_vf_vlan_anti_spoof_result,
13404                  vf_id, UINT32);
13405 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13406         TOKEN_STRING_INITIALIZER
13407                 (struct cmd_vf_vlan_anti_spoof_result,
13408                  on_off, "on#off");
13409
13410 static void
13411 cmd_set_vf_vlan_anti_spoof_parsed(
13412         void *parsed_result,
13413         __rte_unused struct cmdline *cl,
13414         __rte_unused void *data)
13415 {
13416         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13417         int ret = -ENOTSUP;
13418
13419         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13420
13421         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13422                 return;
13423
13424 #ifdef RTE_NET_IXGBE
13425         if (ret == -ENOTSUP)
13426                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13427                                 res->vf_id, is_on);
13428 #endif
13429 #ifdef RTE_NET_I40E
13430         if (ret == -ENOTSUP)
13431                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13432                                 res->vf_id, is_on);
13433 #endif
13434 #ifdef RTE_NET_BNXT
13435         if (ret == -ENOTSUP)
13436                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13437                                 res->vf_id, is_on);
13438 #endif
13439
13440         switch (ret) {
13441         case 0:
13442                 break;
13443         case -EINVAL:
13444                 printf("invalid vf_id %d\n", res->vf_id);
13445                 break;
13446         case -ENODEV:
13447                 printf("invalid port_id %d\n", res->port_id);
13448                 break;
13449         case -ENOTSUP:
13450                 printf("function not implemented\n");
13451                 break;
13452         default:
13453                 printf("programming error: (%s)\n", strerror(-ret));
13454         }
13455 }
13456
13457 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13458         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13459         .data = NULL,
13460         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13461         .tokens = {
13462                 (void *)&cmd_vf_vlan_anti_spoof_set,
13463                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13464                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13465                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13466                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13467                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13468                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13469                 NULL,
13470         },
13471 };
13472
13473 /* vf mac anti spoof configuration */
13474
13475 /* Common result structure for vf mac anti spoof */
13476 struct cmd_vf_mac_anti_spoof_result {
13477         cmdline_fixed_string_t set;
13478         cmdline_fixed_string_t vf;
13479         cmdline_fixed_string_t mac;
13480         cmdline_fixed_string_t antispoof;
13481         portid_t port_id;
13482         uint32_t vf_id;
13483         cmdline_fixed_string_t on_off;
13484 };
13485
13486 /* Common CLI fields for vf mac anti spoof enable disable */
13487 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13488         TOKEN_STRING_INITIALIZER
13489                 (struct cmd_vf_mac_anti_spoof_result,
13490                  set, "set");
13491 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13492         TOKEN_STRING_INITIALIZER
13493                 (struct cmd_vf_mac_anti_spoof_result,
13494                  vf, "vf");
13495 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13496         TOKEN_STRING_INITIALIZER
13497                 (struct cmd_vf_mac_anti_spoof_result,
13498                  mac, "mac");
13499 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13500         TOKEN_STRING_INITIALIZER
13501                 (struct cmd_vf_mac_anti_spoof_result,
13502                  antispoof, "antispoof");
13503 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13504         TOKEN_NUM_INITIALIZER
13505                 (struct cmd_vf_mac_anti_spoof_result,
13506                  port_id, UINT16);
13507 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13508         TOKEN_NUM_INITIALIZER
13509                 (struct cmd_vf_mac_anti_spoof_result,
13510                  vf_id, UINT32);
13511 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13512         TOKEN_STRING_INITIALIZER
13513                 (struct cmd_vf_mac_anti_spoof_result,
13514                  on_off, "on#off");
13515
13516 static void
13517 cmd_set_vf_mac_anti_spoof_parsed(
13518         void *parsed_result,
13519         __rte_unused struct cmdline *cl,
13520         __rte_unused void *data)
13521 {
13522         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13523         int ret = -ENOTSUP;
13524
13525         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13526
13527         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13528                 return;
13529
13530 #ifdef RTE_NET_IXGBE
13531         if (ret == -ENOTSUP)
13532                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13533                         res->vf_id, is_on);
13534 #endif
13535 #ifdef RTE_NET_I40E
13536         if (ret == -ENOTSUP)
13537                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13538                         res->vf_id, is_on);
13539 #endif
13540 #ifdef RTE_NET_BNXT
13541         if (ret == -ENOTSUP)
13542                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13543                         res->vf_id, is_on);
13544 #endif
13545
13546         switch (ret) {
13547         case 0:
13548                 break;
13549         case -EINVAL:
13550                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13551                 break;
13552         case -ENODEV:
13553                 printf("invalid port_id %d\n", res->port_id);
13554                 break;
13555         case -ENOTSUP:
13556                 printf("function not implemented\n");
13557                 break;
13558         default:
13559                 printf("programming error: (%s)\n", strerror(-ret));
13560         }
13561 }
13562
13563 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13564         .f = cmd_set_vf_mac_anti_spoof_parsed,
13565         .data = NULL,
13566         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13567         .tokens = {
13568                 (void *)&cmd_vf_mac_anti_spoof_set,
13569                 (void *)&cmd_vf_mac_anti_spoof_vf,
13570                 (void *)&cmd_vf_mac_anti_spoof_mac,
13571                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13572                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13573                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13574                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13575                 NULL,
13576         },
13577 };
13578
13579 /* vf vlan strip queue configuration */
13580
13581 /* Common result structure for vf mac anti spoof */
13582 struct cmd_vf_vlan_stripq_result {
13583         cmdline_fixed_string_t set;
13584         cmdline_fixed_string_t vf;
13585         cmdline_fixed_string_t vlan;
13586         cmdline_fixed_string_t stripq;
13587         portid_t port_id;
13588         uint16_t vf_id;
13589         cmdline_fixed_string_t on_off;
13590 };
13591
13592 /* Common CLI fields for vf vlan strip enable disable */
13593 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13594         TOKEN_STRING_INITIALIZER
13595                 (struct cmd_vf_vlan_stripq_result,
13596                  set, "set");
13597 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13598         TOKEN_STRING_INITIALIZER
13599                 (struct cmd_vf_vlan_stripq_result,
13600                  vf, "vf");
13601 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13602         TOKEN_STRING_INITIALIZER
13603                 (struct cmd_vf_vlan_stripq_result,
13604                  vlan, "vlan");
13605 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13606         TOKEN_STRING_INITIALIZER
13607                 (struct cmd_vf_vlan_stripq_result,
13608                  stripq, "stripq");
13609 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13610         TOKEN_NUM_INITIALIZER
13611                 (struct cmd_vf_vlan_stripq_result,
13612                  port_id, UINT16);
13613 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13614         TOKEN_NUM_INITIALIZER
13615                 (struct cmd_vf_vlan_stripq_result,
13616                  vf_id, UINT16);
13617 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13618         TOKEN_STRING_INITIALIZER
13619                 (struct cmd_vf_vlan_stripq_result,
13620                  on_off, "on#off");
13621
13622 static void
13623 cmd_set_vf_vlan_stripq_parsed(
13624         void *parsed_result,
13625         __rte_unused struct cmdline *cl,
13626         __rte_unused void *data)
13627 {
13628         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13629         int ret = -ENOTSUP;
13630
13631         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13632
13633         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13634                 return;
13635
13636 #ifdef RTE_NET_IXGBE
13637         if (ret == -ENOTSUP)
13638                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13639                         res->vf_id, is_on);
13640 #endif
13641 #ifdef RTE_NET_I40E
13642         if (ret == -ENOTSUP)
13643                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13644                         res->vf_id, is_on);
13645 #endif
13646 #ifdef RTE_NET_BNXT
13647         if (ret == -ENOTSUP)
13648                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13649                         res->vf_id, is_on);
13650 #endif
13651
13652         switch (ret) {
13653         case 0:
13654                 break;
13655         case -EINVAL:
13656                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13657                 break;
13658         case -ENODEV:
13659                 printf("invalid port_id %d\n", res->port_id);
13660                 break;
13661         case -ENOTSUP:
13662                 printf("function not implemented\n");
13663                 break;
13664         default:
13665                 printf("programming error: (%s)\n", strerror(-ret));
13666         }
13667 }
13668
13669 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13670         .f = cmd_set_vf_vlan_stripq_parsed,
13671         .data = NULL,
13672         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13673         .tokens = {
13674                 (void *)&cmd_vf_vlan_stripq_set,
13675                 (void *)&cmd_vf_vlan_stripq_vf,
13676                 (void *)&cmd_vf_vlan_stripq_vlan,
13677                 (void *)&cmd_vf_vlan_stripq_stripq,
13678                 (void *)&cmd_vf_vlan_stripq_port_id,
13679                 (void *)&cmd_vf_vlan_stripq_vf_id,
13680                 (void *)&cmd_vf_vlan_stripq_on_off,
13681                 NULL,
13682         },
13683 };
13684
13685 /* vf vlan insert configuration */
13686
13687 /* Common result structure for vf vlan insert */
13688 struct cmd_vf_vlan_insert_result {
13689         cmdline_fixed_string_t set;
13690         cmdline_fixed_string_t vf;
13691         cmdline_fixed_string_t vlan;
13692         cmdline_fixed_string_t insert;
13693         portid_t port_id;
13694         uint16_t vf_id;
13695         uint16_t vlan_id;
13696 };
13697
13698 /* Common CLI fields for vf vlan insert enable disable */
13699 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13700         TOKEN_STRING_INITIALIZER
13701                 (struct cmd_vf_vlan_insert_result,
13702                  set, "set");
13703 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13704         TOKEN_STRING_INITIALIZER
13705                 (struct cmd_vf_vlan_insert_result,
13706                  vf, "vf");
13707 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13708         TOKEN_STRING_INITIALIZER
13709                 (struct cmd_vf_vlan_insert_result,
13710                  vlan, "vlan");
13711 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13712         TOKEN_STRING_INITIALIZER
13713                 (struct cmd_vf_vlan_insert_result,
13714                  insert, "insert");
13715 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13716         TOKEN_NUM_INITIALIZER
13717                 (struct cmd_vf_vlan_insert_result,
13718                  port_id, UINT16);
13719 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13720         TOKEN_NUM_INITIALIZER
13721                 (struct cmd_vf_vlan_insert_result,
13722                  vf_id, UINT16);
13723 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13724         TOKEN_NUM_INITIALIZER
13725                 (struct cmd_vf_vlan_insert_result,
13726                  vlan_id, UINT16);
13727
13728 static void
13729 cmd_set_vf_vlan_insert_parsed(
13730         void *parsed_result,
13731         __rte_unused struct cmdline *cl,
13732         __rte_unused void *data)
13733 {
13734         struct cmd_vf_vlan_insert_result *res = parsed_result;
13735         int ret = -ENOTSUP;
13736
13737         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13738                 return;
13739
13740 #ifdef RTE_NET_IXGBE
13741         if (ret == -ENOTSUP)
13742                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13743                         res->vlan_id);
13744 #endif
13745 #ifdef RTE_NET_I40E
13746         if (ret == -ENOTSUP)
13747                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13748                         res->vlan_id);
13749 #endif
13750 #ifdef RTE_NET_BNXT
13751         if (ret == -ENOTSUP)
13752                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13753                         res->vlan_id);
13754 #endif
13755
13756         switch (ret) {
13757         case 0:
13758                 break;
13759         case -EINVAL:
13760                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13761                 break;
13762         case -ENODEV:
13763                 printf("invalid port_id %d\n", res->port_id);
13764                 break;
13765         case -ENOTSUP:
13766                 printf("function not implemented\n");
13767                 break;
13768         default:
13769                 printf("programming error: (%s)\n", strerror(-ret));
13770         }
13771 }
13772
13773 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13774         .f = cmd_set_vf_vlan_insert_parsed,
13775         .data = NULL,
13776         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13777         .tokens = {
13778                 (void *)&cmd_vf_vlan_insert_set,
13779                 (void *)&cmd_vf_vlan_insert_vf,
13780                 (void *)&cmd_vf_vlan_insert_vlan,
13781                 (void *)&cmd_vf_vlan_insert_insert,
13782                 (void *)&cmd_vf_vlan_insert_port_id,
13783                 (void *)&cmd_vf_vlan_insert_vf_id,
13784                 (void *)&cmd_vf_vlan_insert_vlan_id,
13785                 NULL,
13786         },
13787 };
13788
13789 /* tx loopback configuration */
13790
13791 /* Common result structure for tx loopback */
13792 struct cmd_tx_loopback_result {
13793         cmdline_fixed_string_t set;
13794         cmdline_fixed_string_t tx;
13795         cmdline_fixed_string_t loopback;
13796         portid_t port_id;
13797         cmdline_fixed_string_t on_off;
13798 };
13799
13800 /* Common CLI fields for tx loopback enable disable */
13801 cmdline_parse_token_string_t cmd_tx_loopback_set =
13802         TOKEN_STRING_INITIALIZER
13803                 (struct cmd_tx_loopback_result,
13804                  set, "set");
13805 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13806         TOKEN_STRING_INITIALIZER
13807                 (struct cmd_tx_loopback_result,
13808                  tx, "tx");
13809 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13810         TOKEN_STRING_INITIALIZER
13811                 (struct cmd_tx_loopback_result,
13812                  loopback, "loopback");
13813 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13814         TOKEN_NUM_INITIALIZER
13815                 (struct cmd_tx_loopback_result,
13816                  port_id, UINT16);
13817 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13818         TOKEN_STRING_INITIALIZER
13819                 (struct cmd_tx_loopback_result,
13820                  on_off, "on#off");
13821
13822 static void
13823 cmd_set_tx_loopback_parsed(
13824         void *parsed_result,
13825         __rte_unused struct cmdline *cl,
13826         __rte_unused void *data)
13827 {
13828         struct cmd_tx_loopback_result *res = parsed_result;
13829         int ret = -ENOTSUP;
13830
13831         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13832
13833         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13834                 return;
13835
13836 #ifdef RTE_NET_IXGBE
13837         if (ret == -ENOTSUP)
13838                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13839 #endif
13840 #ifdef RTE_NET_I40E
13841         if (ret == -ENOTSUP)
13842                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13843 #endif
13844 #ifdef RTE_NET_BNXT
13845         if (ret == -ENOTSUP)
13846                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13847 #endif
13848 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
13849         if (ret == -ENOTSUP)
13850                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13851 #endif
13852
13853         switch (ret) {
13854         case 0:
13855                 break;
13856         case -EINVAL:
13857                 printf("invalid is_on %d\n", is_on);
13858                 break;
13859         case -ENODEV:
13860                 printf("invalid port_id %d\n", res->port_id);
13861                 break;
13862         case -ENOTSUP:
13863                 printf("function not implemented\n");
13864                 break;
13865         default:
13866                 printf("programming error: (%s)\n", strerror(-ret));
13867         }
13868 }
13869
13870 cmdline_parse_inst_t cmd_set_tx_loopback = {
13871         .f = cmd_set_tx_loopback_parsed,
13872         .data = NULL,
13873         .help_str = "set tx loopback <port_id> on|off",
13874         .tokens = {
13875                 (void *)&cmd_tx_loopback_set,
13876                 (void *)&cmd_tx_loopback_tx,
13877                 (void *)&cmd_tx_loopback_loopback,
13878                 (void *)&cmd_tx_loopback_port_id,
13879                 (void *)&cmd_tx_loopback_on_off,
13880                 NULL,
13881         },
13882 };
13883
13884 /* all queues drop enable configuration */
13885
13886 /* Common result structure for all queues drop enable */
13887 struct cmd_all_queues_drop_en_result {
13888         cmdline_fixed_string_t set;
13889         cmdline_fixed_string_t all;
13890         cmdline_fixed_string_t queues;
13891         cmdline_fixed_string_t drop;
13892         portid_t port_id;
13893         cmdline_fixed_string_t on_off;
13894 };
13895
13896 /* Common CLI fields for tx loopback enable disable */
13897 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13898         TOKEN_STRING_INITIALIZER
13899                 (struct cmd_all_queues_drop_en_result,
13900                  set, "set");
13901 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13902         TOKEN_STRING_INITIALIZER
13903                 (struct cmd_all_queues_drop_en_result,
13904                  all, "all");
13905 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13906         TOKEN_STRING_INITIALIZER
13907                 (struct cmd_all_queues_drop_en_result,
13908                  queues, "queues");
13909 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13910         TOKEN_STRING_INITIALIZER
13911                 (struct cmd_all_queues_drop_en_result,
13912                  drop, "drop");
13913 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13914         TOKEN_NUM_INITIALIZER
13915                 (struct cmd_all_queues_drop_en_result,
13916                  port_id, UINT16);
13917 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13918         TOKEN_STRING_INITIALIZER
13919                 (struct cmd_all_queues_drop_en_result,
13920                  on_off, "on#off");
13921
13922 static void
13923 cmd_set_all_queues_drop_en_parsed(
13924         void *parsed_result,
13925         __rte_unused struct cmdline *cl,
13926         __rte_unused void *data)
13927 {
13928         struct cmd_all_queues_drop_en_result *res = parsed_result;
13929         int ret = -ENOTSUP;
13930         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13931
13932         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13933                 return;
13934
13935 #ifdef RTE_NET_IXGBE
13936         if (ret == -ENOTSUP)
13937                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13938 #endif
13939 #ifdef RTE_NET_BNXT
13940         if (ret == -ENOTSUP)
13941                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13942 #endif
13943         switch (ret) {
13944         case 0:
13945                 break;
13946         case -EINVAL:
13947                 printf("invalid is_on %d\n", is_on);
13948                 break;
13949         case -ENODEV:
13950                 printf("invalid port_id %d\n", res->port_id);
13951                 break;
13952         case -ENOTSUP:
13953                 printf("function not implemented\n");
13954                 break;
13955         default:
13956                 printf("programming error: (%s)\n", strerror(-ret));
13957         }
13958 }
13959
13960 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13961         .f = cmd_set_all_queues_drop_en_parsed,
13962         .data = NULL,
13963         .help_str = "set all queues drop <port_id> on|off",
13964         .tokens = {
13965                 (void *)&cmd_all_queues_drop_en_set,
13966                 (void *)&cmd_all_queues_drop_en_all,
13967                 (void *)&cmd_all_queues_drop_en_queues,
13968                 (void *)&cmd_all_queues_drop_en_drop,
13969                 (void *)&cmd_all_queues_drop_en_port_id,
13970                 (void *)&cmd_all_queues_drop_en_on_off,
13971                 NULL,
13972         },
13973 };
13974
13975 /* vf split drop enable configuration */
13976
13977 /* Common result structure for vf split drop enable */
13978 struct cmd_vf_split_drop_en_result {
13979         cmdline_fixed_string_t set;
13980         cmdline_fixed_string_t vf;
13981         cmdline_fixed_string_t split;
13982         cmdline_fixed_string_t drop;
13983         portid_t port_id;
13984         uint16_t vf_id;
13985         cmdline_fixed_string_t on_off;
13986 };
13987
13988 /* Common CLI fields for vf split drop enable disable */
13989 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
13990         TOKEN_STRING_INITIALIZER
13991                 (struct cmd_vf_split_drop_en_result,
13992                  set, "set");
13993 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
13994         TOKEN_STRING_INITIALIZER
13995                 (struct cmd_vf_split_drop_en_result,
13996                  vf, "vf");
13997 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
13998         TOKEN_STRING_INITIALIZER
13999                 (struct cmd_vf_split_drop_en_result,
14000                  split, "split");
14001 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14002         TOKEN_STRING_INITIALIZER
14003                 (struct cmd_vf_split_drop_en_result,
14004                  drop, "drop");
14005 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14006         TOKEN_NUM_INITIALIZER
14007                 (struct cmd_vf_split_drop_en_result,
14008                  port_id, UINT16);
14009 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14010         TOKEN_NUM_INITIALIZER
14011                 (struct cmd_vf_split_drop_en_result,
14012                  vf_id, UINT16);
14013 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14014         TOKEN_STRING_INITIALIZER
14015                 (struct cmd_vf_split_drop_en_result,
14016                  on_off, "on#off");
14017
14018 static void
14019 cmd_set_vf_split_drop_en_parsed(
14020         void *parsed_result,
14021         __rte_unused struct cmdline *cl,
14022         __rte_unused void *data)
14023 {
14024         struct cmd_vf_split_drop_en_result *res = parsed_result;
14025         int ret = -ENOTSUP;
14026         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14027
14028         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14029                 return;
14030
14031 #ifdef RTE_NET_IXGBE
14032         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14033                         is_on);
14034 #endif
14035         switch (ret) {
14036         case 0:
14037                 break;
14038         case -EINVAL:
14039                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14040                 break;
14041         case -ENODEV:
14042                 printf("invalid port_id %d\n", res->port_id);
14043                 break;
14044         case -ENOTSUP:
14045                 printf("not supported on port %d\n", res->port_id);
14046                 break;
14047         default:
14048                 printf("programming error: (%s)\n", strerror(-ret));
14049         }
14050 }
14051
14052 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14053         .f = cmd_set_vf_split_drop_en_parsed,
14054         .data = NULL,
14055         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14056         .tokens = {
14057                 (void *)&cmd_vf_split_drop_en_set,
14058                 (void *)&cmd_vf_split_drop_en_vf,
14059                 (void *)&cmd_vf_split_drop_en_split,
14060                 (void *)&cmd_vf_split_drop_en_drop,
14061                 (void *)&cmd_vf_split_drop_en_port_id,
14062                 (void *)&cmd_vf_split_drop_en_vf_id,
14063                 (void *)&cmd_vf_split_drop_en_on_off,
14064                 NULL,
14065         },
14066 };
14067
14068 /* vf mac address configuration */
14069
14070 /* Common result structure for vf mac address */
14071 struct cmd_set_vf_mac_addr_result {
14072         cmdline_fixed_string_t set;
14073         cmdline_fixed_string_t vf;
14074         cmdline_fixed_string_t mac;
14075         cmdline_fixed_string_t addr;
14076         portid_t port_id;
14077         uint16_t vf_id;
14078         struct rte_ether_addr mac_addr;
14079
14080 };
14081
14082 /* Common CLI fields for vf split drop enable disable */
14083 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14084         TOKEN_STRING_INITIALIZER
14085                 (struct cmd_set_vf_mac_addr_result,
14086                  set, "set");
14087 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14088         TOKEN_STRING_INITIALIZER
14089                 (struct cmd_set_vf_mac_addr_result,
14090                  vf, "vf");
14091 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14092         TOKEN_STRING_INITIALIZER
14093                 (struct cmd_set_vf_mac_addr_result,
14094                  mac, "mac");
14095 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14096         TOKEN_STRING_INITIALIZER
14097                 (struct cmd_set_vf_mac_addr_result,
14098                  addr, "addr");
14099 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14100         TOKEN_NUM_INITIALIZER
14101                 (struct cmd_set_vf_mac_addr_result,
14102                  port_id, UINT16);
14103 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14104         TOKEN_NUM_INITIALIZER
14105                 (struct cmd_set_vf_mac_addr_result,
14106                  vf_id, UINT16);
14107 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14108         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14109                  mac_addr);
14110
14111 static void
14112 cmd_set_vf_mac_addr_parsed(
14113         void *parsed_result,
14114         __rte_unused struct cmdline *cl,
14115         __rte_unused void *data)
14116 {
14117         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14118         int ret = -ENOTSUP;
14119
14120         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14121                 return;
14122
14123 #ifdef RTE_NET_IXGBE
14124         if (ret == -ENOTSUP)
14125                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14126                                 &res->mac_addr);
14127 #endif
14128 #ifdef RTE_NET_I40E
14129         if (ret == -ENOTSUP)
14130                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14131                                 &res->mac_addr);
14132 #endif
14133 #ifdef RTE_NET_BNXT
14134         if (ret == -ENOTSUP)
14135                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14136                                 &res->mac_addr);
14137 #endif
14138
14139         switch (ret) {
14140         case 0:
14141                 break;
14142         case -EINVAL:
14143                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14144                 break;
14145         case -ENODEV:
14146                 printf("invalid port_id %d\n", res->port_id);
14147                 break;
14148         case -ENOTSUP:
14149                 printf("function not implemented\n");
14150                 break;
14151         default:
14152                 printf("programming error: (%s)\n", strerror(-ret));
14153         }
14154 }
14155
14156 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14157         .f = cmd_set_vf_mac_addr_parsed,
14158         .data = NULL,
14159         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14160         .tokens = {
14161                 (void *)&cmd_set_vf_mac_addr_set,
14162                 (void *)&cmd_set_vf_mac_addr_vf,
14163                 (void *)&cmd_set_vf_mac_addr_mac,
14164                 (void *)&cmd_set_vf_mac_addr_addr,
14165                 (void *)&cmd_set_vf_mac_addr_port_id,
14166                 (void *)&cmd_set_vf_mac_addr_vf_id,
14167                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14168                 NULL,
14169         },
14170 };
14171
14172 /* MACsec configuration */
14173
14174 /* Common result structure for MACsec offload enable */
14175 struct cmd_macsec_offload_on_result {
14176         cmdline_fixed_string_t set;
14177         cmdline_fixed_string_t macsec;
14178         cmdline_fixed_string_t offload;
14179         portid_t port_id;
14180         cmdline_fixed_string_t on;
14181         cmdline_fixed_string_t encrypt;
14182         cmdline_fixed_string_t en_on_off;
14183         cmdline_fixed_string_t replay_protect;
14184         cmdline_fixed_string_t rp_on_off;
14185 };
14186
14187 /* Common CLI fields for MACsec offload disable */
14188 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14189         TOKEN_STRING_INITIALIZER
14190                 (struct cmd_macsec_offload_on_result,
14191                  set, "set");
14192 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14193         TOKEN_STRING_INITIALIZER
14194                 (struct cmd_macsec_offload_on_result,
14195                  macsec, "macsec");
14196 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14197         TOKEN_STRING_INITIALIZER
14198                 (struct cmd_macsec_offload_on_result,
14199                  offload, "offload");
14200 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14201         TOKEN_NUM_INITIALIZER
14202                 (struct cmd_macsec_offload_on_result,
14203                  port_id, UINT16);
14204 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14205         TOKEN_STRING_INITIALIZER
14206                 (struct cmd_macsec_offload_on_result,
14207                  on, "on");
14208 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14209         TOKEN_STRING_INITIALIZER
14210                 (struct cmd_macsec_offload_on_result,
14211                  encrypt, "encrypt");
14212 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14213         TOKEN_STRING_INITIALIZER
14214                 (struct cmd_macsec_offload_on_result,
14215                  en_on_off, "on#off");
14216 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14217         TOKEN_STRING_INITIALIZER
14218                 (struct cmd_macsec_offload_on_result,
14219                  replay_protect, "replay-protect");
14220 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14221         TOKEN_STRING_INITIALIZER
14222                 (struct cmd_macsec_offload_on_result,
14223                  rp_on_off, "on#off");
14224
14225 static void
14226 cmd_set_macsec_offload_on_parsed(
14227         void *parsed_result,
14228         __rte_unused struct cmdline *cl,
14229         __rte_unused void *data)
14230 {
14231         struct cmd_macsec_offload_on_result *res = parsed_result;
14232         int ret = -ENOTSUP;
14233         portid_t port_id = res->port_id;
14234         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14235         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14236         struct rte_eth_dev_info dev_info;
14237
14238         if (port_id_is_invalid(port_id, ENABLED_WARN))
14239                 return;
14240         if (!port_is_stopped(port_id)) {
14241                 printf("Please stop port %d first\n", port_id);
14242                 return;
14243         }
14244
14245         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14246         if (ret != 0)
14247                 return;
14248
14249         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14250 #ifdef RTE_NET_IXGBE
14251                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14252 #endif
14253         }
14254         RTE_SET_USED(en);
14255         RTE_SET_USED(rp);
14256
14257         switch (ret) {
14258         case 0:
14259                 ports[port_id].dev_conf.txmode.offloads |=
14260                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14261                 cmd_reconfig_device_queue(port_id, 1, 1);
14262                 break;
14263         case -ENODEV:
14264                 printf("invalid port_id %d\n", port_id);
14265                 break;
14266         case -ENOTSUP:
14267                 printf("not supported on port %d\n", port_id);
14268                 break;
14269         default:
14270                 printf("programming error: (%s)\n", strerror(-ret));
14271         }
14272 }
14273
14274 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14275         .f = cmd_set_macsec_offload_on_parsed,
14276         .data = NULL,
14277         .help_str = "set macsec offload <port_id> on "
14278                 "encrypt on|off replay-protect on|off",
14279         .tokens = {
14280                 (void *)&cmd_macsec_offload_on_set,
14281                 (void *)&cmd_macsec_offload_on_macsec,
14282                 (void *)&cmd_macsec_offload_on_offload,
14283                 (void *)&cmd_macsec_offload_on_port_id,
14284                 (void *)&cmd_macsec_offload_on_on,
14285                 (void *)&cmd_macsec_offload_on_encrypt,
14286                 (void *)&cmd_macsec_offload_on_en_on_off,
14287                 (void *)&cmd_macsec_offload_on_replay_protect,
14288                 (void *)&cmd_macsec_offload_on_rp_on_off,
14289                 NULL,
14290         },
14291 };
14292
14293 /* Common result structure for MACsec offload disable */
14294 struct cmd_macsec_offload_off_result {
14295         cmdline_fixed_string_t set;
14296         cmdline_fixed_string_t macsec;
14297         cmdline_fixed_string_t offload;
14298         portid_t port_id;
14299         cmdline_fixed_string_t off;
14300 };
14301
14302 /* Common CLI fields for MACsec offload disable */
14303 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14304         TOKEN_STRING_INITIALIZER
14305                 (struct cmd_macsec_offload_off_result,
14306                  set, "set");
14307 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14308         TOKEN_STRING_INITIALIZER
14309                 (struct cmd_macsec_offload_off_result,
14310                  macsec, "macsec");
14311 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14312         TOKEN_STRING_INITIALIZER
14313                 (struct cmd_macsec_offload_off_result,
14314                  offload, "offload");
14315 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14316         TOKEN_NUM_INITIALIZER
14317                 (struct cmd_macsec_offload_off_result,
14318                  port_id, UINT16);
14319 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14320         TOKEN_STRING_INITIALIZER
14321                 (struct cmd_macsec_offload_off_result,
14322                  off, "off");
14323
14324 static void
14325 cmd_set_macsec_offload_off_parsed(
14326         void *parsed_result,
14327         __rte_unused struct cmdline *cl,
14328         __rte_unused void *data)
14329 {
14330         struct cmd_macsec_offload_off_result *res = parsed_result;
14331         int ret = -ENOTSUP;
14332         struct rte_eth_dev_info dev_info;
14333         portid_t port_id = res->port_id;
14334
14335         if (port_id_is_invalid(port_id, ENABLED_WARN))
14336                 return;
14337         if (!port_is_stopped(port_id)) {
14338                 printf("Please stop port %d first\n", port_id);
14339                 return;
14340         }
14341
14342         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14343         if (ret != 0)
14344                 return;
14345
14346         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14347 #ifdef RTE_NET_IXGBE
14348                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14349 #endif
14350         }
14351         switch (ret) {
14352         case 0:
14353                 ports[port_id].dev_conf.txmode.offloads &=
14354                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14355                 cmd_reconfig_device_queue(port_id, 1, 1);
14356                 break;
14357         case -ENODEV:
14358                 printf("invalid port_id %d\n", port_id);
14359                 break;
14360         case -ENOTSUP:
14361                 printf("not supported on port %d\n", port_id);
14362                 break;
14363         default:
14364                 printf("programming error: (%s)\n", strerror(-ret));
14365         }
14366 }
14367
14368 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14369         .f = cmd_set_macsec_offload_off_parsed,
14370         .data = NULL,
14371         .help_str = "set macsec offload <port_id> off",
14372         .tokens = {
14373                 (void *)&cmd_macsec_offload_off_set,
14374                 (void *)&cmd_macsec_offload_off_macsec,
14375                 (void *)&cmd_macsec_offload_off_offload,
14376                 (void *)&cmd_macsec_offload_off_port_id,
14377                 (void *)&cmd_macsec_offload_off_off,
14378                 NULL,
14379         },
14380 };
14381
14382 /* Common result structure for MACsec secure connection configure */
14383 struct cmd_macsec_sc_result {
14384         cmdline_fixed_string_t set;
14385         cmdline_fixed_string_t macsec;
14386         cmdline_fixed_string_t sc;
14387         cmdline_fixed_string_t tx_rx;
14388         portid_t port_id;
14389         struct rte_ether_addr mac;
14390         uint16_t pi;
14391 };
14392
14393 /* Common CLI fields for MACsec secure connection configure */
14394 cmdline_parse_token_string_t cmd_macsec_sc_set =
14395         TOKEN_STRING_INITIALIZER
14396                 (struct cmd_macsec_sc_result,
14397                  set, "set");
14398 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14399         TOKEN_STRING_INITIALIZER
14400                 (struct cmd_macsec_sc_result,
14401                  macsec, "macsec");
14402 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14403         TOKEN_STRING_INITIALIZER
14404                 (struct cmd_macsec_sc_result,
14405                  sc, "sc");
14406 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14407         TOKEN_STRING_INITIALIZER
14408                 (struct cmd_macsec_sc_result,
14409                  tx_rx, "tx#rx");
14410 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14411         TOKEN_NUM_INITIALIZER
14412                 (struct cmd_macsec_sc_result,
14413                  port_id, UINT16);
14414 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14415         TOKEN_ETHERADDR_INITIALIZER
14416                 (struct cmd_macsec_sc_result,
14417                  mac);
14418 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14419         TOKEN_NUM_INITIALIZER
14420                 (struct cmd_macsec_sc_result,
14421                  pi, UINT16);
14422
14423 static void
14424 cmd_set_macsec_sc_parsed(
14425         void *parsed_result,
14426         __rte_unused struct cmdline *cl,
14427         __rte_unused void *data)
14428 {
14429         struct cmd_macsec_sc_result *res = parsed_result;
14430         int ret = -ENOTSUP;
14431         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14432
14433 #ifdef RTE_NET_IXGBE
14434         ret = is_tx ?
14435                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14436                                 res->mac.addr_bytes) :
14437                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14438                                 res->mac.addr_bytes, res->pi);
14439 #endif
14440         RTE_SET_USED(is_tx);
14441
14442         switch (ret) {
14443         case 0:
14444                 break;
14445         case -ENODEV:
14446                 printf("invalid port_id %d\n", res->port_id);
14447                 break;
14448         case -ENOTSUP:
14449                 printf("not supported on port %d\n", res->port_id);
14450                 break;
14451         default:
14452                 printf("programming error: (%s)\n", strerror(-ret));
14453         }
14454 }
14455
14456 cmdline_parse_inst_t cmd_set_macsec_sc = {
14457         .f = cmd_set_macsec_sc_parsed,
14458         .data = NULL,
14459         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14460         .tokens = {
14461                 (void *)&cmd_macsec_sc_set,
14462                 (void *)&cmd_macsec_sc_macsec,
14463                 (void *)&cmd_macsec_sc_sc,
14464                 (void *)&cmd_macsec_sc_tx_rx,
14465                 (void *)&cmd_macsec_sc_port_id,
14466                 (void *)&cmd_macsec_sc_mac,
14467                 (void *)&cmd_macsec_sc_pi,
14468                 NULL,
14469         },
14470 };
14471
14472 /* Common result structure for MACsec secure connection configure */
14473 struct cmd_macsec_sa_result {
14474         cmdline_fixed_string_t set;
14475         cmdline_fixed_string_t macsec;
14476         cmdline_fixed_string_t sa;
14477         cmdline_fixed_string_t tx_rx;
14478         portid_t port_id;
14479         uint8_t idx;
14480         uint8_t an;
14481         uint32_t pn;
14482         cmdline_fixed_string_t key;
14483 };
14484
14485 /* Common CLI fields for MACsec secure connection configure */
14486 cmdline_parse_token_string_t cmd_macsec_sa_set =
14487         TOKEN_STRING_INITIALIZER
14488                 (struct cmd_macsec_sa_result,
14489                  set, "set");
14490 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14491         TOKEN_STRING_INITIALIZER
14492                 (struct cmd_macsec_sa_result,
14493                  macsec, "macsec");
14494 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14495         TOKEN_STRING_INITIALIZER
14496                 (struct cmd_macsec_sa_result,
14497                  sa, "sa");
14498 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14499         TOKEN_STRING_INITIALIZER
14500                 (struct cmd_macsec_sa_result,
14501                  tx_rx, "tx#rx");
14502 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14503         TOKEN_NUM_INITIALIZER
14504                 (struct cmd_macsec_sa_result,
14505                  port_id, UINT16);
14506 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14507         TOKEN_NUM_INITIALIZER
14508                 (struct cmd_macsec_sa_result,
14509                  idx, UINT8);
14510 cmdline_parse_token_num_t cmd_macsec_sa_an =
14511         TOKEN_NUM_INITIALIZER
14512                 (struct cmd_macsec_sa_result,
14513                  an, UINT8);
14514 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14515         TOKEN_NUM_INITIALIZER
14516                 (struct cmd_macsec_sa_result,
14517                  pn, UINT32);
14518 cmdline_parse_token_string_t cmd_macsec_sa_key =
14519         TOKEN_STRING_INITIALIZER
14520                 (struct cmd_macsec_sa_result,
14521                  key, NULL);
14522
14523 static void
14524 cmd_set_macsec_sa_parsed(
14525         void *parsed_result,
14526         __rte_unused struct cmdline *cl,
14527         __rte_unused void *data)
14528 {
14529         struct cmd_macsec_sa_result *res = parsed_result;
14530         int ret = -ENOTSUP;
14531         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14532         uint8_t key[16] = { 0 };
14533         uint8_t xdgt0;
14534         uint8_t xdgt1;
14535         int key_len;
14536         int i;
14537
14538         key_len = strlen(res->key) / 2;
14539         if (key_len > 16)
14540                 key_len = 16;
14541
14542         for (i = 0; i < key_len; i++) {
14543                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14544                 if (xdgt0 == 0xFF)
14545                         return;
14546                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14547                 if (xdgt1 == 0xFF)
14548                         return;
14549                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14550         }
14551
14552 #ifdef RTE_NET_IXGBE
14553         ret = is_tx ?
14554                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14555                         res->idx, res->an, res->pn, key) :
14556                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14557                         res->idx, res->an, res->pn, key);
14558 #endif
14559         RTE_SET_USED(is_tx);
14560         RTE_SET_USED(key);
14561
14562         switch (ret) {
14563         case 0:
14564                 break;
14565         case -EINVAL:
14566                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14567                 break;
14568         case -ENODEV:
14569                 printf("invalid port_id %d\n", res->port_id);
14570                 break;
14571         case -ENOTSUP:
14572                 printf("not supported on port %d\n", res->port_id);
14573                 break;
14574         default:
14575                 printf("programming error: (%s)\n", strerror(-ret));
14576         }
14577 }
14578
14579 cmdline_parse_inst_t cmd_set_macsec_sa = {
14580         .f = cmd_set_macsec_sa_parsed,
14581         .data = NULL,
14582         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14583         .tokens = {
14584                 (void *)&cmd_macsec_sa_set,
14585                 (void *)&cmd_macsec_sa_macsec,
14586                 (void *)&cmd_macsec_sa_sa,
14587                 (void *)&cmd_macsec_sa_tx_rx,
14588                 (void *)&cmd_macsec_sa_port_id,
14589                 (void *)&cmd_macsec_sa_idx,
14590                 (void *)&cmd_macsec_sa_an,
14591                 (void *)&cmd_macsec_sa_pn,
14592                 (void *)&cmd_macsec_sa_key,
14593                 NULL,
14594         },
14595 };
14596
14597 /* VF unicast promiscuous mode configuration */
14598
14599 /* Common result structure for VF unicast promiscuous mode */
14600 struct cmd_vf_promisc_result {
14601         cmdline_fixed_string_t set;
14602         cmdline_fixed_string_t vf;
14603         cmdline_fixed_string_t promisc;
14604         portid_t port_id;
14605         uint32_t vf_id;
14606         cmdline_fixed_string_t on_off;
14607 };
14608
14609 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14610 cmdline_parse_token_string_t cmd_vf_promisc_set =
14611         TOKEN_STRING_INITIALIZER
14612                 (struct cmd_vf_promisc_result,
14613                  set, "set");
14614 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14615         TOKEN_STRING_INITIALIZER
14616                 (struct cmd_vf_promisc_result,
14617                  vf, "vf");
14618 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14619         TOKEN_STRING_INITIALIZER
14620                 (struct cmd_vf_promisc_result,
14621                  promisc, "promisc");
14622 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14623         TOKEN_NUM_INITIALIZER
14624                 (struct cmd_vf_promisc_result,
14625                  port_id, UINT16);
14626 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14627         TOKEN_NUM_INITIALIZER
14628                 (struct cmd_vf_promisc_result,
14629                  vf_id, UINT32);
14630 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14631         TOKEN_STRING_INITIALIZER
14632                 (struct cmd_vf_promisc_result,
14633                  on_off, "on#off");
14634
14635 static void
14636 cmd_set_vf_promisc_parsed(
14637         void *parsed_result,
14638         __rte_unused struct cmdline *cl,
14639         __rte_unused void *data)
14640 {
14641         struct cmd_vf_promisc_result *res = parsed_result;
14642         int ret = -ENOTSUP;
14643
14644         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14645
14646         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14647                 return;
14648
14649 #ifdef RTE_NET_I40E
14650         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14651                                                   res->vf_id, is_on);
14652 #endif
14653
14654         switch (ret) {
14655         case 0:
14656                 break;
14657         case -EINVAL:
14658                 printf("invalid vf_id %d\n", res->vf_id);
14659                 break;
14660         case -ENODEV:
14661                 printf("invalid port_id %d\n", res->port_id);
14662                 break;
14663         case -ENOTSUP:
14664                 printf("function not implemented\n");
14665                 break;
14666         default:
14667                 printf("programming error: (%s)\n", strerror(-ret));
14668         }
14669 }
14670
14671 cmdline_parse_inst_t cmd_set_vf_promisc = {
14672         .f = cmd_set_vf_promisc_parsed,
14673         .data = NULL,
14674         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14675                 "Set unicast promiscuous mode for a VF from the PF",
14676         .tokens = {
14677                 (void *)&cmd_vf_promisc_set,
14678                 (void *)&cmd_vf_promisc_vf,
14679                 (void *)&cmd_vf_promisc_promisc,
14680                 (void *)&cmd_vf_promisc_port_id,
14681                 (void *)&cmd_vf_promisc_vf_id,
14682                 (void *)&cmd_vf_promisc_on_off,
14683                 NULL,
14684         },
14685 };
14686
14687 /* VF multicast promiscuous mode configuration */
14688
14689 /* Common result structure for VF multicast promiscuous mode */
14690 struct cmd_vf_allmulti_result {
14691         cmdline_fixed_string_t set;
14692         cmdline_fixed_string_t vf;
14693         cmdline_fixed_string_t allmulti;
14694         portid_t port_id;
14695         uint32_t vf_id;
14696         cmdline_fixed_string_t on_off;
14697 };
14698
14699 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14700 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14701         TOKEN_STRING_INITIALIZER
14702                 (struct cmd_vf_allmulti_result,
14703                  set, "set");
14704 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14705         TOKEN_STRING_INITIALIZER
14706                 (struct cmd_vf_allmulti_result,
14707                  vf, "vf");
14708 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14709         TOKEN_STRING_INITIALIZER
14710                 (struct cmd_vf_allmulti_result,
14711                  allmulti, "allmulti");
14712 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14713         TOKEN_NUM_INITIALIZER
14714                 (struct cmd_vf_allmulti_result,
14715                  port_id, UINT16);
14716 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14717         TOKEN_NUM_INITIALIZER
14718                 (struct cmd_vf_allmulti_result,
14719                  vf_id, UINT32);
14720 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14721         TOKEN_STRING_INITIALIZER
14722                 (struct cmd_vf_allmulti_result,
14723                  on_off, "on#off");
14724
14725 static void
14726 cmd_set_vf_allmulti_parsed(
14727         void *parsed_result,
14728         __rte_unused struct cmdline *cl,
14729         __rte_unused void *data)
14730 {
14731         struct cmd_vf_allmulti_result *res = parsed_result;
14732         int ret = -ENOTSUP;
14733
14734         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14735
14736         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14737                 return;
14738
14739 #ifdef RTE_NET_I40E
14740         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14741                                                     res->vf_id, is_on);
14742 #endif
14743
14744         switch (ret) {
14745         case 0:
14746                 break;
14747         case -EINVAL:
14748                 printf("invalid vf_id %d\n", res->vf_id);
14749                 break;
14750         case -ENODEV:
14751                 printf("invalid port_id %d\n", res->port_id);
14752                 break;
14753         case -ENOTSUP:
14754                 printf("function not implemented\n");
14755                 break;
14756         default:
14757                 printf("programming error: (%s)\n", strerror(-ret));
14758         }
14759 }
14760
14761 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14762         .f = cmd_set_vf_allmulti_parsed,
14763         .data = NULL,
14764         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14765                 "Set multicast promiscuous mode for a VF from the PF",
14766         .tokens = {
14767                 (void *)&cmd_vf_allmulti_set,
14768                 (void *)&cmd_vf_allmulti_vf,
14769                 (void *)&cmd_vf_allmulti_allmulti,
14770                 (void *)&cmd_vf_allmulti_port_id,
14771                 (void *)&cmd_vf_allmulti_vf_id,
14772                 (void *)&cmd_vf_allmulti_on_off,
14773                 NULL,
14774         },
14775 };
14776
14777 /* vf broadcast mode configuration */
14778
14779 /* Common result structure for vf broadcast */
14780 struct cmd_set_vf_broadcast_result {
14781         cmdline_fixed_string_t set;
14782         cmdline_fixed_string_t vf;
14783         cmdline_fixed_string_t broadcast;
14784         portid_t port_id;
14785         uint16_t vf_id;
14786         cmdline_fixed_string_t on_off;
14787 };
14788
14789 /* Common CLI fields for vf broadcast enable disable */
14790 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14791         TOKEN_STRING_INITIALIZER
14792                 (struct cmd_set_vf_broadcast_result,
14793                  set, "set");
14794 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14795         TOKEN_STRING_INITIALIZER
14796                 (struct cmd_set_vf_broadcast_result,
14797                  vf, "vf");
14798 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14799         TOKEN_STRING_INITIALIZER
14800                 (struct cmd_set_vf_broadcast_result,
14801                  broadcast, "broadcast");
14802 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14803         TOKEN_NUM_INITIALIZER
14804                 (struct cmd_set_vf_broadcast_result,
14805                  port_id, UINT16);
14806 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14807         TOKEN_NUM_INITIALIZER
14808                 (struct cmd_set_vf_broadcast_result,
14809                  vf_id, UINT16);
14810 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14811         TOKEN_STRING_INITIALIZER
14812                 (struct cmd_set_vf_broadcast_result,
14813                  on_off, "on#off");
14814
14815 static void
14816 cmd_set_vf_broadcast_parsed(
14817         void *parsed_result,
14818         __rte_unused struct cmdline *cl,
14819         __rte_unused void *data)
14820 {
14821         struct cmd_set_vf_broadcast_result *res = parsed_result;
14822         int ret = -ENOTSUP;
14823
14824         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14825
14826         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14827                 return;
14828
14829 #ifdef RTE_NET_I40E
14830         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14831                                             res->vf_id, is_on);
14832 #endif
14833
14834         switch (ret) {
14835         case 0:
14836                 break;
14837         case -EINVAL:
14838                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14839                 break;
14840         case -ENODEV:
14841                 printf("invalid port_id %d\n", res->port_id);
14842                 break;
14843         case -ENOTSUP:
14844                 printf("function not implemented\n");
14845                 break;
14846         default:
14847                 printf("programming error: (%s)\n", strerror(-ret));
14848         }
14849 }
14850
14851 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14852         .f = cmd_set_vf_broadcast_parsed,
14853         .data = NULL,
14854         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14855         .tokens = {
14856                 (void *)&cmd_set_vf_broadcast_set,
14857                 (void *)&cmd_set_vf_broadcast_vf,
14858                 (void *)&cmd_set_vf_broadcast_broadcast,
14859                 (void *)&cmd_set_vf_broadcast_port_id,
14860                 (void *)&cmd_set_vf_broadcast_vf_id,
14861                 (void *)&cmd_set_vf_broadcast_on_off,
14862                 NULL,
14863         },
14864 };
14865
14866 /* vf vlan tag configuration */
14867
14868 /* Common result structure for vf vlan tag */
14869 struct cmd_set_vf_vlan_tag_result {
14870         cmdline_fixed_string_t set;
14871         cmdline_fixed_string_t vf;
14872         cmdline_fixed_string_t vlan;
14873         cmdline_fixed_string_t tag;
14874         portid_t port_id;
14875         uint16_t vf_id;
14876         cmdline_fixed_string_t on_off;
14877 };
14878
14879 /* Common CLI fields for vf vlan tag enable disable */
14880 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14881         TOKEN_STRING_INITIALIZER
14882                 (struct cmd_set_vf_vlan_tag_result,
14883                  set, "set");
14884 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14885         TOKEN_STRING_INITIALIZER
14886                 (struct cmd_set_vf_vlan_tag_result,
14887                  vf, "vf");
14888 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14889         TOKEN_STRING_INITIALIZER
14890                 (struct cmd_set_vf_vlan_tag_result,
14891                  vlan, "vlan");
14892 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14893         TOKEN_STRING_INITIALIZER
14894                 (struct cmd_set_vf_vlan_tag_result,
14895                  tag, "tag");
14896 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14897         TOKEN_NUM_INITIALIZER
14898                 (struct cmd_set_vf_vlan_tag_result,
14899                  port_id, UINT16);
14900 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14901         TOKEN_NUM_INITIALIZER
14902                 (struct cmd_set_vf_vlan_tag_result,
14903                  vf_id, UINT16);
14904 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14905         TOKEN_STRING_INITIALIZER
14906                 (struct cmd_set_vf_vlan_tag_result,
14907                  on_off, "on#off");
14908
14909 static void
14910 cmd_set_vf_vlan_tag_parsed(
14911         void *parsed_result,
14912         __rte_unused struct cmdline *cl,
14913         __rte_unused void *data)
14914 {
14915         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14916         int ret = -ENOTSUP;
14917
14918         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14919
14920         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14921                 return;
14922
14923 #ifdef RTE_NET_I40E
14924         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14925                                            res->vf_id, is_on);
14926 #endif
14927
14928         switch (ret) {
14929         case 0:
14930                 break;
14931         case -EINVAL:
14932                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14933                 break;
14934         case -ENODEV:
14935                 printf("invalid port_id %d\n", res->port_id);
14936                 break;
14937         case -ENOTSUP:
14938                 printf("function not implemented\n");
14939                 break;
14940         default:
14941                 printf("programming error: (%s)\n", strerror(-ret));
14942         }
14943 }
14944
14945 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14946         .f = cmd_set_vf_vlan_tag_parsed,
14947         .data = NULL,
14948         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14949         .tokens = {
14950                 (void *)&cmd_set_vf_vlan_tag_set,
14951                 (void *)&cmd_set_vf_vlan_tag_vf,
14952                 (void *)&cmd_set_vf_vlan_tag_vlan,
14953                 (void *)&cmd_set_vf_vlan_tag_tag,
14954                 (void *)&cmd_set_vf_vlan_tag_port_id,
14955                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14956                 (void *)&cmd_set_vf_vlan_tag_on_off,
14957                 NULL,
14958         },
14959 };
14960
14961 /* Common definition of VF and TC TX bandwidth configuration */
14962 struct cmd_vf_tc_bw_result {
14963         cmdline_fixed_string_t set;
14964         cmdline_fixed_string_t vf;
14965         cmdline_fixed_string_t tc;
14966         cmdline_fixed_string_t tx;
14967         cmdline_fixed_string_t min_bw;
14968         cmdline_fixed_string_t max_bw;
14969         cmdline_fixed_string_t strict_link_prio;
14970         portid_t port_id;
14971         uint16_t vf_id;
14972         uint8_t tc_no;
14973         uint32_t bw;
14974         cmdline_fixed_string_t bw_list;
14975         uint8_t tc_map;
14976 };
14977
14978 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
14979         TOKEN_STRING_INITIALIZER
14980                 (struct cmd_vf_tc_bw_result,
14981                  set, "set");
14982 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
14983         TOKEN_STRING_INITIALIZER
14984                 (struct cmd_vf_tc_bw_result,
14985                  vf, "vf");
14986 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
14987         TOKEN_STRING_INITIALIZER
14988                 (struct cmd_vf_tc_bw_result,
14989                  tc, "tc");
14990 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
14991         TOKEN_STRING_INITIALIZER
14992                 (struct cmd_vf_tc_bw_result,
14993                  tx, "tx");
14994 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
14995         TOKEN_STRING_INITIALIZER
14996                 (struct cmd_vf_tc_bw_result,
14997                  strict_link_prio, "strict-link-priority");
14998 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
14999         TOKEN_STRING_INITIALIZER
15000                 (struct cmd_vf_tc_bw_result,
15001                  min_bw, "min-bandwidth");
15002 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15003         TOKEN_STRING_INITIALIZER
15004                 (struct cmd_vf_tc_bw_result,
15005                  max_bw, "max-bandwidth");
15006 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15007         TOKEN_NUM_INITIALIZER
15008                 (struct cmd_vf_tc_bw_result,
15009                  port_id, UINT16);
15010 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15011         TOKEN_NUM_INITIALIZER
15012                 (struct cmd_vf_tc_bw_result,
15013                  vf_id, UINT16);
15014 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15015         TOKEN_NUM_INITIALIZER
15016                 (struct cmd_vf_tc_bw_result,
15017                  tc_no, UINT8);
15018 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15019         TOKEN_NUM_INITIALIZER
15020                 (struct cmd_vf_tc_bw_result,
15021                  bw, UINT32);
15022 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15023         TOKEN_STRING_INITIALIZER
15024                 (struct cmd_vf_tc_bw_result,
15025                  bw_list, NULL);
15026 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15027         TOKEN_NUM_INITIALIZER
15028                 (struct cmd_vf_tc_bw_result,
15029                  tc_map, UINT8);
15030
15031 /* VF max bandwidth setting */
15032 static void
15033 cmd_vf_max_bw_parsed(
15034         void *parsed_result,
15035         __rte_unused struct cmdline *cl,
15036         __rte_unused void *data)
15037 {
15038         struct cmd_vf_tc_bw_result *res = parsed_result;
15039         int ret = -ENOTSUP;
15040
15041         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15042                 return;
15043
15044 #ifdef RTE_NET_I40E
15045         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15046                                          res->vf_id, res->bw);
15047 #endif
15048
15049         switch (ret) {
15050         case 0:
15051                 break;
15052         case -EINVAL:
15053                 printf("invalid vf_id %d or bandwidth %d\n",
15054                        res->vf_id, res->bw);
15055                 break;
15056         case -ENODEV:
15057                 printf("invalid port_id %d\n", res->port_id);
15058                 break;
15059         case -ENOTSUP:
15060                 printf("function not implemented\n");
15061                 break;
15062         default:
15063                 printf("programming error: (%s)\n", strerror(-ret));
15064         }
15065 }
15066
15067 cmdline_parse_inst_t cmd_vf_max_bw = {
15068         .f = cmd_vf_max_bw_parsed,
15069         .data = NULL,
15070         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15071         .tokens = {
15072                 (void *)&cmd_vf_tc_bw_set,
15073                 (void *)&cmd_vf_tc_bw_vf,
15074                 (void *)&cmd_vf_tc_bw_tx,
15075                 (void *)&cmd_vf_tc_bw_max_bw,
15076                 (void *)&cmd_vf_tc_bw_port_id,
15077                 (void *)&cmd_vf_tc_bw_vf_id,
15078                 (void *)&cmd_vf_tc_bw_bw,
15079                 NULL,
15080         },
15081 };
15082
15083 static int
15084 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15085                            uint8_t *tc_num,
15086                            char *str)
15087 {
15088         uint32_t size;
15089         const char *p, *p0 = str;
15090         char s[256];
15091         char *end;
15092         char *str_fld[16];
15093         uint16_t i;
15094         int ret;
15095
15096         p = strchr(p0, '(');
15097         if (p == NULL) {
15098                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15099                 return -1;
15100         }
15101         p++;
15102         p0 = strchr(p, ')');
15103         if (p0 == NULL) {
15104                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15105                 return -1;
15106         }
15107         size = p0 - p;
15108         if (size >= sizeof(s)) {
15109                 printf("The string size exceeds the internal buffer size\n");
15110                 return -1;
15111         }
15112         snprintf(s, sizeof(s), "%.*s", size, p);
15113         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15114         if (ret <= 0) {
15115                 printf("Failed to get the bandwidth list. ");
15116                 return -1;
15117         }
15118         *tc_num = ret;
15119         for (i = 0; i < ret; i++)
15120                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15121
15122         return 0;
15123 }
15124
15125 /* TC min bandwidth setting */
15126 static void
15127 cmd_vf_tc_min_bw_parsed(
15128         void *parsed_result,
15129         __rte_unused struct cmdline *cl,
15130         __rte_unused void *data)
15131 {
15132         struct cmd_vf_tc_bw_result *res = parsed_result;
15133         uint8_t tc_num;
15134         uint8_t bw[16];
15135         int ret = -ENOTSUP;
15136
15137         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15138                 return;
15139
15140         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15141         if (ret)
15142                 return;
15143
15144 #ifdef RTE_NET_I40E
15145         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15146                                               tc_num, bw);
15147 #endif
15148
15149         switch (ret) {
15150         case 0:
15151                 break;
15152         case -EINVAL:
15153                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15154                 break;
15155         case -ENODEV:
15156                 printf("invalid port_id %d\n", res->port_id);
15157                 break;
15158         case -ENOTSUP:
15159                 printf("function not implemented\n");
15160                 break;
15161         default:
15162                 printf("programming error: (%s)\n", strerror(-ret));
15163         }
15164 }
15165
15166 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15167         .f = cmd_vf_tc_min_bw_parsed,
15168         .data = NULL,
15169         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15170                     " <bw1, bw2, ...>",
15171         .tokens = {
15172                 (void *)&cmd_vf_tc_bw_set,
15173                 (void *)&cmd_vf_tc_bw_vf,
15174                 (void *)&cmd_vf_tc_bw_tc,
15175                 (void *)&cmd_vf_tc_bw_tx,
15176                 (void *)&cmd_vf_tc_bw_min_bw,
15177                 (void *)&cmd_vf_tc_bw_port_id,
15178                 (void *)&cmd_vf_tc_bw_vf_id,
15179                 (void *)&cmd_vf_tc_bw_bw_list,
15180                 NULL,
15181         },
15182 };
15183
15184 static void
15185 cmd_tc_min_bw_parsed(
15186         void *parsed_result,
15187         __rte_unused struct cmdline *cl,
15188         __rte_unused void *data)
15189 {
15190         struct cmd_vf_tc_bw_result *res = parsed_result;
15191         struct rte_port *port;
15192         uint8_t tc_num;
15193         uint8_t bw[16];
15194         int ret = -ENOTSUP;
15195
15196         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15197                 return;
15198
15199         port = &ports[res->port_id];
15200         /** Check if the port is not started **/
15201         if (port->port_status != RTE_PORT_STOPPED) {
15202                 printf("Please stop port %d first\n", res->port_id);
15203                 return;
15204         }
15205
15206         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15207         if (ret)
15208                 return;
15209
15210 #ifdef RTE_NET_IXGBE
15211         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15212 #endif
15213
15214         switch (ret) {
15215         case 0:
15216                 break;
15217         case -EINVAL:
15218                 printf("invalid bandwidth\n");
15219                 break;
15220         case -ENODEV:
15221                 printf("invalid port_id %d\n", res->port_id);
15222                 break;
15223         case -ENOTSUP:
15224                 printf("function not implemented\n");
15225                 break;
15226         default:
15227                 printf("programming error: (%s)\n", strerror(-ret));
15228         }
15229 }
15230
15231 cmdline_parse_inst_t cmd_tc_min_bw = {
15232         .f = cmd_tc_min_bw_parsed,
15233         .data = NULL,
15234         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15235         .tokens = {
15236                 (void *)&cmd_vf_tc_bw_set,
15237                 (void *)&cmd_vf_tc_bw_tc,
15238                 (void *)&cmd_vf_tc_bw_tx,
15239                 (void *)&cmd_vf_tc_bw_min_bw,
15240                 (void *)&cmd_vf_tc_bw_port_id,
15241                 (void *)&cmd_vf_tc_bw_bw_list,
15242                 NULL,
15243         },
15244 };
15245
15246 /* TC max bandwidth setting */
15247 static void
15248 cmd_vf_tc_max_bw_parsed(
15249         void *parsed_result,
15250         __rte_unused struct cmdline *cl,
15251         __rte_unused void *data)
15252 {
15253         struct cmd_vf_tc_bw_result *res = parsed_result;
15254         int ret = -ENOTSUP;
15255
15256         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15257                 return;
15258
15259 #ifdef RTE_NET_I40E
15260         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15261                                             res->tc_no, res->bw);
15262 #endif
15263
15264         switch (ret) {
15265         case 0:
15266                 break;
15267         case -EINVAL:
15268                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15269                        res->vf_id, res->tc_no, res->bw);
15270                 break;
15271         case -ENODEV:
15272                 printf("invalid port_id %d\n", res->port_id);
15273                 break;
15274         case -ENOTSUP:
15275                 printf("function not implemented\n");
15276                 break;
15277         default:
15278                 printf("programming error: (%s)\n", strerror(-ret));
15279         }
15280 }
15281
15282 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15283         .f = cmd_vf_tc_max_bw_parsed,
15284         .data = NULL,
15285         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15286                     " <bandwidth>",
15287         .tokens = {
15288                 (void *)&cmd_vf_tc_bw_set,
15289                 (void *)&cmd_vf_tc_bw_vf,
15290                 (void *)&cmd_vf_tc_bw_tc,
15291                 (void *)&cmd_vf_tc_bw_tx,
15292                 (void *)&cmd_vf_tc_bw_max_bw,
15293                 (void *)&cmd_vf_tc_bw_port_id,
15294                 (void *)&cmd_vf_tc_bw_vf_id,
15295                 (void *)&cmd_vf_tc_bw_tc_no,
15296                 (void *)&cmd_vf_tc_bw_bw,
15297                 NULL,
15298         },
15299 };
15300
15301 /** Set VXLAN encapsulation details */
15302 struct cmd_set_vxlan_result {
15303         cmdline_fixed_string_t set;
15304         cmdline_fixed_string_t vxlan;
15305         cmdline_fixed_string_t pos_token;
15306         cmdline_fixed_string_t ip_version;
15307         uint32_t vlan_present:1;
15308         uint32_t vni;
15309         uint16_t udp_src;
15310         uint16_t udp_dst;
15311         cmdline_ipaddr_t ip_src;
15312         cmdline_ipaddr_t ip_dst;
15313         uint16_t tci;
15314         uint8_t tos;
15315         uint8_t ttl;
15316         struct rte_ether_addr eth_src;
15317         struct rte_ether_addr eth_dst;
15318 };
15319
15320 cmdline_parse_token_string_t cmd_set_vxlan_set =
15321         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15322 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15323         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15324 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15325         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15326                                  "vxlan-tos-ttl");
15327 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15328         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15329                                  "vxlan-with-vlan");
15330 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15331         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15332                                  "ip-version");
15333 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15334         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15335                                  "ipv4#ipv6");
15336 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15337         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15338                                  "vni");
15339 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15340         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15341 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15342         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15343                                  "udp-src");
15344 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15345         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15346 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15347         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15348                                  "udp-dst");
15349 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15350         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15351 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15352         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15353                                  "ip-tos");
15354 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15355         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15356 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15357         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15358                                  "ip-ttl");
15359 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15360         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15361 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15362         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15363                                  "ip-src");
15364 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15365         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15366 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15367         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15368                                  "ip-dst");
15369 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15370         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15371 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15372         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15373                                  "vlan-tci");
15374 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15375         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15376 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15377         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15378                                  "eth-src");
15379 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15380         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15381 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15382         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15383                                  "eth-dst");
15384 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15385         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15386
15387 static void cmd_set_vxlan_parsed(void *parsed_result,
15388         __rte_unused struct cmdline *cl,
15389         __rte_unused void *data)
15390 {
15391         struct cmd_set_vxlan_result *res = parsed_result;
15392         union {
15393                 uint32_t vxlan_id;
15394                 uint8_t vni[4];
15395         } id = {
15396                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15397         };
15398
15399         vxlan_encap_conf.select_tos_ttl = 0;
15400         if (strcmp(res->vxlan, "vxlan") == 0)
15401                 vxlan_encap_conf.select_vlan = 0;
15402         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15403                 vxlan_encap_conf.select_vlan = 1;
15404         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15405                 vxlan_encap_conf.select_vlan = 0;
15406                 vxlan_encap_conf.select_tos_ttl = 1;
15407         }
15408         if (strcmp(res->ip_version, "ipv4") == 0)
15409                 vxlan_encap_conf.select_ipv4 = 1;
15410         else if (strcmp(res->ip_version, "ipv6") == 0)
15411                 vxlan_encap_conf.select_ipv4 = 0;
15412         else
15413                 return;
15414         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15415         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15416         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15417         vxlan_encap_conf.ip_tos = res->tos;
15418         vxlan_encap_conf.ip_ttl = res->ttl;
15419         if (vxlan_encap_conf.select_ipv4) {
15420                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15421                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15422         } else {
15423                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15424                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15425         }
15426         if (vxlan_encap_conf.select_vlan)
15427                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15428         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15429                    RTE_ETHER_ADDR_LEN);
15430         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15431                    RTE_ETHER_ADDR_LEN);
15432 }
15433
15434 cmdline_parse_inst_t cmd_set_vxlan = {
15435         .f = cmd_set_vxlan_parsed,
15436         .data = NULL,
15437         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15438                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15439                 " eth-src <eth-src> eth-dst <eth-dst>",
15440         .tokens = {
15441                 (void *)&cmd_set_vxlan_set,
15442                 (void *)&cmd_set_vxlan_vxlan,
15443                 (void *)&cmd_set_vxlan_ip_version,
15444                 (void *)&cmd_set_vxlan_ip_version_value,
15445                 (void *)&cmd_set_vxlan_vni,
15446                 (void *)&cmd_set_vxlan_vni_value,
15447                 (void *)&cmd_set_vxlan_udp_src,
15448                 (void *)&cmd_set_vxlan_udp_src_value,
15449                 (void *)&cmd_set_vxlan_udp_dst,
15450                 (void *)&cmd_set_vxlan_udp_dst_value,
15451                 (void *)&cmd_set_vxlan_ip_src,
15452                 (void *)&cmd_set_vxlan_ip_src_value,
15453                 (void *)&cmd_set_vxlan_ip_dst,
15454                 (void *)&cmd_set_vxlan_ip_dst_value,
15455                 (void *)&cmd_set_vxlan_eth_src,
15456                 (void *)&cmd_set_vxlan_eth_src_value,
15457                 (void *)&cmd_set_vxlan_eth_dst,
15458                 (void *)&cmd_set_vxlan_eth_dst_value,
15459                 NULL,
15460         },
15461 };
15462
15463 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15464         .f = cmd_set_vxlan_parsed,
15465         .data = NULL,
15466         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15467                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15468                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15469                 " eth-dst <eth-dst>",
15470         .tokens = {
15471                 (void *)&cmd_set_vxlan_set,
15472                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15473                 (void *)&cmd_set_vxlan_ip_version,
15474                 (void *)&cmd_set_vxlan_ip_version_value,
15475                 (void *)&cmd_set_vxlan_vni,
15476                 (void *)&cmd_set_vxlan_vni_value,
15477                 (void *)&cmd_set_vxlan_udp_src,
15478                 (void *)&cmd_set_vxlan_udp_src_value,
15479                 (void *)&cmd_set_vxlan_udp_dst,
15480                 (void *)&cmd_set_vxlan_udp_dst_value,
15481                 (void *)&cmd_set_vxlan_ip_tos,
15482                 (void *)&cmd_set_vxlan_ip_tos_value,
15483                 (void *)&cmd_set_vxlan_ip_ttl,
15484                 (void *)&cmd_set_vxlan_ip_ttl_value,
15485                 (void *)&cmd_set_vxlan_ip_src,
15486                 (void *)&cmd_set_vxlan_ip_src_value,
15487                 (void *)&cmd_set_vxlan_ip_dst,
15488                 (void *)&cmd_set_vxlan_ip_dst_value,
15489                 (void *)&cmd_set_vxlan_eth_src,
15490                 (void *)&cmd_set_vxlan_eth_src_value,
15491                 (void *)&cmd_set_vxlan_eth_dst,
15492                 (void *)&cmd_set_vxlan_eth_dst_value,
15493                 NULL,
15494         },
15495 };
15496
15497 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15498         .f = cmd_set_vxlan_parsed,
15499         .data = NULL,
15500         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15501                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15502                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15503                 " <eth-dst>",
15504         .tokens = {
15505                 (void *)&cmd_set_vxlan_set,
15506                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15507                 (void *)&cmd_set_vxlan_ip_version,
15508                 (void *)&cmd_set_vxlan_ip_version_value,
15509                 (void *)&cmd_set_vxlan_vni,
15510                 (void *)&cmd_set_vxlan_vni_value,
15511                 (void *)&cmd_set_vxlan_udp_src,
15512                 (void *)&cmd_set_vxlan_udp_src_value,
15513                 (void *)&cmd_set_vxlan_udp_dst,
15514                 (void *)&cmd_set_vxlan_udp_dst_value,
15515                 (void *)&cmd_set_vxlan_ip_src,
15516                 (void *)&cmd_set_vxlan_ip_src_value,
15517                 (void *)&cmd_set_vxlan_ip_dst,
15518                 (void *)&cmd_set_vxlan_ip_dst_value,
15519                 (void *)&cmd_set_vxlan_vlan,
15520                 (void *)&cmd_set_vxlan_vlan_value,
15521                 (void *)&cmd_set_vxlan_eth_src,
15522                 (void *)&cmd_set_vxlan_eth_src_value,
15523                 (void *)&cmd_set_vxlan_eth_dst,
15524                 (void *)&cmd_set_vxlan_eth_dst_value,
15525                 NULL,
15526         },
15527 };
15528
15529 /** Set NVGRE encapsulation details */
15530 struct cmd_set_nvgre_result {
15531         cmdline_fixed_string_t set;
15532         cmdline_fixed_string_t nvgre;
15533         cmdline_fixed_string_t pos_token;
15534         cmdline_fixed_string_t ip_version;
15535         uint32_t tni;
15536         cmdline_ipaddr_t ip_src;
15537         cmdline_ipaddr_t ip_dst;
15538         uint16_t tci;
15539         struct rte_ether_addr eth_src;
15540         struct rte_ether_addr eth_dst;
15541 };
15542
15543 cmdline_parse_token_string_t cmd_set_nvgre_set =
15544         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15545 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15546         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15547 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15548         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15549                                  "nvgre-with-vlan");
15550 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15551         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15552                                  "ip-version");
15553 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15554         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15555                                  "ipv4#ipv6");
15556 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15557         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15558                                  "tni");
15559 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15560         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15561 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15562         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15563                                  "ip-src");
15564 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15565         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15566 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15567         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15568                                  "ip-dst");
15569 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15570         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15571 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15572         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15573                                  "vlan-tci");
15574 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15575         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15576 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15577         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15578                                  "eth-src");
15579 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15580         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15581 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15582         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15583                                  "eth-dst");
15584 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15585         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15586
15587 static void cmd_set_nvgre_parsed(void *parsed_result,
15588         __rte_unused struct cmdline *cl,
15589         __rte_unused void *data)
15590 {
15591         struct cmd_set_nvgre_result *res = parsed_result;
15592         union {
15593                 uint32_t nvgre_tni;
15594                 uint8_t tni[4];
15595         } id = {
15596                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15597         };
15598
15599         if (strcmp(res->nvgre, "nvgre") == 0)
15600                 nvgre_encap_conf.select_vlan = 0;
15601         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15602                 nvgre_encap_conf.select_vlan = 1;
15603         if (strcmp(res->ip_version, "ipv4") == 0)
15604                 nvgre_encap_conf.select_ipv4 = 1;
15605         else if (strcmp(res->ip_version, "ipv6") == 0)
15606                 nvgre_encap_conf.select_ipv4 = 0;
15607         else
15608                 return;
15609         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15610         if (nvgre_encap_conf.select_ipv4) {
15611                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15612                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15613         } else {
15614                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15615                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15616         }
15617         if (nvgre_encap_conf.select_vlan)
15618                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15619         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15620                    RTE_ETHER_ADDR_LEN);
15621         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15622                    RTE_ETHER_ADDR_LEN);
15623 }
15624
15625 cmdline_parse_inst_t cmd_set_nvgre = {
15626         .f = cmd_set_nvgre_parsed,
15627         .data = NULL,
15628         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15629                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15630                 " eth-dst <eth-dst>",
15631         .tokens = {
15632                 (void *)&cmd_set_nvgre_set,
15633                 (void *)&cmd_set_nvgre_nvgre,
15634                 (void *)&cmd_set_nvgre_ip_version,
15635                 (void *)&cmd_set_nvgre_ip_version_value,
15636                 (void *)&cmd_set_nvgre_tni,
15637                 (void *)&cmd_set_nvgre_tni_value,
15638                 (void *)&cmd_set_nvgre_ip_src,
15639                 (void *)&cmd_set_nvgre_ip_src_value,
15640                 (void *)&cmd_set_nvgre_ip_dst,
15641                 (void *)&cmd_set_nvgre_ip_dst_value,
15642                 (void *)&cmd_set_nvgre_eth_src,
15643                 (void *)&cmd_set_nvgre_eth_src_value,
15644                 (void *)&cmd_set_nvgre_eth_dst,
15645                 (void *)&cmd_set_nvgre_eth_dst_value,
15646                 NULL,
15647         },
15648 };
15649
15650 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15651         .f = cmd_set_nvgre_parsed,
15652         .data = NULL,
15653         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15654                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15655                 " eth-src <eth-src> eth-dst <eth-dst>",
15656         .tokens = {
15657                 (void *)&cmd_set_nvgre_set,
15658                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15659                 (void *)&cmd_set_nvgre_ip_version,
15660                 (void *)&cmd_set_nvgre_ip_version_value,
15661                 (void *)&cmd_set_nvgre_tni,
15662                 (void *)&cmd_set_nvgre_tni_value,
15663                 (void *)&cmd_set_nvgre_ip_src,
15664                 (void *)&cmd_set_nvgre_ip_src_value,
15665                 (void *)&cmd_set_nvgre_ip_dst,
15666                 (void *)&cmd_set_nvgre_ip_dst_value,
15667                 (void *)&cmd_set_nvgre_vlan,
15668                 (void *)&cmd_set_nvgre_vlan_value,
15669                 (void *)&cmd_set_nvgre_eth_src,
15670                 (void *)&cmd_set_nvgre_eth_src_value,
15671                 (void *)&cmd_set_nvgre_eth_dst,
15672                 (void *)&cmd_set_nvgre_eth_dst_value,
15673                 NULL,
15674         },
15675 };
15676
15677 /** Set L2 encapsulation details */
15678 struct cmd_set_l2_encap_result {
15679         cmdline_fixed_string_t set;
15680         cmdline_fixed_string_t l2_encap;
15681         cmdline_fixed_string_t pos_token;
15682         cmdline_fixed_string_t ip_version;
15683         uint32_t vlan_present:1;
15684         uint16_t tci;
15685         struct rte_ether_addr eth_src;
15686         struct rte_ether_addr eth_dst;
15687 };
15688
15689 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15690         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15691 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15692         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15693 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15694         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15695                                  "l2_encap-with-vlan");
15696 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15697         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15698                                  "ip-version");
15699 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15700         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15701                                  "ipv4#ipv6");
15702 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15703         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15704                                  "vlan-tci");
15705 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15706         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15707 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15708         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15709                                  "eth-src");
15710 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15711         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15712 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15713         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15714                                  "eth-dst");
15715 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15716         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15717
15718 static void cmd_set_l2_encap_parsed(void *parsed_result,
15719         __rte_unused struct cmdline *cl,
15720         __rte_unused void *data)
15721 {
15722         struct cmd_set_l2_encap_result *res = parsed_result;
15723
15724         if (strcmp(res->l2_encap, "l2_encap") == 0)
15725                 l2_encap_conf.select_vlan = 0;
15726         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15727                 l2_encap_conf.select_vlan = 1;
15728         if (strcmp(res->ip_version, "ipv4") == 0)
15729                 l2_encap_conf.select_ipv4 = 1;
15730         else if (strcmp(res->ip_version, "ipv6") == 0)
15731                 l2_encap_conf.select_ipv4 = 0;
15732         else
15733                 return;
15734         if (l2_encap_conf.select_vlan)
15735                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15736         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15737                    RTE_ETHER_ADDR_LEN);
15738         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15739                    RTE_ETHER_ADDR_LEN);
15740 }
15741
15742 cmdline_parse_inst_t cmd_set_l2_encap = {
15743         .f = cmd_set_l2_encap_parsed,
15744         .data = NULL,
15745         .help_str = "set l2_encap ip-version ipv4|ipv6"
15746                 " eth-src <eth-src> eth-dst <eth-dst>",
15747         .tokens = {
15748                 (void *)&cmd_set_l2_encap_set,
15749                 (void *)&cmd_set_l2_encap_l2_encap,
15750                 (void *)&cmd_set_l2_encap_ip_version,
15751                 (void *)&cmd_set_l2_encap_ip_version_value,
15752                 (void *)&cmd_set_l2_encap_eth_src,
15753                 (void *)&cmd_set_l2_encap_eth_src_value,
15754                 (void *)&cmd_set_l2_encap_eth_dst,
15755                 (void *)&cmd_set_l2_encap_eth_dst_value,
15756                 NULL,
15757         },
15758 };
15759
15760 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15761         .f = cmd_set_l2_encap_parsed,
15762         .data = NULL,
15763         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15764                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15765         .tokens = {
15766                 (void *)&cmd_set_l2_encap_set,
15767                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15768                 (void *)&cmd_set_l2_encap_ip_version,
15769                 (void *)&cmd_set_l2_encap_ip_version_value,
15770                 (void *)&cmd_set_l2_encap_vlan,
15771                 (void *)&cmd_set_l2_encap_vlan_value,
15772                 (void *)&cmd_set_l2_encap_eth_src,
15773                 (void *)&cmd_set_l2_encap_eth_src_value,
15774                 (void *)&cmd_set_l2_encap_eth_dst,
15775                 (void *)&cmd_set_l2_encap_eth_dst_value,
15776                 NULL,
15777         },
15778 };
15779
15780 /** Set L2 decapsulation details */
15781 struct cmd_set_l2_decap_result {
15782         cmdline_fixed_string_t set;
15783         cmdline_fixed_string_t l2_decap;
15784         cmdline_fixed_string_t pos_token;
15785         uint32_t vlan_present:1;
15786 };
15787
15788 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15789         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15790 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15791         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15792                                  "l2_decap");
15793 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15794         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15795                                  "l2_decap-with-vlan");
15796
15797 static void cmd_set_l2_decap_parsed(void *parsed_result,
15798         __rte_unused struct cmdline *cl,
15799         __rte_unused void *data)
15800 {
15801         struct cmd_set_l2_decap_result *res = parsed_result;
15802
15803         if (strcmp(res->l2_decap, "l2_decap") == 0)
15804                 l2_decap_conf.select_vlan = 0;
15805         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15806                 l2_decap_conf.select_vlan = 1;
15807 }
15808
15809 cmdline_parse_inst_t cmd_set_l2_decap = {
15810         .f = cmd_set_l2_decap_parsed,
15811         .data = NULL,
15812         .help_str = "set l2_decap",
15813         .tokens = {
15814                 (void *)&cmd_set_l2_decap_set,
15815                 (void *)&cmd_set_l2_decap_l2_decap,
15816                 NULL,
15817         },
15818 };
15819
15820 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15821         .f = cmd_set_l2_decap_parsed,
15822         .data = NULL,
15823         .help_str = "set l2_decap-with-vlan",
15824         .tokens = {
15825                 (void *)&cmd_set_l2_decap_set,
15826                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15827                 NULL,
15828         },
15829 };
15830
15831 /** Set MPLSoGRE encapsulation details */
15832 struct cmd_set_mplsogre_encap_result {
15833         cmdline_fixed_string_t set;
15834         cmdline_fixed_string_t mplsogre;
15835         cmdline_fixed_string_t pos_token;
15836         cmdline_fixed_string_t ip_version;
15837         uint32_t vlan_present:1;
15838         uint32_t label;
15839         cmdline_ipaddr_t ip_src;
15840         cmdline_ipaddr_t ip_dst;
15841         uint16_t tci;
15842         struct rte_ether_addr eth_src;
15843         struct rte_ether_addr eth_dst;
15844 };
15845
15846 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15847         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15848                                  "set");
15849 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15850         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15851                                  "mplsogre_encap");
15852 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15853         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15854                                  mplsogre, "mplsogre_encap-with-vlan");
15855 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15856         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15857                                  pos_token, "ip-version");
15858 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15859         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15860                                  ip_version, "ipv4#ipv6");
15861 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15862         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15863                                  pos_token, "label");
15864 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15865         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15866                               UINT32);
15867 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15868         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15869                                  pos_token, "ip-src");
15870 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15871         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15872 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15873         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15874                                  pos_token, "ip-dst");
15875 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15876         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15877 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15878         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15879                                  pos_token, "vlan-tci");
15880 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15881         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15882                               UINT16);
15883 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15884         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15885                                  pos_token, "eth-src");
15886 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15887         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15888                                     eth_src);
15889 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15890         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15891                                  pos_token, "eth-dst");
15892 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15893         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15894                                     eth_dst);
15895
15896 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15897         __rte_unused struct cmdline *cl,
15898         __rte_unused void *data)
15899 {
15900         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15901         union {
15902                 uint32_t mplsogre_label;
15903                 uint8_t label[4];
15904         } id = {
15905                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15906         };
15907
15908         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15909                 mplsogre_encap_conf.select_vlan = 0;
15910         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15911                 mplsogre_encap_conf.select_vlan = 1;
15912         if (strcmp(res->ip_version, "ipv4") == 0)
15913                 mplsogre_encap_conf.select_ipv4 = 1;
15914         else if (strcmp(res->ip_version, "ipv6") == 0)
15915                 mplsogre_encap_conf.select_ipv4 = 0;
15916         else
15917                 return;
15918         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15919         if (mplsogre_encap_conf.select_ipv4) {
15920                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15921                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15922         } else {
15923                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15924                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15925         }
15926         if (mplsogre_encap_conf.select_vlan)
15927                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15928         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15929                    RTE_ETHER_ADDR_LEN);
15930         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15931                    RTE_ETHER_ADDR_LEN);
15932 }
15933
15934 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
15935         .f = cmd_set_mplsogre_encap_parsed,
15936         .data = NULL,
15937         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
15938                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15939                 " eth-dst <eth-dst>",
15940         .tokens = {
15941                 (void *)&cmd_set_mplsogre_encap_set,
15942                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
15943                 (void *)&cmd_set_mplsogre_encap_ip_version,
15944                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15945                 (void *)&cmd_set_mplsogre_encap_label,
15946                 (void *)&cmd_set_mplsogre_encap_label_value,
15947                 (void *)&cmd_set_mplsogre_encap_ip_src,
15948                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15949                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15950                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15951                 (void *)&cmd_set_mplsogre_encap_eth_src,
15952                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15953                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15954                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15955                 NULL,
15956         },
15957 };
15958
15959 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
15960         .f = cmd_set_mplsogre_encap_parsed,
15961         .data = NULL,
15962         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
15963                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
15964                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15965         .tokens = {
15966                 (void *)&cmd_set_mplsogre_encap_set,
15967                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
15968                 (void *)&cmd_set_mplsogre_encap_ip_version,
15969                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
15970                 (void *)&cmd_set_mplsogre_encap_label,
15971                 (void *)&cmd_set_mplsogre_encap_label_value,
15972                 (void *)&cmd_set_mplsogre_encap_ip_src,
15973                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
15974                 (void *)&cmd_set_mplsogre_encap_ip_dst,
15975                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
15976                 (void *)&cmd_set_mplsogre_encap_vlan,
15977                 (void *)&cmd_set_mplsogre_encap_vlan_value,
15978                 (void *)&cmd_set_mplsogre_encap_eth_src,
15979                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
15980                 (void *)&cmd_set_mplsogre_encap_eth_dst,
15981                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
15982                 NULL,
15983         },
15984 };
15985
15986 /** Set MPLSoGRE decapsulation details */
15987 struct cmd_set_mplsogre_decap_result {
15988         cmdline_fixed_string_t set;
15989         cmdline_fixed_string_t mplsogre;
15990         cmdline_fixed_string_t pos_token;
15991         cmdline_fixed_string_t ip_version;
15992         uint32_t vlan_present:1;
15993 };
15994
15995 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
15996         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
15997                                  "set");
15998 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
15999         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16000                                  "mplsogre_decap");
16001 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16002         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16003                                  mplsogre, "mplsogre_decap-with-vlan");
16004 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16005         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16006                                  pos_token, "ip-version");
16007 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16008         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16009                                  ip_version, "ipv4#ipv6");
16010
16011 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16012         __rte_unused struct cmdline *cl,
16013         __rte_unused void *data)
16014 {
16015         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16016
16017         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16018                 mplsogre_decap_conf.select_vlan = 0;
16019         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16020                 mplsogre_decap_conf.select_vlan = 1;
16021         if (strcmp(res->ip_version, "ipv4") == 0)
16022                 mplsogre_decap_conf.select_ipv4 = 1;
16023         else if (strcmp(res->ip_version, "ipv6") == 0)
16024                 mplsogre_decap_conf.select_ipv4 = 0;
16025 }
16026
16027 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16028         .f = cmd_set_mplsogre_decap_parsed,
16029         .data = NULL,
16030         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16031         .tokens = {
16032                 (void *)&cmd_set_mplsogre_decap_set,
16033                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16034                 (void *)&cmd_set_mplsogre_decap_ip_version,
16035                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16036                 NULL,
16037         },
16038 };
16039
16040 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16041         .f = cmd_set_mplsogre_decap_parsed,
16042         .data = NULL,
16043         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16044         .tokens = {
16045                 (void *)&cmd_set_mplsogre_decap_set,
16046                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16047                 (void *)&cmd_set_mplsogre_decap_ip_version,
16048                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16049                 NULL,
16050         },
16051 };
16052
16053 /** Set MPLSoUDP encapsulation details */
16054 struct cmd_set_mplsoudp_encap_result {
16055         cmdline_fixed_string_t set;
16056         cmdline_fixed_string_t mplsoudp;
16057         cmdline_fixed_string_t pos_token;
16058         cmdline_fixed_string_t ip_version;
16059         uint32_t vlan_present:1;
16060         uint32_t label;
16061         uint16_t udp_src;
16062         uint16_t udp_dst;
16063         cmdline_ipaddr_t ip_src;
16064         cmdline_ipaddr_t ip_dst;
16065         uint16_t tci;
16066         struct rte_ether_addr eth_src;
16067         struct rte_ether_addr eth_dst;
16068 };
16069
16070 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16071         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16072                                  "set");
16073 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16074         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16075                                  "mplsoudp_encap");
16076 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16077         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16078                                  mplsoudp, "mplsoudp_encap-with-vlan");
16079 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16080         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16081                                  pos_token, "ip-version");
16082 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16083         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16084                                  ip_version, "ipv4#ipv6");
16085 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16086         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16087                                  pos_token, "label");
16088 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16089         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16090                               UINT32);
16091 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16092         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16093                                  pos_token, "udp-src");
16094 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16095         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16096                               UINT16);
16097 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16098         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16099                                  pos_token, "udp-dst");
16100 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16101         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16102                               UINT16);
16103 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16104         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16105                                  pos_token, "ip-src");
16106 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16107         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16108 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16109         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16110                                  pos_token, "ip-dst");
16111 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16112         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16113 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16114         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16115                                  pos_token, "vlan-tci");
16116 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16117         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16118                               UINT16);
16119 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16120         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16121                                  pos_token, "eth-src");
16122 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16123         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16124                                     eth_src);
16125 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16126         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16127                                  pos_token, "eth-dst");
16128 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16129         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16130                                     eth_dst);
16131
16132 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16133         __rte_unused struct cmdline *cl,
16134         __rte_unused void *data)
16135 {
16136         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16137         union {
16138                 uint32_t mplsoudp_label;
16139                 uint8_t label[4];
16140         } id = {
16141                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16142         };
16143
16144         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16145                 mplsoudp_encap_conf.select_vlan = 0;
16146         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16147                 mplsoudp_encap_conf.select_vlan = 1;
16148         if (strcmp(res->ip_version, "ipv4") == 0)
16149                 mplsoudp_encap_conf.select_ipv4 = 1;
16150         else if (strcmp(res->ip_version, "ipv6") == 0)
16151                 mplsoudp_encap_conf.select_ipv4 = 0;
16152         else
16153                 return;
16154         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16155         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16156         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16157         if (mplsoudp_encap_conf.select_ipv4) {
16158                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16159                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16160         } else {
16161                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16162                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16163         }
16164         if (mplsoudp_encap_conf.select_vlan)
16165                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16166         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16167                    RTE_ETHER_ADDR_LEN);
16168         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16169                    RTE_ETHER_ADDR_LEN);
16170 }
16171
16172 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16173         .f = cmd_set_mplsoudp_encap_parsed,
16174         .data = NULL,
16175         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16176                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16177                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16178         .tokens = {
16179                 (void *)&cmd_set_mplsoudp_encap_set,
16180                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16181                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16182                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16183                 (void *)&cmd_set_mplsoudp_encap_label,
16184                 (void *)&cmd_set_mplsoudp_encap_label_value,
16185                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16186                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16187                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16188                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16189                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16190                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16191                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16192                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16193                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16194                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16195                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16196                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16197                 NULL,
16198         },
16199 };
16200
16201 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16202         .f = cmd_set_mplsoudp_encap_parsed,
16203         .data = NULL,
16204         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16205                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16206                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16207                 " eth-src <eth-src> eth-dst <eth-dst>",
16208         .tokens = {
16209                 (void *)&cmd_set_mplsoudp_encap_set,
16210                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16211                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16212                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16213                 (void *)&cmd_set_mplsoudp_encap_label,
16214                 (void *)&cmd_set_mplsoudp_encap_label_value,
16215                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16216                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16217                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16218                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16219                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16220                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16221                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16222                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16223                 (void *)&cmd_set_mplsoudp_encap_vlan,
16224                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16225                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16226                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16227                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16228                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16229                 NULL,
16230         },
16231 };
16232
16233 /** Set MPLSoUDP decapsulation details */
16234 struct cmd_set_mplsoudp_decap_result {
16235         cmdline_fixed_string_t set;
16236         cmdline_fixed_string_t mplsoudp;
16237         cmdline_fixed_string_t pos_token;
16238         cmdline_fixed_string_t ip_version;
16239         uint32_t vlan_present:1;
16240 };
16241
16242 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16243         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16244                                  "set");
16245 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16246         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16247                                  "mplsoudp_decap");
16248 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16249         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16250                                  mplsoudp, "mplsoudp_decap-with-vlan");
16251 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16252         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16253                                  pos_token, "ip-version");
16254 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16255         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16256                                  ip_version, "ipv4#ipv6");
16257
16258 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16259         __rte_unused struct cmdline *cl,
16260         __rte_unused void *data)
16261 {
16262         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16263
16264         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16265                 mplsoudp_decap_conf.select_vlan = 0;
16266         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16267                 mplsoudp_decap_conf.select_vlan = 1;
16268         if (strcmp(res->ip_version, "ipv4") == 0)
16269                 mplsoudp_decap_conf.select_ipv4 = 1;
16270         else if (strcmp(res->ip_version, "ipv6") == 0)
16271                 mplsoudp_decap_conf.select_ipv4 = 0;
16272 }
16273
16274 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16275         .f = cmd_set_mplsoudp_decap_parsed,
16276         .data = NULL,
16277         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16278         .tokens = {
16279                 (void *)&cmd_set_mplsoudp_decap_set,
16280                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16281                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16282                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16283                 NULL,
16284         },
16285 };
16286
16287 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16288         .f = cmd_set_mplsoudp_decap_parsed,
16289         .data = NULL,
16290         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16291         .tokens = {
16292                 (void *)&cmd_set_mplsoudp_decap_set,
16293                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16294                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16295                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16296                 NULL,
16297         },
16298 };
16299
16300 /* Strict link priority scheduling mode setting */
16301 static void
16302 cmd_strict_link_prio_parsed(
16303         void *parsed_result,
16304         __rte_unused struct cmdline *cl,
16305         __rte_unused void *data)
16306 {
16307         struct cmd_vf_tc_bw_result *res = parsed_result;
16308         int ret = -ENOTSUP;
16309
16310         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16311                 return;
16312
16313 #ifdef RTE_NET_I40E
16314         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16315 #endif
16316
16317         switch (ret) {
16318         case 0:
16319                 break;
16320         case -EINVAL:
16321                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16322                 break;
16323         case -ENODEV:
16324                 printf("invalid port_id %d\n", res->port_id);
16325                 break;
16326         case -ENOTSUP:
16327                 printf("function not implemented\n");
16328                 break;
16329         default:
16330                 printf("programming error: (%s)\n", strerror(-ret));
16331         }
16332 }
16333
16334 cmdline_parse_inst_t cmd_strict_link_prio = {
16335         .f = cmd_strict_link_prio_parsed,
16336         .data = NULL,
16337         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16338         .tokens = {
16339                 (void *)&cmd_vf_tc_bw_set,
16340                 (void *)&cmd_vf_tc_bw_tx,
16341                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16342                 (void *)&cmd_vf_tc_bw_port_id,
16343                 (void *)&cmd_vf_tc_bw_tc_map,
16344                 NULL,
16345         },
16346 };
16347
16348 /* Load dynamic device personalization*/
16349 struct cmd_ddp_add_result {
16350         cmdline_fixed_string_t ddp;
16351         cmdline_fixed_string_t add;
16352         portid_t port_id;
16353         char filepath[];
16354 };
16355
16356 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16357         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16358 cmdline_parse_token_string_t cmd_ddp_add_add =
16359         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16360 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16361         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16362 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16363         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16364
16365 static void
16366 cmd_ddp_add_parsed(
16367         void *parsed_result,
16368         __rte_unused struct cmdline *cl,
16369         __rte_unused void *data)
16370 {
16371         struct cmd_ddp_add_result *res = parsed_result;
16372         uint8_t *buff;
16373         uint32_t size;
16374         char *filepath;
16375         char *file_fld[2];
16376         int file_num;
16377         int ret = -ENOTSUP;
16378
16379         if (!all_ports_stopped()) {
16380                 printf("Please stop all ports first\n");
16381                 return;
16382         }
16383
16384         filepath = strdup(res->filepath);
16385         if (filepath == NULL) {
16386                 printf("Failed to allocate memory\n");
16387                 return;
16388         }
16389         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16390
16391         buff = open_file(file_fld[0], &size);
16392         if (!buff) {
16393                 free((void *)filepath);
16394                 return;
16395         }
16396
16397 #ifdef RTE_NET_I40E
16398         if (ret == -ENOTSUP)
16399                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16400                                                buff, size,
16401                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16402 #endif
16403
16404         if (ret == -EEXIST)
16405                 printf("Profile has already existed.\n");
16406         else if (ret < 0)
16407                 printf("Failed to load profile.\n");
16408         else if (file_num == 2)
16409                 save_file(file_fld[1], buff, size);
16410
16411         close_file(buff);
16412         free((void *)filepath);
16413 }
16414
16415 cmdline_parse_inst_t cmd_ddp_add = {
16416         .f = cmd_ddp_add_parsed,
16417         .data = NULL,
16418         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16419         .tokens = {
16420                 (void *)&cmd_ddp_add_ddp,
16421                 (void *)&cmd_ddp_add_add,
16422                 (void *)&cmd_ddp_add_port_id,
16423                 (void *)&cmd_ddp_add_filepath,
16424                 NULL,
16425         },
16426 };
16427
16428 /* Delete dynamic device personalization*/
16429 struct cmd_ddp_del_result {
16430         cmdline_fixed_string_t ddp;
16431         cmdline_fixed_string_t del;
16432         portid_t port_id;
16433         char filepath[];
16434 };
16435
16436 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16437         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16438 cmdline_parse_token_string_t cmd_ddp_del_del =
16439         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16440 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16441         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16442 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16443         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16444
16445 static void
16446 cmd_ddp_del_parsed(
16447         void *parsed_result,
16448         __rte_unused struct cmdline *cl,
16449         __rte_unused void *data)
16450 {
16451         struct cmd_ddp_del_result *res = parsed_result;
16452         uint8_t *buff;
16453         uint32_t size;
16454         int ret = -ENOTSUP;
16455
16456         if (!all_ports_stopped()) {
16457                 printf("Please stop all ports first\n");
16458                 return;
16459         }
16460
16461         buff = open_file(res->filepath, &size);
16462         if (!buff)
16463                 return;
16464
16465 #ifdef RTE_NET_I40E
16466         if (ret == -ENOTSUP)
16467                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16468                                                buff, size,
16469                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16470 #endif
16471
16472         if (ret == -EACCES)
16473                 printf("Profile does not exist.\n");
16474         else if (ret < 0)
16475                 printf("Failed to delete profile.\n");
16476
16477         close_file(buff);
16478 }
16479
16480 cmdline_parse_inst_t cmd_ddp_del = {
16481         .f = cmd_ddp_del_parsed,
16482         .data = NULL,
16483         .help_str = "ddp del <port_id> <backup_profile_path>",
16484         .tokens = {
16485                 (void *)&cmd_ddp_del_ddp,
16486                 (void *)&cmd_ddp_del_del,
16487                 (void *)&cmd_ddp_del_port_id,
16488                 (void *)&cmd_ddp_del_filepath,
16489                 NULL,
16490         },
16491 };
16492
16493 /* Get dynamic device personalization profile info */
16494 struct cmd_ddp_info_result {
16495         cmdline_fixed_string_t ddp;
16496         cmdline_fixed_string_t get;
16497         cmdline_fixed_string_t info;
16498         char filepath[];
16499 };
16500
16501 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16502         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16503 cmdline_parse_token_string_t cmd_ddp_info_get =
16504         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16505 cmdline_parse_token_string_t cmd_ddp_info_info =
16506         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16507 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16508         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16509
16510 static void
16511 cmd_ddp_info_parsed(
16512         void *parsed_result,
16513         __rte_unused struct cmdline *cl,
16514         __rte_unused void *data)
16515 {
16516         struct cmd_ddp_info_result *res = parsed_result;
16517         uint8_t *pkg;
16518         uint32_t pkg_size;
16519         int ret = -ENOTSUP;
16520 #ifdef RTE_NET_I40E
16521         uint32_t i, j, n;
16522         uint8_t *buff;
16523         uint32_t buff_size = 0;
16524         struct rte_pmd_i40e_profile_info info;
16525         uint32_t dev_num = 0;
16526         struct rte_pmd_i40e_ddp_device_id *devs;
16527         uint32_t proto_num = 0;
16528         struct rte_pmd_i40e_proto_info *proto = NULL;
16529         uint32_t pctype_num = 0;
16530         struct rte_pmd_i40e_ptype_info *pctype;
16531         uint32_t ptype_num = 0;
16532         struct rte_pmd_i40e_ptype_info *ptype;
16533         uint8_t proto_id;
16534
16535 #endif
16536
16537         pkg = open_file(res->filepath, &pkg_size);
16538         if (!pkg)
16539                 return;
16540
16541 #ifdef RTE_NET_I40E
16542         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16543                                 (uint8_t *)&info, sizeof(info),
16544                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16545         if (!ret) {
16546                 printf("Global Track id:       0x%x\n", info.track_id);
16547                 printf("Global Version:        %d.%d.%d.%d\n",
16548                         info.version.major,
16549                         info.version.minor,
16550                         info.version.update,
16551                         info.version.draft);
16552                 printf("Global Package name:   %s\n\n", info.name);
16553         }
16554
16555         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16556                                 (uint8_t *)&info, sizeof(info),
16557                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16558         if (!ret) {
16559                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16560                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16561                         info.version.major,
16562                         info.version.minor,
16563                         info.version.update,
16564                         info.version.draft);
16565                 printf("i40e Profile name:     %s\n\n", info.name);
16566         }
16567
16568         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16569                                 (uint8_t *)&buff_size, sizeof(buff_size),
16570                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16571         if (!ret && buff_size) {
16572                 buff = (uint8_t *)malloc(buff_size);
16573                 if (buff) {
16574                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16575                                                 buff, buff_size,
16576                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16577                         if (!ret)
16578                                 printf("Package Notes:\n%s\n\n", buff);
16579                         free(buff);
16580                 }
16581         }
16582
16583         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16584                                 (uint8_t *)&dev_num, sizeof(dev_num),
16585                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16586         if (!ret && dev_num) {
16587                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16588                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16589                 if (devs) {
16590                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16591                                                 (uint8_t *)devs, buff_size,
16592                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16593                         if (!ret) {
16594                                 printf("List of supported devices:\n");
16595                                 for (i = 0; i < dev_num; i++) {
16596                                         printf("  %04X:%04X %04X:%04X\n",
16597                                                 devs[i].vendor_dev_id >> 16,
16598                                                 devs[i].vendor_dev_id & 0xFFFF,
16599                                                 devs[i].sub_vendor_dev_id >> 16,
16600                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16601                                 }
16602                                 printf("\n");
16603                         }
16604                         free(devs);
16605                 }
16606         }
16607
16608         /* get information about protocols and packet types */
16609         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16610                 (uint8_t *)&proto_num, sizeof(proto_num),
16611                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16612         if (ret || !proto_num)
16613                 goto no_print_return;
16614
16615         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16616         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16617         if (!proto)
16618                 goto no_print_return;
16619
16620         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16621                                         buff_size,
16622                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16623         if (!ret) {
16624                 printf("List of used protocols:\n");
16625                 for (i = 0; i < proto_num; i++)
16626                         printf("  %2u: %s\n", proto[i].proto_id,
16627                                proto[i].name);
16628                 printf("\n");
16629         }
16630         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16631                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16632                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16633         if (ret || !pctype_num)
16634                 goto no_print_pctypes;
16635
16636         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16637         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16638         if (!pctype)
16639                 goto no_print_pctypes;
16640
16641         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16642                                         buff_size,
16643                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16644         if (ret) {
16645                 free(pctype);
16646                 goto no_print_pctypes;
16647         }
16648
16649         printf("List of defined packet classification types:\n");
16650         for (i = 0; i < pctype_num; i++) {
16651                 printf("  %2u:", pctype[i].ptype_id);
16652                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16653                         proto_id = pctype[i].protocols[j];
16654                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16655                                 for (n = 0; n < proto_num; n++) {
16656                                         if (proto[n].proto_id == proto_id) {
16657                                                 printf(" %s", proto[n].name);
16658                                                 break;
16659                                         }
16660                                 }
16661                         }
16662                 }
16663                 printf("\n");
16664         }
16665         printf("\n");
16666         free(pctype);
16667
16668 no_print_pctypes:
16669
16670         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16671                                         sizeof(ptype_num),
16672                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16673         if (ret || !ptype_num)
16674                 goto no_print_return;
16675
16676         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16677         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16678         if (!ptype)
16679                 goto no_print_return;
16680
16681         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16682                                         buff_size,
16683                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16684         if (ret) {
16685                 free(ptype);
16686                 goto no_print_return;
16687         }
16688         printf("List of defined packet types:\n");
16689         for (i = 0; i < ptype_num; i++) {
16690                 printf("  %2u:", ptype[i].ptype_id);
16691                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16692                         proto_id = ptype[i].protocols[j];
16693                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16694                                 for (n = 0; n < proto_num; n++) {
16695                                         if (proto[n].proto_id == proto_id) {
16696                                                 printf(" %s", proto[n].name);
16697                                                 break;
16698                                         }
16699                                 }
16700                         }
16701                 }
16702                 printf("\n");
16703         }
16704         free(ptype);
16705         printf("\n");
16706
16707         ret = 0;
16708 no_print_return:
16709         if (proto)
16710                 free(proto);
16711 #endif
16712         if (ret == -ENOTSUP)
16713                 printf("Function not supported in PMD driver\n");
16714         close_file(pkg);
16715 }
16716
16717 cmdline_parse_inst_t cmd_ddp_get_info = {
16718         .f = cmd_ddp_info_parsed,
16719         .data = NULL,
16720         .help_str = "ddp get info <profile_path>",
16721         .tokens = {
16722                 (void *)&cmd_ddp_info_ddp,
16723                 (void *)&cmd_ddp_info_get,
16724                 (void *)&cmd_ddp_info_info,
16725                 (void *)&cmd_ddp_info_filepath,
16726                 NULL,
16727         },
16728 };
16729
16730 /* Get dynamic device personalization profile info list*/
16731 #define PROFILE_INFO_SIZE 48
16732 #define MAX_PROFILE_NUM 16
16733
16734 struct cmd_ddp_get_list_result {
16735         cmdline_fixed_string_t ddp;
16736         cmdline_fixed_string_t get;
16737         cmdline_fixed_string_t list;
16738         portid_t port_id;
16739 };
16740
16741 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16742         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16743 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16744         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16745 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16746         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16747 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16748         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16749
16750 static void
16751 cmd_ddp_get_list_parsed(
16752         __rte_unused void *parsed_result,
16753         __rte_unused struct cmdline *cl,
16754         __rte_unused void *data)
16755 {
16756 #ifdef RTE_NET_I40E
16757         struct cmd_ddp_get_list_result *res = parsed_result;
16758         struct rte_pmd_i40e_profile_list *p_list;
16759         struct rte_pmd_i40e_profile_info *p_info;
16760         uint32_t p_num;
16761         uint32_t size;
16762         uint32_t i;
16763 #endif
16764         int ret = -ENOTSUP;
16765
16766 #ifdef RTE_NET_I40E
16767         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16768         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16769         if (!p_list) {
16770                 printf("%s: Failed to malloc buffer\n", __func__);
16771                 return;
16772         }
16773
16774         if (ret == -ENOTSUP)
16775                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16776                                                 (uint8_t *)p_list, size);
16777
16778         if (!ret) {
16779                 p_num = p_list->p_count;
16780                 printf("Profile number is: %d\n\n", p_num);
16781
16782                 for (i = 0; i < p_num; i++) {
16783                         p_info = &p_list->p_info[i];
16784                         printf("Profile %d:\n", i);
16785                         printf("Track id:     0x%x\n", p_info->track_id);
16786                         printf("Version:      %d.%d.%d.%d\n",
16787                                p_info->version.major,
16788                                p_info->version.minor,
16789                                p_info->version.update,
16790                                p_info->version.draft);
16791                         printf("Profile name: %s\n\n", p_info->name);
16792                 }
16793         }
16794
16795         free(p_list);
16796 #endif
16797
16798         if (ret < 0)
16799                 printf("Failed to get ddp list\n");
16800 }
16801
16802 cmdline_parse_inst_t cmd_ddp_get_list = {
16803         .f = cmd_ddp_get_list_parsed,
16804         .data = NULL,
16805         .help_str = "ddp get list <port_id>",
16806         .tokens = {
16807                 (void *)&cmd_ddp_get_list_ddp,
16808                 (void *)&cmd_ddp_get_list_get,
16809                 (void *)&cmd_ddp_get_list_list,
16810                 (void *)&cmd_ddp_get_list_port_id,
16811                 NULL,
16812         },
16813 };
16814
16815 /* Configure input set */
16816 struct cmd_cfg_input_set_result {
16817         cmdline_fixed_string_t port;
16818         cmdline_fixed_string_t cfg;
16819         portid_t port_id;
16820         cmdline_fixed_string_t pctype;
16821         uint8_t pctype_id;
16822         cmdline_fixed_string_t inset_type;
16823         cmdline_fixed_string_t opt;
16824         cmdline_fixed_string_t field;
16825         uint8_t field_idx;
16826 };
16827
16828 static void
16829 cmd_cfg_input_set_parsed(
16830         __rte_unused void *parsed_result,
16831         __rte_unused struct cmdline *cl,
16832         __rte_unused void *data)
16833 {
16834 #ifdef RTE_NET_I40E
16835         struct cmd_cfg_input_set_result *res = parsed_result;
16836         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16837         struct rte_pmd_i40e_inset inset;
16838 #endif
16839         int ret = -ENOTSUP;
16840
16841         if (!all_ports_stopped()) {
16842                 printf("Please stop all ports first\n");
16843                 return;
16844         }
16845
16846 #ifdef RTE_NET_I40E
16847         if (!strcmp(res->inset_type, "hash_inset"))
16848                 inset_type = INSET_HASH;
16849         else if (!strcmp(res->inset_type, "fdir_inset"))
16850                 inset_type = INSET_FDIR;
16851         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16852                 inset_type = INSET_FDIR_FLX;
16853         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16854                                      &inset, inset_type);
16855         if (ret) {
16856                 printf("Failed to get input set.\n");
16857                 return;
16858         }
16859
16860         if (!strcmp(res->opt, "get")) {
16861                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16862                                                    res->field_idx);
16863                 if (ret)
16864                         printf("Field index %d is enabled.\n", res->field_idx);
16865                 else
16866                         printf("Field index %d is disabled.\n", res->field_idx);
16867                 return;
16868         } else if (!strcmp(res->opt, "set"))
16869                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16870                                                    res->field_idx);
16871         else if (!strcmp(res->opt, "clear"))
16872                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16873                                                      res->field_idx);
16874         if (ret) {
16875                 printf("Failed to configure input set field.\n");
16876                 return;
16877         }
16878
16879         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16880                                      &inset, inset_type);
16881         if (ret) {
16882                 printf("Failed to set input set.\n");
16883                 return;
16884         }
16885 #endif
16886
16887         if (ret == -ENOTSUP)
16888                 printf("Function not supported\n");
16889 }
16890
16891 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16892         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16893                                  port, "port");
16894 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16895         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16896                                  cfg, "config");
16897 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16898         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16899                               port_id, UINT16);
16900 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16901         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16902                                  pctype, "pctype");
16903 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16904         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16905                               pctype_id, UINT8);
16906 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16907         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16908                                  inset_type,
16909                                  "hash_inset#fdir_inset#fdir_flx_inset");
16910 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16911         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16912                                  opt, "get#set#clear");
16913 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16914         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16915                                  field, "field");
16916 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16917         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16918                               field_idx, UINT8);
16919
16920 cmdline_parse_inst_t cmd_cfg_input_set = {
16921         .f = cmd_cfg_input_set_parsed,
16922         .data = NULL,
16923         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16924                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16925         .tokens = {
16926                 (void *)&cmd_cfg_input_set_port,
16927                 (void *)&cmd_cfg_input_set_cfg,
16928                 (void *)&cmd_cfg_input_set_port_id,
16929                 (void *)&cmd_cfg_input_set_pctype,
16930                 (void *)&cmd_cfg_input_set_pctype_id,
16931                 (void *)&cmd_cfg_input_set_inset_type,
16932                 (void *)&cmd_cfg_input_set_opt,
16933                 (void *)&cmd_cfg_input_set_field,
16934                 (void *)&cmd_cfg_input_set_field_idx,
16935                 NULL,
16936         },
16937 };
16938
16939 /* Clear input set */
16940 struct cmd_clear_input_set_result {
16941         cmdline_fixed_string_t port;
16942         cmdline_fixed_string_t cfg;
16943         portid_t port_id;
16944         cmdline_fixed_string_t pctype;
16945         uint8_t pctype_id;
16946         cmdline_fixed_string_t inset_type;
16947         cmdline_fixed_string_t clear;
16948         cmdline_fixed_string_t all;
16949 };
16950
16951 static void
16952 cmd_clear_input_set_parsed(
16953         __rte_unused void *parsed_result,
16954         __rte_unused struct cmdline *cl,
16955         __rte_unused void *data)
16956 {
16957 #ifdef RTE_NET_I40E
16958         struct cmd_clear_input_set_result *res = parsed_result;
16959         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16960         struct rte_pmd_i40e_inset inset;
16961 #endif
16962         int ret = -ENOTSUP;
16963
16964         if (!all_ports_stopped()) {
16965                 printf("Please stop all ports first\n");
16966                 return;
16967         }
16968
16969 #ifdef RTE_NET_I40E
16970         if (!strcmp(res->inset_type, "hash_inset"))
16971                 inset_type = INSET_HASH;
16972         else if (!strcmp(res->inset_type, "fdir_inset"))
16973                 inset_type = INSET_FDIR;
16974         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16975                 inset_type = INSET_FDIR_FLX;
16976
16977         memset(&inset, 0, sizeof(inset));
16978
16979         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16980                                      &inset, inset_type);
16981         if (ret) {
16982                 printf("Failed to clear input set.\n");
16983                 return;
16984         }
16985
16986 #endif
16987
16988         if (ret == -ENOTSUP)
16989                 printf("Function not supported\n");
16990 }
16991
16992 cmdline_parse_token_string_t cmd_clear_input_set_port =
16993         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16994                                  port, "port");
16995 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
16996         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
16997                                  cfg, "config");
16998 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
16999         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17000                               port_id, UINT16);
17001 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17002         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17003                                  pctype, "pctype");
17004 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17005         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17006                               pctype_id, UINT8);
17007 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17008         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17009                                  inset_type,
17010                                  "hash_inset#fdir_inset#fdir_flx_inset");
17011 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17012         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17013                                  clear, "clear");
17014 cmdline_parse_token_string_t cmd_clear_input_set_all =
17015         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17016                                  all, "all");
17017
17018 cmdline_parse_inst_t cmd_clear_input_set = {
17019         .f = cmd_clear_input_set_parsed,
17020         .data = NULL,
17021         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17022                     "fdir_inset|fdir_flx_inset clear all",
17023         .tokens = {
17024                 (void *)&cmd_clear_input_set_port,
17025                 (void *)&cmd_clear_input_set_cfg,
17026                 (void *)&cmd_clear_input_set_port_id,
17027                 (void *)&cmd_clear_input_set_pctype,
17028                 (void *)&cmd_clear_input_set_pctype_id,
17029                 (void *)&cmd_clear_input_set_inset_type,
17030                 (void *)&cmd_clear_input_set_clear,
17031                 (void *)&cmd_clear_input_set_all,
17032                 NULL,
17033         },
17034 };
17035
17036 /* show vf stats */
17037
17038 /* Common result structure for show vf stats */
17039 struct cmd_show_vf_stats_result {
17040         cmdline_fixed_string_t show;
17041         cmdline_fixed_string_t vf;
17042         cmdline_fixed_string_t stats;
17043         portid_t port_id;
17044         uint16_t vf_id;
17045 };
17046
17047 /* Common CLI fields show vf stats*/
17048 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17049         TOKEN_STRING_INITIALIZER
17050                 (struct cmd_show_vf_stats_result,
17051                  show, "show");
17052 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17053         TOKEN_STRING_INITIALIZER
17054                 (struct cmd_show_vf_stats_result,
17055                  vf, "vf");
17056 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17057         TOKEN_STRING_INITIALIZER
17058                 (struct cmd_show_vf_stats_result,
17059                  stats, "stats");
17060 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17061         TOKEN_NUM_INITIALIZER
17062                 (struct cmd_show_vf_stats_result,
17063                  port_id, UINT16);
17064 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17065         TOKEN_NUM_INITIALIZER
17066                 (struct cmd_show_vf_stats_result,
17067                  vf_id, UINT16);
17068
17069 static void
17070 cmd_show_vf_stats_parsed(
17071         void *parsed_result,
17072         __rte_unused struct cmdline *cl,
17073         __rte_unused void *data)
17074 {
17075         struct cmd_show_vf_stats_result *res = parsed_result;
17076         struct rte_eth_stats stats;
17077         int ret = -ENOTSUP;
17078         static const char *nic_stats_border = "########################";
17079
17080         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17081                 return;
17082
17083         memset(&stats, 0, sizeof(stats));
17084
17085 #ifdef RTE_NET_I40E
17086         if (ret == -ENOTSUP)
17087                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17088                                                 res->vf_id,
17089                                                 &stats);
17090 #endif
17091 #ifdef RTE_NET_BNXT
17092         if (ret == -ENOTSUP)
17093                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17094                                                 res->vf_id,
17095                                                 &stats);
17096 #endif
17097
17098         switch (ret) {
17099         case 0:
17100                 break;
17101         case -EINVAL:
17102                 printf("invalid vf_id %d\n", res->vf_id);
17103                 break;
17104         case -ENODEV:
17105                 printf("invalid port_id %d\n", res->port_id);
17106                 break;
17107         case -ENOTSUP:
17108                 printf("function not implemented\n");
17109                 break;
17110         default:
17111                 printf("programming error: (%s)\n", strerror(-ret));
17112         }
17113
17114         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17115                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17116
17117         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17118                "%-"PRIu64"\n",
17119                stats.ipackets, stats.imissed, stats.ibytes);
17120         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17121         printf("  RX-nombuf:  %-10"PRIu64"\n",
17122                stats.rx_nombuf);
17123         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17124                "%-"PRIu64"\n",
17125                stats.opackets, stats.oerrors, stats.obytes);
17126
17127         printf("  %s############################%s\n",
17128                                nic_stats_border, nic_stats_border);
17129 }
17130
17131 cmdline_parse_inst_t cmd_show_vf_stats = {
17132         .f = cmd_show_vf_stats_parsed,
17133         .data = NULL,
17134         .help_str = "show vf stats <port_id> <vf_id>",
17135         .tokens = {
17136                 (void *)&cmd_show_vf_stats_show,
17137                 (void *)&cmd_show_vf_stats_vf,
17138                 (void *)&cmd_show_vf_stats_stats,
17139                 (void *)&cmd_show_vf_stats_port_id,
17140                 (void *)&cmd_show_vf_stats_vf_id,
17141                 NULL,
17142         },
17143 };
17144
17145 /* clear vf stats */
17146
17147 /* Common result structure for clear vf stats */
17148 struct cmd_clear_vf_stats_result {
17149         cmdline_fixed_string_t clear;
17150         cmdline_fixed_string_t vf;
17151         cmdline_fixed_string_t stats;
17152         portid_t port_id;
17153         uint16_t vf_id;
17154 };
17155
17156 /* Common CLI fields clear vf stats*/
17157 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17158         TOKEN_STRING_INITIALIZER
17159                 (struct cmd_clear_vf_stats_result,
17160                  clear, "clear");
17161 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17162         TOKEN_STRING_INITIALIZER
17163                 (struct cmd_clear_vf_stats_result,
17164                  vf, "vf");
17165 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17166         TOKEN_STRING_INITIALIZER
17167                 (struct cmd_clear_vf_stats_result,
17168                  stats, "stats");
17169 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17170         TOKEN_NUM_INITIALIZER
17171                 (struct cmd_clear_vf_stats_result,
17172                  port_id, UINT16);
17173 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17174         TOKEN_NUM_INITIALIZER
17175                 (struct cmd_clear_vf_stats_result,
17176                  vf_id, UINT16);
17177
17178 static void
17179 cmd_clear_vf_stats_parsed(
17180         void *parsed_result,
17181         __rte_unused struct cmdline *cl,
17182         __rte_unused void *data)
17183 {
17184         struct cmd_clear_vf_stats_result *res = parsed_result;
17185         int ret = -ENOTSUP;
17186
17187         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17188                 return;
17189
17190 #ifdef RTE_NET_I40E
17191         if (ret == -ENOTSUP)
17192                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17193                                                   res->vf_id);
17194 #endif
17195 #ifdef RTE_NET_BNXT
17196         if (ret == -ENOTSUP)
17197                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17198                                                   res->vf_id);
17199 #endif
17200
17201         switch (ret) {
17202         case 0:
17203                 break;
17204         case -EINVAL:
17205                 printf("invalid vf_id %d\n", res->vf_id);
17206                 break;
17207         case -ENODEV:
17208                 printf("invalid port_id %d\n", res->port_id);
17209                 break;
17210         case -ENOTSUP:
17211                 printf("function not implemented\n");
17212                 break;
17213         default:
17214                 printf("programming error: (%s)\n", strerror(-ret));
17215         }
17216 }
17217
17218 cmdline_parse_inst_t cmd_clear_vf_stats = {
17219         .f = cmd_clear_vf_stats_parsed,
17220         .data = NULL,
17221         .help_str = "clear vf stats <port_id> <vf_id>",
17222         .tokens = {
17223                 (void *)&cmd_clear_vf_stats_clear,
17224                 (void *)&cmd_clear_vf_stats_vf,
17225                 (void *)&cmd_clear_vf_stats_stats,
17226                 (void *)&cmd_clear_vf_stats_port_id,
17227                 (void *)&cmd_clear_vf_stats_vf_id,
17228                 NULL,
17229         },
17230 };
17231
17232 /* port config pctype mapping reset */
17233
17234 /* Common result structure for port config pctype mapping reset */
17235 struct cmd_pctype_mapping_reset_result {
17236         cmdline_fixed_string_t port;
17237         cmdline_fixed_string_t config;
17238         portid_t port_id;
17239         cmdline_fixed_string_t pctype;
17240         cmdline_fixed_string_t mapping;
17241         cmdline_fixed_string_t reset;
17242 };
17243
17244 /* Common CLI fields for port config pctype mapping reset*/
17245 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17246         TOKEN_STRING_INITIALIZER
17247                 (struct cmd_pctype_mapping_reset_result,
17248                  port, "port");
17249 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17250         TOKEN_STRING_INITIALIZER
17251                 (struct cmd_pctype_mapping_reset_result,
17252                  config, "config");
17253 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17254         TOKEN_NUM_INITIALIZER
17255                 (struct cmd_pctype_mapping_reset_result,
17256                  port_id, UINT16);
17257 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17258         TOKEN_STRING_INITIALIZER
17259                 (struct cmd_pctype_mapping_reset_result,
17260                  pctype, "pctype");
17261 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17262         TOKEN_STRING_INITIALIZER
17263                 (struct cmd_pctype_mapping_reset_result,
17264                  mapping, "mapping");
17265 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17266         TOKEN_STRING_INITIALIZER
17267                 (struct cmd_pctype_mapping_reset_result,
17268                  reset, "reset");
17269
17270 static void
17271 cmd_pctype_mapping_reset_parsed(
17272         void *parsed_result,
17273         __rte_unused struct cmdline *cl,
17274         __rte_unused void *data)
17275 {
17276         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17277         int ret = -ENOTSUP;
17278
17279         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17280                 return;
17281
17282 #ifdef RTE_NET_I40E
17283         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17284 #endif
17285
17286         switch (ret) {
17287         case 0:
17288                 break;
17289         case -ENODEV:
17290                 printf("invalid port_id %d\n", res->port_id);
17291                 break;
17292         case -ENOTSUP:
17293                 printf("function not implemented\n");
17294                 break;
17295         default:
17296                 printf("programming error: (%s)\n", strerror(-ret));
17297         }
17298 }
17299
17300 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17301         .f = cmd_pctype_mapping_reset_parsed,
17302         .data = NULL,
17303         .help_str = "port config <port_id> pctype mapping reset",
17304         .tokens = {
17305                 (void *)&cmd_pctype_mapping_reset_port,
17306                 (void *)&cmd_pctype_mapping_reset_config,
17307                 (void *)&cmd_pctype_mapping_reset_port_id,
17308                 (void *)&cmd_pctype_mapping_reset_pctype,
17309                 (void *)&cmd_pctype_mapping_reset_mapping,
17310                 (void *)&cmd_pctype_mapping_reset_reset,
17311                 NULL,
17312         },
17313 };
17314
17315 /* show port pctype mapping */
17316
17317 /* Common result structure for show port pctype mapping */
17318 struct cmd_pctype_mapping_get_result {
17319         cmdline_fixed_string_t show;
17320         cmdline_fixed_string_t port;
17321         portid_t port_id;
17322         cmdline_fixed_string_t pctype;
17323         cmdline_fixed_string_t mapping;
17324 };
17325
17326 /* Common CLI fields for pctype mapping get */
17327 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17328         TOKEN_STRING_INITIALIZER
17329                 (struct cmd_pctype_mapping_get_result,
17330                  show, "show");
17331 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17332         TOKEN_STRING_INITIALIZER
17333                 (struct cmd_pctype_mapping_get_result,
17334                  port, "port");
17335 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17336         TOKEN_NUM_INITIALIZER
17337                 (struct cmd_pctype_mapping_get_result,
17338                  port_id, UINT16);
17339 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17340         TOKEN_STRING_INITIALIZER
17341                 (struct cmd_pctype_mapping_get_result,
17342                  pctype, "pctype");
17343 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17344         TOKEN_STRING_INITIALIZER
17345                 (struct cmd_pctype_mapping_get_result,
17346                  mapping, "mapping");
17347
17348 static void
17349 cmd_pctype_mapping_get_parsed(
17350         void *parsed_result,
17351         __rte_unused struct cmdline *cl,
17352         __rte_unused void *data)
17353 {
17354         struct cmd_pctype_mapping_get_result *res = parsed_result;
17355         int ret = -ENOTSUP;
17356 #ifdef RTE_NET_I40E
17357         struct rte_pmd_i40e_flow_type_mapping
17358                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17359         int i, j, first_pctype;
17360 #endif
17361
17362         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17363                 return;
17364
17365 #ifdef RTE_NET_I40E
17366         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17367 #endif
17368
17369         switch (ret) {
17370         case 0:
17371                 break;
17372         case -ENODEV:
17373                 printf("invalid port_id %d\n", res->port_id);
17374                 return;
17375         case -ENOTSUP:
17376                 printf("function not implemented\n");
17377                 return;
17378         default:
17379                 printf("programming error: (%s)\n", strerror(-ret));
17380                 return;
17381         }
17382
17383 #ifdef RTE_NET_I40E
17384         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17385                 if (mapping[i].pctype != 0ULL) {
17386                         first_pctype = 1;
17387
17388                         printf("pctype: ");
17389                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17390                                 if (mapping[i].pctype & (1ULL << j)) {
17391                                         printf(first_pctype ?
17392                                                "%02d" : ",%02d", j);
17393                                         first_pctype = 0;
17394                                 }
17395                         }
17396                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17397                 }
17398         }
17399 #endif
17400 }
17401
17402 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17403         .f = cmd_pctype_mapping_get_parsed,
17404         .data = NULL,
17405         .help_str = "show port <port_id> pctype mapping",
17406         .tokens = {
17407                 (void *)&cmd_pctype_mapping_get_show,
17408                 (void *)&cmd_pctype_mapping_get_port,
17409                 (void *)&cmd_pctype_mapping_get_port_id,
17410                 (void *)&cmd_pctype_mapping_get_pctype,
17411                 (void *)&cmd_pctype_mapping_get_mapping,
17412                 NULL,
17413         },
17414 };
17415
17416 /* port config pctype mapping update */
17417
17418 /* Common result structure for port config pctype mapping update */
17419 struct cmd_pctype_mapping_update_result {
17420         cmdline_fixed_string_t port;
17421         cmdline_fixed_string_t config;
17422         portid_t port_id;
17423         cmdline_fixed_string_t pctype;
17424         cmdline_fixed_string_t mapping;
17425         cmdline_fixed_string_t update;
17426         cmdline_fixed_string_t pctype_list;
17427         uint16_t flow_type;
17428 };
17429
17430 /* Common CLI fields for pctype mapping update*/
17431 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17432         TOKEN_STRING_INITIALIZER
17433                 (struct cmd_pctype_mapping_update_result,
17434                  port, "port");
17435 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17436         TOKEN_STRING_INITIALIZER
17437                 (struct cmd_pctype_mapping_update_result,
17438                  config, "config");
17439 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17440         TOKEN_NUM_INITIALIZER
17441                 (struct cmd_pctype_mapping_update_result,
17442                  port_id, UINT16);
17443 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17444         TOKEN_STRING_INITIALIZER
17445                 (struct cmd_pctype_mapping_update_result,
17446                  pctype, "pctype");
17447 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17448         TOKEN_STRING_INITIALIZER
17449                 (struct cmd_pctype_mapping_update_result,
17450                  mapping, "mapping");
17451 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17452         TOKEN_STRING_INITIALIZER
17453                 (struct cmd_pctype_mapping_update_result,
17454                  update, "update");
17455 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17456         TOKEN_STRING_INITIALIZER
17457                 (struct cmd_pctype_mapping_update_result,
17458                  pctype_list, NULL);
17459 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17460         TOKEN_NUM_INITIALIZER
17461                 (struct cmd_pctype_mapping_update_result,
17462                  flow_type, UINT16);
17463
17464 static void
17465 cmd_pctype_mapping_update_parsed(
17466         void *parsed_result,
17467         __rte_unused struct cmdline *cl,
17468         __rte_unused void *data)
17469 {
17470         struct cmd_pctype_mapping_update_result *res = parsed_result;
17471         int ret = -ENOTSUP;
17472 #ifdef RTE_NET_I40E
17473         struct rte_pmd_i40e_flow_type_mapping mapping;
17474         unsigned int i;
17475         unsigned int nb_item;
17476         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17477 #endif
17478
17479         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17480                 return;
17481
17482 #ifdef RTE_NET_I40E
17483         nb_item = parse_item_list(res->pctype_list, "pctypes",
17484                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17485         mapping.flow_type = res->flow_type;
17486         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17487                 mapping.pctype |= (1ULL << pctype_list[i]);
17488         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17489                                                 &mapping,
17490                                                 1,
17491                                                 0);
17492 #endif
17493
17494         switch (ret) {
17495         case 0:
17496                 break;
17497         case -EINVAL:
17498                 printf("invalid pctype or flow type\n");
17499                 break;
17500         case -ENODEV:
17501                 printf("invalid port_id %d\n", res->port_id);
17502                 break;
17503         case -ENOTSUP:
17504                 printf("function not implemented\n");
17505                 break;
17506         default:
17507                 printf("programming error: (%s)\n", strerror(-ret));
17508         }
17509 }
17510
17511 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17512         .f = cmd_pctype_mapping_update_parsed,
17513         .data = NULL,
17514         .help_str = "port config <port_id> pctype mapping update"
17515         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17516         .tokens = {
17517                 (void *)&cmd_pctype_mapping_update_port,
17518                 (void *)&cmd_pctype_mapping_update_config,
17519                 (void *)&cmd_pctype_mapping_update_port_id,
17520                 (void *)&cmd_pctype_mapping_update_pctype,
17521                 (void *)&cmd_pctype_mapping_update_mapping,
17522                 (void *)&cmd_pctype_mapping_update_update,
17523                 (void *)&cmd_pctype_mapping_update_pc_type,
17524                 (void *)&cmd_pctype_mapping_update_flow_type,
17525                 NULL,
17526         },
17527 };
17528
17529 /* ptype mapping get */
17530
17531 /* Common result structure for ptype mapping get */
17532 struct cmd_ptype_mapping_get_result {
17533         cmdline_fixed_string_t ptype;
17534         cmdline_fixed_string_t mapping;
17535         cmdline_fixed_string_t get;
17536         portid_t port_id;
17537         uint8_t valid_only;
17538 };
17539
17540 /* Common CLI fields for ptype mapping get */
17541 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17542         TOKEN_STRING_INITIALIZER
17543                 (struct cmd_ptype_mapping_get_result,
17544                  ptype, "ptype");
17545 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17546         TOKEN_STRING_INITIALIZER
17547                 (struct cmd_ptype_mapping_get_result,
17548                  mapping, "mapping");
17549 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17550         TOKEN_STRING_INITIALIZER
17551                 (struct cmd_ptype_mapping_get_result,
17552                  get, "get");
17553 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17554         TOKEN_NUM_INITIALIZER
17555                 (struct cmd_ptype_mapping_get_result,
17556                  port_id, UINT16);
17557 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17558         TOKEN_NUM_INITIALIZER
17559                 (struct cmd_ptype_mapping_get_result,
17560                  valid_only, UINT8);
17561
17562 static void
17563 cmd_ptype_mapping_get_parsed(
17564         void *parsed_result,
17565         __rte_unused struct cmdline *cl,
17566         __rte_unused void *data)
17567 {
17568         struct cmd_ptype_mapping_get_result *res = parsed_result;
17569         int ret = -ENOTSUP;
17570 #ifdef RTE_NET_I40E
17571         int max_ptype_num = 256;
17572         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17573         uint16_t count;
17574         int i;
17575 #endif
17576
17577         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17578                 return;
17579
17580 #ifdef RTE_NET_I40E
17581         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17582                                         mapping,
17583                                         max_ptype_num,
17584                                         &count,
17585                                         res->valid_only);
17586 #endif
17587
17588         switch (ret) {
17589         case 0:
17590                 break;
17591         case -ENODEV:
17592                 printf("invalid port_id %d\n", res->port_id);
17593                 break;
17594         case -ENOTSUP:
17595                 printf("function not implemented\n");
17596                 break;
17597         default:
17598                 printf("programming error: (%s)\n", strerror(-ret));
17599         }
17600
17601 #ifdef RTE_NET_I40E
17602         if (!ret) {
17603                 for (i = 0; i < count; i++)
17604                         printf("%3d\t0x%08x\n",
17605                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17606         }
17607 #endif
17608 }
17609
17610 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17611         .f = cmd_ptype_mapping_get_parsed,
17612         .data = NULL,
17613         .help_str = "ptype mapping get <port_id> <valid_only>",
17614         .tokens = {
17615                 (void *)&cmd_ptype_mapping_get_ptype,
17616                 (void *)&cmd_ptype_mapping_get_mapping,
17617                 (void *)&cmd_ptype_mapping_get_get,
17618                 (void *)&cmd_ptype_mapping_get_port_id,
17619                 (void *)&cmd_ptype_mapping_get_valid_only,
17620                 NULL,
17621         },
17622 };
17623
17624 /* ptype mapping replace */
17625
17626 /* Common result structure for ptype mapping replace */
17627 struct cmd_ptype_mapping_replace_result {
17628         cmdline_fixed_string_t ptype;
17629         cmdline_fixed_string_t mapping;
17630         cmdline_fixed_string_t replace;
17631         portid_t port_id;
17632         uint32_t target;
17633         uint8_t mask;
17634         uint32_t pkt_type;
17635 };
17636
17637 /* Common CLI fields for ptype mapping replace */
17638 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17639         TOKEN_STRING_INITIALIZER
17640                 (struct cmd_ptype_mapping_replace_result,
17641                  ptype, "ptype");
17642 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17643         TOKEN_STRING_INITIALIZER
17644                 (struct cmd_ptype_mapping_replace_result,
17645                  mapping, "mapping");
17646 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17647         TOKEN_STRING_INITIALIZER
17648                 (struct cmd_ptype_mapping_replace_result,
17649                  replace, "replace");
17650 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17651         TOKEN_NUM_INITIALIZER
17652                 (struct cmd_ptype_mapping_replace_result,
17653                  port_id, UINT16);
17654 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17655         TOKEN_NUM_INITIALIZER
17656                 (struct cmd_ptype_mapping_replace_result,
17657                  target, UINT32);
17658 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17659         TOKEN_NUM_INITIALIZER
17660                 (struct cmd_ptype_mapping_replace_result,
17661                  mask, UINT8);
17662 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17663         TOKEN_NUM_INITIALIZER
17664                 (struct cmd_ptype_mapping_replace_result,
17665                  pkt_type, UINT32);
17666
17667 static void
17668 cmd_ptype_mapping_replace_parsed(
17669         void *parsed_result,
17670         __rte_unused struct cmdline *cl,
17671         __rte_unused void *data)
17672 {
17673         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17674         int ret = -ENOTSUP;
17675
17676         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17677                 return;
17678
17679 #ifdef RTE_NET_I40E
17680         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17681                                         res->target,
17682                                         res->mask,
17683                                         res->pkt_type);
17684 #endif
17685
17686         switch (ret) {
17687         case 0:
17688                 break;
17689         case -EINVAL:
17690                 printf("invalid ptype 0x%8x or 0x%8x\n",
17691                                 res->target, res->pkt_type);
17692                 break;
17693         case -ENODEV:
17694                 printf("invalid port_id %d\n", res->port_id);
17695                 break;
17696         case -ENOTSUP:
17697                 printf("function not implemented\n");
17698                 break;
17699         default:
17700                 printf("programming error: (%s)\n", strerror(-ret));
17701         }
17702 }
17703
17704 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17705         .f = cmd_ptype_mapping_replace_parsed,
17706         .data = NULL,
17707         .help_str =
17708                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17709         .tokens = {
17710                 (void *)&cmd_ptype_mapping_replace_ptype,
17711                 (void *)&cmd_ptype_mapping_replace_mapping,
17712                 (void *)&cmd_ptype_mapping_replace_replace,
17713                 (void *)&cmd_ptype_mapping_replace_port_id,
17714                 (void *)&cmd_ptype_mapping_replace_target,
17715                 (void *)&cmd_ptype_mapping_replace_mask,
17716                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17717                 NULL,
17718         },
17719 };
17720
17721 /* ptype mapping reset */
17722
17723 /* Common result structure for ptype mapping reset */
17724 struct cmd_ptype_mapping_reset_result {
17725         cmdline_fixed_string_t ptype;
17726         cmdline_fixed_string_t mapping;
17727         cmdline_fixed_string_t reset;
17728         portid_t port_id;
17729 };
17730
17731 /* Common CLI fields for ptype mapping reset*/
17732 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17733         TOKEN_STRING_INITIALIZER
17734                 (struct cmd_ptype_mapping_reset_result,
17735                  ptype, "ptype");
17736 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17737         TOKEN_STRING_INITIALIZER
17738                 (struct cmd_ptype_mapping_reset_result,
17739                  mapping, "mapping");
17740 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17741         TOKEN_STRING_INITIALIZER
17742                 (struct cmd_ptype_mapping_reset_result,
17743                  reset, "reset");
17744 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17745         TOKEN_NUM_INITIALIZER
17746                 (struct cmd_ptype_mapping_reset_result,
17747                  port_id, UINT16);
17748
17749 static void
17750 cmd_ptype_mapping_reset_parsed(
17751         void *parsed_result,
17752         __rte_unused struct cmdline *cl,
17753         __rte_unused void *data)
17754 {
17755         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17756         int ret = -ENOTSUP;
17757
17758         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17759                 return;
17760
17761 #ifdef RTE_NET_I40E
17762         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17763 #endif
17764
17765         switch (ret) {
17766         case 0:
17767                 break;
17768         case -ENODEV:
17769                 printf("invalid port_id %d\n", res->port_id);
17770                 break;
17771         case -ENOTSUP:
17772                 printf("function not implemented\n");
17773                 break;
17774         default:
17775                 printf("programming error: (%s)\n", strerror(-ret));
17776         }
17777 }
17778
17779 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17780         .f = cmd_ptype_mapping_reset_parsed,
17781         .data = NULL,
17782         .help_str = "ptype mapping reset <port_id>",
17783         .tokens = {
17784                 (void *)&cmd_ptype_mapping_reset_ptype,
17785                 (void *)&cmd_ptype_mapping_reset_mapping,
17786                 (void *)&cmd_ptype_mapping_reset_reset,
17787                 (void *)&cmd_ptype_mapping_reset_port_id,
17788                 NULL,
17789         },
17790 };
17791
17792 /* ptype mapping update */
17793
17794 /* Common result structure for ptype mapping update */
17795 struct cmd_ptype_mapping_update_result {
17796         cmdline_fixed_string_t ptype;
17797         cmdline_fixed_string_t mapping;
17798         cmdline_fixed_string_t reset;
17799         portid_t port_id;
17800         uint8_t hw_ptype;
17801         uint32_t sw_ptype;
17802 };
17803
17804 /* Common CLI fields for ptype mapping update*/
17805 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17806         TOKEN_STRING_INITIALIZER
17807                 (struct cmd_ptype_mapping_update_result,
17808                  ptype, "ptype");
17809 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17810         TOKEN_STRING_INITIALIZER
17811                 (struct cmd_ptype_mapping_update_result,
17812                  mapping, "mapping");
17813 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17814         TOKEN_STRING_INITIALIZER
17815                 (struct cmd_ptype_mapping_update_result,
17816                  reset, "update");
17817 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17818         TOKEN_NUM_INITIALIZER
17819                 (struct cmd_ptype_mapping_update_result,
17820                  port_id, UINT16);
17821 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17822         TOKEN_NUM_INITIALIZER
17823                 (struct cmd_ptype_mapping_update_result,
17824                  hw_ptype, UINT8);
17825 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17826         TOKEN_NUM_INITIALIZER
17827                 (struct cmd_ptype_mapping_update_result,
17828                  sw_ptype, UINT32);
17829
17830 static void
17831 cmd_ptype_mapping_update_parsed(
17832         void *parsed_result,
17833         __rte_unused struct cmdline *cl,
17834         __rte_unused void *data)
17835 {
17836         struct cmd_ptype_mapping_update_result *res = parsed_result;
17837         int ret = -ENOTSUP;
17838 #ifdef RTE_NET_I40E
17839         struct rte_pmd_i40e_ptype_mapping mapping;
17840 #endif
17841         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17842                 return;
17843
17844 #ifdef RTE_NET_I40E
17845         mapping.hw_ptype = res->hw_ptype;
17846         mapping.sw_ptype = res->sw_ptype;
17847         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17848                                                 &mapping,
17849                                                 1,
17850                                                 0);
17851 #endif
17852
17853         switch (ret) {
17854         case 0:
17855                 break;
17856         case -EINVAL:
17857                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17858                 break;
17859         case -ENODEV:
17860                 printf("invalid port_id %d\n", res->port_id);
17861                 break;
17862         case -ENOTSUP:
17863                 printf("function not implemented\n");
17864                 break;
17865         default:
17866                 printf("programming error: (%s)\n", strerror(-ret));
17867         }
17868 }
17869
17870 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17871         .f = cmd_ptype_mapping_update_parsed,
17872         .data = NULL,
17873         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17874         .tokens = {
17875                 (void *)&cmd_ptype_mapping_update_ptype,
17876                 (void *)&cmd_ptype_mapping_update_mapping,
17877                 (void *)&cmd_ptype_mapping_update_update,
17878                 (void *)&cmd_ptype_mapping_update_port_id,
17879                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17880                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17881                 NULL,
17882         },
17883 };
17884
17885 /* Common result structure for file commands */
17886 struct cmd_cmdfile_result {
17887         cmdline_fixed_string_t load;
17888         cmdline_fixed_string_t filename;
17889 };
17890
17891 /* Common CLI fields for file commands */
17892 cmdline_parse_token_string_t cmd_load_cmdfile =
17893         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17894 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17895         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17896
17897 static void
17898 cmd_load_from_file_parsed(
17899         void *parsed_result,
17900         __rte_unused struct cmdline *cl,
17901         __rte_unused void *data)
17902 {
17903         struct cmd_cmdfile_result *res = parsed_result;
17904
17905         cmdline_read_from_file(res->filename);
17906 }
17907
17908 cmdline_parse_inst_t cmd_load_from_file = {
17909         .f = cmd_load_from_file_parsed,
17910         .data = NULL,
17911         .help_str = "load <filename>",
17912         .tokens = {
17913                 (void *)&cmd_load_cmdfile,
17914                 (void *)&cmd_load_cmdfile_filename,
17915                 NULL,
17916         },
17917 };
17918
17919 /* Get Rx offloads capabilities */
17920 struct cmd_rx_offload_get_capa_result {
17921         cmdline_fixed_string_t show;
17922         cmdline_fixed_string_t port;
17923         portid_t port_id;
17924         cmdline_fixed_string_t rx_offload;
17925         cmdline_fixed_string_t capabilities;
17926 };
17927
17928 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17929         TOKEN_STRING_INITIALIZER
17930                 (struct cmd_rx_offload_get_capa_result,
17931                  show, "show");
17932 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17933         TOKEN_STRING_INITIALIZER
17934                 (struct cmd_rx_offload_get_capa_result,
17935                  port, "port");
17936 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
17937         TOKEN_NUM_INITIALIZER
17938                 (struct cmd_rx_offload_get_capa_result,
17939                  port_id, UINT16);
17940 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
17941         TOKEN_STRING_INITIALIZER
17942                 (struct cmd_rx_offload_get_capa_result,
17943                  rx_offload, "rx_offload");
17944 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
17945         TOKEN_STRING_INITIALIZER
17946                 (struct cmd_rx_offload_get_capa_result,
17947                  capabilities, "capabilities");
17948
17949 static void
17950 print_rx_offloads(uint64_t offloads)
17951 {
17952         uint64_t single_offload;
17953         int begin;
17954         int end;
17955         int bit;
17956
17957         if (offloads == 0)
17958                 return;
17959
17960         begin = __builtin_ctzll(offloads);
17961         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17962
17963         single_offload = 1ULL << begin;
17964         for (bit = begin; bit < end; bit++) {
17965                 if (offloads & single_offload)
17966                         printf(" %s",
17967                                rte_eth_dev_rx_offload_name(single_offload));
17968                 single_offload <<= 1;
17969         }
17970 }
17971
17972 static void
17973 cmd_rx_offload_get_capa_parsed(
17974         void *parsed_result,
17975         __rte_unused struct cmdline *cl,
17976         __rte_unused void *data)
17977 {
17978         struct cmd_rx_offload_get_capa_result *res = parsed_result;
17979         struct rte_eth_dev_info dev_info;
17980         portid_t port_id = res->port_id;
17981         uint64_t queue_offloads;
17982         uint64_t port_offloads;
17983         int ret;
17984
17985         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17986         if (ret != 0)
17987                 return;
17988
17989         queue_offloads = dev_info.rx_queue_offload_capa;
17990         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
17991
17992         printf("Rx Offloading Capabilities of port %d :\n", port_id);
17993         printf("  Per Queue :");
17994         print_rx_offloads(queue_offloads);
17995
17996         printf("\n");
17997         printf("  Per Port  :");
17998         print_rx_offloads(port_offloads);
17999         printf("\n\n");
18000 }
18001
18002 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18003         .f = cmd_rx_offload_get_capa_parsed,
18004         .data = NULL,
18005         .help_str = "show port <port_id> rx_offload capabilities",
18006         .tokens = {
18007                 (void *)&cmd_rx_offload_get_capa_show,
18008                 (void *)&cmd_rx_offload_get_capa_port,
18009                 (void *)&cmd_rx_offload_get_capa_port_id,
18010                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18011                 (void *)&cmd_rx_offload_get_capa_capabilities,
18012                 NULL,
18013         }
18014 };
18015
18016 /* Get Rx offloads configuration */
18017 struct cmd_rx_offload_get_configuration_result {
18018         cmdline_fixed_string_t show;
18019         cmdline_fixed_string_t port;
18020         portid_t port_id;
18021         cmdline_fixed_string_t rx_offload;
18022         cmdline_fixed_string_t configuration;
18023 };
18024
18025 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18026         TOKEN_STRING_INITIALIZER
18027                 (struct cmd_rx_offload_get_configuration_result,
18028                  show, "show");
18029 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18030         TOKEN_STRING_INITIALIZER
18031                 (struct cmd_rx_offload_get_configuration_result,
18032                  port, "port");
18033 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18034         TOKEN_NUM_INITIALIZER
18035                 (struct cmd_rx_offload_get_configuration_result,
18036                  port_id, UINT16);
18037 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18038         TOKEN_STRING_INITIALIZER
18039                 (struct cmd_rx_offload_get_configuration_result,
18040                  rx_offload, "rx_offload");
18041 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18042         TOKEN_STRING_INITIALIZER
18043                 (struct cmd_rx_offload_get_configuration_result,
18044                  configuration, "configuration");
18045
18046 static void
18047 cmd_rx_offload_get_configuration_parsed(
18048         void *parsed_result,
18049         __rte_unused struct cmdline *cl,
18050         __rte_unused void *data)
18051 {
18052         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18053         struct rte_eth_dev_info dev_info;
18054         portid_t port_id = res->port_id;
18055         struct rte_port *port = &ports[port_id];
18056         uint64_t port_offloads;
18057         uint64_t queue_offloads;
18058         uint16_t nb_rx_queues;
18059         int q;
18060         int ret;
18061
18062         printf("Rx Offloading Configuration of port %d :\n", port_id);
18063
18064         port_offloads = port->dev_conf.rxmode.offloads;
18065         printf("  Port :");
18066         print_rx_offloads(port_offloads);
18067         printf("\n");
18068
18069         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18070         if (ret != 0)
18071                 return;
18072
18073         nb_rx_queues = dev_info.nb_rx_queues;
18074         for (q = 0; q < nb_rx_queues; q++) {
18075                 queue_offloads = port->rx_conf[q].offloads;
18076                 printf("  Queue[%2d] :", q);
18077                 print_rx_offloads(queue_offloads);
18078                 printf("\n");
18079         }
18080         printf("\n");
18081 }
18082
18083 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18084         .f = cmd_rx_offload_get_configuration_parsed,
18085         .data = NULL,
18086         .help_str = "show port <port_id> rx_offload configuration",
18087         .tokens = {
18088                 (void *)&cmd_rx_offload_get_configuration_show,
18089                 (void *)&cmd_rx_offload_get_configuration_port,
18090                 (void *)&cmd_rx_offload_get_configuration_port_id,
18091                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18092                 (void *)&cmd_rx_offload_get_configuration_configuration,
18093                 NULL,
18094         }
18095 };
18096
18097 /* Enable/Disable a per port offloading */
18098 struct cmd_config_per_port_rx_offload_result {
18099         cmdline_fixed_string_t port;
18100         cmdline_fixed_string_t config;
18101         portid_t port_id;
18102         cmdline_fixed_string_t rx_offload;
18103         cmdline_fixed_string_t offload;
18104         cmdline_fixed_string_t on_off;
18105 };
18106
18107 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18108         TOKEN_STRING_INITIALIZER
18109                 (struct cmd_config_per_port_rx_offload_result,
18110                  port, "port");
18111 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18112         TOKEN_STRING_INITIALIZER
18113                 (struct cmd_config_per_port_rx_offload_result,
18114                  config, "config");
18115 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18116         TOKEN_NUM_INITIALIZER
18117                 (struct cmd_config_per_port_rx_offload_result,
18118                  port_id, UINT16);
18119 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18120         TOKEN_STRING_INITIALIZER
18121                 (struct cmd_config_per_port_rx_offload_result,
18122                  rx_offload, "rx_offload");
18123 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18124         TOKEN_STRING_INITIALIZER
18125                 (struct cmd_config_per_port_rx_offload_result,
18126                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18127                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18128                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18129                            "scatter#buffer_split#timestamp#security#"
18130                            "keep_crc#rss_hash");
18131 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18132         TOKEN_STRING_INITIALIZER
18133                 (struct cmd_config_per_port_rx_offload_result,
18134                  on_off, "on#off");
18135
18136 static uint64_t
18137 search_rx_offload(const char *name)
18138 {
18139         uint64_t single_offload;
18140         const char *single_name;
18141         int found = 0;
18142         unsigned int bit;
18143
18144         single_offload = 1;
18145         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18146                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18147                 if (!strcasecmp(single_name, name)) {
18148                         found = 1;
18149                         break;
18150                 }
18151                 single_offload <<= 1;
18152         }
18153
18154         if (found)
18155                 return single_offload;
18156
18157         return 0;
18158 }
18159
18160 static void
18161 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18162                                 __rte_unused struct cmdline *cl,
18163                                 __rte_unused void *data)
18164 {
18165         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18166         portid_t port_id = res->port_id;
18167         struct rte_eth_dev_info dev_info;
18168         struct rte_port *port = &ports[port_id];
18169         uint64_t single_offload;
18170         uint16_t nb_rx_queues;
18171         int q;
18172         int ret;
18173
18174         if (port->port_status != RTE_PORT_STOPPED) {
18175                 printf("Error: Can't config offload when Port %d "
18176                        "is not stopped\n", port_id);
18177                 return;
18178         }
18179
18180         single_offload = search_rx_offload(res->offload);
18181         if (single_offload == 0) {
18182                 printf("Unknown offload name: %s\n", res->offload);
18183                 return;
18184         }
18185
18186         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18187         if (ret != 0)
18188                 return;
18189
18190         nb_rx_queues = dev_info.nb_rx_queues;
18191         if (!strcmp(res->on_off, "on")) {
18192                 port->dev_conf.rxmode.offloads |= single_offload;
18193                 for (q = 0; q < nb_rx_queues; q++)
18194                         port->rx_conf[q].offloads |= single_offload;
18195         } else {
18196                 port->dev_conf.rxmode.offloads &= ~single_offload;
18197                 for (q = 0; q < nb_rx_queues; q++)
18198                         port->rx_conf[q].offloads &= ~single_offload;
18199         }
18200
18201         cmd_reconfig_device_queue(port_id, 1, 1);
18202 }
18203
18204 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18205         .f = cmd_config_per_port_rx_offload_parsed,
18206         .data = NULL,
18207         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18208                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18209                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18210                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
18211                     "keep_crc|rss_hash on|off",
18212         .tokens = {
18213                 (void *)&cmd_config_per_port_rx_offload_result_port,
18214                 (void *)&cmd_config_per_port_rx_offload_result_config,
18215                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18216                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18217                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18218                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18219                 NULL,
18220         }
18221 };
18222
18223 /* Enable/Disable a per queue offloading */
18224 struct cmd_config_per_queue_rx_offload_result {
18225         cmdline_fixed_string_t port;
18226         portid_t port_id;
18227         cmdline_fixed_string_t rxq;
18228         uint16_t queue_id;
18229         cmdline_fixed_string_t rx_offload;
18230         cmdline_fixed_string_t offload;
18231         cmdline_fixed_string_t on_off;
18232 };
18233
18234 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18235         TOKEN_STRING_INITIALIZER
18236                 (struct cmd_config_per_queue_rx_offload_result,
18237                  port, "port");
18238 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18239         TOKEN_NUM_INITIALIZER
18240                 (struct cmd_config_per_queue_rx_offload_result,
18241                  port_id, UINT16);
18242 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18243         TOKEN_STRING_INITIALIZER
18244                 (struct cmd_config_per_queue_rx_offload_result,
18245                  rxq, "rxq");
18246 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18247         TOKEN_NUM_INITIALIZER
18248                 (struct cmd_config_per_queue_rx_offload_result,
18249                  queue_id, UINT16);
18250 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18251         TOKEN_STRING_INITIALIZER
18252                 (struct cmd_config_per_queue_rx_offload_result,
18253                  rx_offload, "rx_offload");
18254 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18255         TOKEN_STRING_INITIALIZER
18256                 (struct cmd_config_per_queue_rx_offload_result,
18257                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18258                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18259                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18260                            "scatter#buffer_split#timestamp#security#keep_crc");
18261 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18262         TOKEN_STRING_INITIALIZER
18263                 (struct cmd_config_per_queue_rx_offload_result,
18264                  on_off, "on#off");
18265
18266 static void
18267 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18268                                 __rte_unused struct cmdline *cl,
18269                                 __rte_unused void *data)
18270 {
18271         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18272         struct rte_eth_dev_info dev_info;
18273         portid_t port_id = res->port_id;
18274         uint16_t queue_id = res->queue_id;
18275         struct rte_port *port = &ports[port_id];
18276         uint64_t single_offload;
18277         int ret;
18278
18279         if (port->port_status != RTE_PORT_STOPPED) {
18280                 printf("Error: Can't config offload when Port %d "
18281                        "is not stopped\n", port_id);
18282                 return;
18283         }
18284
18285         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18286         if (ret != 0)
18287                 return;
18288
18289         if (queue_id >= dev_info.nb_rx_queues) {
18290                 printf("Error: input queue_id should be 0 ... "
18291                        "%d\n", dev_info.nb_rx_queues - 1);
18292                 return;
18293         }
18294
18295         single_offload = search_rx_offload(res->offload);
18296         if (single_offload == 0) {
18297                 printf("Unknown offload name: %s\n", res->offload);
18298                 return;
18299         }
18300
18301         if (!strcmp(res->on_off, "on"))
18302                 port->rx_conf[queue_id].offloads |= single_offload;
18303         else
18304                 port->rx_conf[queue_id].offloads &= ~single_offload;
18305
18306         cmd_reconfig_device_queue(port_id, 1, 1);
18307 }
18308
18309 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18310         .f = cmd_config_per_queue_rx_offload_parsed,
18311         .data = NULL,
18312         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18313                     "vlan_strip|ipv4_cksum|"
18314                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18315                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18316                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
18317                     "keep_crc on|off",
18318         .tokens = {
18319                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18320                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18321                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18322                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18323                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18324                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18325                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18326                 NULL,
18327         }
18328 };
18329
18330 /* Get Tx offloads capabilities */
18331 struct cmd_tx_offload_get_capa_result {
18332         cmdline_fixed_string_t show;
18333         cmdline_fixed_string_t port;
18334         portid_t port_id;
18335         cmdline_fixed_string_t tx_offload;
18336         cmdline_fixed_string_t capabilities;
18337 };
18338
18339 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18340         TOKEN_STRING_INITIALIZER
18341                 (struct cmd_tx_offload_get_capa_result,
18342                  show, "show");
18343 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18344         TOKEN_STRING_INITIALIZER
18345                 (struct cmd_tx_offload_get_capa_result,
18346                  port, "port");
18347 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18348         TOKEN_NUM_INITIALIZER
18349                 (struct cmd_tx_offload_get_capa_result,
18350                  port_id, UINT16);
18351 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18352         TOKEN_STRING_INITIALIZER
18353                 (struct cmd_tx_offload_get_capa_result,
18354                  tx_offload, "tx_offload");
18355 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18356         TOKEN_STRING_INITIALIZER
18357                 (struct cmd_tx_offload_get_capa_result,
18358                  capabilities, "capabilities");
18359
18360 static void
18361 print_tx_offloads(uint64_t offloads)
18362 {
18363         uint64_t single_offload;
18364         int begin;
18365         int end;
18366         int bit;
18367
18368         if (offloads == 0)
18369                 return;
18370
18371         begin = __builtin_ctzll(offloads);
18372         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18373
18374         single_offload = 1ULL << begin;
18375         for (bit = begin; bit < end; bit++) {
18376                 if (offloads & single_offload)
18377                         printf(" %s",
18378                                rte_eth_dev_tx_offload_name(single_offload));
18379                 single_offload <<= 1;
18380         }
18381 }
18382
18383 static void
18384 cmd_tx_offload_get_capa_parsed(
18385         void *parsed_result,
18386         __rte_unused struct cmdline *cl,
18387         __rte_unused void *data)
18388 {
18389         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18390         struct rte_eth_dev_info dev_info;
18391         portid_t port_id = res->port_id;
18392         uint64_t queue_offloads;
18393         uint64_t port_offloads;
18394         int ret;
18395
18396         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18397         if (ret != 0)
18398                 return;
18399
18400         queue_offloads = dev_info.tx_queue_offload_capa;
18401         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18402
18403         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18404         printf("  Per Queue :");
18405         print_tx_offloads(queue_offloads);
18406
18407         printf("\n");
18408         printf("  Per Port  :");
18409         print_tx_offloads(port_offloads);
18410         printf("\n\n");
18411 }
18412
18413 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18414         .f = cmd_tx_offload_get_capa_parsed,
18415         .data = NULL,
18416         .help_str = "show port <port_id> tx_offload capabilities",
18417         .tokens = {
18418                 (void *)&cmd_tx_offload_get_capa_show,
18419                 (void *)&cmd_tx_offload_get_capa_port,
18420                 (void *)&cmd_tx_offload_get_capa_port_id,
18421                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18422                 (void *)&cmd_tx_offload_get_capa_capabilities,
18423                 NULL,
18424         }
18425 };
18426
18427 /* Get Tx offloads configuration */
18428 struct cmd_tx_offload_get_configuration_result {
18429         cmdline_fixed_string_t show;
18430         cmdline_fixed_string_t port;
18431         portid_t port_id;
18432         cmdline_fixed_string_t tx_offload;
18433         cmdline_fixed_string_t configuration;
18434 };
18435
18436 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18437         TOKEN_STRING_INITIALIZER
18438                 (struct cmd_tx_offload_get_configuration_result,
18439                  show, "show");
18440 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18441         TOKEN_STRING_INITIALIZER
18442                 (struct cmd_tx_offload_get_configuration_result,
18443                  port, "port");
18444 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18445         TOKEN_NUM_INITIALIZER
18446                 (struct cmd_tx_offload_get_configuration_result,
18447                  port_id, UINT16);
18448 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18449         TOKEN_STRING_INITIALIZER
18450                 (struct cmd_tx_offload_get_configuration_result,
18451                  tx_offload, "tx_offload");
18452 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18453         TOKEN_STRING_INITIALIZER
18454                 (struct cmd_tx_offload_get_configuration_result,
18455                  configuration, "configuration");
18456
18457 static void
18458 cmd_tx_offload_get_configuration_parsed(
18459         void *parsed_result,
18460         __rte_unused struct cmdline *cl,
18461         __rte_unused void *data)
18462 {
18463         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18464         struct rte_eth_dev_info dev_info;
18465         portid_t port_id = res->port_id;
18466         struct rte_port *port = &ports[port_id];
18467         uint64_t port_offloads;
18468         uint64_t queue_offloads;
18469         uint16_t nb_tx_queues;
18470         int q;
18471         int ret;
18472
18473         printf("Tx Offloading Configuration of port %d :\n", port_id);
18474
18475         port_offloads = port->dev_conf.txmode.offloads;
18476         printf("  Port :");
18477         print_tx_offloads(port_offloads);
18478         printf("\n");
18479
18480         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18481         if (ret != 0)
18482                 return;
18483
18484         nb_tx_queues = dev_info.nb_tx_queues;
18485         for (q = 0; q < nb_tx_queues; q++) {
18486                 queue_offloads = port->tx_conf[q].offloads;
18487                 printf("  Queue[%2d] :", q);
18488                 print_tx_offloads(queue_offloads);
18489                 printf("\n");
18490         }
18491         printf("\n");
18492 }
18493
18494 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18495         .f = cmd_tx_offload_get_configuration_parsed,
18496         .data = NULL,
18497         .help_str = "show port <port_id> tx_offload configuration",
18498         .tokens = {
18499                 (void *)&cmd_tx_offload_get_configuration_show,
18500                 (void *)&cmd_tx_offload_get_configuration_port,
18501                 (void *)&cmd_tx_offload_get_configuration_port_id,
18502                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18503                 (void *)&cmd_tx_offload_get_configuration_configuration,
18504                 NULL,
18505         }
18506 };
18507
18508 /* Enable/Disable a per port offloading */
18509 struct cmd_config_per_port_tx_offload_result {
18510         cmdline_fixed_string_t port;
18511         cmdline_fixed_string_t config;
18512         portid_t port_id;
18513         cmdline_fixed_string_t tx_offload;
18514         cmdline_fixed_string_t offload;
18515         cmdline_fixed_string_t on_off;
18516 };
18517
18518 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18519         TOKEN_STRING_INITIALIZER
18520                 (struct cmd_config_per_port_tx_offload_result,
18521                  port, "port");
18522 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18523         TOKEN_STRING_INITIALIZER
18524                 (struct cmd_config_per_port_tx_offload_result,
18525                  config, "config");
18526 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18527         TOKEN_NUM_INITIALIZER
18528                 (struct cmd_config_per_port_tx_offload_result,
18529                  port_id, UINT16);
18530 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18531         TOKEN_STRING_INITIALIZER
18532                 (struct cmd_config_per_port_tx_offload_result,
18533                  tx_offload, "tx_offload");
18534 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18535         TOKEN_STRING_INITIALIZER
18536                 (struct cmd_config_per_port_tx_offload_result,
18537                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18538                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18539                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18540                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18541                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18542                           "send_on_timestamp");
18543 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18544         TOKEN_STRING_INITIALIZER
18545                 (struct cmd_config_per_port_tx_offload_result,
18546                  on_off, "on#off");
18547
18548 static uint64_t
18549 search_tx_offload(const char *name)
18550 {
18551         uint64_t single_offload;
18552         const char *single_name;
18553         int found = 0;
18554         unsigned int bit;
18555
18556         single_offload = 1;
18557         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18558                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18559                 if (single_name == NULL)
18560                         break;
18561                 if (!strcasecmp(single_name, name)) {
18562                         found = 1;
18563                         break;
18564                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18565                         break;
18566                 single_offload <<= 1;
18567         }
18568
18569         if (found)
18570                 return single_offload;
18571
18572         return 0;
18573 }
18574
18575 static void
18576 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18577                                 __rte_unused struct cmdline *cl,
18578                                 __rte_unused void *data)
18579 {
18580         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18581         portid_t port_id = res->port_id;
18582         struct rte_eth_dev_info dev_info;
18583         struct rte_port *port = &ports[port_id];
18584         uint64_t single_offload;
18585         uint16_t nb_tx_queues;
18586         int q;
18587         int ret;
18588
18589         if (port->port_status != RTE_PORT_STOPPED) {
18590                 printf("Error: Can't config offload when Port %d "
18591                        "is not stopped\n", port_id);
18592                 return;
18593         }
18594
18595         single_offload = search_tx_offload(res->offload);
18596         if (single_offload == 0) {
18597                 printf("Unknown offload name: %s\n", res->offload);
18598                 return;
18599         }
18600
18601         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18602         if (ret != 0)
18603                 return;
18604
18605         nb_tx_queues = dev_info.nb_tx_queues;
18606         if (!strcmp(res->on_off, "on")) {
18607                 port->dev_conf.txmode.offloads |= single_offload;
18608                 for (q = 0; q < nb_tx_queues; q++)
18609                         port->tx_conf[q].offloads |= single_offload;
18610         } else {
18611                 port->dev_conf.txmode.offloads &= ~single_offload;
18612                 for (q = 0; q < nb_tx_queues; q++)
18613                         port->tx_conf[q].offloads &= ~single_offload;
18614         }
18615
18616         cmd_reconfig_device_queue(port_id, 1, 1);
18617 }
18618
18619 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18620         .f = cmd_config_per_port_tx_offload_parsed,
18621         .data = NULL,
18622         .help_str = "port config <port_id> tx_offload "
18623                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18624                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18625                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18626                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18627                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18628                     "send_on_timestamp on|off",
18629         .tokens = {
18630                 (void *)&cmd_config_per_port_tx_offload_result_port,
18631                 (void *)&cmd_config_per_port_tx_offload_result_config,
18632                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18633                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18634                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18635                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18636                 NULL,
18637         }
18638 };
18639
18640 /* Enable/Disable a per queue offloading */
18641 struct cmd_config_per_queue_tx_offload_result {
18642         cmdline_fixed_string_t port;
18643         portid_t port_id;
18644         cmdline_fixed_string_t txq;
18645         uint16_t queue_id;
18646         cmdline_fixed_string_t tx_offload;
18647         cmdline_fixed_string_t offload;
18648         cmdline_fixed_string_t on_off;
18649 };
18650
18651 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18652         TOKEN_STRING_INITIALIZER
18653                 (struct cmd_config_per_queue_tx_offload_result,
18654                  port, "port");
18655 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18656         TOKEN_NUM_INITIALIZER
18657                 (struct cmd_config_per_queue_tx_offload_result,
18658                  port_id, UINT16);
18659 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18660         TOKEN_STRING_INITIALIZER
18661                 (struct cmd_config_per_queue_tx_offload_result,
18662                  txq, "txq");
18663 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18664         TOKEN_NUM_INITIALIZER
18665                 (struct cmd_config_per_queue_tx_offload_result,
18666                  queue_id, UINT16);
18667 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18668         TOKEN_STRING_INITIALIZER
18669                 (struct cmd_config_per_queue_tx_offload_result,
18670                  tx_offload, "tx_offload");
18671 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18672         TOKEN_STRING_INITIALIZER
18673                 (struct cmd_config_per_queue_tx_offload_result,
18674                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18675                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18676                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18677                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18678                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18679 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18680         TOKEN_STRING_INITIALIZER
18681                 (struct cmd_config_per_queue_tx_offload_result,
18682                  on_off, "on#off");
18683
18684 static void
18685 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18686                                 __rte_unused struct cmdline *cl,
18687                                 __rte_unused void *data)
18688 {
18689         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18690         struct rte_eth_dev_info dev_info;
18691         portid_t port_id = res->port_id;
18692         uint16_t queue_id = res->queue_id;
18693         struct rte_port *port = &ports[port_id];
18694         uint64_t single_offload;
18695         int ret;
18696
18697         if (port->port_status != RTE_PORT_STOPPED) {
18698                 printf("Error: Can't config offload when Port %d "
18699                        "is not stopped\n", port_id);
18700                 return;
18701         }
18702
18703         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18704         if (ret != 0)
18705                 return;
18706
18707         if (queue_id >= dev_info.nb_tx_queues) {
18708                 printf("Error: input queue_id should be 0 ... "
18709                        "%d\n", dev_info.nb_tx_queues - 1);
18710                 return;
18711         }
18712
18713         single_offload = search_tx_offload(res->offload);
18714         if (single_offload == 0) {
18715                 printf("Unknown offload name: %s\n", res->offload);
18716                 return;
18717         }
18718
18719         if (!strcmp(res->on_off, "on"))
18720                 port->tx_conf[queue_id].offloads |= single_offload;
18721         else
18722                 port->tx_conf[queue_id].offloads &= ~single_offload;
18723
18724         cmd_reconfig_device_queue(port_id, 1, 1);
18725 }
18726
18727 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18728         .f = cmd_config_per_queue_tx_offload_parsed,
18729         .data = NULL,
18730         .help_str = "port <port_id> txq <queue_id> tx_offload "
18731                     "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                     "on|off",
18737         .tokens = {
18738                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18739                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18740                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18741                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18742                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18743                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18744                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18745                 NULL,
18746         }
18747 };
18748
18749 /* *** configure tx_metadata for specific port *** */
18750 struct cmd_config_tx_metadata_specific_result {
18751         cmdline_fixed_string_t port;
18752         cmdline_fixed_string_t keyword;
18753         uint16_t port_id;
18754         cmdline_fixed_string_t item;
18755         uint32_t value;
18756 };
18757
18758 static void
18759 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18760                                 __rte_unused struct cmdline *cl,
18761                                 __rte_unused void *data)
18762 {
18763         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18764
18765         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18766                 return;
18767         ports[res->port_id].tx_metadata = res->value;
18768         /* Add/remove callback to insert valid metadata in every Tx packet. */
18769         if (ports[res->port_id].tx_metadata)
18770                 add_tx_md_callback(res->port_id);
18771         else
18772                 remove_tx_md_callback(res->port_id);
18773         rte_flow_dynf_metadata_register();
18774 }
18775
18776 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18777         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18778                         port, "port");
18779 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18780         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18781                         keyword, "config");
18782 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18783         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18784                         port_id, UINT16);
18785 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18786         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18787                         item, "tx_metadata");
18788 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18789         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18790                         value, UINT32);
18791
18792 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18793         .f = cmd_config_tx_metadata_specific_parsed,
18794         .data = NULL,
18795         .help_str = "port config <port_id> tx_metadata <value>",
18796         .tokens = {
18797                 (void *)&cmd_config_tx_metadata_specific_port,
18798                 (void *)&cmd_config_tx_metadata_specific_keyword,
18799                 (void *)&cmd_config_tx_metadata_specific_id,
18800                 (void *)&cmd_config_tx_metadata_specific_item,
18801                 (void *)&cmd_config_tx_metadata_specific_value,
18802                 NULL,
18803         },
18804 };
18805
18806 /* *** set dynf *** */
18807 struct cmd_config_tx_dynf_specific_result {
18808         cmdline_fixed_string_t port;
18809         cmdline_fixed_string_t keyword;
18810         uint16_t port_id;
18811         cmdline_fixed_string_t item;
18812         cmdline_fixed_string_t name;
18813         cmdline_fixed_string_t value;
18814 };
18815
18816 static void
18817 cmd_config_dynf_specific_parsed(void *parsed_result,
18818                                 __rte_unused struct cmdline *cl,
18819                                 __rte_unused void *data)
18820 {
18821         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18822         struct rte_mbuf_dynflag desc_flag;
18823         int flag;
18824         uint64_t old_port_flags;
18825
18826         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18827                 return;
18828         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18829         if (flag <= 0) {
18830                 if (strlcpy(desc_flag.name, res->name,
18831                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18832                         printf("Flag name too long\n");
18833                         return;
18834                 }
18835                 desc_flag.flags = 0;
18836                 flag = rte_mbuf_dynflag_register(&desc_flag);
18837                 if (flag < 0) {
18838                         printf("Can't register flag\n");
18839                         return;
18840                 }
18841                 strcpy(dynf_names[flag], desc_flag.name);
18842         }
18843         old_port_flags = ports[res->port_id].mbuf_dynf;
18844         if (!strcmp(res->value, "set")) {
18845                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
18846                 if (old_port_flags == 0)
18847                         add_tx_dynf_callback(res->port_id);
18848         } else {
18849                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18850                 if (ports[res->port_id].mbuf_dynf == 0)
18851                         remove_tx_dynf_callback(res->port_id);
18852         }
18853 }
18854
18855 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18856         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18857                         keyword, "port");
18858 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18859         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18860                         keyword, "config");
18861 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18862         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18863                         port_id, UINT16);
18864 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18865         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18866                         item, "dynf");
18867 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18868         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18869                         name, NULL);
18870 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
18871         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18872                         value, "set#clear");
18873
18874 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
18875         .f = cmd_config_dynf_specific_parsed,
18876         .data = NULL,
18877         .help_str = "port config <port id> dynf <name> set|clear",
18878         .tokens = {
18879                 (void *)&cmd_config_tx_dynf_specific_port,
18880                 (void *)&cmd_config_tx_dynf_specific_keyword,
18881                 (void *)&cmd_config_tx_dynf_specific_port_id,
18882                 (void *)&cmd_config_tx_dynf_specific_item,
18883                 (void *)&cmd_config_tx_dynf_specific_name,
18884                 (void *)&cmd_config_tx_dynf_specific_value,
18885                 NULL,
18886         },
18887 };
18888
18889 /* *** display tx_metadata per port configuration *** */
18890 struct cmd_show_tx_metadata_result {
18891         cmdline_fixed_string_t cmd_show;
18892         cmdline_fixed_string_t cmd_port;
18893         cmdline_fixed_string_t cmd_keyword;
18894         portid_t cmd_pid;
18895 };
18896
18897 static void
18898 cmd_show_tx_metadata_parsed(void *parsed_result,
18899                 __rte_unused struct cmdline *cl,
18900                 __rte_unused void *data)
18901 {
18902         struct cmd_show_tx_metadata_result *res = parsed_result;
18903
18904         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18905                 printf("invalid port id %u\n", res->cmd_pid);
18906                 return;
18907         }
18908         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18909                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18910                        ports[res->cmd_pid].tx_metadata);
18911         }
18912 }
18913
18914 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18915         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18916                         cmd_show, "show");
18917 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18918         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18919                         cmd_port, "port");
18920 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18921         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18922                         cmd_pid, UINT16);
18923 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18924         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18925                         cmd_keyword, "tx_metadata");
18926
18927 cmdline_parse_inst_t cmd_show_tx_metadata = {
18928         .f = cmd_show_tx_metadata_parsed,
18929         .data = NULL,
18930         .help_str = "show port <port_id> tx_metadata",
18931         .tokens = {
18932                 (void *)&cmd_show_tx_metadata_show,
18933                 (void *)&cmd_show_tx_metadata_port,
18934                 (void *)&cmd_show_tx_metadata_pid,
18935                 (void *)&cmd_show_tx_metadata_keyword,
18936                 NULL,
18937         },
18938 };
18939
18940 /* *** show fec capability per port configuration *** */
18941 struct cmd_show_fec_capability_result {
18942         cmdline_fixed_string_t cmd_show;
18943         cmdline_fixed_string_t cmd_port;
18944         cmdline_fixed_string_t cmd_fec;
18945         cmdline_fixed_string_t cmd_keyword;
18946         portid_t cmd_pid;
18947 };
18948
18949 static void
18950 cmd_show_fec_capability_parsed(void *parsed_result,
18951                 __rte_unused struct cmdline *cl,
18952                 __rte_unused void *data)
18953 {
18954 #define FEC_CAP_NUM 2
18955         struct cmd_show_fec_capability_result *res = parsed_result;
18956         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
18957         unsigned int num = FEC_CAP_NUM;
18958         unsigned int ret_num;
18959         int ret;
18960
18961         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18962                 printf("Invalid port id %u\n", res->cmd_pid);
18963                 return;
18964         }
18965
18966         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
18967         if (ret == -ENOTSUP) {
18968                 printf("Function not implemented\n");
18969                 return;
18970         } else if (ret < 0) {
18971                 printf("Get FEC capability failed\n");
18972                 return;
18973         }
18974
18975         ret_num = (unsigned int)ret;
18976         show_fec_capability(ret_num, speed_fec_capa);
18977 }
18978
18979 cmdline_parse_token_string_t cmd_show_fec_capability_show =
18980         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
18981                         cmd_show, "show");
18982 cmdline_parse_token_string_t cmd_show_fec_capability_port =
18983         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
18984                         cmd_port, "port");
18985 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
18986         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
18987                         cmd_pid, UINT16);
18988 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
18989         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
18990                         cmd_fec, "fec");
18991 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
18992         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
18993                         cmd_keyword, "capabilities");
18994
18995 cmdline_parse_inst_t cmd_show_capability = {
18996         .f = cmd_show_fec_capability_parsed,
18997         .data = NULL,
18998         .help_str = "show port <port_id> fec capabilities",
18999         .tokens = {
19000                 (void *)&cmd_show_fec_capability_show,
19001                 (void *)&cmd_show_fec_capability_port,
19002                 (void *)&cmd_show_fec_capability_pid,
19003                 (void *)&cmd_show_fec_capability_fec,
19004                 (void *)&cmd_show_fec_capability_keyword,
19005                 NULL,
19006         },
19007 };
19008
19009 /* *** show fec mode per port configuration *** */
19010 struct cmd_show_fec_metadata_result {
19011         cmdline_fixed_string_t cmd_show;
19012         cmdline_fixed_string_t cmd_port;
19013         cmdline_fixed_string_t cmd_keyword;
19014         portid_t cmd_pid;
19015 };
19016
19017 static void
19018 cmd_show_fec_mode_parsed(void *parsed_result,
19019                 __rte_unused struct cmdline *cl,
19020                 __rte_unused void *data)
19021 {
19022 #define FEC_NAME_SIZE 16
19023         struct cmd_show_fec_metadata_result *res = parsed_result;
19024         uint32_t mode;
19025         char buf[FEC_NAME_SIZE];
19026         int ret;
19027
19028         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19029                 printf("Invalid port id %u\n", res->cmd_pid);
19030                 return;
19031         }
19032         ret = rte_eth_fec_get(res->cmd_pid, &mode);
19033         if (ret == -ENOTSUP) {
19034                 printf("Function not implemented\n");
19035                 return;
19036         } else if (ret < 0) {
19037                 printf("Get FEC mode failed\n");
19038                 return;
19039         }
19040
19041         switch (mode) {
19042         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
19043                 strlcpy(buf, "off", sizeof(buf));
19044                 break;
19045         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
19046                 strlcpy(buf, "auto", sizeof(buf));
19047                 break;
19048         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
19049                 strlcpy(buf, "baser", sizeof(buf));
19050                 break;
19051         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
19052                 strlcpy(buf, "rs", sizeof(buf));
19053                 break;
19054         default:
19055                 return;
19056         }
19057
19058         printf("%s\n", buf);
19059 }
19060
19061 cmdline_parse_token_string_t cmd_show_fec_mode_show =
19062         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19063                         cmd_show, "show");
19064 cmdline_parse_token_string_t cmd_show_fec_mode_port =
19065         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19066                         cmd_port, "port");
19067 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
19068         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
19069                         cmd_pid, UINT16);
19070 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
19071         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19072                         cmd_keyword, "fec_mode");
19073
19074 cmdline_parse_inst_t cmd_show_fec_mode = {
19075         .f = cmd_show_fec_mode_parsed,
19076         .data = NULL,
19077         .help_str = "show port <port_id> fec_mode",
19078         .tokens = {
19079                 (void *)&cmd_show_fec_mode_show,
19080                 (void *)&cmd_show_fec_mode_port,
19081                 (void *)&cmd_show_fec_mode_pid,
19082                 (void *)&cmd_show_fec_mode_keyword,
19083                 NULL,
19084         },
19085 };
19086
19087 /* *** set fec mode per port configuration *** */
19088 struct cmd_set_port_fec_mode {
19089         cmdline_fixed_string_t set;
19090         cmdline_fixed_string_t port;
19091         portid_t port_id;
19092         cmdline_fixed_string_t fec_mode;
19093         cmdline_fixed_string_t fec_value;
19094 };
19095
19096 /* Common CLI fields for set fec mode */
19097 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
19098         TOKEN_STRING_INITIALIZER
19099                 (struct cmd_set_port_fec_mode,
19100                  set, "set");
19101 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
19102         TOKEN_STRING_INITIALIZER
19103                 (struct cmd_set_port_fec_mode,
19104                  port, "port");
19105 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
19106         TOKEN_NUM_INITIALIZER
19107                 (struct cmd_set_port_fec_mode,
19108                  port_id, UINT16);
19109 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
19110         TOKEN_STRING_INITIALIZER
19111                 (struct cmd_set_port_fec_mode,
19112                  fec_mode, "fec_mode");
19113 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
19114         TOKEN_STRING_INITIALIZER
19115                 (struct cmd_set_port_fec_mode,
19116                  fec_value, NULL);
19117
19118 static void
19119 cmd_set_port_fec_mode_parsed(
19120         void *parsed_result,
19121         __rte_unused struct cmdline *cl,
19122         __rte_unused void *data)
19123 {
19124         struct cmd_set_port_fec_mode *res = parsed_result;
19125         uint16_t port_id = res->port_id;
19126         uint32_t mode;
19127         int ret;
19128
19129         ret = parse_fec_mode(res->fec_value, &mode);
19130         if (ret < 0) {
19131                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
19132                         port_id);
19133                 return;
19134         }
19135
19136         ret = rte_eth_fec_set(port_id, mode);
19137         if (ret == -ENOTSUP) {
19138                 printf("Function not implemented\n");
19139                 return;
19140         } else if (ret < 0) {
19141                 printf("Set FEC mode failed\n");
19142                 return;
19143         }
19144 }
19145
19146 cmdline_parse_inst_t cmd_set_fec_mode = {
19147         .f = cmd_set_port_fec_mode_parsed,
19148         .data = NULL,
19149         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
19150         .tokens = {
19151                 (void *)&cmd_set_port_fec_mode_set,
19152                 (void *)&cmd_set_port_fec_mode_port,
19153                 (void *)&cmd_set_port_fec_mode_port_id,
19154                 (void *)&cmd_set_port_fec_mode_str,
19155                 (void *)&cmd_set_port_fec_mode_value,
19156                 NULL,
19157         },
19158 };
19159
19160 /* show port supported ptypes */
19161
19162 /* Common result structure for show port ptypes */
19163 struct cmd_show_port_supported_ptypes_result {
19164         cmdline_fixed_string_t show;
19165         cmdline_fixed_string_t port;
19166         portid_t port_id;
19167         cmdline_fixed_string_t ptypes;
19168 };
19169
19170 /* Common CLI fields for show port ptypes */
19171 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19172         TOKEN_STRING_INITIALIZER
19173                 (struct cmd_show_port_supported_ptypes_result,
19174                  show, "show");
19175 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19176         TOKEN_STRING_INITIALIZER
19177                 (struct cmd_show_port_supported_ptypes_result,
19178                  port, "port");
19179 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19180         TOKEN_NUM_INITIALIZER
19181                 (struct cmd_show_port_supported_ptypes_result,
19182                  port_id, UINT16);
19183 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19184         TOKEN_STRING_INITIALIZER
19185                 (struct cmd_show_port_supported_ptypes_result,
19186                  ptypes, "ptypes");
19187
19188 static void
19189 cmd_show_port_supported_ptypes_parsed(
19190         void *parsed_result,
19191         __rte_unused struct cmdline *cl,
19192         __rte_unused void *data)
19193 {
19194 #define RSVD_PTYPE_MASK       0xf0000000
19195 #define MAX_PTYPES_PER_LAYER  16
19196 #define LTYPE_NAMESIZE        32
19197 #define PTYPE_NAMESIZE        256
19198         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19199         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19200         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19201         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19202         uint16_t port_id = res->port_id;
19203         int ret, i;
19204
19205         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19206         if (ret < 0)
19207                 return;
19208
19209         while (ptype_mask != RSVD_PTYPE_MASK) {
19210
19211                 switch (ptype_mask) {
19212                 case RTE_PTYPE_L2_MASK:
19213                         strlcpy(ltype, "L2", sizeof(ltype));
19214                         break;
19215                 case RTE_PTYPE_L3_MASK:
19216                         strlcpy(ltype, "L3", sizeof(ltype));
19217                         break;
19218                 case RTE_PTYPE_L4_MASK:
19219                         strlcpy(ltype, "L4", sizeof(ltype));
19220                         break;
19221                 case RTE_PTYPE_TUNNEL_MASK:
19222                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19223                         break;
19224                 case RTE_PTYPE_INNER_L2_MASK:
19225                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19226                         break;
19227                 case RTE_PTYPE_INNER_L3_MASK:
19228                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19229                         break;
19230                 case RTE_PTYPE_INNER_L4_MASK:
19231                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19232                         break;
19233                 default:
19234                         return;
19235                 }
19236
19237                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19238                                                        ptype_mask, ptypes,
19239                                                        MAX_PTYPES_PER_LAYER);
19240
19241                 if (ret > 0)
19242                         printf("Supported %s ptypes:\n", ltype);
19243                 else
19244                         printf("%s ptypes unsupported\n", ltype);
19245
19246                 for (i = 0; i < ret; ++i) {
19247                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19248                         printf("%s\n", buf);
19249                 }
19250
19251                 ptype_mask <<= 4;
19252         }
19253 }
19254
19255 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19256         .f = cmd_show_port_supported_ptypes_parsed,
19257         .data = NULL,
19258         .help_str = "show port <port_id> ptypes",
19259         .tokens = {
19260                 (void *)&cmd_show_port_supported_ptypes_show,
19261                 (void *)&cmd_show_port_supported_ptypes_port,
19262                 (void *)&cmd_show_port_supported_ptypes_port_id,
19263                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19264                 NULL,
19265         },
19266 };
19267
19268 /* *** display rx/tx descriptor status *** */
19269 struct cmd_show_rx_tx_desc_status_result {
19270         cmdline_fixed_string_t cmd_show;
19271         cmdline_fixed_string_t cmd_port;
19272         cmdline_fixed_string_t cmd_keyword;
19273         cmdline_fixed_string_t cmd_desc;
19274         cmdline_fixed_string_t cmd_status;
19275         portid_t cmd_pid;
19276         portid_t cmd_qid;
19277         portid_t cmd_did;
19278 };
19279
19280 static void
19281 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19282                 __rte_unused struct cmdline *cl,
19283                 __rte_unused void *data)
19284 {
19285         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19286         int rc;
19287
19288         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19289                 printf("invalid port id %u\n", res->cmd_pid);
19290                 return;
19291         }
19292
19293         if (!strcmp(res->cmd_keyword, "rxq")) {
19294                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19295                                              res->cmd_did);
19296                 if (rc < 0) {
19297                         printf("Invalid queueid = %d\n", res->cmd_qid);
19298                         return;
19299                 }
19300                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19301                         printf("Desc status = AVAILABLE\n");
19302                 else if (rc == RTE_ETH_RX_DESC_DONE)
19303                         printf("Desc status = DONE\n");
19304                 else
19305                         printf("Desc status = UNAVAILABLE\n");
19306         } else if (!strcmp(res->cmd_keyword, "txq")) {
19307                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19308                                              res->cmd_did);
19309                 if (rc < 0) {
19310                         printf("Invalid queueid = %d\n", res->cmd_qid);
19311                         return;
19312                 }
19313                 if (rc == RTE_ETH_TX_DESC_FULL)
19314                         printf("Desc status = FULL\n");
19315                 else if (rc == RTE_ETH_TX_DESC_DONE)
19316                         printf("Desc status = DONE\n");
19317                 else
19318                         printf("Desc status = UNAVAILABLE\n");
19319         }
19320 }
19321
19322 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19323         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19324                         cmd_show, "show");
19325 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19326         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19327                         cmd_port, "port");
19328 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19329         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19330                         cmd_pid, UINT16);
19331 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19332         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19333                         cmd_keyword, "rxq#txq");
19334 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19335         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19336                         cmd_qid, UINT16);
19337 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19338         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19339                         cmd_desc, "desc");
19340 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19341         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19342                         cmd_did, UINT16);
19343 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19344         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19345                         cmd_status, "status");
19346 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19347         .f = cmd_show_rx_tx_desc_status_parsed,
19348         .data = NULL,
19349         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19350                 "status",
19351         .tokens = {
19352                 (void *)&cmd_show_rx_tx_desc_status_show,
19353                 (void *)&cmd_show_rx_tx_desc_status_port,
19354                 (void *)&cmd_show_rx_tx_desc_status_pid,
19355                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19356                 (void *)&cmd_show_rx_tx_desc_status_qid,
19357                 (void *)&cmd_show_rx_tx_desc_status_desc,
19358                 (void *)&cmd_show_rx_tx_desc_status_did,
19359                 (void *)&cmd_show_rx_tx_desc_status_status,
19360                 NULL,
19361         },
19362 };
19363
19364 /* Common result structure for set port ptypes */
19365 struct cmd_set_port_ptypes_result {
19366         cmdline_fixed_string_t set;
19367         cmdline_fixed_string_t port;
19368         portid_t port_id;
19369         cmdline_fixed_string_t ptype_mask;
19370         uint32_t mask;
19371 };
19372
19373 /* Common CLI fields for set port ptypes */
19374 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19375         TOKEN_STRING_INITIALIZER
19376                 (struct cmd_set_port_ptypes_result,
19377                  set, "set");
19378 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19379         TOKEN_STRING_INITIALIZER
19380                 (struct cmd_set_port_ptypes_result,
19381                  port, "port");
19382 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19383         TOKEN_NUM_INITIALIZER
19384                 (struct cmd_set_port_ptypes_result,
19385                  port_id, UINT16);
19386 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19387         TOKEN_STRING_INITIALIZER
19388                 (struct cmd_set_port_ptypes_result,
19389                  ptype_mask, "ptype_mask");
19390 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19391         TOKEN_NUM_INITIALIZER
19392                 (struct cmd_set_port_ptypes_result,
19393                  mask, UINT32);
19394
19395 static void
19396 cmd_set_port_ptypes_parsed(
19397         void *parsed_result,
19398         __rte_unused struct cmdline *cl,
19399         __rte_unused void *data)
19400 {
19401         struct cmd_set_port_ptypes_result *res = parsed_result;
19402 #define PTYPE_NAMESIZE        256
19403         char ptype_name[PTYPE_NAMESIZE];
19404         uint16_t port_id = res->port_id;
19405         uint32_t ptype_mask = res->mask;
19406         int ret, i;
19407
19408         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19409                                                NULL, 0);
19410         if (ret <= 0) {
19411                 printf("Port %d doesn't support any ptypes.\n", port_id);
19412                 return;
19413         }
19414
19415         uint32_t ptypes[ret];
19416
19417         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19418         if (ret < 0) {
19419                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19420                 return;
19421         }
19422
19423         printf("Successfully set following ptypes for Port %d\n", port_id);
19424         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19425                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19426                 printf("%s\n", ptype_name);
19427         }
19428
19429         clear_ptypes = false;
19430 }
19431
19432 cmdline_parse_inst_t cmd_set_port_ptypes = {
19433         .f = cmd_set_port_ptypes_parsed,
19434         .data = NULL,
19435         .help_str = "set port <port_id> ptype_mask <mask>",
19436         .tokens = {
19437                 (void *)&cmd_set_port_ptypes_set,
19438                 (void *)&cmd_set_port_ptypes_port,
19439                 (void *)&cmd_set_port_ptypes_port_id,
19440                 (void *)&cmd_set_port_ptypes_mask_str,
19441                 (void *)&cmd_set_port_ptypes_mask_u32,
19442                 NULL,
19443         },
19444 };
19445
19446 /* *** display mac addresses added to a port *** */
19447 struct cmd_showport_macs_result {
19448         cmdline_fixed_string_t cmd_show;
19449         cmdline_fixed_string_t cmd_port;
19450         cmdline_fixed_string_t cmd_keyword;
19451         portid_t cmd_pid;
19452 };
19453
19454 static void
19455 cmd_showport_macs_parsed(void *parsed_result,
19456                 __rte_unused struct cmdline *cl,
19457                 __rte_unused void *data)
19458 {
19459         struct cmd_showport_macs_result *res = parsed_result;
19460
19461         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19462                 return;
19463
19464         if (!strcmp(res->cmd_keyword, "macs"))
19465                 show_macs(res->cmd_pid);
19466         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19467                 show_mcast_macs(res->cmd_pid);
19468 }
19469
19470 cmdline_parse_token_string_t cmd_showport_macs_show =
19471         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19472                         cmd_show, "show");
19473 cmdline_parse_token_string_t cmd_showport_macs_port =
19474         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19475                         cmd_port, "port");
19476 cmdline_parse_token_num_t cmd_showport_macs_pid =
19477         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19478                         cmd_pid, UINT16);
19479 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19480         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19481                         cmd_keyword, "macs#mcast_macs");
19482
19483 cmdline_parse_inst_t cmd_showport_macs = {
19484         .f = cmd_showport_macs_parsed,
19485         .data = NULL,
19486         .help_str = "show port <port_id> macs|mcast_macs",
19487         .tokens = {
19488                 (void *)&cmd_showport_macs_show,
19489                 (void *)&cmd_showport_macs_port,
19490                 (void *)&cmd_showport_macs_pid,
19491                 (void *)&cmd_showport_macs_keyword,
19492                 NULL,
19493         },
19494 };
19495
19496 /* ******************************************************************************** */
19497
19498 /* list of instructions */
19499 cmdline_parse_ctx_t main_ctx[] = {
19500         (cmdline_parse_inst_t *)&cmd_help_brief,
19501         (cmdline_parse_inst_t *)&cmd_help_long,
19502         (cmdline_parse_inst_t *)&cmd_quit,
19503         (cmdline_parse_inst_t *)&cmd_load_from_file,
19504         (cmdline_parse_inst_t *)&cmd_showport,
19505         (cmdline_parse_inst_t *)&cmd_showqueue,
19506         (cmdline_parse_inst_t *)&cmd_showeeprom,
19507         (cmdline_parse_inst_t *)&cmd_showportall,
19508         (cmdline_parse_inst_t *)&cmd_showdevice,
19509         (cmdline_parse_inst_t *)&cmd_showcfg,
19510         (cmdline_parse_inst_t *)&cmd_showfwdall,
19511         (cmdline_parse_inst_t *)&cmd_start,
19512         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19513         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19514         (cmdline_parse_inst_t *)&cmd_set_link_up,
19515         (cmdline_parse_inst_t *)&cmd_set_link_down,
19516         (cmdline_parse_inst_t *)&cmd_reset,
19517         (cmdline_parse_inst_t *)&cmd_set_numbers,
19518         (cmdline_parse_inst_t *)&cmd_set_log,
19519         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
19520         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
19521         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19522         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19523         (cmdline_parse_inst_t *)&cmd_set_txtimes,
19524         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19525         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19526         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19527         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19528         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19529         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19530         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19531         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19532         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19533         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19534         (cmdline_parse_inst_t *)&cmd_set_link_check,
19535         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19536         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19537         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19538         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19539 #ifdef RTE_NET_BOND
19540         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19541         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19542         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19543         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19544         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19545         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19546         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19547         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19548         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19549         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19550         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19551 #endif
19552         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19553         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19554         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19555         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19556         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19557         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19558         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19559         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19560         (cmdline_parse_inst_t *)&cmd_csum_set,
19561         (cmdline_parse_inst_t *)&cmd_csum_show,
19562         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19563         (cmdline_parse_inst_t *)&cmd_tso_set,
19564         (cmdline_parse_inst_t *)&cmd_tso_show,
19565         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19566         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19567         (cmdline_parse_inst_t *)&cmd_gro_enable,
19568         (cmdline_parse_inst_t *)&cmd_gro_flush,
19569         (cmdline_parse_inst_t *)&cmd_gro_show,
19570         (cmdline_parse_inst_t *)&cmd_gso_enable,
19571         (cmdline_parse_inst_t *)&cmd_gso_size,
19572         (cmdline_parse_inst_t *)&cmd_gso_show,
19573         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19574         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19575         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19576         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19577         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19578         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19579         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19580         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19581         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19582         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19583         (cmdline_parse_inst_t *)&cmd_config_dcb,
19584         (cmdline_parse_inst_t *)&cmd_read_reg,
19585         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19586         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19587         (cmdline_parse_inst_t *)&cmd_write_reg,
19588         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19589         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19590         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19591         (cmdline_parse_inst_t *)&cmd_stop,
19592         (cmdline_parse_inst_t *)&cmd_mac_addr,
19593         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19594         (cmdline_parse_inst_t *)&cmd_set_qmap,
19595         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19596         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
19597         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
19598         (cmdline_parse_inst_t *)&cmd_operate_port,
19599         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19600         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19601         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19602         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19603         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19604         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19605         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19606         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19607         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19608         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19609         (cmdline_parse_inst_t *)&cmd_config_mtu,
19610         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19611         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19612         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19613         (cmdline_parse_inst_t *)&cmd_config_rss,
19614         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19615         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19616         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19617         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19618         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19619         (cmdline_parse_inst_t *)&cmd_showport_reta,
19620         (cmdline_parse_inst_t *)&cmd_showport_macs,
19621         (cmdline_parse_inst_t *)&cmd_config_burst,
19622         (cmdline_parse_inst_t *)&cmd_config_thresh,
19623         (cmdline_parse_inst_t *)&cmd_config_threshold,
19624         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19625         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19626         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19627         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19628         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19629         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19630         (cmdline_parse_inst_t *)&cmd_global_config,
19631         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19632         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19633         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19634         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19635         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19636         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19637         (cmdline_parse_inst_t *)&cmd_dump,
19638         (cmdline_parse_inst_t *)&cmd_dump_one,
19639         (cmdline_parse_inst_t *)&cmd_syn_filter,
19640         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19641         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19642         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19643         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19644         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19645         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19646         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19647         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19648         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19649         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19650         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19651         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19652         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19653         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19654         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19655         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19656         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19657         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19658         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19659         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19660         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19661         (cmdline_parse_inst_t *)&cmd_flow,
19662         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19663         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19664         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19665         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19666         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19667         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19668         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19669         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19670         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19671         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19672         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19673         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19674         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19675         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19676         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19677         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19678         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19679         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19680         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19681         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19682         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19683         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19684         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19685         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19686         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19687         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19688         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19689         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19690         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19691         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19692         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19693         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19694         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19695         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19696         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19697         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19698         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19699         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19700         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19701         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19702         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19703         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19704         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19705         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19706         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19707         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19708         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19709         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19710         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19711         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19712         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19713         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19714         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19715         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19716         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19717         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19718         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19719         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19720         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19721         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19722         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19723         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19724         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19725         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19726         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19727         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19728         (cmdline_parse_inst_t *)&cmd_ddp_add,
19729         (cmdline_parse_inst_t *)&cmd_ddp_del,
19730         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19731         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19732         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19733         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19734         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19735         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19736         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19737         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19738         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19739         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19740         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19741         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19742
19743         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19744         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19745         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19746         (cmdline_parse_inst_t *)&cmd_queue_region,
19747         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19748         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19749         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19750         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19751         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19752         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19753         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19754         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19755         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19756         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19757         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19758         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19759         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19760         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19761         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19762         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19763         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19764         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
19765         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19766         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19767         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19768         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19769         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19770         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19771         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19772         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19773         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19774         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19775         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19776         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19777         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19778         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19779         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19780         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19781         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19782         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19783 #ifdef RTE_LIB_BPF
19784         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19785         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19786 #endif
19787         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19788         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19789         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19790         (cmdline_parse_inst_t *)&cmd_set_raw,
19791         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19792         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19793         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19794         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
19795         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
19796         (cmdline_parse_inst_t *)&cmd_show_capability,
19797         NULL,
19798 };
19799
19800 /* read cmdline commands from file */
19801 void
19802 cmdline_read_from_file(const char *filename)
19803 {
19804         struct cmdline *cl;
19805
19806         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19807         if (cl == NULL) {
19808                 printf("Failed to create file based cmdline context: %s\n",
19809                        filename);
19810                 return;
19811         }
19812
19813         cmdline_interact(cl);
19814         cmdline_quit(cl);
19815
19816         cmdline_free(cl);
19817
19818         printf("Read CLI commands from %s\n", filename);
19819 }
19820
19821 /* prompt function, called from main on MAIN lcore */
19822 void
19823 prompt(void)
19824 {
19825         /* initialize non-constant commands */
19826         cmd_set_fwd_mode_init();
19827         cmd_set_fwd_retry_mode_init();
19828
19829         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19830         if (testpmd_cl == NULL)
19831                 return;
19832         cmdline_interact(testpmd_cl);
19833         cmdline_stdin_exit(testpmd_cl);
19834 }
19835
19836 void
19837 prompt_exit(void)
19838 {
19839         if (testpmd_cl != NULL)
19840                 cmdline_quit(testpmd_cl);
19841 }
19842
19843 static void
19844 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19845 {
19846         if (id == (portid_t)RTE_PORT_ALL) {
19847                 portid_t pid;
19848
19849                 RTE_ETH_FOREACH_DEV(pid) {
19850                         /* check if need_reconfig has been set to 1 */
19851                         if (ports[pid].need_reconfig == 0)
19852                                 ports[pid].need_reconfig = dev;
19853                         /* check if need_reconfig_queues has been set to 1 */
19854                         if (ports[pid].need_reconfig_queues == 0)
19855                                 ports[pid].need_reconfig_queues = queue;
19856                 }
19857         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19858                 /* check if need_reconfig has been set to 1 */
19859                 if (ports[id].need_reconfig == 0)
19860                         ports[id].need_reconfig = dev;
19861                 /* check if need_reconfig_queues has been set to 1 */
19862                 if (ports[id].need_reconfig_queues == 0)
19863                         ports[id].need_reconfig_queues = queue;
19864         }
19865 }