app/testpmd: fix port id check in Tx VLAN command
[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_LIBRTE_PMD_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_LIBRTE_IXGBE_PMD
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_LIBRTE_I40E_PMD
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_LIBRTE_BNXT_PMD
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|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         }
253
254         if (show_all || !strcmp(res->section, "config")) {
255                 cmdline_printf(
256                         cl,
257                         "\n"
258                         "Configuration:\n"
259                         "--------------\n"
260                         "Configuration changes only become active when"
261                         " forwarding is started/restarted.\n\n"
262
263                         "set default\n"
264                         "    Reset forwarding to the default configuration.\n\n"
265
266                         "set verbose (level)\n"
267                         "    Set the debug verbosity level X.\n\n"
268
269                         "set log global|(type) (level)\n"
270                         "    Set the log level.\n\n"
271
272                         "set nbport (num)\n"
273                         "    Set number of ports.\n\n"
274
275                         "set nbcore (num)\n"
276                         "    Set number of cores.\n\n"
277
278                         "set coremask (mask)\n"
279                         "    Set the forwarding cores hexadecimal mask.\n\n"
280
281                         "set portmask (mask)\n"
282                         "    Set the forwarding ports hexadecimal mask.\n\n"
283
284                         "set burst (num)\n"
285                         "    Set number of packets per burst.\n\n"
286
287                         "set burst tx delay (microseconds) retry (num)\n"
288                         "    Set the transmit delay time and number of retries,"
289                         " effective when retry is enabled.\n\n"
290
291                         "set txpkts (x[,y]*)\n"
292                         "    Set the length of each segment of TXONLY"
293                         " and optionally CSUM packets.\n\n"
294
295                         "set txsplit (off|on|rand)\n"
296                         "    Set the split policy for the TX packets."
297                         " Right now only applicable for CSUM and TXONLY"
298                         " modes\n\n"
299
300                         "set txtimes (x, y)\n"
301                         "    Set the scheduling on timestamps"
302                         " timings for the TXONLY mode\n\n"
303
304                         "set corelist (x[,y]*)\n"
305                         "    Set the list of forwarding cores.\n\n"
306
307                         "set portlist (x[,y]*)\n"
308                         "    Set the list of forwarding ports.\n\n"
309
310                         "set port setup on (iterator|event)\n"
311                         "    Select how attached port is retrieved for setup.\n\n"
312
313                         "set tx loopback (port_id) (on|off)\n"
314                         "    Enable or disable tx loopback.\n\n"
315
316                         "set all queues drop (port_id) (on|off)\n"
317                         "    Set drop enable bit for all queues.\n\n"
318
319                         "set vf split drop (port_id) (vf_id) (on|off)\n"
320                         "    Set split drop enable bit for a VF from the PF.\n\n"
321
322                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
323                         "    Set MAC antispoof for a VF from the PF.\n\n"
324
325                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
326                         "    Enable MACsec offload.\n\n"
327
328                         "set macsec offload (port_id) off\n"
329                         "    Disable MACsec offload.\n\n"
330
331                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
332                         "    Configure MACsec secure connection (SC).\n\n"
333
334                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
335                         "    Configure MACsec secure association (SA).\n\n"
336
337                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
338                         "    Set VF broadcast for a VF from the PF.\n\n"
339
340                         "vlan set stripq (on|off) (port_id,queue_id)\n"
341                         "    Set the VLAN strip for a queue on a port.\n\n"
342
343                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
344                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
345
346                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
347                         "    Set VLAN insert for a VF from the PF.\n\n"
348
349                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
350                         "    Set VLAN antispoof for a VF from the PF.\n\n"
351
352                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
353                         "    Set VLAN tag for a VF from the PF.\n\n"
354
355                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
356                         "    Set a VF's max bandwidth(Mbps).\n\n"
357
358                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
359                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
360
361                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
362                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
363
364                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
365                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
366
367                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
368                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
369
370                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
371                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
372
373                         "vlan set (inner|outer) tpid (value) (port_id)\n"
374                         "    Set the VLAN TPID for Packet Filtering on"
375                         " a port\n\n"
376
377                         "rx_vlan add (vlan_id|all) (port_id)\n"
378                         "    Add a vlan_id, or all identifiers, to the set"
379                         " of VLAN identifiers filtered by port_id.\n\n"
380
381                         "rx_vlan rm (vlan_id|all) (port_id)\n"
382                         "    Remove a vlan_id, or all identifiers, from the set"
383                         " of VLAN identifiers filtered by port_id.\n\n"
384
385                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
386                         "    Add a vlan_id, to the set of VLAN identifiers"
387                         "filtered for VF(s) from port_id.\n\n"
388
389                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
390                         "    Remove a vlan_id, to the set of VLAN identifiers"
391                         "filtered for VF(s) from port_id.\n\n"
392
393                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
394                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
395                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
396                         "   add a tunnel filter of a port.\n\n"
397
398                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
399                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
400                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
401                         "   remove a tunnel filter of a port.\n\n"
402
403                         "rx_vxlan_port add (udp_port) (port_id)\n"
404                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
405
406                         "rx_vxlan_port rm (udp_port) (port_id)\n"
407                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
408
409                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
410                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
411                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
412
413                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
414                         "    Set port based TX VLAN insertion.\n\n"
415
416                         "tx_vlan reset (port_id)\n"
417                         "    Disable hardware insertion of a VLAN header in"
418                         " packets sent on a port.\n\n"
419
420                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
421                         "    Select hardware or software calculation of the"
422                         " checksum when transmitting a packet using the"
423                         " csum forward engine.\n"
424                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
425                         "    outer-ip concerns the outer IP layer in"
426                         "    outer-udp concerns the outer UDP layer in"
427                         " case the packet is recognized as a tunnel packet by"
428                         " the forward engine (vxlan, gre and ipip are supported)\n"
429                         "    Please check the NIC datasheet for HW limits.\n\n"
430
431                         "csum parse-tunnel (on|off) (tx_port_id)\n"
432                         "    If disabled, treat tunnel packets as non-tunneled"
433                         " packets (treat inner headers as payload). The port\n"
434                         "    argument is the port used for TX in csum forward"
435                         " engine.\n\n"
436
437                         "csum show (port_id)\n"
438                         "    Display tx checksum offload configuration\n\n"
439
440                         "tso set (segsize) (portid)\n"
441                         "    Enable TCP Segmentation Offload in csum forward"
442                         " engine.\n"
443                         "    Please check the NIC datasheet for HW limits.\n\n"
444
445                         "tso show (portid)"
446                         "    Display the status of TCP Segmentation Offload.\n\n"
447
448                         "set port (port_id) gro on|off\n"
449                         "    Enable or disable Generic Receive Offload in"
450                         " csum forwarding engine.\n\n"
451
452                         "show port (port_id) gro\n"
453                         "    Display GRO configuration.\n\n"
454
455                         "set gro flush (cycles)\n"
456                         "    Set the cycle to flush GROed packets from"
457                         " reassembly tables.\n\n"
458
459                         "set port (port_id) gso (on|off)"
460                         "    Enable or disable Generic Segmentation Offload in"
461                         " csum forwarding engine.\n\n"
462
463                         "set gso segsz (length)\n"
464                         "    Set max packet length for output GSO segments,"
465                         " including packet header and payload.\n\n"
466
467                         "show port (port_id) gso\n"
468                         "    Show GSO configuration.\n\n"
469
470                         "set fwd (%s)\n"
471                         "    Set packet forwarding mode.\n\n"
472
473                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
474                         "    Add a MAC address on port_id.\n\n"
475
476                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
477                         "    Remove a MAC address from port_id.\n\n"
478
479                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
480                         "    Set the default MAC address for port_id.\n\n"
481
482                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
483                         "    Add a MAC address for a VF on the port.\n\n"
484
485                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
486                         "    Set the MAC address for a VF from the PF.\n\n"
487
488                         "set eth-peer (port_id) (peer_addr)\n"
489                         "    set the peer address for certain port.\n\n"
490
491                         "set port (port_id) uta (mac_address|all) (on|off)\n"
492                         "    Add/Remove a or all unicast hash filter(s)"
493                         "from port X.\n\n"
494
495                         "set promisc (port_id|all) (on|off)\n"
496                         "    Set the promiscuous mode on port_id, or all.\n\n"
497
498                         "set allmulti (port_id|all) (on|off)\n"
499                         "    Set the allmulti mode on port_id, or all.\n\n"
500
501                         "set vf promisc (port_id) (vf_id) (on|off)\n"
502                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
503
504                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
505                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
506
507                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
508                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
509                         " (on|off) autoneg (on|off) (port_id)\n"
510                         "set flow_ctrl rx (on|off) (portid)\n"
511                         "set flow_ctrl tx (on|off) (portid)\n"
512                         "set flow_ctrl high_water (high_water) (portid)\n"
513                         "set flow_ctrl low_water (low_water) (portid)\n"
514                         "set flow_ctrl pause_time (pause_time) (portid)\n"
515                         "set flow_ctrl send_xon (send_xon) (portid)\n"
516                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
517                         "set flow_ctrl autoneg (on|off) (port_id)\n"
518                         "    Set the link flow control parameter on a port.\n\n"
519
520                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
521                         " (low_water) (pause_time) (priority) (port_id)\n"
522                         "    Set the priority flow control parameter on a"
523                         " port.\n\n"
524
525                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
526                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
527                         " queue on port.\n"
528                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
529                         " on port 0 to mapping 5.\n\n"
530
531                         "set xstats-hide-zero on|off\n"
532                         "    Set the option to hide the zero values"
533                         " for xstats display.\n"
534
535                         "set record-core-cycles on|off\n"
536                         "    Set the option to enable measurement of CPU cycles.\n"
537
538                         "set record-burst-stats on|off\n"
539                         "    Set the option to enable display of RX and TX bursts.\n"
540
541                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
542                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
543
544                         "set port (port_id) vf (vf_id) (mac_addr)"
545                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
546                         "   Add/Remove unicast or multicast MAC addr filter"
547                         " for a VF.\n\n"
548
549                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
550                         "|MPE) (on|off)\n"
551                         "    AUPE:accepts untagged VLAN;"
552                         "ROPE:accept unicast hash\n\n"
553                         "    BAM:accepts broadcast packets;"
554                         "MPE:accepts all multicast packets\n\n"
555                         "    Enable/Disable a VF receive mode of a port\n\n"
556
557                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
558                         "    Set rate limit for a queue of a port\n\n"
559
560                         "set port (port_id) vf (vf_id) rate (rate_num) "
561                         "queue_mask (queue_mask_value)\n"
562                         "    Set rate limit for queues in VF of a port\n\n"
563
564                         "set port (port_id) mirror-rule (rule_id)"
565                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
566                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
567                         "   Set pool or vlan type mirror rule on a port.\n"
568                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
569                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
570                         " to pool 0.\n\n"
571
572                         "set port (port_id) mirror-rule (rule_id)"
573                         " (uplink-mirror|downlink-mirror) dst-pool"
574                         " (pool_id) (on|off)\n"
575                         "   Set uplink or downlink type mirror rule on a port.\n"
576                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
577                         " 0 on' enable mirror income traffic to pool 0.\n\n"
578
579                         "reset port (port_id) mirror-rule (rule_id)\n"
580                         "   Reset a mirror rule.\n\n"
581
582                         "set flush_rx (on|off)\n"
583                         "   Flush (default) or don't flush RX streams before"
584                         " forwarding. Mainly used with PCAP drivers.\n\n"
585
586                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
587                         "   Set the bypass mode for the lowest port on bypass enabled"
588                         " NIC.\n\n"
589
590                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
591                         "mode (normal|bypass|isolate) (port_id)\n"
592                         "   Set the event required to initiate specified bypass mode for"
593                         " the lowest port on a bypass enabled NIC where:\n"
594                         "       timeout   = enable bypass after watchdog timeout.\n"
595                         "       os_on     = enable bypass when OS/board is powered on.\n"
596                         "       os_off    = enable bypass when OS/board is powered off.\n"
597                         "       power_on  = enable bypass when power supply is turned on.\n"
598                         "       power_off = enable bypass when power supply is turned off."
599                         "\n\n"
600
601                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
602                         "   Set the bypass watchdog timeout to 'n' seconds"
603                         " where 0 = instant.\n\n"
604
605                         "show bypass config (port_id)\n"
606                         "   Show the bypass configuration for a bypass enabled NIC"
607                         " using the lowest port on the NIC.\n\n"
608
609 #ifdef RTE_LIBRTE_PMD_BOND
610                         "create bonded device (mode) (socket)\n"
611                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
612
613                         "add bonding slave (slave_id) (port_id)\n"
614                         "       Add a slave device to a bonded device.\n\n"
615
616                         "remove bonding slave (slave_id) (port_id)\n"
617                         "       Remove a slave device from a bonded device.\n\n"
618
619                         "set bonding mode (value) (port_id)\n"
620                         "       Set the bonding mode on a bonded device.\n\n"
621
622                         "set bonding primary (slave_id) (port_id)\n"
623                         "       Set the primary slave for a bonded device.\n\n"
624
625                         "show bonding config (port_id)\n"
626                         "       Show the bonding config for port_id.\n\n"
627
628                         "set bonding mac_addr (port_id) (address)\n"
629                         "       Set the MAC address of a bonded device.\n\n"
630
631                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
632                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
633
634                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
635                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
636
637                         "set bonding mon_period (port_id) (value)\n"
638                         "       Set the bonding link status monitoring polling period in ms.\n\n"
639
640                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
641                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
642
643 #endif
644                         "set link-up port (port_id)\n"
645                         "       Set link up for a port.\n\n"
646
647                         "set link-down port (port_id)\n"
648                         "       Set link down for a port.\n\n"
649
650                         "E-tag set insertion on port-tag-id (value)"
651                         " port (port_id) vf (vf_id)\n"
652                         "    Enable E-tag insertion for a VF on a port\n\n"
653
654                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
655                         "    Disable E-tag insertion for a VF on a port\n\n"
656
657                         "E-tag set stripping (on|off) port (port_id)\n"
658                         "    Enable/disable E-tag stripping on a port\n\n"
659
660                         "E-tag set forwarding (on|off) port (port_id)\n"
661                         "    Enable/disable E-tag based forwarding"
662                         " on a port\n\n"
663
664                         "E-tag set filter add e-tag-id (value) dst-pool"
665                         " (pool_id) port (port_id)\n"
666                         "    Add an E-tag forwarding filter on a port\n\n"
667
668                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
669                         "    Delete an E-tag forwarding filter on a port\n\n"
670
671                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
672                         "    Load a profile package on a port\n\n"
673
674                         "ddp del (port_id) (backup_profile_path)\n"
675                         "    Delete a profile package from a port\n\n"
676
677                         "ptype mapping get (port_id) (valid_only)\n"
678                         "    Get ptype mapping on a port\n\n"
679
680                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
681                         "    Replace target with the pkt_type in ptype mapping\n\n"
682
683                         "ptype mapping reset (port_id)\n"
684                         "    Reset ptype mapping on a port\n\n"
685
686                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
687                         "    Update a ptype mapping item on a port\n\n"
688
689                         "set port (port_id) ptype_mask (ptype_mask)\n"
690                         "    set packet types classification for a specific port\n\n"
691
692                         "set port (port_id) queue-region region_id (value) "
693                         "queue_start_index (value) queue_num (value)\n"
694                         "    Set a queue region on a port\n\n"
695
696                         "set port (port_id) queue-region region_id (value) "
697                         "flowtype (value)\n"
698                         "    Set a flowtype region index on a port\n\n"
699
700                         "set port (port_id) queue-region UP (value) region_id (value)\n"
701                         "    Set the mapping of User Priority to "
702                         "queue region on a port\n\n"
703
704                         "set port (port_id) queue-region flush (on|off)\n"
705                         "    flush all queue region related configuration\n\n"
706
707                         "show port meter cap (port_id)\n"
708                         "    Show port meter capability information\n\n"
709
710                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
711                         "    meter profile add - srtcm rfc 2697\n\n"
712
713                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
714                         "    meter profile add - trtcm rfc 2698\n\n"
715
716                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
717                         "    meter profile add - trtcm rfc 4115\n\n"
718
719                         "del port meter profile (port_id) (profile_id)\n"
720                         "    meter profile delete\n\n"
721
722                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
723                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
724                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
725                         "(dscp_tbl_entry63)]\n"
726                         "    meter create\n\n"
727
728                         "enable port meter (port_id) (mtr_id)\n"
729                         "    meter enable\n\n"
730
731                         "disable port meter (port_id) (mtr_id)\n"
732                         "    meter disable\n\n"
733
734                         "del port meter (port_id) (mtr_id)\n"
735                         "    meter delete\n\n"
736
737                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
738                         "    meter update meter profile\n\n"
739
740                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
741                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
742                         "    update meter dscp table entries\n\n"
743
744                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
745                         "(action0) [(action1) (action2)]\n"
746                         "    meter update policer action\n\n"
747
748                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
749                         "    meter update stats\n\n"
750
751                         "show port (port_id) queue-region\n"
752                         "    show all queue region related configuration info\n\n"
753
754                         , list_pkt_forwarding_modes()
755                 );
756         }
757
758         if (show_all || !strcmp(res->section, "ports")) {
759
760                 cmdline_printf(
761                         cl,
762                         "\n"
763                         "Port Operations:\n"
764                         "----------------\n\n"
765
766                         "port start (port_id|all)\n"
767                         "    Start all ports or port_id.\n\n"
768
769                         "port stop (port_id|all)\n"
770                         "    Stop all ports or port_id.\n\n"
771
772                         "port close (port_id|all)\n"
773                         "    Close all ports or port_id.\n\n"
774
775                         "port reset (port_id|all)\n"
776                         "    Reset all ports or port_id.\n\n"
777
778                         "port attach (ident)\n"
779                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
780
781                         "port detach (port_id)\n"
782                         "    Detach physical or virtual dev by port_id\n\n"
783
784                         "port config (port_id|all)"
785                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
786                         " duplex (half|full|auto)\n"
787                         "    Set speed and duplex for all ports or port_id\n\n"
788
789                         "port config (port_id|all) loopback (mode)\n"
790                         "    Set loopback mode for all ports or port_id\n\n"
791
792                         "port config all (rxq|txq|rxd|txd) (value)\n"
793                         "    Set number for rxq/txq/rxd/txd.\n\n"
794
795                         "port config all max-pkt-len (value)\n"
796                         "    Set the max packet length.\n\n"
797
798                         "port config all max-lro-pkt-size (value)\n"
799                         "    Set the max LRO aggregated packet size.\n\n"
800
801                         "port config all drop-en (on|off)\n"
802                         "    Enable or disable packet drop on all RX queues of all ports when no "
803                         "receive buffers available.\n\n"
804
805                         "port config all rss (all|default|ip|tcp|udp|sctp|"
806                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|level-default|"
807                         "level-outer|level-inner|<flowtype_id>)\n"
808                         "    Set the RSS mode.\n\n"
809
810                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
811                         "    Set the RSS redirection table.\n\n"
812
813                         "port config (port_id) dcb vt (on|off) (traffic_class)"
814                         " pfc (on|off)\n"
815                         "    Set the DCB mode.\n\n"
816
817                         "port config all burst (value)\n"
818                         "    Set the number of packets per burst.\n\n"
819
820                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
821                         " (value)\n"
822                         "    Set the ring prefetch/host/writeback threshold"
823                         " for tx/rx queue.\n\n"
824
825                         "port config all (txfreet|txrst|rxfreet) (value)\n"
826                         "    Set free threshold for rx/tx, or set"
827                         " tx rs bit threshold.\n\n"
828                         "port config mtu X value\n"
829                         "    Set the MTU of port X to a given value\n\n"
830
831                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
832                         "    Set a rx/tx queue's ring size configuration, the new"
833                         " value will take effect after command that (re-)start the port"
834                         " or command that setup the specific queue\n\n"
835
836                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
837                         "    Start/stop a rx/tx queue of port X. Only take effect"
838                         " when port X is started\n\n"
839
840                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
841                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
842                         " take effect when port X is stopped.\n\n"
843
844                         "port (port_id) (rxq|txq) (queue_id) setup\n"
845                         "    Setup a rx/tx queue of port X.\n\n"
846
847                         "port config (port_id|all) l2-tunnel E-tag ether-type"
848                         " (value)\n"
849                         "    Set the value of E-tag ether-type.\n\n"
850
851                         "port config (port_id|all) l2-tunnel E-tag"
852                         " (enable|disable)\n"
853                         "    Enable/disable the E-tag support.\n\n"
854
855                         "port config (port_id) pctype mapping reset\n"
856                         "    Reset flow type to pctype mapping on a port\n\n"
857
858                         "port config (port_id) pctype mapping update"
859                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
860                         "    Update a flow type to pctype mapping item on a port\n\n"
861
862                         "port config (port_id) pctype (pctype_id) hash_inset|"
863                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
864                         " (field_idx)\n"
865                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
866
867                         "port config (port_id) pctype (pctype_id) hash_inset|"
868                         "fdir_inset|fdir_flx_inset clear all"
869                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
870
871                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
872                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
873
874                         "port config <port_id> rx_offload vlan_strip|"
875                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
876                         "outer_ipv4_cksum|macsec_strip|header_split|"
877                         "vlan_filter|vlan_extend|jumbo_frame|"
878                         "scatter|timestamp|security|keep_crc on|off\n"
879                         "     Enable or disable a per port Rx offloading"
880                         " on all Rx queues of a port\n\n"
881
882                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
883                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
884                         "outer_ipv4_cksum|macsec_strip|header_split|"
885                         "vlan_filter|vlan_extend|jumbo_frame|"
886                         "scatter|timestamp|security|keep_crc on|off\n"
887                         "    Enable or disable a per queue Rx offloading"
888                         " only on a specific Rx queue\n\n"
889
890                         "port config (port_id) tx_offload vlan_insert|"
891                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
892                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
893                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
894                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
895                         "security on|off\n"
896                         "    Enable or disable a per port Tx offloading"
897                         " on all Tx queues of a port\n\n"
898
899                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
900                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
901                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
902                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
903                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
904                         " on|off\n"
905                         "    Enable or disable a per queue Tx offloading"
906                         " only on a specific Tx queue\n\n"
907
908                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
909                         "    Load an eBPF program as a callback"
910                         " for particular RX/TX queue\n\n"
911
912                         "bpf-unload rx|tx (port) (queue)\n"
913                         "    Unload previously loaded eBPF program"
914                         " for particular RX/TX queue\n\n"
915
916                         "port config (port_id) tx_metadata (value)\n"
917                         "    Set Tx metadata value per port. Testpmd will add this value"
918                         " to any Tx packet sent from this port\n\n"
919
920                         "port config (port_id) dynf (name) set|clear\n"
921                         "    Register a dynf and Set/clear this flag on Tx. "
922                         "Testpmd will set this value to any Tx packet "
923                         "sent from this port\n\n"
924                 );
925         }
926
927         if (show_all || !strcmp(res->section, "registers")) {
928
929                 cmdline_printf(
930                         cl,
931                         "\n"
932                         "Registers:\n"
933                         "----------\n\n"
934
935                         "read reg (port_id) (address)\n"
936                         "    Display value of a port register.\n\n"
937
938                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
939                         "    Display a port register bit field.\n\n"
940
941                         "read regbit (port_id) (address) (bit_x)\n"
942                         "    Display a single port register bit.\n\n"
943
944                         "write reg (port_id) (address) (value)\n"
945                         "    Set value of a port register.\n\n"
946
947                         "write regfield (port_id) (address) (bit_x) (bit_y)"
948                         " (value)\n"
949                         "    Set bit field of a port register.\n\n"
950
951                         "write regbit (port_id) (address) (bit_x) (value)\n"
952                         "    Set single bit value of a port register.\n\n"
953                 );
954         }
955         if (show_all || !strcmp(res->section, "filters")) {
956
957                 cmdline_printf(
958                         cl,
959                         "\n"
960                         "filters:\n"
961                         "--------\n\n"
962
963                         "ethertype_filter (port_id) (add|del)"
964                         " (mac_addr|mac_ignr) (mac_address) ethertype"
965                         " (ether_type) (drop|fwd) queue (queue_id)\n"
966                         "    Add/Del an ethertype filter.\n\n"
967
968                         "2tuple_filter (port_id) (add|del)"
969                         " dst_port (dst_port_value) protocol (protocol_value)"
970                         " mask (mask_value) tcp_flags (tcp_flags_value)"
971                         " priority (prio_value) queue (queue_id)\n"
972                         "    Add/Del a 2tuple filter.\n\n"
973
974                         "5tuple_filter (port_id) (add|del)"
975                         " dst_ip (dst_address) src_ip (src_address)"
976                         " dst_port (dst_port_value) src_port (src_port_value)"
977                         " protocol (protocol_value)"
978                         " mask (mask_value) tcp_flags (tcp_flags_value)"
979                         " priority (prio_value) queue (queue_id)\n"
980                         "    Add/Del a 5tuple filter.\n\n"
981
982                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
983                         "    Add/Del syn filter.\n\n"
984
985                         "flex_filter (port_id) (add|del) len (len_value)"
986                         " bytes (bytes_value) mask (mask_value)"
987                         " priority (prio_value) queue (queue_id)\n"
988                         "    Add/Del a flex filter.\n\n"
989
990                         "flow_director_filter (port_id) mode IP (add|del|update)"
991                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
992                         " src (src_ip_address) dst (dst_ip_address)"
993                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
994                         " vlan (vlan_value) flexbytes (flexbytes_value)"
995                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
996                         " fd_id (fd_id_value)\n"
997                         "    Add/Del an IP type flow director filter.\n\n"
998
999                         "flow_director_filter (port_id) mode IP (add|del|update)"
1000                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
1001                         " src (src_ip_address) (src_port)"
1002                         " dst (dst_ip_address) (dst_port)"
1003                         " tos (tos_value) ttl (ttl_value)"
1004                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1005                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1006                         " fd_id (fd_id_value)\n"
1007                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1008
1009                         "flow_director_filter (port_id) mode IP (add|del|update)"
1010                         " flow (ipv4-sctp|ipv6-sctp)"
1011                         " src (src_ip_address) (src_port)"
1012                         " dst (dst_ip_address) (dst_port)"
1013                         " tag (verification_tag) "
1014                         " tos (tos_value) ttl (ttl_value)"
1015                         " vlan (vlan_value)"
1016                         " flexbytes (flexbytes_value) (drop|fwd)"
1017                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1018                         "    Add/Del a SCTP type flow director filter.\n\n"
1019
1020                         "flow_director_filter (port_id) mode IP (add|del|update)"
1021                         " flow l2_payload ether (ethertype)"
1022                         " flexbytes (flexbytes_value) (drop|fwd)"
1023                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1024                         "    Add/Del a l2 payload type flow director filter.\n\n"
1025
1026                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1027                         " mac (mac_address) vlan (vlan_value)"
1028                         " flexbytes (flexbytes_value) (drop|fwd)"
1029                         " queue (queue_id) fd_id (fd_id_value)\n"
1030                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1031
1032                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1033                         " mac (mac_address) vlan (vlan_value)"
1034                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1035                         " flexbytes (flexbytes_value) (drop|fwd)"
1036                         " queue (queue_id) fd_id (fd_id_value)\n"
1037                         "    Add/Del a Tunnel flow director filter.\n\n"
1038
1039                         "flow_director_filter (port_id) mode raw (add|del|update)"
1040                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1041                         " fd_id (fd_id_value) packet (packet file name)\n"
1042                         "    Add/Del a raw type flow director filter.\n\n"
1043
1044                         "flush_flow_director (port_id)\n"
1045                         "    Flush all flow director entries of a device.\n\n"
1046
1047                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1048                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1049                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1050                         "    Set flow director IP mask.\n\n"
1051
1052                         "flow_director_mask (port_id) mode MAC-VLAN"
1053                         " vlan (vlan_value)\n"
1054                         "    Set flow director MAC-VLAN mask.\n\n"
1055
1056                         "flow_director_mask (port_id) mode Tunnel"
1057                         " vlan (vlan_value) mac (mac_value)"
1058                         " tunnel-type (tunnel_type_value)"
1059                         " tunnel-id (tunnel_id_value)\n"
1060                         "    Set flow director Tunnel mask.\n\n"
1061
1062                         "flow_director_flex_mask (port_id)"
1063                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1064                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1065                         " (mask)\n"
1066                         "    Configure mask of flex payload.\n\n"
1067
1068                         "flow_director_flex_payload (port_id)"
1069                         " (raw|l2|l3|l4) (config)\n"
1070                         "    Configure flex payload selection.\n\n"
1071
1072                         "get_sym_hash_ena_per_port (port_id)\n"
1073                         "    get symmetric hash enable configuration per port.\n\n"
1074
1075                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1076                         "    set symmetric hash enable configuration per port"
1077                         " to enable or disable.\n\n"
1078
1079                         "get_hash_global_config (port_id)\n"
1080                         "    Get the global configurations of hash filters.\n\n"
1081
1082                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1083                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1084                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1085                         " (enable|disable)\n"
1086                         "    Set the global configurations of hash filters.\n\n"
1087
1088                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1089                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1090                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1091                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1092                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1093                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1094                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1095                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1096                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1097                         "fld-8th|none) (select|add)\n"
1098                         "    Set the input set for hash.\n\n"
1099
1100                         "set_fdir_input_set (port_id) "
1101                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1102                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1103                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1104                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1105                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1106                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1107                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1108                         " (select|add)\n"
1109                         "    Set the input set for FDir.\n\n"
1110
1111                         "flow validate {port_id}"
1112                         " [group {group_id}] [priority {level}]"
1113                         " [ingress] [egress]"
1114                         " pattern {item} [/ {item} [...]] / end"
1115                         " actions {action} [/ {action} [...]] / end\n"
1116                         "    Check whether a flow rule can be created.\n\n"
1117
1118                         "flow create {port_id}"
1119                         " [group {group_id}] [priority {level}]"
1120                         " [ingress] [egress]"
1121                         " pattern {item} [/ {item} [...]] / end"
1122                         " actions {action} [/ {action} [...]] / end\n"
1123                         "    Create a flow rule.\n\n"
1124
1125                         "flow destroy {port_id} rule {rule_id} [...]\n"
1126                         "    Destroy specific flow rules.\n\n"
1127
1128                         "flow flush {port_id}\n"
1129                         "    Destroy all flow rules.\n\n"
1130
1131                         "flow query {port_id} {rule_id} {action}\n"
1132                         "    Query an existing flow rule.\n\n"
1133
1134                         "flow list {port_id} [group {group_id}] [...]\n"
1135                         "    List existing flow rules sorted by priority,"
1136                         " filtered by group identifiers.\n\n"
1137
1138                         "flow isolate {port_id} {boolean}\n"
1139                         "    Restrict ingress traffic to the defined"
1140                         " flow rules\n\n"
1141
1142                         "flow aged {port_id} [destroy]\n"
1143                         "    List and destroy aged flows"
1144                         " flow rules\n\n"
1145
1146                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1147                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1148                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1149                         "       Configure the VXLAN encapsulation for flows.\n\n"
1150
1151                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1152                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1153                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1154                         " eth-dst (eth-dst)\n"
1155                         "       Configure the VXLAN encapsulation for flows.\n\n"
1156
1157                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1158                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1159                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1160                         " eth-dst (eth-dst)\n"
1161                         "       Configure the VXLAN encapsulation for flows.\n\n"
1162
1163                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1164                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1165                         " (eth-dst)\n"
1166                         "       Configure the NVGRE encapsulation for flows.\n\n"
1167
1168                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1169                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1170                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1171                         "       Configure the NVGRE encapsulation for flows.\n\n"
1172
1173                         "set raw_encap {flow items}\n"
1174                         "       Configure the encapsulation with raw data.\n\n"
1175
1176                         "set raw_decap {flow items}\n"
1177                         "       Configure the decapsulation with raw data.\n\n"
1178
1179                 );
1180         }
1181
1182         if (show_all || !strcmp(res->section, "traffic_management")) {
1183                 cmdline_printf(
1184                         cl,
1185                         "\n"
1186                         "Traffic Management:\n"
1187                         "--------------\n"
1188                         "show port tm cap (port_id)\n"
1189                         "       Display the port TM capability.\n\n"
1190
1191                         "show port tm level cap (port_id) (level_id)\n"
1192                         "       Display the port TM hierarchical level capability.\n\n"
1193
1194                         "show port tm node cap (port_id) (node_id)\n"
1195                         "       Display the port TM node capability.\n\n"
1196
1197                         "show port tm node type (port_id) (node_id)\n"
1198                         "       Display the port TM node type.\n\n"
1199
1200                         "show port tm node stats (port_id) (node_id) (clear)\n"
1201                         "       Display the port TM node stats.\n\n"
1202
1203                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1204                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1205                         " (packet_length_adjust) (packet_mode)\n"
1206                         "       Add port tm node private shaper profile.\n\n"
1207
1208                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1209                         "       Delete port tm node private shaper profile.\n\n"
1210
1211                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1212                         " (shaper_profile_id)\n"
1213                         "       Add/update port tm node shared shaper.\n\n"
1214
1215                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1216                         "       Delete port tm node shared shaper.\n\n"
1217
1218                         "set port tm node shaper profile (port_id) (node_id)"
1219                         " (shaper_profile_id)\n"
1220                         "       Set port tm node shaper profile.\n\n"
1221
1222                         "add port tm node wred profile (port_id) (wred_profile_id)"
1223                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1224                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1225                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1226                         "       Add port tm node wred profile.\n\n"
1227
1228                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1229                         "       Delete port tm node wred profile.\n\n"
1230
1231                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1232                         " (priority) (weight) (level_id) (shaper_profile_id)"
1233                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1234                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1235                         "       Add port tm nonleaf node.\n\n"
1236
1237                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1238                         " (priority) (weight) (level_id) (shaper_profile_id)"
1239                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1240                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1241                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1242
1243                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1244                         " (priority) (weight) (level_id) (shaper_profile_id)"
1245                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1246                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1247                         "       Add port tm leaf node.\n\n"
1248
1249                         "del port tm node (port_id) (node_id)\n"
1250                         "       Delete port tm node.\n\n"
1251
1252                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1253                         " (priority) (weight)\n"
1254                         "       Set port tm node parent.\n\n"
1255
1256                         "suspend port tm node (port_id) (node_id)"
1257                         "       Suspend tm node.\n\n"
1258
1259                         "resume port tm node (port_id) (node_id)"
1260                         "       Resume tm node.\n\n"
1261
1262                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1263                         "       Commit tm hierarchy.\n\n"
1264
1265                         "set port tm mark ip_ecn (port) (green) (yellow)"
1266                         " (red)\n"
1267                         "    Enables/Disables the traffic management marking"
1268                         " for IP ECN (Explicit Congestion Notification)"
1269                         " packets on a given port\n\n"
1270
1271                         "set port tm mark ip_dscp (port) (green) (yellow)"
1272                         " (red)\n"
1273                         "    Enables/Disables the traffic management marking"
1274                         " on the port for IP dscp packets\n\n"
1275
1276                         "set port tm mark vlan_dei (port) (green) (yellow)"
1277                         " (red)\n"
1278                         "    Enables/Disables the traffic management marking"
1279                         " on the port for VLAN packets with DEI enabled\n\n"
1280                 );
1281         }
1282
1283         if (show_all || !strcmp(res->section, "devices")) {
1284                 cmdline_printf(
1285                         cl,
1286                         "\n"
1287                         "Device Operations:\n"
1288                         "--------------\n"
1289                         "device detach (identifier)\n"
1290                         "       Detach device by identifier.\n\n"
1291                 );
1292         }
1293
1294 }
1295
1296 cmdline_parse_token_string_t cmd_help_long_help =
1297         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1298
1299 cmdline_parse_token_string_t cmd_help_long_section =
1300         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1301                         "all#control#display#config#"
1302                         "ports#registers#filters#traffic_management#devices");
1303
1304 cmdline_parse_inst_t cmd_help_long = {
1305         .f = cmd_help_long_parsed,
1306         .data = NULL,
1307         .help_str = "help all|control|display|config|ports|register|"
1308                 "filters|traffic_management|devices: "
1309                 "Show help",
1310         .tokens = {
1311                 (void *)&cmd_help_long_help,
1312                 (void *)&cmd_help_long_section,
1313                 NULL,
1314         },
1315 };
1316
1317
1318 /* *** start/stop/close all ports *** */
1319 struct cmd_operate_port_result {
1320         cmdline_fixed_string_t keyword;
1321         cmdline_fixed_string_t name;
1322         cmdline_fixed_string_t value;
1323 };
1324
1325 static void cmd_operate_port_parsed(void *parsed_result,
1326                                 __rte_unused struct cmdline *cl,
1327                                 __rte_unused void *data)
1328 {
1329         struct cmd_operate_port_result *res = parsed_result;
1330
1331         if (!strcmp(res->name, "start"))
1332                 start_port(RTE_PORT_ALL);
1333         else if (!strcmp(res->name, "stop"))
1334                 stop_port(RTE_PORT_ALL);
1335         else if (!strcmp(res->name, "close"))
1336                 close_port(RTE_PORT_ALL);
1337         else if (!strcmp(res->name, "reset"))
1338                 reset_port(RTE_PORT_ALL);
1339         else
1340                 printf("Unknown parameter\n");
1341 }
1342
1343 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1344         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1345                                                                 "port");
1346 cmdline_parse_token_string_t cmd_operate_port_all_port =
1347         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1348                                                 "start#stop#close#reset");
1349 cmdline_parse_token_string_t cmd_operate_port_all_all =
1350         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1351
1352 cmdline_parse_inst_t cmd_operate_port = {
1353         .f = cmd_operate_port_parsed,
1354         .data = NULL,
1355         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1356         .tokens = {
1357                 (void *)&cmd_operate_port_all_cmd,
1358                 (void *)&cmd_operate_port_all_port,
1359                 (void *)&cmd_operate_port_all_all,
1360                 NULL,
1361         },
1362 };
1363
1364 /* *** start/stop/close specific port *** */
1365 struct cmd_operate_specific_port_result {
1366         cmdline_fixed_string_t keyword;
1367         cmdline_fixed_string_t name;
1368         uint8_t value;
1369 };
1370
1371 static void cmd_operate_specific_port_parsed(void *parsed_result,
1372                         __rte_unused struct cmdline *cl,
1373                                 __rte_unused void *data)
1374 {
1375         struct cmd_operate_specific_port_result *res = parsed_result;
1376
1377         if (!strcmp(res->name, "start"))
1378                 start_port(res->value);
1379         else if (!strcmp(res->name, "stop"))
1380                 stop_port(res->value);
1381         else if (!strcmp(res->name, "close"))
1382                 close_port(res->value);
1383         else if (!strcmp(res->name, "reset"))
1384                 reset_port(res->value);
1385         else
1386                 printf("Unknown parameter\n");
1387 }
1388
1389 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1390         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1391                                                         keyword, "port");
1392 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1393         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1394                                                 name, "start#stop#close#reset");
1395 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1396         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1397                                                         value, UINT8);
1398
1399 cmdline_parse_inst_t cmd_operate_specific_port = {
1400         .f = cmd_operate_specific_port_parsed,
1401         .data = NULL,
1402         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1403         .tokens = {
1404                 (void *)&cmd_operate_specific_port_cmd,
1405                 (void *)&cmd_operate_specific_port_port,
1406                 (void *)&cmd_operate_specific_port_id,
1407                 NULL,
1408         },
1409 };
1410
1411 /* *** enable port setup (after attach) via iterator or event *** */
1412 struct cmd_set_port_setup_on_result {
1413         cmdline_fixed_string_t set;
1414         cmdline_fixed_string_t port;
1415         cmdline_fixed_string_t setup;
1416         cmdline_fixed_string_t on;
1417         cmdline_fixed_string_t mode;
1418 };
1419
1420 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1421                                 __rte_unused struct cmdline *cl,
1422                                 __rte_unused void *data)
1423 {
1424         struct cmd_set_port_setup_on_result *res = parsed_result;
1425
1426         if (strcmp(res->mode, "event") == 0)
1427                 setup_on_probe_event = true;
1428         else if (strcmp(res->mode, "iterator") == 0)
1429                 setup_on_probe_event = false;
1430         else
1431                 printf("Unknown mode\n");
1432 }
1433
1434 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1435         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1436                         set, "set");
1437 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1438         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1439                         port, "port");
1440 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1441         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1442                         setup, "setup");
1443 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1444         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1445                         on, "on");
1446 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1447         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1448                         mode, "iterator#event");
1449
1450 cmdline_parse_inst_t cmd_set_port_setup_on = {
1451         .f = cmd_set_port_setup_on_parsed,
1452         .data = NULL,
1453         .help_str = "set port setup on iterator|event",
1454         .tokens = {
1455                 (void *)&cmd_set_port_setup_on_set,
1456                 (void *)&cmd_set_port_setup_on_port,
1457                 (void *)&cmd_set_port_setup_on_setup,
1458                 (void *)&cmd_set_port_setup_on_on,
1459                 (void *)&cmd_set_port_setup_on_mode,
1460                 NULL,
1461         },
1462 };
1463
1464 /* *** attach a specified port *** */
1465 struct cmd_operate_attach_port_result {
1466         cmdline_fixed_string_t port;
1467         cmdline_fixed_string_t keyword;
1468         cmdline_multi_string_t identifier;
1469 };
1470
1471 static void cmd_operate_attach_port_parsed(void *parsed_result,
1472                                 __rte_unused struct cmdline *cl,
1473                                 __rte_unused void *data)
1474 {
1475         struct cmd_operate_attach_port_result *res = parsed_result;
1476
1477         if (!strcmp(res->keyword, "attach"))
1478                 attach_port(res->identifier);
1479         else
1480                 printf("Unknown parameter\n");
1481 }
1482
1483 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1484         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1485                         port, "port");
1486 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1487         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1488                         keyword, "attach");
1489 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1490         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1491                         identifier, TOKEN_STRING_MULTI);
1492
1493 cmdline_parse_inst_t cmd_operate_attach_port = {
1494         .f = cmd_operate_attach_port_parsed,
1495         .data = NULL,
1496         .help_str = "port attach <identifier>: "
1497                 "(identifier: pci address or virtual dev name)",
1498         .tokens = {
1499                 (void *)&cmd_operate_attach_port_port,
1500                 (void *)&cmd_operate_attach_port_keyword,
1501                 (void *)&cmd_operate_attach_port_identifier,
1502                 NULL,
1503         },
1504 };
1505
1506 /* *** detach a specified port *** */
1507 struct cmd_operate_detach_port_result {
1508         cmdline_fixed_string_t port;
1509         cmdline_fixed_string_t keyword;
1510         portid_t port_id;
1511 };
1512
1513 static void cmd_operate_detach_port_parsed(void *parsed_result,
1514                                 __rte_unused struct cmdline *cl,
1515                                 __rte_unused void *data)
1516 {
1517         struct cmd_operate_detach_port_result *res = parsed_result;
1518
1519         if (!strcmp(res->keyword, "detach")) {
1520                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1521                 detach_port_device(res->port_id);
1522         } else {
1523                 printf("Unknown parameter\n");
1524         }
1525 }
1526
1527 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1528         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1529                         port, "port");
1530 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1531         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1532                         keyword, "detach");
1533 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1534         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1535                         port_id, UINT16);
1536
1537 cmdline_parse_inst_t cmd_operate_detach_port = {
1538         .f = cmd_operate_detach_port_parsed,
1539         .data = NULL,
1540         .help_str = "port detach <port_id>",
1541         .tokens = {
1542                 (void *)&cmd_operate_detach_port_port,
1543                 (void *)&cmd_operate_detach_port_keyword,
1544                 (void *)&cmd_operate_detach_port_port_id,
1545                 NULL,
1546         },
1547 };
1548
1549 /* *** detach device by identifier *** */
1550 struct cmd_operate_detach_device_result {
1551         cmdline_fixed_string_t device;
1552         cmdline_fixed_string_t keyword;
1553         cmdline_fixed_string_t identifier;
1554 };
1555
1556 static void cmd_operate_detach_device_parsed(void *parsed_result,
1557                                 __rte_unused struct cmdline *cl,
1558                                 __rte_unused void *data)
1559 {
1560         struct cmd_operate_detach_device_result *res = parsed_result;
1561
1562         if (!strcmp(res->keyword, "detach"))
1563                 detach_devargs(res->identifier);
1564         else
1565                 printf("Unknown parameter\n");
1566 }
1567
1568 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1569         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1570                         device, "device");
1571 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1572         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1573                         keyword, "detach");
1574 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1575         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1576                         identifier, NULL);
1577
1578 cmdline_parse_inst_t cmd_operate_detach_device = {
1579         .f = cmd_operate_detach_device_parsed,
1580         .data = NULL,
1581         .help_str = "device detach <identifier>:"
1582                 "(identifier: pci address or virtual dev name)",
1583         .tokens = {
1584                 (void *)&cmd_operate_detach_device_device,
1585                 (void *)&cmd_operate_detach_device_keyword,
1586                 (void *)&cmd_operate_detach_device_identifier,
1587                 NULL,
1588         },
1589 };
1590 /* *** configure speed for all ports *** */
1591 struct cmd_config_speed_all {
1592         cmdline_fixed_string_t port;
1593         cmdline_fixed_string_t keyword;
1594         cmdline_fixed_string_t all;
1595         cmdline_fixed_string_t item1;
1596         cmdline_fixed_string_t item2;
1597         cmdline_fixed_string_t value1;
1598         cmdline_fixed_string_t value2;
1599 };
1600
1601 static int
1602 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1603 {
1604
1605         int duplex;
1606
1607         if (!strcmp(duplexstr, "half")) {
1608                 duplex = ETH_LINK_HALF_DUPLEX;
1609         } else if (!strcmp(duplexstr, "full")) {
1610                 duplex = ETH_LINK_FULL_DUPLEX;
1611         } else if (!strcmp(duplexstr, "auto")) {
1612                 duplex = ETH_LINK_FULL_DUPLEX;
1613         } else {
1614                 printf("Unknown duplex parameter\n");
1615                 return -1;
1616         }
1617
1618         if (!strcmp(speedstr, "10")) {
1619                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1620                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1621         } else if (!strcmp(speedstr, "100")) {
1622                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1623                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1624         } else {
1625                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1626                         printf("Invalid speed/duplex parameters\n");
1627                         return -1;
1628                 }
1629                 if (!strcmp(speedstr, "1000")) {
1630                         *speed = ETH_LINK_SPEED_1G;
1631                 } else if (!strcmp(speedstr, "10000")) {
1632                         *speed = ETH_LINK_SPEED_10G;
1633                 } else if (!strcmp(speedstr, "25000")) {
1634                         *speed = ETH_LINK_SPEED_25G;
1635                 } else if (!strcmp(speedstr, "40000")) {
1636                         *speed = ETH_LINK_SPEED_40G;
1637                 } else if (!strcmp(speedstr, "50000")) {
1638                         *speed = ETH_LINK_SPEED_50G;
1639                 } else if (!strcmp(speedstr, "100000")) {
1640                         *speed = ETH_LINK_SPEED_100G;
1641                 } else if (!strcmp(speedstr, "200000")) {
1642                         *speed = ETH_LINK_SPEED_200G;
1643                 } else if (!strcmp(speedstr, "auto")) {
1644                         *speed = ETH_LINK_SPEED_AUTONEG;
1645                 } else {
1646                         printf("Unknown speed parameter\n");
1647                         return -1;
1648                 }
1649         }
1650
1651         return 0;
1652 }
1653
1654 static void
1655 cmd_config_speed_all_parsed(void *parsed_result,
1656                         __rte_unused struct cmdline *cl,
1657                         __rte_unused void *data)
1658 {
1659         struct cmd_config_speed_all *res = parsed_result;
1660         uint32_t link_speed;
1661         portid_t pid;
1662
1663         if (!all_ports_stopped()) {
1664                 printf("Please stop all ports first\n");
1665                 return;
1666         }
1667
1668         if (parse_and_check_speed_duplex(res->value1, res->value2,
1669                         &link_speed) < 0)
1670                 return;
1671
1672         RTE_ETH_FOREACH_DEV(pid) {
1673                 ports[pid].dev_conf.link_speeds = link_speed;
1674         }
1675
1676         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1677 }
1678
1679 cmdline_parse_token_string_t cmd_config_speed_all_port =
1680         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1681 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1682         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1683                                                         "config");
1684 cmdline_parse_token_string_t cmd_config_speed_all_all =
1685         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1686 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1687         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1688 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1689         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1690                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1691 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1692         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1693 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1694         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1695                                                 "half#full#auto");
1696
1697 cmdline_parse_inst_t cmd_config_speed_all = {
1698         .f = cmd_config_speed_all_parsed,
1699         .data = NULL,
1700         .help_str = "port config all speed "
1701                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1702                                                         "half|full|auto",
1703         .tokens = {
1704                 (void *)&cmd_config_speed_all_port,
1705                 (void *)&cmd_config_speed_all_keyword,
1706                 (void *)&cmd_config_speed_all_all,
1707                 (void *)&cmd_config_speed_all_item1,
1708                 (void *)&cmd_config_speed_all_value1,
1709                 (void *)&cmd_config_speed_all_item2,
1710                 (void *)&cmd_config_speed_all_value2,
1711                 NULL,
1712         },
1713 };
1714
1715 /* *** configure speed for specific port *** */
1716 struct cmd_config_speed_specific {
1717         cmdline_fixed_string_t port;
1718         cmdline_fixed_string_t keyword;
1719         portid_t id;
1720         cmdline_fixed_string_t item1;
1721         cmdline_fixed_string_t item2;
1722         cmdline_fixed_string_t value1;
1723         cmdline_fixed_string_t value2;
1724 };
1725
1726 static void
1727 cmd_config_speed_specific_parsed(void *parsed_result,
1728                                 __rte_unused struct cmdline *cl,
1729                                 __rte_unused void *data)
1730 {
1731         struct cmd_config_speed_specific *res = parsed_result;
1732         uint32_t link_speed;
1733
1734         if (!all_ports_stopped()) {
1735                 printf("Please stop all ports first\n");
1736                 return;
1737         }
1738
1739         if (port_id_is_invalid(res->id, ENABLED_WARN))
1740                 return;
1741
1742         if (parse_and_check_speed_duplex(res->value1, res->value2,
1743                         &link_speed) < 0)
1744                 return;
1745
1746         ports[res->id].dev_conf.link_speeds = link_speed;
1747
1748         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1749 }
1750
1751
1752 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1753         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1754                                                                 "port");
1755 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1756         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1757                                                                 "config");
1758 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1759         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1760 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1761         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1762                                                                 "speed");
1763 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1764         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1765                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1766 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1767         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1768                                                                 "duplex");
1769 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1770         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1771                                                         "half#full#auto");
1772
1773 cmdline_parse_inst_t cmd_config_speed_specific = {
1774         .f = cmd_config_speed_specific_parsed,
1775         .data = NULL,
1776         .help_str = "port config <port_id> speed "
1777                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1778                                                         "half|full|auto",
1779         .tokens = {
1780                 (void *)&cmd_config_speed_specific_port,
1781                 (void *)&cmd_config_speed_specific_keyword,
1782                 (void *)&cmd_config_speed_specific_id,
1783                 (void *)&cmd_config_speed_specific_item1,
1784                 (void *)&cmd_config_speed_specific_value1,
1785                 (void *)&cmd_config_speed_specific_item2,
1786                 (void *)&cmd_config_speed_specific_value2,
1787                 NULL,
1788         },
1789 };
1790
1791 /* *** configure loopback for all ports *** */
1792 struct cmd_config_loopback_all {
1793         cmdline_fixed_string_t port;
1794         cmdline_fixed_string_t keyword;
1795         cmdline_fixed_string_t all;
1796         cmdline_fixed_string_t item;
1797         uint32_t mode;
1798 };
1799
1800 static void
1801 cmd_config_loopback_all_parsed(void *parsed_result,
1802                         __rte_unused struct cmdline *cl,
1803                         __rte_unused void *data)
1804 {
1805         struct cmd_config_loopback_all *res = parsed_result;
1806         portid_t pid;
1807
1808         if (!all_ports_stopped()) {
1809                 printf("Please stop all ports first\n");
1810                 return;
1811         }
1812
1813         RTE_ETH_FOREACH_DEV(pid) {
1814                 ports[pid].dev_conf.lpbk_mode = res->mode;
1815         }
1816
1817         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1818 }
1819
1820 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1821         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1822 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1823         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1824                                                         "config");
1825 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1826         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1827 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1828         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1829                                                         "loopback");
1830 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1831         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1832
1833 cmdline_parse_inst_t cmd_config_loopback_all = {
1834         .f = cmd_config_loopback_all_parsed,
1835         .data = NULL,
1836         .help_str = "port config all loopback <mode>",
1837         .tokens = {
1838                 (void *)&cmd_config_loopback_all_port,
1839                 (void *)&cmd_config_loopback_all_keyword,
1840                 (void *)&cmd_config_loopback_all_all,
1841                 (void *)&cmd_config_loopback_all_item,
1842                 (void *)&cmd_config_loopback_all_mode,
1843                 NULL,
1844         },
1845 };
1846
1847 /* *** configure loopback for specific port *** */
1848 struct cmd_config_loopback_specific {
1849         cmdline_fixed_string_t port;
1850         cmdline_fixed_string_t keyword;
1851         uint16_t port_id;
1852         cmdline_fixed_string_t item;
1853         uint32_t mode;
1854 };
1855
1856 static void
1857 cmd_config_loopback_specific_parsed(void *parsed_result,
1858                                 __rte_unused struct cmdline *cl,
1859                                 __rte_unused void *data)
1860 {
1861         struct cmd_config_loopback_specific *res = parsed_result;
1862
1863         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1864                 return;
1865
1866         if (!port_is_stopped(res->port_id)) {
1867                 printf("Please stop port %u first\n", res->port_id);
1868                 return;
1869         }
1870
1871         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1872
1873         cmd_reconfig_device_queue(res->port_id, 1, 1);
1874 }
1875
1876
1877 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1878         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1879                                                                 "port");
1880 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1881         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1882                                                                 "config");
1883 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1884         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1885                                                                 UINT16);
1886 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1887         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1888                                                                 "loopback");
1889 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1890         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1891                               UINT32);
1892
1893 cmdline_parse_inst_t cmd_config_loopback_specific = {
1894         .f = cmd_config_loopback_specific_parsed,
1895         .data = NULL,
1896         .help_str = "port config <port_id> loopback <mode>",
1897         .tokens = {
1898                 (void *)&cmd_config_loopback_specific_port,
1899                 (void *)&cmd_config_loopback_specific_keyword,
1900                 (void *)&cmd_config_loopback_specific_id,
1901                 (void *)&cmd_config_loopback_specific_item,
1902                 (void *)&cmd_config_loopback_specific_mode,
1903                 NULL,
1904         },
1905 };
1906
1907 /* *** configure txq/rxq, txd/rxd *** */
1908 struct cmd_config_rx_tx {
1909         cmdline_fixed_string_t port;
1910         cmdline_fixed_string_t keyword;
1911         cmdline_fixed_string_t all;
1912         cmdline_fixed_string_t name;
1913         uint16_t value;
1914 };
1915
1916 static void
1917 cmd_config_rx_tx_parsed(void *parsed_result,
1918                         __rte_unused struct cmdline *cl,
1919                         __rte_unused void *data)
1920 {
1921         struct cmd_config_rx_tx *res = parsed_result;
1922
1923         if (!all_ports_stopped()) {
1924                 printf("Please stop all ports first\n");
1925                 return;
1926         }
1927         if (!strcmp(res->name, "rxq")) {
1928                 if (!res->value && !nb_txq) {
1929                         printf("Warning: Either rx or tx queues should be non zero\n");
1930                         return;
1931                 }
1932                 if (check_nb_rxq(res->value) != 0)
1933                         return;
1934                 nb_rxq = res->value;
1935         }
1936         else if (!strcmp(res->name, "txq")) {
1937                 if (!res->value && !nb_rxq) {
1938                         printf("Warning: Either rx or tx queues should be non zero\n");
1939                         return;
1940                 }
1941                 if (check_nb_txq(res->value) != 0)
1942                         return;
1943                 nb_txq = res->value;
1944         }
1945         else if (!strcmp(res->name, "rxd")) {
1946                 if (check_nb_rxd(res->value) != 0)
1947                         return;
1948                 nb_rxd = res->value;
1949         } else if (!strcmp(res->name, "txd")) {
1950                 if (check_nb_txd(res->value) != 0)
1951                         return;
1952
1953                 nb_txd = res->value;
1954         } else {
1955                 printf("Unknown parameter\n");
1956                 return;
1957         }
1958
1959         fwd_config_setup();
1960
1961         init_port_config();
1962
1963         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1964 }
1965
1966 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1967         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1968 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1969         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1970 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1971         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1972 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1973         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1974                                                 "rxq#txq#rxd#txd");
1975 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1976         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1977
1978 cmdline_parse_inst_t cmd_config_rx_tx = {
1979         .f = cmd_config_rx_tx_parsed,
1980         .data = NULL,
1981         .help_str = "port config all rxq|txq|rxd|txd <value>",
1982         .tokens = {
1983                 (void *)&cmd_config_rx_tx_port,
1984                 (void *)&cmd_config_rx_tx_keyword,
1985                 (void *)&cmd_config_rx_tx_all,
1986                 (void *)&cmd_config_rx_tx_name,
1987                 (void *)&cmd_config_rx_tx_value,
1988                 NULL,
1989         },
1990 };
1991
1992 /* *** config max packet length *** */
1993 struct cmd_config_max_pkt_len_result {
1994         cmdline_fixed_string_t port;
1995         cmdline_fixed_string_t keyword;
1996         cmdline_fixed_string_t all;
1997         cmdline_fixed_string_t name;
1998         uint32_t value;
1999 };
2000
2001 static void
2002 cmd_config_max_pkt_len_parsed(void *parsed_result,
2003                                 __rte_unused struct cmdline *cl,
2004                                 __rte_unused void *data)
2005 {
2006         struct cmd_config_max_pkt_len_result *res = parsed_result;
2007         portid_t pid;
2008
2009         if (!all_ports_stopped()) {
2010                 printf("Please stop all ports first\n");
2011                 return;
2012         }
2013
2014         RTE_ETH_FOREACH_DEV(pid) {
2015                 struct rte_port *port = &ports[pid];
2016                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2017
2018                 if (!strcmp(res->name, "max-pkt-len")) {
2019                         if (res->value < RTE_ETHER_MIN_LEN) {
2020                                 printf("max-pkt-len can not be less than %d\n",
2021                                                 RTE_ETHER_MIN_LEN);
2022                                 return;
2023                         }
2024                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2025                                 return;
2026
2027                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2028                         if (res->value > RTE_ETHER_MAX_LEN)
2029                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2030                         else
2031                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2032                         port->dev_conf.rxmode.offloads = rx_offloads;
2033                 } else {
2034                         printf("Unknown parameter\n");
2035                         return;
2036                 }
2037         }
2038
2039         init_port_config();
2040
2041         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2042 }
2043
2044 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2045         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2046                                                                 "port");
2047 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2048         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2049                                                                 "config");
2050 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2051         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2052                                                                 "all");
2053 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2054         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2055                                                                 "max-pkt-len");
2056 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2057         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2058                                                                 UINT32);
2059
2060 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2061         .f = cmd_config_max_pkt_len_parsed,
2062         .data = NULL,
2063         .help_str = "port config all max-pkt-len <value>",
2064         .tokens = {
2065                 (void *)&cmd_config_max_pkt_len_port,
2066                 (void *)&cmd_config_max_pkt_len_keyword,
2067                 (void *)&cmd_config_max_pkt_len_all,
2068                 (void *)&cmd_config_max_pkt_len_name,
2069                 (void *)&cmd_config_max_pkt_len_value,
2070                 NULL,
2071         },
2072 };
2073
2074 /* *** config max LRO aggregated packet size *** */
2075 struct cmd_config_max_lro_pkt_size_result {
2076         cmdline_fixed_string_t port;
2077         cmdline_fixed_string_t keyword;
2078         cmdline_fixed_string_t all;
2079         cmdline_fixed_string_t name;
2080         uint32_t value;
2081 };
2082
2083 static void
2084 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2085                                 __rte_unused struct cmdline *cl,
2086                                 __rte_unused void *data)
2087 {
2088         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2089         portid_t pid;
2090
2091         if (!all_ports_stopped()) {
2092                 printf("Please stop all ports first\n");
2093                 return;
2094         }
2095
2096         RTE_ETH_FOREACH_DEV(pid) {
2097                 struct rte_port *port = &ports[pid];
2098
2099                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2100                         if (res->value ==
2101                                         port->dev_conf.rxmode.max_lro_pkt_size)
2102                                 return;
2103
2104                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2105                 } else {
2106                         printf("Unknown parameter\n");
2107                         return;
2108                 }
2109         }
2110
2111         init_port_config();
2112
2113         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2114 }
2115
2116 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2117         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2118                                  port, "port");
2119 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2120         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2121                                  keyword, "config");
2122 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2123         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2124                                  all, "all");
2125 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2126         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2127                                  name, "max-lro-pkt-size");
2128 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2129         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2130                               value, UINT32);
2131
2132 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2133         .f = cmd_config_max_lro_pkt_size_parsed,
2134         .data = NULL,
2135         .help_str = "port config all max-lro-pkt-size <value>",
2136         .tokens = {
2137                 (void *)&cmd_config_max_lro_pkt_size_port,
2138                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2139                 (void *)&cmd_config_max_lro_pkt_size_all,
2140                 (void *)&cmd_config_max_lro_pkt_size_name,
2141                 (void *)&cmd_config_max_lro_pkt_size_value,
2142                 NULL,
2143         },
2144 };
2145
2146 /* *** configure port MTU *** */
2147 struct cmd_config_mtu_result {
2148         cmdline_fixed_string_t port;
2149         cmdline_fixed_string_t keyword;
2150         cmdline_fixed_string_t mtu;
2151         portid_t port_id;
2152         uint16_t value;
2153 };
2154
2155 static void
2156 cmd_config_mtu_parsed(void *parsed_result,
2157                       __rte_unused struct cmdline *cl,
2158                       __rte_unused void *data)
2159 {
2160         struct cmd_config_mtu_result *res = parsed_result;
2161
2162         if (res->value < RTE_ETHER_MIN_LEN) {
2163                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2164                 return;
2165         }
2166         port_mtu_set(res->port_id, res->value);
2167 }
2168
2169 cmdline_parse_token_string_t cmd_config_mtu_port =
2170         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2171                                  "port");
2172 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2173         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2174                                  "config");
2175 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2176         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2177                                  "mtu");
2178 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2179         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2180 cmdline_parse_token_num_t cmd_config_mtu_value =
2181         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2182
2183 cmdline_parse_inst_t cmd_config_mtu = {
2184         .f = cmd_config_mtu_parsed,
2185         .data = NULL,
2186         .help_str = "port config mtu <port_id> <value>",
2187         .tokens = {
2188                 (void *)&cmd_config_mtu_port,
2189                 (void *)&cmd_config_mtu_keyword,
2190                 (void *)&cmd_config_mtu_mtu,
2191                 (void *)&cmd_config_mtu_port_id,
2192                 (void *)&cmd_config_mtu_value,
2193                 NULL,
2194         },
2195 };
2196
2197 /* *** configure rx mode *** */
2198 struct cmd_config_rx_mode_flag {
2199         cmdline_fixed_string_t port;
2200         cmdline_fixed_string_t keyword;
2201         cmdline_fixed_string_t all;
2202         cmdline_fixed_string_t name;
2203         cmdline_fixed_string_t value;
2204 };
2205
2206 static void
2207 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2208                                 __rte_unused struct cmdline *cl,
2209                                 __rte_unused void *data)
2210 {
2211         struct cmd_config_rx_mode_flag *res = parsed_result;
2212
2213         if (!all_ports_stopped()) {
2214                 printf("Please stop all ports first\n");
2215                 return;
2216         }
2217
2218         if (!strcmp(res->name, "drop-en")) {
2219                 if (!strcmp(res->value, "on"))
2220                         rx_drop_en = 1;
2221                 else if (!strcmp(res->value, "off"))
2222                         rx_drop_en = 0;
2223                 else {
2224                         printf("Unknown parameter\n");
2225                         return;
2226                 }
2227         } else {
2228                 printf("Unknown parameter\n");
2229                 return;
2230         }
2231
2232         init_port_config();
2233
2234         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2235 }
2236
2237 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2238         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2239 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2240         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2241                                                                 "config");
2242 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2243         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2244 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2245         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2246                                         "drop-en");
2247 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2248         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2249                                                         "on#off");
2250
2251 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2252         .f = cmd_config_rx_mode_flag_parsed,
2253         .data = NULL,
2254         .help_str = "port config all drop-en on|off",
2255         .tokens = {
2256                 (void *)&cmd_config_rx_mode_flag_port,
2257                 (void *)&cmd_config_rx_mode_flag_keyword,
2258                 (void *)&cmd_config_rx_mode_flag_all,
2259                 (void *)&cmd_config_rx_mode_flag_name,
2260                 (void *)&cmd_config_rx_mode_flag_value,
2261                 NULL,
2262         },
2263 };
2264
2265 /* *** configure rss *** */
2266 struct cmd_config_rss {
2267         cmdline_fixed_string_t port;
2268         cmdline_fixed_string_t keyword;
2269         cmdline_fixed_string_t all;
2270         cmdline_fixed_string_t name;
2271         cmdline_fixed_string_t value;
2272 };
2273
2274 static void
2275 cmd_config_rss_parsed(void *parsed_result,
2276                         __rte_unused struct cmdline *cl,
2277                         __rte_unused void *data)
2278 {
2279         struct cmd_config_rss *res = parsed_result;
2280         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2281         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2282         int use_default = 0;
2283         int all_updated = 1;
2284         int diag;
2285         uint16_t i;
2286         int ret;
2287
2288         if (!strcmp(res->value, "all"))
2289                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2290                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2291                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2292                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2293         else if (!strcmp(res->value, "eth"))
2294                 rss_conf.rss_hf = ETH_RSS_ETH;
2295         else if (!strcmp(res->value, "vlan"))
2296                 rss_conf.rss_hf = ETH_RSS_VLAN;
2297         else if (!strcmp(res->value, "ip"))
2298                 rss_conf.rss_hf = ETH_RSS_IP;
2299         else if (!strcmp(res->value, "udp"))
2300                 rss_conf.rss_hf = ETH_RSS_UDP;
2301         else if (!strcmp(res->value, "tcp"))
2302                 rss_conf.rss_hf = ETH_RSS_TCP;
2303         else if (!strcmp(res->value, "sctp"))
2304                 rss_conf.rss_hf = ETH_RSS_SCTP;
2305         else if (!strcmp(res->value, "ether"))
2306                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2307         else if (!strcmp(res->value, "port"))
2308                 rss_conf.rss_hf = ETH_RSS_PORT;
2309         else if (!strcmp(res->value, "vxlan"))
2310                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2311         else if (!strcmp(res->value, "geneve"))
2312                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2313         else if (!strcmp(res->value, "nvgre"))
2314                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2315         else if (!strcmp(res->value, "l3-pre32"))
2316                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2317         else if (!strcmp(res->value, "l3-pre40"))
2318                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2319         else if (!strcmp(res->value, "l3-pre48"))
2320                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2321         else if (!strcmp(res->value, "l3-pre56"))
2322                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2323         else if (!strcmp(res->value, "l3-pre64"))
2324                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2325         else if (!strcmp(res->value, "l3-pre96"))
2326                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2327         else if (!strcmp(res->value, "l3-src-only"))
2328                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2329         else if (!strcmp(res->value, "l3-dst-only"))
2330                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2331         else if (!strcmp(res->value, "l4-src-only"))
2332                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2333         else if (!strcmp(res->value, "l4-dst-only"))
2334                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2335         else if (!strcmp(res->value, "l2-src-only"))
2336                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2337         else if (!strcmp(res->value, "l2-dst-only"))
2338                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2339         else if (!strcmp(res->value, "l2tpv3"))
2340                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2341         else if (!strcmp(res->value, "esp"))
2342                 rss_conf.rss_hf = ETH_RSS_ESP;
2343         else if (!strcmp(res->value, "ah"))
2344                 rss_conf.rss_hf = ETH_RSS_AH;
2345         else if (!strcmp(res->value, "pfcp"))
2346                 rss_conf.rss_hf = ETH_RSS_PFCP;
2347         else if (!strcmp(res->value, "pppoe"))
2348                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2349         else if (!strcmp(res->value, "gtpu"))
2350                 rss_conf.rss_hf = ETH_RSS_GTPU;
2351         else if (!strcmp(res->value, "none"))
2352                 rss_conf.rss_hf = 0;
2353         else if (!strcmp(res->value, "level-default")) {
2354                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2355                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2356         } else if (!strcmp(res->value, "level-outer")) {
2357                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2358                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2359         } else if (!strcmp(res->value, "level-inner")) {
2360                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2361                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2362         } else if (!strcmp(res->value, "default"))
2363                 use_default = 1;
2364         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2365                                                 atoi(res->value) < 64)
2366                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2367         else {
2368                 printf("Unknown parameter\n");
2369                 return;
2370         }
2371         rss_conf.rss_key = NULL;
2372         /* Update global configuration for RSS types. */
2373         RTE_ETH_FOREACH_DEV(i) {
2374                 struct rte_eth_rss_conf local_rss_conf;
2375
2376                 ret = eth_dev_info_get_print_err(i, &dev_info);
2377                 if (ret != 0)
2378                         return;
2379
2380                 if (use_default)
2381                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2382
2383                 local_rss_conf = rss_conf;
2384                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2385                         dev_info.flow_type_rss_offloads;
2386                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2387                         printf("Port %u modified RSS hash function based on hardware support,"
2388                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2389                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2390                 }
2391                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2392                 if (diag < 0) {
2393                         all_updated = 0;
2394                         printf("Configuration of RSS hash at ethernet port %d "
2395                                 "failed with error (%d): %s.\n",
2396                                 i, -diag, strerror(-diag));
2397                 }
2398         }
2399         if (all_updated && !use_default) {
2400                 rss_hf = rss_conf.rss_hf;
2401                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2402         }
2403 }
2404
2405 cmdline_parse_token_string_t cmd_config_rss_port =
2406         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2407 cmdline_parse_token_string_t cmd_config_rss_keyword =
2408         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2409 cmdline_parse_token_string_t cmd_config_rss_all =
2410         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2411 cmdline_parse_token_string_t cmd_config_rss_name =
2412         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2413 cmdline_parse_token_string_t cmd_config_rss_value =
2414         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2415
2416 cmdline_parse_inst_t cmd_config_rss = {
2417         .f = cmd_config_rss_parsed,
2418         .data = NULL,
2419         .help_str = "port config all rss "
2420                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2421                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2422                 "level-outer|level-inner|<flowtype_id>",
2423         .tokens = {
2424                 (void *)&cmd_config_rss_port,
2425                 (void *)&cmd_config_rss_keyword,
2426                 (void *)&cmd_config_rss_all,
2427                 (void *)&cmd_config_rss_name,
2428                 (void *)&cmd_config_rss_value,
2429                 NULL,
2430         },
2431 };
2432
2433 /* *** configure rss hash key *** */
2434 struct cmd_config_rss_hash_key {
2435         cmdline_fixed_string_t port;
2436         cmdline_fixed_string_t config;
2437         portid_t port_id;
2438         cmdline_fixed_string_t rss_hash_key;
2439         cmdline_fixed_string_t rss_type;
2440         cmdline_fixed_string_t key;
2441 };
2442
2443 static uint8_t
2444 hexa_digit_to_value(char hexa_digit)
2445 {
2446         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2447                 return (uint8_t) (hexa_digit - '0');
2448         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2449                 return (uint8_t) ((hexa_digit - 'a') + 10);
2450         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2451                 return (uint8_t) ((hexa_digit - 'A') + 10);
2452         /* Invalid hexa digit */
2453         return 0xFF;
2454 }
2455
2456 static uint8_t
2457 parse_and_check_key_hexa_digit(char *key, int idx)
2458 {
2459         uint8_t hexa_v;
2460
2461         hexa_v = hexa_digit_to_value(key[idx]);
2462         if (hexa_v == 0xFF)
2463                 printf("invalid key: character %c at position %d is not a "
2464                        "valid hexa digit\n", key[idx], idx);
2465         return hexa_v;
2466 }
2467
2468 static void
2469 cmd_config_rss_hash_key_parsed(void *parsed_result,
2470                                __rte_unused struct cmdline *cl,
2471                                __rte_unused void *data)
2472 {
2473         struct cmd_config_rss_hash_key *res = parsed_result;
2474         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2475         uint8_t xdgt0;
2476         uint8_t xdgt1;
2477         int i;
2478         struct rte_eth_dev_info dev_info;
2479         uint8_t hash_key_size;
2480         uint32_t key_len;
2481         int ret;
2482
2483         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2484         if (ret != 0)
2485                 return;
2486
2487         if (dev_info.hash_key_size > 0 &&
2488                         dev_info.hash_key_size <= sizeof(hash_key))
2489                 hash_key_size = dev_info.hash_key_size;
2490         else {
2491                 printf("dev_info did not provide a valid hash key size\n");
2492                 return;
2493         }
2494         /* Check the length of the RSS hash key */
2495         key_len = strlen(res->key);
2496         if (key_len != (hash_key_size * 2)) {
2497                 printf("key length: %d invalid - key must be a string of %d"
2498                            " hexa-decimal numbers\n",
2499                            (int) key_len, hash_key_size * 2);
2500                 return;
2501         }
2502         /* Translate RSS hash key into binary representation */
2503         for (i = 0; i < hash_key_size; i++) {
2504                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2505                 if (xdgt0 == 0xFF)
2506                         return;
2507                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2508                 if (xdgt1 == 0xFF)
2509                         return;
2510                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2511         }
2512         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2513                         hash_key_size);
2514 }
2515
2516 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2517         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2518 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2519         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2520                                  "config");
2521 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2522         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2523 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2524         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2525                                  rss_hash_key, "rss-hash-key");
2526 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2527         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2528                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2529                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2530                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2531                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2532                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2533                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2534                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2535 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2536         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2537
2538 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2539         .f = cmd_config_rss_hash_key_parsed,
2540         .data = NULL,
2541         .help_str = "port config <port_id> rss-hash-key "
2542                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2543                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2544                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2545                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2546                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2547                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2548                 "<string of hex digits (variable length, NIC dependent)>",
2549         .tokens = {
2550                 (void *)&cmd_config_rss_hash_key_port,
2551                 (void *)&cmd_config_rss_hash_key_config,
2552                 (void *)&cmd_config_rss_hash_key_port_id,
2553                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2554                 (void *)&cmd_config_rss_hash_key_rss_type,
2555                 (void *)&cmd_config_rss_hash_key_value,
2556                 NULL,
2557         },
2558 };
2559
2560 /* *** configure port rxq/txq ring size *** */
2561 struct cmd_config_rxtx_ring_size {
2562         cmdline_fixed_string_t port;
2563         cmdline_fixed_string_t config;
2564         portid_t portid;
2565         cmdline_fixed_string_t rxtxq;
2566         uint16_t qid;
2567         cmdline_fixed_string_t rsize;
2568         uint16_t size;
2569 };
2570
2571 static void
2572 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2573                                  __rte_unused struct cmdline *cl,
2574                                  __rte_unused void *data)
2575 {
2576         struct cmd_config_rxtx_ring_size *res = parsed_result;
2577         struct rte_port *port;
2578         uint8_t isrx;
2579
2580         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2581                 return;
2582
2583         if (res->portid == (portid_t)RTE_PORT_ALL) {
2584                 printf("Invalid port id\n");
2585                 return;
2586         }
2587
2588         port = &ports[res->portid];
2589
2590         if (!strcmp(res->rxtxq, "rxq"))
2591                 isrx = 1;
2592         else if (!strcmp(res->rxtxq, "txq"))
2593                 isrx = 0;
2594         else {
2595                 printf("Unknown parameter\n");
2596                 return;
2597         }
2598
2599         if (isrx && rx_queue_id_is_invalid(res->qid))
2600                 return;
2601         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2602                 return;
2603
2604         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2605                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2606                        rx_free_thresh);
2607                 return;
2608         }
2609
2610         if (isrx)
2611                 port->nb_rx_desc[res->qid] = res->size;
2612         else
2613                 port->nb_tx_desc[res->qid] = res->size;
2614
2615         cmd_reconfig_device_queue(res->portid, 0, 1);
2616 }
2617
2618 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2619         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2620                                  port, "port");
2621 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2622         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2623                                  config, "config");
2624 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2625         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2626                                  portid, UINT16);
2627 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2628         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2629                                  rxtxq, "rxq#txq");
2630 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2631         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2632                               qid, UINT16);
2633 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2634         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2635                                  rsize, "ring_size");
2636 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2637         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2638                               size, UINT16);
2639
2640 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2641         .f = cmd_config_rxtx_ring_size_parsed,
2642         .data = NULL,
2643         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2644         .tokens = {
2645                 (void *)&cmd_config_rxtx_ring_size_port,
2646                 (void *)&cmd_config_rxtx_ring_size_config,
2647                 (void *)&cmd_config_rxtx_ring_size_portid,
2648                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2649                 (void *)&cmd_config_rxtx_ring_size_qid,
2650                 (void *)&cmd_config_rxtx_ring_size_rsize,
2651                 (void *)&cmd_config_rxtx_ring_size_size,
2652                 NULL,
2653         },
2654 };
2655
2656 /* *** configure port rxq/txq start/stop *** */
2657 struct cmd_config_rxtx_queue {
2658         cmdline_fixed_string_t port;
2659         portid_t portid;
2660         cmdline_fixed_string_t rxtxq;
2661         uint16_t qid;
2662         cmdline_fixed_string_t opname;
2663 };
2664
2665 static void
2666 cmd_config_rxtx_queue_parsed(void *parsed_result,
2667                         __rte_unused struct cmdline *cl,
2668                         __rte_unused void *data)
2669 {
2670         struct cmd_config_rxtx_queue *res = parsed_result;
2671         uint8_t isrx;
2672         uint8_t isstart;
2673         int ret = 0;
2674
2675         if (test_done == 0) {
2676                 printf("Please stop forwarding first\n");
2677                 return;
2678         }
2679
2680         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2681                 return;
2682
2683         if (port_is_started(res->portid) != 1) {
2684                 printf("Please start port %u first\n", res->portid);
2685                 return;
2686         }
2687
2688         if (!strcmp(res->rxtxq, "rxq"))
2689                 isrx = 1;
2690         else if (!strcmp(res->rxtxq, "txq"))
2691                 isrx = 0;
2692         else {
2693                 printf("Unknown parameter\n");
2694                 return;
2695         }
2696
2697         if (isrx && rx_queue_id_is_invalid(res->qid))
2698                 return;
2699         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2700                 return;
2701
2702         if (!strcmp(res->opname, "start"))
2703                 isstart = 1;
2704         else if (!strcmp(res->opname, "stop"))
2705                 isstart = 0;
2706         else {
2707                 printf("Unknown parameter\n");
2708                 return;
2709         }
2710
2711         if (isstart && isrx)
2712                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2713         else if (!isstart && isrx)
2714                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2715         else if (isstart && !isrx)
2716                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2717         else
2718                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2719
2720         if (ret == -ENOTSUP)
2721                 printf("Function not supported in PMD driver\n");
2722 }
2723
2724 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2725         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2726 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2727         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2728 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2729         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2730 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2731         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2732 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2733         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2734                                                 "start#stop");
2735
2736 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2737         .f = cmd_config_rxtx_queue_parsed,
2738         .data = NULL,
2739         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2740         .tokens = {
2741                 (void *)&cmd_config_rxtx_queue_port,
2742                 (void *)&cmd_config_rxtx_queue_portid,
2743                 (void *)&cmd_config_rxtx_queue_rxtxq,
2744                 (void *)&cmd_config_rxtx_queue_qid,
2745                 (void *)&cmd_config_rxtx_queue_opname,
2746                 NULL,
2747         },
2748 };
2749
2750 /* *** configure port rxq/txq deferred start on/off *** */
2751 struct cmd_config_deferred_start_rxtx_queue {
2752         cmdline_fixed_string_t port;
2753         portid_t port_id;
2754         cmdline_fixed_string_t rxtxq;
2755         uint16_t qid;
2756         cmdline_fixed_string_t opname;
2757         cmdline_fixed_string_t state;
2758 };
2759
2760 static void
2761 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2762                         __rte_unused struct cmdline *cl,
2763                         __rte_unused void *data)
2764 {
2765         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2766         struct rte_port *port;
2767         uint8_t isrx;
2768         uint8_t ison;
2769         uint8_t needreconfig = 0;
2770
2771         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2772                 return;
2773
2774         if (port_is_started(res->port_id) != 0) {
2775                 printf("Please stop port %u first\n", res->port_id);
2776                 return;
2777         }
2778
2779         port = &ports[res->port_id];
2780
2781         isrx = !strcmp(res->rxtxq, "rxq");
2782
2783         if (isrx && rx_queue_id_is_invalid(res->qid))
2784                 return;
2785         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2786                 return;
2787
2788         ison = !strcmp(res->state, "on");
2789
2790         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2791                 port->rx_conf[res->qid].rx_deferred_start = ison;
2792                 needreconfig = 1;
2793         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2794                 port->tx_conf[res->qid].tx_deferred_start = ison;
2795                 needreconfig = 1;
2796         }
2797
2798         if (needreconfig)
2799                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2800 }
2801
2802 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2803         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2804                                                 port, "port");
2805 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2806         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2807                                                 port_id, UINT16);
2808 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2809         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2810                                                 rxtxq, "rxq#txq");
2811 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2812         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2813                                                 qid, UINT16);
2814 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2815         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2816                                                 opname, "deferred_start");
2817 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2818         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2819                                                 state, "on#off");
2820
2821 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2822         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2823         .data = NULL,
2824         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2825         .tokens = {
2826                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2827                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2828                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2829                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2830                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2831                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2832                 NULL,
2833         },
2834 };
2835
2836 /* *** configure port rxq/txq setup *** */
2837 struct cmd_setup_rxtx_queue {
2838         cmdline_fixed_string_t port;
2839         portid_t portid;
2840         cmdline_fixed_string_t rxtxq;
2841         uint16_t qid;
2842         cmdline_fixed_string_t setup;
2843 };
2844
2845 /* Common CLI fields for queue setup */
2846 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2847         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2848 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2849         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2850 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2851         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2852 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2853         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2854 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2855         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2856
2857 static void
2858 cmd_setup_rxtx_queue_parsed(
2859         void *parsed_result,
2860         __rte_unused struct cmdline *cl,
2861         __rte_unused void *data)
2862 {
2863         struct cmd_setup_rxtx_queue *res = parsed_result;
2864         struct rte_port *port;
2865         struct rte_mempool *mp;
2866         unsigned int socket_id;
2867         uint8_t isrx = 0;
2868         int ret;
2869
2870         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2871                 return;
2872
2873         if (res->portid == (portid_t)RTE_PORT_ALL) {
2874                 printf("Invalid port id\n");
2875                 return;
2876         }
2877
2878         if (!strcmp(res->rxtxq, "rxq"))
2879                 isrx = 1;
2880         else if (!strcmp(res->rxtxq, "txq"))
2881                 isrx = 0;
2882         else {
2883                 printf("Unknown parameter\n");
2884                 return;
2885         }
2886
2887         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2888                 printf("Invalid rx queue\n");
2889                 return;
2890         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2891                 printf("Invalid tx queue\n");
2892                 return;
2893         }
2894
2895         port = &ports[res->portid];
2896         if (isrx) {
2897                 socket_id = rxring_numa[res->portid];
2898                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2899                         socket_id = port->socket_id;
2900
2901                 mp = mbuf_pool_find(socket_id);
2902                 if (mp == NULL) {
2903                         printf("Failed to setup RX queue: "
2904                                 "No mempool allocation"
2905                                 " on the socket %d\n",
2906                                 rxring_numa[res->portid]);
2907                         return;
2908                 }
2909                 ret = rte_eth_rx_queue_setup(res->portid,
2910                                              res->qid,
2911                                              port->nb_rx_desc[res->qid],
2912                                              socket_id,
2913                                              &port->rx_conf[res->qid],
2914                                              mp);
2915                 if (ret)
2916                         printf("Failed to setup RX queue\n");
2917         } else {
2918                 socket_id = txring_numa[res->portid];
2919                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2920                         socket_id = port->socket_id;
2921
2922                 ret = rte_eth_tx_queue_setup(res->portid,
2923                                              res->qid,
2924                                              port->nb_tx_desc[res->qid],
2925                                              socket_id,
2926                                              &port->tx_conf[res->qid]);
2927                 if (ret)
2928                         printf("Failed to setup TX queue\n");
2929         }
2930 }
2931
2932 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2933         .f = cmd_setup_rxtx_queue_parsed,
2934         .data = NULL,
2935         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2936         .tokens = {
2937                 (void *)&cmd_setup_rxtx_queue_port,
2938                 (void *)&cmd_setup_rxtx_queue_portid,
2939                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2940                 (void *)&cmd_setup_rxtx_queue_qid,
2941                 (void *)&cmd_setup_rxtx_queue_setup,
2942                 NULL,
2943         },
2944 };
2945
2946
2947 /* *** Configure RSS RETA *** */
2948 struct cmd_config_rss_reta {
2949         cmdline_fixed_string_t port;
2950         cmdline_fixed_string_t keyword;
2951         portid_t port_id;
2952         cmdline_fixed_string_t name;
2953         cmdline_fixed_string_t list_name;
2954         cmdline_fixed_string_t list_of_items;
2955 };
2956
2957 static int
2958 parse_reta_config(const char *str,
2959                   struct rte_eth_rss_reta_entry64 *reta_conf,
2960                   uint16_t nb_entries)
2961 {
2962         int i;
2963         unsigned size;
2964         uint16_t hash_index, idx, shift;
2965         uint16_t nb_queue;
2966         char s[256];
2967         const char *p, *p0 = str;
2968         char *end;
2969         enum fieldnames {
2970                 FLD_HASH_INDEX = 0,
2971                 FLD_QUEUE,
2972                 _NUM_FLD
2973         };
2974         unsigned long int_fld[_NUM_FLD];
2975         char *str_fld[_NUM_FLD];
2976
2977         while ((p = strchr(p0,'(')) != NULL) {
2978                 ++p;
2979                 if((p0 = strchr(p,')')) == NULL)
2980                         return -1;
2981
2982                 size = p0 - p;
2983                 if(size >= sizeof(s))
2984                         return -1;
2985
2986                 snprintf(s, sizeof(s), "%.*s", size, p);
2987                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2988                         return -1;
2989                 for (i = 0; i < _NUM_FLD; i++) {
2990                         errno = 0;
2991                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2992                         if (errno != 0 || end == str_fld[i] ||
2993                                         int_fld[i] > 65535)
2994                                 return -1;
2995                 }
2996
2997                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2998                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2999
3000                 if (hash_index >= nb_entries) {
3001                         printf("Invalid RETA hash index=%d\n", hash_index);
3002                         return -1;
3003                 }
3004
3005                 idx = hash_index / RTE_RETA_GROUP_SIZE;
3006                 shift = hash_index % RTE_RETA_GROUP_SIZE;
3007                 reta_conf[idx].mask |= (1ULL << shift);
3008                 reta_conf[idx].reta[shift] = nb_queue;
3009         }
3010
3011         return 0;
3012 }
3013
3014 static void
3015 cmd_set_rss_reta_parsed(void *parsed_result,
3016                         __rte_unused struct cmdline *cl,
3017                         __rte_unused void *data)
3018 {
3019         int ret;
3020         struct rte_eth_dev_info dev_info;
3021         struct rte_eth_rss_reta_entry64 reta_conf[8];
3022         struct cmd_config_rss_reta *res = parsed_result;
3023
3024         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3025         if (ret != 0)
3026                 return;
3027
3028         if (dev_info.reta_size == 0) {
3029                 printf("Redirection table size is 0 which is "
3030                                         "invalid for RSS\n");
3031                 return;
3032         } else
3033                 printf("The reta size of port %d is %u\n",
3034                         res->port_id, dev_info.reta_size);
3035         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3036                 printf("Currently do not support more than %u entries of "
3037                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3038                 return;
3039         }
3040
3041         memset(reta_conf, 0, sizeof(reta_conf));
3042         if (!strcmp(res->list_name, "reta")) {
3043                 if (parse_reta_config(res->list_of_items, reta_conf,
3044                                                 dev_info.reta_size)) {
3045                         printf("Invalid RSS Redirection Table "
3046                                         "config entered\n");
3047                         return;
3048                 }
3049                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3050                                 reta_conf, dev_info.reta_size);
3051                 if (ret != 0)
3052                         printf("Bad redirection table parameter, "
3053                                         "return code = %d \n", ret);
3054         }
3055 }
3056
3057 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3058         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3059 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3060         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3061 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3062         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3063 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3064         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3065 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3066         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3067 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3068         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3069                                  NULL);
3070 cmdline_parse_inst_t cmd_config_rss_reta = {
3071         .f = cmd_set_rss_reta_parsed,
3072         .data = NULL,
3073         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3074         .tokens = {
3075                 (void *)&cmd_config_rss_reta_port,
3076                 (void *)&cmd_config_rss_reta_keyword,
3077                 (void *)&cmd_config_rss_reta_port_id,
3078                 (void *)&cmd_config_rss_reta_name,
3079                 (void *)&cmd_config_rss_reta_list_name,
3080                 (void *)&cmd_config_rss_reta_list_of_items,
3081                 NULL,
3082         },
3083 };
3084
3085 /* *** SHOW PORT RETA INFO *** */
3086 struct cmd_showport_reta {
3087         cmdline_fixed_string_t show;
3088         cmdline_fixed_string_t port;
3089         portid_t port_id;
3090         cmdline_fixed_string_t rss;
3091         cmdline_fixed_string_t reta;
3092         uint16_t size;
3093         cmdline_fixed_string_t list_of_items;
3094 };
3095
3096 static int
3097 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3098                            uint16_t nb_entries,
3099                            char *str)
3100 {
3101         uint32_t size;
3102         const char *p, *p0 = str;
3103         char s[256];
3104         char *end;
3105         char *str_fld[8];
3106         uint16_t i;
3107         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3108                         RTE_RETA_GROUP_SIZE;
3109         int ret;
3110
3111         p = strchr(p0, '(');
3112         if (p == NULL)
3113                 return -1;
3114         p++;
3115         p0 = strchr(p, ')');
3116         if (p0 == NULL)
3117                 return -1;
3118         size = p0 - p;
3119         if (size >= sizeof(s)) {
3120                 printf("The string size exceeds the internal buffer size\n");
3121                 return -1;
3122         }
3123         snprintf(s, sizeof(s), "%.*s", size, p);
3124         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3125         if (ret <= 0 || ret != num) {
3126                 printf("The bits of masks do not match the number of "
3127                                         "reta entries: %u\n", num);
3128                 return -1;
3129         }
3130         for (i = 0; i < ret; i++)
3131                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3132
3133         return 0;
3134 }
3135
3136 static void
3137 cmd_showport_reta_parsed(void *parsed_result,
3138                          __rte_unused struct cmdline *cl,
3139                          __rte_unused void *data)
3140 {
3141         struct cmd_showport_reta *res = parsed_result;
3142         struct rte_eth_rss_reta_entry64 reta_conf[8];
3143         struct rte_eth_dev_info dev_info;
3144         uint16_t max_reta_size;
3145         int ret;
3146
3147         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3148         if (ret != 0)
3149                 return;
3150
3151         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3152         if (res->size == 0 || res->size > max_reta_size) {
3153                 printf("Invalid redirection table size: %u (1-%u)\n",
3154                         res->size, max_reta_size);
3155                 return;
3156         }
3157
3158         memset(reta_conf, 0, sizeof(reta_conf));
3159         if (showport_parse_reta_config(reta_conf, res->size,
3160                                 res->list_of_items) < 0) {
3161                 printf("Invalid string: %s for reta masks\n",
3162                                         res->list_of_items);
3163                 return;
3164         }
3165         port_rss_reta_info(res->port_id, reta_conf, res->size);
3166 }
3167
3168 cmdline_parse_token_string_t cmd_showport_reta_show =
3169         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3170 cmdline_parse_token_string_t cmd_showport_reta_port =
3171         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3172 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3173         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3174 cmdline_parse_token_string_t cmd_showport_reta_rss =
3175         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3176 cmdline_parse_token_string_t cmd_showport_reta_reta =
3177         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3178 cmdline_parse_token_num_t cmd_showport_reta_size =
3179         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3180 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3181         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3182                                         list_of_items, NULL);
3183
3184 cmdline_parse_inst_t cmd_showport_reta = {
3185         .f = cmd_showport_reta_parsed,
3186         .data = NULL,
3187         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3188         .tokens = {
3189                 (void *)&cmd_showport_reta_show,
3190                 (void *)&cmd_showport_reta_port,
3191                 (void *)&cmd_showport_reta_port_id,
3192                 (void *)&cmd_showport_reta_rss,
3193                 (void *)&cmd_showport_reta_reta,
3194                 (void *)&cmd_showport_reta_size,
3195                 (void *)&cmd_showport_reta_list_of_items,
3196                 NULL,
3197         },
3198 };
3199
3200 /* *** Show RSS hash configuration *** */
3201 struct cmd_showport_rss_hash {
3202         cmdline_fixed_string_t show;
3203         cmdline_fixed_string_t port;
3204         portid_t port_id;
3205         cmdline_fixed_string_t rss_hash;
3206         cmdline_fixed_string_t rss_type;
3207         cmdline_fixed_string_t key; /* optional argument */
3208 };
3209
3210 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3211                                 __rte_unused struct cmdline *cl,
3212                                 void *show_rss_key)
3213 {
3214         struct cmd_showport_rss_hash *res = parsed_result;
3215
3216         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3217 }
3218
3219 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3220         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3221 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3222         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3223 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3224         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3225 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3226         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3227                                  "rss-hash");
3228 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3229         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3230
3231 cmdline_parse_inst_t cmd_showport_rss_hash = {
3232         .f = cmd_showport_rss_hash_parsed,
3233         .data = NULL,
3234         .help_str = "show port <port_id> rss-hash",
3235         .tokens = {
3236                 (void *)&cmd_showport_rss_hash_show,
3237                 (void *)&cmd_showport_rss_hash_port,
3238                 (void *)&cmd_showport_rss_hash_port_id,
3239                 (void *)&cmd_showport_rss_hash_rss_hash,
3240                 NULL,
3241         },
3242 };
3243
3244 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3245         .f = cmd_showport_rss_hash_parsed,
3246         .data = (void *)1,
3247         .help_str = "show port <port_id> rss-hash key",
3248         .tokens = {
3249                 (void *)&cmd_showport_rss_hash_show,
3250                 (void *)&cmd_showport_rss_hash_port,
3251                 (void *)&cmd_showport_rss_hash_port_id,
3252                 (void *)&cmd_showport_rss_hash_rss_hash,
3253                 (void *)&cmd_showport_rss_hash_rss_key,
3254                 NULL,
3255         },
3256 };
3257
3258 /* *** Configure DCB *** */
3259 struct cmd_config_dcb {
3260         cmdline_fixed_string_t port;
3261         cmdline_fixed_string_t config;
3262         portid_t port_id;
3263         cmdline_fixed_string_t dcb;
3264         cmdline_fixed_string_t vt;
3265         cmdline_fixed_string_t vt_en;
3266         uint8_t num_tcs;
3267         cmdline_fixed_string_t pfc;
3268         cmdline_fixed_string_t pfc_en;
3269 };
3270
3271 static void
3272 cmd_config_dcb_parsed(void *parsed_result,
3273                         __rte_unused struct cmdline *cl,
3274                         __rte_unused void *data)
3275 {
3276         struct cmd_config_dcb *res = parsed_result;
3277         portid_t port_id = res->port_id;
3278         struct rte_port *port;
3279         uint8_t pfc_en;
3280         int ret;
3281
3282         port = &ports[port_id];
3283         /** Check if the port is not started **/
3284         if (port->port_status != RTE_PORT_STOPPED) {
3285                 printf("Please stop port %d first\n", port_id);
3286                 return;
3287         }
3288
3289         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3290                 printf("The invalid number of traffic class,"
3291                         " only 4 or 8 allowed.\n");
3292                 return;
3293         }
3294
3295         if (nb_fwd_lcores < res->num_tcs) {
3296                 printf("nb_cores shouldn't be less than number of TCs.\n");
3297                 return;
3298         }
3299         if (!strncmp(res->pfc_en, "on", 2))
3300                 pfc_en = 1;
3301         else
3302                 pfc_en = 0;
3303
3304         /* DCB in VT mode */
3305         if (!strncmp(res->vt_en, "on", 2))
3306                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3307                                 (enum rte_eth_nb_tcs)res->num_tcs,
3308                                 pfc_en);
3309         else
3310                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3311                                 (enum rte_eth_nb_tcs)res->num_tcs,
3312                                 pfc_en);
3313
3314
3315         if (ret != 0) {
3316                 printf("Cannot initialize network ports.\n");
3317                 return;
3318         }
3319
3320         cmd_reconfig_device_queue(port_id, 1, 1);
3321 }
3322
3323 cmdline_parse_token_string_t cmd_config_dcb_port =
3324         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3325 cmdline_parse_token_string_t cmd_config_dcb_config =
3326         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3327 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3328         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3329 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3330         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3331 cmdline_parse_token_string_t cmd_config_dcb_vt =
3332         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3333 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3334         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3335 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3336         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3337 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3338         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3339 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3340         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3341
3342 cmdline_parse_inst_t cmd_config_dcb = {
3343         .f = cmd_config_dcb_parsed,
3344         .data = NULL,
3345         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3346         .tokens = {
3347                 (void *)&cmd_config_dcb_port,
3348                 (void *)&cmd_config_dcb_config,
3349                 (void *)&cmd_config_dcb_port_id,
3350                 (void *)&cmd_config_dcb_dcb,
3351                 (void *)&cmd_config_dcb_vt,
3352                 (void *)&cmd_config_dcb_vt_en,
3353                 (void *)&cmd_config_dcb_num_tcs,
3354                 (void *)&cmd_config_dcb_pfc,
3355                 (void *)&cmd_config_dcb_pfc_en,
3356                 NULL,
3357         },
3358 };
3359
3360 /* *** configure number of packets per burst *** */
3361 struct cmd_config_burst {
3362         cmdline_fixed_string_t port;
3363         cmdline_fixed_string_t keyword;
3364         cmdline_fixed_string_t all;
3365         cmdline_fixed_string_t name;
3366         uint16_t value;
3367 };
3368
3369 static void
3370 cmd_config_burst_parsed(void *parsed_result,
3371                         __rte_unused struct cmdline *cl,
3372                         __rte_unused void *data)
3373 {
3374         struct cmd_config_burst *res = parsed_result;
3375         struct rte_eth_dev_info dev_info;
3376         uint16_t rec_nb_pkts;
3377         int ret;
3378
3379         if (!all_ports_stopped()) {
3380                 printf("Please stop all ports first\n");
3381                 return;
3382         }
3383
3384         if (!strcmp(res->name, "burst")) {
3385                 if (res->value == 0) {
3386                         /* If user gives a value of zero, query the PMD for
3387                          * its recommended Rx burst size. Testpmd uses a single
3388                          * size for all ports, so assume all ports are the same
3389                          * NIC model and use the values from Port 0.
3390                          */
3391                         ret = eth_dev_info_get_print_err(0, &dev_info);
3392                         if (ret != 0)
3393                                 return;
3394
3395                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3396
3397                         if (rec_nb_pkts == 0) {
3398                                 printf("PMD does not recommend a burst size.\n"
3399                                         "User provided value must be between"
3400                                         " 1 and %d\n", MAX_PKT_BURST);
3401                                 return;
3402                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3403                                 printf("PMD recommended burst size of %d"
3404                                         " exceeds maximum value of %d\n",
3405                                         rec_nb_pkts, MAX_PKT_BURST);
3406                                 return;
3407                         }
3408                         printf("Using PMD-provided burst value of %d\n",
3409                                 rec_nb_pkts);
3410                         nb_pkt_per_burst = rec_nb_pkts;
3411                 } else if (res->value > MAX_PKT_BURST) {
3412                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3413                         return;
3414                 } else
3415                         nb_pkt_per_burst = res->value;
3416         } else {
3417                 printf("Unknown parameter\n");
3418                 return;
3419         }
3420
3421         init_port_config();
3422
3423         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3424 }
3425
3426 cmdline_parse_token_string_t cmd_config_burst_port =
3427         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3428 cmdline_parse_token_string_t cmd_config_burst_keyword =
3429         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3430 cmdline_parse_token_string_t cmd_config_burst_all =
3431         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3432 cmdline_parse_token_string_t cmd_config_burst_name =
3433         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3434 cmdline_parse_token_num_t cmd_config_burst_value =
3435         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3436
3437 cmdline_parse_inst_t cmd_config_burst = {
3438         .f = cmd_config_burst_parsed,
3439         .data = NULL,
3440         .help_str = "port config all burst <value>",
3441         .tokens = {
3442                 (void *)&cmd_config_burst_port,
3443                 (void *)&cmd_config_burst_keyword,
3444                 (void *)&cmd_config_burst_all,
3445                 (void *)&cmd_config_burst_name,
3446                 (void *)&cmd_config_burst_value,
3447                 NULL,
3448         },
3449 };
3450
3451 /* *** configure rx/tx queues *** */
3452 struct cmd_config_thresh {
3453         cmdline_fixed_string_t port;
3454         cmdline_fixed_string_t keyword;
3455         cmdline_fixed_string_t all;
3456         cmdline_fixed_string_t name;
3457         uint8_t value;
3458 };
3459
3460 static void
3461 cmd_config_thresh_parsed(void *parsed_result,
3462                         __rte_unused struct cmdline *cl,
3463                         __rte_unused void *data)
3464 {
3465         struct cmd_config_thresh *res = parsed_result;
3466
3467         if (!all_ports_stopped()) {
3468                 printf("Please stop all ports first\n");
3469                 return;
3470         }
3471
3472         if (!strcmp(res->name, "txpt"))
3473                 tx_pthresh = res->value;
3474         else if(!strcmp(res->name, "txht"))
3475                 tx_hthresh = res->value;
3476         else if(!strcmp(res->name, "txwt"))
3477                 tx_wthresh = res->value;
3478         else if(!strcmp(res->name, "rxpt"))
3479                 rx_pthresh = res->value;
3480         else if(!strcmp(res->name, "rxht"))
3481                 rx_hthresh = res->value;
3482         else if(!strcmp(res->name, "rxwt"))
3483                 rx_wthresh = res->value;
3484         else {
3485                 printf("Unknown parameter\n");
3486                 return;
3487         }
3488
3489         init_port_config();
3490
3491         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3492 }
3493
3494 cmdline_parse_token_string_t cmd_config_thresh_port =
3495         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3496 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3497         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3498 cmdline_parse_token_string_t cmd_config_thresh_all =
3499         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3500 cmdline_parse_token_string_t cmd_config_thresh_name =
3501         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3502                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3503 cmdline_parse_token_num_t cmd_config_thresh_value =
3504         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3505
3506 cmdline_parse_inst_t cmd_config_thresh = {
3507         .f = cmd_config_thresh_parsed,
3508         .data = NULL,
3509         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3510         .tokens = {
3511                 (void *)&cmd_config_thresh_port,
3512                 (void *)&cmd_config_thresh_keyword,
3513                 (void *)&cmd_config_thresh_all,
3514                 (void *)&cmd_config_thresh_name,
3515                 (void *)&cmd_config_thresh_value,
3516                 NULL,
3517         },
3518 };
3519
3520 /* *** configure free/rs threshold *** */
3521 struct cmd_config_threshold {
3522         cmdline_fixed_string_t port;
3523         cmdline_fixed_string_t keyword;
3524         cmdline_fixed_string_t all;
3525         cmdline_fixed_string_t name;
3526         uint16_t value;
3527 };
3528
3529 static void
3530 cmd_config_threshold_parsed(void *parsed_result,
3531                         __rte_unused struct cmdline *cl,
3532                         __rte_unused void *data)
3533 {
3534         struct cmd_config_threshold *res = parsed_result;
3535
3536         if (!all_ports_stopped()) {
3537                 printf("Please stop all ports first\n");
3538                 return;
3539         }
3540
3541         if (!strcmp(res->name, "txfreet"))
3542                 tx_free_thresh = res->value;
3543         else if (!strcmp(res->name, "txrst"))
3544                 tx_rs_thresh = res->value;
3545         else if (!strcmp(res->name, "rxfreet"))
3546                 rx_free_thresh = res->value;
3547         else {
3548                 printf("Unknown parameter\n");
3549                 return;
3550         }
3551
3552         init_port_config();
3553
3554         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3555 }
3556
3557 cmdline_parse_token_string_t cmd_config_threshold_port =
3558         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3559 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3560         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3561                                                                 "config");
3562 cmdline_parse_token_string_t cmd_config_threshold_all =
3563         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3564 cmdline_parse_token_string_t cmd_config_threshold_name =
3565         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3566                                                 "txfreet#txrst#rxfreet");
3567 cmdline_parse_token_num_t cmd_config_threshold_value =
3568         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3569
3570 cmdline_parse_inst_t cmd_config_threshold = {
3571         .f = cmd_config_threshold_parsed,
3572         .data = NULL,
3573         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3574         .tokens = {
3575                 (void *)&cmd_config_threshold_port,
3576                 (void *)&cmd_config_threshold_keyword,
3577                 (void *)&cmd_config_threshold_all,
3578                 (void *)&cmd_config_threshold_name,
3579                 (void *)&cmd_config_threshold_value,
3580                 NULL,
3581         },
3582 };
3583
3584 /* *** stop *** */
3585 struct cmd_stop_result {
3586         cmdline_fixed_string_t stop;
3587 };
3588
3589 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3590                             __rte_unused struct cmdline *cl,
3591                             __rte_unused void *data)
3592 {
3593         stop_packet_forwarding();
3594 }
3595
3596 cmdline_parse_token_string_t cmd_stop_stop =
3597         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3598
3599 cmdline_parse_inst_t cmd_stop = {
3600         .f = cmd_stop_parsed,
3601         .data = NULL,
3602         .help_str = "stop: Stop packet forwarding",
3603         .tokens = {
3604                 (void *)&cmd_stop_stop,
3605                 NULL,
3606         },
3607 };
3608
3609 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3610
3611 unsigned int
3612 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3613                 unsigned int *parsed_items, int check_unique_values)
3614 {
3615         unsigned int nb_item;
3616         unsigned int value;
3617         unsigned int i;
3618         unsigned int j;
3619         int value_ok;
3620         char c;
3621
3622         /*
3623          * First parse all items in the list and store their value.
3624          */
3625         value = 0;
3626         nb_item = 0;
3627         value_ok = 0;
3628         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3629                 c = str[i];
3630                 if ((c >= '0') && (c <= '9')) {
3631                         value = (unsigned int) (value * 10 + (c - '0'));
3632                         value_ok = 1;
3633                         continue;
3634                 }
3635                 if (c != ',') {
3636                         printf("character %c is not a decimal digit\n", c);
3637                         return 0;
3638                 }
3639                 if (! value_ok) {
3640                         printf("No valid value before comma\n");
3641                         return 0;
3642                 }
3643                 if (nb_item < max_items) {
3644                         parsed_items[nb_item] = value;
3645                         value_ok = 0;
3646                         value = 0;
3647                 }
3648                 nb_item++;
3649         }
3650         if (nb_item >= max_items) {
3651                 printf("Number of %s = %u > %u (maximum items)\n",
3652                        item_name, nb_item + 1, max_items);
3653                 return 0;
3654         }
3655         parsed_items[nb_item++] = value;
3656         if (! check_unique_values)
3657                 return nb_item;
3658
3659         /*
3660          * Then, check that all values in the list are differents.
3661          * No optimization here...
3662          */
3663         for (i = 0; i < nb_item; i++) {
3664                 for (j = i + 1; j < nb_item; j++) {
3665                         if (parsed_items[j] == parsed_items[i]) {
3666                                 printf("duplicated %s %u at index %u and %u\n",
3667                                        item_name, parsed_items[i], i, j);
3668                                 return 0;
3669                         }
3670                 }
3671         }
3672         return nb_item;
3673 }
3674
3675 struct cmd_set_list_result {
3676         cmdline_fixed_string_t cmd_keyword;
3677         cmdline_fixed_string_t list_name;
3678         cmdline_fixed_string_t list_of_items;
3679 };
3680
3681 static void cmd_set_list_parsed(void *parsed_result,
3682                                 __rte_unused struct cmdline *cl,
3683                                 __rte_unused void *data)
3684 {
3685         struct cmd_set_list_result *res;
3686         union {
3687                 unsigned int lcorelist[RTE_MAX_LCORE];
3688                 unsigned int portlist[RTE_MAX_ETHPORTS];
3689         } parsed_items;
3690         unsigned int nb_item;
3691
3692         if (test_done == 0) {
3693                 printf("Please stop forwarding first\n");
3694                 return;
3695         }
3696
3697         res = parsed_result;
3698         if (!strcmp(res->list_name, "corelist")) {
3699                 nb_item = parse_item_list(res->list_of_items, "core",
3700                                           RTE_MAX_LCORE,
3701                                           parsed_items.lcorelist, 1);
3702                 if (nb_item > 0) {
3703                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3704                         fwd_config_setup();
3705                 }
3706                 return;
3707         }
3708         if (!strcmp(res->list_name, "portlist")) {
3709                 nb_item = parse_item_list(res->list_of_items, "port",
3710                                           RTE_MAX_ETHPORTS,
3711                                           parsed_items.portlist, 1);
3712                 if (nb_item > 0) {
3713                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3714                         fwd_config_setup();
3715                 }
3716         }
3717 }
3718
3719 cmdline_parse_token_string_t cmd_set_list_keyword =
3720         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3721                                  "set");
3722 cmdline_parse_token_string_t cmd_set_list_name =
3723         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3724                                  "corelist#portlist");
3725 cmdline_parse_token_string_t cmd_set_list_of_items =
3726         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3727                                  NULL);
3728
3729 cmdline_parse_inst_t cmd_set_fwd_list = {
3730         .f = cmd_set_list_parsed,
3731         .data = NULL,
3732         .help_str = "set corelist|portlist <list0[,list1]*>",
3733         .tokens = {
3734                 (void *)&cmd_set_list_keyword,
3735                 (void *)&cmd_set_list_name,
3736                 (void *)&cmd_set_list_of_items,
3737                 NULL,
3738         },
3739 };
3740
3741 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3742
3743 struct cmd_setmask_result {
3744         cmdline_fixed_string_t set;
3745         cmdline_fixed_string_t mask;
3746         uint64_t hexavalue;
3747 };
3748
3749 static void cmd_set_mask_parsed(void *parsed_result,
3750                                 __rte_unused struct cmdline *cl,
3751                                 __rte_unused void *data)
3752 {
3753         struct cmd_setmask_result *res = parsed_result;
3754
3755         if (test_done == 0) {
3756                 printf("Please stop forwarding first\n");
3757                 return;
3758         }
3759         if (!strcmp(res->mask, "coremask")) {
3760                 set_fwd_lcores_mask(res->hexavalue);
3761                 fwd_config_setup();
3762         } else if (!strcmp(res->mask, "portmask")) {
3763                 set_fwd_ports_mask(res->hexavalue);
3764                 fwd_config_setup();
3765         }
3766 }
3767
3768 cmdline_parse_token_string_t cmd_setmask_set =
3769         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3770 cmdline_parse_token_string_t cmd_setmask_mask =
3771         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3772                                  "coremask#portmask");
3773 cmdline_parse_token_num_t cmd_setmask_value =
3774         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3775
3776 cmdline_parse_inst_t cmd_set_fwd_mask = {
3777         .f = cmd_set_mask_parsed,
3778         .data = NULL,
3779         .help_str = "set coremask|portmask <hexadecimal value>",
3780         .tokens = {
3781                 (void *)&cmd_setmask_set,
3782                 (void *)&cmd_setmask_mask,
3783                 (void *)&cmd_setmask_value,
3784                 NULL,
3785         },
3786 };
3787
3788 /*
3789  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3790  */
3791 struct cmd_set_result {
3792         cmdline_fixed_string_t set;
3793         cmdline_fixed_string_t what;
3794         uint16_t value;
3795 };
3796
3797 static void cmd_set_parsed(void *parsed_result,
3798                            __rte_unused struct cmdline *cl,
3799                            __rte_unused void *data)
3800 {
3801         struct cmd_set_result *res = parsed_result;
3802         if (!strcmp(res->what, "nbport")) {
3803                 set_fwd_ports_number(res->value);
3804                 fwd_config_setup();
3805         } else if (!strcmp(res->what, "nbcore")) {
3806                 set_fwd_lcores_number(res->value);
3807                 fwd_config_setup();
3808         } else if (!strcmp(res->what, "burst"))
3809                 set_nb_pkt_per_burst(res->value);
3810         else if (!strcmp(res->what, "verbose"))
3811                 set_verbose_level(res->value);
3812 }
3813
3814 cmdline_parse_token_string_t cmd_set_set =
3815         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3816 cmdline_parse_token_string_t cmd_set_what =
3817         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3818                                  "nbport#nbcore#burst#verbose");
3819 cmdline_parse_token_num_t cmd_set_value =
3820         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3821
3822 cmdline_parse_inst_t cmd_set_numbers = {
3823         .f = cmd_set_parsed,
3824         .data = NULL,
3825         .help_str = "set nbport|nbcore|burst|verbose <value>",
3826         .tokens = {
3827                 (void *)&cmd_set_set,
3828                 (void *)&cmd_set_what,
3829                 (void *)&cmd_set_value,
3830                 NULL,
3831         },
3832 };
3833
3834 /* *** SET LOG LEVEL CONFIGURATION *** */
3835
3836 struct cmd_set_log_result {
3837         cmdline_fixed_string_t set;
3838         cmdline_fixed_string_t log;
3839         cmdline_fixed_string_t type;
3840         uint32_t level;
3841 };
3842
3843 static void
3844 cmd_set_log_parsed(void *parsed_result,
3845                    __rte_unused struct cmdline *cl,
3846                    __rte_unused void *data)
3847 {
3848         struct cmd_set_log_result *res;
3849         int ret;
3850
3851         res = parsed_result;
3852         if (!strcmp(res->type, "global"))
3853                 rte_log_set_global_level(res->level);
3854         else {
3855                 ret = rte_log_set_level_regexp(res->type, res->level);
3856                 if (ret < 0)
3857                         printf("Unable to set log level\n");
3858         }
3859 }
3860
3861 cmdline_parse_token_string_t cmd_set_log_set =
3862         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3863 cmdline_parse_token_string_t cmd_set_log_log =
3864         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3865 cmdline_parse_token_string_t cmd_set_log_type =
3866         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3867 cmdline_parse_token_num_t cmd_set_log_level =
3868         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3869
3870 cmdline_parse_inst_t cmd_set_log = {
3871         .f = cmd_set_log_parsed,
3872         .data = NULL,
3873         .help_str = "set log global|<type> <level>",
3874         .tokens = {
3875                 (void *)&cmd_set_log_set,
3876                 (void *)&cmd_set_log_log,
3877                 (void *)&cmd_set_log_type,
3878                 (void *)&cmd_set_log_level,
3879                 NULL,
3880         },
3881 };
3882
3883 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3884
3885 struct cmd_set_txpkts_result {
3886         cmdline_fixed_string_t cmd_keyword;
3887         cmdline_fixed_string_t txpkts;
3888         cmdline_fixed_string_t seg_lengths;
3889 };
3890
3891 static void
3892 cmd_set_txpkts_parsed(void *parsed_result,
3893                       __rte_unused struct cmdline *cl,
3894                       __rte_unused void *data)
3895 {
3896         struct cmd_set_txpkts_result *res;
3897         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3898         unsigned int nb_segs;
3899
3900         res = parsed_result;
3901         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3902                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3903         if (nb_segs > 0)
3904                 set_tx_pkt_segments(seg_lengths, nb_segs);
3905 }
3906
3907 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3908         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3909                                  cmd_keyword, "set");
3910 cmdline_parse_token_string_t cmd_set_txpkts_name =
3911         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3912                                  txpkts, "txpkts");
3913 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3914         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3915                                  seg_lengths, NULL);
3916
3917 cmdline_parse_inst_t cmd_set_txpkts = {
3918         .f = cmd_set_txpkts_parsed,
3919         .data = NULL,
3920         .help_str = "set txpkts <len0[,len1]*>",
3921         .tokens = {
3922                 (void *)&cmd_set_txpkts_keyword,
3923                 (void *)&cmd_set_txpkts_name,
3924                 (void *)&cmd_set_txpkts_lengths,
3925                 NULL,
3926         },
3927 };
3928
3929 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3930
3931 struct cmd_set_txsplit_result {
3932         cmdline_fixed_string_t cmd_keyword;
3933         cmdline_fixed_string_t txsplit;
3934         cmdline_fixed_string_t mode;
3935 };
3936
3937 static void
3938 cmd_set_txsplit_parsed(void *parsed_result,
3939                       __rte_unused struct cmdline *cl,
3940                       __rte_unused void *data)
3941 {
3942         struct cmd_set_txsplit_result *res;
3943
3944         res = parsed_result;
3945         set_tx_pkt_split(res->mode);
3946 }
3947
3948 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3949         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3950                                  cmd_keyword, "set");
3951 cmdline_parse_token_string_t cmd_set_txsplit_name =
3952         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3953                                  txsplit, "txsplit");
3954 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3955         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3956                                  mode, NULL);
3957
3958 cmdline_parse_inst_t cmd_set_txsplit = {
3959         .f = cmd_set_txsplit_parsed,
3960         .data = NULL,
3961         .help_str = "set txsplit on|off|rand",
3962         .tokens = {
3963                 (void *)&cmd_set_txsplit_keyword,
3964                 (void *)&cmd_set_txsplit_name,
3965                 (void *)&cmd_set_txsplit_mode,
3966                 NULL,
3967         },
3968 };
3969
3970 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3971
3972 struct cmd_set_txtimes_result {
3973         cmdline_fixed_string_t cmd_keyword;
3974         cmdline_fixed_string_t txtimes;
3975         cmdline_fixed_string_t tx_times;
3976 };
3977
3978 static void
3979 cmd_set_txtimes_parsed(void *parsed_result,
3980                        __rte_unused struct cmdline *cl,
3981                        __rte_unused void *data)
3982 {
3983         struct cmd_set_txtimes_result *res;
3984         unsigned int tx_times[2] = {0, 0};
3985         unsigned int n_times;
3986
3987         res = parsed_result;
3988         n_times = parse_item_list(res->tx_times, "tx times",
3989                                   2, tx_times, 0);
3990         if (n_times == 2)
3991                 set_tx_pkt_times(tx_times);
3992 }
3993
3994 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3995         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3996                                  cmd_keyword, "set");
3997 cmdline_parse_token_string_t cmd_set_txtimes_name =
3998         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3999                                  txtimes, "txtimes");
4000 cmdline_parse_token_string_t cmd_set_txtimes_value =
4001         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4002                                  tx_times, NULL);
4003
4004 cmdline_parse_inst_t cmd_set_txtimes = {
4005         .f = cmd_set_txtimes_parsed,
4006         .data = NULL,
4007         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4008         .tokens = {
4009                 (void *)&cmd_set_txtimes_keyword,
4010                 (void *)&cmd_set_txtimes_name,
4011                 (void *)&cmd_set_txtimes_value,
4012                 NULL,
4013         },
4014 };
4015
4016 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4017 struct cmd_rx_vlan_filter_all_result {
4018         cmdline_fixed_string_t rx_vlan;
4019         cmdline_fixed_string_t what;
4020         cmdline_fixed_string_t all;
4021         portid_t port_id;
4022 };
4023
4024 static void
4025 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4026                               __rte_unused struct cmdline *cl,
4027                               __rte_unused void *data)
4028 {
4029         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4030
4031         if (!strcmp(res->what, "add"))
4032                 rx_vlan_all_filter_set(res->port_id, 1);
4033         else
4034                 rx_vlan_all_filter_set(res->port_id, 0);
4035 }
4036
4037 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4038         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4039                                  rx_vlan, "rx_vlan");
4040 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4041         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4042                                  what, "add#rm");
4043 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4044         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4045                                  all, "all");
4046 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4047         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4048                               port_id, UINT16);
4049
4050 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4051         .f = cmd_rx_vlan_filter_all_parsed,
4052         .data = NULL,
4053         .help_str = "rx_vlan add|rm all <port_id>: "
4054                 "Add/Remove all identifiers to/from the set of VLAN "
4055                 "identifiers filtered by a port",
4056         .tokens = {
4057                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4058                 (void *)&cmd_rx_vlan_filter_all_what,
4059                 (void *)&cmd_rx_vlan_filter_all_all,
4060                 (void *)&cmd_rx_vlan_filter_all_portid,
4061                 NULL,
4062         },
4063 };
4064
4065 /* *** VLAN OFFLOAD SET ON A PORT *** */
4066 struct cmd_vlan_offload_result {
4067         cmdline_fixed_string_t vlan;
4068         cmdline_fixed_string_t set;
4069         cmdline_fixed_string_t vlan_type;
4070         cmdline_fixed_string_t what;
4071         cmdline_fixed_string_t on;
4072         cmdline_fixed_string_t port_id;
4073 };
4074
4075 static void
4076 cmd_vlan_offload_parsed(void *parsed_result,
4077                           __rte_unused struct cmdline *cl,
4078                           __rte_unused void *data)
4079 {
4080         int on;
4081         struct cmd_vlan_offload_result *res = parsed_result;
4082         char *str;
4083         int i, len = 0;
4084         portid_t port_id = 0;
4085         unsigned int tmp;
4086
4087         str = res->port_id;
4088         len = strnlen(str, STR_TOKEN_SIZE);
4089         i = 0;
4090         /* Get port_id first */
4091         while(i < len){
4092                 if(str[i] == ',')
4093                         break;
4094
4095                 i++;
4096         }
4097         str[i]='\0';
4098         tmp = strtoul(str, NULL, 0);
4099         /* If port_id greater that what portid_t can represent, return */
4100         if(tmp >= RTE_MAX_ETHPORTS)
4101                 return;
4102         port_id = (portid_t)tmp;
4103
4104         if (!strcmp(res->on, "on"))
4105                 on = 1;
4106         else
4107                 on = 0;
4108
4109         if (!strcmp(res->what, "strip"))
4110                 rx_vlan_strip_set(port_id,  on);
4111         else if(!strcmp(res->what, "stripq")){
4112                 uint16_t queue_id = 0;
4113
4114                 /* No queue_id, return */
4115                 if(i + 1 >= len) {
4116                         printf("must specify (port,queue_id)\n");
4117                         return;
4118                 }
4119                 tmp = strtoul(str + i + 1, NULL, 0);
4120                 /* If queue_id greater that what 16-bits can represent, return */
4121                 if(tmp > 0xffff)
4122                         return;
4123
4124                 queue_id = (uint16_t)tmp;
4125                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4126         }
4127         else if (!strcmp(res->what, "filter"))
4128                 rx_vlan_filter_set(port_id, on);
4129         else if (!strcmp(res->what, "qinq_strip"))
4130                 rx_vlan_qinq_strip_set(port_id, on);
4131         else
4132                 vlan_extend_set(port_id, on);
4133
4134         return;
4135 }
4136
4137 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4138         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4139                                  vlan, "vlan");
4140 cmdline_parse_token_string_t cmd_vlan_offload_set =
4141         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4142                                  set, "set");
4143 cmdline_parse_token_string_t cmd_vlan_offload_what =
4144         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4145                                 what, "strip#filter#qinq_strip#extend#stripq");
4146 cmdline_parse_token_string_t cmd_vlan_offload_on =
4147         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4148                               on, "on#off");
4149 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4150         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4151                               port_id, NULL);
4152
4153 cmdline_parse_inst_t cmd_vlan_offload = {
4154         .f = cmd_vlan_offload_parsed,
4155         .data = NULL,
4156         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4157                 "<port_id[,queue_id]>: "
4158                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4159         .tokens = {
4160                 (void *)&cmd_vlan_offload_vlan,
4161                 (void *)&cmd_vlan_offload_set,
4162                 (void *)&cmd_vlan_offload_what,
4163                 (void *)&cmd_vlan_offload_on,
4164                 (void *)&cmd_vlan_offload_portid,
4165                 NULL,
4166         },
4167 };
4168
4169 /* *** VLAN TPID SET ON A PORT *** */
4170 struct cmd_vlan_tpid_result {
4171         cmdline_fixed_string_t vlan;
4172         cmdline_fixed_string_t set;
4173         cmdline_fixed_string_t vlan_type;
4174         cmdline_fixed_string_t what;
4175         uint16_t tp_id;
4176         portid_t port_id;
4177 };
4178
4179 static void
4180 cmd_vlan_tpid_parsed(void *parsed_result,
4181                           __rte_unused struct cmdline *cl,
4182                           __rte_unused void *data)
4183 {
4184         struct cmd_vlan_tpid_result *res = parsed_result;
4185         enum rte_vlan_type vlan_type;
4186
4187         if (!strcmp(res->vlan_type, "inner"))
4188                 vlan_type = ETH_VLAN_TYPE_INNER;
4189         else if (!strcmp(res->vlan_type, "outer"))
4190                 vlan_type = ETH_VLAN_TYPE_OUTER;
4191         else {
4192                 printf("Unknown vlan type\n");
4193                 return;
4194         }
4195         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4196 }
4197
4198 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4199         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4200                                  vlan, "vlan");
4201 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4202         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4203                                  set, "set");
4204 cmdline_parse_token_string_t cmd_vlan_type =
4205         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4206                                  vlan_type, "inner#outer");
4207 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4208         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4209                                  what, "tpid");
4210 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4211         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4212                               tp_id, UINT16);
4213 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4214         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4215                               port_id, UINT16);
4216
4217 cmdline_parse_inst_t cmd_vlan_tpid = {
4218         .f = cmd_vlan_tpid_parsed,
4219         .data = NULL,
4220         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4221                 "Set the VLAN Ether type",
4222         .tokens = {
4223                 (void *)&cmd_vlan_tpid_vlan,
4224                 (void *)&cmd_vlan_tpid_set,
4225                 (void *)&cmd_vlan_type,
4226                 (void *)&cmd_vlan_tpid_what,
4227                 (void *)&cmd_vlan_tpid_tpid,
4228                 (void *)&cmd_vlan_tpid_portid,
4229                 NULL,
4230         },
4231 };
4232
4233 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4234 struct cmd_rx_vlan_filter_result {
4235         cmdline_fixed_string_t rx_vlan;
4236         cmdline_fixed_string_t what;
4237         uint16_t vlan_id;
4238         portid_t port_id;
4239 };
4240
4241 static void
4242 cmd_rx_vlan_filter_parsed(void *parsed_result,
4243                           __rte_unused struct cmdline *cl,
4244                           __rte_unused void *data)
4245 {
4246         struct cmd_rx_vlan_filter_result *res = parsed_result;
4247
4248         if (!strcmp(res->what, "add"))
4249                 rx_vft_set(res->port_id, res->vlan_id, 1);
4250         else
4251                 rx_vft_set(res->port_id, res->vlan_id, 0);
4252 }
4253
4254 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4255         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4256                                  rx_vlan, "rx_vlan");
4257 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4258         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4259                                  what, "add#rm");
4260 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4261         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4262                               vlan_id, UINT16);
4263 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4264         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4265                               port_id, UINT16);
4266
4267 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4268         .f = cmd_rx_vlan_filter_parsed,
4269         .data = NULL,
4270         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4271                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4272                 "identifiers filtered by a port",
4273         .tokens = {
4274                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4275                 (void *)&cmd_rx_vlan_filter_what,
4276                 (void *)&cmd_rx_vlan_filter_vlanid,
4277                 (void *)&cmd_rx_vlan_filter_portid,
4278                 NULL,
4279         },
4280 };
4281
4282 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4283 struct cmd_tx_vlan_set_result {
4284         cmdline_fixed_string_t tx_vlan;
4285         cmdline_fixed_string_t set;
4286         portid_t port_id;
4287         uint16_t vlan_id;
4288 };
4289
4290 static void
4291 cmd_tx_vlan_set_parsed(void *parsed_result,
4292                        __rte_unused struct cmdline *cl,
4293                        __rte_unused void *data)
4294 {
4295         struct cmd_tx_vlan_set_result *res = parsed_result;
4296
4297         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4298                 return;
4299
4300         if (!port_is_stopped(res->port_id)) {
4301                 printf("Please stop port %d first\n", res->port_id);
4302                 return;
4303         }
4304
4305         tx_vlan_set(res->port_id, res->vlan_id);
4306
4307         cmd_reconfig_device_queue(res->port_id, 1, 1);
4308 }
4309
4310 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4311         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4312                                  tx_vlan, "tx_vlan");
4313 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4314         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4315                                  set, "set");
4316 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4317         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4318                               port_id, UINT16);
4319 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4320         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4321                               vlan_id, UINT16);
4322
4323 cmdline_parse_inst_t cmd_tx_vlan_set = {
4324         .f = cmd_tx_vlan_set_parsed,
4325         .data = NULL,
4326         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4327                 "Enable hardware insertion of a single VLAN header "
4328                 "with a given TAG Identifier in packets sent on a port",
4329         .tokens = {
4330                 (void *)&cmd_tx_vlan_set_tx_vlan,
4331                 (void *)&cmd_tx_vlan_set_set,
4332                 (void *)&cmd_tx_vlan_set_portid,
4333                 (void *)&cmd_tx_vlan_set_vlanid,
4334                 NULL,
4335         },
4336 };
4337
4338 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4339 struct cmd_tx_vlan_set_qinq_result {
4340         cmdline_fixed_string_t tx_vlan;
4341         cmdline_fixed_string_t set;
4342         portid_t port_id;
4343         uint16_t vlan_id;
4344         uint16_t vlan_id_outer;
4345 };
4346
4347 static void
4348 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4349                             __rte_unused struct cmdline *cl,
4350                             __rte_unused void *data)
4351 {
4352         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4353
4354         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4355                 return;
4356
4357         if (!port_is_stopped(res->port_id)) {
4358                 printf("Please stop port %d first\n", res->port_id);
4359                 return;
4360         }
4361
4362         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4363
4364         cmd_reconfig_device_queue(res->port_id, 1, 1);
4365 }
4366
4367 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4368         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4369                 tx_vlan, "tx_vlan");
4370 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4371         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4372                 set, "set");
4373 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4374         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4375                 port_id, UINT16);
4376 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4377         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4378                 vlan_id, UINT16);
4379 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4380         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4381                 vlan_id_outer, UINT16);
4382
4383 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4384         .f = cmd_tx_vlan_set_qinq_parsed,
4385         .data = NULL,
4386         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4387                 "Enable hardware insertion of double VLAN header "
4388                 "with given TAG Identifiers in packets sent on a port",
4389         .tokens = {
4390                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4391                 (void *)&cmd_tx_vlan_set_qinq_set,
4392                 (void *)&cmd_tx_vlan_set_qinq_portid,
4393                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4394                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4395                 NULL,
4396         },
4397 };
4398
4399 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4400 struct cmd_tx_vlan_set_pvid_result {
4401         cmdline_fixed_string_t tx_vlan;
4402         cmdline_fixed_string_t set;
4403         cmdline_fixed_string_t pvid;
4404         portid_t port_id;
4405         uint16_t vlan_id;
4406         cmdline_fixed_string_t mode;
4407 };
4408
4409 static void
4410 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4411                             __rte_unused struct cmdline *cl,
4412                             __rte_unused void *data)
4413 {
4414         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4415
4416         if (strcmp(res->mode, "on") == 0)
4417                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4418         else
4419                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4420 }
4421
4422 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4423         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4424                                  tx_vlan, "tx_vlan");
4425 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4426         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4427                                  set, "set");
4428 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4429         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4430                                  pvid, "pvid");
4431 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4432         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4433                              port_id, UINT16);
4434 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4435         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4436                               vlan_id, UINT16);
4437 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4438         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4439                                  mode, "on#off");
4440
4441 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4442         .f = cmd_tx_vlan_set_pvid_parsed,
4443         .data = NULL,
4444         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4445         .tokens = {
4446                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4447                 (void *)&cmd_tx_vlan_set_pvid_set,
4448                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4449                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4450                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4451                 (void *)&cmd_tx_vlan_set_pvid_mode,
4452                 NULL,
4453         },
4454 };
4455
4456 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4457 struct cmd_tx_vlan_reset_result {
4458         cmdline_fixed_string_t tx_vlan;
4459         cmdline_fixed_string_t reset;
4460         portid_t port_id;
4461 };
4462
4463 static void
4464 cmd_tx_vlan_reset_parsed(void *parsed_result,
4465                          __rte_unused struct cmdline *cl,
4466                          __rte_unused void *data)
4467 {
4468         struct cmd_tx_vlan_reset_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_vlan_reset(res->port_id);
4479
4480         cmd_reconfig_device_queue(res->port_id, 1, 1);
4481 }
4482
4483 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4484         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4485                                  tx_vlan, "tx_vlan");
4486 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4487         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4488                                  reset, "reset");
4489 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4490         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4491                               port_id, UINT16);
4492
4493 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4494         .f = cmd_tx_vlan_reset_parsed,
4495         .data = NULL,
4496         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4497                 "VLAN header in packets sent on a port",
4498         .tokens = {
4499                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4500                 (void *)&cmd_tx_vlan_reset_reset,
4501                 (void *)&cmd_tx_vlan_reset_portid,
4502                 NULL,
4503         },
4504 };
4505
4506
4507 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4508 struct cmd_csum_result {
4509         cmdline_fixed_string_t csum;
4510         cmdline_fixed_string_t mode;
4511         cmdline_fixed_string_t proto;
4512         cmdline_fixed_string_t hwsw;
4513         portid_t port_id;
4514 };
4515
4516 static void
4517 csum_show(int port_id)
4518 {
4519         struct rte_eth_dev_info dev_info;
4520         uint64_t tx_offloads;
4521         int ret;
4522
4523         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4524         printf("Parse tunnel is %s\n",
4525                 (ports[port_id].parse_tunnel) ? "on" : "off");
4526         printf("IP checksum offload is %s\n",
4527                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4528         printf("UDP checksum offload is %s\n",
4529                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4530         printf("TCP checksum offload is %s\n",
4531                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4532         printf("SCTP checksum offload is %s\n",
4533                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4534         printf("Outer-Ip checksum offload is %s\n",
4535                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4536         printf("Outer-Udp checksum offload is %s\n",
4537                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4538
4539         /* display warnings if configuration is not supported by the NIC */
4540         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4541         if (ret != 0)
4542                 return;
4543
4544         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4545                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4546                 printf("Warning: hardware IP checksum enabled but not "
4547                         "supported by port %d\n", port_id);
4548         }
4549         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4550                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4551                 printf("Warning: hardware UDP checksum enabled but not "
4552                         "supported by port %d\n", port_id);
4553         }
4554         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4555                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4556                 printf("Warning: hardware TCP checksum enabled but not "
4557                         "supported by port %d\n", port_id);
4558         }
4559         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4560                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4561                 printf("Warning: hardware SCTP checksum enabled but not "
4562                         "supported by port %d\n", port_id);
4563         }
4564         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4565                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4566                 printf("Warning: hardware outer IP checksum enabled but not "
4567                         "supported by port %d\n", port_id);
4568         }
4569         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4570                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4571                         == 0) {
4572                 printf("Warning: hardware outer UDP checksum enabled but not "
4573                         "supported by port %d\n", port_id);
4574         }
4575 }
4576
4577 static void
4578 cmd_config_queue_tx_offloads(struct rte_port *port)
4579 {
4580         int k;
4581
4582         /* Apply queue tx offloads configuration */
4583         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4584                 port->tx_conf[k].offloads =
4585                         port->dev_conf.txmode.offloads;
4586 }
4587
4588 static void
4589 cmd_csum_parsed(void *parsed_result,
4590                        __rte_unused struct cmdline *cl,
4591                        __rte_unused void *data)
4592 {
4593         struct cmd_csum_result *res = parsed_result;
4594         int hw = 0;
4595         uint64_t csum_offloads = 0;
4596         struct rte_eth_dev_info dev_info;
4597         int ret;
4598
4599         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4600                 printf("invalid port %d\n", res->port_id);
4601                 return;
4602         }
4603         if (!port_is_stopped(res->port_id)) {
4604                 printf("Please stop port %d first\n", res->port_id);
4605                 return;
4606         }
4607
4608         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4609         if (ret != 0)
4610                 return;
4611
4612         if (!strcmp(res->mode, "set")) {
4613
4614                 if (!strcmp(res->hwsw, "hw"))
4615                         hw = 1;
4616
4617                 if (!strcmp(res->proto, "ip")) {
4618                         if (hw == 0 || (dev_info.tx_offload_capa &
4619                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4620                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4621                         } else {
4622                                 printf("IP checksum offload is not supported "
4623                                        "by port %u\n", res->port_id);
4624                         }
4625                 } else if (!strcmp(res->proto, "udp")) {
4626                         if (hw == 0 || (dev_info.tx_offload_capa &
4627                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4628                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4629                         } else {
4630                                 printf("UDP checksum offload is not supported "
4631                                        "by port %u\n", res->port_id);
4632                         }
4633                 } else if (!strcmp(res->proto, "tcp")) {
4634                         if (hw == 0 || (dev_info.tx_offload_capa &
4635                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4636                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4637                         } else {
4638                                 printf("TCP checksum offload is not supported "
4639                                        "by port %u\n", res->port_id);
4640                         }
4641                 } else if (!strcmp(res->proto, "sctp")) {
4642                         if (hw == 0 || (dev_info.tx_offload_capa &
4643                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4644                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4645                         } else {
4646                                 printf("SCTP checksum offload is not supported "
4647                                        "by port %u\n", res->port_id);
4648                         }
4649                 } else if (!strcmp(res->proto, "outer-ip")) {
4650                         if (hw == 0 || (dev_info.tx_offload_capa &
4651                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4652                                 csum_offloads |=
4653                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4654                         } else {
4655                                 printf("Outer IP checksum offload is not "
4656                                        "supported by port %u\n", res->port_id);
4657                         }
4658                 } else if (!strcmp(res->proto, "outer-udp")) {
4659                         if (hw == 0 || (dev_info.tx_offload_capa &
4660                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4661                                 csum_offloads |=
4662                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4663                         } else {
4664                                 printf("Outer UDP checksum offload is not "
4665                                        "supported by port %u\n", res->port_id);
4666                         }
4667                 }
4668
4669                 if (hw) {
4670                         ports[res->port_id].dev_conf.txmode.offloads |=
4671                                                         csum_offloads;
4672                 } else {
4673                         ports[res->port_id].dev_conf.txmode.offloads &=
4674                                                         (~csum_offloads);
4675                 }
4676                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4677         }
4678         csum_show(res->port_id);
4679
4680         cmd_reconfig_device_queue(res->port_id, 1, 1);
4681 }
4682
4683 cmdline_parse_token_string_t cmd_csum_csum =
4684         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4685                                 csum, "csum");
4686 cmdline_parse_token_string_t cmd_csum_mode =
4687         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4688                                 mode, "set");
4689 cmdline_parse_token_string_t cmd_csum_proto =
4690         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4691                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4692 cmdline_parse_token_string_t cmd_csum_hwsw =
4693         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4694                                 hwsw, "hw#sw");
4695 cmdline_parse_token_num_t cmd_csum_portid =
4696         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4697                                 port_id, UINT16);
4698
4699 cmdline_parse_inst_t cmd_csum_set = {
4700         .f = cmd_csum_parsed,
4701         .data = NULL,
4702         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4703                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4704                 "using csum forward engine",
4705         .tokens = {
4706                 (void *)&cmd_csum_csum,
4707                 (void *)&cmd_csum_mode,
4708                 (void *)&cmd_csum_proto,
4709                 (void *)&cmd_csum_hwsw,
4710                 (void *)&cmd_csum_portid,
4711                 NULL,
4712         },
4713 };
4714
4715 cmdline_parse_token_string_t cmd_csum_mode_show =
4716         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4717                                 mode, "show");
4718
4719 cmdline_parse_inst_t cmd_csum_show = {
4720         .f = cmd_csum_parsed,
4721         .data = NULL,
4722         .help_str = "csum show <port_id>: Show checksum offload configuration",
4723         .tokens = {
4724                 (void *)&cmd_csum_csum,
4725                 (void *)&cmd_csum_mode_show,
4726                 (void *)&cmd_csum_portid,
4727                 NULL,
4728         },
4729 };
4730
4731 /* Enable/disable tunnel parsing */
4732 struct cmd_csum_tunnel_result {
4733         cmdline_fixed_string_t csum;
4734         cmdline_fixed_string_t parse;
4735         cmdline_fixed_string_t onoff;
4736         portid_t port_id;
4737 };
4738
4739 static void
4740 cmd_csum_tunnel_parsed(void *parsed_result,
4741                        __rte_unused struct cmdline *cl,
4742                        __rte_unused void *data)
4743 {
4744         struct cmd_csum_tunnel_result *res = parsed_result;
4745
4746         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4747                 return;
4748
4749         if (!strcmp(res->onoff, "on"))
4750                 ports[res->port_id].parse_tunnel = 1;
4751         else
4752                 ports[res->port_id].parse_tunnel = 0;
4753
4754         csum_show(res->port_id);
4755 }
4756
4757 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4758         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4759                                 csum, "csum");
4760 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4761         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4762                                 parse, "parse-tunnel");
4763 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4764         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4765                                 onoff, "on#off");
4766 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4767         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4768                                 port_id, UINT16);
4769
4770 cmdline_parse_inst_t cmd_csum_tunnel = {
4771         .f = cmd_csum_tunnel_parsed,
4772         .data = NULL,
4773         .help_str = "csum parse-tunnel on|off <port_id>: "
4774                 "Enable/Disable parsing of tunnels for csum engine",
4775         .tokens = {
4776                 (void *)&cmd_csum_tunnel_csum,
4777                 (void *)&cmd_csum_tunnel_parse,
4778                 (void *)&cmd_csum_tunnel_onoff,
4779                 (void *)&cmd_csum_tunnel_portid,
4780                 NULL,
4781         },
4782 };
4783
4784 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4785 struct cmd_tso_set_result {
4786         cmdline_fixed_string_t tso;
4787         cmdline_fixed_string_t mode;
4788         uint16_t tso_segsz;
4789         portid_t port_id;
4790 };
4791
4792 static void
4793 cmd_tso_set_parsed(void *parsed_result,
4794                        __rte_unused struct cmdline *cl,
4795                        __rte_unused void *data)
4796 {
4797         struct cmd_tso_set_result *res = parsed_result;
4798         struct rte_eth_dev_info dev_info;
4799         int ret;
4800
4801         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4802                 return;
4803         if (!port_is_stopped(res->port_id)) {
4804                 printf("Please stop port %d first\n", res->port_id);
4805                 return;
4806         }
4807
4808         if (!strcmp(res->mode, "set"))
4809                 ports[res->port_id].tso_segsz = res->tso_segsz;
4810
4811         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4812         if (ret != 0)
4813                 return;
4814
4815         if ((ports[res->port_id].tso_segsz != 0) &&
4816                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4817                 printf("Error: TSO is not supported by port %d\n",
4818                        res->port_id);
4819                 return;
4820         }
4821
4822         if (ports[res->port_id].tso_segsz == 0) {
4823                 ports[res->port_id].dev_conf.txmode.offloads &=
4824                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4825                 printf("TSO for non-tunneled packets is disabled\n");
4826         } else {
4827                 ports[res->port_id].dev_conf.txmode.offloads |=
4828                                                 DEV_TX_OFFLOAD_TCP_TSO;
4829                 printf("TSO segment size for non-tunneled packets is %d\n",
4830                         ports[res->port_id].tso_segsz);
4831         }
4832         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4833
4834         /* display warnings if configuration is not supported by the NIC */
4835         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4836         if (ret != 0)
4837                 return;
4838
4839         if ((ports[res->port_id].tso_segsz != 0) &&
4840                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4841                 printf("Warning: TSO enabled but not "
4842                         "supported by port %d\n", res->port_id);
4843         }
4844
4845         cmd_reconfig_device_queue(res->port_id, 1, 1);
4846 }
4847
4848 cmdline_parse_token_string_t cmd_tso_set_tso =
4849         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4850                                 tso, "tso");
4851 cmdline_parse_token_string_t cmd_tso_set_mode =
4852         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4853                                 mode, "set");
4854 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4855         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4856                                 tso_segsz, UINT16);
4857 cmdline_parse_token_num_t cmd_tso_set_portid =
4858         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4859                                 port_id, UINT16);
4860
4861 cmdline_parse_inst_t cmd_tso_set = {
4862         .f = cmd_tso_set_parsed,
4863         .data = NULL,
4864         .help_str = "tso set <tso_segsz> <port_id>: "
4865                 "Set TSO segment size of non-tunneled packets for csum engine "
4866                 "(0 to disable)",
4867         .tokens = {
4868                 (void *)&cmd_tso_set_tso,
4869                 (void *)&cmd_tso_set_mode,
4870                 (void *)&cmd_tso_set_tso_segsz,
4871                 (void *)&cmd_tso_set_portid,
4872                 NULL,
4873         },
4874 };
4875
4876 cmdline_parse_token_string_t cmd_tso_show_mode =
4877         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4878                                 mode, "show");
4879
4880
4881 cmdline_parse_inst_t cmd_tso_show = {
4882         .f = cmd_tso_set_parsed,
4883         .data = NULL,
4884         .help_str = "tso show <port_id>: "
4885                 "Show TSO segment size of non-tunneled packets for csum engine",
4886         .tokens = {
4887                 (void *)&cmd_tso_set_tso,
4888                 (void *)&cmd_tso_show_mode,
4889                 (void *)&cmd_tso_set_portid,
4890                 NULL,
4891         },
4892 };
4893
4894 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4895 struct cmd_tunnel_tso_set_result {
4896         cmdline_fixed_string_t tso;
4897         cmdline_fixed_string_t mode;
4898         uint16_t tso_segsz;
4899         portid_t port_id;
4900 };
4901
4902 static struct rte_eth_dev_info
4903 check_tunnel_tso_nic_support(portid_t port_id)
4904 {
4905         struct rte_eth_dev_info dev_info;
4906
4907         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4908                 return dev_info;
4909
4910         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4911                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4912                        "not enabled for port %d\n", port_id);
4913         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4914                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4915                        "not enabled for port %d\n", port_id);
4916         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4917                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4918                        "not enabled for port %d\n", port_id);
4919         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4920                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4921                        "not enabled for port %d\n", port_id);
4922         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4923                 printf("Warning: IP TUNNEL TSO not supported therefore "
4924                        "not enabled for port %d\n", port_id);
4925         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4926                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4927                        "not enabled for port %d\n", port_id);
4928         return dev_info;
4929 }
4930
4931 static void
4932 cmd_tunnel_tso_set_parsed(void *parsed_result,
4933                           __rte_unused struct cmdline *cl,
4934                           __rte_unused void *data)
4935 {
4936         struct cmd_tunnel_tso_set_result *res = parsed_result;
4937         struct rte_eth_dev_info dev_info;
4938
4939         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4940                 return;
4941         if (!port_is_stopped(res->port_id)) {
4942                 printf("Please stop port %d first\n", res->port_id);
4943                 return;
4944         }
4945
4946         if (!strcmp(res->mode, "set"))
4947                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4948
4949         dev_info = check_tunnel_tso_nic_support(res->port_id);
4950         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4951                 ports[res->port_id].dev_conf.txmode.offloads &=
4952                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4953                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4954                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4955                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4956                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4957                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4958                 printf("TSO for tunneled packets is disabled\n");
4959         } else {
4960                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4961                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4962                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4963                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4964                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4965                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4966
4967                 ports[res->port_id].dev_conf.txmode.offloads |=
4968                         (tso_offloads & dev_info.tx_offload_capa);
4969                 printf("TSO segment size for tunneled packets is %d\n",
4970                         ports[res->port_id].tunnel_tso_segsz);
4971
4972                 /* Below conditions are needed to make it work:
4973                  * (1) tunnel TSO is supported by the NIC;
4974                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4975                  * are recognized;
4976                  * (3) for tunneled pkts with outer L3 of IPv4,
4977                  * "csum set outer-ip" must be set to hw, because after tso,
4978                  * total_len of outer IP header is changed, and the checksum
4979                  * of outer IP header calculated by sw should be wrong; that
4980                  * is not necessary for IPv6 tunneled pkts because there's no
4981                  * checksum in IP header anymore.
4982                  */
4983
4984                 if (!ports[res->port_id].parse_tunnel)
4985                         printf("Warning: csum parse_tunnel must be set "
4986                                 "so that tunneled packets are recognized\n");
4987                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4988                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4989                         printf("Warning: csum set outer-ip must be set to hw "
4990                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4991         }
4992
4993         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4994         cmd_reconfig_device_queue(res->port_id, 1, 1);
4995 }
4996
4997 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4998         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4999                                 tso, "tunnel_tso");
5000 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5001         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5002                                 mode, "set");
5003 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5004         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5005                                 tso_segsz, UINT16);
5006 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5007         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5008                                 port_id, UINT16);
5009
5010 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5011         .f = cmd_tunnel_tso_set_parsed,
5012         .data = NULL,
5013         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5014                 "Set TSO segment size of tunneled packets for csum engine "
5015                 "(0 to disable)",
5016         .tokens = {
5017                 (void *)&cmd_tunnel_tso_set_tso,
5018                 (void *)&cmd_tunnel_tso_set_mode,
5019                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5020                 (void *)&cmd_tunnel_tso_set_portid,
5021                 NULL,
5022         },
5023 };
5024
5025 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5026         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5027                                 mode, "show");
5028
5029
5030 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5031         .f = cmd_tunnel_tso_set_parsed,
5032         .data = NULL,
5033         .help_str = "tunnel_tso show <port_id> "
5034                 "Show TSO segment size of tunneled packets for csum engine",
5035         .tokens = {
5036                 (void *)&cmd_tunnel_tso_set_tso,
5037                 (void *)&cmd_tunnel_tso_show_mode,
5038                 (void *)&cmd_tunnel_tso_set_portid,
5039                 NULL,
5040         },
5041 };
5042
5043 /* *** SET GRO FOR A PORT *** */
5044 struct cmd_gro_enable_result {
5045         cmdline_fixed_string_t cmd_set;
5046         cmdline_fixed_string_t cmd_port;
5047         cmdline_fixed_string_t cmd_keyword;
5048         cmdline_fixed_string_t cmd_onoff;
5049         portid_t cmd_pid;
5050 };
5051
5052 static void
5053 cmd_gro_enable_parsed(void *parsed_result,
5054                 __rte_unused struct cmdline *cl,
5055                 __rte_unused void *data)
5056 {
5057         struct cmd_gro_enable_result *res;
5058
5059         res = parsed_result;
5060         if (!strcmp(res->cmd_keyword, "gro"))
5061                 setup_gro(res->cmd_onoff, res->cmd_pid);
5062 }
5063
5064 cmdline_parse_token_string_t cmd_gro_enable_set =
5065         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5066                         cmd_set, "set");
5067 cmdline_parse_token_string_t cmd_gro_enable_port =
5068         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5069                         cmd_keyword, "port");
5070 cmdline_parse_token_num_t cmd_gro_enable_pid =
5071         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5072                         cmd_pid, UINT16);
5073 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5074         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5075                         cmd_keyword, "gro");
5076 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5077         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5078                         cmd_onoff, "on#off");
5079
5080 cmdline_parse_inst_t cmd_gro_enable = {
5081         .f = cmd_gro_enable_parsed,
5082         .data = NULL,
5083         .help_str = "set port <port_id> gro on|off",
5084         .tokens = {
5085                 (void *)&cmd_gro_enable_set,
5086                 (void *)&cmd_gro_enable_port,
5087                 (void *)&cmd_gro_enable_pid,
5088                 (void *)&cmd_gro_enable_keyword,
5089                 (void *)&cmd_gro_enable_onoff,
5090                 NULL,
5091         },
5092 };
5093
5094 /* *** DISPLAY GRO CONFIGURATION *** */
5095 struct cmd_gro_show_result {
5096         cmdline_fixed_string_t cmd_show;
5097         cmdline_fixed_string_t cmd_port;
5098         cmdline_fixed_string_t cmd_keyword;
5099         portid_t cmd_pid;
5100 };
5101
5102 static void
5103 cmd_gro_show_parsed(void *parsed_result,
5104                 __rte_unused struct cmdline *cl,
5105                 __rte_unused void *data)
5106 {
5107         struct cmd_gro_show_result *res;
5108
5109         res = parsed_result;
5110         if (!strcmp(res->cmd_keyword, "gro"))
5111                 show_gro(res->cmd_pid);
5112 }
5113
5114 cmdline_parse_token_string_t cmd_gro_show_show =
5115         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5116                         cmd_show, "show");
5117 cmdline_parse_token_string_t cmd_gro_show_port =
5118         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5119                         cmd_port, "port");
5120 cmdline_parse_token_num_t cmd_gro_show_pid =
5121         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5122                         cmd_pid, UINT16);
5123 cmdline_parse_token_string_t cmd_gro_show_keyword =
5124         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5125                         cmd_keyword, "gro");
5126
5127 cmdline_parse_inst_t cmd_gro_show = {
5128         .f = cmd_gro_show_parsed,
5129         .data = NULL,
5130         .help_str = "show port <port_id> gro",
5131         .tokens = {
5132                 (void *)&cmd_gro_show_show,
5133                 (void *)&cmd_gro_show_port,
5134                 (void *)&cmd_gro_show_pid,
5135                 (void *)&cmd_gro_show_keyword,
5136                 NULL,
5137         },
5138 };
5139
5140 /* *** SET FLUSH CYCLES FOR GRO *** */
5141 struct cmd_gro_flush_result {
5142         cmdline_fixed_string_t cmd_set;
5143         cmdline_fixed_string_t cmd_keyword;
5144         cmdline_fixed_string_t cmd_flush;
5145         uint8_t cmd_cycles;
5146 };
5147
5148 static void
5149 cmd_gro_flush_parsed(void *parsed_result,
5150                 __rte_unused struct cmdline *cl,
5151                 __rte_unused void *data)
5152 {
5153         struct cmd_gro_flush_result *res;
5154
5155         res = parsed_result;
5156         if ((!strcmp(res->cmd_keyword, "gro")) &&
5157                         (!strcmp(res->cmd_flush, "flush")))
5158                 setup_gro_flush_cycles(res->cmd_cycles);
5159 }
5160
5161 cmdline_parse_token_string_t cmd_gro_flush_set =
5162         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5163                         cmd_set, "set");
5164 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5165         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5166                         cmd_keyword, "gro");
5167 cmdline_parse_token_string_t cmd_gro_flush_flush =
5168         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5169                         cmd_flush, "flush");
5170 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5171         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5172                         cmd_cycles, UINT8);
5173
5174 cmdline_parse_inst_t cmd_gro_flush = {
5175         .f = cmd_gro_flush_parsed,
5176         .data = NULL,
5177         .help_str = "set gro flush <cycles>",
5178         .tokens = {
5179                 (void *)&cmd_gro_flush_set,
5180                 (void *)&cmd_gro_flush_keyword,
5181                 (void *)&cmd_gro_flush_flush,
5182                 (void *)&cmd_gro_flush_cycles,
5183                 NULL,
5184         },
5185 };
5186
5187 /* *** ENABLE/DISABLE GSO *** */
5188 struct cmd_gso_enable_result {
5189         cmdline_fixed_string_t cmd_set;
5190         cmdline_fixed_string_t cmd_port;
5191         cmdline_fixed_string_t cmd_keyword;
5192         cmdline_fixed_string_t cmd_mode;
5193         portid_t cmd_pid;
5194 };
5195
5196 static void
5197 cmd_gso_enable_parsed(void *parsed_result,
5198                 __rte_unused struct cmdline *cl,
5199                 __rte_unused void *data)
5200 {
5201         struct cmd_gso_enable_result *res;
5202
5203         res = parsed_result;
5204         if (!strcmp(res->cmd_keyword, "gso"))
5205                 setup_gso(res->cmd_mode, res->cmd_pid);
5206 }
5207
5208 cmdline_parse_token_string_t cmd_gso_enable_set =
5209         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5210                         cmd_set, "set");
5211 cmdline_parse_token_string_t cmd_gso_enable_port =
5212         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5213                         cmd_port, "port");
5214 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5215         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5216                         cmd_keyword, "gso");
5217 cmdline_parse_token_string_t cmd_gso_enable_mode =
5218         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5219                         cmd_mode, "on#off");
5220 cmdline_parse_token_num_t cmd_gso_enable_pid =
5221         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5222                         cmd_pid, UINT16);
5223
5224 cmdline_parse_inst_t cmd_gso_enable = {
5225         .f = cmd_gso_enable_parsed,
5226         .data = NULL,
5227         .help_str = "set port <port_id> gso on|off",
5228         .tokens = {
5229                 (void *)&cmd_gso_enable_set,
5230                 (void *)&cmd_gso_enable_port,
5231                 (void *)&cmd_gso_enable_pid,
5232                 (void *)&cmd_gso_enable_keyword,
5233                 (void *)&cmd_gso_enable_mode,
5234                 NULL,
5235         },
5236 };
5237
5238 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5239 struct cmd_gso_size_result {
5240         cmdline_fixed_string_t cmd_set;
5241         cmdline_fixed_string_t cmd_keyword;
5242         cmdline_fixed_string_t cmd_segsz;
5243         uint16_t cmd_size;
5244 };
5245
5246 static void
5247 cmd_gso_size_parsed(void *parsed_result,
5248                        __rte_unused struct cmdline *cl,
5249                        __rte_unused void *data)
5250 {
5251         struct cmd_gso_size_result *res = parsed_result;
5252
5253         if (test_done == 0) {
5254                 printf("Before setting GSO segsz, please first"
5255                                 " stop forwarding\n");
5256                 return;
5257         }
5258
5259         if (!strcmp(res->cmd_keyword, "gso") &&
5260                         !strcmp(res->cmd_segsz, "segsz")) {
5261                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5262                         printf("gso_size should be larger than %zu."
5263                                         " Please input a legal value\n",
5264                                         RTE_GSO_SEG_SIZE_MIN);
5265                 else
5266                         gso_max_segment_size = res->cmd_size;
5267         }
5268 }
5269
5270 cmdline_parse_token_string_t cmd_gso_size_set =
5271         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5272                                 cmd_set, "set");
5273 cmdline_parse_token_string_t cmd_gso_size_keyword =
5274         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5275                                 cmd_keyword, "gso");
5276 cmdline_parse_token_string_t cmd_gso_size_segsz =
5277         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5278                                 cmd_segsz, "segsz");
5279 cmdline_parse_token_num_t cmd_gso_size_size =
5280         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5281                                 cmd_size, UINT16);
5282
5283 cmdline_parse_inst_t cmd_gso_size = {
5284         .f = cmd_gso_size_parsed,
5285         .data = NULL,
5286         .help_str = "set gso segsz <length>",
5287         .tokens = {
5288                 (void *)&cmd_gso_size_set,
5289                 (void *)&cmd_gso_size_keyword,
5290                 (void *)&cmd_gso_size_segsz,
5291                 (void *)&cmd_gso_size_size,
5292                 NULL,
5293         },
5294 };
5295
5296 /* *** SHOW GSO CONFIGURATION *** */
5297 struct cmd_gso_show_result {
5298         cmdline_fixed_string_t cmd_show;
5299         cmdline_fixed_string_t cmd_port;
5300         cmdline_fixed_string_t cmd_keyword;
5301         portid_t cmd_pid;
5302 };
5303
5304 static void
5305 cmd_gso_show_parsed(void *parsed_result,
5306                        __rte_unused struct cmdline *cl,
5307                        __rte_unused void *data)
5308 {
5309         struct cmd_gso_show_result *res = parsed_result;
5310
5311         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5312                 printf("invalid port id %u\n", res->cmd_pid);
5313                 return;
5314         }
5315         if (!strcmp(res->cmd_keyword, "gso")) {
5316                 if (gso_ports[res->cmd_pid].enable) {
5317                         printf("Max GSO'd packet size: %uB\n"
5318                                         "Supported GSO types: TCP/IPv4, "
5319                                         "UDP/IPv4, VxLAN with inner "
5320                                         "TCP/IPv4 packet, GRE with inner "
5321                                         "TCP/IPv4 packet\n",
5322                                         gso_max_segment_size);
5323                 } else
5324                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5325         }
5326 }
5327
5328 cmdline_parse_token_string_t cmd_gso_show_show =
5329 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5330                 cmd_show, "show");
5331 cmdline_parse_token_string_t cmd_gso_show_port =
5332 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5333                 cmd_port, "port");
5334 cmdline_parse_token_string_t cmd_gso_show_keyword =
5335         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5336                                 cmd_keyword, "gso");
5337 cmdline_parse_token_num_t cmd_gso_show_pid =
5338         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5339                                 cmd_pid, UINT16);
5340
5341 cmdline_parse_inst_t cmd_gso_show = {
5342         .f = cmd_gso_show_parsed,
5343         .data = NULL,
5344         .help_str = "show port <port_id> gso",
5345         .tokens = {
5346                 (void *)&cmd_gso_show_show,
5347                 (void *)&cmd_gso_show_port,
5348                 (void *)&cmd_gso_show_pid,
5349                 (void *)&cmd_gso_show_keyword,
5350                 NULL,
5351         },
5352 };
5353
5354 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5355 struct cmd_set_flush_rx {
5356         cmdline_fixed_string_t set;
5357         cmdline_fixed_string_t flush_rx;
5358         cmdline_fixed_string_t mode;
5359 };
5360
5361 static void
5362 cmd_set_flush_rx_parsed(void *parsed_result,
5363                 __rte_unused struct cmdline *cl,
5364                 __rte_unused void *data)
5365 {
5366         struct cmd_set_flush_rx *res = parsed_result;
5367         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5368 }
5369
5370 cmdline_parse_token_string_t cmd_setflushrx_set =
5371         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5372                         set, "set");
5373 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5374         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5375                         flush_rx, "flush_rx");
5376 cmdline_parse_token_string_t cmd_setflushrx_mode =
5377         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5378                         mode, "on#off");
5379
5380
5381 cmdline_parse_inst_t cmd_set_flush_rx = {
5382         .f = cmd_set_flush_rx_parsed,
5383         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5384         .data = NULL,
5385         .tokens = {
5386                 (void *)&cmd_setflushrx_set,
5387                 (void *)&cmd_setflushrx_flush_rx,
5388                 (void *)&cmd_setflushrx_mode,
5389                 NULL,
5390         },
5391 };
5392
5393 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5394 struct cmd_set_link_check {
5395         cmdline_fixed_string_t set;
5396         cmdline_fixed_string_t link_check;
5397         cmdline_fixed_string_t mode;
5398 };
5399
5400 static void
5401 cmd_set_link_check_parsed(void *parsed_result,
5402                 __rte_unused struct cmdline *cl,
5403                 __rte_unused void *data)
5404 {
5405         struct cmd_set_link_check *res = parsed_result;
5406         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5407 }
5408
5409 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5410         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5411                         set, "set");
5412 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5413         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5414                         link_check, "link_check");
5415 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5416         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5417                         mode, "on#off");
5418
5419
5420 cmdline_parse_inst_t cmd_set_link_check = {
5421         .f = cmd_set_link_check_parsed,
5422         .help_str = "set link_check on|off: Enable/Disable link status check "
5423                     "when starting/stopping a port",
5424         .data = NULL,
5425         .tokens = {
5426                 (void *)&cmd_setlinkcheck_set,
5427                 (void *)&cmd_setlinkcheck_link_check,
5428                 (void *)&cmd_setlinkcheck_mode,
5429                 NULL,
5430         },
5431 };
5432
5433 /* *** SET NIC BYPASS MODE *** */
5434 struct cmd_set_bypass_mode_result {
5435         cmdline_fixed_string_t set;
5436         cmdline_fixed_string_t bypass;
5437         cmdline_fixed_string_t mode;
5438         cmdline_fixed_string_t value;
5439         portid_t port_id;
5440 };
5441
5442 static void
5443 cmd_set_bypass_mode_parsed(void *parsed_result,
5444                 __rte_unused struct cmdline *cl,
5445                 __rte_unused void *data)
5446 {
5447         struct cmd_set_bypass_mode_result *res = parsed_result;
5448         portid_t port_id = res->port_id;
5449         int32_t rc = -EINVAL;
5450
5451 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5452         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5453
5454         if (!strcmp(res->value, "bypass"))
5455                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5456         else if (!strcmp(res->value, "isolate"))
5457                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5458         else
5459                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5460
5461         /* Set the bypass mode for the relevant port. */
5462         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5463 #endif
5464         if (rc != 0)
5465                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5466 }
5467
5468 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5469         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5470                         set, "set");
5471 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5472         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5473                         bypass, "bypass");
5474 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5475         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5476                         mode, "mode");
5477 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5478         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5479                         value, "normal#bypass#isolate");
5480 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5481         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5482                                 port_id, UINT16);
5483
5484 cmdline_parse_inst_t cmd_set_bypass_mode = {
5485         .f = cmd_set_bypass_mode_parsed,
5486         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5487                     "Set the NIC bypass mode for port_id",
5488         .data = NULL,
5489         .tokens = {
5490                 (void *)&cmd_setbypass_mode_set,
5491                 (void *)&cmd_setbypass_mode_bypass,
5492                 (void *)&cmd_setbypass_mode_mode,
5493                 (void *)&cmd_setbypass_mode_value,
5494                 (void *)&cmd_setbypass_mode_port,
5495                 NULL,
5496         },
5497 };
5498
5499 /* *** SET NIC BYPASS EVENT *** */
5500 struct cmd_set_bypass_event_result {
5501         cmdline_fixed_string_t set;
5502         cmdline_fixed_string_t bypass;
5503         cmdline_fixed_string_t event;
5504         cmdline_fixed_string_t event_value;
5505         cmdline_fixed_string_t mode;
5506         cmdline_fixed_string_t mode_value;
5507         portid_t port_id;
5508 };
5509
5510 static void
5511 cmd_set_bypass_event_parsed(void *parsed_result,
5512                 __rte_unused struct cmdline *cl,
5513                 __rte_unused void *data)
5514 {
5515         int32_t rc = -EINVAL;
5516         struct cmd_set_bypass_event_result *res = parsed_result;
5517         portid_t port_id = res->port_id;
5518
5519 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5520         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5521         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5522
5523         if (!strcmp(res->event_value, "timeout"))
5524                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5525         else if (!strcmp(res->event_value, "os_on"))
5526                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5527         else if (!strcmp(res->event_value, "os_off"))
5528                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5529         else if (!strcmp(res->event_value, "power_on"))
5530                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5531         else if (!strcmp(res->event_value, "power_off"))
5532                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5533         else
5534                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5535
5536         if (!strcmp(res->mode_value, "bypass"))
5537                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5538         else if (!strcmp(res->mode_value, "isolate"))
5539                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5540         else
5541                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5542
5543         /* Set the watchdog timeout. */
5544         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5545
5546                 rc = -EINVAL;
5547                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5548                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5549                                                            bypass_timeout);
5550                 }
5551                 if (rc != 0) {
5552                         printf("Failed to set timeout value %u "
5553                         "for port %d, errto code: %d.\n",
5554                         bypass_timeout, port_id, rc);
5555                 }
5556         }
5557
5558         /* Set the bypass event to transition to bypass mode. */
5559         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5560                                               bypass_mode);
5561 #endif
5562
5563         if (rc != 0)
5564                 printf("\t Failed to set bypass event for port = %d.\n",
5565                        port_id);
5566 }
5567
5568 cmdline_parse_token_string_t cmd_setbypass_event_set =
5569         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5570                         set, "set");
5571 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5572         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5573                         bypass, "bypass");
5574 cmdline_parse_token_string_t cmd_setbypass_event_event =
5575         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5576                         event, "event");
5577 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5578         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5579                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5580 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5581         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5582                         mode, "mode");
5583 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5584         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5585                         mode_value, "normal#bypass#isolate");
5586 cmdline_parse_token_num_t cmd_setbypass_event_port =
5587         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5588                                 port_id, UINT16);
5589
5590 cmdline_parse_inst_t cmd_set_bypass_event = {
5591         .f = cmd_set_bypass_event_parsed,
5592         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5593                 "power_off mode normal|bypass|isolate <port_id>: "
5594                 "Set the NIC bypass event mode for port_id",
5595         .data = NULL,
5596         .tokens = {
5597                 (void *)&cmd_setbypass_event_set,
5598                 (void *)&cmd_setbypass_event_bypass,
5599                 (void *)&cmd_setbypass_event_event,
5600                 (void *)&cmd_setbypass_event_event_value,
5601                 (void *)&cmd_setbypass_event_mode,
5602                 (void *)&cmd_setbypass_event_mode_value,
5603                 (void *)&cmd_setbypass_event_port,
5604                 NULL,
5605         },
5606 };
5607
5608
5609 /* *** SET NIC BYPASS TIMEOUT *** */
5610 struct cmd_set_bypass_timeout_result {
5611         cmdline_fixed_string_t set;
5612         cmdline_fixed_string_t bypass;
5613         cmdline_fixed_string_t timeout;
5614         cmdline_fixed_string_t value;
5615 };
5616
5617 static void
5618 cmd_set_bypass_timeout_parsed(void *parsed_result,
5619                 __rte_unused struct cmdline *cl,
5620                 __rte_unused void *data)
5621 {
5622         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5623
5624 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5625         if (!strcmp(res->value, "1.5"))
5626                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5627         else if (!strcmp(res->value, "2"))
5628                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5629         else if (!strcmp(res->value, "3"))
5630                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5631         else if (!strcmp(res->value, "4"))
5632                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5633         else if (!strcmp(res->value, "8"))
5634                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5635         else if (!strcmp(res->value, "16"))
5636                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5637         else if (!strcmp(res->value, "32"))
5638                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5639         else
5640                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5641 #endif
5642 }
5643
5644 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5645         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5646                         set, "set");
5647 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5648         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5649                         bypass, "bypass");
5650 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5651         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5652                         timeout, "timeout");
5653 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5654         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5655                         value, "0#1.5#2#3#4#8#16#32");
5656
5657 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5658         .f = cmd_set_bypass_timeout_parsed,
5659         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5660                 "Set the NIC bypass watchdog timeout in seconds",
5661         .data = NULL,
5662         .tokens = {
5663                 (void *)&cmd_setbypass_timeout_set,
5664                 (void *)&cmd_setbypass_timeout_bypass,
5665                 (void *)&cmd_setbypass_timeout_timeout,
5666                 (void *)&cmd_setbypass_timeout_value,
5667                 NULL,
5668         },
5669 };
5670
5671 /* *** SHOW NIC BYPASS MODE *** */
5672 struct cmd_show_bypass_config_result {
5673         cmdline_fixed_string_t show;
5674         cmdline_fixed_string_t bypass;
5675         cmdline_fixed_string_t config;
5676         portid_t port_id;
5677 };
5678
5679 static void
5680 cmd_show_bypass_config_parsed(void *parsed_result,
5681                 __rte_unused struct cmdline *cl,
5682                 __rte_unused void *data)
5683 {
5684         struct cmd_show_bypass_config_result *res = parsed_result;
5685         portid_t port_id = res->port_id;
5686         int rc = -EINVAL;
5687 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5688         uint32_t event_mode;
5689         uint32_t bypass_mode;
5690         uint32_t timeout = bypass_timeout;
5691         unsigned int i;
5692
5693         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5694                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5695         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5696                 {"UNKNOWN", "normal", "bypass", "isolate"};
5697         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5698                 "NONE",
5699                 "OS/board on",
5700                 "power supply on",
5701                 "OS/board off",
5702                 "power supply off",
5703                 "timeout"};
5704
5705         /* Display the bypass mode.*/
5706         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5707                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5708                 return;
5709         }
5710         else {
5711                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5712                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5713
5714                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5715         }
5716
5717         /* Display the bypass timeout.*/
5718         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5719                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5720
5721         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5722
5723         /* Display the bypass events and associated modes. */
5724         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5725
5726                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5727                         printf("\tFailed to get bypass mode for event = %s\n",
5728                                 events[i]);
5729                 } else {
5730                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5731                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5732
5733                         printf("\tbypass event: %-16s = %s\n", events[i],
5734                                 modes[event_mode]);
5735                 }
5736         }
5737 #endif
5738         if (rc != 0)
5739                 printf("\tFailed to get bypass configuration for port = %d\n",
5740                        port_id);
5741 }
5742
5743 cmdline_parse_token_string_t cmd_showbypass_config_show =
5744         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5745                         show, "show");
5746 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5747         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5748                         bypass, "bypass");
5749 cmdline_parse_token_string_t cmd_showbypass_config_config =
5750         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5751                         config, "config");
5752 cmdline_parse_token_num_t cmd_showbypass_config_port =
5753         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5754                                 port_id, UINT16);
5755
5756 cmdline_parse_inst_t cmd_show_bypass_config = {
5757         .f = cmd_show_bypass_config_parsed,
5758         .help_str = "show bypass config <port_id>: "
5759                     "Show the NIC bypass config for port_id",
5760         .data = NULL,
5761         .tokens = {
5762                 (void *)&cmd_showbypass_config_show,
5763                 (void *)&cmd_showbypass_config_bypass,
5764                 (void *)&cmd_showbypass_config_config,
5765                 (void *)&cmd_showbypass_config_port,
5766                 NULL,
5767         },
5768 };
5769
5770 #ifdef RTE_LIBRTE_PMD_BOND
5771 /* *** SET BONDING MODE *** */
5772 struct cmd_set_bonding_mode_result {
5773         cmdline_fixed_string_t set;
5774         cmdline_fixed_string_t bonding;
5775         cmdline_fixed_string_t mode;
5776         uint8_t value;
5777         portid_t port_id;
5778 };
5779
5780 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5781                 __rte_unused  struct cmdline *cl,
5782                 __rte_unused void *data)
5783 {
5784         struct cmd_set_bonding_mode_result *res = parsed_result;
5785         portid_t port_id = res->port_id;
5786
5787         /* Set the bonding mode for the relevant port. */
5788         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5789                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5790 }
5791
5792 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5793 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5794                 set, "set");
5795 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5796 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5797                 bonding, "bonding");
5798 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5799 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5800                 mode, "mode");
5801 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5802 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5803                 value, UINT8);
5804 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5805 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5806                 port_id, UINT16);
5807
5808 cmdline_parse_inst_t cmd_set_bonding_mode = {
5809                 .f = cmd_set_bonding_mode_parsed,
5810                 .help_str = "set bonding mode <mode_value> <port_id>: "
5811                         "Set the bonding mode for port_id",
5812                 .data = NULL,
5813                 .tokens = {
5814                                 (void *) &cmd_setbonding_mode_set,
5815                                 (void *) &cmd_setbonding_mode_bonding,
5816                                 (void *) &cmd_setbonding_mode_mode,
5817                                 (void *) &cmd_setbonding_mode_value,
5818                                 (void *) &cmd_setbonding_mode_port,
5819                                 NULL
5820                 }
5821 };
5822
5823 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5824 struct cmd_set_bonding_lacp_dedicated_queues_result {
5825         cmdline_fixed_string_t set;
5826         cmdline_fixed_string_t bonding;
5827         cmdline_fixed_string_t lacp;
5828         cmdline_fixed_string_t dedicated_queues;
5829         portid_t port_id;
5830         cmdline_fixed_string_t mode;
5831 };
5832
5833 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5834                 __rte_unused  struct cmdline *cl,
5835                 __rte_unused void *data)
5836 {
5837         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5838         portid_t port_id = res->port_id;
5839         struct rte_port *port;
5840
5841         port = &ports[port_id];
5842
5843         /** Check if the port is not started **/
5844         if (port->port_status != RTE_PORT_STOPPED) {
5845                 printf("Please stop port %d first\n", port_id);
5846                 return;
5847         }
5848
5849         if (!strcmp(res->mode, "enable")) {
5850                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5851                         printf("Dedicate queues for LACP control packets"
5852                                         " enabled\n");
5853                 else
5854                         printf("Enabling dedicate queues for LACP control "
5855                                         "packets on port %d failed\n", port_id);
5856         } else if (!strcmp(res->mode, "disable")) {
5857                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5858                         printf("Dedicated queues for LACP control packets "
5859                                         "disabled\n");
5860                 else
5861                         printf("Disabling dedicated queues for LACP control "
5862                                         "traffic on port %d failed\n", port_id);
5863         }
5864 }
5865
5866 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5867 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5868                 set, "set");
5869 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5870 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5871                 bonding, "bonding");
5872 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5873 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5874                 lacp, "lacp");
5875 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5876 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5877                 dedicated_queues, "dedicated_queues");
5878 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5879 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5880                 port_id, UINT16);
5881 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5882 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5883                 mode, "enable#disable");
5884
5885 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5886                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5887                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5888                         "enable|disable: "
5889                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5890                 .data = NULL,
5891                 .tokens = {
5892                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5893                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5894                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5895                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5896                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5897                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5898                         NULL
5899                 }
5900 };
5901
5902 /* *** SET BALANCE XMIT POLICY *** */
5903 struct cmd_set_bonding_balance_xmit_policy_result {
5904         cmdline_fixed_string_t set;
5905         cmdline_fixed_string_t bonding;
5906         cmdline_fixed_string_t balance_xmit_policy;
5907         portid_t port_id;
5908         cmdline_fixed_string_t policy;
5909 };
5910
5911 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5912                 __rte_unused  struct cmdline *cl,
5913                 __rte_unused void *data)
5914 {
5915         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5916         portid_t port_id = res->port_id;
5917         uint8_t policy;
5918
5919         if (!strcmp(res->policy, "l2")) {
5920                 policy = BALANCE_XMIT_POLICY_LAYER2;
5921         } else if (!strcmp(res->policy, "l23")) {
5922                 policy = BALANCE_XMIT_POLICY_LAYER23;
5923         } else if (!strcmp(res->policy, "l34")) {
5924                 policy = BALANCE_XMIT_POLICY_LAYER34;
5925         } else {
5926                 printf("\t Invalid xmit policy selection");
5927                 return;
5928         }
5929
5930         /* Set the bonding mode for the relevant port. */
5931         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5932                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5933                                 port_id);
5934         }
5935 }
5936
5937 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5938 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5939                 set, "set");
5940 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5941 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5942                 bonding, "bonding");
5943 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5944 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5945                 balance_xmit_policy, "balance_xmit_policy");
5946 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5947 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5948                 port_id, UINT16);
5949 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5950 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5951                 policy, "l2#l23#l34");
5952
5953 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5954                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5955                 .help_str = "set bonding balance_xmit_policy <port_id> "
5956                         "l2|l23|l34: "
5957                         "Set the bonding balance_xmit_policy for port_id",
5958                 .data = NULL,
5959                 .tokens = {
5960                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5961                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5962                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5963                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5964                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5965                                 NULL
5966                 }
5967 };
5968
5969 /* *** SHOW NIC BONDING CONFIGURATION *** */
5970 struct cmd_show_bonding_config_result {
5971         cmdline_fixed_string_t show;
5972         cmdline_fixed_string_t bonding;
5973         cmdline_fixed_string_t config;
5974         portid_t port_id;
5975 };
5976
5977 static void cmd_show_bonding_config_parsed(void *parsed_result,
5978                 __rte_unused  struct cmdline *cl,
5979                 __rte_unused void *data)
5980 {
5981         struct cmd_show_bonding_config_result *res = parsed_result;
5982         int bonding_mode, agg_mode;
5983         portid_t slaves[RTE_MAX_ETHPORTS];
5984         int num_slaves, num_active_slaves;
5985         int primary_id;
5986         int i;
5987         portid_t port_id = res->port_id;
5988
5989         /* Display the bonding mode.*/
5990         bonding_mode = rte_eth_bond_mode_get(port_id);
5991         if (bonding_mode < 0) {
5992                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5993                 return;
5994         } else
5995                 printf("\tBonding mode: %d\n", bonding_mode);
5996
5997         if (bonding_mode == BONDING_MODE_BALANCE) {
5998                 int balance_xmit_policy;
5999
6000                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6001                 if (balance_xmit_policy < 0) {
6002                         printf("\tFailed to get balance xmit policy for port = %d\n",
6003                                         port_id);
6004                         return;
6005                 } else {
6006                         printf("\tBalance Xmit Policy: ");
6007
6008                         switch (balance_xmit_policy) {
6009                         case BALANCE_XMIT_POLICY_LAYER2:
6010                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6011                                 break;
6012                         case BALANCE_XMIT_POLICY_LAYER23:
6013                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6014                                 break;
6015                         case BALANCE_XMIT_POLICY_LAYER34:
6016                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6017                                 break;
6018                         }
6019                         printf("\n");
6020                 }
6021         }
6022
6023         if (bonding_mode == BONDING_MODE_8023AD) {
6024                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6025                 printf("\tIEEE802.3AD Aggregator Mode: ");
6026                 switch (agg_mode) {
6027                 case AGG_BANDWIDTH:
6028                         printf("bandwidth");
6029                         break;
6030                 case AGG_STABLE:
6031                         printf("stable");
6032                         break;
6033                 case AGG_COUNT:
6034                         printf("count");
6035                         break;
6036                 }
6037                 printf("\n");
6038         }
6039
6040         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6041
6042         if (num_slaves < 0) {
6043                 printf("\tFailed to get slave list for port = %d\n", port_id);
6044                 return;
6045         }
6046         if (num_slaves > 0) {
6047                 printf("\tSlaves (%d): [", num_slaves);
6048                 for (i = 0; i < num_slaves - 1; i++)
6049                         printf("%d ", slaves[i]);
6050
6051                 printf("%d]\n", slaves[num_slaves - 1]);
6052         } else {
6053                 printf("\tSlaves: []\n");
6054
6055         }
6056
6057         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6058                         RTE_MAX_ETHPORTS);
6059
6060         if (num_active_slaves < 0) {
6061                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6062                 return;
6063         }
6064         if (num_active_slaves > 0) {
6065                 printf("\tActive Slaves (%d): [", num_active_slaves);
6066                 for (i = 0; i < num_active_slaves - 1; i++)
6067                         printf("%d ", slaves[i]);
6068
6069                 printf("%d]\n", slaves[num_active_slaves - 1]);
6070
6071         } else {
6072                 printf("\tActive Slaves: []\n");
6073
6074         }
6075
6076         primary_id = rte_eth_bond_primary_get(port_id);
6077         if (primary_id < 0) {
6078                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6079                 return;
6080         } else
6081                 printf("\tPrimary: [%d]\n", primary_id);
6082
6083 }
6084
6085 cmdline_parse_token_string_t cmd_showbonding_config_show =
6086 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6087                 show, "show");
6088 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6089 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6090                 bonding, "bonding");
6091 cmdline_parse_token_string_t cmd_showbonding_config_config =
6092 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6093                 config, "config");
6094 cmdline_parse_token_num_t cmd_showbonding_config_port =
6095 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6096                 port_id, UINT16);
6097
6098 cmdline_parse_inst_t cmd_show_bonding_config = {
6099                 .f = cmd_show_bonding_config_parsed,
6100                 .help_str = "show bonding config <port_id>: "
6101                         "Show the bonding config for port_id",
6102                 .data = NULL,
6103                 .tokens = {
6104                                 (void *)&cmd_showbonding_config_show,
6105                                 (void *)&cmd_showbonding_config_bonding,
6106                                 (void *)&cmd_showbonding_config_config,
6107                                 (void *)&cmd_showbonding_config_port,
6108                                 NULL
6109                 }
6110 };
6111
6112 /* *** SET BONDING PRIMARY *** */
6113 struct cmd_set_bonding_primary_result {
6114         cmdline_fixed_string_t set;
6115         cmdline_fixed_string_t bonding;
6116         cmdline_fixed_string_t primary;
6117         portid_t slave_id;
6118         portid_t port_id;
6119 };
6120
6121 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6122                 __rte_unused  struct cmdline *cl,
6123                 __rte_unused void *data)
6124 {
6125         struct cmd_set_bonding_primary_result *res = parsed_result;
6126         portid_t master_port_id = res->port_id;
6127         portid_t slave_port_id = res->slave_id;
6128
6129         /* Set the primary slave for a bonded device. */
6130         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6131                 printf("\t Failed to set primary slave for port = %d.\n",
6132                                 master_port_id);
6133                 return;
6134         }
6135         init_port_config();
6136 }
6137
6138 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6139 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6140                 set, "set");
6141 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6142 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6143                 bonding, "bonding");
6144 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6145 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6146                 primary, "primary");
6147 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6148 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6149                 slave_id, UINT16);
6150 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6151 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6152                 port_id, UINT16);
6153
6154 cmdline_parse_inst_t cmd_set_bonding_primary = {
6155                 .f = cmd_set_bonding_primary_parsed,
6156                 .help_str = "set bonding primary <slave_id> <port_id>: "
6157                         "Set the primary slave for port_id",
6158                 .data = NULL,
6159                 .tokens = {
6160                                 (void *)&cmd_setbonding_primary_set,
6161                                 (void *)&cmd_setbonding_primary_bonding,
6162                                 (void *)&cmd_setbonding_primary_primary,
6163                                 (void *)&cmd_setbonding_primary_slave,
6164                                 (void *)&cmd_setbonding_primary_port,
6165                                 NULL
6166                 }
6167 };
6168
6169 /* *** ADD SLAVE *** */
6170 struct cmd_add_bonding_slave_result {
6171         cmdline_fixed_string_t add;
6172         cmdline_fixed_string_t bonding;
6173         cmdline_fixed_string_t slave;
6174         portid_t slave_id;
6175         portid_t port_id;
6176 };
6177
6178 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6179                 __rte_unused  struct cmdline *cl,
6180                 __rte_unused void *data)
6181 {
6182         struct cmd_add_bonding_slave_result *res = parsed_result;
6183         portid_t master_port_id = res->port_id;
6184         portid_t slave_port_id = res->slave_id;
6185
6186         /* add the slave for a bonded device. */
6187         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6188                 printf("\t Failed to add slave %d to master port = %d.\n",
6189                                 slave_port_id, master_port_id);
6190                 return;
6191         }
6192         init_port_config();
6193         set_port_slave_flag(slave_port_id);
6194 }
6195
6196 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6197 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6198                 add, "add");
6199 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6200 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6201                 bonding, "bonding");
6202 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6203 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6204                 slave, "slave");
6205 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6206 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6207                 slave_id, UINT16);
6208 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6209 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6210                 port_id, UINT16);
6211
6212 cmdline_parse_inst_t cmd_add_bonding_slave = {
6213                 .f = cmd_add_bonding_slave_parsed,
6214                 .help_str = "add bonding slave <slave_id> <port_id>: "
6215                         "Add a slave device to a bonded device",
6216                 .data = NULL,
6217                 .tokens = {
6218                                 (void *)&cmd_addbonding_slave_add,
6219                                 (void *)&cmd_addbonding_slave_bonding,
6220                                 (void *)&cmd_addbonding_slave_slave,
6221                                 (void *)&cmd_addbonding_slave_slaveid,
6222                                 (void *)&cmd_addbonding_slave_port,
6223                                 NULL
6224                 }
6225 };
6226
6227 /* *** REMOVE SLAVE *** */
6228 struct cmd_remove_bonding_slave_result {
6229         cmdline_fixed_string_t remove;
6230         cmdline_fixed_string_t bonding;
6231         cmdline_fixed_string_t slave;
6232         portid_t slave_id;
6233         portid_t port_id;
6234 };
6235
6236 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6237                 __rte_unused  struct cmdline *cl,
6238                 __rte_unused void *data)
6239 {
6240         struct cmd_remove_bonding_slave_result *res = parsed_result;
6241         portid_t master_port_id = res->port_id;
6242         portid_t slave_port_id = res->slave_id;
6243
6244         /* remove the slave from a bonded device. */
6245         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6246                 printf("\t Failed to remove slave %d from master port = %d.\n",
6247                                 slave_port_id, master_port_id);
6248                 return;
6249         }
6250         init_port_config();
6251         clear_port_slave_flag(slave_port_id);
6252 }
6253
6254 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6255                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6256                                 remove, "remove");
6257 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6258                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6259                                 bonding, "bonding");
6260 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6261                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6262                                 slave, "slave");
6263 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6264                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6265                                 slave_id, UINT16);
6266 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6267                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6268                                 port_id, UINT16);
6269
6270 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6271                 .f = cmd_remove_bonding_slave_parsed,
6272                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6273                         "Remove a slave device from a bonded device",
6274                 .data = NULL,
6275                 .tokens = {
6276                                 (void *)&cmd_removebonding_slave_remove,
6277                                 (void *)&cmd_removebonding_slave_bonding,
6278                                 (void *)&cmd_removebonding_slave_slave,
6279                                 (void *)&cmd_removebonding_slave_slaveid,
6280                                 (void *)&cmd_removebonding_slave_port,
6281                                 NULL
6282                 }
6283 };
6284
6285 /* *** CREATE BONDED DEVICE *** */
6286 struct cmd_create_bonded_device_result {
6287         cmdline_fixed_string_t create;
6288         cmdline_fixed_string_t bonded;
6289         cmdline_fixed_string_t device;
6290         uint8_t mode;
6291         uint8_t socket;
6292 };
6293
6294 static int bond_dev_num = 0;
6295
6296 static void cmd_create_bonded_device_parsed(void *parsed_result,
6297                 __rte_unused  struct cmdline *cl,
6298                 __rte_unused void *data)
6299 {
6300         struct cmd_create_bonded_device_result *res = parsed_result;
6301         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6302         int port_id;
6303         int ret;
6304
6305         if (test_done == 0) {
6306                 printf("Please stop forwarding first\n");
6307                 return;
6308         }
6309
6310         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6311                         bond_dev_num++);
6312
6313         /* Create a new bonded device. */
6314         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6315         if (port_id < 0) {
6316                 printf("\t Failed to create bonded device.\n");
6317                 return;
6318         } else {
6319                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6320                                 port_id);
6321
6322                 /* Update number of ports */
6323                 nb_ports = rte_eth_dev_count_avail();
6324                 reconfig(port_id, res->socket);
6325                 ret = rte_eth_promiscuous_enable(port_id);
6326                 if (ret != 0)
6327                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6328                                 port_id, rte_strerror(-ret));
6329
6330                 ports[port_id].need_setup = 0;
6331                 ports[port_id].port_status = RTE_PORT_STOPPED;
6332         }
6333
6334 }
6335
6336 cmdline_parse_token_string_t cmd_createbonded_device_create =
6337                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6338                                 create, "create");
6339 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6340                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6341                                 bonded, "bonded");
6342 cmdline_parse_token_string_t cmd_createbonded_device_device =
6343                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6344                                 device, "device");
6345 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6346                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6347                                 mode, UINT8);
6348 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6349                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6350                                 socket, UINT8);
6351
6352 cmdline_parse_inst_t cmd_create_bonded_device = {
6353                 .f = cmd_create_bonded_device_parsed,
6354                 .help_str = "create bonded device <mode> <socket>: "
6355                         "Create a new bonded device with specific bonding mode and socket",
6356                 .data = NULL,
6357                 .tokens = {
6358                                 (void *)&cmd_createbonded_device_create,
6359                                 (void *)&cmd_createbonded_device_bonded,
6360                                 (void *)&cmd_createbonded_device_device,
6361                                 (void *)&cmd_createbonded_device_mode,
6362                                 (void *)&cmd_createbonded_device_socket,
6363                                 NULL
6364                 }
6365 };
6366
6367 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6368 struct cmd_set_bond_mac_addr_result {
6369         cmdline_fixed_string_t set;
6370         cmdline_fixed_string_t bonding;
6371         cmdline_fixed_string_t mac_addr;
6372         uint16_t port_num;
6373         struct rte_ether_addr address;
6374 };
6375
6376 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6377                 __rte_unused  struct cmdline *cl,
6378                 __rte_unused void *data)
6379 {
6380         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6381         int ret;
6382
6383         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6384                 return;
6385
6386         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6387
6388         /* check the return value and print it if is < 0 */
6389         if (ret < 0)
6390                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6391 }
6392
6393 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6394                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6395 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6396                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6397                                 "bonding");
6398 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6399                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6400                                 "mac_addr");
6401 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6402                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6403                                 port_num, UINT16);
6404 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6405                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6406
6407 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6408                 .f = cmd_set_bond_mac_addr_parsed,
6409                 .data = (void *) 0,
6410                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6411                 .tokens = {
6412                                 (void *)&cmd_set_bond_mac_addr_set,
6413                                 (void *)&cmd_set_bond_mac_addr_bonding,
6414                                 (void *)&cmd_set_bond_mac_addr_mac,
6415                                 (void *)&cmd_set_bond_mac_addr_portnum,
6416                                 (void *)&cmd_set_bond_mac_addr_addr,
6417                                 NULL
6418                 }
6419 };
6420
6421
6422 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6423 struct cmd_set_bond_mon_period_result {
6424         cmdline_fixed_string_t set;
6425         cmdline_fixed_string_t bonding;
6426         cmdline_fixed_string_t mon_period;
6427         uint16_t port_num;
6428         uint32_t period_ms;
6429 };
6430
6431 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6432                 __rte_unused  struct cmdline *cl,
6433                 __rte_unused void *data)
6434 {
6435         struct cmd_set_bond_mon_period_result *res = parsed_result;
6436         int ret;
6437
6438         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6439
6440         /* check the return value and print it if is < 0 */
6441         if (ret < 0)
6442                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6443 }
6444
6445 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6446                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6447                                 set, "set");
6448 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6449                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6450                                 bonding, "bonding");
6451 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6452                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6453                                 mon_period,     "mon_period");
6454 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6455                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6456                                 port_num, UINT16);
6457 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6458                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6459                                 period_ms, UINT32);
6460
6461 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6462                 .f = cmd_set_bond_mon_period_parsed,
6463                 .data = (void *) 0,
6464                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6465                 .tokens = {
6466                                 (void *)&cmd_set_bond_mon_period_set,
6467                                 (void *)&cmd_set_bond_mon_period_bonding,
6468                                 (void *)&cmd_set_bond_mon_period_mon_period,
6469                                 (void *)&cmd_set_bond_mon_period_portnum,
6470                                 (void *)&cmd_set_bond_mon_period_period_ms,
6471                                 NULL
6472                 }
6473 };
6474
6475
6476
6477 struct cmd_set_bonding_agg_mode_policy_result {
6478         cmdline_fixed_string_t set;
6479         cmdline_fixed_string_t bonding;
6480         cmdline_fixed_string_t agg_mode;
6481         uint16_t port_num;
6482         cmdline_fixed_string_t policy;
6483 };
6484
6485
6486 static void
6487 cmd_set_bonding_agg_mode(void *parsed_result,
6488                 __rte_unused struct cmdline *cl,
6489                 __rte_unused void *data)
6490 {
6491         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6492         uint8_t policy = AGG_BANDWIDTH;
6493
6494         if (!strcmp(res->policy, "bandwidth"))
6495                 policy = AGG_BANDWIDTH;
6496         else if (!strcmp(res->policy, "stable"))
6497                 policy = AGG_STABLE;
6498         else if (!strcmp(res->policy, "count"))
6499                 policy = AGG_COUNT;
6500
6501         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6502 }
6503
6504
6505 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6506         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6507                                 set, "set");
6508 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6509         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6510                                 bonding, "bonding");
6511
6512 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6513         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6514                                 agg_mode, "agg_mode");
6515
6516 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6517         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6518                                 port_num, UINT16);
6519
6520 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6521         TOKEN_STRING_INITIALIZER(
6522                         struct cmd_set_bonding_balance_xmit_policy_result,
6523                 policy, "stable#bandwidth#count");
6524
6525 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6526         .f = cmd_set_bonding_agg_mode,
6527         .data = (void *) 0,
6528         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6529         .tokens = {
6530                         (void *)&cmd_set_bonding_agg_mode_set,
6531                         (void *)&cmd_set_bonding_agg_mode_bonding,
6532                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6533                         (void *)&cmd_set_bonding_agg_mode_portnum,
6534                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6535                         NULL
6536                 }
6537 };
6538
6539
6540 #endif /* RTE_LIBRTE_PMD_BOND */
6541
6542 /* *** SET FORWARDING MODE *** */
6543 struct cmd_set_fwd_mode_result {
6544         cmdline_fixed_string_t set;
6545         cmdline_fixed_string_t fwd;
6546         cmdline_fixed_string_t mode;
6547 };
6548
6549 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6550                                     __rte_unused struct cmdline *cl,
6551                                     __rte_unused void *data)
6552 {
6553         struct cmd_set_fwd_mode_result *res = parsed_result;
6554
6555         retry_enabled = 0;
6556         set_pkt_forwarding_mode(res->mode);
6557 }
6558
6559 cmdline_parse_token_string_t cmd_setfwd_set =
6560         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6561 cmdline_parse_token_string_t cmd_setfwd_fwd =
6562         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6563 cmdline_parse_token_string_t cmd_setfwd_mode =
6564         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6565                 "" /* defined at init */);
6566
6567 cmdline_parse_inst_t cmd_set_fwd_mode = {
6568         .f = cmd_set_fwd_mode_parsed,
6569         .data = NULL,
6570         .help_str = NULL, /* defined at init */
6571         .tokens = {
6572                 (void *)&cmd_setfwd_set,
6573                 (void *)&cmd_setfwd_fwd,
6574                 (void *)&cmd_setfwd_mode,
6575                 NULL,
6576         },
6577 };
6578
6579 static void cmd_set_fwd_mode_init(void)
6580 {
6581         char *modes, *c;
6582         static char token[128];
6583         static char help[256];
6584         cmdline_parse_token_string_t *token_struct;
6585
6586         modes = list_pkt_forwarding_modes();
6587         snprintf(help, sizeof(help), "set fwd %s: "
6588                 "Set packet forwarding mode", modes);
6589         cmd_set_fwd_mode.help_str = help;
6590
6591         /* string token separator is # */
6592         for (c = token; *modes != '\0'; modes++)
6593                 if (*modes == '|')
6594                         *c++ = '#';
6595                 else
6596                         *c++ = *modes;
6597         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6598         token_struct->string_data.str = token;
6599 }
6600
6601 /* *** SET RETRY FORWARDING MODE *** */
6602 struct cmd_set_fwd_retry_mode_result {
6603         cmdline_fixed_string_t set;
6604         cmdline_fixed_string_t fwd;
6605         cmdline_fixed_string_t mode;
6606         cmdline_fixed_string_t retry;
6607 };
6608
6609 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6610                             __rte_unused struct cmdline *cl,
6611                             __rte_unused void *data)
6612 {
6613         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6614
6615         retry_enabled = 1;
6616         set_pkt_forwarding_mode(res->mode);
6617 }
6618
6619 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6620         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6621                         set, "set");
6622 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6623         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6624                         fwd, "fwd");
6625 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6626         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6627                         mode,
6628                 "" /* defined at init */);
6629 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6630         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6631                         retry, "retry");
6632
6633 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6634         .f = cmd_set_fwd_retry_mode_parsed,
6635         .data = NULL,
6636         .help_str = NULL, /* defined at init */
6637         .tokens = {
6638                 (void *)&cmd_setfwd_retry_set,
6639                 (void *)&cmd_setfwd_retry_fwd,
6640                 (void *)&cmd_setfwd_retry_mode,
6641                 (void *)&cmd_setfwd_retry_retry,
6642                 NULL,
6643         },
6644 };
6645
6646 static void cmd_set_fwd_retry_mode_init(void)
6647 {
6648         char *modes, *c;
6649         static char token[128];
6650         static char help[256];
6651         cmdline_parse_token_string_t *token_struct;
6652
6653         modes = list_pkt_forwarding_retry_modes();
6654         snprintf(help, sizeof(help), "set fwd %s retry: "
6655                 "Set packet forwarding mode with retry", modes);
6656         cmd_set_fwd_retry_mode.help_str = help;
6657
6658         /* string token separator is # */
6659         for (c = token; *modes != '\0'; modes++)
6660                 if (*modes == '|')
6661                         *c++ = '#';
6662                 else
6663                         *c++ = *modes;
6664         token_struct = (cmdline_parse_token_string_t *)
6665                 cmd_set_fwd_retry_mode.tokens[2];
6666         token_struct->string_data.str = token;
6667 }
6668
6669 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6670 struct cmd_set_burst_tx_retry_result {
6671         cmdline_fixed_string_t set;
6672         cmdline_fixed_string_t burst;
6673         cmdline_fixed_string_t tx;
6674         cmdline_fixed_string_t delay;
6675         uint32_t time;
6676         cmdline_fixed_string_t retry;
6677         uint32_t retry_num;
6678 };
6679
6680 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6681                                         __rte_unused struct cmdline *cl,
6682                                         __rte_unused void *data)
6683 {
6684         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6685
6686         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6687                 && !strcmp(res->tx, "tx")) {
6688                 if (!strcmp(res->delay, "delay"))
6689                         burst_tx_delay_time = res->time;
6690                 if (!strcmp(res->retry, "retry"))
6691                         burst_tx_retry_num = res->retry_num;
6692         }
6693
6694 }
6695
6696 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6697         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6698 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6699         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6700                                  "burst");
6701 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6702         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6703 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6704         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6705 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6706         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6707 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6708         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6709 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6710         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6711
6712 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6713         .f = cmd_set_burst_tx_retry_parsed,
6714         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6715         .tokens = {
6716                 (void *)&cmd_set_burst_tx_retry_set,
6717                 (void *)&cmd_set_burst_tx_retry_burst,
6718                 (void *)&cmd_set_burst_tx_retry_tx,
6719                 (void *)&cmd_set_burst_tx_retry_delay,
6720                 (void *)&cmd_set_burst_tx_retry_time,
6721                 (void *)&cmd_set_burst_tx_retry_retry,
6722                 (void *)&cmd_set_burst_tx_retry_retry_num,
6723                 NULL,
6724         },
6725 };
6726
6727 /* *** SET PROMISC MODE *** */
6728 struct cmd_set_promisc_mode_result {
6729         cmdline_fixed_string_t set;
6730         cmdline_fixed_string_t promisc;
6731         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6732         uint16_t port_num;               /* valid if "allports" argument == 0 */
6733         cmdline_fixed_string_t mode;
6734 };
6735
6736 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6737                                         __rte_unused struct cmdline *cl,
6738                                         void *allports)
6739 {
6740         struct cmd_set_promisc_mode_result *res = parsed_result;
6741         int enable;
6742         portid_t i;
6743
6744         if (!strcmp(res->mode, "on"))
6745                 enable = 1;
6746         else
6747                 enable = 0;
6748
6749         /* all ports */
6750         if (allports) {
6751                 RTE_ETH_FOREACH_DEV(i)
6752                         eth_set_promisc_mode(i, enable);
6753         } else {
6754                 eth_set_promisc_mode(res->port_num, enable);
6755         }
6756 }
6757
6758 cmdline_parse_token_string_t cmd_setpromisc_set =
6759         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6760 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6761         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6762                                  "promisc");
6763 cmdline_parse_token_string_t cmd_setpromisc_portall =
6764         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6765                                  "all");
6766 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6767         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6768                               UINT16);
6769 cmdline_parse_token_string_t cmd_setpromisc_mode =
6770         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6771                                  "on#off");
6772
6773 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6774         .f = cmd_set_promisc_mode_parsed,
6775         .data = (void *)1,
6776         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6777         .tokens = {
6778                 (void *)&cmd_setpromisc_set,
6779                 (void *)&cmd_setpromisc_promisc,
6780                 (void *)&cmd_setpromisc_portall,
6781                 (void *)&cmd_setpromisc_mode,
6782                 NULL,
6783         },
6784 };
6785
6786 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6787         .f = cmd_set_promisc_mode_parsed,
6788         .data = (void *)0,
6789         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6790         .tokens = {
6791                 (void *)&cmd_setpromisc_set,
6792                 (void *)&cmd_setpromisc_promisc,
6793                 (void *)&cmd_setpromisc_portnum,
6794                 (void *)&cmd_setpromisc_mode,
6795                 NULL,
6796         },
6797 };
6798
6799 /* *** SET ALLMULTI MODE *** */
6800 struct cmd_set_allmulti_mode_result {
6801         cmdline_fixed_string_t set;
6802         cmdline_fixed_string_t allmulti;
6803         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6804         uint16_t port_num;               /* valid if "allports" argument == 0 */
6805         cmdline_fixed_string_t mode;
6806 };
6807
6808 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6809                                         __rte_unused struct cmdline *cl,
6810                                         void *allports)
6811 {
6812         struct cmd_set_allmulti_mode_result *res = parsed_result;
6813         int enable;
6814         portid_t i;
6815
6816         if (!strcmp(res->mode, "on"))
6817                 enable = 1;
6818         else
6819                 enable = 0;
6820
6821         /* all ports */
6822         if (allports) {
6823                 RTE_ETH_FOREACH_DEV(i) {
6824                         eth_set_allmulticast_mode(i, enable);
6825                 }
6826         }
6827         else {
6828                 eth_set_allmulticast_mode(res->port_num, enable);
6829         }
6830 }
6831
6832 cmdline_parse_token_string_t cmd_setallmulti_set =
6833         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6834 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6835         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6836                                  "allmulti");
6837 cmdline_parse_token_string_t cmd_setallmulti_portall =
6838         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6839                                  "all");
6840 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6841         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6842                               UINT16);
6843 cmdline_parse_token_string_t cmd_setallmulti_mode =
6844         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6845                                  "on#off");
6846
6847 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6848         .f = cmd_set_allmulti_mode_parsed,
6849         .data = (void *)1,
6850         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6851         .tokens = {
6852                 (void *)&cmd_setallmulti_set,
6853                 (void *)&cmd_setallmulti_allmulti,
6854                 (void *)&cmd_setallmulti_portall,
6855                 (void *)&cmd_setallmulti_mode,
6856                 NULL,
6857         },
6858 };
6859
6860 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6861         .f = cmd_set_allmulti_mode_parsed,
6862         .data = (void *)0,
6863         .help_str = "set allmulti <port_id> on|off: "
6864                 "Set allmulti mode on port_id",
6865         .tokens = {
6866                 (void *)&cmd_setallmulti_set,
6867                 (void *)&cmd_setallmulti_allmulti,
6868                 (void *)&cmd_setallmulti_portnum,
6869                 (void *)&cmd_setallmulti_mode,
6870                 NULL,
6871         },
6872 };
6873
6874 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6875 struct cmd_link_flow_ctrl_set_result {
6876         cmdline_fixed_string_t set;
6877         cmdline_fixed_string_t flow_ctrl;
6878         cmdline_fixed_string_t rx;
6879         cmdline_fixed_string_t rx_lfc_mode;
6880         cmdline_fixed_string_t tx;
6881         cmdline_fixed_string_t tx_lfc_mode;
6882         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6883         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6884         cmdline_fixed_string_t autoneg_str;
6885         cmdline_fixed_string_t autoneg;
6886         cmdline_fixed_string_t hw_str;
6887         uint32_t high_water;
6888         cmdline_fixed_string_t lw_str;
6889         uint32_t low_water;
6890         cmdline_fixed_string_t pt_str;
6891         uint16_t pause_time;
6892         cmdline_fixed_string_t xon_str;
6893         uint16_t send_xon;
6894         portid_t port_id;
6895 };
6896
6897 cmdline_parse_token_string_t cmd_lfc_set_set =
6898         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6899                                 set, "set");
6900 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6901         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6902                                 flow_ctrl, "flow_ctrl");
6903 cmdline_parse_token_string_t cmd_lfc_set_rx =
6904         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6905                                 rx, "rx");
6906 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6907         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6908                                 rx_lfc_mode, "on#off");
6909 cmdline_parse_token_string_t cmd_lfc_set_tx =
6910         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6911                                 tx, "tx");
6912 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6913         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6914                                 tx_lfc_mode, "on#off");
6915 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6916         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6917                                 hw_str, "high_water");
6918 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6919         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6920                                 high_water, UINT32);
6921 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6922         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6923                                 lw_str, "low_water");
6924 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6925         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6926                                 low_water, UINT32);
6927 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6928         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6929                                 pt_str, "pause_time");
6930 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6931         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6932                                 pause_time, UINT16);
6933 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6934         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6935                                 xon_str, "send_xon");
6936 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6937         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6938                                 send_xon, UINT16);
6939 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6940         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6941                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6942 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6943         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6944                                 mac_ctrl_frame_fwd_mode, "on#off");
6945 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6946         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6947                                 autoneg_str, "autoneg");
6948 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6949         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6950                                 autoneg, "on#off");
6951 cmdline_parse_token_num_t cmd_lfc_set_portid =
6952         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6953                                 port_id, UINT16);
6954
6955 /* forward declaration */
6956 static void
6957 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6958                               void *data);
6959
6960 cmdline_parse_inst_t cmd_link_flow_control_set = {
6961         .f = cmd_link_flow_ctrl_set_parsed,
6962         .data = NULL,
6963         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6964                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6965                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6966         .tokens = {
6967                 (void *)&cmd_lfc_set_set,
6968                 (void *)&cmd_lfc_set_flow_ctrl,
6969                 (void *)&cmd_lfc_set_rx,
6970                 (void *)&cmd_lfc_set_rx_mode,
6971                 (void *)&cmd_lfc_set_tx,
6972                 (void *)&cmd_lfc_set_tx_mode,
6973                 (void *)&cmd_lfc_set_high_water,
6974                 (void *)&cmd_lfc_set_low_water,
6975                 (void *)&cmd_lfc_set_pause_time,
6976                 (void *)&cmd_lfc_set_send_xon,
6977                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6978                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6979                 (void *)&cmd_lfc_set_autoneg_str,
6980                 (void *)&cmd_lfc_set_autoneg,
6981                 (void *)&cmd_lfc_set_portid,
6982                 NULL,
6983         },
6984 };
6985
6986 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6987         .f = cmd_link_flow_ctrl_set_parsed,
6988         .data = (void *)&cmd_link_flow_control_set_rx,
6989         .help_str = "set flow_ctrl rx on|off <port_id>: "
6990                 "Change rx flow control parameter",
6991         .tokens = {
6992                 (void *)&cmd_lfc_set_set,
6993                 (void *)&cmd_lfc_set_flow_ctrl,
6994                 (void *)&cmd_lfc_set_rx,
6995                 (void *)&cmd_lfc_set_rx_mode,
6996                 (void *)&cmd_lfc_set_portid,
6997                 NULL,
6998         },
6999 };
7000
7001 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7002         .f = cmd_link_flow_ctrl_set_parsed,
7003         .data = (void *)&cmd_link_flow_control_set_tx,
7004         .help_str = "set flow_ctrl tx on|off <port_id>: "
7005                 "Change tx flow control parameter",
7006         .tokens = {
7007                 (void *)&cmd_lfc_set_set,
7008                 (void *)&cmd_lfc_set_flow_ctrl,
7009                 (void *)&cmd_lfc_set_tx,
7010                 (void *)&cmd_lfc_set_tx_mode,
7011                 (void *)&cmd_lfc_set_portid,
7012                 NULL,
7013         },
7014 };
7015
7016 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7017         .f = cmd_link_flow_ctrl_set_parsed,
7018         .data = (void *)&cmd_link_flow_control_set_hw,
7019         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7020                 "Change high water flow control parameter",
7021         .tokens = {
7022                 (void *)&cmd_lfc_set_set,
7023                 (void *)&cmd_lfc_set_flow_ctrl,
7024                 (void *)&cmd_lfc_set_high_water_str,
7025                 (void *)&cmd_lfc_set_high_water,
7026                 (void *)&cmd_lfc_set_portid,
7027                 NULL,
7028         },
7029 };
7030
7031 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7032         .f = cmd_link_flow_ctrl_set_parsed,
7033         .data = (void *)&cmd_link_flow_control_set_lw,
7034         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7035                 "Change low water flow control parameter",
7036         .tokens = {
7037                 (void *)&cmd_lfc_set_set,
7038                 (void *)&cmd_lfc_set_flow_ctrl,
7039                 (void *)&cmd_lfc_set_low_water_str,
7040                 (void *)&cmd_lfc_set_low_water,
7041                 (void *)&cmd_lfc_set_portid,
7042                 NULL,
7043         },
7044 };
7045
7046 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7047         .f = cmd_link_flow_ctrl_set_parsed,
7048         .data = (void *)&cmd_link_flow_control_set_pt,
7049         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7050                 "Change pause time flow control parameter",
7051         .tokens = {
7052                 (void *)&cmd_lfc_set_set,
7053                 (void *)&cmd_lfc_set_flow_ctrl,
7054                 (void *)&cmd_lfc_set_pause_time_str,
7055                 (void *)&cmd_lfc_set_pause_time,
7056                 (void *)&cmd_lfc_set_portid,
7057                 NULL,
7058         },
7059 };
7060
7061 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7062         .f = cmd_link_flow_ctrl_set_parsed,
7063         .data = (void *)&cmd_link_flow_control_set_xon,
7064         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7065                 "Change send_xon flow control parameter",
7066         .tokens = {
7067                 (void *)&cmd_lfc_set_set,
7068                 (void *)&cmd_lfc_set_flow_ctrl,
7069                 (void *)&cmd_lfc_set_send_xon_str,
7070                 (void *)&cmd_lfc_set_send_xon,
7071                 (void *)&cmd_lfc_set_portid,
7072                 NULL,
7073         },
7074 };
7075
7076 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7077         .f = cmd_link_flow_ctrl_set_parsed,
7078         .data = (void *)&cmd_link_flow_control_set_macfwd,
7079         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7080                 "Change mac ctrl fwd flow control parameter",
7081         .tokens = {
7082                 (void *)&cmd_lfc_set_set,
7083                 (void *)&cmd_lfc_set_flow_ctrl,
7084                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7085                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7086                 (void *)&cmd_lfc_set_portid,
7087                 NULL,
7088         },
7089 };
7090
7091 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7092         .f = cmd_link_flow_ctrl_set_parsed,
7093         .data = (void *)&cmd_link_flow_control_set_autoneg,
7094         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7095                 "Change autoneg flow control parameter",
7096         .tokens = {
7097                 (void *)&cmd_lfc_set_set,
7098                 (void *)&cmd_lfc_set_flow_ctrl,
7099                 (void *)&cmd_lfc_set_autoneg_str,
7100                 (void *)&cmd_lfc_set_autoneg,
7101                 (void *)&cmd_lfc_set_portid,
7102                 NULL,
7103         },
7104 };
7105
7106 static void
7107 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7108                               __rte_unused struct cmdline *cl,
7109                               void *data)
7110 {
7111         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7112         cmdline_parse_inst_t *cmd = data;
7113         struct rte_eth_fc_conf fc_conf;
7114         int rx_fc_en = 0;
7115         int tx_fc_en = 0;
7116         int ret;
7117
7118         /*
7119          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7120          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7121          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7122          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7123          */
7124         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7125                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7126         };
7127
7128         /* Partial command line, retrieve current configuration */
7129         if (cmd) {
7130                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7131                 if (ret != 0) {
7132                         printf("cannot get current flow ctrl parameters, return"
7133                                "code = %d\n", ret);
7134                         return;
7135                 }
7136
7137                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7138                     (fc_conf.mode == RTE_FC_FULL))
7139                         rx_fc_en = 1;
7140                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7141                     (fc_conf.mode == RTE_FC_FULL))
7142                         tx_fc_en = 1;
7143         }
7144
7145         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7146                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7147
7148         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7149                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7150
7151         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7152
7153         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7154                 fc_conf.high_water = res->high_water;
7155
7156         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7157                 fc_conf.low_water = res->low_water;
7158
7159         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7160                 fc_conf.pause_time = res->pause_time;
7161
7162         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7163                 fc_conf.send_xon = res->send_xon;
7164
7165         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7166                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7167                         fc_conf.mac_ctrl_frame_fwd = 1;
7168                 else
7169                         fc_conf.mac_ctrl_frame_fwd = 0;
7170         }
7171
7172         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7173                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7174
7175         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7176         if (ret != 0)
7177                 printf("bad flow contrl parameter, return code = %d \n", ret);
7178 }
7179
7180 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7181 struct cmd_priority_flow_ctrl_set_result {
7182         cmdline_fixed_string_t set;
7183         cmdline_fixed_string_t pfc_ctrl;
7184         cmdline_fixed_string_t rx;
7185         cmdline_fixed_string_t rx_pfc_mode;
7186         cmdline_fixed_string_t tx;
7187         cmdline_fixed_string_t tx_pfc_mode;
7188         uint32_t high_water;
7189         uint32_t low_water;
7190         uint16_t pause_time;
7191         uint8_t  priority;
7192         portid_t port_id;
7193 };
7194
7195 static void
7196 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7197                        __rte_unused struct cmdline *cl,
7198                        __rte_unused void *data)
7199 {
7200         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7201         struct rte_eth_pfc_conf pfc_conf;
7202         int rx_fc_enable, tx_fc_enable;
7203         int ret;
7204
7205         /*
7206          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7207          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7208          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7209          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7210          */
7211         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7212                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7213         };
7214
7215         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7216         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7217         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7218         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7219         pfc_conf.fc.high_water = res->high_water;
7220         pfc_conf.fc.low_water  = res->low_water;
7221         pfc_conf.fc.pause_time = res->pause_time;
7222         pfc_conf.priority      = res->priority;
7223
7224         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7225         if (ret != 0)
7226                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7227 }
7228
7229 cmdline_parse_token_string_t cmd_pfc_set_set =
7230         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7231                                 set, "set");
7232 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7233         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7234                                 pfc_ctrl, "pfc_ctrl");
7235 cmdline_parse_token_string_t cmd_pfc_set_rx =
7236         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7237                                 rx, "rx");
7238 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7239         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7240                                 rx_pfc_mode, "on#off");
7241 cmdline_parse_token_string_t cmd_pfc_set_tx =
7242         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7243                                 tx, "tx");
7244 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7245         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7246                                 tx_pfc_mode, "on#off");
7247 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7248         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7249                                 high_water, UINT32);
7250 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7251         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7252                                 low_water, UINT32);
7253 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7254         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7255                                 pause_time, UINT16);
7256 cmdline_parse_token_num_t cmd_pfc_set_priority =
7257         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7258                                 priority, UINT8);
7259 cmdline_parse_token_num_t cmd_pfc_set_portid =
7260         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7261                                 port_id, UINT16);
7262
7263 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7264         .f = cmd_priority_flow_ctrl_set_parsed,
7265         .data = NULL,
7266         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7267                 "<pause_time> <priority> <port_id>: "
7268                 "Configure the Ethernet priority flow control",
7269         .tokens = {
7270                 (void *)&cmd_pfc_set_set,
7271                 (void *)&cmd_pfc_set_flow_ctrl,
7272                 (void *)&cmd_pfc_set_rx,
7273                 (void *)&cmd_pfc_set_rx_mode,
7274                 (void *)&cmd_pfc_set_tx,
7275                 (void *)&cmd_pfc_set_tx_mode,
7276                 (void *)&cmd_pfc_set_high_water,
7277                 (void *)&cmd_pfc_set_low_water,
7278                 (void *)&cmd_pfc_set_pause_time,
7279                 (void *)&cmd_pfc_set_priority,
7280                 (void *)&cmd_pfc_set_portid,
7281                 NULL,
7282         },
7283 };
7284
7285 /* *** RESET CONFIGURATION *** */
7286 struct cmd_reset_result {
7287         cmdline_fixed_string_t reset;
7288         cmdline_fixed_string_t def;
7289 };
7290
7291 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7292                              struct cmdline *cl,
7293                              __rte_unused void *data)
7294 {
7295         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7296         set_def_fwd_config();
7297 }
7298
7299 cmdline_parse_token_string_t cmd_reset_set =
7300         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7301 cmdline_parse_token_string_t cmd_reset_def =
7302         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7303                                  "default");
7304
7305 cmdline_parse_inst_t cmd_reset = {
7306         .f = cmd_reset_parsed,
7307         .data = NULL,
7308         .help_str = "set default: Reset default forwarding configuration",
7309         .tokens = {
7310                 (void *)&cmd_reset_set,
7311                 (void *)&cmd_reset_def,
7312                 NULL,
7313         },
7314 };
7315
7316 /* *** START FORWARDING *** */
7317 struct cmd_start_result {
7318         cmdline_fixed_string_t start;
7319 };
7320
7321 cmdline_parse_token_string_t cmd_start_start =
7322         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7323
7324 static void cmd_start_parsed(__rte_unused void *parsed_result,
7325                              __rte_unused struct cmdline *cl,
7326                              __rte_unused void *data)
7327 {
7328         start_packet_forwarding(0);
7329 }
7330
7331 cmdline_parse_inst_t cmd_start = {
7332         .f = cmd_start_parsed,
7333         .data = NULL,
7334         .help_str = "start: Start packet forwarding",
7335         .tokens = {
7336                 (void *)&cmd_start_start,
7337                 NULL,
7338         },
7339 };
7340
7341 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7342 struct cmd_start_tx_first_result {
7343         cmdline_fixed_string_t start;
7344         cmdline_fixed_string_t tx_first;
7345 };
7346
7347 static void
7348 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7349                           __rte_unused struct cmdline *cl,
7350                           __rte_unused void *data)
7351 {
7352         start_packet_forwarding(1);
7353 }
7354
7355 cmdline_parse_token_string_t cmd_start_tx_first_start =
7356         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7357                                  "start");
7358 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7359         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7360                                  tx_first, "tx_first");
7361
7362 cmdline_parse_inst_t cmd_start_tx_first = {
7363         .f = cmd_start_tx_first_parsed,
7364         .data = NULL,
7365         .help_str = "start tx_first: Start packet forwarding, "
7366                 "after sending 1 burst of packets",
7367         .tokens = {
7368                 (void *)&cmd_start_tx_first_start,
7369                 (void *)&cmd_start_tx_first_tx_first,
7370                 NULL,
7371         },
7372 };
7373
7374 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7375 struct cmd_start_tx_first_n_result {
7376         cmdline_fixed_string_t start;
7377         cmdline_fixed_string_t tx_first;
7378         uint32_t tx_num;
7379 };
7380
7381 static void
7382 cmd_start_tx_first_n_parsed(void *parsed_result,
7383                           __rte_unused struct cmdline *cl,
7384                           __rte_unused void *data)
7385 {
7386         struct cmd_start_tx_first_n_result *res = parsed_result;
7387
7388         start_packet_forwarding(res->tx_num);
7389 }
7390
7391 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7392         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7393                         start, "start");
7394 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7395         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7396                         tx_first, "tx_first");
7397 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7398         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7399                         tx_num, UINT32);
7400
7401 cmdline_parse_inst_t cmd_start_tx_first_n = {
7402         .f = cmd_start_tx_first_n_parsed,
7403         .data = NULL,
7404         .help_str = "start tx_first <num>: "
7405                 "packet forwarding, after sending <num> bursts of packets",
7406         .tokens = {
7407                 (void *)&cmd_start_tx_first_n_start,
7408                 (void *)&cmd_start_tx_first_n_tx_first,
7409                 (void *)&cmd_start_tx_first_n_tx_num,
7410                 NULL,
7411         },
7412 };
7413
7414 /* *** SET LINK UP *** */
7415 struct cmd_set_link_up_result {
7416         cmdline_fixed_string_t set;
7417         cmdline_fixed_string_t link_up;
7418         cmdline_fixed_string_t port;
7419         portid_t port_id;
7420 };
7421
7422 cmdline_parse_token_string_t cmd_set_link_up_set =
7423         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7424 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7425         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7426                                 "link-up");
7427 cmdline_parse_token_string_t cmd_set_link_up_port =
7428         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7429 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7430         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7431
7432 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7433                              __rte_unused struct cmdline *cl,
7434                              __rte_unused void *data)
7435 {
7436         struct cmd_set_link_up_result *res = parsed_result;
7437         dev_set_link_up(res->port_id);
7438 }
7439
7440 cmdline_parse_inst_t cmd_set_link_up = {
7441         .f = cmd_set_link_up_parsed,
7442         .data = NULL,
7443         .help_str = "set link-up port <port id>",
7444         .tokens = {
7445                 (void *)&cmd_set_link_up_set,
7446                 (void *)&cmd_set_link_up_link_up,
7447                 (void *)&cmd_set_link_up_port,
7448                 (void *)&cmd_set_link_up_port_id,
7449                 NULL,
7450         },
7451 };
7452
7453 /* *** SET LINK DOWN *** */
7454 struct cmd_set_link_down_result {
7455         cmdline_fixed_string_t set;
7456         cmdline_fixed_string_t link_down;
7457         cmdline_fixed_string_t port;
7458         portid_t port_id;
7459 };
7460
7461 cmdline_parse_token_string_t cmd_set_link_down_set =
7462         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7463 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7464         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7465                                 "link-down");
7466 cmdline_parse_token_string_t cmd_set_link_down_port =
7467         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7468 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7469         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7470
7471 static void cmd_set_link_down_parsed(
7472                                 __rte_unused void *parsed_result,
7473                                 __rte_unused struct cmdline *cl,
7474                                 __rte_unused void *data)
7475 {
7476         struct cmd_set_link_down_result *res = parsed_result;
7477         dev_set_link_down(res->port_id);
7478 }
7479
7480 cmdline_parse_inst_t cmd_set_link_down = {
7481         .f = cmd_set_link_down_parsed,
7482         .data = NULL,
7483         .help_str = "set link-down port <port id>",
7484         .tokens = {
7485                 (void *)&cmd_set_link_down_set,
7486                 (void *)&cmd_set_link_down_link_down,
7487                 (void *)&cmd_set_link_down_port,
7488                 (void *)&cmd_set_link_down_port_id,
7489                 NULL,
7490         },
7491 };
7492
7493 /* *** SHOW CFG *** */
7494 struct cmd_showcfg_result {
7495         cmdline_fixed_string_t show;
7496         cmdline_fixed_string_t cfg;
7497         cmdline_fixed_string_t what;
7498 };
7499
7500 static void cmd_showcfg_parsed(void *parsed_result,
7501                                __rte_unused struct cmdline *cl,
7502                                __rte_unused void *data)
7503 {
7504         struct cmd_showcfg_result *res = parsed_result;
7505         if (!strcmp(res->what, "rxtx"))
7506                 rxtx_config_display();
7507         else if (!strcmp(res->what, "cores"))
7508                 fwd_lcores_config_display();
7509         else if (!strcmp(res->what, "fwd"))
7510                 pkt_fwd_config_display(&cur_fwd_config);
7511         else if (!strcmp(res->what, "txpkts"))
7512                 show_tx_pkt_segments();
7513         else if (!strcmp(res->what, "txtimes"))
7514                 show_tx_pkt_times();
7515 }
7516
7517 cmdline_parse_token_string_t cmd_showcfg_show =
7518         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7519 cmdline_parse_token_string_t cmd_showcfg_port =
7520         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7521 cmdline_parse_token_string_t cmd_showcfg_what =
7522         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7523                                  "rxtx#cores#fwd#txpkts#txtimes");
7524
7525 cmdline_parse_inst_t cmd_showcfg = {
7526         .f = cmd_showcfg_parsed,
7527         .data = NULL,
7528         .help_str = "show config rxtx|cores|fwd|txpkts|txtimes",
7529         .tokens = {
7530                 (void *)&cmd_showcfg_show,
7531                 (void *)&cmd_showcfg_port,
7532                 (void *)&cmd_showcfg_what,
7533                 NULL,
7534         },
7535 };
7536
7537 /* *** SHOW ALL PORT INFO *** */
7538 struct cmd_showportall_result {
7539         cmdline_fixed_string_t show;
7540         cmdline_fixed_string_t port;
7541         cmdline_fixed_string_t what;
7542         cmdline_fixed_string_t all;
7543 };
7544
7545 static void cmd_showportall_parsed(void *parsed_result,
7546                                 __rte_unused struct cmdline *cl,
7547                                 __rte_unused void *data)
7548 {
7549         portid_t i;
7550
7551         struct cmd_showportall_result *res = parsed_result;
7552         if (!strcmp(res->show, "clear")) {
7553                 if (!strcmp(res->what, "stats"))
7554                         RTE_ETH_FOREACH_DEV(i)
7555                                 nic_stats_clear(i);
7556                 else if (!strcmp(res->what, "xstats"))
7557                         RTE_ETH_FOREACH_DEV(i)
7558                                 nic_xstats_clear(i);
7559         } else if (!strcmp(res->what, "info"))
7560                 RTE_ETH_FOREACH_DEV(i)
7561                         port_infos_display(i);
7562         else if (!strcmp(res->what, "summary")) {
7563                 port_summary_header_display();
7564                 RTE_ETH_FOREACH_DEV(i)
7565                         port_summary_display(i);
7566         }
7567         else if (!strcmp(res->what, "stats"))
7568                 RTE_ETH_FOREACH_DEV(i)
7569                         nic_stats_display(i);
7570         else if (!strcmp(res->what, "xstats"))
7571                 RTE_ETH_FOREACH_DEV(i)
7572                         nic_xstats_display(i);
7573         else if (!strcmp(res->what, "fdir"))
7574                 RTE_ETH_FOREACH_DEV(i)
7575                         fdir_get_infos(i);
7576         else if (!strcmp(res->what, "stat_qmap"))
7577                 RTE_ETH_FOREACH_DEV(i)
7578                         nic_stats_mapping_display(i);
7579         else if (!strcmp(res->what, "dcb_tc"))
7580                 RTE_ETH_FOREACH_DEV(i)
7581                         port_dcb_info_display(i);
7582         else if (!strcmp(res->what, "cap"))
7583                 RTE_ETH_FOREACH_DEV(i)
7584                         port_offload_cap_display(i);
7585 }
7586
7587 cmdline_parse_token_string_t cmd_showportall_show =
7588         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7589                                  "show#clear");
7590 cmdline_parse_token_string_t cmd_showportall_port =
7591         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7592 cmdline_parse_token_string_t cmd_showportall_what =
7593         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7594                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7595 cmdline_parse_token_string_t cmd_showportall_all =
7596         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7597 cmdline_parse_inst_t cmd_showportall = {
7598         .f = cmd_showportall_parsed,
7599         .data = NULL,
7600         .help_str = "show|clear port "
7601                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7602         .tokens = {
7603                 (void *)&cmd_showportall_show,
7604                 (void *)&cmd_showportall_port,
7605                 (void *)&cmd_showportall_what,
7606                 (void *)&cmd_showportall_all,
7607                 NULL,
7608         },
7609 };
7610
7611 /* *** SHOW PORT INFO *** */
7612 struct cmd_showport_result {
7613         cmdline_fixed_string_t show;
7614         cmdline_fixed_string_t port;
7615         cmdline_fixed_string_t what;
7616         uint16_t portnum;
7617 };
7618
7619 static void cmd_showport_parsed(void *parsed_result,
7620                                 __rte_unused struct cmdline *cl,
7621                                 __rte_unused void *data)
7622 {
7623         struct cmd_showport_result *res = parsed_result;
7624         if (!strcmp(res->show, "clear")) {
7625                 if (!strcmp(res->what, "stats"))
7626                         nic_stats_clear(res->portnum);
7627                 else if (!strcmp(res->what, "xstats"))
7628                         nic_xstats_clear(res->portnum);
7629         } else if (!strcmp(res->what, "info"))
7630                 port_infos_display(res->portnum);
7631         else if (!strcmp(res->what, "summary")) {
7632                 port_summary_header_display();
7633                 port_summary_display(res->portnum);
7634         }
7635         else if (!strcmp(res->what, "stats"))
7636                 nic_stats_display(res->portnum);
7637         else if (!strcmp(res->what, "xstats"))
7638                 nic_xstats_display(res->portnum);
7639         else if (!strcmp(res->what, "fdir"))
7640                  fdir_get_infos(res->portnum);
7641         else if (!strcmp(res->what, "stat_qmap"))
7642                 nic_stats_mapping_display(res->portnum);
7643         else if (!strcmp(res->what, "dcb_tc"))
7644                 port_dcb_info_display(res->portnum);
7645         else if (!strcmp(res->what, "cap"))
7646                 port_offload_cap_display(res->portnum);
7647 }
7648
7649 cmdline_parse_token_string_t cmd_showport_show =
7650         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7651                                  "show#clear");
7652 cmdline_parse_token_string_t cmd_showport_port =
7653         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7654 cmdline_parse_token_string_t cmd_showport_what =
7655         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7656                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7657 cmdline_parse_token_num_t cmd_showport_portnum =
7658         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7659
7660 cmdline_parse_inst_t cmd_showport = {
7661         .f = cmd_showport_parsed,
7662         .data = NULL,
7663         .help_str = "show|clear port "
7664                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7665                 "<port_id>",
7666         .tokens = {
7667                 (void *)&cmd_showport_show,
7668                 (void *)&cmd_showport_port,
7669                 (void *)&cmd_showport_what,
7670                 (void *)&cmd_showport_portnum,
7671                 NULL,
7672         },
7673 };
7674
7675 /* *** SHOW DEVICE INFO *** */
7676 struct cmd_showdevice_result {
7677         cmdline_fixed_string_t show;
7678         cmdline_fixed_string_t device;
7679         cmdline_fixed_string_t what;
7680         cmdline_fixed_string_t identifier;
7681 };
7682
7683 static void cmd_showdevice_parsed(void *parsed_result,
7684                                 __rte_unused struct cmdline *cl,
7685                                 __rte_unused void *data)
7686 {
7687         struct cmd_showdevice_result *res = parsed_result;
7688         if (!strcmp(res->what, "info")) {
7689                 if (!strcmp(res->identifier, "all"))
7690                         device_infos_display(NULL);
7691                 else
7692                         device_infos_display(res->identifier);
7693         }
7694 }
7695
7696 cmdline_parse_token_string_t cmd_showdevice_show =
7697         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7698                                  "show");
7699 cmdline_parse_token_string_t cmd_showdevice_device =
7700         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7701 cmdline_parse_token_string_t cmd_showdevice_what =
7702         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7703                                  "info");
7704 cmdline_parse_token_string_t cmd_showdevice_identifier =
7705         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7706                         identifier, NULL);
7707
7708 cmdline_parse_inst_t cmd_showdevice = {
7709         .f = cmd_showdevice_parsed,
7710         .data = NULL,
7711         .help_str = "show device info <identifier>|all",
7712         .tokens = {
7713                 (void *)&cmd_showdevice_show,
7714                 (void *)&cmd_showdevice_device,
7715                 (void *)&cmd_showdevice_what,
7716                 (void *)&cmd_showdevice_identifier,
7717                 NULL,
7718         },
7719 };
7720
7721 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7722 struct cmd_showeeprom_result {
7723         cmdline_fixed_string_t show;
7724         cmdline_fixed_string_t port;
7725         uint16_t portnum;
7726         cmdline_fixed_string_t type;
7727 };
7728
7729 static void cmd_showeeprom_parsed(void *parsed_result,
7730                 __rte_unused struct cmdline *cl,
7731                 __rte_unused void *data)
7732 {
7733         struct cmd_showeeprom_result *res = parsed_result;
7734
7735         if (!strcmp(res->type, "eeprom"))
7736                 port_eeprom_display(res->portnum);
7737         else if (!strcmp(res->type, "module_eeprom"))
7738                 port_module_eeprom_display(res->portnum);
7739         else
7740                 printf("Unknown argument\n");
7741 }
7742
7743 cmdline_parse_token_string_t cmd_showeeprom_show =
7744         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7745 cmdline_parse_token_string_t cmd_showeeprom_port =
7746         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7747 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7748         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7749 cmdline_parse_token_string_t cmd_showeeprom_type =
7750         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7751
7752 cmdline_parse_inst_t cmd_showeeprom = {
7753         .f = cmd_showeeprom_parsed,
7754         .data = NULL,
7755         .help_str = "show port <port_id> module_eeprom|eeprom",
7756         .tokens = {
7757                 (void *)&cmd_showeeprom_show,
7758                 (void *)&cmd_showeeprom_port,
7759                 (void *)&cmd_showeeprom_portnum,
7760                 (void *)&cmd_showeeprom_type,
7761                 NULL,
7762         },
7763 };
7764
7765 /* *** SHOW QUEUE INFO *** */
7766 struct cmd_showqueue_result {
7767         cmdline_fixed_string_t show;
7768         cmdline_fixed_string_t type;
7769         cmdline_fixed_string_t what;
7770         uint16_t portnum;
7771         uint16_t queuenum;
7772 };
7773
7774 static void
7775 cmd_showqueue_parsed(void *parsed_result,
7776         __rte_unused struct cmdline *cl,
7777         __rte_unused void *data)
7778 {
7779         struct cmd_showqueue_result *res = parsed_result;
7780
7781         if (!strcmp(res->type, "rxq"))
7782                 rx_queue_infos_display(res->portnum, res->queuenum);
7783         else if (!strcmp(res->type, "txq"))
7784                 tx_queue_infos_display(res->portnum, res->queuenum);
7785 }
7786
7787 cmdline_parse_token_string_t cmd_showqueue_show =
7788         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7789 cmdline_parse_token_string_t cmd_showqueue_type =
7790         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7791 cmdline_parse_token_string_t cmd_showqueue_what =
7792         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7793 cmdline_parse_token_num_t cmd_showqueue_portnum =
7794         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7795 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7796         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7797
7798 cmdline_parse_inst_t cmd_showqueue = {
7799         .f = cmd_showqueue_parsed,
7800         .data = NULL,
7801         .help_str = "show rxq|txq info <port_id> <queue_id>",
7802         .tokens = {
7803                 (void *)&cmd_showqueue_show,
7804                 (void *)&cmd_showqueue_type,
7805                 (void *)&cmd_showqueue_what,
7806                 (void *)&cmd_showqueue_portnum,
7807                 (void *)&cmd_showqueue_queuenum,
7808                 NULL,
7809         },
7810 };
7811
7812 /* show/clear fwd engine statistics */
7813 struct fwd_result {
7814         cmdline_fixed_string_t action;
7815         cmdline_fixed_string_t fwd;
7816         cmdline_fixed_string_t stats;
7817         cmdline_fixed_string_t all;
7818 };
7819
7820 cmdline_parse_token_string_t cmd_fwd_action =
7821         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7822 cmdline_parse_token_string_t cmd_fwd_fwd =
7823         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7824 cmdline_parse_token_string_t cmd_fwd_stats =
7825         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7826 cmdline_parse_token_string_t cmd_fwd_all =
7827         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7828
7829 static void
7830 cmd_showfwdall_parsed(void *parsed_result,
7831                       __rte_unused struct cmdline *cl,
7832                       __rte_unused void *data)
7833 {
7834         struct fwd_result *res = parsed_result;
7835
7836         if (!strcmp(res->action, "show"))
7837                 fwd_stats_display();
7838         else
7839                 fwd_stats_reset();
7840 }
7841
7842 static cmdline_parse_inst_t cmd_showfwdall = {
7843         .f = cmd_showfwdall_parsed,
7844         .data = NULL,
7845         .help_str = "show|clear fwd stats all",
7846         .tokens = {
7847                 (void *)&cmd_fwd_action,
7848                 (void *)&cmd_fwd_fwd,
7849                 (void *)&cmd_fwd_stats,
7850                 (void *)&cmd_fwd_all,
7851                 NULL,
7852         },
7853 };
7854
7855 /* *** READ PORT REGISTER *** */
7856 struct cmd_read_reg_result {
7857         cmdline_fixed_string_t read;
7858         cmdline_fixed_string_t reg;
7859         portid_t port_id;
7860         uint32_t reg_off;
7861 };
7862
7863 static void
7864 cmd_read_reg_parsed(void *parsed_result,
7865                     __rte_unused struct cmdline *cl,
7866                     __rte_unused void *data)
7867 {
7868         struct cmd_read_reg_result *res = parsed_result;
7869         port_reg_display(res->port_id, res->reg_off);
7870 }
7871
7872 cmdline_parse_token_string_t cmd_read_reg_read =
7873         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7874 cmdline_parse_token_string_t cmd_read_reg_reg =
7875         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7876 cmdline_parse_token_num_t cmd_read_reg_port_id =
7877         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7878 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7879         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7880
7881 cmdline_parse_inst_t cmd_read_reg = {
7882         .f = cmd_read_reg_parsed,
7883         .data = NULL,
7884         .help_str = "read reg <port_id> <reg_off>",
7885         .tokens = {
7886                 (void *)&cmd_read_reg_read,
7887                 (void *)&cmd_read_reg_reg,
7888                 (void *)&cmd_read_reg_port_id,
7889                 (void *)&cmd_read_reg_reg_off,
7890                 NULL,
7891         },
7892 };
7893
7894 /* *** READ PORT REGISTER BIT FIELD *** */
7895 struct cmd_read_reg_bit_field_result {
7896         cmdline_fixed_string_t read;
7897         cmdline_fixed_string_t regfield;
7898         portid_t port_id;
7899         uint32_t reg_off;
7900         uint8_t bit1_pos;
7901         uint8_t bit2_pos;
7902 };
7903
7904 static void
7905 cmd_read_reg_bit_field_parsed(void *parsed_result,
7906                               __rte_unused struct cmdline *cl,
7907                               __rte_unused void *data)
7908 {
7909         struct cmd_read_reg_bit_field_result *res = parsed_result;
7910         port_reg_bit_field_display(res->port_id, res->reg_off,
7911                                    res->bit1_pos, res->bit2_pos);
7912 }
7913
7914 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7915         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7916                                  "read");
7917 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7918         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7919                                  regfield, "regfield");
7920 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7921         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7922                               UINT16);
7923 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7924         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7925                               UINT32);
7926 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7927         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7928                               UINT8);
7929 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7930         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7931                               UINT8);
7932
7933 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7934         .f = cmd_read_reg_bit_field_parsed,
7935         .data = NULL,
7936         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7937         "Read register bit field between bit_x and bit_y included",
7938         .tokens = {
7939                 (void *)&cmd_read_reg_bit_field_read,
7940                 (void *)&cmd_read_reg_bit_field_regfield,
7941                 (void *)&cmd_read_reg_bit_field_port_id,
7942                 (void *)&cmd_read_reg_bit_field_reg_off,
7943                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7944                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7945                 NULL,
7946         },
7947 };
7948
7949 /* *** READ PORT REGISTER BIT *** */
7950 struct cmd_read_reg_bit_result {
7951         cmdline_fixed_string_t read;
7952         cmdline_fixed_string_t regbit;
7953         portid_t port_id;
7954         uint32_t reg_off;
7955         uint8_t bit_pos;
7956 };
7957
7958 static void
7959 cmd_read_reg_bit_parsed(void *parsed_result,
7960                         __rte_unused struct cmdline *cl,
7961                         __rte_unused void *data)
7962 {
7963         struct cmd_read_reg_bit_result *res = parsed_result;
7964         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7965 }
7966
7967 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7968         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7969 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7970         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7971                                  regbit, "regbit");
7972 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7973         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7974 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7975         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7976 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7977         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7978
7979 cmdline_parse_inst_t cmd_read_reg_bit = {
7980         .f = cmd_read_reg_bit_parsed,
7981         .data = NULL,
7982         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7983         .tokens = {
7984                 (void *)&cmd_read_reg_bit_read,
7985                 (void *)&cmd_read_reg_bit_regbit,
7986                 (void *)&cmd_read_reg_bit_port_id,
7987                 (void *)&cmd_read_reg_bit_reg_off,
7988                 (void *)&cmd_read_reg_bit_bit_pos,
7989                 NULL,
7990         },
7991 };
7992
7993 /* *** WRITE PORT REGISTER *** */
7994 struct cmd_write_reg_result {
7995         cmdline_fixed_string_t write;
7996         cmdline_fixed_string_t reg;
7997         portid_t port_id;
7998         uint32_t reg_off;
7999         uint32_t value;
8000 };
8001
8002 static void
8003 cmd_write_reg_parsed(void *parsed_result,
8004                      __rte_unused struct cmdline *cl,
8005                      __rte_unused void *data)
8006 {
8007         struct cmd_write_reg_result *res = parsed_result;
8008         port_reg_set(res->port_id, res->reg_off, res->value);
8009 }
8010
8011 cmdline_parse_token_string_t cmd_write_reg_write =
8012         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8013 cmdline_parse_token_string_t cmd_write_reg_reg =
8014         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8015 cmdline_parse_token_num_t cmd_write_reg_port_id =
8016         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
8017 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8018         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
8019 cmdline_parse_token_num_t cmd_write_reg_value =
8020         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
8021
8022 cmdline_parse_inst_t cmd_write_reg = {
8023         .f = cmd_write_reg_parsed,
8024         .data = NULL,
8025         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8026         .tokens = {
8027                 (void *)&cmd_write_reg_write,
8028                 (void *)&cmd_write_reg_reg,
8029                 (void *)&cmd_write_reg_port_id,
8030                 (void *)&cmd_write_reg_reg_off,
8031                 (void *)&cmd_write_reg_value,
8032                 NULL,
8033         },
8034 };
8035
8036 /* *** WRITE PORT REGISTER BIT FIELD *** */
8037 struct cmd_write_reg_bit_field_result {
8038         cmdline_fixed_string_t write;
8039         cmdline_fixed_string_t regfield;
8040         portid_t port_id;
8041         uint32_t reg_off;
8042         uint8_t bit1_pos;
8043         uint8_t bit2_pos;
8044         uint32_t value;
8045 };
8046
8047 static void
8048 cmd_write_reg_bit_field_parsed(void *parsed_result,
8049                                __rte_unused struct cmdline *cl,
8050                                __rte_unused void *data)
8051 {
8052         struct cmd_write_reg_bit_field_result *res = parsed_result;
8053         port_reg_bit_field_set(res->port_id, res->reg_off,
8054                           res->bit1_pos, res->bit2_pos, res->value);
8055 }
8056
8057 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8058         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8059                                  "write");
8060 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8061         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8062                                  regfield, "regfield");
8063 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8064         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8065                               UINT16);
8066 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8067         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8068                               UINT32);
8069 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8070         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8071                               UINT8);
8072 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8073         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8074                               UINT8);
8075 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8076         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8077                               UINT32);
8078
8079 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8080         .f = cmd_write_reg_bit_field_parsed,
8081         .data = NULL,
8082         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8083                 "<reg_value>: "
8084                 "Set register bit field between bit_x and bit_y included",
8085         .tokens = {
8086                 (void *)&cmd_write_reg_bit_field_write,
8087                 (void *)&cmd_write_reg_bit_field_regfield,
8088                 (void *)&cmd_write_reg_bit_field_port_id,
8089                 (void *)&cmd_write_reg_bit_field_reg_off,
8090                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8091                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8092                 (void *)&cmd_write_reg_bit_field_value,
8093                 NULL,
8094         },
8095 };
8096
8097 /* *** WRITE PORT REGISTER BIT *** */
8098 struct cmd_write_reg_bit_result {
8099         cmdline_fixed_string_t write;
8100         cmdline_fixed_string_t regbit;
8101         portid_t port_id;
8102         uint32_t reg_off;
8103         uint8_t bit_pos;
8104         uint8_t value;
8105 };
8106
8107 static void
8108 cmd_write_reg_bit_parsed(void *parsed_result,
8109                          __rte_unused struct cmdline *cl,
8110                          __rte_unused void *data)
8111 {
8112         struct cmd_write_reg_bit_result *res = parsed_result;
8113         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8114 }
8115
8116 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8117         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8118                                  "write");
8119 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8120         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8121                                  regbit, "regbit");
8122 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8123         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8124 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8125         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8126 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8127         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8128 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8129         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8130
8131 cmdline_parse_inst_t cmd_write_reg_bit = {
8132         .f = cmd_write_reg_bit_parsed,
8133         .data = NULL,
8134         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8135                 "0 <= bit_x <= 31",
8136         .tokens = {
8137                 (void *)&cmd_write_reg_bit_write,
8138                 (void *)&cmd_write_reg_bit_regbit,
8139                 (void *)&cmd_write_reg_bit_port_id,
8140                 (void *)&cmd_write_reg_bit_reg_off,
8141                 (void *)&cmd_write_reg_bit_bit_pos,
8142                 (void *)&cmd_write_reg_bit_value,
8143                 NULL,
8144         },
8145 };
8146
8147 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8148 struct cmd_read_rxd_txd_result {
8149         cmdline_fixed_string_t read;
8150         cmdline_fixed_string_t rxd_txd;
8151         portid_t port_id;
8152         uint16_t queue_id;
8153         uint16_t desc_id;
8154 };
8155
8156 static void
8157 cmd_read_rxd_txd_parsed(void *parsed_result,
8158                         __rte_unused struct cmdline *cl,
8159                         __rte_unused void *data)
8160 {
8161         struct cmd_read_rxd_txd_result *res = parsed_result;
8162
8163         if (!strcmp(res->rxd_txd, "rxd"))
8164                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8165         else if (!strcmp(res->rxd_txd, "txd"))
8166                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8167 }
8168
8169 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8170         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8171 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8172         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8173                                  "rxd#txd");
8174 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8175         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8176 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8177         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8178 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8179         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8180
8181 cmdline_parse_inst_t cmd_read_rxd_txd = {
8182         .f = cmd_read_rxd_txd_parsed,
8183         .data = NULL,
8184         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8185         .tokens = {
8186                 (void *)&cmd_read_rxd_txd_read,
8187                 (void *)&cmd_read_rxd_txd_rxd_txd,
8188                 (void *)&cmd_read_rxd_txd_port_id,
8189                 (void *)&cmd_read_rxd_txd_queue_id,
8190                 (void *)&cmd_read_rxd_txd_desc_id,
8191                 NULL,
8192         },
8193 };
8194
8195 /* *** QUIT *** */
8196 struct cmd_quit_result {
8197         cmdline_fixed_string_t quit;
8198 };
8199
8200 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8201                             struct cmdline *cl,
8202                             __rte_unused void *data)
8203 {
8204         cmdline_quit(cl);
8205 }
8206
8207 cmdline_parse_token_string_t cmd_quit_quit =
8208         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8209
8210 cmdline_parse_inst_t cmd_quit = {
8211         .f = cmd_quit_parsed,
8212         .data = NULL,
8213         .help_str = "quit: Exit application",
8214         .tokens = {
8215                 (void *)&cmd_quit_quit,
8216                 NULL,
8217         },
8218 };
8219
8220 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8221 struct cmd_mac_addr_result {
8222         cmdline_fixed_string_t mac_addr_cmd;
8223         cmdline_fixed_string_t what;
8224         uint16_t port_num;
8225         struct rte_ether_addr address;
8226 };
8227
8228 static void cmd_mac_addr_parsed(void *parsed_result,
8229                 __rte_unused struct cmdline *cl,
8230                 __rte_unused void *data)
8231 {
8232         struct cmd_mac_addr_result *res = parsed_result;
8233         int ret;
8234
8235         if (strcmp(res->what, "add") == 0)
8236                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8237         else if (strcmp(res->what, "set") == 0)
8238                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8239                                                        &res->address);
8240         else
8241                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8242
8243         /* check the return value and print it if is < 0 */
8244         if(ret < 0)
8245                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8246
8247 }
8248
8249 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8250         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8251                                 "mac_addr");
8252 cmdline_parse_token_string_t cmd_mac_addr_what =
8253         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8254                                 "add#remove#set");
8255 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8256                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8257                                         UINT16);
8258 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8259                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8260
8261 cmdline_parse_inst_t cmd_mac_addr = {
8262         .f = cmd_mac_addr_parsed,
8263         .data = (void *)0,
8264         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8265                         "Add/Remove/Set MAC address on port_id",
8266         .tokens = {
8267                 (void *)&cmd_mac_addr_cmd,
8268                 (void *)&cmd_mac_addr_what,
8269                 (void *)&cmd_mac_addr_portnum,
8270                 (void *)&cmd_mac_addr_addr,
8271                 NULL,
8272         },
8273 };
8274
8275 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8276 struct cmd_eth_peer_result {
8277         cmdline_fixed_string_t set;
8278         cmdline_fixed_string_t eth_peer;
8279         portid_t port_id;
8280         cmdline_fixed_string_t peer_addr;
8281 };
8282
8283 static void cmd_set_eth_peer_parsed(void *parsed_result,
8284                         __rte_unused struct cmdline *cl,
8285                         __rte_unused void *data)
8286 {
8287                 struct cmd_eth_peer_result *res = parsed_result;
8288
8289                 if (test_done == 0) {
8290                         printf("Please stop forwarding first\n");
8291                         return;
8292                 }
8293                 if (!strcmp(res->eth_peer, "eth-peer")) {
8294                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8295                         fwd_config_setup();
8296                 }
8297 }
8298 cmdline_parse_token_string_t cmd_eth_peer_set =
8299         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8300 cmdline_parse_token_string_t cmd_eth_peer =
8301         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8302 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8303         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8304 cmdline_parse_token_string_t cmd_eth_peer_addr =
8305         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8306
8307 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8308         .f = cmd_set_eth_peer_parsed,
8309         .data = NULL,
8310         .help_str = "set eth-peer <port_id> <peer_mac>",
8311         .tokens = {
8312                 (void *)&cmd_eth_peer_set,
8313                 (void *)&cmd_eth_peer,
8314                 (void *)&cmd_eth_peer_port_id,
8315                 (void *)&cmd_eth_peer_addr,
8316                 NULL,
8317         },
8318 };
8319
8320 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8321 struct cmd_set_qmap_result {
8322         cmdline_fixed_string_t set;
8323         cmdline_fixed_string_t qmap;
8324         cmdline_fixed_string_t what;
8325         portid_t port_id;
8326         uint16_t queue_id;
8327         uint8_t map_value;
8328 };
8329
8330 static void
8331 cmd_set_qmap_parsed(void *parsed_result,
8332                        __rte_unused struct cmdline *cl,
8333                        __rte_unused void *data)
8334 {
8335         struct cmd_set_qmap_result *res = parsed_result;
8336         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8337
8338         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8339 }
8340
8341 cmdline_parse_token_string_t cmd_setqmap_set =
8342         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8343                                  set, "set");
8344 cmdline_parse_token_string_t cmd_setqmap_qmap =
8345         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8346                                  qmap, "stat_qmap");
8347 cmdline_parse_token_string_t cmd_setqmap_what =
8348         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8349                                  what, "tx#rx");
8350 cmdline_parse_token_num_t cmd_setqmap_portid =
8351         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8352                               port_id, UINT16);
8353 cmdline_parse_token_num_t cmd_setqmap_queueid =
8354         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8355                               queue_id, UINT16);
8356 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8357         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8358                               map_value, UINT8);
8359
8360 cmdline_parse_inst_t cmd_set_qmap = {
8361         .f = cmd_set_qmap_parsed,
8362         .data = NULL,
8363         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8364                 "Set statistics mapping value on tx|rx queue_id of port_id",
8365         .tokens = {
8366                 (void *)&cmd_setqmap_set,
8367                 (void *)&cmd_setqmap_qmap,
8368                 (void *)&cmd_setqmap_what,
8369                 (void *)&cmd_setqmap_portid,
8370                 (void *)&cmd_setqmap_queueid,
8371                 (void *)&cmd_setqmap_mapvalue,
8372                 NULL,
8373         },
8374 };
8375
8376 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8377 struct cmd_set_xstats_hide_zero_result {
8378         cmdline_fixed_string_t keyword;
8379         cmdline_fixed_string_t name;
8380         cmdline_fixed_string_t on_off;
8381 };
8382
8383 static void
8384 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8385                         __rte_unused struct cmdline *cl,
8386                         __rte_unused void *data)
8387 {
8388         struct cmd_set_xstats_hide_zero_result *res;
8389         uint16_t on_off = 0;
8390
8391         res = parsed_result;
8392         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8393         set_xstats_hide_zero(on_off);
8394 }
8395
8396 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8397         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8398                                  keyword, "set");
8399 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8400         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8401                                  name, "xstats-hide-zero");
8402 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8403         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8404                                  on_off, "on#off");
8405
8406 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8407         .f = cmd_set_xstats_hide_zero_parsed,
8408         .data = NULL,
8409         .help_str = "set xstats-hide-zero on|off",
8410         .tokens = {
8411                 (void *)&cmd_set_xstats_hide_zero_keyword,
8412                 (void *)&cmd_set_xstats_hide_zero_name,
8413                 (void *)&cmd_set_xstats_hide_zero_on_off,
8414                 NULL,
8415         },
8416 };
8417
8418 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8419 struct cmd_set_record_core_cycles_result {
8420         cmdline_fixed_string_t keyword;
8421         cmdline_fixed_string_t name;
8422         cmdline_fixed_string_t on_off;
8423 };
8424
8425 static void
8426 cmd_set_record_core_cycles_parsed(void *parsed_result,
8427                         __rte_unused struct cmdline *cl,
8428                         __rte_unused void *data)
8429 {
8430         struct cmd_set_record_core_cycles_result *res;
8431         uint16_t on_off = 0;
8432
8433         res = parsed_result;
8434         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8435         set_record_core_cycles(on_off);
8436 }
8437
8438 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8439         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8440                                  keyword, "set");
8441 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8442         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8443                                  name, "record-core-cycles");
8444 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8445         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8446                                  on_off, "on#off");
8447
8448 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8449         .f = cmd_set_record_core_cycles_parsed,
8450         .data = NULL,
8451         .help_str = "set record-core-cycles on|off",
8452         .tokens = {
8453                 (void *)&cmd_set_record_core_cycles_keyword,
8454                 (void *)&cmd_set_record_core_cycles_name,
8455                 (void *)&cmd_set_record_core_cycles_on_off,
8456                 NULL,
8457         },
8458 };
8459
8460 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8461 struct cmd_set_record_burst_stats_result {
8462         cmdline_fixed_string_t keyword;
8463         cmdline_fixed_string_t name;
8464         cmdline_fixed_string_t on_off;
8465 };
8466
8467 static void
8468 cmd_set_record_burst_stats_parsed(void *parsed_result,
8469                         __rte_unused struct cmdline *cl,
8470                         __rte_unused void *data)
8471 {
8472         struct cmd_set_record_burst_stats_result *res;
8473         uint16_t on_off = 0;
8474
8475         res = parsed_result;
8476         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8477         set_record_burst_stats(on_off);
8478 }
8479
8480 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8481         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8482                                  keyword, "set");
8483 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8484         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8485                                  name, "record-burst-stats");
8486 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8487         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8488                                  on_off, "on#off");
8489
8490 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8491         .f = cmd_set_record_burst_stats_parsed,
8492         .data = NULL,
8493         .help_str = "set record-burst-stats on|off",
8494         .tokens = {
8495                 (void *)&cmd_set_record_burst_stats_keyword,
8496                 (void *)&cmd_set_record_burst_stats_name,
8497                 (void *)&cmd_set_record_burst_stats_on_off,
8498                 NULL,
8499         },
8500 };
8501
8502 /* *** CONFIGURE UNICAST HASH TABLE *** */
8503 struct cmd_set_uc_hash_table {
8504         cmdline_fixed_string_t set;
8505         cmdline_fixed_string_t port;
8506         portid_t port_id;
8507         cmdline_fixed_string_t what;
8508         struct rte_ether_addr address;
8509         cmdline_fixed_string_t mode;
8510 };
8511
8512 static void
8513 cmd_set_uc_hash_parsed(void *parsed_result,
8514                        __rte_unused struct cmdline *cl,
8515                        __rte_unused void *data)
8516 {
8517         int ret=0;
8518         struct cmd_set_uc_hash_table *res = parsed_result;
8519
8520         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8521
8522         if (strcmp(res->what, "uta") == 0)
8523                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8524                                                 &res->address,(uint8_t)is_on);
8525         if (ret < 0)
8526                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8527
8528 }
8529
8530 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8531         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8532                                  set, "set");
8533 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8534         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8535                                  port, "port");
8536 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8537         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8538                               port_id, UINT16);
8539 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8540         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8541                                  what, "uta");
8542 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8543         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8544                                 address);
8545 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8546         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8547                                  mode, "on#off");
8548
8549 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8550         .f = cmd_set_uc_hash_parsed,
8551         .data = NULL,
8552         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8553         .tokens = {
8554                 (void *)&cmd_set_uc_hash_set,
8555                 (void *)&cmd_set_uc_hash_port,
8556                 (void *)&cmd_set_uc_hash_portid,
8557                 (void *)&cmd_set_uc_hash_what,
8558                 (void *)&cmd_set_uc_hash_mac,
8559                 (void *)&cmd_set_uc_hash_mode,
8560                 NULL,
8561         },
8562 };
8563
8564 struct cmd_set_uc_all_hash_table {
8565         cmdline_fixed_string_t set;
8566         cmdline_fixed_string_t port;
8567         portid_t port_id;
8568         cmdline_fixed_string_t what;
8569         cmdline_fixed_string_t value;
8570         cmdline_fixed_string_t mode;
8571 };
8572
8573 static void
8574 cmd_set_uc_all_hash_parsed(void *parsed_result,
8575                        __rte_unused struct cmdline *cl,
8576                        __rte_unused void *data)
8577 {
8578         int ret=0;
8579         struct cmd_set_uc_all_hash_table *res = parsed_result;
8580
8581         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8582
8583         if ((strcmp(res->what, "uta") == 0) &&
8584                 (strcmp(res->value, "all") == 0))
8585                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8586         if (ret < 0)
8587                 printf("bad unicast hash table parameter,"
8588                         "return code = %d \n", ret);
8589 }
8590
8591 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8592         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8593                                  set, "set");
8594 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8595         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8596                                  port, "port");
8597 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8598         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8599                               port_id, UINT16);
8600 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8601         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8602                                  what, "uta");
8603 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8604         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8605                                 value,"all");
8606 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8607         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8608                                  mode, "on#off");
8609
8610 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8611         .f = cmd_set_uc_all_hash_parsed,
8612         .data = NULL,
8613         .help_str = "set port <port_id> uta all on|off",
8614         .tokens = {
8615                 (void *)&cmd_set_uc_all_hash_set,
8616                 (void *)&cmd_set_uc_all_hash_port,
8617                 (void *)&cmd_set_uc_all_hash_portid,
8618                 (void *)&cmd_set_uc_all_hash_what,
8619                 (void *)&cmd_set_uc_all_hash_value,
8620                 (void *)&cmd_set_uc_all_hash_mode,
8621                 NULL,
8622         },
8623 };
8624
8625 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8626 struct cmd_set_vf_macvlan_filter {
8627         cmdline_fixed_string_t set;
8628         cmdline_fixed_string_t port;
8629         portid_t port_id;
8630         cmdline_fixed_string_t vf;
8631         uint8_t vf_id;
8632         struct rte_ether_addr address;
8633         cmdline_fixed_string_t filter_type;
8634         cmdline_fixed_string_t mode;
8635 };
8636
8637 static void
8638 cmd_set_vf_macvlan_parsed(void *parsed_result,
8639                        __rte_unused struct cmdline *cl,
8640                        __rte_unused void *data)
8641 {
8642         int is_on, ret = 0;
8643         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8644         struct rte_eth_mac_filter filter;
8645
8646         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8647
8648         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8649
8650         /* set VF MAC filter */
8651         filter.is_vf = 1;
8652
8653         /* set VF ID */
8654         filter.dst_id = res->vf_id;
8655
8656         if (!strcmp(res->filter_type, "exact-mac"))
8657                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8658         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8659                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8660         else if (!strcmp(res->filter_type, "hashmac"))
8661                 filter.filter_type = RTE_MAC_HASH_MATCH;
8662         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8663                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8664
8665         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8666
8667         if (is_on)
8668                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8669                                         RTE_ETH_FILTER_MACVLAN,
8670                                         RTE_ETH_FILTER_ADD,
8671                                          &filter);
8672         else
8673                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8674                                         RTE_ETH_FILTER_MACVLAN,
8675                                         RTE_ETH_FILTER_DELETE,
8676                                         &filter);
8677
8678         if (ret < 0)
8679                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8680
8681 }
8682
8683 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8684         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8685                                  set, "set");
8686 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8687         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8688                                  port, "port");
8689 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8690         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8691                               port_id, UINT16);
8692 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8693         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8694                                  vf, "vf");
8695 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8696         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8697                                 vf_id, UINT8);
8698 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8699         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8700                                 address);
8701 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8702         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8703                                 filter_type, "exact-mac#exact-mac-vlan"
8704                                 "#hashmac#hashmac-vlan");
8705 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8706         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8707                                  mode, "on#off");
8708
8709 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8710         .f = cmd_set_vf_macvlan_parsed,
8711         .data = NULL,
8712         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8713                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8714                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8715                 "hash match rule: hash match of MAC and exact match of VLAN",
8716         .tokens = {
8717                 (void *)&cmd_set_vf_macvlan_set,
8718                 (void *)&cmd_set_vf_macvlan_port,
8719                 (void *)&cmd_set_vf_macvlan_portid,
8720                 (void *)&cmd_set_vf_macvlan_vf,
8721                 (void *)&cmd_set_vf_macvlan_vf_id,
8722                 (void *)&cmd_set_vf_macvlan_mac,
8723                 (void *)&cmd_set_vf_macvlan_filter_type,
8724                 (void *)&cmd_set_vf_macvlan_mode,
8725                 NULL,
8726         },
8727 };
8728
8729 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8730 struct cmd_set_vf_traffic {
8731         cmdline_fixed_string_t set;
8732         cmdline_fixed_string_t port;
8733         portid_t port_id;
8734         cmdline_fixed_string_t vf;
8735         uint8_t vf_id;
8736         cmdline_fixed_string_t what;
8737         cmdline_fixed_string_t mode;
8738 };
8739
8740 static void
8741 cmd_set_vf_traffic_parsed(void *parsed_result,
8742                        __rte_unused struct cmdline *cl,
8743                        __rte_unused void *data)
8744 {
8745         struct cmd_set_vf_traffic *res = parsed_result;
8746         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8747         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8748
8749         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8750 }
8751
8752 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8753         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8754                                  set, "set");
8755 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8756         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8757                                  port, "port");
8758 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8759         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8760                               port_id, UINT16);
8761 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8762         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8763                                  vf, "vf");
8764 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8765         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8766                               vf_id, UINT8);
8767 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8768         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8769                                  what, "tx#rx");
8770 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8771         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8772                                  mode, "on#off");
8773
8774 cmdline_parse_inst_t cmd_set_vf_traffic = {
8775         .f = cmd_set_vf_traffic_parsed,
8776         .data = NULL,
8777         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8778         .tokens = {
8779                 (void *)&cmd_setvf_traffic_set,
8780                 (void *)&cmd_setvf_traffic_port,
8781                 (void *)&cmd_setvf_traffic_portid,
8782                 (void *)&cmd_setvf_traffic_vf,
8783                 (void *)&cmd_setvf_traffic_vfid,
8784                 (void *)&cmd_setvf_traffic_what,
8785                 (void *)&cmd_setvf_traffic_mode,
8786                 NULL,
8787         },
8788 };
8789
8790 /* *** CONFIGURE VF RECEIVE MODE *** */
8791 struct cmd_set_vf_rxmode {
8792         cmdline_fixed_string_t set;
8793         cmdline_fixed_string_t port;
8794         portid_t port_id;
8795         cmdline_fixed_string_t vf;
8796         uint8_t vf_id;
8797         cmdline_fixed_string_t what;
8798         cmdline_fixed_string_t mode;
8799         cmdline_fixed_string_t on;
8800 };
8801
8802 static void
8803 cmd_set_vf_rxmode_parsed(void *parsed_result,
8804                        __rte_unused struct cmdline *cl,
8805                        __rte_unused void *data)
8806 {
8807         int ret = -ENOTSUP;
8808         uint16_t vf_rxmode = 0;
8809         struct cmd_set_vf_rxmode *res = parsed_result;
8810
8811         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8812         if (!strcmp(res->what,"rxmode")) {
8813                 if (!strcmp(res->mode, "AUPE"))
8814                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8815                 else if (!strcmp(res->mode, "ROPE"))
8816                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8817                 else if (!strcmp(res->mode, "BAM"))
8818                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8819                 else if (!strncmp(res->mode, "MPE",3))
8820                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8821         }
8822
8823         RTE_SET_USED(is_on);
8824
8825 #ifdef RTE_LIBRTE_IXGBE_PMD
8826         if (ret == -ENOTSUP)
8827                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8828                                                   vf_rxmode, (uint8_t)is_on);
8829 #endif
8830 #ifdef RTE_LIBRTE_BNXT_PMD
8831         if (ret == -ENOTSUP)
8832                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8833                                                  vf_rxmode, (uint8_t)is_on);
8834 #endif
8835         if (ret < 0)
8836                 printf("bad VF receive mode parameter, return code = %d \n",
8837                 ret);
8838 }
8839
8840 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8841         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8842                                  set, "set");
8843 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8844         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8845                                  port, "port");
8846 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8847         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8848                               port_id, UINT16);
8849 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8850         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8851                                  vf, "vf");
8852 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8853         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8854                               vf_id, UINT8);
8855 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8856         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8857                                  what, "rxmode");
8858 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8859         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8860                                  mode, "AUPE#ROPE#BAM#MPE");
8861 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8862         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8863                                  on, "on#off");
8864
8865 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8866         .f = cmd_set_vf_rxmode_parsed,
8867         .data = NULL,
8868         .help_str = "set port <port_id> vf <vf_id> rxmode "
8869                 "AUPE|ROPE|BAM|MPE on|off",
8870         .tokens = {
8871                 (void *)&cmd_set_vf_rxmode_set,
8872                 (void *)&cmd_set_vf_rxmode_port,
8873                 (void *)&cmd_set_vf_rxmode_portid,
8874                 (void *)&cmd_set_vf_rxmode_vf,
8875                 (void *)&cmd_set_vf_rxmode_vfid,
8876                 (void *)&cmd_set_vf_rxmode_what,
8877                 (void *)&cmd_set_vf_rxmode_mode,
8878                 (void *)&cmd_set_vf_rxmode_on,
8879                 NULL,
8880         },
8881 };
8882
8883 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8884 struct cmd_vf_mac_addr_result {
8885         cmdline_fixed_string_t mac_addr_cmd;
8886         cmdline_fixed_string_t what;
8887         cmdline_fixed_string_t port;
8888         uint16_t port_num;
8889         cmdline_fixed_string_t vf;
8890         uint8_t vf_num;
8891         struct rte_ether_addr address;
8892 };
8893
8894 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8895                 __rte_unused struct cmdline *cl,
8896                 __rte_unused void *data)
8897 {
8898         struct cmd_vf_mac_addr_result *res = parsed_result;
8899         int ret = -ENOTSUP;
8900
8901         if (strcmp(res->what, "add") != 0)
8902                 return;
8903
8904 #ifdef RTE_LIBRTE_I40E_PMD
8905         if (ret == -ENOTSUP)
8906                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8907                                                    &res->address);
8908 #endif
8909 #ifdef RTE_LIBRTE_BNXT_PMD
8910         if (ret == -ENOTSUP)
8911                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8912                                                 res->vf_num);
8913 #endif
8914
8915         if(ret < 0)
8916                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8917
8918 }
8919
8920 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8921         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8922                                 mac_addr_cmd,"mac_addr");
8923 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8924         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8925                                 what,"add");
8926 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8927         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8928                                 port,"port");
8929 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8930         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8931                                 port_num, UINT16);
8932 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8933         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8934                                 vf,"vf");
8935 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8936         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8937                                 vf_num, UINT8);
8938 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8939         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8940                                 address);
8941
8942 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8943         .f = cmd_vf_mac_addr_parsed,
8944         .data = (void *)0,
8945         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8946                 "Add MAC address filtering for a VF on port_id",
8947         .tokens = {
8948                 (void *)&cmd_vf_mac_addr_cmd,
8949                 (void *)&cmd_vf_mac_addr_what,
8950                 (void *)&cmd_vf_mac_addr_port,
8951                 (void *)&cmd_vf_mac_addr_portnum,
8952                 (void *)&cmd_vf_mac_addr_vf,
8953                 (void *)&cmd_vf_mac_addr_vfnum,
8954                 (void *)&cmd_vf_mac_addr_addr,
8955                 NULL,
8956         },
8957 };
8958
8959 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8960 struct cmd_vf_rx_vlan_filter {
8961         cmdline_fixed_string_t rx_vlan;
8962         cmdline_fixed_string_t what;
8963         uint16_t vlan_id;
8964         cmdline_fixed_string_t port;
8965         portid_t port_id;
8966         cmdline_fixed_string_t vf;
8967         uint64_t vf_mask;
8968 };
8969
8970 static void
8971 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8972                           __rte_unused struct cmdline *cl,
8973                           __rte_unused void *data)
8974 {
8975         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8976         int ret = -ENOTSUP;
8977
8978         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8979
8980 #ifdef RTE_LIBRTE_IXGBE_PMD
8981         if (ret == -ENOTSUP)
8982                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8983                                 res->vlan_id, res->vf_mask, is_add);
8984 #endif
8985 #ifdef RTE_LIBRTE_I40E_PMD
8986         if (ret == -ENOTSUP)
8987                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8988                                 res->vlan_id, res->vf_mask, is_add);
8989 #endif
8990 #ifdef RTE_LIBRTE_BNXT_PMD
8991         if (ret == -ENOTSUP)
8992                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8993                                 res->vlan_id, res->vf_mask, is_add);
8994 #endif
8995
8996         switch (ret) {
8997         case 0:
8998                 break;
8999         case -EINVAL:
9000                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
9001                                 res->vlan_id, res->vf_mask);
9002                 break;
9003         case -ENODEV:
9004                 printf("invalid port_id %d\n", res->port_id);
9005                 break;
9006         case -ENOTSUP:
9007                 printf("function not implemented or supported\n");
9008                 break;
9009         default:
9010                 printf("programming error: (%s)\n", strerror(-ret));
9011         }
9012 }
9013
9014 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9015         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9016                                  rx_vlan, "rx_vlan");
9017 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9018         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9019                                  what, "add#rm");
9020 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9021         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9022                               vlan_id, UINT16);
9023 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9024         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9025                                  port, "port");
9026 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9027         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9028                               port_id, UINT16);
9029 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9030         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9031                                  vf, "vf");
9032 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9033         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9034                               vf_mask, UINT64);
9035
9036 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9037         .f = cmd_vf_rx_vlan_filter_parsed,
9038         .data = NULL,
9039         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9040                 "(vf_mask = hexadecimal VF mask)",
9041         .tokens = {
9042                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9043                 (void *)&cmd_vf_rx_vlan_filter_what,
9044                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9045                 (void *)&cmd_vf_rx_vlan_filter_port,
9046                 (void *)&cmd_vf_rx_vlan_filter_portid,
9047                 (void *)&cmd_vf_rx_vlan_filter_vf,
9048                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9049                 NULL,
9050         },
9051 };
9052
9053 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9054 struct cmd_queue_rate_limit_result {
9055         cmdline_fixed_string_t set;
9056         cmdline_fixed_string_t port;
9057         uint16_t port_num;
9058         cmdline_fixed_string_t queue;
9059         uint8_t queue_num;
9060         cmdline_fixed_string_t rate;
9061         uint16_t rate_num;
9062 };
9063
9064 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9065                 __rte_unused struct cmdline *cl,
9066                 __rte_unused void *data)
9067 {
9068         struct cmd_queue_rate_limit_result *res = parsed_result;
9069         int ret = 0;
9070
9071         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9072                 && (strcmp(res->queue, "queue") == 0)
9073                 && (strcmp(res->rate, "rate") == 0))
9074                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9075                                         res->rate_num);
9076         if (ret < 0)
9077                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9078
9079 }
9080
9081 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9082         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9083                                 set, "set");
9084 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9085         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9086                                 port, "port");
9087 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9088         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9089                                 port_num, UINT16);
9090 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9091         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9092                                 queue, "queue");
9093 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9094         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9095                                 queue_num, UINT8);
9096 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9097         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9098                                 rate, "rate");
9099 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9100         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9101                                 rate_num, UINT16);
9102
9103 cmdline_parse_inst_t cmd_queue_rate_limit = {
9104         .f = cmd_queue_rate_limit_parsed,
9105         .data = (void *)0,
9106         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9107                 "Set rate limit for a queue on port_id",
9108         .tokens = {
9109                 (void *)&cmd_queue_rate_limit_set,
9110                 (void *)&cmd_queue_rate_limit_port,
9111                 (void *)&cmd_queue_rate_limit_portnum,
9112                 (void *)&cmd_queue_rate_limit_queue,
9113                 (void *)&cmd_queue_rate_limit_queuenum,
9114                 (void *)&cmd_queue_rate_limit_rate,
9115                 (void *)&cmd_queue_rate_limit_ratenum,
9116                 NULL,
9117         },
9118 };
9119
9120 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9121 struct cmd_vf_rate_limit_result {
9122         cmdline_fixed_string_t set;
9123         cmdline_fixed_string_t port;
9124         uint16_t port_num;
9125         cmdline_fixed_string_t vf;
9126         uint8_t vf_num;
9127         cmdline_fixed_string_t rate;
9128         uint16_t rate_num;
9129         cmdline_fixed_string_t q_msk;
9130         uint64_t q_msk_val;
9131 };
9132
9133 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9134                 __rte_unused struct cmdline *cl,
9135                 __rte_unused void *data)
9136 {
9137         struct cmd_vf_rate_limit_result *res = parsed_result;
9138         int ret = 0;
9139
9140         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9141                 && (strcmp(res->vf, "vf") == 0)
9142                 && (strcmp(res->rate, "rate") == 0)
9143                 && (strcmp(res->q_msk, "queue_mask") == 0))
9144                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9145                                         res->rate_num, res->q_msk_val);
9146         if (ret < 0)
9147                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9148
9149 }
9150
9151 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9152         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9153                                 set, "set");
9154 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9155         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9156                                 port, "port");
9157 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9158         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9159                                 port_num, UINT16);
9160 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9161         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9162                                 vf, "vf");
9163 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9164         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9165                                 vf_num, UINT8);
9166 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9167         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9168                                 rate, "rate");
9169 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9170         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9171                                 rate_num, UINT16);
9172 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9173         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9174                                 q_msk, "queue_mask");
9175 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9176         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9177                                 q_msk_val, UINT64);
9178
9179 cmdline_parse_inst_t cmd_vf_rate_limit = {
9180         .f = cmd_vf_rate_limit_parsed,
9181         .data = (void *)0,
9182         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9183                 "queue_mask <queue_mask_value>: "
9184                 "Set rate limit for queues of VF on port_id",
9185         .tokens = {
9186                 (void *)&cmd_vf_rate_limit_set,
9187                 (void *)&cmd_vf_rate_limit_port,
9188                 (void *)&cmd_vf_rate_limit_portnum,
9189                 (void *)&cmd_vf_rate_limit_vf,
9190                 (void *)&cmd_vf_rate_limit_vfnum,
9191                 (void *)&cmd_vf_rate_limit_rate,
9192                 (void *)&cmd_vf_rate_limit_ratenum,
9193                 (void *)&cmd_vf_rate_limit_q_msk,
9194                 (void *)&cmd_vf_rate_limit_q_msk_val,
9195                 NULL,
9196         },
9197 };
9198
9199 /* *** ADD TUNNEL FILTER OF A PORT *** */
9200 struct cmd_tunnel_filter_result {
9201         cmdline_fixed_string_t cmd;
9202         cmdline_fixed_string_t what;
9203         portid_t port_id;
9204         struct rte_ether_addr outer_mac;
9205         struct rte_ether_addr inner_mac;
9206         cmdline_ipaddr_t ip_value;
9207         uint16_t inner_vlan;
9208         cmdline_fixed_string_t tunnel_type;
9209         cmdline_fixed_string_t filter_type;
9210         uint32_t tenant_id;
9211         uint16_t queue_num;
9212 };
9213
9214 static void
9215 cmd_tunnel_filter_parsed(void *parsed_result,
9216                           __rte_unused struct cmdline *cl,
9217                           __rte_unused void *data)
9218 {
9219         struct cmd_tunnel_filter_result *res = parsed_result;
9220         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9221         int ret = 0;
9222
9223         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9224
9225         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9226         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9227         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9228
9229         if (res->ip_value.family == AF_INET) {
9230                 tunnel_filter_conf.ip_addr.ipv4_addr =
9231                         res->ip_value.addr.ipv4.s_addr;
9232                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9233         } else {
9234                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9235                         &(res->ip_value.addr.ipv6),
9236                         sizeof(struct in6_addr));
9237                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9238         }
9239
9240         if (!strcmp(res->filter_type, "imac-ivlan"))
9241                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9242         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9243                 tunnel_filter_conf.filter_type =
9244                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9245         else if (!strcmp(res->filter_type, "imac-tenid"))
9246                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9247         else if (!strcmp(res->filter_type, "imac"))
9248                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9249         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9250                 tunnel_filter_conf.filter_type =
9251                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9252         else if (!strcmp(res->filter_type, "oip"))
9253                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9254         else if (!strcmp(res->filter_type, "iip"))
9255                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9256         else {
9257                 printf("The filter type is not supported");
9258                 return;
9259         }
9260
9261         if (!strcmp(res->tunnel_type, "vxlan"))
9262                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9263         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9264                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9265         else if (!strcmp(res->tunnel_type, "nvgre"))
9266                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9267         else if (!strcmp(res->tunnel_type, "ipingre"))
9268                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9269         else {
9270                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9271                 return;
9272         }
9273
9274         tunnel_filter_conf.tenant_id = res->tenant_id;
9275         tunnel_filter_conf.queue_id = res->queue_num;
9276         if (!strcmp(res->what, "add"))
9277                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9278                                         RTE_ETH_FILTER_TUNNEL,
9279                                         RTE_ETH_FILTER_ADD,
9280                                         &tunnel_filter_conf);
9281         else
9282                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9283                                         RTE_ETH_FILTER_TUNNEL,
9284                                         RTE_ETH_FILTER_DELETE,
9285                                         &tunnel_filter_conf);
9286         if (ret < 0)
9287                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9288                                 strerror(-ret));
9289
9290 }
9291 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9292         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9293         cmd, "tunnel_filter");
9294 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9295         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9296         what, "add#rm");
9297 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9298         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9299         port_id, UINT16);
9300 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9301         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9302         outer_mac);
9303 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9304         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9305         inner_mac);
9306 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9307         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9308         inner_vlan, UINT16);
9309 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9310         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9311         ip_value);
9312 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9313         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9314         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9315
9316 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9317         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9318         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9319                 "imac#omac-imac-tenid");
9320 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9321         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9322         tenant_id, UINT32);
9323 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9324         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9325         queue_num, UINT16);
9326
9327 cmdline_parse_inst_t cmd_tunnel_filter = {
9328         .f = cmd_tunnel_filter_parsed,
9329         .data = (void *)0,
9330         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9331                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9332                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9333                 "<queue_id>: Add/Rm tunnel filter of a port",
9334         .tokens = {
9335                 (void *)&cmd_tunnel_filter_cmd,
9336                 (void *)&cmd_tunnel_filter_what,
9337                 (void *)&cmd_tunnel_filter_port_id,
9338                 (void *)&cmd_tunnel_filter_outer_mac,
9339                 (void *)&cmd_tunnel_filter_inner_mac,
9340                 (void *)&cmd_tunnel_filter_ip_value,
9341                 (void *)&cmd_tunnel_filter_innner_vlan,
9342                 (void *)&cmd_tunnel_filter_tunnel_type,
9343                 (void *)&cmd_tunnel_filter_filter_type,
9344                 (void *)&cmd_tunnel_filter_tenant_id,
9345                 (void *)&cmd_tunnel_filter_queue_num,
9346                 NULL,
9347         },
9348 };
9349
9350 /* *** CONFIGURE TUNNEL UDP PORT *** */
9351 struct cmd_tunnel_udp_config {
9352         cmdline_fixed_string_t cmd;
9353         cmdline_fixed_string_t what;
9354         uint16_t udp_port;
9355         portid_t port_id;
9356 };
9357
9358 static void
9359 cmd_tunnel_udp_config_parsed(void *parsed_result,
9360                           __rte_unused struct cmdline *cl,
9361                           __rte_unused void *data)
9362 {
9363         struct cmd_tunnel_udp_config *res = parsed_result;
9364         struct rte_eth_udp_tunnel tunnel_udp;
9365         int ret;
9366
9367         tunnel_udp.udp_port = res->udp_port;
9368
9369         if (!strcmp(res->cmd, "rx_vxlan_port"))
9370                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9371
9372         if (!strcmp(res->what, "add"))
9373                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9374                                                       &tunnel_udp);
9375         else
9376                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9377                                                          &tunnel_udp);
9378
9379         if (ret < 0)
9380                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9381 }
9382
9383 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9384         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9385                                 cmd, "rx_vxlan_port");
9386 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9387         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9388                                 what, "add#rm");
9389 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9390         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9391                                 udp_port, UINT16);
9392 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9393         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9394                                 port_id, UINT16);
9395
9396 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9397         .f = cmd_tunnel_udp_config_parsed,
9398         .data = (void *)0,
9399         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9400                 "Add/Remove a tunneling UDP port filter",
9401         .tokens = {
9402                 (void *)&cmd_tunnel_udp_config_cmd,
9403                 (void *)&cmd_tunnel_udp_config_what,
9404                 (void *)&cmd_tunnel_udp_config_udp_port,
9405                 (void *)&cmd_tunnel_udp_config_port_id,
9406                 NULL,
9407         },
9408 };
9409
9410 struct cmd_config_tunnel_udp_port {
9411         cmdline_fixed_string_t port;
9412         cmdline_fixed_string_t config;
9413         portid_t port_id;
9414         cmdline_fixed_string_t udp_tunnel_port;
9415         cmdline_fixed_string_t action;
9416         cmdline_fixed_string_t tunnel_type;
9417         uint16_t udp_port;
9418 };
9419
9420 static void
9421 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9422                                __rte_unused struct cmdline *cl,
9423                                __rte_unused void *data)
9424 {
9425         struct cmd_config_tunnel_udp_port *res = parsed_result;
9426         struct rte_eth_udp_tunnel tunnel_udp;
9427         int ret = 0;
9428
9429         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9430                 return;
9431
9432         tunnel_udp.udp_port = res->udp_port;
9433
9434         if (!strcmp(res->tunnel_type, "vxlan")) {
9435                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9436         } else if (!strcmp(res->tunnel_type, "geneve")) {
9437                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9438         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9439                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9440         } else {
9441                 printf("Invalid tunnel type\n");
9442                 return;
9443         }
9444
9445         if (!strcmp(res->action, "add"))
9446                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9447                                                       &tunnel_udp);
9448         else
9449                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9450                                                          &tunnel_udp);
9451
9452         if (ret < 0)
9453                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9454 }
9455
9456 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9457         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9458                                  "port");
9459 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9460         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9461                                  "config");
9462 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9463         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9464                               UINT16);
9465 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9466         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9467                                  udp_tunnel_port,
9468                                  "udp_tunnel_port");
9469 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9470         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9471                                  "add#rm");
9472 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9473         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9474                                  "vxlan#geneve#vxlan-gpe");
9475 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9476         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9477                               UINT16);
9478
9479 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9480         .f = cmd_cfg_tunnel_udp_port_parsed,
9481         .data = NULL,
9482         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9483         .tokens = {
9484                 (void *)&cmd_config_tunnel_udp_port_port,
9485                 (void *)&cmd_config_tunnel_udp_port_config,
9486                 (void *)&cmd_config_tunnel_udp_port_port_id,
9487                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9488                 (void *)&cmd_config_tunnel_udp_port_action,
9489                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9490                 (void *)&cmd_config_tunnel_udp_port_value,
9491                 NULL,
9492         },
9493 };
9494
9495 /* *** GLOBAL CONFIG *** */
9496 struct cmd_global_config_result {
9497         cmdline_fixed_string_t cmd;
9498         portid_t port_id;
9499         cmdline_fixed_string_t cfg_type;
9500         uint8_t len;
9501 };
9502
9503 static void
9504 cmd_global_config_parsed(void *parsed_result,
9505                          __rte_unused struct cmdline *cl,
9506                          __rte_unused void *data)
9507 {
9508         struct cmd_global_config_result *res = parsed_result;
9509         struct rte_eth_global_cfg conf;
9510         int ret;
9511
9512         memset(&conf, 0, sizeof(conf));
9513         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9514         conf.cfg.gre_key_len = res->len;
9515         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9516                                       RTE_ETH_FILTER_SET, &conf);
9517 #ifdef RTE_LIBRTE_I40E_PMD
9518         if (ret == -ENOTSUP)
9519                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9520 #endif
9521         if (ret != 0)
9522                 printf("Global config error\n");
9523 }
9524
9525 cmdline_parse_token_string_t cmd_global_config_cmd =
9526         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9527                 "global_config");
9528 cmdline_parse_token_num_t cmd_global_config_port_id =
9529         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9530                                UINT16);
9531 cmdline_parse_token_string_t cmd_global_config_type =
9532         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9533                 cfg_type, "gre-key-len");
9534 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9535         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9536                 len, UINT8);
9537
9538 cmdline_parse_inst_t cmd_global_config = {
9539         .f = cmd_global_config_parsed,
9540         .data = (void *)NULL,
9541         .help_str = "global_config <port_id> gre-key-len <key_len>",
9542         .tokens = {
9543                 (void *)&cmd_global_config_cmd,
9544                 (void *)&cmd_global_config_port_id,
9545                 (void *)&cmd_global_config_type,
9546                 (void *)&cmd_global_config_gre_key_len,
9547                 NULL,
9548         },
9549 };
9550
9551 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9552 struct cmd_set_mirror_mask_result {
9553         cmdline_fixed_string_t set;
9554         cmdline_fixed_string_t port;
9555         portid_t port_id;
9556         cmdline_fixed_string_t mirror;
9557         uint8_t rule_id;
9558         cmdline_fixed_string_t what;
9559         cmdline_fixed_string_t value;
9560         cmdline_fixed_string_t dstpool;
9561         uint8_t dstpool_id;
9562         cmdline_fixed_string_t on;
9563 };
9564
9565 cmdline_parse_token_string_t cmd_mirror_mask_set =
9566         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9567                                 set, "set");
9568 cmdline_parse_token_string_t cmd_mirror_mask_port =
9569         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9570                                 port, "port");
9571 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9572         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9573                                 port_id, UINT16);
9574 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9575         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9576                                 mirror, "mirror-rule");
9577 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9578         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9579                                 rule_id, UINT8);
9580 cmdline_parse_token_string_t cmd_mirror_mask_what =
9581         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9582                                 what, "pool-mirror-up#pool-mirror-down"
9583                                       "#vlan-mirror");
9584 cmdline_parse_token_string_t cmd_mirror_mask_value =
9585         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9586                                 value, NULL);
9587 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9588         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9589                                 dstpool, "dst-pool");
9590 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9591         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9592                                 dstpool_id, UINT8);
9593 cmdline_parse_token_string_t cmd_mirror_mask_on =
9594         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9595                                 on, "on#off");
9596
9597 static void
9598 cmd_set_mirror_mask_parsed(void *parsed_result,
9599                        __rte_unused struct cmdline *cl,
9600                        __rte_unused void *data)
9601 {
9602         int ret,nb_item,i;
9603         struct cmd_set_mirror_mask_result *res = parsed_result;
9604         struct rte_eth_mirror_conf mr_conf;
9605
9606         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9607
9608         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9609
9610         mr_conf.dst_pool = res->dstpool_id;
9611
9612         if (!strcmp(res->what, "pool-mirror-up")) {
9613                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9614                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9615         } else if (!strcmp(res->what, "pool-mirror-down")) {
9616                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9617                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9618         } else if (!strcmp(res->what, "vlan-mirror")) {
9619                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9620                 nb_item = parse_item_list(res->value, "vlan",
9621                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9622                 if (nb_item <= 0)
9623                         return;
9624
9625                 for (i = 0; i < nb_item; i++) {
9626                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9627                                 printf("Invalid vlan_id: must be < 4096\n");
9628                                 return;
9629                         }
9630
9631                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9632                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9633                 }
9634         }
9635
9636         if (!strcmp(res->on, "on"))
9637                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9638                                                 res->rule_id, 1);
9639         else
9640                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9641                                                 res->rule_id, 0);
9642         if (ret < 0)
9643                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9644 }
9645
9646 cmdline_parse_inst_t cmd_set_mirror_mask = {
9647                 .f = cmd_set_mirror_mask_parsed,
9648                 .data = NULL,
9649                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9650                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9651                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9652                 .tokens = {
9653                         (void *)&cmd_mirror_mask_set,
9654                         (void *)&cmd_mirror_mask_port,
9655                         (void *)&cmd_mirror_mask_portid,
9656                         (void *)&cmd_mirror_mask_mirror,
9657                         (void *)&cmd_mirror_mask_ruleid,
9658                         (void *)&cmd_mirror_mask_what,
9659                         (void *)&cmd_mirror_mask_value,
9660                         (void *)&cmd_mirror_mask_dstpool,
9661                         (void *)&cmd_mirror_mask_poolid,
9662                         (void *)&cmd_mirror_mask_on,
9663                         NULL,
9664                 },
9665 };
9666
9667 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9668 struct cmd_set_mirror_link_result {
9669         cmdline_fixed_string_t set;
9670         cmdline_fixed_string_t port;
9671         portid_t port_id;
9672         cmdline_fixed_string_t mirror;
9673         uint8_t rule_id;
9674         cmdline_fixed_string_t what;
9675         cmdline_fixed_string_t dstpool;
9676         uint8_t dstpool_id;
9677         cmdline_fixed_string_t on;
9678 };
9679
9680 cmdline_parse_token_string_t cmd_mirror_link_set =
9681         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9682                                  set, "set");
9683 cmdline_parse_token_string_t cmd_mirror_link_port =
9684         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9685                                 port, "port");
9686 cmdline_parse_token_num_t cmd_mirror_link_portid =
9687         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9688                                 port_id, UINT16);
9689 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9690         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9691                                 mirror, "mirror-rule");
9692 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9693         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9694                             rule_id, UINT8);
9695 cmdline_parse_token_string_t cmd_mirror_link_what =
9696         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9697                                 what, "uplink-mirror#downlink-mirror");
9698 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9699         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9700                                 dstpool, "dst-pool");
9701 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9702         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9703                                 dstpool_id, UINT8);
9704 cmdline_parse_token_string_t cmd_mirror_link_on =
9705         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9706                                 on, "on#off");
9707
9708 static void
9709 cmd_set_mirror_link_parsed(void *parsed_result,
9710                        __rte_unused struct cmdline *cl,
9711                        __rte_unused void *data)
9712 {
9713         int ret;
9714         struct cmd_set_mirror_link_result *res = parsed_result;
9715         struct rte_eth_mirror_conf mr_conf;
9716
9717         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9718         if (!strcmp(res->what, "uplink-mirror"))
9719                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9720         else
9721                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9722
9723         mr_conf.dst_pool = res->dstpool_id;
9724
9725         if (!strcmp(res->on, "on"))
9726                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9727                                                 res->rule_id, 1);
9728         else
9729                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9730                                                 res->rule_id, 0);
9731
9732         /* check the return value and print it if is < 0 */
9733         if (ret < 0)
9734                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9735
9736 }
9737
9738 cmdline_parse_inst_t cmd_set_mirror_link = {
9739                 .f = cmd_set_mirror_link_parsed,
9740                 .data = NULL,
9741                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9742                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9743                 .tokens = {
9744                         (void *)&cmd_mirror_link_set,
9745                         (void *)&cmd_mirror_link_port,
9746                         (void *)&cmd_mirror_link_portid,
9747                         (void *)&cmd_mirror_link_mirror,
9748                         (void *)&cmd_mirror_link_ruleid,
9749                         (void *)&cmd_mirror_link_what,
9750                         (void *)&cmd_mirror_link_dstpool,
9751                         (void *)&cmd_mirror_link_poolid,
9752                         (void *)&cmd_mirror_link_on,
9753                         NULL,
9754                 },
9755 };
9756
9757 /* *** RESET VM MIRROR RULE *** */
9758 struct cmd_rm_mirror_rule_result {
9759         cmdline_fixed_string_t reset;
9760         cmdline_fixed_string_t port;
9761         portid_t port_id;
9762         cmdline_fixed_string_t mirror;
9763         uint8_t rule_id;
9764 };
9765
9766 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9767         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9768                                  reset, "reset");
9769 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9770         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9771                                 port, "port");
9772 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9773         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9774                                 port_id, UINT16);
9775 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9776         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9777                                 mirror, "mirror-rule");
9778 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9779         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9780                                 rule_id, UINT8);
9781
9782 static void
9783 cmd_reset_mirror_rule_parsed(void *parsed_result,
9784                        __rte_unused struct cmdline *cl,
9785                        __rte_unused void *data)
9786 {
9787         int ret;
9788         struct cmd_set_mirror_link_result *res = parsed_result;
9789         /* check rule_id */
9790         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9791         if(ret < 0)
9792                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9793 }
9794
9795 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9796                 .f = cmd_reset_mirror_rule_parsed,
9797                 .data = NULL,
9798                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9799                 .tokens = {
9800                         (void *)&cmd_rm_mirror_rule_reset,
9801                         (void *)&cmd_rm_mirror_rule_port,
9802                         (void *)&cmd_rm_mirror_rule_portid,
9803                         (void *)&cmd_rm_mirror_rule_mirror,
9804                         (void *)&cmd_rm_mirror_rule_ruleid,
9805                         NULL,
9806                 },
9807 };
9808
9809 /* ******************************************************************************** */
9810
9811 struct cmd_dump_result {
9812         cmdline_fixed_string_t dump;
9813 };
9814
9815 static void
9816 dump_struct_sizes(void)
9817 {
9818 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9819         DUMP_SIZE(struct rte_mbuf);
9820         DUMP_SIZE(struct rte_mempool);
9821         DUMP_SIZE(struct rte_ring);
9822 #undef DUMP_SIZE
9823 }
9824
9825
9826 /* Dump the socket memory statistics on console */
9827 static void
9828 dump_socket_mem(FILE *f)
9829 {
9830         struct rte_malloc_socket_stats socket_stats;
9831         unsigned int i;
9832         size_t total = 0;
9833         size_t alloc = 0;
9834         size_t free = 0;
9835         unsigned int n_alloc = 0;
9836         unsigned int n_free = 0;
9837         static size_t last_allocs;
9838         static size_t last_total;
9839
9840
9841         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9842                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9843                     !socket_stats.heap_totalsz_bytes)
9844                         continue;
9845                 total += socket_stats.heap_totalsz_bytes;
9846                 alloc += socket_stats.heap_allocsz_bytes;
9847                 free += socket_stats.heap_freesz_bytes;
9848                 n_alloc += socket_stats.alloc_count;
9849                 n_free += socket_stats.free_count;
9850                 fprintf(f,
9851                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9852                         i,
9853                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9854                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9855                         (double)socket_stats.heap_allocsz_bytes * 100 /
9856                         (double)socket_stats.heap_totalsz_bytes,
9857                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9858                         socket_stats.alloc_count,
9859                         socket_stats.free_count);
9860         }
9861         fprintf(f,
9862                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9863                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9864                 (double)alloc * 100 / (double)total,
9865                 (double)free / (1024 * 1024),
9866                 n_alloc, n_free);
9867         if (last_allocs)
9868                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9869                         ((double)total - (double)last_total) / (1024 * 1024),
9870                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9871         last_allocs = alloc;
9872         last_total = total;
9873 }
9874
9875 static void cmd_dump_parsed(void *parsed_result,
9876                             __rte_unused struct cmdline *cl,
9877                             __rte_unused void *data)
9878 {
9879         struct cmd_dump_result *res = parsed_result;
9880
9881         if (!strcmp(res->dump, "dump_physmem"))
9882                 rte_dump_physmem_layout(stdout);
9883         else if (!strcmp(res->dump, "dump_socket_mem"))
9884                 dump_socket_mem(stdout);
9885         else if (!strcmp(res->dump, "dump_memzone"))
9886                 rte_memzone_dump(stdout);
9887         else if (!strcmp(res->dump, "dump_struct_sizes"))
9888                 dump_struct_sizes();
9889         else if (!strcmp(res->dump, "dump_ring"))
9890                 rte_ring_list_dump(stdout);
9891         else if (!strcmp(res->dump, "dump_mempool"))
9892                 rte_mempool_list_dump(stdout);
9893         else if (!strcmp(res->dump, "dump_devargs"))
9894                 rte_devargs_dump(stdout);
9895         else if (!strcmp(res->dump, "dump_log_types"))
9896                 rte_log_dump(stdout);
9897 }
9898
9899 cmdline_parse_token_string_t cmd_dump_dump =
9900         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9901                 "dump_physmem#"
9902                 "dump_memzone#"
9903                 "dump_socket_mem#"
9904                 "dump_struct_sizes#"
9905                 "dump_ring#"
9906                 "dump_mempool#"
9907                 "dump_devargs#"
9908                 "dump_log_types");
9909
9910 cmdline_parse_inst_t cmd_dump = {
9911         .f = cmd_dump_parsed,  /* function to call */
9912         .data = NULL,      /* 2nd arg of func */
9913         .help_str = "Dump status",
9914         .tokens = {        /* token list, NULL terminated */
9915                 (void *)&cmd_dump_dump,
9916                 NULL,
9917         },
9918 };
9919
9920 /* ******************************************************************************** */
9921
9922 struct cmd_dump_one_result {
9923         cmdline_fixed_string_t dump;
9924         cmdline_fixed_string_t name;
9925 };
9926
9927 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9928                                 __rte_unused void *data)
9929 {
9930         struct cmd_dump_one_result *res = parsed_result;
9931
9932         if (!strcmp(res->dump, "dump_ring")) {
9933                 struct rte_ring *r;
9934                 r = rte_ring_lookup(res->name);
9935                 if (r == NULL) {
9936                         cmdline_printf(cl, "Cannot find ring\n");
9937                         return;
9938                 }
9939                 rte_ring_dump(stdout, r);
9940         } else if (!strcmp(res->dump, "dump_mempool")) {
9941                 struct rte_mempool *mp;
9942                 mp = rte_mempool_lookup(res->name);
9943                 if (mp == NULL) {
9944                         cmdline_printf(cl, "Cannot find mempool\n");
9945                         return;
9946                 }
9947                 rte_mempool_dump(stdout, mp);
9948         }
9949 }
9950
9951 cmdline_parse_token_string_t cmd_dump_one_dump =
9952         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9953                                  "dump_ring#dump_mempool");
9954
9955 cmdline_parse_token_string_t cmd_dump_one_name =
9956         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9957
9958 cmdline_parse_inst_t cmd_dump_one = {
9959         .f = cmd_dump_one_parsed,  /* function to call */
9960         .data = NULL,      /* 2nd arg of func */
9961         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9962         .tokens = {        /* token list, NULL terminated */
9963                 (void *)&cmd_dump_one_dump,
9964                 (void *)&cmd_dump_one_name,
9965                 NULL,
9966         },
9967 };
9968
9969 /* *** Add/Del syn filter *** */
9970 struct cmd_syn_filter_result {
9971         cmdline_fixed_string_t filter;
9972         portid_t port_id;
9973         cmdline_fixed_string_t ops;
9974         cmdline_fixed_string_t priority;
9975         cmdline_fixed_string_t high;
9976         cmdline_fixed_string_t queue;
9977         uint16_t queue_id;
9978 };
9979
9980 static void
9981 cmd_syn_filter_parsed(void *parsed_result,
9982                         __rte_unused struct cmdline *cl,
9983                         __rte_unused void *data)
9984 {
9985         struct cmd_syn_filter_result *res = parsed_result;
9986         struct rte_eth_syn_filter syn_filter;
9987         int ret = 0;
9988
9989         ret = rte_eth_dev_filter_supported(res->port_id,
9990                                         RTE_ETH_FILTER_SYN);
9991         if (ret < 0) {
9992                 printf("syn filter is not supported on port %u.\n",
9993                                 res->port_id);
9994                 return;
9995         }
9996
9997         memset(&syn_filter, 0, sizeof(syn_filter));
9998
9999         if (!strcmp(res->ops, "add")) {
10000                 if (!strcmp(res->high, "high"))
10001                         syn_filter.hig_pri = 1;
10002                 else
10003                         syn_filter.hig_pri = 0;
10004
10005                 syn_filter.queue = res->queue_id;
10006                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10007                                                 RTE_ETH_FILTER_SYN,
10008                                                 RTE_ETH_FILTER_ADD,
10009                                                 &syn_filter);
10010         } else
10011                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10012                                                 RTE_ETH_FILTER_SYN,
10013                                                 RTE_ETH_FILTER_DELETE,
10014                                                 &syn_filter);
10015
10016         if (ret < 0)
10017                 printf("syn filter programming error: (%s)\n",
10018                                 strerror(-ret));
10019 }
10020
10021 cmdline_parse_token_string_t cmd_syn_filter_filter =
10022         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10023         filter, "syn_filter");
10024 cmdline_parse_token_num_t cmd_syn_filter_port_id =
10025         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10026         port_id, UINT16);
10027 cmdline_parse_token_string_t cmd_syn_filter_ops =
10028         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10029         ops, "add#del");
10030 cmdline_parse_token_string_t cmd_syn_filter_priority =
10031         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10032                                 priority, "priority");
10033 cmdline_parse_token_string_t cmd_syn_filter_high =
10034         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10035                                 high, "high#low");
10036 cmdline_parse_token_string_t cmd_syn_filter_queue =
10037         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10038                                 queue, "queue");
10039 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
10040         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10041                                 queue_id, UINT16);
10042
10043 cmdline_parse_inst_t cmd_syn_filter = {
10044         .f = cmd_syn_filter_parsed,
10045         .data = NULL,
10046         .help_str = "syn_filter <port_id> add|del priority high|low queue "
10047                 "<queue_id>: Add/Delete syn filter",
10048         .tokens = {
10049                 (void *)&cmd_syn_filter_filter,
10050                 (void *)&cmd_syn_filter_port_id,
10051                 (void *)&cmd_syn_filter_ops,
10052                 (void *)&cmd_syn_filter_priority,
10053                 (void *)&cmd_syn_filter_high,
10054                 (void *)&cmd_syn_filter_queue,
10055                 (void *)&cmd_syn_filter_queue_id,
10056                 NULL,
10057         },
10058 };
10059
10060 /* *** queue region set *** */
10061 struct cmd_queue_region_result {
10062         cmdline_fixed_string_t set;
10063         cmdline_fixed_string_t port;
10064         portid_t port_id;
10065         cmdline_fixed_string_t cmd;
10066         cmdline_fixed_string_t region;
10067         uint8_t  region_id;
10068         cmdline_fixed_string_t queue_start_index;
10069         uint8_t  queue_id;
10070         cmdline_fixed_string_t queue_num;
10071         uint8_t  queue_num_value;
10072 };
10073
10074 static void
10075 cmd_queue_region_parsed(void *parsed_result,
10076                         __rte_unused struct cmdline *cl,
10077                         __rte_unused void *data)
10078 {
10079         struct cmd_queue_region_result *res = parsed_result;
10080         int ret = -ENOTSUP;
10081 #ifdef RTE_LIBRTE_I40E_PMD
10082         struct rte_pmd_i40e_queue_region_conf region_conf;
10083         enum rte_pmd_i40e_queue_region_op op_type;
10084 #endif
10085
10086         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10087                 return;
10088
10089 #ifdef RTE_LIBRTE_I40E_PMD
10090         memset(&region_conf, 0, sizeof(region_conf));
10091         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10092         region_conf.region_id = res->region_id;
10093         region_conf.queue_num = res->queue_num_value;
10094         region_conf.queue_start_index = res->queue_id;
10095
10096         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10097                                 op_type, &region_conf);
10098 #endif
10099
10100         switch (ret) {
10101         case 0:
10102                 break;
10103         case -ENOTSUP:
10104                 printf("function not implemented or supported\n");
10105                 break;
10106         default:
10107                 printf("queue region config error: (%s)\n", strerror(-ret));
10108         }
10109 }
10110
10111 cmdline_parse_token_string_t cmd_queue_region_set =
10112 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10113                 set, "set");
10114 cmdline_parse_token_string_t cmd_queue_region_port =
10115         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10116 cmdline_parse_token_num_t cmd_queue_region_port_id =
10117         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10118                                 port_id, UINT16);
10119 cmdline_parse_token_string_t cmd_queue_region_cmd =
10120         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10121                                  cmd, "queue-region");
10122 cmdline_parse_token_string_t cmd_queue_region_id =
10123         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10124                                 region, "region_id");
10125 cmdline_parse_token_num_t cmd_queue_region_index =
10126         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10127                                 region_id, UINT8);
10128 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10129         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10130                                 queue_start_index, "queue_start_index");
10131 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10132         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10133                                 queue_id, UINT8);
10134 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10135         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10136                                 queue_num, "queue_num");
10137 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10138         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10139                                 queue_num_value, UINT8);
10140
10141 cmdline_parse_inst_t cmd_queue_region = {
10142         .f = cmd_queue_region_parsed,
10143         .data = NULL,
10144         .help_str = "set port <port_id> queue-region region_id <value> "
10145                 "queue_start_index <value> queue_num <value>: Set a queue region",
10146         .tokens = {
10147                 (void *)&cmd_queue_region_set,
10148                 (void *)&cmd_queue_region_port,
10149                 (void *)&cmd_queue_region_port_id,
10150                 (void *)&cmd_queue_region_cmd,
10151                 (void *)&cmd_queue_region_id,
10152                 (void *)&cmd_queue_region_index,
10153                 (void *)&cmd_queue_region_queue_start_index,
10154                 (void *)&cmd_queue_region_queue_id,
10155                 (void *)&cmd_queue_region_queue_num,
10156                 (void *)&cmd_queue_region_queue_num_value,
10157                 NULL,
10158         },
10159 };
10160
10161 /* *** queue region and flowtype set *** */
10162 struct cmd_region_flowtype_result {
10163         cmdline_fixed_string_t set;
10164         cmdline_fixed_string_t port;
10165         portid_t port_id;
10166         cmdline_fixed_string_t cmd;
10167         cmdline_fixed_string_t region;
10168         uint8_t  region_id;
10169         cmdline_fixed_string_t flowtype;
10170         uint8_t  flowtype_id;
10171 };
10172
10173 static void
10174 cmd_region_flowtype_parsed(void *parsed_result,
10175                         __rte_unused struct cmdline *cl,
10176                         __rte_unused void *data)
10177 {
10178         struct cmd_region_flowtype_result *res = parsed_result;
10179         int ret = -ENOTSUP;
10180 #ifdef RTE_LIBRTE_I40E_PMD
10181         struct rte_pmd_i40e_queue_region_conf region_conf;
10182         enum rte_pmd_i40e_queue_region_op op_type;
10183 #endif
10184
10185         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10186                 return;
10187
10188 #ifdef RTE_LIBRTE_I40E_PMD
10189         memset(&region_conf, 0, sizeof(region_conf));
10190
10191         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10192         region_conf.region_id = res->region_id;
10193         region_conf.hw_flowtype = res->flowtype_id;
10194
10195         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10196                         op_type, &region_conf);
10197 #endif
10198
10199         switch (ret) {
10200         case 0:
10201                 break;
10202         case -ENOTSUP:
10203                 printf("function not implemented or supported\n");
10204                 break;
10205         default:
10206                 printf("region flowtype config error: (%s)\n", strerror(-ret));
10207         }
10208 }
10209
10210 cmdline_parse_token_string_t cmd_region_flowtype_set =
10211 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10212                                 set, "set");
10213 cmdline_parse_token_string_t cmd_region_flowtype_port =
10214         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10215                                 port, "port");
10216 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10217         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10218                                 port_id, UINT16);
10219 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10220         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10221                                 cmd, "queue-region");
10222 cmdline_parse_token_string_t cmd_region_flowtype_index =
10223         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10224                                 region, "region_id");
10225 cmdline_parse_token_num_t cmd_region_flowtype_id =
10226         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10227                                 region_id, UINT8);
10228 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10229         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10230                                 flowtype, "flowtype");
10231 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10232         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10233                                 flowtype_id, UINT8);
10234 cmdline_parse_inst_t cmd_region_flowtype = {
10235         .f = cmd_region_flowtype_parsed,
10236         .data = NULL,
10237         .help_str = "set port <port_id> queue-region region_id <value> "
10238                 "flowtype <value>: Set a flowtype region index",
10239         .tokens = {
10240                 (void *)&cmd_region_flowtype_set,
10241                 (void *)&cmd_region_flowtype_port,
10242                 (void *)&cmd_region_flowtype_port_index,
10243                 (void *)&cmd_region_flowtype_cmd,
10244                 (void *)&cmd_region_flowtype_index,
10245                 (void *)&cmd_region_flowtype_id,
10246                 (void *)&cmd_region_flowtype_flow_index,
10247                 (void *)&cmd_region_flowtype_flow_id,
10248                 NULL,
10249         },
10250 };
10251
10252 /* *** User Priority (UP) to queue region (region_id) set *** */
10253 struct cmd_user_priority_region_result {
10254         cmdline_fixed_string_t set;
10255         cmdline_fixed_string_t port;
10256         portid_t port_id;
10257         cmdline_fixed_string_t cmd;
10258         cmdline_fixed_string_t user_priority;
10259         uint8_t  user_priority_id;
10260         cmdline_fixed_string_t region;
10261         uint8_t  region_id;
10262 };
10263
10264 static void
10265 cmd_user_priority_region_parsed(void *parsed_result,
10266                         __rte_unused struct cmdline *cl,
10267                         __rte_unused void *data)
10268 {
10269         struct cmd_user_priority_region_result *res = parsed_result;
10270         int ret = -ENOTSUP;
10271 #ifdef RTE_LIBRTE_I40E_PMD
10272         struct rte_pmd_i40e_queue_region_conf region_conf;
10273         enum rte_pmd_i40e_queue_region_op op_type;
10274 #endif
10275
10276         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10277                 return;
10278
10279 #ifdef RTE_LIBRTE_I40E_PMD
10280         memset(&region_conf, 0, sizeof(region_conf));
10281         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10282         region_conf.user_priority = res->user_priority_id;
10283         region_conf.region_id = res->region_id;
10284
10285         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10286                                 op_type, &region_conf);
10287 #endif
10288
10289         switch (ret) {
10290         case 0:
10291                 break;
10292         case -ENOTSUP:
10293                 printf("function not implemented or supported\n");
10294                 break;
10295         default:
10296                 printf("user_priority region config error: (%s)\n",
10297                                 strerror(-ret));
10298         }
10299 }
10300
10301 cmdline_parse_token_string_t cmd_user_priority_region_set =
10302         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10303                                 set, "set");
10304 cmdline_parse_token_string_t cmd_user_priority_region_port =
10305         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10306                                 port, "port");
10307 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10308         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10309                                 port_id, UINT16);
10310 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10311         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10312                                 cmd, "queue-region");
10313 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10314         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10315                                 user_priority, "UP");
10316 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10317         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10318                                 user_priority_id, UINT8);
10319 cmdline_parse_token_string_t cmd_user_priority_region_region =
10320         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10321                                 region, "region_id");
10322 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10323         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10324                                 region_id, UINT8);
10325
10326 cmdline_parse_inst_t cmd_user_priority_region = {
10327         .f = cmd_user_priority_region_parsed,
10328         .data = NULL,
10329         .help_str = "set port <port_id> queue-region UP <value> "
10330                 "region_id <value>: Set the mapping of User Priority (UP) "
10331                 "to queue region (region_id) ",
10332         .tokens = {
10333                 (void *)&cmd_user_priority_region_set,
10334                 (void *)&cmd_user_priority_region_port,
10335                 (void *)&cmd_user_priority_region_port_index,
10336                 (void *)&cmd_user_priority_region_cmd,
10337                 (void *)&cmd_user_priority_region_UP,
10338                 (void *)&cmd_user_priority_region_UP_id,
10339                 (void *)&cmd_user_priority_region_region,
10340                 (void *)&cmd_user_priority_region_region_id,
10341                 NULL,
10342         },
10343 };
10344
10345 /* *** flush all queue region related configuration *** */
10346 struct cmd_flush_queue_region_result {
10347         cmdline_fixed_string_t set;
10348         cmdline_fixed_string_t port;
10349         portid_t port_id;
10350         cmdline_fixed_string_t cmd;
10351         cmdline_fixed_string_t flush;
10352         cmdline_fixed_string_t what;
10353 };
10354
10355 static void
10356 cmd_flush_queue_region_parsed(void *parsed_result,
10357                         __rte_unused struct cmdline *cl,
10358                         __rte_unused void *data)
10359 {
10360         struct cmd_flush_queue_region_result *res = parsed_result;
10361         int ret = -ENOTSUP;
10362 #ifdef RTE_LIBRTE_I40E_PMD
10363         struct rte_pmd_i40e_queue_region_conf region_conf;
10364         enum rte_pmd_i40e_queue_region_op op_type;
10365 #endif
10366
10367         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10368                 return;
10369
10370 #ifdef RTE_LIBRTE_I40E_PMD
10371         memset(&region_conf, 0, sizeof(region_conf));
10372
10373         if (strcmp(res->what, "on") == 0)
10374                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10375         else
10376                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10377
10378         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10379                                 op_type, &region_conf);
10380 #endif
10381
10382         switch (ret) {
10383         case 0:
10384                 break;
10385         case -ENOTSUP:
10386                 printf("function not implemented or supported\n");
10387                 break;
10388         default:
10389                 printf("queue region config flush error: (%s)\n",
10390                                 strerror(-ret));
10391         }
10392 }
10393
10394 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10395         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10396                                 set, "set");
10397 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10398         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10399                                 port, "port");
10400 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10401         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10402                                 port_id, UINT16);
10403 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10404         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10405                                 cmd, "queue-region");
10406 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10407         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10408                                 flush, "flush");
10409 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10410         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10411                                 what, "on#off");
10412
10413 cmdline_parse_inst_t cmd_flush_queue_region = {
10414         .f = cmd_flush_queue_region_parsed,
10415         .data = NULL,
10416         .help_str = "set port <port_id> queue-region flush on|off"
10417                 ": flush all queue region related configuration",
10418         .tokens = {
10419                 (void *)&cmd_flush_queue_region_set,
10420                 (void *)&cmd_flush_queue_region_port,
10421                 (void *)&cmd_flush_queue_region_port_index,
10422                 (void *)&cmd_flush_queue_region_cmd,
10423                 (void *)&cmd_flush_queue_region_flush,
10424                 (void *)&cmd_flush_queue_region_what,
10425                 NULL,
10426         },
10427 };
10428
10429 /* *** get all queue region related configuration info *** */
10430 struct cmd_show_queue_region_info {
10431         cmdline_fixed_string_t show;
10432         cmdline_fixed_string_t port;
10433         portid_t port_id;
10434         cmdline_fixed_string_t cmd;
10435 };
10436
10437 static void
10438 cmd_show_queue_region_info_parsed(void *parsed_result,
10439                         __rte_unused struct cmdline *cl,
10440                         __rte_unused void *data)
10441 {
10442         struct cmd_show_queue_region_info *res = parsed_result;
10443         int ret = -ENOTSUP;
10444 #ifdef RTE_LIBRTE_I40E_PMD
10445         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10446         enum rte_pmd_i40e_queue_region_op op_type;
10447 #endif
10448
10449         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10450                 return;
10451
10452 #ifdef RTE_LIBRTE_I40E_PMD
10453         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10454
10455         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10456
10457         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10458                                         op_type, &rte_pmd_regions);
10459
10460         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10461 #endif
10462
10463         switch (ret) {
10464         case 0:
10465                 break;
10466         case -ENOTSUP:
10467                 printf("function not implemented or supported\n");
10468                 break;
10469         default:
10470                 printf("queue region config info show error: (%s)\n",
10471                                 strerror(-ret));
10472         }
10473 }
10474
10475 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10476 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10477                                 show, "show");
10478 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10479         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10480                                 port, "port");
10481 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10482         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10483                                 port_id, UINT16);
10484 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10485         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10486                                 cmd, "queue-region");
10487
10488 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10489         .f = cmd_show_queue_region_info_parsed,
10490         .data = NULL,
10491         .help_str = "show port <port_id> queue-region"
10492                 ": show all queue region related configuration info",
10493         .tokens = {
10494                 (void *)&cmd_show_queue_region_info_get,
10495                 (void *)&cmd_show_queue_region_info_port,
10496                 (void *)&cmd_show_queue_region_info_port_index,
10497                 (void *)&cmd_show_queue_region_info_cmd,
10498                 NULL,
10499         },
10500 };
10501
10502 /* *** ADD/REMOVE A 2tuple FILTER *** */
10503 struct cmd_2tuple_filter_result {
10504         cmdline_fixed_string_t filter;
10505         portid_t port_id;
10506         cmdline_fixed_string_t ops;
10507         cmdline_fixed_string_t dst_port;
10508         uint16_t dst_port_value;
10509         cmdline_fixed_string_t protocol;
10510         uint8_t protocol_value;
10511         cmdline_fixed_string_t mask;
10512         uint8_t  mask_value;
10513         cmdline_fixed_string_t tcp_flags;
10514         uint8_t tcp_flags_value;
10515         cmdline_fixed_string_t priority;
10516         uint8_t  priority_value;
10517         cmdline_fixed_string_t queue;
10518         uint16_t  queue_id;
10519 };
10520
10521 static void
10522 cmd_2tuple_filter_parsed(void *parsed_result,
10523                         __rte_unused struct cmdline *cl,
10524                         __rte_unused void *data)
10525 {
10526         struct rte_eth_ntuple_filter filter;
10527         struct cmd_2tuple_filter_result *res = parsed_result;
10528         int ret = 0;
10529
10530         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10531         if (ret < 0) {
10532                 printf("ntuple filter is not supported on port %u.\n",
10533                         res->port_id);
10534                 return;
10535         }
10536
10537         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10538
10539         filter.flags = RTE_2TUPLE_FLAGS;
10540         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10541         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10542         filter.proto = res->protocol_value;
10543         filter.priority = res->priority_value;
10544         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10545                 printf("nonzero tcp_flags is only meaningful"
10546                         " when protocol is TCP.\n");
10547                 return;
10548         }
10549         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10550                 printf("invalid TCP flags.\n");
10551                 return;
10552         }
10553
10554         if (res->tcp_flags_value != 0) {
10555                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10556                 filter.tcp_flags = res->tcp_flags_value;
10557         }
10558
10559         /* need convert to big endian. */
10560         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10561         filter.queue = res->queue_id;
10562
10563         if (!strcmp(res->ops, "add"))
10564                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10565                                 RTE_ETH_FILTER_NTUPLE,
10566                                 RTE_ETH_FILTER_ADD,
10567                                 &filter);
10568         else
10569                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10570                                 RTE_ETH_FILTER_NTUPLE,
10571                                 RTE_ETH_FILTER_DELETE,
10572                                 &filter);
10573         if (ret < 0)
10574                 printf("2tuple filter programming error: (%s)\n",
10575                         strerror(-ret));
10576
10577 }
10578
10579 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10580         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10581                                  filter, "2tuple_filter");
10582 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10583         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10584                                 port_id, UINT16);
10585 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10586         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10587                                  ops, "add#del");
10588 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10589         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10590                                 dst_port, "dst_port");
10591 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10592         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10593                                 dst_port_value, UINT16);
10594 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10595         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10596                                 protocol, "protocol");
10597 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10598         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10599                                 protocol_value, UINT8);
10600 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10601         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10602                                 mask, "mask");
10603 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10604         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10605                                 mask_value, INT8);
10606 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10607         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10608                                 tcp_flags, "tcp_flags");
10609 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10610         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10611                                 tcp_flags_value, UINT8);
10612 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10613         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10614                                 priority, "priority");
10615 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10616         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10617                                 priority_value, UINT8);
10618 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10619         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10620                                 queue, "queue");
10621 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10622         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10623                                 queue_id, UINT16);
10624
10625 cmdline_parse_inst_t cmd_2tuple_filter = {
10626         .f = cmd_2tuple_filter_parsed,
10627         .data = NULL,
10628         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10629                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10630                 "<queue_id>: Add a 2tuple filter",
10631         .tokens = {
10632                 (void *)&cmd_2tuple_filter_filter,
10633                 (void *)&cmd_2tuple_filter_port_id,
10634                 (void *)&cmd_2tuple_filter_ops,
10635                 (void *)&cmd_2tuple_filter_dst_port,
10636                 (void *)&cmd_2tuple_filter_dst_port_value,
10637                 (void *)&cmd_2tuple_filter_protocol,
10638                 (void *)&cmd_2tuple_filter_protocol_value,
10639                 (void *)&cmd_2tuple_filter_mask,
10640                 (void *)&cmd_2tuple_filter_mask_value,
10641                 (void *)&cmd_2tuple_filter_tcp_flags,
10642                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10643                 (void *)&cmd_2tuple_filter_priority,
10644                 (void *)&cmd_2tuple_filter_priority_value,
10645                 (void *)&cmd_2tuple_filter_queue,
10646                 (void *)&cmd_2tuple_filter_queue_id,
10647                 NULL,
10648         },
10649 };
10650
10651 /* *** ADD/REMOVE A 5tuple FILTER *** */
10652 struct cmd_5tuple_filter_result {
10653         cmdline_fixed_string_t filter;
10654         portid_t port_id;
10655         cmdline_fixed_string_t ops;
10656         cmdline_fixed_string_t dst_ip;
10657         cmdline_ipaddr_t dst_ip_value;
10658         cmdline_fixed_string_t src_ip;
10659         cmdline_ipaddr_t src_ip_value;
10660         cmdline_fixed_string_t dst_port;
10661         uint16_t dst_port_value;
10662         cmdline_fixed_string_t src_port;
10663         uint16_t src_port_value;
10664         cmdline_fixed_string_t protocol;
10665         uint8_t protocol_value;
10666         cmdline_fixed_string_t mask;
10667         uint8_t  mask_value;
10668         cmdline_fixed_string_t tcp_flags;
10669         uint8_t tcp_flags_value;
10670         cmdline_fixed_string_t priority;
10671         uint8_t  priority_value;
10672         cmdline_fixed_string_t queue;
10673         uint16_t  queue_id;
10674 };
10675
10676 static void
10677 cmd_5tuple_filter_parsed(void *parsed_result,
10678                         __rte_unused struct cmdline *cl,
10679                         __rte_unused void *data)
10680 {
10681         struct rte_eth_ntuple_filter filter;
10682         struct cmd_5tuple_filter_result *res = parsed_result;
10683         int ret = 0;
10684
10685         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10686         if (ret < 0) {
10687                 printf("ntuple filter is not supported on port %u.\n",
10688                         res->port_id);
10689                 return;
10690         }
10691
10692         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10693
10694         filter.flags = RTE_5TUPLE_FLAGS;
10695         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10696         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10697         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10698         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10699         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10700         filter.proto = res->protocol_value;
10701         filter.priority = res->priority_value;
10702         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10703                 printf("nonzero tcp_flags is only meaningful"
10704                         " when protocol is TCP.\n");
10705                 return;
10706         }
10707         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10708                 printf("invalid TCP flags.\n");
10709                 return;
10710         }
10711
10712         if (res->tcp_flags_value != 0) {
10713                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10714                 filter.tcp_flags = res->tcp_flags_value;
10715         }
10716
10717         if (res->dst_ip_value.family == AF_INET)
10718                 /* no need to convert, already big endian. */
10719                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10720         else {
10721                 if (filter.dst_ip_mask == 0) {
10722                         printf("can not support ipv6 involved compare.\n");
10723                         return;
10724                 }
10725                 filter.dst_ip = 0;
10726         }
10727
10728         if (res->src_ip_value.family == AF_INET)
10729                 /* no need to convert, already big endian. */
10730                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10731         else {
10732                 if (filter.src_ip_mask == 0) {
10733                         printf("can not support ipv6 involved compare.\n");
10734                         return;
10735                 }
10736                 filter.src_ip = 0;
10737         }
10738         /* need convert to big endian. */
10739         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10740         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10741         filter.queue = res->queue_id;
10742
10743         if (!strcmp(res->ops, "add"))
10744                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10745                                 RTE_ETH_FILTER_NTUPLE,
10746                                 RTE_ETH_FILTER_ADD,
10747                                 &filter);
10748         else
10749                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10750                                 RTE_ETH_FILTER_NTUPLE,
10751                                 RTE_ETH_FILTER_DELETE,
10752                                 &filter);
10753         if (ret < 0)
10754                 printf("5tuple filter programming error: (%s)\n",
10755                         strerror(-ret));
10756 }
10757
10758 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10759         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10760                                  filter, "5tuple_filter");
10761 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10762         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10763                                 port_id, UINT16);
10764 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10765         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10766                                  ops, "add#del");
10767 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10768         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10769                                 dst_ip, "dst_ip");
10770 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10771         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10772                                 dst_ip_value);
10773 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10774         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10775                                 src_ip, "src_ip");
10776 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10777         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10778                                 src_ip_value);
10779 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10780         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10781                                 dst_port, "dst_port");
10782 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10783         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10784                                 dst_port_value, UINT16);
10785 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10786         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10787                                 src_port, "src_port");
10788 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10789         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10790                                 src_port_value, UINT16);
10791 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10792         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10793                                 protocol, "protocol");
10794 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10795         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10796                                 protocol_value, UINT8);
10797 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10798         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10799                                 mask, "mask");
10800 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10801         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10802                                 mask_value, INT8);
10803 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10804         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10805                                 tcp_flags, "tcp_flags");
10806 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10807         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10808                                 tcp_flags_value, UINT8);
10809 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10810         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10811                                 priority, "priority");
10812 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10813         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10814                                 priority_value, UINT8);
10815 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10816         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10817                                 queue, "queue");
10818 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10819         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10820                                 queue_id, UINT16);
10821
10822 cmdline_parse_inst_t cmd_5tuple_filter = {
10823         .f = cmd_5tuple_filter_parsed,
10824         .data = NULL,
10825         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10826                 "src_ip <value> dst_port <value> src_port <value> "
10827                 "protocol <value>  mask <value> tcp_flags <value> "
10828                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10829         .tokens = {
10830                 (void *)&cmd_5tuple_filter_filter,
10831                 (void *)&cmd_5tuple_filter_port_id,
10832                 (void *)&cmd_5tuple_filter_ops,
10833                 (void *)&cmd_5tuple_filter_dst_ip,
10834                 (void *)&cmd_5tuple_filter_dst_ip_value,
10835                 (void *)&cmd_5tuple_filter_src_ip,
10836                 (void *)&cmd_5tuple_filter_src_ip_value,
10837                 (void *)&cmd_5tuple_filter_dst_port,
10838                 (void *)&cmd_5tuple_filter_dst_port_value,
10839                 (void *)&cmd_5tuple_filter_src_port,
10840                 (void *)&cmd_5tuple_filter_src_port_value,
10841                 (void *)&cmd_5tuple_filter_protocol,
10842                 (void *)&cmd_5tuple_filter_protocol_value,
10843                 (void *)&cmd_5tuple_filter_mask,
10844                 (void *)&cmd_5tuple_filter_mask_value,
10845                 (void *)&cmd_5tuple_filter_tcp_flags,
10846                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10847                 (void *)&cmd_5tuple_filter_priority,
10848                 (void *)&cmd_5tuple_filter_priority_value,
10849                 (void *)&cmd_5tuple_filter_queue,
10850                 (void *)&cmd_5tuple_filter_queue_id,
10851                 NULL,
10852         },
10853 };
10854
10855 /* *** ADD/REMOVE A flex FILTER *** */
10856 struct cmd_flex_filter_result {
10857         cmdline_fixed_string_t filter;
10858         cmdline_fixed_string_t ops;
10859         portid_t port_id;
10860         cmdline_fixed_string_t len;
10861         uint8_t len_value;
10862         cmdline_fixed_string_t bytes;
10863         cmdline_fixed_string_t bytes_value;
10864         cmdline_fixed_string_t mask;
10865         cmdline_fixed_string_t mask_value;
10866         cmdline_fixed_string_t priority;
10867         uint8_t priority_value;
10868         cmdline_fixed_string_t queue;
10869         uint16_t queue_id;
10870 };
10871
10872 static int xdigit2val(unsigned char c)
10873 {
10874         int val;
10875         if (isdigit(c))
10876                 val = c - '0';
10877         else if (isupper(c))
10878                 val = c - 'A' + 10;
10879         else
10880                 val = c - 'a' + 10;
10881         return val;
10882 }
10883
10884 static void
10885 cmd_flex_filter_parsed(void *parsed_result,
10886                           __rte_unused struct cmdline *cl,
10887                           __rte_unused void *data)
10888 {
10889         int ret = 0;
10890         struct rte_eth_flex_filter filter;
10891         struct cmd_flex_filter_result *res = parsed_result;
10892         char *bytes_ptr, *mask_ptr;
10893         uint16_t len, i, j = 0;
10894         char c;
10895         int val;
10896         uint8_t byte = 0;
10897
10898         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10899                 printf("the len exceed the max length 128\n");
10900                 return;
10901         }
10902         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10903         filter.len = res->len_value;
10904         filter.priority = res->priority_value;
10905         filter.queue = res->queue_id;
10906         bytes_ptr = res->bytes_value;
10907         mask_ptr = res->mask_value;
10908
10909          /* translate bytes string to array. */
10910         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10911                 (bytes_ptr[1] == 'X')))
10912                 bytes_ptr += 2;
10913         len = strnlen(bytes_ptr, res->len_value * 2);
10914         if (len == 0 || (len % 8 != 0)) {
10915                 printf("please check len and bytes input\n");
10916                 return;
10917         }
10918         for (i = 0; i < len; i++) {
10919                 c = bytes_ptr[i];
10920                 if (isxdigit(c) == 0) {
10921                         /* invalid characters. */
10922                         printf("invalid input\n");
10923                         return;
10924                 }
10925                 val = xdigit2val(c);
10926                 if (i % 2) {
10927                         byte |= val;
10928                         filter.bytes[j] = byte;
10929                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10930                         j++;
10931                         byte = 0;
10932                 } else
10933                         byte |= val << 4;
10934         }
10935         printf("\n");
10936          /* translate mask string to uint8_t array. */
10937         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10938                 (mask_ptr[1] == 'X')))
10939                 mask_ptr += 2;
10940         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10941         if (len == 0) {
10942                 printf("invalid input\n");
10943                 return;
10944         }
10945         j = 0;
10946         byte = 0;
10947         for (i = 0; i < len; i++) {
10948                 c = mask_ptr[i];
10949                 if (isxdigit(c) == 0) {
10950                         /* invalid characters. */
10951                         printf("invalid input\n");
10952                         return;
10953                 }
10954                 val = xdigit2val(c);
10955                 if (i % 2) {
10956                         byte |= val;
10957                         filter.mask[j] = byte;
10958                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10959                         j++;
10960                         byte = 0;
10961                 } else
10962                         byte |= val << 4;
10963         }
10964         printf("\n");
10965
10966         if (!strcmp(res->ops, "add"))
10967                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10968                                 RTE_ETH_FILTER_FLEXIBLE,
10969                                 RTE_ETH_FILTER_ADD,
10970                                 &filter);
10971         else
10972                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10973                                 RTE_ETH_FILTER_FLEXIBLE,
10974                                 RTE_ETH_FILTER_DELETE,
10975                                 &filter);
10976
10977         if (ret < 0)
10978                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10979 }
10980
10981 cmdline_parse_token_string_t cmd_flex_filter_filter =
10982         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10983                                 filter, "flex_filter");
10984 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10985         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10986                                 port_id, UINT16);
10987 cmdline_parse_token_string_t cmd_flex_filter_ops =
10988         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10989                                 ops, "add#del");
10990 cmdline_parse_token_string_t cmd_flex_filter_len =
10991         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10992                                 len, "len");
10993 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10994         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10995                                 len_value, UINT8);
10996 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10997         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10998                                 bytes, "bytes");
10999 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
11000         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11001                                 bytes_value, NULL);
11002 cmdline_parse_token_string_t cmd_flex_filter_mask =
11003         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11004                                 mask, "mask");
11005 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
11006         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11007                                 mask_value, NULL);
11008 cmdline_parse_token_string_t cmd_flex_filter_priority =
11009         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11010                                 priority, "priority");
11011 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
11012         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11013                                 priority_value, UINT8);
11014 cmdline_parse_token_string_t cmd_flex_filter_queue =
11015         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11016                                 queue, "queue");
11017 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
11018         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11019                                 queue_id, UINT16);
11020 cmdline_parse_inst_t cmd_flex_filter = {
11021         .f = cmd_flex_filter_parsed,
11022         .data = NULL,
11023         .help_str = "flex_filter <port_id> add|del len <value> bytes "
11024                 "<value> mask <value> priority <value> queue <queue_id>: "
11025                 "Add/Del a flex filter",
11026         .tokens = {
11027                 (void *)&cmd_flex_filter_filter,
11028                 (void *)&cmd_flex_filter_port_id,
11029                 (void *)&cmd_flex_filter_ops,
11030                 (void *)&cmd_flex_filter_len,
11031                 (void *)&cmd_flex_filter_len_value,
11032                 (void *)&cmd_flex_filter_bytes,
11033                 (void *)&cmd_flex_filter_bytes_value,
11034                 (void *)&cmd_flex_filter_mask,
11035                 (void *)&cmd_flex_filter_mask_value,
11036                 (void *)&cmd_flex_filter_priority,
11037                 (void *)&cmd_flex_filter_priority_value,
11038                 (void *)&cmd_flex_filter_queue,
11039                 (void *)&cmd_flex_filter_queue_id,
11040                 NULL,
11041         },
11042 };
11043
11044 /* *** Filters Control *** */
11045
11046 /* *** deal with ethertype filter *** */
11047 struct cmd_ethertype_filter_result {
11048         cmdline_fixed_string_t filter;
11049         portid_t port_id;
11050         cmdline_fixed_string_t ops;
11051         cmdline_fixed_string_t mac;
11052         struct rte_ether_addr mac_addr;
11053         cmdline_fixed_string_t ethertype;
11054         uint16_t ethertype_value;
11055         cmdline_fixed_string_t drop;
11056         cmdline_fixed_string_t queue;
11057         uint16_t  queue_id;
11058 };
11059
11060 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
11061         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11062                                  filter, "ethertype_filter");
11063 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
11064         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11065                               port_id, UINT16);
11066 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
11067         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11068                                  ops, "add#del");
11069 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
11070         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11071                                  mac, "mac_addr#mac_ignr");
11072 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
11073         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
11074                                      mac_addr);
11075 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
11076         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11077                                  ethertype, "ethertype");
11078 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
11079         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11080                               ethertype_value, UINT16);
11081 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
11082         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11083                                  drop, "drop#fwd");
11084 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
11085         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11086                                  queue, "queue");
11087 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
11088         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11089                               queue_id, UINT16);
11090
11091 static void
11092 cmd_ethertype_filter_parsed(void *parsed_result,
11093                           __rte_unused struct cmdline *cl,
11094                           __rte_unused void *data)
11095 {
11096         struct cmd_ethertype_filter_result *res = parsed_result;
11097         struct rte_eth_ethertype_filter filter;
11098         int ret = 0;
11099
11100         ret = rte_eth_dev_filter_supported(res->port_id,
11101                         RTE_ETH_FILTER_ETHERTYPE);
11102         if (ret < 0) {
11103                 printf("ethertype filter is not supported on port %u.\n",
11104                         res->port_id);
11105                 return;
11106         }
11107
11108         memset(&filter, 0, sizeof(filter));
11109         if (!strcmp(res->mac, "mac_addr")) {
11110                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
11111                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
11112                         sizeof(struct rte_ether_addr));
11113         }
11114         if (!strcmp(res->drop, "drop"))
11115                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
11116         filter.ether_type = res->ethertype_value;
11117         filter.queue = res->queue_id;
11118
11119         if (!strcmp(res->ops, "add"))
11120                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11121                                 RTE_ETH_FILTER_ETHERTYPE,
11122                                 RTE_ETH_FILTER_ADD,
11123                                 &filter);
11124         else
11125                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11126                                 RTE_ETH_FILTER_ETHERTYPE,
11127                                 RTE_ETH_FILTER_DELETE,
11128                                 &filter);
11129         if (ret < 0)
11130                 printf("ethertype filter programming error: (%s)\n",
11131                         strerror(-ret));
11132 }
11133
11134 cmdline_parse_inst_t cmd_ethertype_filter = {
11135         .f = cmd_ethertype_filter_parsed,
11136         .data = NULL,
11137         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
11138                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
11139                 "Add or delete an ethertype filter entry",
11140         .tokens = {
11141                 (void *)&cmd_ethertype_filter_filter,
11142                 (void *)&cmd_ethertype_filter_port_id,
11143                 (void *)&cmd_ethertype_filter_ops,
11144                 (void *)&cmd_ethertype_filter_mac,
11145                 (void *)&cmd_ethertype_filter_mac_addr,
11146                 (void *)&cmd_ethertype_filter_ethertype,
11147                 (void *)&cmd_ethertype_filter_ethertype_value,
11148                 (void *)&cmd_ethertype_filter_drop,
11149                 (void *)&cmd_ethertype_filter_queue,
11150                 (void *)&cmd_ethertype_filter_queue_id,
11151                 NULL,
11152         },
11153 };
11154
11155 /* *** deal with flow director filter *** */
11156 struct cmd_flow_director_result {
11157         cmdline_fixed_string_t flow_director_filter;
11158         portid_t port_id;
11159         cmdline_fixed_string_t mode;
11160         cmdline_fixed_string_t mode_value;
11161         cmdline_fixed_string_t ops;
11162         cmdline_fixed_string_t flow;
11163         cmdline_fixed_string_t flow_type;
11164         cmdline_fixed_string_t ether;
11165         uint16_t ether_type;
11166         cmdline_fixed_string_t src;
11167         cmdline_ipaddr_t ip_src;
11168         uint16_t port_src;
11169         cmdline_fixed_string_t dst;
11170         cmdline_ipaddr_t ip_dst;
11171         uint16_t port_dst;
11172         cmdline_fixed_string_t verify_tag;
11173         uint32_t verify_tag_value;
11174         cmdline_fixed_string_t tos;
11175         uint8_t tos_value;
11176         cmdline_fixed_string_t proto;
11177         uint8_t proto_value;
11178         cmdline_fixed_string_t ttl;
11179         uint8_t ttl_value;
11180         cmdline_fixed_string_t vlan;
11181         uint16_t vlan_value;
11182         cmdline_fixed_string_t flexbytes;
11183         cmdline_fixed_string_t flexbytes_value;
11184         cmdline_fixed_string_t pf_vf;
11185         cmdline_fixed_string_t drop;
11186         cmdline_fixed_string_t queue;
11187         uint16_t  queue_id;
11188         cmdline_fixed_string_t fd_id;
11189         uint32_t  fd_id_value;
11190         cmdline_fixed_string_t mac;
11191         struct rte_ether_addr mac_addr;
11192         cmdline_fixed_string_t tunnel;
11193         cmdline_fixed_string_t tunnel_type;
11194         cmdline_fixed_string_t tunnel_id;
11195         uint32_t tunnel_id_value;
11196         cmdline_fixed_string_t packet;
11197         char filepath[];
11198 };
11199
11200 static inline int
11201 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
11202 {
11203         char s[256];
11204         const char *p, *p0 = q_arg;
11205         char *end;
11206         unsigned long int_fld;
11207         char *str_fld[max_num];
11208         int i;
11209         unsigned size;
11210         int ret = -1;
11211
11212         p = strchr(p0, '(');
11213         if (p == NULL)
11214                 return -1;
11215         ++p;
11216         p0 = strchr(p, ')');
11217         if (p0 == NULL)
11218                 return -1;
11219
11220         size = p0 - p;
11221         if (size >= sizeof(s))
11222                 return -1;
11223
11224         snprintf(s, sizeof(s), "%.*s", size, p);
11225         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11226         if (ret < 0 || ret > max_num)
11227                 return -1;
11228         for (i = 0; i < ret; i++) {
11229                 errno = 0;
11230                 int_fld = strtoul(str_fld[i], &end, 0);
11231                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11232                         return -1;
11233                 flexbytes[i] = (uint8_t)int_fld;
11234         }
11235         return ret;
11236 }
11237
11238 static uint16_t
11239 str2flowtype(char *string)
11240 {
11241         uint8_t i = 0;
11242         static const struct {
11243                 char str[32];
11244                 uint16_t type;
11245         } flowtype_str[] = {
11246                 {"raw", RTE_ETH_FLOW_RAW},
11247                 {"ipv4", RTE_ETH_FLOW_IPV4},
11248                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11249                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11250                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11251                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11252                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11253                 {"ipv6", RTE_ETH_FLOW_IPV6},
11254                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11255                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11256                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11257                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11258                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11259                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11260         };
11261
11262         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11263                 if (!strcmp(flowtype_str[i].str, string))
11264                         return flowtype_str[i].type;
11265         }
11266
11267         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11268                 return (uint16_t)atoi(string);
11269
11270         return RTE_ETH_FLOW_UNKNOWN;
11271 }
11272
11273 static enum rte_eth_fdir_tunnel_type
11274 str2fdir_tunneltype(char *string)
11275 {
11276         uint8_t i = 0;
11277
11278         static const struct {
11279                 char str[32];
11280                 enum rte_eth_fdir_tunnel_type type;
11281         } tunneltype_str[] = {
11282                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11283                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11284         };
11285
11286         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11287                 if (!strcmp(tunneltype_str[i].str, string))
11288                         return tunneltype_str[i].type;
11289         }
11290         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11291 }
11292
11293 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11294 do { \
11295         if ((ip_addr).family == AF_INET) \
11296                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11297         else { \
11298                 printf("invalid parameter.\n"); \
11299                 return; \
11300         } \
11301 } while (0)
11302
11303 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11304 do { \
11305         if ((ip_addr).family == AF_INET6) \
11306                 rte_memcpy(&(ip), \
11307                                  &((ip_addr).addr.ipv6), \
11308                                  sizeof(struct in6_addr)); \
11309         else { \
11310                 printf("invalid parameter.\n"); \
11311                 return; \
11312         } \
11313 } while (0)
11314
11315 static void
11316 cmd_flow_director_filter_parsed(void *parsed_result,
11317                           __rte_unused struct cmdline *cl,
11318                           __rte_unused void *data)
11319 {
11320         struct cmd_flow_director_result *res = parsed_result;
11321         struct rte_eth_fdir_filter entry;
11322         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11323         char *end;
11324         unsigned long vf_id;
11325         int ret = 0;
11326
11327         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11328         if (ret < 0) {
11329                 printf("flow director is not supported on port %u.\n",
11330                         res->port_id);
11331                 return;
11332         }
11333         memset(flexbytes, 0, sizeof(flexbytes));
11334         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11335
11336         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11337                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11338                         printf("Please set mode to MAC-VLAN.\n");
11339                         return;
11340                 }
11341         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11342                 if (strcmp(res->mode_value, "Tunnel")) {
11343                         printf("Please set mode to Tunnel.\n");
11344                         return;
11345                 }
11346         } else {
11347                 if (!strcmp(res->mode_value, "raw")) {
11348 #ifdef RTE_LIBRTE_I40E_PMD
11349                         struct rte_pmd_i40e_flow_type_mapping
11350                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11351                         struct rte_pmd_i40e_pkt_template_conf conf;
11352                         uint16_t flow_type = str2flowtype(res->flow_type);
11353                         uint16_t i, port = res->port_id;
11354                         uint8_t add;
11355
11356                         memset(&conf, 0, sizeof(conf));
11357
11358                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11359                                 printf("Invalid flow type specified.\n");
11360                                 return;
11361                         }
11362                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11363                                                                  mapping);
11364                         if (ret)
11365                                 return;
11366                         if (mapping[flow_type].pctype == 0ULL) {
11367                                 printf("Invalid flow type specified.\n");
11368                                 return;
11369                         }
11370                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11371                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11372                                         conf.input.pctype = i;
11373                                         break;
11374                                 }
11375                         }
11376
11377                         conf.input.packet = open_file(res->filepath,
11378                                                 &conf.input.length);
11379                         if (!conf.input.packet)
11380                                 return;
11381                         if (!strcmp(res->drop, "drop"))
11382                                 conf.action.behavior =
11383                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11384                         else
11385                                 conf.action.behavior =
11386                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11387                         conf.action.report_status =
11388                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11389                         conf.action.rx_queue = res->queue_id;
11390                         conf.soft_id = res->fd_id_value;
11391                         add  = strcmp(res->ops, "del") ? 1 : 0;
11392                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11393                                                                         &conf,
11394                                                                         add);
11395                         if (ret < 0)
11396                                 printf("flow director config error: (%s)\n",
11397                                        strerror(-ret));
11398                         close_file(conf.input.packet);
11399 #endif
11400                         return;
11401                 } else if (strcmp(res->mode_value, "IP")) {
11402                         printf("Please set mode to IP or raw.\n");
11403                         return;
11404                 }
11405                 entry.input.flow_type = str2flowtype(res->flow_type);
11406         }
11407
11408         ret = parse_flexbytes(res->flexbytes_value,
11409                                         flexbytes,
11410                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11411         if (ret < 0) {
11412                 printf("error: Cannot parse flexbytes input.\n");
11413                 return;
11414         }
11415
11416         switch (entry.input.flow_type) {
11417         case RTE_ETH_FLOW_FRAG_IPV4:
11418         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11419                 entry.input.flow.ip4_flow.proto = res->proto_value;
11420                 /* fall-through */
11421         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11422         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11423                 IPV4_ADDR_TO_UINT(res->ip_dst,
11424                         entry.input.flow.ip4_flow.dst_ip);
11425                 IPV4_ADDR_TO_UINT(res->ip_src,
11426                         entry.input.flow.ip4_flow.src_ip);
11427                 entry.input.flow.ip4_flow.tos = res->tos_value;
11428                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11429                 /* need convert to big endian. */
11430                 entry.input.flow.udp4_flow.dst_port =
11431                                 rte_cpu_to_be_16(res->port_dst);
11432                 entry.input.flow.udp4_flow.src_port =
11433                                 rte_cpu_to_be_16(res->port_src);
11434                 break;
11435         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11436                 IPV4_ADDR_TO_UINT(res->ip_dst,
11437                         entry.input.flow.sctp4_flow.ip.dst_ip);
11438                 IPV4_ADDR_TO_UINT(res->ip_src,
11439                         entry.input.flow.sctp4_flow.ip.src_ip);
11440                 entry.input.flow.ip4_flow.tos = res->tos_value;
11441                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11442                 /* need convert to big endian. */
11443                 entry.input.flow.sctp4_flow.dst_port =
11444                                 rte_cpu_to_be_16(res->port_dst);
11445                 entry.input.flow.sctp4_flow.src_port =
11446                                 rte_cpu_to_be_16(res->port_src);
11447                 entry.input.flow.sctp4_flow.verify_tag =
11448                                 rte_cpu_to_be_32(res->verify_tag_value);
11449                 break;
11450         case RTE_ETH_FLOW_FRAG_IPV6:
11451         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11452                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11453                 /* fall-through */
11454         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11455         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11456                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11457                         entry.input.flow.ipv6_flow.dst_ip);
11458                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11459                         entry.input.flow.ipv6_flow.src_ip);
11460                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11461                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11462                 /* need convert to big endian. */
11463                 entry.input.flow.udp6_flow.dst_port =
11464                                 rte_cpu_to_be_16(res->port_dst);
11465                 entry.input.flow.udp6_flow.src_port =
11466                                 rte_cpu_to_be_16(res->port_src);
11467                 break;
11468         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11469                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11470                         entry.input.flow.sctp6_flow.ip.dst_ip);
11471                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11472                         entry.input.flow.sctp6_flow.ip.src_ip);
11473                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11474                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11475                 /* need convert to big endian. */
11476                 entry.input.flow.sctp6_flow.dst_port =
11477                                 rte_cpu_to_be_16(res->port_dst);
11478                 entry.input.flow.sctp6_flow.src_port =
11479                                 rte_cpu_to_be_16(res->port_src);
11480                 entry.input.flow.sctp6_flow.verify_tag =
11481                                 rte_cpu_to_be_32(res->verify_tag_value);
11482                 break;
11483         case RTE_ETH_FLOW_L2_PAYLOAD:
11484                 entry.input.flow.l2_flow.ether_type =
11485                         rte_cpu_to_be_16(res->ether_type);
11486                 break;
11487         default:
11488                 break;
11489         }
11490
11491         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11492                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11493                                  &res->mac_addr,
11494                                  sizeof(struct rte_ether_addr));
11495
11496         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11497                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11498                                  &res->mac_addr,
11499                                  sizeof(struct rte_ether_addr));
11500                 entry.input.flow.tunnel_flow.tunnel_type =
11501                         str2fdir_tunneltype(res->tunnel_type);
11502                 entry.input.flow.tunnel_flow.tunnel_id =
11503                         rte_cpu_to_be_32(res->tunnel_id_value);
11504         }
11505
11506         rte_memcpy(entry.input.flow_ext.flexbytes,
11507                    flexbytes,
11508                    RTE_ETH_FDIR_MAX_FLEXLEN);
11509
11510         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11511
11512         entry.action.flex_off = 0;  /*use 0 by default */
11513         if (!strcmp(res->drop, "drop"))
11514                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11515         else
11516                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11517
11518         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11519             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11520                 if (!strcmp(res->pf_vf, "pf"))
11521                         entry.input.flow_ext.is_vf = 0;
11522                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11523                         struct rte_eth_dev_info dev_info;
11524
11525                         ret = eth_dev_info_get_print_err(res->port_id,
11526                                                 &dev_info);
11527                         if (ret != 0)
11528                                 return;
11529
11530                         errno = 0;
11531                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11532                         if (errno != 0 || *end != '\0' ||
11533                             vf_id >= dev_info.max_vfs) {
11534                                 printf("invalid parameter %s.\n", res->pf_vf);
11535                                 return;
11536                         }
11537                         entry.input.flow_ext.is_vf = 1;
11538                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11539                 } else {
11540                         printf("invalid parameter %s.\n", res->pf_vf);
11541                         return;
11542                 }
11543         }
11544
11545         /* set to report FD ID by default */
11546         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11547         entry.action.rx_queue = res->queue_id;
11548         entry.soft_id = res->fd_id_value;
11549         if (!strcmp(res->ops, "add"))
11550                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11551                                              RTE_ETH_FILTER_ADD, &entry);
11552         else if (!strcmp(res->ops, "del"))
11553                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11554                                              RTE_ETH_FILTER_DELETE, &entry);
11555         else
11556                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11557                                              RTE_ETH_FILTER_UPDATE, &entry);
11558         if (ret < 0)
11559                 printf("flow director programming error: (%s)\n",
11560                         strerror(-ret));
11561 }
11562
11563 cmdline_parse_token_string_t cmd_flow_director_filter =
11564         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11565                                  flow_director_filter, "flow_director_filter");
11566 cmdline_parse_token_num_t cmd_flow_director_port_id =
11567         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11568                               port_id, UINT16);
11569 cmdline_parse_token_string_t cmd_flow_director_ops =
11570         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11571                                  ops, "add#del#update");
11572 cmdline_parse_token_string_t cmd_flow_director_flow =
11573         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11574                                  flow, "flow");
11575 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11576         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11577                 flow_type, NULL);
11578 cmdline_parse_token_string_t cmd_flow_director_ether =
11579         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11580                                  ether, "ether");
11581 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11582         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11583                               ether_type, UINT16);
11584 cmdline_parse_token_string_t cmd_flow_director_src =
11585         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11586                                  src, "src");
11587 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11588         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11589                                  ip_src);
11590 cmdline_parse_token_num_t cmd_flow_director_port_src =
11591         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11592                               port_src, UINT16);
11593 cmdline_parse_token_string_t cmd_flow_director_dst =
11594         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11595                                  dst, "dst");
11596 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11597         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11598                                  ip_dst);
11599 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11600         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11601                               port_dst, UINT16);
11602 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11603         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11604                                   verify_tag, "verify_tag");
11605 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11606         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11607                               verify_tag_value, UINT32);
11608 cmdline_parse_token_string_t cmd_flow_director_tos =
11609         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11610                                  tos, "tos");
11611 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11612         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11613                               tos_value, UINT8);
11614 cmdline_parse_token_string_t cmd_flow_director_proto =
11615         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11616                                  proto, "proto");
11617 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11618         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11619                               proto_value, UINT8);
11620 cmdline_parse_token_string_t cmd_flow_director_ttl =
11621         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11622                                  ttl, "ttl");
11623 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11624         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11625                               ttl_value, UINT8);
11626 cmdline_parse_token_string_t cmd_flow_director_vlan =
11627         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11628                                  vlan, "vlan");
11629 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11630         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11631                               vlan_value, UINT16);
11632 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11633         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11634                                  flexbytes, "flexbytes");
11635 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11636         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11637                               flexbytes_value, NULL);
11638 cmdline_parse_token_string_t cmd_flow_director_drop =
11639         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11640                                  drop, "drop#fwd");
11641 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11642         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11643                               pf_vf, NULL);
11644 cmdline_parse_token_string_t cmd_flow_director_queue =
11645         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11646                                  queue, "queue");
11647 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11648         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11649                               queue_id, UINT16);
11650 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11651         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11652                                  fd_id, "fd_id");
11653 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11654         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11655                               fd_id_value, UINT32);
11656
11657 cmdline_parse_token_string_t cmd_flow_director_mode =
11658         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11659                                  mode, "mode");
11660 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11661         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11662                                  mode_value, "IP");
11663 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11664         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11665                                  mode_value, "MAC-VLAN");
11666 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11667         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11668                                  mode_value, "Tunnel");
11669 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11670         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11671                                  mode_value, "raw");
11672 cmdline_parse_token_string_t cmd_flow_director_mac =
11673         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11674                                  mac, "mac");
11675 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11676         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11677                                     mac_addr);
11678 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11679         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11680                                  tunnel, "tunnel");
11681 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11682         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11683                                  tunnel_type, "NVGRE#VxLAN");
11684 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11685         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11686                                  tunnel_id, "tunnel-id");
11687 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11688         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11689                               tunnel_id_value, UINT32);
11690 cmdline_parse_token_string_t cmd_flow_director_packet =
11691         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11692                                  packet, "packet");
11693 cmdline_parse_token_string_t cmd_flow_director_filepath =
11694         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11695                                  filepath, NULL);
11696
11697 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11698         .f = cmd_flow_director_filter_parsed,
11699         .data = NULL,
11700         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11701                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11702                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11703                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11704                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11705                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11706                 "fd_id <fd_id_value>: "
11707                 "Add or delete an ip flow director entry on NIC",
11708         .tokens = {
11709                 (void *)&cmd_flow_director_filter,
11710                 (void *)&cmd_flow_director_port_id,
11711                 (void *)&cmd_flow_director_mode,
11712                 (void *)&cmd_flow_director_mode_ip,
11713                 (void *)&cmd_flow_director_ops,
11714                 (void *)&cmd_flow_director_flow,
11715                 (void *)&cmd_flow_director_flow_type,
11716                 (void *)&cmd_flow_director_src,
11717                 (void *)&cmd_flow_director_ip_src,
11718                 (void *)&cmd_flow_director_dst,
11719                 (void *)&cmd_flow_director_ip_dst,
11720                 (void *)&cmd_flow_director_tos,
11721                 (void *)&cmd_flow_director_tos_value,
11722                 (void *)&cmd_flow_director_proto,
11723                 (void *)&cmd_flow_director_proto_value,
11724                 (void *)&cmd_flow_director_ttl,
11725                 (void *)&cmd_flow_director_ttl_value,
11726                 (void *)&cmd_flow_director_vlan,
11727                 (void *)&cmd_flow_director_vlan_value,
11728                 (void *)&cmd_flow_director_flexbytes,
11729                 (void *)&cmd_flow_director_flexbytes_value,
11730                 (void *)&cmd_flow_director_drop,
11731                 (void *)&cmd_flow_director_pf_vf,
11732                 (void *)&cmd_flow_director_queue,
11733                 (void *)&cmd_flow_director_queue_id,
11734                 (void *)&cmd_flow_director_fd_id,
11735                 (void *)&cmd_flow_director_fd_id_value,
11736                 NULL,
11737         },
11738 };
11739
11740 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11741         .f = cmd_flow_director_filter_parsed,
11742         .data = NULL,
11743         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11744                 "director entry on NIC",
11745         .tokens = {
11746                 (void *)&cmd_flow_director_filter,
11747                 (void *)&cmd_flow_director_port_id,
11748                 (void *)&cmd_flow_director_mode,
11749                 (void *)&cmd_flow_director_mode_ip,
11750                 (void *)&cmd_flow_director_ops,
11751                 (void *)&cmd_flow_director_flow,
11752                 (void *)&cmd_flow_director_flow_type,
11753                 (void *)&cmd_flow_director_src,
11754                 (void *)&cmd_flow_director_ip_src,
11755                 (void *)&cmd_flow_director_port_src,
11756                 (void *)&cmd_flow_director_dst,
11757                 (void *)&cmd_flow_director_ip_dst,
11758                 (void *)&cmd_flow_director_port_dst,
11759                 (void *)&cmd_flow_director_tos,
11760                 (void *)&cmd_flow_director_tos_value,
11761                 (void *)&cmd_flow_director_ttl,
11762                 (void *)&cmd_flow_director_ttl_value,
11763                 (void *)&cmd_flow_director_vlan,
11764                 (void *)&cmd_flow_director_vlan_value,
11765                 (void *)&cmd_flow_director_flexbytes,
11766                 (void *)&cmd_flow_director_flexbytes_value,
11767                 (void *)&cmd_flow_director_drop,
11768                 (void *)&cmd_flow_director_pf_vf,
11769                 (void *)&cmd_flow_director_queue,
11770                 (void *)&cmd_flow_director_queue_id,
11771                 (void *)&cmd_flow_director_fd_id,
11772                 (void *)&cmd_flow_director_fd_id_value,
11773                 NULL,
11774         },
11775 };
11776
11777 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11778         .f = cmd_flow_director_filter_parsed,
11779         .data = NULL,
11780         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11781                 "director entry on NIC",
11782         .tokens = {
11783                 (void *)&cmd_flow_director_filter,
11784                 (void *)&cmd_flow_director_port_id,
11785                 (void *)&cmd_flow_director_mode,
11786                 (void *)&cmd_flow_director_mode_ip,
11787                 (void *)&cmd_flow_director_ops,
11788                 (void *)&cmd_flow_director_flow,
11789                 (void *)&cmd_flow_director_flow_type,
11790                 (void *)&cmd_flow_director_src,
11791                 (void *)&cmd_flow_director_ip_src,
11792                 (void *)&cmd_flow_director_port_src,
11793                 (void *)&cmd_flow_director_dst,
11794                 (void *)&cmd_flow_director_ip_dst,
11795                 (void *)&cmd_flow_director_port_dst,
11796                 (void *)&cmd_flow_director_verify_tag,
11797                 (void *)&cmd_flow_director_verify_tag_value,
11798                 (void *)&cmd_flow_director_tos,
11799                 (void *)&cmd_flow_director_tos_value,
11800                 (void *)&cmd_flow_director_ttl,
11801                 (void *)&cmd_flow_director_ttl_value,
11802                 (void *)&cmd_flow_director_vlan,
11803                 (void *)&cmd_flow_director_vlan_value,
11804                 (void *)&cmd_flow_director_flexbytes,
11805                 (void *)&cmd_flow_director_flexbytes_value,
11806                 (void *)&cmd_flow_director_drop,
11807                 (void *)&cmd_flow_director_pf_vf,
11808                 (void *)&cmd_flow_director_queue,
11809                 (void *)&cmd_flow_director_queue_id,
11810                 (void *)&cmd_flow_director_fd_id,
11811                 (void *)&cmd_flow_director_fd_id_value,
11812                 NULL,
11813         },
11814 };
11815
11816 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11817         .f = cmd_flow_director_filter_parsed,
11818         .data = NULL,
11819         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11820                 "director entry on NIC",
11821         .tokens = {
11822                 (void *)&cmd_flow_director_filter,
11823                 (void *)&cmd_flow_director_port_id,
11824                 (void *)&cmd_flow_director_mode,
11825                 (void *)&cmd_flow_director_mode_ip,
11826                 (void *)&cmd_flow_director_ops,
11827                 (void *)&cmd_flow_director_flow,
11828                 (void *)&cmd_flow_director_flow_type,
11829                 (void *)&cmd_flow_director_ether,
11830                 (void *)&cmd_flow_director_ether_type,
11831                 (void *)&cmd_flow_director_flexbytes,
11832                 (void *)&cmd_flow_director_flexbytes_value,
11833                 (void *)&cmd_flow_director_drop,
11834                 (void *)&cmd_flow_director_pf_vf,
11835                 (void *)&cmd_flow_director_queue,
11836                 (void *)&cmd_flow_director_queue_id,
11837                 (void *)&cmd_flow_director_fd_id,
11838                 (void *)&cmd_flow_director_fd_id_value,
11839                 NULL,
11840         },
11841 };
11842
11843 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11844         .f = cmd_flow_director_filter_parsed,
11845         .data = NULL,
11846         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11847                 "director entry on NIC",
11848         .tokens = {
11849                 (void *)&cmd_flow_director_filter,
11850                 (void *)&cmd_flow_director_port_id,
11851                 (void *)&cmd_flow_director_mode,
11852                 (void *)&cmd_flow_director_mode_mac_vlan,
11853                 (void *)&cmd_flow_director_ops,
11854                 (void *)&cmd_flow_director_mac,
11855                 (void *)&cmd_flow_director_mac_addr,
11856                 (void *)&cmd_flow_director_vlan,
11857                 (void *)&cmd_flow_director_vlan_value,
11858                 (void *)&cmd_flow_director_flexbytes,
11859                 (void *)&cmd_flow_director_flexbytes_value,
11860                 (void *)&cmd_flow_director_drop,
11861                 (void *)&cmd_flow_director_queue,
11862                 (void *)&cmd_flow_director_queue_id,
11863                 (void *)&cmd_flow_director_fd_id,
11864                 (void *)&cmd_flow_director_fd_id_value,
11865                 NULL,
11866         },
11867 };
11868
11869 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11870         .f = cmd_flow_director_filter_parsed,
11871         .data = NULL,
11872         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11873                 "director entry on NIC",
11874         .tokens = {
11875                 (void *)&cmd_flow_director_filter,
11876                 (void *)&cmd_flow_director_port_id,
11877                 (void *)&cmd_flow_director_mode,
11878                 (void *)&cmd_flow_director_mode_tunnel,
11879                 (void *)&cmd_flow_director_ops,
11880                 (void *)&cmd_flow_director_mac,
11881                 (void *)&cmd_flow_director_mac_addr,
11882                 (void *)&cmd_flow_director_vlan,
11883                 (void *)&cmd_flow_director_vlan_value,
11884                 (void *)&cmd_flow_director_tunnel,
11885                 (void *)&cmd_flow_director_tunnel_type,
11886                 (void *)&cmd_flow_director_tunnel_id,
11887                 (void *)&cmd_flow_director_tunnel_id_value,
11888                 (void *)&cmd_flow_director_flexbytes,
11889                 (void *)&cmd_flow_director_flexbytes_value,
11890                 (void *)&cmd_flow_director_drop,
11891                 (void *)&cmd_flow_director_queue,
11892                 (void *)&cmd_flow_director_queue_id,
11893                 (void *)&cmd_flow_director_fd_id,
11894                 (void *)&cmd_flow_director_fd_id_value,
11895                 NULL,
11896         },
11897 };
11898
11899 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11900         .f = cmd_flow_director_filter_parsed,
11901         .data = NULL,
11902         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11903                 "director entry on NIC",
11904         .tokens = {
11905                 (void *)&cmd_flow_director_filter,
11906                 (void *)&cmd_flow_director_port_id,
11907                 (void *)&cmd_flow_director_mode,
11908                 (void *)&cmd_flow_director_mode_raw,
11909                 (void *)&cmd_flow_director_ops,
11910                 (void *)&cmd_flow_director_flow,
11911                 (void *)&cmd_flow_director_flow_type,
11912                 (void *)&cmd_flow_director_drop,
11913                 (void *)&cmd_flow_director_queue,
11914                 (void *)&cmd_flow_director_queue_id,
11915                 (void *)&cmd_flow_director_fd_id,
11916                 (void *)&cmd_flow_director_fd_id_value,
11917                 (void *)&cmd_flow_director_packet,
11918                 (void *)&cmd_flow_director_filepath,
11919                 NULL,
11920         },
11921 };
11922
11923 struct cmd_flush_flow_director_result {
11924         cmdline_fixed_string_t flush_flow_director;
11925         portid_t port_id;
11926 };
11927
11928 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11929         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11930                                  flush_flow_director, "flush_flow_director");
11931 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11932         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11933                               port_id, UINT16);
11934
11935 static void
11936 cmd_flush_flow_director_parsed(void *parsed_result,
11937                           __rte_unused struct cmdline *cl,
11938                           __rte_unused void *data)
11939 {
11940         struct cmd_flow_director_result *res = parsed_result;
11941         int ret = 0;
11942
11943         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11944         if (ret < 0) {
11945                 printf("flow director is not supported on port %u.\n",
11946                         res->port_id);
11947                 return;
11948         }
11949
11950         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11951                         RTE_ETH_FILTER_FLUSH, NULL);
11952         if (ret < 0)
11953                 printf("flow director table flushing error: (%s)\n",
11954                         strerror(-ret));
11955 }
11956
11957 cmdline_parse_inst_t cmd_flush_flow_director = {
11958         .f = cmd_flush_flow_director_parsed,
11959         .data = NULL,
11960         .help_str = "flush_flow_director <port_id>: "
11961                 "Flush all flow director entries of a device on NIC",
11962         .tokens = {
11963                 (void *)&cmd_flush_flow_director_flush,
11964                 (void *)&cmd_flush_flow_director_port_id,
11965                 NULL,
11966         },
11967 };
11968
11969 /* *** deal with flow director mask *** */
11970 struct cmd_flow_director_mask_result {
11971         cmdline_fixed_string_t flow_director_mask;
11972         portid_t port_id;
11973         cmdline_fixed_string_t mode;
11974         cmdline_fixed_string_t mode_value;
11975         cmdline_fixed_string_t vlan;
11976         uint16_t vlan_mask;
11977         cmdline_fixed_string_t src_mask;
11978         cmdline_ipaddr_t ipv4_src;
11979         cmdline_ipaddr_t ipv6_src;
11980         uint16_t port_src;
11981         cmdline_fixed_string_t dst_mask;
11982         cmdline_ipaddr_t ipv4_dst;
11983         cmdline_ipaddr_t ipv6_dst;
11984         uint16_t port_dst;
11985         cmdline_fixed_string_t mac;
11986         uint8_t mac_addr_byte_mask;
11987         cmdline_fixed_string_t tunnel_id;
11988         uint32_t tunnel_id_mask;
11989         cmdline_fixed_string_t tunnel_type;
11990         uint8_t tunnel_type_mask;
11991 };
11992
11993 static void
11994 cmd_flow_director_mask_parsed(void *parsed_result,
11995                           __rte_unused struct cmdline *cl,
11996                           __rte_unused void *data)
11997 {
11998         struct cmd_flow_director_mask_result *res = parsed_result;
11999         struct rte_eth_fdir_masks *mask;
12000         struct rte_port *port;
12001
12002         port = &ports[res->port_id];
12003         /** Check if the port is not started **/
12004         if (port->port_status != RTE_PORT_STOPPED) {
12005                 printf("Please stop port %d first\n", res->port_id);
12006                 return;
12007         }
12008
12009         mask = &port->dev_conf.fdir_conf.mask;
12010
12011         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
12012                 if (strcmp(res->mode_value, "MAC-VLAN")) {
12013                         printf("Please set mode to MAC-VLAN.\n");
12014                         return;
12015                 }
12016
12017                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12018         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
12019                 if (strcmp(res->mode_value, "Tunnel")) {
12020                         printf("Please set mode to Tunnel.\n");
12021                         return;
12022                 }
12023
12024                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12025                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
12026                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
12027                 mask->tunnel_type_mask = res->tunnel_type_mask;
12028         } else {
12029                 if (strcmp(res->mode_value, "IP")) {
12030                         printf("Please set mode to IP.\n");
12031                         return;
12032                 }
12033
12034                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12035                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
12036                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
12037                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
12038                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
12039                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
12040                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
12041         }
12042
12043         cmd_reconfig_device_queue(res->port_id, 1, 1);
12044 }
12045
12046 cmdline_parse_token_string_t cmd_flow_director_mask =
12047         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12048                                  flow_director_mask, "flow_director_mask");
12049 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
12050         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12051                               port_id, UINT16);
12052 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
12053         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12054                                  vlan, "vlan");
12055 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
12056         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12057                               vlan_mask, UINT16);
12058 cmdline_parse_token_string_t cmd_flow_director_mask_src =
12059         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12060                                  src_mask, "src_mask");
12061 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
12062         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12063                                  ipv4_src);
12064 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
12065         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12066                                  ipv6_src);
12067 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
12068         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12069                               port_src, UINT16);
12070 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
12071         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12072                                  dst_mask, "dst_mask");
12073 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
12074         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12075                                  ipv4_dst);
12076 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
12077         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12078                                  ipv6_dst);
12079 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
12080         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12081                               port_dst, UINT16);
12082
12083 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
12084         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12085                                  mode, "mode");
12086 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
12087         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12088                                  mode_value, "IP");
12089 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
12090         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12091                                  mode_value, "MAC-VLAN");
12092 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
12093         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12094                                  mode_value, "Tunnel");
12095 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
12096         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12097                                  mac, "mac");
12098 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
12099         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12100                               mac_addr_byte_mask, UINT8);
12101 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
12102         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12103                                  tunnel_type, "tunnel-type");
12104 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
12105         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12106                               tunnel_type_mask, UINT8);
12107 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
12108         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12109                                  tunnel_id, "tunnel-id");
12110 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
12111         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12112                               tunnel_id_mask, UINT32);
12113
12114 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
12115         .f = cmd_flow_director_mask_parsed,
12116         .data = NULL,
12117         .help_str = "flow_director_mask ... : "
12118                 "Set IP mode flow director's mask on NIC",
12119         .tokens = {
12120                 (void *)&cmd_flow_director_mask,
12121                 (void *)&cmd_flow_director_mask_port_id,
12122                 (void *)&cmd_flow_director_mask_mode,
12123                 (void *)&cmd_flow_director_mask_mode_ip,
12124                 (void *)&cmd_flow_director_mask_vlan,
12125                 (void *)&cmd_flow_director_mask_vlan_value,
12126                 (void *)&cmd_flow_director_mask_src,
12127                 (void *)&cmd_flow_director_mask_ipv4_src,
12128                 (void *)&cmd_flow_director_mask_ipv6_src,
12129                 (void *)&cmd_flow_director_mask_port_src,
12130                 (void *)&cmd_flow_director_mask_dst,
12131                 (void *)&cmd_flow_director_mask_ipv4_dst,
12132                 (void *)&cmd_flow_director_mask_ipv6_dst,
12133                 (void *)&cmd_flow_director_mask_port_dst,
12134                 NULL,
12135         },
12136 };
12137
12138 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
12139         .f = cmd_flow_director_mask_parsed,
12140         .data = NULL,
12141         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
12142                 "flow director's mask on NIC",
12143         .tokens = {
12144                 (void *)&cmd_flow_director_mask,
12145                 (void *)&cmd_flow_director_mask_port_id,
12146                 (void *)&cmd_flow_director_mask_mode,
12147                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
12148                 (void *)&cmd_flow_director_mask_vlan,
12149                 (void *)&cmd_flow_director_mask_vlan_value,
12150                 NULL,
12151         },
12152 };
12153
12154 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
12155         .f = cmd_flow_director_mask_parsed,
12156         .data = NULL,
12157         .help_str = "flow_director_mask ... : Set tunnel mode "
12158                 "flow director's mask on NIC",
12159         .tokens = {
12160                 (void *)&cmd_flow_director_mask,
12161                 (void *)&cmd_flow_director_mask_port_id,
12162                 (void *)&cmd_flow_director_mask_mode,
12163                 (void *)&cmd_flow_director_mask_mode_tunnel,
12164                 (void *)&cmd_flow_director_mask_vlan,
12165                 (void *)&cmd_flow_director_mask_vlan_value,
12166                 (void *)&cmd_flow_director_mask_mac,
12167                 (void *)&cmd_flow_director_mask_mac_value,
12168                 (void *)&cmd_flow_director_mask_tunnel_type,
12169                 (void *)&cmd_flow_director_mask_tunnel_type_value,
12170                 (void *)&cmd_flow_director_mask_tunnel_id,
12171                 (void *)&cmd_flow_director_mask_tunnel_id_value,
12172                 NULL,
12173         },
12174 };
12175
12176 /* *** deal with flow director mask on flexible payload *** */
12177 struct cmd_flow_director_flex_mask_result {
12178         cmdline_fixed_string_t flow_director_flexmask;
12179         portid_t port_id;
12180         cmdline_fixed_string_t flow;
12181         cmdline_fixed_string_t flow_type;
12182         cmdline_fixed_string_t mask;
12183 };
12184
12185 static void
12186 cmd_flow_director_flex_mask_parsed(void *parsed_result,
12187                           __rte_unused struct cmdline *cl,
12188                           __rte_unused void *data)
12189 {
12190         struct cmd_flow_director_flex_mask_result *res = parsed_result;
12191         struct rte_eth_fdir_info fdir_info;
12192         struct rte_eth_fdir_flex_mask flex_mask;
12193         struct rte_port *port;
12194         uint64_t flow_type_mask;
12195         uint16_t i;
12196         int ret;
12197
12198         port = &ports[res->port_id];
12199         /** Check if the port is not started **/
12200         if (port->port_status != RTE_PORT_STOPPED) {
12201                 printf("Please stop port %d first\n", res->port_id);
12202                 return;
12203         }
12204
12205         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
12206         ret = parse_flexbytes(res->mask,
12207                         flex_mask.mask,
12208                         RTE_ETH_FDIR_MAX_FLEXLEN);
12209         if (ret < 0) {
12210                 printf("error: Cannot parse mask input.\n");
12211                 return;
12212         }
12213
12214         memset(&fdir_info, 0, sizeof(fdir_info));
12215         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12216                                 RTE_ETH_FILTER_INFO, &fdir_info);
12217         if (ret < 0) {
12218                 printf("Cannot get FDir filter info\n");
12219                 return;
12220         }
12221
12222         if (!strcmp(res->flow_type, "none")) {
12223                 /* means don't specify the flow type */
12224                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
12225                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
12226                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12227                                0, sizeof(struct rte_eth_fdir_flex_mask));
12228                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12229                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12230                                  &flex_mask,
12231                                  sizeof(struct rte_eth_fdir_flex_mask));
12232                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12233                 return;
12234         }
12235         flow_type_mask = fdir_info.flow_types_mask[0];
12236         if (!strcmp(res->flow_type, "all")) {
12237                 if (!flow_type_mask) {
12238                         printf("No flow type supported\n");
12239                         return;
12240                 }
12241                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12242                         if (flow_type_mask & (1ULL << i)) {
12243                                 flex_mask.flow_type = i;
12244                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12245                         }
12246                 }
12247                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12248                 return;
12249         }
12250         flex_mask.flow_type = str2flowtype(res->flow_type);
12251         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12252                 printf("Flow type %s not supported on port %d\n",
12253                                 res->flow_type, res->port_id);
12254                 return;
12255         }
12256         fdir_set_flex_mask(res->port_id, &flex_mask);
12257         cmd_reconfig_device_queue(res->port_id, 1, 1);
12258 }
12259
12260 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12261         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12262                                  flow_director_flexmask,
12263                                  "flow_director_flex_mask");
12264 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12265         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12266                               port_id, UINT16);
12267 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12268         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12269                                  flow, "flow");
12270 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12271         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12272                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12273                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12274 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12275         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12276                                  mask, NULL);
12277
12278 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12279         .f = cmd_flow_director_flex_mask_parsed,
12280         .data = NULL,
12281         .help_str = "flow_director_flex_mask ... : "
12282                 "Set flow director's flex mask on NIC",
12283         .tokens = {
12284                 (void *)&cmd_flow_director_flexmask,
12285                 (void *)&cmd_flow_director_flexmask_port_id,
12286                 (void *)&cmd_flow_director_flexmask_flow,
12287                 (void *)&cmd_flow_director_flexmask_flow_type,
12288                 (void *)&cmd_flow_director_flexmask_mask,
12289                 NULL,
12290         },
12291 };
12292
12293 /* *** deal with flow director flexible payload configuration *** */
12294 struct cmd_flow_director_flexpayload_result {
12295         cmdline_fixed_string_t flow_director_flexpayload;
12296         portid_t port_id;
12297         cmdline_fixed_string_t payload_layer;
12298         cmdline_fixed_string_t payload_cfg;
12299 };
12300
12301 static inline int
12302 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12303 {
12304         char s[256];
12305         const char *p, *p0 = q_arg;
12306         char *end;
12307         unsigned long int_fld;
12308         char *str_fld[max_num];
12309         int i;
12310         unsigned size;
12311         int ret = -1;
12312
12313         p = strchr(p0, '(');
12314         if (p == NULL)
12315                 return -1;
12316         ++p;
12317         p0 = strchr(p, ')');
12318         if (p0 == NULL)
12319                 return -1;
12320
12321         size = p0 - p;
12322         if (size >= sizeof(s))
12323                 return -1;
12324
12325         snprintf(s, sizeof(s), "%.*s", size, p);
12326         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12327         if (ret < 0 || ret > max_num)
12328                 return -1;
12329         for (i = 0; i < ret; i++) {
12330                 errno = 0;
12331                 int_fld = strtoul(str_fld[i], &end, 0);
12332                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12333                         return -1;
12334                 offsets[i] = (uint16_t)int_fld;
12335         }
12336         return ret;
12337 }
12338
12339 static void
12340 cmd_flow_director_flxpld_parsed(void *parsed_result,
12341                           __rte_unused struct cmdline *cl,
12342                           __rte_unused void *data)
12343 {
12344         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12345         struct rte_eth_flex_payload_cfg flex_cfg;
12346         struct rte_port *port;
12347         int ret = 0;
12348
12349         port = &ports[res->port_id];
12350         /** Check if the port is not started **/
12351         if (port->port_status != RTE_PORT_STOPPED) {
12352                 printf("Please stop port %d first\n", res->port_id);
12353                 return;
12354         }
12355
12356         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12357
12358         if (!strcmp(res->payload_layer, "raw"))
12359                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12360         else if (!strcmp(res->payload_layer, "l2"))
12361                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12362         else if (!strcmp(res->payload_layer, "l3"))
12363                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12364         else if (!strcmp(res->payload_layer, "l4"))
12365                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12366
12367         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12368                             RTE_ETH_FDIR_MAX_FLEXLEN);
12369         if (ret < 0) {
12370                 printf("error: Cannot parse flex payload input.\n");
12371                 return;
12372         }
12373
12374         fdir_set_flex_payload(res->port_id, &flex_cfg);
12375         cmd_reconfig_device_queue(res->port_id, 1, 1);
12376 }
12377
12378 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12379         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12380                                  flow_director_flexpayload,
12381                                  "flow_director_flex_payload");
12382 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12383         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12384                               port_id, UINT16);
12385 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12386         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12387                                  payload_layer, "raw#l2#l3#l4");
12388 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12389         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12390                                  payload_cfg, NULL);
12391
12392 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12393         .f = cmd_flow_director_flxpld_parsed,
12394         .data = NULL,
12395         .help_str = "flow_director_flexpayload ... : "
12396                 "Set flow director's flex payload on NIC",
12397         .tokens = {
12398                 (void *)&cmd_flow_director_flexpayload,
12399                 (void *)&cmd_flow_director_flexpayload_port_id,
12400                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12401                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12402                 NULL,
12403         },
12404 };
12405
12406 /* Generic flow interface command. */
12407 extern cmdline_parse_inst_t cmd_flow;
12408
12409 /* *** Classification Filters Control *** */
12410 /* *** Get symmetric hash enable per port *** */
12411 struct cmd_get_sym_hash_ena_per_port_result {
12412         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12413         portid_t port_id;
12414 };
12415
12416 static void
12417 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12418                                  __rte_unused struct cmdline *cl,
12419                                  __rte_unused void *data)
12420 {
12421         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12422         struct rte_eth_hash_filter_info info;
12423         int ret;
12424
12425         if (rte_eth_dev_filter_supported(res->port_id,
12426                                 RTE_ETH_FILTER_HASH) < 0) {
12427                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12428                                                         res->port_id);
12429                 return;
12430         }
12431
12432         memset(&info, 0, sizeof(info));
12433         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12434         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12435                                                 RTE_ETH_FILTER_GET, &info);
12436
12437         if (ret < 0) {
12438                 printf("Cannot get symmetric hash enable per port "
12439                                         "on port %u\n", res->port_id);
12440                 return;
12441         }
12442
12443         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12444                                 "enabled" : "disabled", res->port_id);
12445 }
12446
12447 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12448         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12449                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12450 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12451         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12452                 port_id, UINT16);
12453
12454 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12455         .f = cmd_get_sym_hash_per_port_parsed,
12456         .data = NULL,
12457         .help_str = "get_sym_hash_ena_per_port <port_id>",
12458         .tokens = {
12459                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12460                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12461                 NULL,
12462         },
12463 };
12464
12465 /* *** Set symmetric hash enable per port *** */
12466 struct cmd_set_sym_hash_ena_per_port_result {
12467         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12468         cmdline_fixed_string_t enable;
12469         portid_t port_id;
12470 };
12471
12472 static void
12473 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12474                                  __rte_unused struct cmdline *cl,
12475                                  __rte_unused void *data)
12476 {
12477         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12478         struct rte_eth_hash_filter_info info;
12479         int ret;
12480
12481         if (rte_eth_dev_filter_supported(res->port_id,
12482                                 RTE_ETH_FILTER_HASH) < 0) {
12483                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12484                                                         res->port_id);
12485                 return;
12486         }
12487
12488         memset(&info, 0, sizeof(info));
12489         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12490         if (!strcmp(res->enable, "enable"))
12491                 info.info.enable = 1;
12492         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12493                                         RTE_ETH_FILTER_SET, &info);
12494         if (ret < 0) {
12495                 printf("Cannot set symmetric hash enable per port on "
12496                                         "port %u\n", res->port_id);
12497                 return;
12498         }
12499         printf("Symmetric hash has been set to %s on port %u\n",
12500                                         res->enable, res->port_id);
12501 }
12502
12503 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12504         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12505                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12506 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12507         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12508                 port_id, UINT16);
12509 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12510         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12511                 enable, "enable#disable");
12512
12513 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12514         .f = cmd_set_sym_hash_per_port_parsed,
12515         .data = NULL,
12516         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12517         .tokens = {
12518                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12519                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12520                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12521                 NULL,
12522         },
12523 };
12524
12525 /* Get global config of hash function */
12526 struct cmd_get_hash_global_config_result {
12527         cmdline_fixed_string_t get_hash_global_config;
12528         portid_t port_id;
12529 };
12530
12531 static char *
12532 flowtype_to_str(uint16_t ftype)
12533 {
12534         uint16_t i;
12535         static struct {
12536                 char str[16];
12537                 uint16_t ftype;
12538         } ftype_table[] = {
12539                 {"ipv4", RTE_ETH_FLOW_IPV4},
12540                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12541                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12542                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12543                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12544                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12545                 {"ipv6", RTE_ETH_FLOW_IPV6},
12546                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12547                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12548                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12549                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12550                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12551                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12552                 {"port", RTE_ETH_FLOW_PORT},
12553                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12554                 {"geneve", RTE_ETH_FLOW_GENEVE},
12555                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12556                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12557         };
12558
12559         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12560                 if (ftype_table[i].ftype == ftype)
12561                         return ftype_table[i].str;
12562         }
12563
12564         return NULL;
12565 }
12566
12567 static void
12568 cmd_get_hash_global_config_parsed(void *parsed_result,
12569                                   __rte_unused struct cmdline *cl,
12570                                   __rte_unused void *data)
12571 {
12572         struct cmd_get_hash_global_config_result *res = parsed_result;
12573         struct rte_eth_hash_filter_info info;
12574         uint32_t idx, offset;
12575         uint16_t i;
12576         char *str;
12577         int ret;
12578
12579         if (rte_eth_dev_filter_supported(res->port_id,
12580                         RTE_ETH_FILTER_HASH) < 0) {
12581                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12582                                                         res->port_id);
12583                 return;
12584         }
12585
12586         memset(&info, 0, sizeof(info));
12587         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12588         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12589                                         RTE_ETH_FILTER_GET, &info);
12590         if (ret < 0) {
12591                 printf("Cannot get hash global configurations by port %d\n",
12592                                                         res->port_id);
12593                 return;
12594         }
12595
12596         switch (info.info.global_conf.hash_func) {
12597         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12598                 printf("Hash function is Toeplitz\n");
12599                 break;
12600         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12601                 printf("Hash function is Simple XOR\n");
12602                 break;
12603         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12604                 printf("Hash function is Symmetric Toeplitz\n");
12605                 break;
12606         default:
12607                 printf("Unknown hash function\n");
12608                 break;
12609         }
12610
12611         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12612                 idx = i / UINT64_BIT;
12613                 offset = i % UINT64_BIT;
12614                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12615                                                 (1ULL << offset)))
12616                         continue;
12617                 str = flowtype_to_str(i);
12618                 if (!str)
12619                         continue;
12620                 printf("Symmetric hash is %s globally for flow type %s "
12621                                                         "by port %d\n",
12622                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12623                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12624                                                         res->port_id);
12625         }
12626 }
12627
12628 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12629         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12630                 get_hash_global_config, "get_hash_global_config");
12631 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12632         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12633                 port_id, UINT16);
12634
12635 cmdline_parse_inst_t cmd_get_hash_global_config = {
12636         .f = cmd_get_hash_global_config_parsed,
12637         .data = NULL,
12638         .help_str = "get_hash_global_config <port_id>",
12639         .tokens = {
12640                 (void *)&cmd_get_hash_global_config_all,
12641                 (void *)&cmd_get_hash_global_config_port_id,
12642                 NULL,
12643         },
12644 };
12645
12646 /* Set global config of hash function */
12647 struct cmd_set_hash_global_config_result {
12648         cmdline_fixed_string_t set_hash_global_config;
12649         portid_t port_id;
12650         cmdline_fixed_string_t hash_func;
12651         cmdline_fixed_string_t flow_type;
12652         cmdline_fixed_string_t enable;
12653 };
12654
12655 static void
12656 cmd_set_hash_global_config_parsed(void *parsed_result,
12657                                   __rte_unused struct cmdline *cl,
12658                                   __rte_unused void *data)
12659 {
12660         struct cmd_set_hash_global_config_result *res = parsed_result;
12661         struct rte_eth_hash_filter_info info;
12662         uint32_t ftype, idx, offset;
12663         int ret;
12664
12665         if (rte_eth_dev_filter_supported(res->port_id,
12666                                 RTE_ETH_FILTER_HASH) < 0) {
12667                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12668                                                         res->port_id);
12669                 return;
12670         }
12671         memset(&info, 0, sizeof(info));
12672         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12673         if (!strcmp(res->hash_func, "toeplitz"))
12674                 info.info.global_conf.hash_func =
12675                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12676         else if (!strcmp(res->hash_func, "simple_xor"))
12677                 info.info.global_conf.hash_func =
12678                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12679         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12680                 info.info.global_conf.hash_func =
12681                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12682         else if (!strcmp(res->hash_func, "default"))
12683                 info.info.global_conf.hash_func =
12684                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12685
12686         ftype = str2flowtype(res->flow_type);
12687         idx = ftype / UINT64_BIT;
12688         offset = ftype % UINT64_BIT;
12689         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12690         if (!strcmp(res->enable, "enable"))
12691                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12692                                                 (1ULL << offset);
12693         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12694                                         RTE_ETH_FILTER_SET, &info);
12695         if (ret < 0)
12696                 printf("Cannot set global hash configurations by port %d\n",
12697                                                         res->port_id);
12698         else
12699                 printf("Global hash configurations have been set "
12700                         "successfully by port %d\n", res->port_id);
12701 }
12702
12703 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12704         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12705                 set_hash_global_config, "set_hash_global_config");
12706 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12707         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12708                 port_id, UINT16);
12709 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12710         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12711                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12712 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12713         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12714                 flow_type,
12715                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12716                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12717 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12718         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12719                 enable, "enable#disable");
12720
12721 cmdline_parse_inst_t cmd_set_hash_global_config = {
12722         .f = cmd_set_hash_global_config_parsed,
12723         .data = NULL,
12724         .help_str = "set_hash_global_config <port_id> "
12725                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12726                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12727                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12728                 "l2_payload enable|disable",
12729         .tokens = {
12730                 (void *)&cmd_set_hash_global_config_all,
12731                 (void *)&cmd_set_hash_global_config_port_id,
12732                 (void *)&cmd_set_hash_global_config_hash_func,
12733                 (void *)&cmd_set_hash_global_config_flow_type,
12734                 (void *)&cmd_set_hash_global_config_enable,
12735                 NULL,
12736         },
12737 };
12738
12739 /* Set hash input set */
12740 struct cmd_set_hash_input_set_result {
12741         cmdline_fixed_string_t set_hash_input_set;
12742         portid_t port_id;
12743         cmdline_fixed_string_t flow_type;
12744         cmdline_fixed_string_t inset_field;
12745         cmdline_fixed_string_t select;
12746 };
12747
12748 static enum rte_eth_input_set_field
12749 str2inset(char *string)
12750 {
12751         uint16_t i;
12752
12753         static const struct {
12754                 char str[32];
12755                 enum rte_eth_input_set_field inset;
12756         } inset_table[] = {
12757                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12758                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12759                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12760                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12761                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12762                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12763                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12764                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12765                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12766                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12767                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12768                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12769                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12770                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12771                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12772                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12773                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12774                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12775                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12776                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12777                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12778                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12779                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12780                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12781                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12782                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12783                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12784                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12785                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12786                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12787                 {"none", RTE_ETH_INPUT_SET_NONE},
12788         };
12789
12790         for (i = 0; i < RTE_DIM(inset_table); i++) {
12791                 if (!strcmp(string, inset_table[i].str))
12792                         return inset_table[i].inset;
12793         }
12794
12795         return RTE_ETH_INPUT_SET_UNKNOWN;
12796 }
12797
12798 static void
12799 cmd_set_hash_input_set_parsed(void *parsed_result,
12800                               __rte_unused struct cmdline *cl,
12801                               __rte_unused void *data)
12802 {
12803         struct cmd_set_hash_input_set_result *res = parsed_result;
12804         struct rte_eth_hash_filter_info info;
12805
12806         memset(&info, 0, sizeof(info));
12807         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12808         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12809         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12810         info.info.input_set_conf.inset_size = 1;
12811         if (!strcmp(res->select, "select"))
12812                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12813         else if (!strcmp(res->select, "add"))
12814                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12815         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12816                                 RTE_ETH_FILTER_SET, &info);
12817 }
12818
12819 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12820         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12821                 set_hash_input_set, "set_hash_input_set");
12822 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12823         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12824                 port_id, UINT16);
12825 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12826         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12827                 flow_type, NULL);
12828 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12829         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12830                 inset_field,
12831                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12832                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12833                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12834                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12835                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12836                 "fld-8th#none");
12837 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12838         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12839                 select, "select#add");
12840
12841 cmdline_parse_inst_t cmd_set_hash_input_set = {
12842         .f = cmd_set_hash_input_set_parsed,
12843         .data = NULL,
12844         .help_str = "set_hash_input_set <port_id> "
12845         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12846         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12847         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12848         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12849         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12850         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12851         "fld-7th|fld-8th|none select|add",
12852         .tokens = {
12853                 (void *)&cmd_set_hash_input_set_cmd,
12854                 (void *)&cmd_set_hash_input_set_port_id,
12855                 (void *)&cmd_set_hash_input_set_flow_type,
12856                 (void *)&cmd_set_hash_input_set_field,
12857                 (void *)&cmd_set_hash_input_set_select,
12858                 NULL,
12859         },
12860 };
12861
12862 /* Set flow director input set */
12863 struct cmd_set_fdir_input_set_result {
12864         cmdline_fixed_string_t set_fdir_input_set;
12865         portid_t port_id;
12866         cmdline_fixed_string_t flow_type;
12867         cmdline_fixed_string_t inset_field;
12868         cmdline_fixed_string_t select;
12869 };
12870
12871 static void
12872 cmd_set_fdir_input_set_parsed(void *parsed_result,
12873         __rte_unused struct cmdline *cl,
12874         __rte_unused void *data)
12875 {
12876         struct cmd_set_fdir_input_set_result *res = parsed_result;
12877         struct rte_eth_fdir_filter_info info;
12878
12879         memset(&info, 0, sizeof(info));
12880         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12881         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12882         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12883         info.info.input_set_conf.inset_size = 1;
12884         if (!strcmp(res->select, "select"))
12885                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12886         else if (!strcmp(res->select, "add"))
12887                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12888         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12889                 RTE_ETH_FILTER_SET, &info);
12890 }
12891
12892 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12893         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12894         set_fdir_input_set, "set_fdir_input_set");
12895 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12896         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12897         port_id, UINT16);
12898 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12899         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12900         flow_type,
12901         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12902         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12903 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12904         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12905         inset_field,
12906         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12907         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12908         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12909         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12910         "sctp-veri-tag#none");
12911 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12912         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12913         select, "select#add");
12914
12915 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12916         .f = cmd_set_fdir_input_set_parsed,
12917         .data = NULL,
12918         .help_str = "set_fdir_input_set <port_id> "
12919         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12920         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12921         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12922         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12923         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12924         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12925         "sctp-veri-tag|none select|add",
12926         .tokens = {
12927                 (void *)&cmd_set_fdir_input_set_cmd,
12928                 (void *)&cmd_set_fdir_input_set_port_id,
12929                 (void *)&cmd_set_fdir_input_set_flow_type,
12930                 (void *)&cmd_set_fdir_input_set_field,
12931                 (void *)&cmd_set_fdir_input_set_select,
12932                 NULL,
12933         },
12934 };
12935
12936 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12937 struct cmd_mcast_addr_result {
12938         cmdline_fixed_string_t mcast_addr_cmd;
12939         cmdline_fixed_string_t what;
12940         uint16_t port_num;
12941         struct rte_ether_addr mc_addr;
12942 };
12943
12944 static void cmd_mcast_addr_parsed(void *parsed_result,
12945                 __rte_unused struct cmdline *cl,
12946                 __rte_unused void *data)
12947 {
12948         struct cmd_mcast_addr_result *res = parsed_result;
12949
12950         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12951                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12952                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12953                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12954                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12955                 return;
12956         }
12957         if (strcmp(res->what, "add") == 0)
12958                 mcast_addr_add(res->port_num, &res->mc_addr);
12959         else
12960                 mcast_addr_remove(res->port_num, &res->mc_addr);
12961 }
12962
12963 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12964         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12965                                  mcast_addr_cmd, "mcast_addr");
12966 cmdline_parse_token_string_t cmd_mcast_addr_what =
12967         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12968                                  "add#remove");
12969 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12970         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12971 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12972         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12973
12974 cmdline_parse_inst_t cmd_mcast_addr = {
12975         .f = cmd_mcast_addr_parsed,
12976         .data = (void *)0,
12977         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12978                 "Add/Remove multicast MAC address on port_id",
12979         .tokens = {
12980                 (void *)&cmd_mcast_addr_cmd,
12981                 (void *)&cmd_mcast_addr_what,
12982                 (void *)&cmd_mcast_addr_portnum,
12983                 (void *)&cmd_mcast_addr_addr,
12984                 NULL,
12985         },
12986 };
12987
12988 /* l2 tunnel config
12989  * only support E-tag now.
12990  */
12991
12992 /* Ether type config */
12993 struct cmd_config_l2_tunnel_eth_type_result {
12994         cmdline_fixed_string_t port;
12995         cmdline_fixed_string_t config;
12996         cmdline_fixed_string_t all;
12997         portid_t id;
12998         cmdline_fixed_string_t l2_tunnel;
12999         cmdline_fixed_string_t l2_tunnel_type;
13000         cmdline_fixed_string_t eth_type;
13001         uint16_t eth_type_val;
13002 };
13003
13004 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
13005         TOKEN_STRING_INITIALIZER
13006                 (struct cmd_config_l2_tunnel_eth_type_result,
13007                  port, "port");
13008 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
13009         TOKEN_STRING_INITIALIZER
13010                 (struct cmd_config_l2_tunnel_eth_type_result,
13011                  config, "config");
13012 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
13013         TOKEN_STRING_INITIALIZER
13014                 (struct cmd_config_l2_tunnel_eth_type_result,
13015                  all, "all");
13016 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
13017         TOKEN_NUM_INITIALIZER
13018                 (struct cmd_config_l2_tunnel_eth_type_result,
13019                  id, UINT16);
13020 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
13021         TOKEN_STRING_INITIALIZER
13022                 (struct cmd_config_l2_tunnel_eth_type_result,
13023                  l2_tunnel, "l2-tunnel");
13024 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
13025         TOKEN_STRING_INITIALIZER
13026                 (struct cmd_config_l2_tunnel_eth_type_result,
13027                  l2_tunnel_type, "E-tag");
13028 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
13029         TOKEN_STRING_INITIALIZER
13030                 (struct cmd_config_l2_tunnel_eth_type_result,
13031                  eth_type, "ether-type");
13032 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
13033         TOKEN_NUM_INITIALIZER
13034                 (struct cmd_config_l2_tunnel_eth_type_result,
13035                  eth_type_val, UINT16);
13036
13037 static enum rte_eth_tunnel_type
13038 str2fdir_l2_tunnel_type(char *string)
13039 {
13040         uint32_t i = 0;
13041
13042         static const struct {
13043                 char str[32];
13044                 enum rte_eth_tunnel_type type;
13045         } l2_tunnel_type_str[] = {
13046                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
13047         };
13048
13049         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
13050                 if (!strcmp(l2_tunnel_type_str[i].str, string))
13051                         return l2_tunnel_type_str[i].type;
13052         }
13053         return RTE_TUNNEL_TYPE_NONE;
13054 }
13055
13056 /* ether type config for all ports */
13057 static void
13058 cmd_config_l2_tunnel_eth_type_all_parsed
13059         (void *parsed_result,
13060          __rte_unused struct cmdline *cl,
13061          __rte_unused void *data)
13062 {
13063         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
13064         struct rte_eth_l2_tunnel_conf entry;
13065         portid_t pid;
13066
13067         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13068         entry.ether_type = res->eth_type_val;
13069
13070         RTE_ETH_FOREACH_DEV(pid) {
13071                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
13072         }
13073 }
13074
13075 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
13076         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
13077         .data = NULL,
13078         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
13079         .tokens = {
13080                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13081                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13082                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
13083                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13084                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13085                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13086                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13087                 NULL,
13088         },
13089 };
13090
13091 /* ether type config for a specific port */
13092 static void
13093 cmd_config_l2_tunnel_eth_type_specific_parsed(
13094         void *parsed_result,
13095         __rte_unused struct cmdline *cl,
13096         __rte_unused void *data)
13097 {
13098         struct cmd_config_l2_tunnel_eth_type_result *res =
13099                  parsed_result;
13100         struct rte_eth_l2_tunnel_conf entry;
13101
13102         if (port_id_is_invalid(res->id, ENABLED_WARN))
13103                 return;
13104
13105         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13106         entry.ether_type = res->eth_type_val;
13107
13108         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
13109 }
13110
13111 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
13112         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
13113         .data = NULL,
13114         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
13115         .tokens = {
13116                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13117                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13118                 (void *)&cmd_config_l2_tunnel_eth_type_id,
13119                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13120                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13121                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13122                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13123                 NULL,
13124         },
13125 };
13126
13127 /* Enable/disable l2 tunnel */
13128 struct cmd_config_l2_tunnel_en_dis_result {
13129         cmdline_fixed_string_t port;
13130         cmdline_fixed_string_t config;
13131         cmdline_fixed_string_t all;
13132         portid_t id;
13133         cmdline_fixed_string_t l2_tunnel;
13134         cmdline_fixed_string_t l2_tunnel_type;
13135         cmdline_fixed_string_t en_dis;
13136 };
13137
13138 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
13139         TOKEN_STRING_INITIALIZER
13140                 (struct cmd_config_l2_tunnel_en_dis_result,
13141                  port, "port");
13142 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
13143         TOKEN_STRING_INITIALIZER
13144                 (struct cmd_config_l2_tunnel_en_dis_result,
13145                  config, "config");
13146 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
13147         TOKEN_STRING_INITIALIZER
13148                 (struct cmd_config_l2_tunnel_en_dis_result,
13149                  all, "all");
13150 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
13151         TOKEN_NUM_INITIALIZER
13152                 (struct cmd_config_l2_tunnel_en_dis_result,
13153                  id, UINT16);
13154 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
13155         TOKEN_STRING_INITIALIZER
13156                 (struct cmd_config_l2_tunnel_en_dis_result,
13157                  l2_tunnel, "l2-tunnel");
13158 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
13159         TOKEN_STRING_INITIALIZER
13160                 (struct cmd_config_l2_tunnel_en_dis_result,
13161                  l2_tunnel_type, "E-tag");
13162 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
13163         TOKEN_STRING_INITIALIZER
13164                 (struct cmd_config_l2_tunnel_en_dis_result,
13165                  en_dis, "enable#disable");
13166
13167 /* enable/disable l2 tunnel for all ports */
13168 static void
13169 cmd_config_l2_tunnel_en_dis_all_parsed(
13170         void *parsed_result,
13171         __rte_unused struct cmdline *cl,
13172         __rte_unused void *data)
13173 {
13174         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
13175         struct rte_eth_l2_tunnel_conf entry;
13176         portid_t pid;
13177         uint8_t en;
13178
13179         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13180
13181         if (!strcmp("enable", res->en_dis))
13182                 en = 1;
13183         else
13184                 en = 0;
13185
13186         RTE_ETH_FOREACH_DEV(pid) {
13187                 rte_eth_dev_l2_tunnel_offload_set(pid,
13188                                                   &entry,
13189                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13190                                                   en);
13191         }
13192 }
13193
13194 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
13195         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
13196         .data = NULL,
13197         .help_str = "port config all l2-tunnel E-tag enable|disable",
13198         .tokens = {
13199                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13200                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13201                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
13202                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13203                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13204                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13205                 NULL,
13206         },
13207 };
13208
13209 /* enable/disable l2 tunnel for a port */
13210 static void
13211 cmd_config_l2_tunnel_en_dis_specific_parsed(
13212         void *parsed_result,
13213         __rte_unused struct cmdline *cl,
13214         __rte_unused void *data)
13215 {
13216         struct cmd_config_l2_tunnel_en_dis_result *res =
13217                 parsed_result;
13218         struct rte_eth_l2_tunnel_conf entry;
13219
13220         if (port_id_is_invalid(res->id, ENABLED_WARN))
13221                 return;
13222
13223         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13224
13225         if (!strcmp("enable", res->en_dis))
13226                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13227                                                   &entry,
13228                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13229                                                   1);
13230         else
13231                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13232                                                   &entry,
13233                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13234                                                   0);
13235 }
13236
13237 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13238         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13239         .data = NULL,
13240         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13241         .tokens = {
13242                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13243                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13244                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13245                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13246                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13247                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13248                 NULL,
13249         },
13250 };
13251
13252 /* E-tag configuration */
13253
13254 /* Common result structure for all E-tag configuration */
13255 struct cmd_config_e_tag_result {
13256         cmdline_fixed_string_t e_tag;
13257         cmdline_fixed_string_t set;
13258         cmdline_fixed_string_t insertion;
13259         cmdline_fixed_string_t stripping;
13260         cmdline_fixed_string_t forwarding;
13261         cmdline_fixed_string_t filter;
13262         cmdline_fixed_string_t add;
13263         cmdline_fixed_string_t del;
13264         cmdline_fixed_string_t on;
13265         cmdline_fixed_string_t off;
13266         cmdline_fixed_string_t on_off;
13267         cmdline_fixed_string_t port_tag_id;
13268         uint32_t port_tag_id_val;
13269         cmdline_fixed_string_t e_tag_id;
13270         uint16_t e_tag_id_val;
13271         cmdline_fixed_string_t dst_pool;
13272         uint8_t dst_pool_val;
13273         cmdline_fixed_string_t port;
13274         portid_t port_id;
13275         cmdline_fixed_string_t vf;
13276         uint8_t vf_id;
13277 };
13278
13279 /* Common CLI fields for all E-tag configuration */
13280 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13281         TOKEN_STRING_INITIALIZER
13282                 (struct cmd_config_e_tag_result,
13283                  e_tag, "E-tag");
13284 cmdline_parse_token_string_t cmd_config_e_tag_set =
13285         TOKEN_STRING_INITIALIZER
13286                 (struct cmd_config_e_tag_result,
13287                  set, "set");
13288 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13289         TOKEN_STRING_INITIALIZER
13290                 (struct cmd_config_e_tag_result,
13291                  insertion, "insertion");
13292 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13293         TOKEN_STRING_INITIALIZER
13294                 (struct cmd_config_e_tag_result,
13295                  stripping, "stripping");
13296 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13297         TOKEN_STRING_INITIALIZER
13298                 (struct cmd_config_e_tag_result,
13299                  forwarding, "forwarding");
13300 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13301         TOKEN_STRING_INITIALIZER
13302                 (struct cmd_config_e_tag_result,
13303                  filter, "filter");
13304 cmdline_parse_token_string_t cmd_config_e_tag_add =
13305         TOKEN_STRING_INITIALIZER
13306                 (struct cmd_config_e_tag_result,
13307                  add, "add");
13308 cmdline_parse_token_string_t cmd_config_e_tag_del =
13309         TOKEN_STRING_INITIALIZER
13310                 (struct cmd_config_e_tag_result,
13311                  del, "del");
13312 cmdline_parse_token_string_t cmd_config_e_tag_on =
13313         TOKEN_STRING_INITIALIZER
13314                 (struct cmd_config_e_tag_result,
13315                  on, "on");
13316 cmdline_parse_token_string_t cmd_config_e_tag_off =
13317         TOKEN_STRING_INITIALIZER
13318                 (struct cmd_config_e_tag_result,
13319                  off, "off");
13320 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13321         TOKEN_STRING_INITIALIZER
13322                 (struct cmd_config_e_tag_result,
13323                  on_off, "on#off");
13324 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13325         TOKEN_STRING_INITIALIZER
13326                 (struct cmd_config_e_tag_result,
13327                  port_tag_id, "port-tag-id");
13328 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13329         TOKEN_NUM_INITIALIZER
13330                 (struct cmd_config_e_tag_result,
13331                  port_tag_id_val, UINT32);
13332 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13333         TOKEN_STRING_INITIALIZER
13334                 (struct cmd_config_e_tag_result,
13335                  e_tag_id, "e-tag-id");
13336 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13337         TOKEN_NUM_INITIALIZER
13338                 (struct cmd_config_e_tag_result,
13339                  e_tag_id_val, UINT16);
13340 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13341         TOKEN_STRING_INITIALIZER
13342                 (struct cmd_config_e_tag_result,
13343                  dst_pool, "dst-pool");
13344 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13345         TOKEN_NUM_INITIALIZER
13346                 (struct cmd_config_e_tag_result,
13347                  dst_pool_val, UINT8);
13348 cmdline_parse_token_string_t cmd_config_e_tag_port =
13349         TOKEN_STRING_INITIALIZER
13350                 (struct cmd_config_e_tag_result,
13351                  port, "port");
13352 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13353         TOKEN_NUM_INITIALIZER
13354                 (struct cmd_config_e_tag_result,
13355                  port_id, UINT16);
13356 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13357         TOKEN_STRING_INITIALIZER
13358                 (struct cmd_config_e_tag_result,
13359                  vf, "vf");
13360 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13361         TOKEN_NUM_INITIALIZER
13362                 (struct cmd_config_e_tag_result,
13363                  vf_id, UINT8);
13364
13365 /* E-tag insertion configuration */
13366 static void
13367 cmd_config_e_tag_insertion_en_parsed(
13368         void *parsed_result,
13369         __rte_unused struct cmdline *cl,
13370         __rte_unused void *data)
13371 {
13372         struct cmd_config_e_tag_result *res =
13373                 parsed_result;
13374         struct rte_eth_l2_tunnel_conf entry;
13375
13376         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13377                 return;
13378
13379         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13380         entry.tunnel_id = res->port_tag_id_val;
13381         entry.vf_id = res->vf_id;
13382         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13383                                           &entry,
13384                                           ETH_L2_TUNNEL_INSERTION_MASK,
13385                                           1);
13386 }
13387
13388 static void
13389 cmd_config_e_tag_insertion_dis_parsed(
13390         void *parsed_result,
13391         __rte_unused struct cmdline *cl,
13392         __rte_unused void *data)
13393 {
13394         struct cmd_config_e_tag_result *res =
13395                 parsed_result;
13396         struct rte_eth_l2_tunnel_conf entry;
13397
13398         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13399                 return;
13400
13401         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13402         entry.vf_id = res->vf_id;
13403
13404         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13405                                           &entry,
13406                                           ETH_L2_TUNNEL_INSERTION_MASK,
13407                                           0);
13408 }
13409
13410 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13411         .f = cmd_config_e_tag_insertion_en_parsed,
13412         .data = NULL,
13413         .help_str = "E-tag ... : E-tag insertion enable",
13414         .tokens = {
13415                 (void *)&cmd_config_e_tag_e_tag,
13416                 (void *)&cmd_config_e_tag_set,
13417                 (void *)&cmd_config_e_tag_insertion,
13418                 (void *)&cmd_config_e_tag_on,
13419                 (void *)&cmd_config_e_tag_port_tag_id,
13420                 (void *)&cmd_config_e_tag_port_tag_id_val,
13421                 (void *)&cmd_config_e_tag_port,
13422                 (void *)&cmd_config_e_tag_port_id,
13423                 (void *)&cmd_config_e_tag_vf,
13424                 (void *)&cmd_config_e_tag_vf_id,
13425                 NULL,
13426         },
13427 };
13428
13429 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13430         .f = cmd_config_e_tag_insertion_dis_parsed,
13431         .data = NULL,
13432         .help_str = "E-tag ... : E-tag insertion disable",
13433         .tokens = {
13434                 (void *)&cmd_config_e_tag_e_tag,
13435                 (void *)&cmd_config_e_tag_set,
13436                 (void *)&cmd_config_e_tag_insertion,
13437                 (void *)&cmd_config_e_tag_off,
13438                 (void *)&cmd_config_e_tag_port,
13439                 (void *)&cmd_config_e_tag_port_id,
13440                 (void *)&cmd_config_e_tag_vf,
13441                 (void *)&cmd_config_e_tag_vf_id,
13442                 NULL,
13443         },
13444 };
13445
13446 /* E-tag stripping configuration */
13447 static void
13448 cmd_config_e_tag_stripping_parsed(
13449         void *parsed_result,
13450         __rte_unused struct cmdline *cl,
13451         __rte_unused void *data)
13452 {
13453         struct cmd_config_e_tag_result *res =
13454                 parsed_result;
13455         struct rte_eth_l2_tunnel_conf entry;
13456
13457         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13458                 return;
13459
13460         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13461
13462         if (!strcmp(res->on_off, "on"))
13463                 rte_eth_dev_l2_tunnel_offload_set
13464                         (res->port_id,
13465                          &entry,
13466                          ETH_L2_TUNNEL_STRIPPING_MASK,
13467                          1);
13468         else
13469                 rte_eth_dev_l2_tunnel_offload_set
13470                         (res->port_id,
13471                          &entry,
13472                          ETH_L2_TUNNEL_STRIPPING_MASK,
13473                          0);
13474 }
13475
13476 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13477         .f = cmd_config_e_tag_stripping_parsed,
13478         .data = NULL,
13479         .help_str = "E-tag ... : E-tag stripping enable/disable",
13480         .tokens = {
13481                 (void *)&cmd_config_e_tag_e_tag,
13482                 (void *)&cmd_config_e_tag_set,
13483                 (void *)&cmd_config_e_tag_stripping,
13484                 (void *)&cmd_config_e_tag_on_off,
13485                 (void *)&cmd_config_e_tag_port,
13486                 (void *)&cmd_config_e_tag_port_id,
13487                 NULL,
13488         },
13489 };
13490
13491 /* E-tag forwarding configuration */
13492 static void
13493 cmd_config_e_tag_forwarding_parsed(
13494         void *parsed_result,
13495         __rte_unused struct cmdline *cl,
13496         __rte_unused void *data)
13497 {
13498         struct cmd_config_e_tag_result *res = parsed_result;
13499         struct rte_eth_l2_tunnel_conf entry;
13500
13501         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13502                 return;
13503
13504         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13505
13506         if (!strcmp(res->on_off, "on"))
13507                 rte_eth_dev_l2_tunnel_offload_set
13508                         (res->port_id,
13509                          &entry,
13510                          ETH_L2_TUNNEL_FORWARDING_MASK,
13511                          1);
13512         else
13513                 rte_eth_dev_l2_tunnel_offload_set
13514                         (res->port_id,
13515                          &entry,
13516                          ETH_L2_TUNNEL_FORWARDING_MASK,
13517                          0);
13518 }
13519
13520 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13521         .f = cmd_config_e_tag_forwarding_parsed,
13522         .data = NULL,
13523         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13524         .tokens = {
13525                 (void *)&cmd_config_e_tag_e_tag,
13526                 (void *)&cmd_config_e_tag_set,
13527                 (void *)&cmd_config_e_tag_forwarding,
13528                 (void *)&cmd_config_e_tag_on_off,
13529                 (void *)&cmd_config_e_tag_port,
13530                 (void *)&cmd_config_e_tag_port_id,
13531                 NULL,
13532         },
13533 };
13534
13535 /* E-tag filter configuration */
13536 static void
13537 cmd_config_e_tag_filter_add_parsed(
13538         void *parsed_result,
13539         __rte_unused struct cmdline *cl,
13540         __rte_unused void *data)
13541 {
13542         struct cmd_config_e_tag_result *res = parsed_result;
13543         struct rte_eth_l2_tunnel_conf entry;
13544         int ret = 0;
13545
13546         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13547                 return;
13548
13549         if (res->e_tag_id_val > 0x3fff) {
13550                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13551                 return;
13552         }
13553
13554         ret = rte_eth_dev_filter_supported(res->port_id,
13555                                            RTE_ETH_FILTER_L2_TUNNEL);
13556         if (ret < 0) {
13557                 printf("E-tag filter is not supported on port %u.\n",
13558                        res->port_id);
13559                 return;
13560         }
13561
13562         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13563         entry.tunnel_id = res->e_tag_id_val;
13564         entry.pool = res->dst_pool_val;
13565
13566         ret = rte_eth_dev_filter_ctrl(res->port_id,
13567                                       RTE_ETH_FILTER_L2_TUNNEL,
13568                                       RTE_ETH_FILTER_ADD,
13569                                       &entry);
13570         if (ret < 0)
13571                 printf("E-tag filter programming error: (%s)\n",
13572                        strerror(-ret));
13573 }
13574
13575 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13576         .f = cmd_config_e_tag_filter_add_parsed,
13577         .data = NULL,
13578         .help_str = "E-tag ... : E-tag filter add",
13579         .tokens = {
13580                 (void *)&cmd_config_e_tag_e_tag,
13581                 (void *)&cmd_config_e_tag_set,
13582                 (void *)&cmd_config_e_tag_filter,
13583                 (void *)&cmd_config_e_tag_add,
13584                 (void *)&cmd_config_e_tag_e_tag_id,
13585                 (void *)&cmd_config_e_tag_e_tag_id_val,
13586                 (void *)&cmd_config_e_tag_dst_pool,
13587                 (void *)&cmd_config_e_tag_dst_pool_val,
13588                 (void *)&cmd_config_e_tag_port,
13589                 (void *)&cmd_config_e_tag_port_id,
13590                 NULL,
13591         },
13592 };
13593
13594 static void
13595 cmd_config_e_tag_filter_del_parsed(
13596         void *parsed_result,
13597         __rte_unused struct cmdline *cl,
13598         __rte_unused void *data)
13599 {
13600         struct cmd_config_e_tag_result *res = parsed_result;
13601         struct rte_eth_l2_tunnel_conf entry;
13602         int ret = 0;
13603
13604         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13605                 return;
13606
13607         if (res->e_tag_id_val > 0x3fff) {
13608                 printf("e-tag-id must be less than 0x3fff.\n");
13609                 return;
13610         }
13611
13612         ret = rte_eth_dev_filter_supported(res->port_id,
13613                                            RTE_ETH_FILTER_L2_TUNNEL);
13614         if (ret < 0) {
13615                 printf("E-tag filter is not supported on port %u.\n",
13616                        res->port_id);
13617                 return;
13618         }
13619
13620         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13621         entry.tunnel_id = res->e_tag_id_val;
13622
13623         ret = rte_eth_dev_filter_ctrl(res->port_id,
13624                                       RTE_ETH_FILTER_L2_TUNNEL,
13625                                       RTE_ETH_FILTER_DELETE,
13626                                       &entry);
13627         if (ret < 0)
13628                 printf("E-tag filter programming error: (%s)\n",
13629                        strerror(-ret));
13630 }
13631
13632 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13633         .f = cmd_config_e_tag_filter_del_parsed,
13634         .data = NULL,
13635         .help_str = "E-tag ... : E-tag filter delete",
13636         .tokens = {
13637                 (void *)&cmd_config_e_tag_e_tag,
13638                 (void *)&cmd_config_e_tag_set,
13639                 (void *)&cmd_config_e_tag_filter,
13640                 (void *)&cmd_config_e_tag_del,
13641                 (void *)&cmd_config_e_tag_e_tag_id,
13642                 (void *)&cmd_config_e_tag_e_tag_id_val,
13643                 (void *)&cmd_config_e_tag_port,
13644                 (void *)&cmd_config_e_tag_port_id,
13645                 NULL,
13646         },
13647 };
13648
13649 /* vf vlan anti spoof configuration */
13650
13651 /* Common result structure for vf vlan anti spoof */
13652 struct cmd_vf_vlan_anti_spoof_result {
13653         cmdline_fixed_string_t set;
13654         cmdline_fixed_string_t vf;
13655         cmdline_fixed_string_t vlan;
13656         cmdline_fixed_string_t antispoof;
13657         portid_t port_id;
13658         uint32_t vf_id;
13659         cmdline_fixed_string_t on_off;
13660 };
13661
13662 /* Common CLI fields for vf vlan anti spoof enable disable */
13663 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13664         TOKEN_STRING_INITIALIZER
13665                 (struct cmd_vf_vlan_anti_spoof_result,
13666                  set, "set");
13667 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13668         TOKEN_STRING_INITIALIZER
13669                 (struct cmd_vf_vlan_anti_spoof_result,
13670                  vf, "vf");
13671 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13672         TOKEN_STRING_INITIALIZER
13673                 (struct cmd_vf_vlan_anti_spoof_result,
13674                  vlan, "vlan");
13675 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13676         TOKEN_STRING_INITIALIZER
13677                 (struct cmd_vf_vlan_anti_spoof_result,
13678                  antispoof, "antispoof");
13679 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13680         TOKEN_NUM_INITIALIZER
13681                 (struct cmd_vf_vlan_anti_spoof_result,
13682                  port_id, UINT16);
13683 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13684         TOKEN_NUM_INITIALIZER
13685                 (struct cmd_vf_vlan_anti_spoof_result,
13686                  vf_id, UINT32);
13687 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13688         TOKEN_STRING_INITIALIZER
13689                 (struct cmd_vf_vlan_anti_spoof_result,
13690                  on_off, "on#off");
13691
13692 static void
13693 cmd_set_vf_vlan_anti_spoof_parsed(
13694         void *parsed_result,
13695         __rte_unused struct cmdline *cl,
13696         __rte_unused void *data)
13697 {
13698         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13699         int ret = -ENOTSUP;
13700
13701         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13702
13703         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13704                 return;
13705
13706 #ifdef RTE_LIBRTE_IXGBE_PMD
13707         if (ret == -ENOTSUP)
13708                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13709                                 res->vf_id, is_on);
13710 #endif
13711 #ifdef RTE_LIBRTE_I40E_PMD
13712         if (ret == -ENOTSUP)
13713                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13714                                 res->vf_id, is_on);
13715 #endif
13716 #ifdef RTE_LIBRTE_BNXT_PMD
13717         if (ret == -ENOTSUP)
13718                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13719                                 res->vf_id, is_on);
13720 #endif
13721
13722         switch (ret) {
13723         case 0:
13724                 break;
13725         case -EINVAL:
13726                 printf("invalid vf_id %d\n", res->vf_id);
13727                 break;
13728         case -ENODEV:
13729                 printf("invalid port_id %d\n", res->port_id);
13730                 break;
13731         case -ENOTSUP:
13732                 printf("function not implemented\n");
13733                 break;
13734         default:
13735                 printf("programming error: (%s)\n", strerror(-ret));
13736         }
13737 }
13738
13739 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13740         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13741         .data = NULL,
13742         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13743         .tokens = {
13744                 (void *)&cmd_vf_vlan_anti_spoof_set,
13745                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13746                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13747                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13748                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13749                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13750                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13751                 NULL,
13752         },
13753 };
13754
13755 /* vf mac anti spoof configuration */
13756
13757 /* Common result structure for vf mac anti spoof */
13758 struct cmd_vf_mac_anti_spoof_result {
13759         cmdline_fixed_string_t set;
13760         cmdline_fixed_string_t vf;
13761         cmdline_fixed_string_t mac;
13762         cmdline_fixed_string_t antispoof;
13763         portid_t port_id;
13764         uint32_t vf_id;
13765         cmdline_fixed_string_t on_off;
13766 };
13767
13768 /* Common CLI fields for vf mac anti spoof enable disable */
13769 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13770         TOKEN_STRING_INITIALIZER
13771                 (struct cmd_vf_mac_anti_spoof_result,
13772                  set, "set");
13773 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13774         TOKEN_STRING_INITIALIZER
13775                 (struct cmd_vf_mac_anti_spoof_result,
13776                  vf, "vf");
13777 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13778         TOKEN_STRING_INITIALIZER
13779                 (struct cmd_vf_mac_anti_spoof_result,
13780                  mac, "mac");
13781 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13782         TOKEN_STRING_INITIALIZER
13783                 (struct cmd_vf_mac_anti_spoof_result,
13784                  antispoof, "antispoof");
13785 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13786         TOKEN_NUM_INITIALIZER
13787                 (struct cmd_vf_mac_anti_spoof_result,
13788                  port_id, UINT16);
13789 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13790         TOKEN_NUM_INITIALIZER
13791                 (struct cmd_vf_mac_anti_spoof_result,
13792                  vf_id, UINT32);
13793 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13794         TOKEN_STRING_INITIALIZER
13795                 (struct cmd_vf_mac_anti_spoof_result,
13796                  on_off, "on#off");
13797
13798 static void
13799 cmd_set_vf_mac_anti_spoof_parsed(
13800         void *parsed_result,
13801         __rte_unused struct cmdline *cl,
13802         __rte_unused void *data)
13803 {
13804         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13805         int ret = -ENOTSUP;
13806
13807         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13808
13809         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13810                 return;
13811
13812 #ifdef RTE_LIBRTE_IXGBE_PMD
13813         if (ret == -ENOTSUP)
13814                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13815                         res->vf_id, is_on);
13816 #endif
13817 #ifdef RTE_LIBRTE_I40E_PMD
13818         if (ret == -ENOTSUP)
13819                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13820                         res->vf_id, is_on);
13821 #endif
13822 #ifdef RTE_LIBRTE_BNXT_PMD
13823         if (ret == -ENOTSUP)
13824                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13825                         res->vf_id, is_on);
13826 #endif
13827
13828         switch (ret) {
13829         case 0:
13830                 break;
13831         case -EINVAL:
13832                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13833                 break;
13834         case -ENODEV:
13835                 printf("invalid port_id %d\n", res->port_id);
13836                 break;
13837         case -ENOTSUP:
13838                 printf("function not implemented\n");
13839                 break;
13840         default:
13841                 printf("programming error: (%s)\n", strerror(-ret));
13842         }
13843 }
13844
13845 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13846         .f = cmd_set_vf_mac_anti_spoof_parsed,
13847         .data = NULL,
13848         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13849         .tokens = {
13850                 (void *)&cmd_vf_mac_anti_spoof_set,
13851                 (void *)&cmd_vf_mac_anti_spoof_vf,
13852                 (void *)&cmd_vf_mac_anti_spoof_mac,
13853                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13854                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13855                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13856                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13857                 NULL,
13858         },
13859 };
13860
13861 /* vf vlan strip queue configuration */
13862
13863 /* Common result structure for vf mac anti spoof */
13864 struct cmd_vf_vlan_stripq_result {
13865         cmdline_fixed_string_t set;
13866         cmdline_fixed_string_t vf;
13867         cmdline_fixed_string_t vlan;
13868         cmdline_fixed_string_t stripq;
13869         portid_t port_id;
13870         uint16_t vf_id;
13871         cmdline_fixed_string_t on_off;
13872 };
13873
13874 /* Common CLI fields for vf vlan strip enable disable */
13875 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13876         TOKEN_STRING_INITIALIZER
13877                 (struct cmd_vf_vlan_stripq_result,
13878                  set, "set");
13879 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13880         TOKEN_STRING_INITIALIZER
13881                 (struct cmd_vf_vlan_stripq_result,
13882                  vf, "vf");
13883 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13884         TOKEN_STRING_INITIALIZER
13885                 (struct cmd_vf_vlan_stripq_result,
13886                  vlan, "vlan");
13887 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13888         TOKEN_STRING_INITIALIZER
13889                 (struct cmd_vf_vlan_stripq_result,
13890                  stripq, "stripq");
13891 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13892         TOKEN_NUM_INITIALIZER
13893                 (struct cmd_vf_vlan_stripq_result,
13894                  port_id, UINT16);
13895 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13896         TOKEN_NUM_INITIALIZER
13897                 (struct cmd_vf_vlan_stripq_result,
13898                  vf_id, UINT16);
13899 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13900         TOKEN_STRING_INITIALIZER
13901                 (struct cmd_vf_vlan_stripq_result,
13902                  on_off, "on#off");
13903
13904 static void
13905 cmd_set_vf_vlan_stripq_parsed(
13906         void *parsed_result,
13907         __rte_unused struct cmdline *cl,
13908         __rte_unused void *data)
13909 {
13910         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13911         int ret = -ENOTSUP;
13912
13913         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13914
13915         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13916                 return;
13917
13918 #ifdef RTE_LIBRTE_IXGBE_PMD
13919         if (ret == -ENOTSUP)
13920                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13921                         res->vf_id, is_on);
13922 #endif
13923 #ifdef RTE_LIBRTE_I40E_PMD
13924         if (ret == -ENOTSUP)
13925                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13926                         res->vf_id, is_on);
13927 #endif
13928 #ifdef RTE_LIBRTE_BNXT_PMD
13929         if (ret == -ENOTSUP)
13930                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13931                         res->vf_id, is_on);
13932 #endif
13933
13934         switch (ret) {
13935         case 0:
13936                 break;
13937         case -EINVAL:
13938                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13939                 break;
13940         case -ENODEV:
13941                 printf("invalid port_id %d\n", res->port_id);
13942                 break;
13943         case -ENOTSUP:
13944                 printf("function not implemented\n");
13945                 break;
13946         default:
13947                 printf("programming error: (%s)\n", strerror(-ret));
13948         }
13949 }
13950
13951 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13952         .f = cmd_set_vf_vlan_stripq_parsed,
13953         .data = NULL,
13954         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13955         .tokens = {
13956                 (void *)&cmd_vf_vlan_stripq_set,
13957                 (void *)&cmd_vf_vlan_stripq_vf,
13958                 (void *)&cmd_vf_vlan_stripq_vlan,
13959                 (void *)&cmd_vf_vlan_stripq_stripq,
13960                 (void *)&cmd_vf_vlan_stripq_port_id,
13961                 (void *)&cmd_vf_vlan_stripq_vf_id,
13962                 (void *)&cmd_vf_vlan_stripq_on_off,
13963                 NULL,
13964         },
13965 };
13966
13967 /* vf vlan insert configuration */
13968
13969 /* Common result structure for vf vlan insert */
13970 struct cmd_vf_vlan_insert_result {
13971         cmdline_fixed_string_t set;
13972         cmdline_fixed_string_t vf;
13973         cmdline_fixed_string_t vlan;
13974         cmdline_fixed_string_t insert;
13975         portid_t port_id;
13976         uint16_t vf_id;
13977         uint16_t vlan_id;
13978 };
13979
13980 /* Common CLI fields for vf vlan insert enable disable */
13981 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13982         TOKEN_STRING_INITIALIZER
13983                 (struct cmd_vf_vlan_insert_result,
13984                  set, "set");
13985 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13986         TOKEN_STRING_INITIALIZER
13987                 (struct cmd_vf_vlan_insert_result,
13988                  vf, "vf");
13989 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13990         TOKEN_STRING_INITIALIZER
13991                 (struct cmd_vf_vlan_insert_result,
13992                  vlan, "vlan");
13993 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13994         TOKEN_STRING_INITIALIZER
13995                 (struct cmd_vf_vlan_insert_result,
13996                  insert, "insert");
13997 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13998         TOKEN_NUM_INITIALIZER
13999                 (struct cmd_vf_vlan_insert_result,
14000                  port_id, UINT16);
14001 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
14002         TOKEN_NUM_INITIALIZER
14003                 (struct cmd_vf_vlan_insert_result,
14004                  vf_id, UINT16);
14005 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
14006         TOKEN_NUM_INITIALIZER
14007                 (struct cmd_vf_vlan_insert_result,
14008                  vlan_id, UINT16);
14009
14010 static void
14011 cmd_set_vf_vlan_insert_parsed(
14012         void *parsed_result,
14013         __rte_unused struct cmdline *cl,
14014         __rte_unused void *data)
14015 {
14016         struct cmd_vf_vlan_insert_result *res = parsed_result;
14017         int ret = -ENOTSUP;
14018
14019         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14020                 return;
14021
14022 #ifdef RTE_LIBRTE_IXGBE_PMD
14023         if (ret == -ENOTSUP)
14024                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
14025                         res->vlan_id);
14026 #endif
14027 #ifdef RTE_LIBRTE_I40E_PMD
14028         if (ret == -ENOTSUP)
14029                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
14030                         res->vlan_id);
14031 #endif
14032 #ifdef RTE_LIBRTE_BNXT_PMD
14033         if (ret == -ENOTSUP)
14034                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
14035                         res->vlan_id);
14036 #endif
14037
14038         switch (ret) {
14039         case 0:
14040                 break;
14041         case -EINVAL:
14042                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
14043                 break;
14044         case -ENODEV:
14045                 printf("invalid port_id %d\n", res->port_id);
14046                 break;
14047         case -ENOTSUP:
14048                 printf("function not implemented\n");
14049                 break;
14050         default:
14051                 printf("programming error: (%s)\n", strerror(-ret));
14052         }
14053 }
14054
14055 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
14056         .f = cmd_set_vf_vlan_insert_parsed,
14057         .data = NULL,
14058         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
14059         .tokens = {
14060                 (void *)&cmd_vf_vlan_insert_set,
14061                 (void *)&cmd_vf_vlan_insert_vf,
14062                 (void *)&cmd_vf_vlan_insert_vlan,
14063                 (void *)&cmd_vf_vlan_insert_insert,
14064                 (void *)&cmd_vf_vlan_insert_port_id,
14065                 (void *)&cmd_vf_vlan_insert_vf_id,
14066                 (void *)&cmd_vf_vlan_insert_vlan_id,
14067                 NULL,
14068         },
14069 };
14070
14071 /* tx loopback configuration */
14072
14073 /* Common result structure for tx loopback */
14074 struct cmd_tx_loopback_result {
14075         cmdline_fixed_string_t set;
14076         cmdline_fixed_string_t tx;
14077         cmdline_fixed_string_t loopback;
14078         portid_t port_id;
14079         cmdline_fixed_string_t on_off;
14080 };
14081
14082 /* Common CLI fields for tx loopback enable disable */
14083 cmdline_parse_token_string_t cmd_tx_loopback_set =
14084         TOKEN_STRING_INITIALIZER
14085                 (struct cmd_tx_loopback_result,
14086                  set, "set");
14087 cmdline_parse_token_string_t cmd_tx_loopback_tx =
14088         TOKEN_STRING_INITIALIZER
14089                 (struct cmd_tx_loopback_result,
14090                  tx, "tx");
14091 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
14092         TOKEN_STRING_INITIALIZER
14093                 (struct cmd_tx_loopback_result,
14094                  loopback, "loopback");
14095 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
14096         TOKEN_NUM_INITIALIZER
14097                 (struct cmd_tx_loopback_result,
14098                  port_id, UINT16);
14099 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
14100         TOKEN_STRING_INITIALIZER
14101                 (struct cmd_tx_loopback_result,
14102                  on_off, "on#off");
14103
14104 static void
14105 cmd_set_tx_loopback_parsed(
14106         void *parsed_result,
14107         __rte_unused struct cmdline *cl,
14108         __rte_unused void *data)
14109 {
14110         struct cmd_tx_loopback_result *res = parsed_result;
14111         int ret = -ENOTSUP;
14112
14113         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14114
14115         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14116                 return;
14117
14118 #ifdef RTE_LIBRTE_IXGBE_PMD
14119         if (ret == -ENOTSUP)
14120                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
14121 #endif
14122 #ifdef RTE_LIBRTE_I40E_PMD
14123         if (ret == -ENOTSUP)
14124                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
14125 #endif
14126 #ifdef RTE_LIBRTE_BNXT_PMD
14127         if (ret == -ENOTSUP)
14128                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
14129 #endif
14130 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
14131         if (ret == -ENOTSUP)
14132                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
14133 #endif
14134
14135         switch (ret) {
14136         case 0:
14137                 break;
14138         case -EINVAL:
14139                 printf("invalid is_on %d\n", is_on);
14140                 break;
14141         case -ENODEV:
14142                 printf("invalid port_id %d\n", res->port_id);
14143                 break;
14144         case -ENOTSUP:
14145                 printf("function not implemented\n");
14146                 break;
14147         default:
14148                 printf("programming error: (%s)\n", strerror(-ret));
14149         }
14150 }
14151
14152 cmdline_parse_inst_t cmd_set_tx_loopback = {
14153         .f = cmd_set_tx_loopback_parsed,
14154         .data = NULL,
14155         .help_str = "set tx loopback <port_id> on|off",
14156         .tokens = {
14157                 (void *)&cmd_tx_loopback_set,
14158                 (void *)&cmd_tx_loopback_tx,
14159                 (void *)&cmd_tx_loopback_loopback,
14160                 (void *)&cmd_tx_loopback_port_id,
14161                 (void *)&cmd_tx_loopback_on_off,
14162                 NULL,
14163         },
14164 };
14165
14166 /* all queues drop enable configuration */
14167
14168 /* Common result structure for all queues drop enable */
14169 struct cmd_all_queues_drop_en_result {
14170         cmdline_fixed_string_t set;
14171         cmdline_fixed_string_t all;
14172         cmdline_fixed_string_t queues;
14173         cmdline_fixed_string_t drop;
14174         portid_t port_id;
14175         cmdline_fixed_string_t on_off;
14176 };
14177
14178 /* Common CLI fields for tx loopback enable disable */
14179 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
14180         TOKEN_STRING_INITIALIZER
14181                 (struct cmd_all_queues_drop_en_result,
14182                  set, "set");
14183 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
14184         TOKEN_STRING_INITIALIZER
14185                 (struct cmd_all_queues_drop_en_result,
14186                  all, "all");
14187 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
14188         TOKEN_STRING_INITIALIZER
14189                 (struct cmd_all_queues_drop_en_result,
14190                  queues, "queues");
14191 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
14192         TOKEN_STRING_INITIALIZER
14193                 (struct cmd_all_queues_drop_en_result,
14194                  drop, "drop");
14195 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
14196         TOKEN_NUM_INITIALIZER
14197                 (struct cmd_all_queues_drop_en_result,
14198                  port_id, UINT16);
14199 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
14200         TOKEN_STRING_INITIALIZER
14201                 (struct cmd_all_queues_drop_en_result,
14202                  on_off, "on#off");
14203
14204 static void
14205 cmd_set_all_queues_drop_en_parsed(
14206         void *parsed_result,
14207         __rte_unused struct cmdline *cl,
14208         __rte_unused void *data)
14209 {
14210         struct cmd_all_queues_drop_en_result *res = parsed_result;
14211         int ret = -ENOTSUP;
14212         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14213
14214         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14215                 return;
14216
14217 #ifdef RTE_LIBRTE_IXGBE_PMD
14218         if (ret == -ENOTSUP)
14219                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
14220 #endif
14221 #ifdef RTE_LIBRTE_BNXT_PMD
14222         if (ret == -ENOTSUP)
14223                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
14224 #endif
14225         switch (ret) {
14226         case 0:
14227                 break;
14228         case -EINVAL:
14229                 printf("invalid is_on %d\n", is_on);
14230                 break;
14231         case -ENODEV:
14232                 printf("invalid port_id %d\n", res->port_id);
14233                 break;
14234         case -ENOTSUP:
14235                 printf("function not implemented\n");
14236                 break;
14237         default:
14238                 printf("programming error: (%s)\n", strerror(-ret));
14239         }
14240 }
14241
14242 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14243         .f = cmd_set_all_queues_drop_en_parsed,
14244         .data = NULL,
14245         .help_str = "set all queues drop <port_id> on|off",
14246         .tokens = {
14247                 (void *)&cmd_all_queues_drop_en_set,
14248                 (void *)&cmd_all_queues_drop_en_all,
14249                 (void *)&cmd_all_queues_drop_en_queues,
14250                 (void *)&cmd_all_queues_drop_en_drop,
14251                 (void *)&cmd_all_queues_drop_en_port_id,
14252                 (void *)&cmd_all_queues_drop_en_on_off,
14253                 NULL,
14254         },
14255 };
14256
14257 /* vf split drop enable configuration */
14258
14259 /* Common result structure for vf split drop enable */
14260 struct cmd_vf_split_drop_en_result {
14261         cmdline_fixed_string_t set;
14262         cmdline_fixed_string_t vf;
14263         cmdline_fixed_string_t split;
14264         cmdline_fixed_string_t drop;
14265         portid_t port_id;
14266         uint16_t vf_id;
14267         cmdline_fixed_string_t on_off;
14268 };
14269
14270 /* Common CLI fields for vf split drop enable disable */
14271 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14272         TOKEN_STRING_INITIALIZER
14273                 (struct cmd_vf_split_drop_en_result,
14274                  set, "set");
14275 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14276         TOKEN_STRING_INITIALIZER
14277                 (struct cmd_vf_split_drop_en_result,
14278                  vf, "vf");
14279 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14280         TOKEN_STRING_INITIALIZER
14281                 (struct cmd_vf_split_drop_en_result,
14282                  split, "split");
14283 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14284         TOKEN_STRING_INITIALIZER
14285                 (struct cmd_vf_split_drop_en_result,
14286                  drop, "drop");
14287 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14288         TOKEN_NUM_INITIALIZER
14289                 (struct cmd_vf_split_drop_en_result,
14290                  port_id, UINT16);
14291 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14292         TOKEN_NUM_INITIALIZER
14293                 (struct cmd_vf_split_drop_en_result,
14294                  vf_id, UINT16);
14295 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14296         TOKEN_STRING_INITIALIZER
14297                 (struct cmd_vf_split_drop_en_result,
14298                  on_off, "on#off");
14299
14300 static void
14301 cmd_set_vf_split_drop_en_parsed(
14302         void *parsed_result,
14303         __rte_unused struct cmdline *cl,
14304         __rte_unused void *data)
14305 {
14306         struct cmd_vf_split_drop_en_result *res = parsed_result;
14307         int ret = -ENOTSUP;
14308         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14309
14310         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14311                 return;
14312
14313 #ifdef RTE_LIBRTE_IXGBE_PMD
14314         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14315                         is_on);
14316 #endif
14317         switch (ret) {
14318         case 0:
14319                 break;
14320         case -EINVAL:
14321                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14322                 break;
14323         case -ENODEV:
14324                 printf("invalid port_id %d\n", res->port_id);
14325                 break;
14326         case -ENOTSUP:
14327                 printf("not supported on port %d\n", res->port_id);
14328                 break;
14329         default:
14330                 printf("programming error: (%s)\n", strerror(-ret));
14331         }
14332 }
14333
14334 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14335         .f = cmd_set_vf_split_drop_en_parsed,
14336         .data = NULL,
14337         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14338         .tokens = {
14339                 (void *)&cmd_vf_split_drop_en_set,
14340                 (void *)&cmd_vf_split_drop_en_vf,
14341                 (void *)&cmd_vf_split_drop_en_split,
14342                 (void *)&cmd_vf_split_drop_en_drop,
14343                 (void *)&cmd_vf_split_drop_en_port_id,
14344                 (void *)&cmd_vf_split_drop_en_vf_id,
14345                 (void *)&cmd_vf_split_drop_en_on_off,
14346                 NULL,
14347         },
14348 };
14349
14350 /* vf mac address configuration */
14351
14352 /* Common result structure for vf mac address */
14353 struct cmd_set_vf_mac_addr_result {
14354         cmdline_fixed_string_t set;
14355         cmdline_fixed_string_t vf;
14356         cmdline_fixed_string_t mac;
14357         cmdline_fixed_string_t addr;
14358         portid_t port_id;
14359         uint16_t vf_id;
14360         struct rte_ether_addr mac_addr;
14361
14362 };
14363
14364 /* Common CLI fields for vf split drop enable disable */
14365 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14366         TOKEN_STRING_INITIALIZER
14367                 (struct cmd_set_vf_mac_addr_result,
14368                  set, "set");
14369 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14370         TOKEN_STRING_INITIALIZER
14371                 (struct cmd_set_vf_mac_addr_result,
14372                  vf, "vf");
14373 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14374         TOKEN_STRING_INITIALIZER
14375                 (struct cmd_set_vf_mac_addr_result,
14376                  mac, "mac");
14377 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14378         TOKEN_STRING_INITIALIZER
14379                 (struct cmd_set_vf_mac_addr_result,
14380                  addr, "addr");
14381 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14382         TOKEN_NUM_INITIALIZER
14383                 (struct cmd_set_vf_mac_addr_result,
14384                  port_id, UINT16);
14385 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14386         TOKEN_NUM_INITIALIZER
14387                 (struct cmd_set_vf_mac_addr_result,
14388                  vf_id, UINT16);
14389 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14390         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14391                  mac_addr);
14392
14393 static void
14394 cmd_set_vf_mac_addr_parsed(
14395         void *parsed_result,
14396         __rte_unused struct cmdline *cl,
14397         __rte_unused void *data)
14398 {
14399         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14400         int ret = -ENOTSUP;
14401
14402         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14403                 return;
14404
14405 #ifdef RTE_LIBRTE_IXGBE_PMD
14406         if (ret == -ENOTSUP)
14407                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14408                                 &res->mac_addr);
14409 #endif
14410 #ifdef RTE_LIBRTE_I40E_PMD
14411         if (ret == -ENOTSUP)
14412                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14413                                 &res->mac_addr);
14414 #endif
14415 #ifdef RTE_LIBRTE_BNXT_PMD
14416         if (ret == -ENOTSUP)
14417                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14418                                 &res->mac_addr);
14419 #endif
14420
14421         switch (ret) {
14422         case 0:
14423                 break;
14424         case -EINVAL:
14425                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14426                 break;
14427         case -ENODEV:
14428                 printf("invalid port_id %d\n", res->port_id);
14429                 break;
14430         case -ENOTSUP:
14431                 printf("function not implemented\n");
14432                 break;
14433         default:
14434                 printf("programming error: (%s)\n", strerror(-ret));
14435         }
14436 }
14437
14438 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14439         .f = cmd_set_vf_mac_addr_parsed,
14440         .data = NULL,
14441         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14442         .tokens = {
14443                 (void *)&cmd_set_vf_mac_addr_set,
14444                 (void *)&cmd_set_vf_mac_addr_vf,
14445                 (void *)&cmd_set_vf_mac_addr_mac,
14446                 (void *)&cmd_set_vf_mac_addr_addr,
14447                 (void *)&cmd_set_vf_mac_addr_port_id,
14448                 (void *)&cmd_set_vf_mac_addr_vf_id,
14449                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14450                 NULL,
14451         },
14452 };
14453
14454 /* MACsec configuration */
14455
14456 /* Common result structure for MACsec offload enable */
14457 struct cmd_macsec_offload_on_result {
14458         cmdline_fixed_string_t set;
14459         cmdline_fixed_string_t macsec;
14460         cmdline_fixed_string_t offload;
14461         portid_t port_id;
14462         cmdline_fixed_string_t on;
14463         cmdline_fixed_string_t encrypt;
14464         cmdline_fixed_string_t en_on_off;
14465         cmdline_fixed_string_t replay_protect;
14466         cmdline_fixed_string_t rp_on_off;
14467 };
14468
14469 /* Common CLI fields for MACsec offload disable */
14470 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14471         TOKEN_STRING_INITIALIZER
14472                 (struct cmd_macsec_offload_on_result,
14473                  set, "set");
14474 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14475         TOKEN_STRING_INITIALIZER
14476                 (struct cmd_macsec_offload_on_result,
14477                  macsec, "macsec");
14478 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14479         TOKEN_STRING_INITIALIZER
14480                 (struct cmd_macsec_offload_on_result,
14481                  offload, "offload");
14482 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14483         TOKEN_NUM_INITIALIZER
14484                 (struct cmd_macsec_offload_on_result,
14485                  port_id, UINT16);
14486 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14487         TOKEN_STRING_INITIALIZER
14488                 (struct cmd_macsec_offload_on_result,
14489                  on, "on");
14490 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14491         TOKEN_STRING_INITIALIZER
14492                 (struct cmd_macsec_offload_on_result,
14493                  encrypt, "encrypt");
14494 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14495         TOKEN_STRING_INITIALIZER
14496                 (struct cmd_macsec_offload_on_result,
14497                  en_on_off, "on#off");
14498 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14499         TOKEN_STRING_INITIALIZER
14500                 (struct cmd_macsec_offload_on_result,
14501                  replay_protect, "replay-protect");
14502 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14503         TOKEN_STRING_INITIALIZER
14504                 (struct cmd_macsec_offload_on_result,
14505                  rp_on_off, "on#off");
14506
14507 static void
14508 cmd_set_macsec_offload_on_parsed(
14509         void *parsed_result,
14510         __rte_unused struct cmdline *cl,
14511         __rte_unused void *data)
14512 {
14513         struct cmd_macsec_offload_on_result *res = parsed_result;
14514         int ret = -ENOTSUP;
14515         portid_t port_id = res->port_id;
14516         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14517         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14518         struct rte_eth_dev_info dev_info;
14519
14520         if (port_id_is_invalid(port_id, ENABLED_WARN))
14521                 return;
14522         if (!port_is_stopped(port_id)) {
14523                 printf("Please stop port %d first\n", port_id);
14524                 return;
14525         }
14526
14527         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14528         if (ret != 0)
14529                 return;
14530
14531         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14532 #ifdef RTE_LIBRTE_IXGBE_PMD
14533                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14534 #endif
14535         }
14536         RTE_SET_USED(en);
14537         RTE_SET_USED(rp);
14538
14539         switch (ret) {
14540         case 0:
14541                 ports[port_id].dev_conf.txmode.offloads |=
14542                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14543                 cmd_reconfig_device_queue(port_id, 1, 1);
14544                 break;
14545         case -ENODEV:
14546                 printf("invalid port_id %d\n", port_id);
14547                 break;
14548         case -ENOTSUP:
14549                 printf("not supported on port %d\n", port_id);
14550                 break;
14551         default:
14552                 printf("programming error: (%s)\n", strerror(-ret));
14553         }
14554 }
14555
14556 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14557         .f = cmd_set_macsec_offload_on_parsed,
14558         .data = NULL,
14559         .help_str = "set macsec offload <port_id> on "
14560                 "encrypt on|off replay-protect on|off",
14561         .tokens = {
14562                 (void *)&cmd_macsec_offload_on_set,
14563                 (void *)&cmd_macsec_offload_on_macsec,
14564                 (void *)&cmd_macsec_offload_on_offload,
14565                 (void *)&cmd_macsec_offload_on_port_id,
14566                 (void *)&cmd_macsec_offload_on_on,
14567                 (void *)&cmd_macsec_offload_on_encrypt,
14568                 (void *)&cmd_macsec_offload_on_en_on_off,
14569                 (void *)&cmd_macsec_offload_on_replay_protect,
14570                 (void *)&cmd_macsec_offload_on_rp_on_off,
14571                 NULL,
14572         },
14573 };
14574
14575 /* Common result structure for MACsec offload disable */
14576 struct cmd_macsec_offload_off_result {
14577         cmdline_fixed_string_t set;
14578         cmdline_fixed_string_t macsec;
14579         cmdline_fixed_string_t offload;
14580         portid_t port_id;
14581         cmdline_fixed_string_t off;
14582 };
14583
14584 /* Common CLI fields for MACsec offload disable */
14585 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14586         TOKEN_STRING_INITIALIZER
14587                 (struct cmd_macsec_offload_off_result,
14588                  set, "set");
14589 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14590         TOKEN_STRING_INITIALIZER
14591                 (struct cmd_macsec_offload_off_result,
14592                  macsec, "macsec");
14593 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14594         TOKEN_STRING_INITIALIZER
14595                 (struct cmd_macsec_offload_off_result,
14596                  offload, "offload");
14597 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14598         TOKEN_NUM_INITIALIZER
14599                 (struct cmd_macsec_offload_off_result,
14600                  port_id, UINT16);
14601 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14602         TOKEN_STRING_INITIALIZER
14603                 (struct cmd_macsec_offload_off_result,
14604                  off, "off");
14605
14606 static void
14607 cmd_set_macsec_offload_off_parsed(
14608         void *parsed_result,
14609         __rte_unused struct cmdline *cl,
14610         __rte_unused void *data)
14611 {
14612         struct cmd_macsec_offload_off_result *res = parsed_result;
14613         int ret = -ENOTSUP;
14614         struct rte_eth_dev_info dev_info;
14615         portid_t port_id = res->port_id;
14616
14617         if (port_id_is_invalid(port_id, ENABLED_WARN))
14618                 return;
14619         if (!port_is_stopped(port_id)) {
14620                 printf("Please stop port %d first\n", port_id);
14621                 return;
14622         }
14623
14624         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14625         if (ret != 0)
14626                 return;
14627
14628         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14629 #ifdef RTE_LIBRTE_IXGBE_PMD
14630                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14631 #endif
14632         }
14633         switch (ret) {
14634         case 0:
14635                 ports[port_id].dev_conf.txmode.offloads &=
14636                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14637                 cmd_reconfig_device_queue(port_id, 1, 1);
14638                 break;
14639         case -ENODEV:
14640                 printf("invalid port_id %d\n", port_id);
14641                 break;
14642         case -ENOTSUP:
14643                 printf("not supported on port %d\n", port_id);
14644                 break;
14645         default:
14646                 printf("programming error: (%s)\n", strerror(-ret));
14647         }
14648 }
14649
14650 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14651         .f = cmd_set_macsec_offload_off_parsed,
14652         .data = NULL,
14653         .help_str = "set macsec offload <port_id> off",
14654         .tokens = {
14655                 (void *)&cmd_macsec_offload_off_set,
14656                 (void *)&cmd_macsec_offload_off_macsec,
14657                 (void *)&cmd_macsec_offload_off_offload,
14658                 (void *)&cmd_macsec_offload_off_port_id,
14659                 (void *)&cmd_macsec_offload_off_off,
14660                 NULL,
14661         },
14662 };
14663
14664 /* Common result structure for MACsec secure connection configure */
14665 struct cmd_macsec_sc_result {
14666         cmdline_fixed_string_t set;
14667         cmdline_fixed_string_t macsec;
14668         cmdline_fixed_string_t sc;
14669         cmdline_fixed_string_t tx_rx;
14670         portid_t port_id;
14671         struct rte_ether_addr mac;
14672         uint16_t pi;
14673 };
14674
14675 /* Common CLI fields for MACsec secure connection configure */
14676 cmdline_parse_token_string_t cmd_macsec_sc_set =
14677         TOKEN_STRING_INITIALIZER
14678                 (struct cmd_macsec_sc_result,
14679                  set, "set");
14680 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14681         TOKEN_STRING_INITIALIZER
14682                 (struct cmd_macsec_sc_result,
14683                  macsec, "macsec");
14684 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14685         TOKEN_STRING_INITIALIZER
14686                 (struct cmd_macsec_sc_result,
14687                  sc, "sc");
14688 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14689         TOKEN_STRING_INITIALIZER
14690                 (struct cmd_macsec_sc_result,
14691                  tx_rx, "tx#rx");
14692 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14693         TOKEN_NUM_INITIALIZER
14694                 (struct cmd_macsec_sc_result,
14695                  port_id, UINT16);
14696 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14697         TOKEN_ETHERADDR_INITIALIZER
14698                 (struct cmd_macsec_sc_result,
14699                  mac);
14700 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14701         TOKEN_NUM_INITIALIZER
14702                 (struct cmd_macsec_sc_result,
14703                  pi, UINT16);
14704
14705 static void
14706 cmd_set_macsec_sc_parsed(
14707         void *parsed_result,
14708         __rte_unused struct cmdline *cl,
14709         __rte_unused void *data)
14710 {
14711         struct cmd_macsec_sc_result *res = parsed_result;
14712         int ret = -ENOTSUP;
14713         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14714
14715 #ifdef RTE_LIBRTE_IXGBE_PMD
14716         ret = is_tx ?
14717                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14718                                 res->mac.addr_bytes) :
14719                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14720                                 res->mac.addr_bytes, res->pi);
14721 #endif
14722         RTE_SET_USED(is_tx);
14723
14724         switch (ret) {
14725         case 0:
14726                 break;
14727         case -ENODEV:
14728                 printf("invalid port_id %d\n", res->port_id);
14729                 break;
14730         case -ENOTSUP:
14731                 printf("not supported on port %d\n", res->port_id);
14732                 break;
14733         default:
14734                 printf("programming error: (%s)\n", strerror(-ret));
14735         }
14736 }
14737
14738 cmdline_parse_inst_t cmd_set_macsec_sc = {
14739         .f = cmd_set_macsec_sc_parsed,
14740         .data = NULL,
14741         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14742         .tokens = {
14743                 (void *)&cmd_macsec_sc_set,
14744                 (void *)&cmd_macsec_sc_macsec,
14745                 (void *)&cmd_macsec_sc_sc,
14746                 (void *)&cmd_macsec_sc_tx_rx,
14747                 (void *)&cmd_macsec_sc_port_id,
14748                 (void *)&cmd_macsec_sc_mac,
14749                 (void *)&cmd_macsec_sc_pi,
14750                 NULL,
14751         },
14752 };
14753
14754 /* Common result structure for MACsec secure connection configure */
14755 struct cmd_macsec_sa_result {
14756         cmdline_fixed_string_t set;
14757         cmdline_fixed_string_t macsec;
14758         cmdline_fixed_string_t sa;
14759         cmdline_fixed_string_t tx_rx;
14760         portid_t port_id;
14761         uint8_t idx;
14762         uint8_t an;
14763         uint32_t pn;
14764         cmdline_fixed_string_t key;
14765 };
14766
14767 /* Common CLI fields for MACsec secure connection configure */
14768 cmdline_parse_token_string_t cmd_macsec_sa_set =
14769         TOKEN_STRING_INITIALIZER
14770                 (struct cmd_macsec_sa_result,
14771                  set, "set");
14772 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14773         TOKEN_STRING_INITIALIZER
14774                 (struct cmd_macsec_sa_result,
14775                  macsec, "macsec");
14776 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14777         TOKEN_STRING_INITIALIZER
14778                 (struct cmd_macsec_sa_result,
14779                  sa, "sa");
14780 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14781         TOKEN_STRING_INITIALIZER
14782                 (struct cmd_macsec_sa_result,
14783                  tx_rx, "tx#rx");
14784 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14785         TOKEN_NUM_INITIALIZER
14786                 (struct cmd_macsec_sa_result,
14787                  port_id, UINT16);
14788 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14789         TOKEN_NUM_INITIALIZER
14790                 (struct cmd_macsec_sa_result,
14791                  idx, UINT8);
14792 cmdline_parse_token_num_t cmd_macsec_sa_an =
14793         TOKEN_NUM_INITIALIZER
14794                 (struct cmd_macsec_sa_result,
14795                  an, UINT8);
14796 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14797         TOKEN_NUM_INITIALIZER
14798                 (struct cmd_macsec_sa_result,
14799                  pn, UINT32);
14800 cmdline_parse_token_string_t cmd_macsec_sa_key =
14801         TOKEN_STRING_INITIALIZER
14802                 (struct cmd_macsec_sa_result,
14803                  key, NULL);
14804
14805 static void
14806 cmd_set_macsec_sa_parsed(
14807         void *parsed_result,
14808         __rte_unused struct cmdline *cl,
14809         __rte_unused void *data)
14810 {
14811         struct cmd_macsec_sa_result *res = parsed_result;
14812         int ret = -ENOTSUP;
14813         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14814         uint8_t key[16] = { 0 };
14815         uint8_t xdgt0;
14816         uint8_t xdgt1;
14817         int key_len;
14818         int i;
14819
14820         key_len = strlen(res->key) / 2;
14821         if (key_len > 16)
14822                 key_len = 16;
14823
14824         for (i = 0; i < key_len; i++) {
14825                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14826                 if (xdgt0 == 0xFF)
14827                         return;
14828                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14829                 if (xdgt1 == 0xFF)
14830                         return;
14831                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14832         }
14833
14834 #ifdef RTE_LIBRTE_IXGBE_PMD
14835         ret = is_tx ?
14836                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14837                         res->idx, res->an, res->pn, key) :
14838                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14839                         res->idx, res->an, res->pn, key);
14840 #endif
14841         RTE_SET_USED(is_tx);
14842         RTE_SET_USED(key);
14843
14844         switch (ret) {
14845         case 0:
14846                 break;
14847         case -EINVAL:
14848                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14849                 break;
14850         case -ENODEV:
14851                 printf("invalid port_id %d\n", res->port_id);
14852                 break;
14853         case -ENOTSUP:
14854                 printf("not supported on port %d\n", res->port_id);
14855                 break;
14856         default:
14857                 printf("programming error: (%s)\n", strerror(-ret));
14858         }
14859 }
14860
14861 cmdline_parse_inst_t cmd_set_macsec_sa = {
14862         .f = cmd_set_macsec_sa_parsed,
14863         .data = NULL,
14864         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14865         .tokens = {
14866                 (void *)&cmd_macsec_sa_set,
14867                 (void *)&cmd_macsec_sa_macsec,
14868                 (void *)&cmd_macsec_sa_sa,
14869                 (void *)&cmd_macsec_sa_tx_rx,
14870                 (void *)&cmd_macsec_sa_port_id,
14871                 (void *)&cmd_macsec_sa_idx,
14872                 (void *)&cmd_macsec_sa_an,
14873                 (void *)&cmd_macsec_sa_pn,
14874                 (void *)&cmd_macsec_sa_key,
14875                 NULL,
14876         },
14877 };
14878
14879 /* VF unicast promiscuous mode configuration */
14880
14881 /* Common result structure for VF unicast promiscuous mode */
14882 struct cmd_vf_promisc_result {
14883         cmdline_fixed_string_t set;
14884         cmdline_fixed_string_t vf;
14885         cmdline_fixed_string_t promisc;
14886         portid_t port_id;
14887         uint32_t vf_id;
14888         cmdline_fixed_string_t on_off;
14889 };
14890
14891 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14892 cmdline_parse_token_string_t cmd_vf_promisc_set =
14893         TOKEN_STRING_INITIALIZER
14894                 (struct cmd_vf_promisc_result,
14895                  set, "set");
14896 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14897         TOKEN_STRING_INITIALIZER
14898                 (struct cmd_vf_promisc_result,
14899                  vf, "vf");
14900 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14901         TOKEN_STRING_INITIALIZER
14902                 (struct cmd_vf_promisc_result,
14903                  promisc, "promisc");
14904 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14905         TOKEN_NUM_INITIALIZER
14906                 (struct cmd_vf_promisc_result,
14907                  port_id, UINT16);
14908 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14909         TOKEN_NUM_INITIALIZER
14910                 (struct cmd_vf_promisc_result,
14911                  vf_id, UINT32);
14912 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14913         TOKEN_STRING_INITIALIZER
14914                 (struct cmd_vf_promisc_result,
14915                  on_off, "on#off");
14916
14917 static void
14918 cmd_set_vf_promisc_parsed(
14919         void *parsed_result,
14920         __rte_unused struct cmdline *cl,
14921         __rte_unused void *data)
14922 {
14923         struct cmd_vf_promisc_result *res = parsed_result;
14924         int ret = -ENOTSUP;
14925
14926         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14927
14928         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14929                 return;
14930
14931 #ifdef RTE_LIBRTE_I40E_PMD
14932         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14933                                                   res->vf_id, is_on);
14934 #endif
14935
14936         switch (ret) {
14937         case 0:
14938                 break;
14939         case -EINVAL:
14940                 printf("invalid vf_id %d\n", res->vf_id);
14941                 break;
14942         case -ENODEV:
14943                 printf("invalid port_id %d\n", res->port_id);
14944                 break;
14945         case -ENOTSUP:
14946                 printf("function not implemented\n");
14947                 break;
14948         default:
14949                 printf("programming error: (%s)\n", strerror(-ret));
14950         }
14951 }
14952
14953 cmdline_parse_inst_t cmd_set_vf_promisc = {
14954         .f = cmd_set_vf_promisc_parsed,
14955         .data = NULL,
14956         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14957                 "Set unicast promiscuous mode for a VF from the PF",
14958         .tokens = {
14959                 (void *)&cmd_vf_promisc_set,
14960                 (void *)&cmd_vf_promisc_vf,
14961                 (void *)&cmd_vf_promisc_promisc,
14962                 (void *)&cmd_vf_promisc_port_id,
14963                 (void *)&cmd_vf_promisc_vf_id,
14964                 (void *)&cmd_vf_promisc_on_off,
14965                 NULL,
14966         },
14967 };
14968
14969 /* VF multicast promiscuous mode configuration */
14970
14971 /* Common result structure for VF multicast promiscuous mode */
14972 struct cmd_vf_allmulti_result {
14973         cmdline_fixed_string_t set;
14974         cmdline_fixed_string_t vf;
14975         cmdline_fixed_string_t allmulti;
14976         portid_t port_id;
14977         uint32_t vf_id;
14978         cmdline_fixed_string_t on_off;
14979 };
14980
14981 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14982 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14983         TOKEN_STRING_INITIALIZER
14984                 (struct cmd_vf_allmulti_result,
14985                  set, "set");
14986 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14987         TOKEN_STRING_INITIALIZER
14988                 (struct cmd_vf_allmulti_result,
14989                  vf, "vf");
14990 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14991         TOKEN_STRING_INITIALIZER
14992                 (struct cmd_vf_allmulti_result,
14993                  allmulti, "allmulti");
14994 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14995         TOKEN_NUM_INITIALIZER
14996                 (struct cmd_vf_allmulti_result,
14997                  port_id, UINT16);
14998 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14999         TOKEN_NUM_INITIALIZER
15000                 (struct cmd_vf_allmulti_result,
15001                  vf_id, UINT32);
15002 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
15003         TOKEN_STRING_INITIALIZER
15004                 (struct cmd_vf_allmulti_result,
15005                  on_off, "on#off");
15006
15007 static void
15008 cmd_set_vf_allmulti_parsed(
15009         void *parsed_result,
15010         __rte_unused struct cmdline *cl,
15011         __rte_unused void *data)
15012 {
15013         struct cmd_vf_allmulti_result *res = parsed_result;
15014         int ret = -ENOTSUP;
15015
15016         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15017
15018         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15019                 return;
15020
15021 #ifdef RTE_LIBRTE_I40E_PMD
15022         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
15023                                                     res->vf_id, is_on);
15024 #endif
15025
15026         switch (ret) {
15027         case 0:
15028                 break;
15029         case -EINVAL:
15030                 printf("invalid vf_id %d\n", res->vf_id);
15031                 break;
15032         case -ENODEV:
15033                 printf("invalid port_id %d\n", res->port_id);
15034                 break;
15035         case -ENOTSUP:
15036                 printf("function not implemented\n");
15037                 break;
15038         default:
15039                 printf("programming error: (%s)\n", strerror(-ret));
15040         }
15041 }
15042
15043 cmdline_parse_inst_t cmd_set_vf_allmulti = {
15044         .f = cmd_set_vf_allmulti_parsed,
15045         .data = NULL,
15046         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
15047                 "Set multicast promiscuous mode for a VF from the PF",
15048         .tokens = {
15049                 (void *)&cmd_vf_allmulti_set,
15050                 (void *)&cmd_vf_allmulti_vf,
15051                 (void *)&cmd_vf_allmulti_allmulti,
15052                 (void *)&cmd_vf_allmulti_port_id,
15053                 (void *)&cmd_vf_allmulti_vf_id,
15054                 (void *)&cmd_vf_allmulti_on_off,
15055                 NULL,
15056         },
15057 };
15058
15059 /* vf broadcast mode configuration */
15060
15061 /* Common result structure for vf broadcast */
15062 struct cmd_set_vf_broadcast_result {
15063         cmdline_fixed_string_t set;
15064         cmdline_fixed_string_t vf;
15065         cmdline_fixed_string_t broadcast;
15066         portid_t port_id;
15067         uint16_t vf_id;
15068         cmdline_fixed_string_t on_off;
15069 };
15070
15071 /* Common CLI fields for vf broadcast enable disable */
15072 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
15073         TOKEN_STRING_INITIALIZER
15074                 (struct cmd_set_vf_broadcast_result,
15075                  set, "set");
15076 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
15077         TOKEN_STRING_INITIALIZER
15078                 (struct cmd_set_vf_broadcast_result,
15079                  vf, "vf");
15080 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
15081         TOKEN_STRING_INITIALIZER
15082                 (struct cmd_set_vf_broadcast_result,
15083                  broadcast, "broadcast");
15084 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
15085         TOKEN_NUM_INITIALIZER
15086                 (struct cmd_set_vf_broadcast_result,
15087                  port_id, UINT16);
15088 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
15089         TOKEN_NUM_INITIALIZER
15090                 (struct cmd_set_vf_broadcast_result,
15091                  vf_id, UINT16);
15092 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
15093         TOKEN_STRING_INITIALIZER
15094                 (struct cmd_set_vf_broadcast_result,
15095                  on_off, "on#off");
15096
15097 static void
15098 cmd_set_vf_broadcast_parsed(
15099         void *parsed_result,
15100         __rte_unused struct cmdline *cl,
15101         __rte_unused void *data)
15102 {
15103         struct cmd_set_vf_broadcast_result *res = parsed_result;
15104         int ret = -ENOTSUP;
15105
15106         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15107
15108         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15109                 return;
15110
15111 #ifdef RTE_LIBRTE_I40E_PMD
15112         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
15113                                             res->vf_id, is_on);
15114 #endif
15115
15116         switch (ret) {
15117         case 0:
15118                 break;
15119         case -EINVAL:
15120                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15121                 break;
15122         case -ENODEV:
15123                 printf("invalid port_id %d\n", res->port_id);
15124                 break;
15125         case -ENOTSUP:
15126                 printf("function not implemented\n");
15127                 break;
15128         default:
15129                 printf("programming error: (%s)\n", strerror(-ret));
15130         }
15131 }
15132
15133 cmdline_parse_inst_t cmd_set_vf_broadcast = {
15134         .f = cmd_set_vf_broadcast_parsed,
15135         .data = NULL,
15136         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
15137         .tokens = {
15138                 (void *)&cmd_set_vf_broadcast_set,
15139                 (void *)&cmd_set_vf_broadcast_vf,
15140                 (void *)&cmd_set_vf_broadcast_broadcast,
15141                 (void *)&cmd_set_vf_broadcast_port_id,
15142                 (void *)&cmd_set_vf_broadcast_vf_id,
15143                 (void *)&cmd_set_vf_broadcast_on_off,
15144                 NULL,
15145         },
15146 };
15147
15148 /* vf vlan tag configuration */
15149
15150 /* Common result structure for vf vlan tag */
15151 struct cmd_set_vf_vlan_tag_result {
15152         cmdline_fixed_string_t set;
15153         cmdline_fixed_string_t vf;
15154         cmdline_fixed_string_t vlan;
15155         cmdline_fixed_string_t tag;
15156         portid_t port_id;
15157         uint16_t vf_id;
15158         cmdline_fixed_string_t on_off;
15159 };
15160
15161 /* Common CLI fields for vf vlan tag enable disable */
15162 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
15163         TOKEN_STRING_INITIALIZER
15164                 (struct cmd_set_vf_vlan_tag_result,
15165                  set, "set");
15166 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
15167         TOKEN_STRING_INITIALIZER
15168                 (struct cmd_set_vf_vlan_tag_result,
15169                  vf, "vf");
15170 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
15171         TOKEN_STRING_INITIALIZER
15172                 (struct cmd_set_vf_vlan_tag_result,
15173                  vlan, "vlan");
15174 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
15175         TOKEN_STRING_INITIALIZER
15176                 (struct cmd_set_vf_vlan_tag_result,
15177                  tag, "tag");
15178 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
15179         TOKEN_NUM_INITIALIZER
15180                 (struct cmd_set_vf_vlan_tag_result,
15181                  port_id, UINT16);
15182 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
15183         TOKEN_NUM_INITIALIZER
15184                 (struct cmd_set_vf_vlan_tag_result,
15185                  vf_id, UINT16);
15186 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
15187         TOKEN_STRING_INITIALIZER
15188                 (struct cmd_set_vf_vlan_tag_result,
15189                  on_off, "on#off");
15190
15191 static void
15192 cmd_set_vf_vlan_tag_parsed(
15193         void *parsed_result,
15194         __rte_unused struct cmdline *cl,
15195         __rte_unused void *data)
15196 {
15197         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
15198         int ret = -ENOTSUP;
15199
15200         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15201
15202         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15203                 return;
15204
15205 #ifdef RTE_LIBRTE_I40E_PMD
15206         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
15207                                            res->vf_id, is_on);
15208 #endif
15209
15210         switch (ret) {
15211         case 0:
15212                 break;
15213         case -EINVAL:
15214                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15215                 break;
15216         case -ENODEV:
15217                 printf("invalid port_id %d\n", res->port_id);
15218                 break;
15219         case -ENOTSUP:
15220                 printf("function not implemented\n");
15221                 break;
15222         default:
15223                 printf("programming error: (%s)\n", strerror(-ret));
15224         }
15225 }
15226
15227 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15228         .f = cmd_set_vf_vlan_tag_parsed,
15229         .data = NULL,
15230         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15231         .tokens = {
15232                 (void *)&cmd_set_vf_vlan_tag_set,
15233                 (void *)&cmd_set_vf_vlan_tag_vf,
15234                 (void *)&cmd_set_vf_vlan_tag_vlan,
15235                 (void *)&cmd_set_vf_vlan_tag_tag,
15236                 (void *)&cmd_set_vf_vlan_tag_port_id,
15237                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15238                 (void *)&cmd_set_vf_vlan_tag_on_off,
15239                 NULL,
15240         },
15241 };
15242
15243 /* Common definition of VF and TC TX bandwidth configuration */
15244 struct cmd_vf_tc_bw_result {
15245         cmdline_fixed_string_t set;
15246         cmdline_fixed_string_t vf;
15247         cmdline_fixed_string_t tc;
15248         cmdline_fixed_string_t tx;
15249         cmdline_fixed_string_t min_bw;
15250         cmdline_fixed_string_t max_bw;
15251         cmdline_fixed_string_t strict_link_prio;
15252         portid_t port_id;
15253         uint16_t vf_id;
15254         uint8_t tc_no;
15255         uint32_t bw;
15256         cmdline_fixed_string_t bw_list;
15257         uint8_t tc_map;
15258 };
15259
15260 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15261         TOKEN_STRING_INITIALIZER
15262                 (struct cmd_vf_tc_bw_result,
15263                  set, "set");
15264 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15265         TOKEN_STRING_INITIALIZER
15266                 (struct cmd_vf_tc_bw_result,
15267                  vf, "vf");
15268 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15269         TOKEN_STRING_INITIALIZER
15270                 (struct cmd_vf_tc_bw_result,
15271                  tc, "tc");
15272 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15273         TOKEN_STRING_INITIALIZER
15274                 (struct cmd_vf_tc_bw_result,
15275                  tx, "tx");
15276 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15277         TOKEN_STRING_INITIALIZER
15278                 (struct cmd_vf_tc_bw_result,
15279                  strict_link_prio, "strict-link-priority");
15280 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15281         TOKEN_STRING_INITIALIZER
15282                 (struct cmd_vf_tc_bw_result,
15283                  min_bw, "min-bandwidth");
15284 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15285         TOKEN_STRING_INITIALIZER
15286                 (struct cmd_vf_tc_bw_result,
15287                  max_bw, "max-bandwidth");
15288 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15289         TOKEN_NUM_INITIALIZER
15290                 (struct cmd_vf_tc_bw_result,
15291                  port_id, UINT16);
15292 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15293         TOKEN_NUM_INITIALIZER
15294                 (struct cmd_vf_tc_bw_result,
15295                  vf_id, UINT16);
15296 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15297         TOKEN_NUM_INITIALIZER
15298                 (struct cmd_vf_tc_bw_result,
15299                  tc_no, UINT8);
15300 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15301         TOKEN_NUM_INITIALIZER
15302                 (struct cmd_vf_tc_bw_result,
15303                  bw, UINT32);
15304 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15305         TOKEN_STRING_INITIALIZER
15306                 (struct cmd_vf_tc_bw_result,
15307                  bw_list, NULL);
15308 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15309         TOKEN_NUM_INITIALIZER
15310                 (struct cmd_vf_tc_bw_result,
15311                  tc_map, UINT8);
15312
15313 /* VF max bandwidth setting */
15314 static void
15315 cmd_vf_max_bw_parsed(
15316         void *parsed_result,
15317         __rte_unused struct cmdline *cl,
15318         __rte_unused void *data)
15319 {
15320         struct cmd_vf_tc_bw_result *res = parsed_result;
15321         int ret = -ENOTSUP;
15322
15323         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15324                 return;
15325
15326 #ifdef RTE_LIBRTE_I40E_PMD
15327         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15328                                          res->vf_id, res->bw);
15329 #endif
15330
15331         switch (ret) {
15332         case 0:
15333                 break;
15334         case -EINVAL:
15335                 printf("invalid vf_id %d or bandwidth %d\n",
15336                        res->vf_id, res->bw);
15337                 break;
15338         case -ENODEV:
15339                 printf("invalid port_id %d\n", res->port_id);
15340                 break;
15341         case -ENOTSUP:
15342                 printf("function not implemented\n");
15343                 break;
15344         default:
15345                 printf("programming error: (%s)\n", strerror(-ret));
15346         }
15347 }
15348
15349 cmdline_parse_inst_t cmd_vf_max_bw = {
15350         .f = cmd_vf_max_bw_parsed,
15351         .data = NULL,
15352         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15353         .tokens = {
15354                 (void *)&cmd_vf_tc_bw_set,
15355                 (void *)&cmd_vf_tc_bw_vf,
15356                 (void *)&cmd_vf_tc_bw_tx,
15357                 (void *)&cmd_vf_tc_bw_max_bw,
15358                 (void *)&cmd_vf_tc_bw_port_id,
15359                 (void *)&cmd_vf_tc_bw_vf_id,
15360                 (void *)&cmd_vf_tc_bw_bw,
15361                 NULL,
15362         },
15363 };
15364
15365 static int
15366 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15367                            uint8_t *tc_num,
15368                            char *str)
15369 {
15370         uint32_t size;
15371         const char *p, *p0 = str;
15372         char s[256];
15373         char *end;
15374         char *str_fld[16];
15375         uint16_t i;
15376         int ret;
15377
15378         p = strchr(p0, '(');
15379         if (p == NULL) {
15380                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15381                 return -1;
15382         }
15383         p++;
15384         p0 = strchr(p, ')');
15385         if (p0 == NULL) {
15386                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15387                 return -1;
15388         }
15389         size = p0 - p;
15390         if (size >= sizeof(s)) {
15391                 printf("The string size exceeds the internal buffer size\n");
15392                 return -1;
15393         }
15394         snprintf(s, sizeof(s), "%.*s", size, p);
15395         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15396         if (ret <= 0) {
15397                 printf("Failed to get the bandwidth list. ");
15398                 return -1;
15399         }
15400         *tc_num = ret;
15401         for (i = 0; i < ret; i++)
15402                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15403
15404         return 0;
15405 }
15406
15407 /* TC min bandwidth setting */
15408 static void
15409 cmd_vf_tc_min_bw_parsed(
15410         void *parsed_result,
15411         __rte_unused struct cmdline *cl,
15412         __rte_unused void *data)
15413 {
15414         struct cmd_vf_tc_bw_result *res = parsed_result;
15415         uint8_t tc_num;
15416         uint8_t bw[16];
15417         int ret = -ENOTSUP;
15418
15419         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15420                 return;
15421
15422         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15423         if (ret)
15424                 return;
15425
15426 #ifdef RTE_LIBRTE_I40E_PMD
15427         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15428                                               tc_num, bw);
15429 #endif
15430
15431         switch (ret) {
15432         case 0:
15433                 break;
15434         case -EINVAL:
15435                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15436                 break;
15437         case -ENODEV:
15438                 printf("invalid port_id %d\n", res->port_id);
15439                 break;
15440         case -ENOTSUP:
15441                 printf("function not implemented\n");
15442                 break;
15443         default:
15444                 printf("programming error: (%s)\n", strerror(-ret));
15445         }
15446 }
15447
15448 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15449         .f = cmd_vf_tc_min_bw_parsed,
15450         .data = NULL,
15451         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15452                     " <bw1, bw2, ...>",
15453         .tokens = {
15454                 (void *)&cmd_vf_tc_bw_set,
15455                 (void *)&cmd_vf_tc_bw_vf,
15456                 (void *)&cmd_vf_tc_bw_tc,
15457                 (void *)&cmd_vf_tc_bw_tx,
15458                 (void *)&cmd_vf_tc_bw_min_bw,
15459                 (void *)&cmd_vf_tc_bw_port_id,
15460                 (void *)&cmd_vf_tc_bw_vf_id,
15461                 (void *)&cmd_vf_tc_bw_bw_list,
15462                 NULL,
15463         },
15464 };
15465
15466 static void
15467 cmd_tc_min_bw_parsed(
15468         void *parsed_result,
15469         __rte_unused struct cmdline *cl,
15470         __rte_unused void *data)
15471 {
15472         struct cmd_vf_tc_bw_result *res = parsed_result;
15473         struct rte_port *port;
15474         uint8_t tc_num;
15475         uint8_t bw[16];
15476         int ret = -ENOTSUP;
15477
15478         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15479                 return;
15480
15481         port = &ports[res->port_id];
15482         /** Check if the port is not started **/
15483         if (port->port_status != RTE_PORT_STOPPED) {
15484                 printf("Please stop port %d first\n", res->port_id);
15485                 return;
15486         }
15487
15488         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15489         if (ret)
15490                 return;
15491
15492 #ifdef RTE_LIBRTE_IXGBE_PMD
15493         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15494 #endif
15495
15496         switch (ret) {
15497         case 0:
15498                 break;
15499         case -EINVAL:
15500                 printf("invalid bandwidth\n");
15501                 break;
15502         case -ENODEV:
15503                 printf("invalid port_id %d\n", res->port_id);
15504                 break;
15505         case -ENOTSUP:
15506                 printf("function not implemented\n");
15507                 break;
15508         default:
15509                 printf("programming error: (%s)\n", strerror(-ret));
15510         }
15511 }
15512
15513 cmdline_parse_inst_t cmd_tc_min_bw = {
15514         .f = cmd_tc_min_bw_parsed,
15515         .data = NULL,
15516         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15517         .tokens = {
15518                 (void *)&cmd_vf_tc_bw_set,
15519                 (void *)&cmd_vf_tc_bw_tc,
15520                 (void *)&cmd_vf_tc_bw_tx,
15521                 (void *)&cmd_vf_tc_bw_min_bw,
15522                 (void *)&cmd_vf_tc_bw_port_id,
15523                 (void *)&cmd_vf_tc_bw_bw_list,
15524                 NULL,
15525         },
15526 };
15527
15528 /* TC max bandwidth setting */
15529 static void
15530 cmd_vf_tc_max_bw_parsed(
15531         void *parsed_result,
15532         __rte_unused struct cmdline *cl,
15533         __rte_unused void *data)
15534 {
15535         struct cmd_vf_tc_bw_result *res = parsed_result;
15536         int ret = -ENOTSUP;
15537
15538         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15539                 return;
15540
15541 #ifdef RTE_LIBRTE_I40E_PMD
15542         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15543                                             res->tc_no, res->bw);
15544 #endif
15545
15546         switch (ret) {
15547         case 0:
15548                 break;
15549         case -EINVAL:
15550                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15551                        res->vf_id, res->tc_no, res->bw);
15552                 break;
15553         case -ENODEV:
15554                 printf("invalid port_id %d\n", res->port_id);
15555                 break;
15556         case -ENOTSUP:
15557                 printf("function not implemented\n");
15558                 break;
15559         default:
15560                 printf("programming error: (%s)\n", strerror(-ret));
15561         }
15562 }
15563
15564 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15565         .f = cmd_vf_tc_max_bw_parsed,
15566         .data = NULL,
15567         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15568                     " <bandwidth>",
15569         .tokens = {
15570                 (void *)&cmd_vf_tc_bw_set,
15571                 (void *)&cmd_vf_tc_bw_vf,
15572                 (void *)&cmd_vf_tc_bw_tc,
15573                 (void *)&cmd_vf_tc_bw_tx,
15574                 (void *)&cmd_vf_tc_bw_max_bw,
15575                 (void *)&cmd_vf_tc_bw_port_id,
15576                 (void *)&cmd_vf_tc_bw_vf_id,
15577                 (void *)&cmd_vf_tc_bw_tc_no,
15578                 (void *)&cmd_vf_tc_bw_bw,
15579                 NULL,
15580         },
15581 };
15582
15583 /** Set VXLAN encapsulation details */
15584 struct cmd_set_vxlan_result {
15585         cmdline_fixed_string_t set;
15586         cmdline_fixed_string_t vxlan;
15587         cmdline_fixed_string_t pos_token;
15588         cmdline_fixed_string_t ip_version;
15589         uint32_t vlan_present:1;
15590         uint32_t vni;
15591         uint16_t udp_src;
15592         uint16_t udp_dst;
15593         cmdline_ipaddr_t ip_src;
15594         cmdline_ipaddr_t ip_dst;
15595         uint16_t tci;
15596         uint8_t tos;
15597         uint8_t ttl;
15598         struct rte_ether_addr eth_src;
15599         struct rte_ether_addr eth_dst;
15600 };
15601
15602 cmdline_parse_token_string_t cmd_set_vxlan_set =
15603         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15604 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15605         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15606 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15607         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15608                                  "vxlan-tos-ttl");
15609 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15610         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15611                                  "vxlan-with-vlan");
15612 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15613         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15614                                  "ip-version");
15615 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15616         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15617                                  "ipv4#ipv6");
15618 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15619         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15620                                  "vni");
15621 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15622         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15623 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15624         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15625                                  "udp-src");
15626 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15627         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15628 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15629         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15630                                  "udp-dst");
15631 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15632         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15633 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15634         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15635                                  "ip-tos");
15636 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15637         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15638 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15639         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15640                                  "ip-ttl");
15641 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15642         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15643 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15644         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15645                                  "ip-src");
15646 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15647         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15648 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15649         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15650                                  "ip-dst");
15651 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15652         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15653 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15654         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15655                                  "vlan-tci");
15656 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15657         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15658 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15659         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15660                                  "eth-src");
15661 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15662         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15663 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15664         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15665                                  "eth-dst");
15666 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15667         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15668
15669 static void cmd_set_vxlan_parsed(void *parsed_result,
15670         __rte_unused struct cmdline *cl,
15671         __rte_unused void *data)
15672 {
15673         struct cmd_set_vxlan_result *res = parsed_result;
15674         union {
15675                 uint32_t vxlan_id;
15676                 uint8_t vni[4];
15677         } id = {
15678                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15679         };
15680
15681         vxlan_encap_conf.select_tos_ttl = 0;
15682         if (strcmp(res->vxlan, "vxlan") == 0)
15683                 vxlan_encap_conf.select_vlan = 0;
15684         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15685                 vxlan_encap_conf.select_vlan = 1;
15686         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15687                 vxlan_encap_conf.select_vlan = 0;
15688                 vxlan_encap_conf.select_tos_ttl = 1;
15689         }
15690         if (strcmp(res->ip_version, "ipv4") == 0)
15691                 vxlan_encap_conf.select_ipv4 = 1;
15692         else if (strcmp(res->ip_version, "ipv6") == 0)
15693                 vxlan_encap_conf.select_ipv4 = 0;
15694         else
15695                 return;
15696         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15697         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15698         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15699         vxlan_encap_conf.ip_tos = res->tos;
15700         vxlan_encap_conf.ip_ttl = res->ttl;
15701         if (vxlan_encap_conf.select_ipv4) {
15702                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15703                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15704         } else {
15705                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15706                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15707         }
15708         if (vxlan_encap_conf.select_vlan)
15709                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15710         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15711                    RTE_ETHER_ADDR_LEN);
15712         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15713                    RTE_ETHER_ADDR_LEN);
15714 }
15715
15716 cmdline_parse_inst_t cmd_set_vxlan = {
15717         .f = cmd_set_vxlan_parsed,
15718         .data = NULL,
15719         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15720                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15721                 " eth-src <eth-src> eth-dst <eth-dst>",
15722         .tokens = {
15723                 (void *)&cmd_set_vxlan_set,
15724                 (void *)&cmd_set_vxlan_vxlan,
15725                 (void *)&cmd_set_vxlan_ip_version,
15726                 (void *)&cmd_set_vxlan_ip_version_value,
15727                 (void *)&cmd_set_vxlan_vni,
15728                 (void *)&cmd_set_vxlan_vni_value,
15729                 (void *)&cmd_set_vxlan_udp_src,
15730                 (void *)&cmd_set_vxlan_udp_src_value,
15731                 (void *)&cmd_set_vxlan_udp_dst,
15732                 (void *)&cmd_set_vxlan_udp_dst_value,
15733                 (void *)&cmd_set_vxlan_ip_src,
15734                 (void *)&cmd_set_vxlan_ip_src_value,
15735                 (void *)&cmd_set_vxlan_ip_dst,
15736                 (void *)&cmd_set_vxlan_ip_dst_value,
15737                 (void *)&cmd_set_vxlan_eth_src,
15738                 (void *)&cmd_set_vxlan_eth_src_value,
15739                 (void *)&cmd_set_vxlan_eth_dst,
15740                 (void *)&cmd_set_vxlan_eth_dst_value,
15741                 NULL,
15742         },
15743 };
15744
15745 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15746         .f = cmd_set_vxlan_parsed,
15747         .data = NULL,
15748         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15749                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15750                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15751                 " eth-dst <eth-dst>",
15752         .tokens = {
15753                 (void *)&cmd_set_vxlan_set,
15754                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15755                 (void *)&cmd_set_vxlan_ip_version,
15756                 (void *)&cmd_set_vxlan_ip_version_value,
15757                 (void *)&cmd_set_vxlan_vni,
15758                 (void *)&cmd_set_vxlan_vni_value,
15759                 (void *)&cmd_set_vxlan_udp_src,
15760                 (void *)&cmd_set_vxlan_udp_src_value,
15761                 (void *)&cmd_set_vxlan_udp_dst,
15762                 (void *)&cmd_set_vxlan_udp_dst_value,
15763                 (void *)&cmd_set_vxlan_ip_tos,
15764                 (void *)&cmd_set_vxlan_ip_tos_value,
15765                 (void *)&cmd_set_vxlan_ip_ttl,
15766                 (void *)&cmd_set_vxlan_ip_ttl_value,
15767                 (void *)&cmd_set_vxlan_ip_src,
15768                 (void *)&cmd_set_vxlan_ip_src_value,
15769                 (void *)&cmd_set_vxlan_ip_dst,
15770                 (void *)&cmd_set_vxlan_ip_dst_value,
15771                 (void *)&cmd_set_vxlan_eth_src,
15772                 (void *)&cmd_set_vxlan_eth_src_value,
15773                 (void *)&cmd_set_vxlan_eth_dst,
15774                 (void *)&cmd_set_vxlan_eth_dst_value,
15775                 NULL,
15776         },
15777 };
15778
15779 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15780         .f = cmd_set_vxlan_parsed,
15781         .data = NULL,
15782         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15783                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15784                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15785                 " <eth-dst>",
15786         .tokens = {
15787                 (void *)&cmd_set_vxlan_set,
15788                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15789                 (void *)&cmd_set_vxlan_ip_version,
15790                 (void *)&cmd_set_vxlan_ip_version_value,
15791                 (void *)&cmd_set_vxlan_vni,
15792                 (void *)&cmd_set_vxlan_vni_value,
15793                 (void *)&cmd_set_vxlan_udp_src,
15794                 (void *)&cmd_set_vxlan_udp_src_value,
15795                 (void *)&cmd_set_vxlan_udp_dst,
15796                 (void *)&cmd_set_vxlan_udp_dst_value,
15797                 (void *)&cmd_set_vxlan_ip_src,
15798                 (void *)&cmd_set_vxlan_ip_src_value,
15799                 (void *)&cmd_set_vxlan_ip_dst,
15800                 (void *)&cmd_set_vxlan_ip_dst_value,
15801                 (void *)&cmd_set_vxlan_vlan,
15802                 (void *)&cmd_set_vxlan_vlan_value,
15803                 (void *)&cmd_set_vxlan_eth_src,
15804                 (void *)&cmd_set_vxlan_eth_src_value,
15805                 (void *)&cmd_set_vxlan_eth_dst,
15806                 (void *)&cmd_set_vxlan_eth_dst_value,
15807                 NULL,
15808         },
15809 };
15810
15811 /** Set NVGRE encapsulation details */
15812 struct cmd_set_nvgre_result {
15813         cmdline_fixed_string_t set;
15814         cmdline_fixed_string_t nvgre;
15815         cmdline_fixed_string_t pos_token;
15816         cmdline_fixed_string_t ip_version;
15817         uint32_t tni;
15818         cmdline_ipaddr_t ip_src;
15819         cmdline_ipaddr_t ip_dst;
15820         uint16_t tci;
15821         struct rte_ether_addr eth_src;
15822         struct rte_ether_addr eth_dst;
15823 };
15824
15825 cmdline_parse_token_string_t cmd_set_nvgre_set =
15826         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15827 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15828         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15829 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15830         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15831                                  "nvgre-with-vlan");
15832 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15833         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15834                                  "ip-version");
15835 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15836         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15837                                  "ipv4#ipv6");
15838 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15839         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15840                                  "tni");
15841 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15842         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15843 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15844         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15845                                  "ip-src");
15846 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15847         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15848 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15849         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15850                                  "ip-dst");
15851 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15852         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15853 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15854         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15855                                  "vlan-tci");
15856 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15857         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15858 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15859         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15860                                  "eth-src");
15861 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15862         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15863 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15864         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15865                                  "eth-dst");
15866 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15867         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15868
15869 static void cmd_set_nvgre_parsed(void *parsed_result,
15870         __rte_unused struct cmdline *cl,
15871         __rte_unused void *data)
15872 {
15873         struct cmd_set_nvgre_result *res = parsed_result;
15874         union {
15875                 uint32_t nvgre_tni;
15876                 uint8_t tni[4];
15877         } id = {
15878                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15879         };
15880
15881         if (strcmp(res->nvgre, "nvgre") == 0)
15882                 nvgre_encap_conf.select_vlan = 0;
15883         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15884                 nvgre_encap_conf.select_vlan = 1;
15885         if (strcmp(res->ip_version, "ipv4") == 0)
15886                 nvgre_encap_conf.select_ipv4 = 1;
15887         else if (strcmp(res->ip_version, "ipv6") == 0)
15888                 nvgre_encap_conf.select_ipv4 = 0;
15889         else
15890                 return;
15891         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15892         if (nvgre_encap_conf.select_ipv4) {
15893                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15894                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15895         } else {
15896                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15897                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15898         }
15899         if (nvgre_encap_conf.select_vlan)
15900                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15901         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15902                    RTE_ETHER_ADDR_LEN);
15903         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15904                    RTE_ETHER_ADDR_LEN);
15905 }
15906
15907 cmdline_parse_inst_t cmd_set_nvgre = {
15908         .f = cmd_set_nvgre_parsed,
15909         .data = NULL,
15910         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15911                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15912                 " eth-dst <eth-dst>",
15913         .tokens = {
15914                 (void *)&cmd_set_nvgre_set,
15915                 (void *)&cmd_set_nvgre_nvgre,
15916                 (void *)&cmd_set_nvgre_ip_version,
15917                 (void *)&cmd_set_nvgre_ip_version_value,
15918                 (void *)&cmd_set_nvgre_tni,
15919                 (void *)&cmd_set_nvgre_tni_value,
15920                 (void *)&cmd_set_nvgre_ip_src,
15921                 (void *)&cmd_set_nvgre_ip_src_value,
15922                 (void *)&cmd_set_nvgre_ip_dst,
15923                 (void *)&cmd_set_nvgre_ip_dst_value,
15924                 (void *)&cmd_set_nvgre_eth_src,
15925                 (void *)&cmd_set_nvgre_eth_src_value,
15926                 (void *)&cmd_set_nvgre_eth_dst,
15927                 (void *)&cmd_set_nvgre_eth_dst_value,
15928                 NULL,
15929         },
15930 };
15931
15932 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15933         .f = cmd_set_nvgre_parsed,
15934         .data = NULL,
15935         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15936                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15937                 " eth-src <eth-src> eth-dst <eth-dst>",
15938         .tokens = {
15939                 (void *)&cmd_set_nvgre_set,
15940                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15941                 (void *)&cmd_set_nvgre_ip_version,
15942                 (void *)&cmd_set_nvgre_ip_version_value,
15943                 (void *)&cmd_set_nvgre_tni,
15944                 (void *)&cmd_set_nvgre_tni_value,
15945                 (void *)&cmd_set_nvgre_ip_src,
15946                 (void *)&cmd_set_nvgre_ip_src_value,
15947                 (void *)&cmd_set_nvgre_ip_dst,
15948                 (void *)&cmd_set_nvgre_ip_dst_value,
15949                 (void *)&cmd_set_nvgre_vlan,
15950                 (void *)&cmd_set_nvgre_vlan_value,
15951                 (void *)&cmd_set_nvgre_eth_src,
15952                 (void *)&cmd_set_nvgre_eth_src_value,
15953                 (void *)&cmd_set_nvgre_eth_dst,
15954                 (void *)&cmd_set_nvgre_eth_dst_value,
15955                 NULL,
15956         },
15957 };
15958
15959 /** Set L2 encapsulation details */
15960 struct cmd_set_l2_encap_result {
15961         cmdline_fixed_string_t set;
15962         cmdline_fixed_string_t l2_encap;
15963         cmdline_fixed_string_t pos_token;
15964         cmdline_fixed_string_t ip_version;
15965         uint32_t vlan_present:1;
15966         uint16_t tci;
15967         struct rte_ether_addr eth_src;
15968         struct rte_ether_addr eth_dst;
15969 };
15970
15971 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15972         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15973 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15974         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15975 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15976         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15977                                  "l2_encap-with-vlan");
15978 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15979         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15980                                  "ip-version");
15981 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15982         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15983                                  "ipv4#ipv6");
15984 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15985         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15986                                  "vlan-tci");
15987 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15988         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15989 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15990         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15991                                  "eth-src");
15992 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15993         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15994 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15995         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15996                                  "eth-dst");
15997 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15998         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15999
16000 static void cmd_set_l2_encap_parsed(void *parsed_result,
16001         __rte_unused struct cmdline *cl,
16002         __rte_unused void *data)
16003 {
16004         struct cmd_set_l2_encap_result *res = parsed_result;
16005
16006         if (strcmp(res->l2_encap, "l2_encap") == 0)
16007                 l2_encap_conf.select_vlan = 0;
16008         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
16009                 l2_encap_conf.select_vlan = 1;
16010         if (strcmp(res->ip_version, "ipv4") == 0)
16011                 l2_encap_conf.select_ipv4 = 1;
16012         else if (strcmp(res->ip_version, "ipv6") == 0)
16013                 l2_encap_conf.select_ipv4 = 0;
16014         else
16015                 return;
16016         if (l2_encap_conf.select_vlan)
16017                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16018         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
16019                    RTE_ETHER_ADDR_LEN);
16020         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16021                    RTE_ETHER_ADDR_LEN);
16022 }
16023
16024 cmdline_parse_inst_t cmd_set_l2_encap = {
16025         .f = cmd_set_l2_encap_parsed,
16026         .data = NULL,
16027         .help_str = "set l2_encap ip-version ipv4|ipv6"
16028                 " eth-src <eth-src> eth-dst <eth-dst>",
16029         .tokens = {
16030                 (void *)&cmd_set_l2_encap_set,
16031                 (void *)&cmd_set_l2_encap_l2_encap,
16032                 (void *)&cmd_set_l2_encap_ip_version,
16033                 (void *)&cmd_set_l2_encap_ip_version_value,
16034                 (void *)&cmd_set_l2_encap_eth_src,
16035                 (void *)&cmd_set_l2_encap_eth_src_value,
16036                 (void *)&cmd_set_l2_encap_eth_dst,
16037                 (void *)&cmd_set_l2_encap_eth_dst_value,
16038                 NULL,
16039         },
16040 };
16041
16042 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
16043         .f = cmd_set_l2_encap_parsed,
16044         .data = NULL,
16045         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
16046                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16047         .tokens = {
16048                 (void *)&cmd_set_l2_encap_set,
16049                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
16050                 (void *)&cmd_set_l2_encap_ip_version,
16051                 (void *)&cmd_set_l2_encap_ip_version_value,
16052                 (void *)&cmd_set_l2_encap_vlan,
16053                 (void *)&cmd_set_l2_encap_vlan_value,
16054                 (void *)&cmd_set_l2_encap_eth_src,
16055                 (void *)&cmd_set_l2_encap_eth_src_value,
16056                 (void *)&cmd_set_l2_encap_eth_dst,
16057                 (void *)&cmd_set_l2_encap_eth_dst_value,
16058                 NULL,
16059         },
16060 };
16061
16062 /** Set L2 decapsulation details */
16063 struct cmd_set_l2_decap_result {
16064         cmdline_fixed_string_t set;
16065         cmdline_fixed_string_t l2_decap;
16066         cmdline_fixed_string_t pos_token;
16067         uint32_t vlan_present:1;
16068 };
16069
16070 cmdline_parse_token_string_t cmd_set_l2_decap_set =
16071         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
16072 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
16073         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16074                                  "l2_decap");
16075 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
16076         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16077                                  "l2_decap-with-vlan");
16078
16079 static void cmd_set_l2_decap_parsed(void *parsed_result,
16080         __rte_unused struct cmdline *cl,
16081         __rte_unused void *data)
16082 {
16083         struct cmd_set_l2_decap_result *res = parsed_result;
16084
16085         if (strcmp(res->l2_decap, "l2_decap") == 0)
16086                 l2_decap_conf.select_vlan = 0;
16087         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
16088                 l2_decap_conf.select_vlan = 1;
16089 }
16090
16091 cmdline_parse_inst_t cmd_set_l2_decap = {
16092         .f = cmd_set_l2_decap_parsed,
16093         .data = NULL,
16094         .help_str = "set l2_decap",
16095         .tokens = {
16096                 (void *)&cmd_set_l2_decap_set,
16097                 (void *)&cmd_set_l2_decap_l2_decap,
16098                 NULL,
16099         },
16100 };
16101
16102 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
16103         .f = cmd_set_l2_decap_parsed,
16104         .data = NULL,
16105         .help_str = "set l2_decap-with-vlan",
16106         .tokens = {
16107                 (void *)&cmd_set_l2_decap_set,
16108                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
16109                 NULL,
16110         },
16111 };
16112
16113 /** Set MPLSoGRE encapsulation details */
16114 struct cmd_set_mplsogre_encap_result {
16115         cmdline_fixed_string_t set;
16116         cmdline_fixed_string_t mplsogre;
16117         cmdline_fixed_string_t pos_token;
16118         cmdline_fixed_string_t ip_version;
16119         uint32_t vlan_present:1;
16120         uint32_t label;
16121         cmdline_ipaddr_t ip_src;
16122         cmdline_ipaddr_t ip_dst;
16123         uint16_t tci;
16124         struct rte_ether_addr eth_src;
16125         struct rte_ether_addr eth_dst;
16126 };
16127
16128 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
16129         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
16130                                  "set");
16131 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
16132         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
16133                                  "mplsogre_encap");
16134 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
16135         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16136                                  mplsogre, "mplsogre_encap-with-vlan");
16137 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
16138         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16139                                  pos_token, "ip-version");
16140 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
16141         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16142                                  ip_version, "ipv4#ipv6");
16143 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
16144         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16145                                  pos_token, "label");
16146 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
16147         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
16148                               UINT32);
16149 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
16150         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16151                                  pos_token, "ip-src");
16152 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
16153         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
16154 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
16155         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16156                                  pos_token, "ip-dst");
16157 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16158         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16159 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16160         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16161                                  pos_token, "vlan-tci");
16162 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16163         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16164                               UINT16);
16165 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16166         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16167                                  pos_token, "eth-src");
16168 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16169         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16170                                     eth_src);
16171 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16172         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16173                                  pos_token, "eth-dst");
16174 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16175         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16176                                     eth_dst);
16177
16178 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16179         __rte_unused struct cmdline *cl,
16180         __rte_unused void *data)
16181 {
16182         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16183         union {
16184                 uint32_t mplsogre_label;
16185                 uint8_t label[4];
16186         } id = {
16187                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16188         };
16189
16190         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16191                 mplsogre_encap_conf.select_vlan = 0;
16192         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16193                 mplsogre_encap_conf.select_vlan = 1;
16194         if (strcmp(res->ip_version, "ipv4") == 0)
16195                 mplsogre_encap_conf.select_ipv4 = 1;
16196         else if (strcmp(res->ip_version, "ipv6") == 0)
16197                 mplsogre_encap_conf.select_ipv4 = 0;
16198         else
16199                 return;
16200         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16201         if (mplsogre_encap_conf.select_ipv4) {
16202                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16203                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16204         } else {
16205                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16206                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16207         }
16208         if (mplsogre_encap_conf.select_vlan)
16209                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16210         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16211                    RTE_ETHER_ADDR_LEN);
16212         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16213                    RTE_ETHER_ADDR_LEN);
16214 }
16215
16216 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16217         .f = cmd_set_mplsogre_encap_parsed,
16218         .data = NULL,
16219         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16220                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16221                 " eth-dst <eth-dst>",
16222         .tokens = {
16223                 (void *)&cmd_set_mplsogre_encap_set,
16224                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16225                 (void *)&cmd_set_mplsogre_encap_ip_version,
16226                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16227                 (void *)&cmd_set_mplsogre_encap_label,
16228                 (void *)&cmd_set_mplsogre_encap_label_value,
16229                 (void *)&cmd_set_mplsogre_encap_ip_src,
16230                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16231                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16232                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16233                 (void *)&cmd_set_mplsogre_encap_eth_src,
16234                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16235                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16236                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16237                 NULL,
16238         },
16239 };
16240
16241 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16242         .f = cmd_set_mplsogre_encap_parsed,
16243         .data = NULL,
16244         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16245                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16246                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16247         .tokens = {
16248                 (void *)&cmd_set_mplsogre_encap_set,
16249                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16250                 (void *)&cmd_set_mplsogre_encap_ip_version,
16251                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16252                 (void *)&cmd_set_mplsogre_encap_label,
16253                 (void *)&cmd_set_mplsogre_encap_label_value,
16254                 (void *)&cmd_set_mplsogre_encap_ip_src,
16255                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16256                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16257                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16258                 (void *)&cmd_set_mplsogre_encap_vlan,
16259                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16260                 (void *)&cmd_set_mplsogre_encap_eth_src,
16261                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16262                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16263                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16264                 NULL,
16265         },
16266 };
16267
16268 /** Set MPLSoGRE decapsulation details */
16269 struct cmd_set_mplsogre_decap_result {
16270         cmdline_fixed_string_t set;
16271         cmdline_fixed_string_t mplsogre;
16272         cmdline_fixed_string_t pos_token;
16273         cmdline_fixed_string_t ip_version;
16274         uint32_t vlan_present:1;
16275 };
16276
16277 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16278         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16279                                  "set");
16280 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16281         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16282                                  "mplsogre_decap");
16283 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16284         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16285                                  mplsogre, "mplsogre_decap-with-vlan");
16286 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16287         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16288                                  pos_token, "ip-version");
16289 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16290         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16291                                  ip_version, "ipv4#ipv6");
16292
16293 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16294         __rte_unused struct cmdline *cl,
16295         __rte_unused void *data)
16296 {
16297         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16298
16299         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16300                 mplsogre_decap_conf.select_vlan = 0;
16301         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16302                 mplsogre_decap_conf.select_vlan = 1;
16303         if (strcmp(res->ip_version, "ipv4") == 0)
16304                 mplsogre_decap_conf.select_ipv4 = 1;
16305         else if (strcmp(res->ip_version, "ipv6") == 0)
16306                 mplsogre_decap_conf.select_ipv4 = 0;
16307 }
16308
16309 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16310         .f = cmd_set_mplsogre_decap_parsed,
16311         .data = NULL,
16312         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16313         .tokens = {
16314                 (void *)&cmd_set_mplsogre_decap_set,
16315                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16316                 (void *)&cmd_set_mplsogre_decap_ip_version,
16317                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16318                 NULL,
16319         },
16320 };
16321
16322 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16323         .f = cmd_set_mplsogre_decap_parsed,
16324         .data = NULL,
16325         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16326         .tokens = {
16327                 (void *)&cmd_set_mplsogre_decap_set,
16328                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16329                 (void *)&cmd_set_mplsogre_decap_ip_version,
16330                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16331                 NULL,
16332         },
16333 };
16334
16335 /** Set MPLSoUDP encapsulation details */
16336 struct cmd_set_mplsoudp_encap_result {
16337         cmdline_fixed_string_t set;
16338         cmdline_fixed_string_t mplsoudp;
16339         cmdline_fixed_string_t pos_token;
16340         cmdline_fixed_string_t ip_version;
16341         uint32_t vlan_present:1;
16342         uint32_t label;
16343         uint16_t udp_src;
16344         uint16_t udp_dst;
16345         cmdline_ipaddr_t ip_src;
16346         cmdline_ipaddr_t ip_dst;
16347         uint16_t tci;
16348         struct rte_ether_addr eth_src;
16349         struct rte_ether_addr eth_dst;
16350 };
16351
16352 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16353         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16354                                  "set");
16355 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16356         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16357                                  "mplsoudp_encap");
16358 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16359         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16360                                  mplsoudp, "mplsoudp_encap-with-vlan");
16361 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16362         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16363                                  pos_token, "ip-version");
16364 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16365         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16366                                  ip_version, "ipv4#ipv6");
16367 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16368         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16369                                  pos_token, "label");
16370 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16371         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16372                               UINT32);
16373 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16374         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16375                                  pos_token, "udp-src");
16376 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16377         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16378                               UINT16);
16379 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16380         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16381                                  pos_token, "udp-dst");
16382 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16383         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16384                               UINT16);
16385 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16386         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16387                                  pos_token, "ip-src");
16388 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16389         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16390 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16391         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16392                                  pos_token, "ip-dst");
16393 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16394         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16395 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16396         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16397                                  pos_token, "vlan-tci");
16398 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16399         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16400                               UINT16);
16401 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16402         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16403                                  pos_token, "eth-src");
16404 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16405         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16406                                     eth_src);
16407 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16408         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16409                                  pos_token, "eth-dst");
16410 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16411         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16412                                     eth_dst);
16413
16414 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16415         __rte_unused struct cmdline *cl,
16416         __rte_unused void *data)
16417 {
16418         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16419         union {
16420                 uint32_t mplsoudp_label;
16421                 uint8_t label[4];
16422         } id = {
16423                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16424         };
16425
16426         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16427                 mplsoudp_encap_conf.select_vlan = 0;
16428         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16429                 mplsoudp_encap_conf.select_vlan = 1;
16430         if (strcmp(res->ip_version, "ipv4") == 0)
16431                 mplsoudp_encap_conf.select_ipv4 = 1;
16432         else if (strcmp(res->ip_version, "ipv6") == 0)
16433                 mplsoudp_encap_conf.select_ipv4 = 0;
16434         else
16435                 return;
16436         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16437         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16438         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16439         if (mplsoudp_encap_conf.select_ipv4) {
16440                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16441                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16442         } else {
16443                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16444                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16445         }
16446         if (mplsoudp_encap_conf.select_vlan)
16447                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16448         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16449                    RTE_ETHER_ADDR_LEN);
16450         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16451                    RTE_ETHER_ADDR_LEN);
16452 }
16453
16454 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16455         .f = cmd_set_mplsoudp_encap_parsed,
16456         .data = NULL,
16457         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16458                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16459                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16460         .tokens = {
16461                 (void *)&cmd_set_mplsoudp_encap_set,
16462                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16463                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16464                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16465                 (void *)&cmd_set_mplsoudp_encap_label,
16466                 (void *)&cmd_set_mplsoudp_encap_label_value,
16467                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16468                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16469                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16470                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16471                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16472                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16473                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16474                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16475                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16476                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16477                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16478                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16479                 NULL,
16480         },
16481 };
16482
16483 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16484         .f = cmd_set_mplsoudp_encap_parsed,
16485         .data = NULL,
16486         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16487                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16488                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16489                 " eth-src <eth-src> eth-dst <eth-dst>",
16490         .tokens = {
16491                 (void *)&cmd_set_mplsoudp_encap_set,
16492                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16493                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16494                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16495                 (void *)&cmd_set_mplsoudp_encap_label,
16496                 (void *)&cmd_set_mplsoudp_encap_label_value,
16497                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16498                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16499                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16500                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16501                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16502                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16503                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16504                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16505                 (void *)&cmd_set_mplsoudp_encap_vlan,
16506                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16507                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16508                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16509                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16510                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16511                 NULL,
16512         },
16513 };
16514
16515 /** Set MPLSoUDP decapsulation details */
16516 struct cmd_set_mplsoudp_decap_result {
16517         cmdline_fixed_string_t set;
16518         cmdline_fixed_string_t mplsoudp;
16519         cmdline_fixed_string_t pos_token;
16520         cmdline_fixed_string_t ip_version;
16521         uint32_t vlan_present:1;
16522 };
16523
16524 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16525         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16526                                  "set");
16527 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16528         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16529                                  "mplsoudp_decap");
16530 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16531         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16532                                  mplsoudp, "mplsoudp_decap-with-vlan");
16533 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16534         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16535                                  pos_token, "ip-version");
16536 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16537         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16538                                  ip_version, "ipv4#ipv6");
16539
16540 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16541         __rte_unused struct cmdline *cl,
16542         __rte_unused void *data)
16543 {
16544         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16545
16546         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16547                 mplsoudp_decap_conf.select_vlan = 0;
16548         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16549                 mplsoudp_decap_conf.select_vlan = 1;
16550         if (strcmp(res->ip_version, "ipv4") == 0)
16551                 mplsoudp_decap_conf.select_ipv4 = 1;
16552         else if (strcmp(res->ip_version, "ipv6") == 0)
16553                 mplsoudp_decap_conf.select_ipv4 = 0;
16554 }
16555
16556 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16557         .f = cmd_set_mplsoudp_decap_parsed,
16558         .data = NULL,
16559         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16560         .tokens = {
16561                 (void *)&cmd_set_mplsoudp_decap_set,
16562                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16563                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16564                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16565                 NULL,
16566         },
16567 };
16568
16569 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16570         .f = cmd_set_mplsoudp_decap_parsed,
16571         .data = NULL,
16572         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16573         .tokens = {
16574                 (void *)&cmd_set_mplsoudp_decap_set,
16575                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16576                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16577                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16578                 NULL,
16579         },
16580 };
16581
16582 /* Strict link priority scheduling mode setting */
16583 static void
16584 cmd_strict_link_prio_parsed(
16585         void *parsed_result,
16586         __rte_unused struct cmdline *cl,
16587         __rte_unused void *data)
16588 {
16589         struct cmd_vf_tc_bw_result *res = parsed_result;
16590         int ret = -ENOTSUP;
16591
16592         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16593                 return;
16594
16595 #ifdef RTE_LIBRTE_I40E_PMD
16596         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16597 #endif
16598
16599         switch (ret) {
16600         case 0:
16601                 break;
16602         case -EINVAL:
16603                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16604                 break;
16605         case -ENODEV:
16606                 printf("invalid port_id %d\n", res->port_id);
16607                 break;
16608         case -ENOTSUP:
16609                 printf("function not implemented\n");
16610                 break;
16611         default:
16612                 printf("programming error: (%s)\n", strerror(-ret));
16613         }
16614 }
16615
16616 cmdline_parse_inst_t cmd_strict_link_prio = {
16617         .f = cmd_strict_link_prio_parsed,
16618         .data = NULL,
16619         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16620         .tokens = {
16621                 (void *)&cmd_vf_tc_bw_set,
16622                 (void *)&cmd_vf_tc_bw_tx,
16623                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16624                 (void *)&cmd_vf_tc_bw_port_id,
16625                 (void *)&cmd_vf_tc_bw_tc_map,
16626                 NULL,
16627         },
16628 };
16629
16630 /* Load dynamic device personalization*/
16631 struct cmd_ddp_add_result {
16632         cmdline_fixed_string_t ddp;
16633         cmdline_fixed_string_t add;
16634         portid_t port_id;
16635         char filepath[];
16636 };
16637
16638 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16639         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16640 cmdline_parse_token_string_t cmd_ddp_add_add =
16641         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16642 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16643         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16644 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16645         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16646
16647 static void
16648 cmd_ddp_add_parsed(
16649         void *parsed_result,
16650         __rte_unused struct cmdline *cl,
16651         __rte_unused void *data)
16652 {
16653         struct cmd_ddp_add_result *res = parsed_result;
16654         uint8_t *buff;
16655         uint32_t size;
16656         char *filepath;
16657         char *file_fld[2];
16658         int file_num;
16659         int ret = -ENOTSUP;
16660
16661         if (!all_ports_stopped()) {
16662                 printf("Please stop all ports first\n");
16663                 return;
16664         }
16665
16666         filepath = strdup(res->filepath);
16667         if (filepath == NULL) {
16668                 printf("Failed to allocate memory\n");
16669                 return;
16670         }
16671         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16672
16673         buff = open_file(file_fld[0], &size);
16674         if (!buff) {
16675                 free((void *)filepath);
16676                 return;
16677         }
16678
16679 #ifdef RTE_LIBRTE_I40E_PMD
16680         if (ret == -ENOTSUP)
16681                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16682                                                buff, size,
16683                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16684 #endif
16685
16686         if (ret == -EEXIST)
16687                 printf("Profile has already existed.\n");
16688         else if (ret < 0)
16689                 printf("Failed to load profile.\n");
16690         else if (file_num == 2)
16691                 save_file(file_fld[1], buff, size);
16692
16693         close_file(buff);
16694         free((void *)filepath);
16695 }
16696
16697 cmdline_parse_inst_t cmd_ddp_add = {
16698         .f = cmd_ddp_add_parsed,
16699         .data = NULL,
16700         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16701         .tokens = {
16702                 (void *)&cmd_ddp_add_ddp,
16703                 (void *)&cmd_ddp_add_add,
16704                 (void *)&cmd_ddp_add_port_id,
16705                 (void *)&cmd_ddp_add_filepath,
16706                 NULL,
16707         },
16708 };
16709
16710 /* Delete dynamic device personalization*/
16711 struct cmd_ddp_del_result {
16712         cmdline_fixed_string_t ddp;
16713         cmdline_fixed_string_t del;
16714         portid_t port_id;
16715         char filepath[];
16716 };
16717
16718 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16719         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16720 cmdline_parse_token_string_t cmd_ddp_del_del =
16721         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16722 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16723         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16724 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16725         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16726
16727 static void
16728 cmd_ddp_del_parsed(
16729         void *parsed_result,
16730         __rte_unused struct cmdline *cl,
16731         __rte_unused void *data)
16732 {
16733         struct cmd_ddp_del_result *res = parsed_result;
16734         uint8_t *buff;
16735         uint32_t size;
16736         int ret = -ENOTSUP;
16737
16738         if (!all_ports_stopped()) {
16739                 printf("Please stop all ports first\n");
16740                 return;
16741         }
16742
16743         buff = open_file(res->filepath, &size);
16744         if (!buff)
16745                 return;
16746
16747 #ifdef RTE_LIBRTE_I40E_PMD
16748         if (ret == -ENOTSUP)
16749                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16750                                                buff, size,
16751                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16752 #endif
16753
16754         if (ret == -EACCES)
16755                 printf("Profile does not exist.\n");
16756         else if (ret < 0)
16757                 printf("Failed to delete profile.\n");
16758
16759         close_file(buff);
16760 }
16761
16762 cmdline_parse_inst_t cmd_ddp_del = {
16763         .f = cmd_ddp_del_parsed,
16764         .data = NULL,
16765         .help_str = "ddp del <port_id> <backup_profile_path>",
16766         .tokens = {
16767                 (void *)&cmd_ddp_del_ddp,
16768                 (void *)&cmd_ddp_del_del,
16769                 (void *)&cmd_ddp_del_port_id,
16770                 (void *)&cmd_ddp_del_filepath,
16771                 NULL,
16772         },
16773 };
16774
16775 /* Get dynamic device personalization profile info */
16776 struct cmd_ddp_info_result {
16777         cmdline_fixed_string_t ddp;
16778         cmdline_fixed_string_t get;
16779         cmdline_fixed_string_t info;
16780         char filepath[];
16781 };
16782
16783 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16784         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16785 cmdline_parse_token_string_t cmd_ddp_info_get =
16786         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16787 cmdline_parse_token_string_t cmd_ddp_info_info =
16788         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16789 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16790         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16791
16792 static void
16793 cmd_ddp_info_parsed(
16794         void *parsed_result,
16795         __rte_unused struct cmdline *cl,
16796         __rte_unused void *data)
16797 {
16798         struct cmd_ddp_info_result *res = parsed_result;
16799         uint8_t *pkg;
16800         uint32_t pkg_size;
16801         int ret = -ENOTSUP;
16802 #ifdef RTE_LIBRTE_I40E_PMD
16803         uint32_t i, j, n;
16804         uint8_t *buff;
16805         uint32_t buff_size = 0;
16806         struct rte_pmd_i40e_profile_info info;
16807         uint32_t dev_num = 0;
16808         struct rte_pmd_i40e_ddp_device_id *devs;
16809         uint32_t proto_num = 0;
16810         struct rte_pmd_i40e_proto_info *proto = NULL;
16811         uint32_t pctype_num = 0;
16812         struct rte_pmd_i40e_ptype_info *pctype;
16813         uint32_t ptype_num = 0;
16814         struct rte_pmd_i40e_ptype_info *ptype;
16815         uint8_t proto_id;
16816
16817 #endif
16818
16819         pkg = open_file(res->filepath, &pkg_size);
16820         if (!pkg)
16821                 return;
16822
16823 #ifdef RTE_LIBRTE_I40E_PMD
16824         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16825                                 (uint8_t *)&info, sizeof(info),
16826                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16827         if (!ret) {
16828                 printf("Global Track id:       0x%x\n", info.track_id);
16829                 printf("Global Version:        %d.%d.%d.%d\n",
16830                         info.version.major,
16831                         info.version.minor,
16832                         info.version.update,
16833                         info.version.draft);
16834                 printf("Global Package name:   %s\n\n", info.name);
16835         }
16836
16837         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16838                                 (uint8_t *)&info, sizeof(info),
16839                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16840         if (!ret) {
16841                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16842                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16843                         info.version.major,
16844                         info.version.minor,
16845                         info.version.update,
16846                         info.version.draft);
16847                 printf("i40e Profile name:     %s\n\n", info.name);
16848         }
16849
16850         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16851                                 (uint8_t *)&buff_size, sizeof(buff_size),
16852                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16853         if (!ret && buff_size) {
16854                 buff = (uint8_t *)malloc(buff_size);
16855                 if (buff) {
16856                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16857                                                 buff, buff_size,
16858                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16859                         if (!ret)
16860                                 printf("Package Notes:\n%s\n\n", buff);
16861                         free(buff);
16862                 }
16863         }
16864
16865         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16866                                 (uint8_t *)&dev_num, sizeof(dev_num),
16867                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16868         if (!ret && dev_num) {
16869                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16870                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16871                 if (devs) {
16872                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16873                                                 (uint8_t *)devs, buff_size,
16874                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16875                         if (!ret) {
16876                                 printf("List of supported devices:\n");
16877                                 for (i = 0; i < dev_num; i++) {
16878                                         printf("  %04X:%04X %04X:%04X\n",
16879                                                 devs[i].vendor_dev_id >> 16,
16880                                                 devs[i].vendor_dev_id & 0xFFFF,
16881                                                 devs[i].sub_vendor_dev_id >> 16,
16882                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16883                                 }
16884                                 printf("\n");
16885                         }
16886                         free(devs);
16887                 }
16888         }
16889
16890         /* get information about protocols and packet types */
16891         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16892                 (uint8_t *)&proto_num, sizeof(proto_num),
16893                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16894         if (ret || !proto_num)
16895                 goto no_print_return;
16896
16897         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16898         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16899         if (!proto)
16900                 goto no_print_return;
16901
16902         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16903                                         buff_size,
16904                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16905         if (!ret) {
16906                 printf("List of used protocols:\n");
16907                 for (i = 0; i < proto_num; i++)
16908                         printf("  %2u: %s\n", proto[i].proto_id,
16909                                proto[i].name);
16910                 printf("\n");
16911         }
16912         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16913                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16914                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16915         if (ret || !pctype_num)
16916                 goto no_print_pctypes;
16917
16918         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16919         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16920         if (!pctype)
16921                 goto no_print_pctypes;
16922
16923         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16924                                         buff_size,
16925                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16926         if (ret) {
16927                 free(pctype);
16928                 goto no_print_pctypes;
16929         }
16930
16931         printf("List of defined packet classification types:\n");
16932         for (i = 0; i < pctype_num; i++) {
16933                 printf("  %2u:", pctype[i].ptype_id);
16934                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16935                         proto_id = pctype[i].protocols[j];
16936                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16937                                 for (n = 0; n < proto_num; n++) {
16938                                         if (proto[n].proto_id == proto_id) {
16939                                                 printf(" %s", proto[n].name);
16940                                                 break;
16941                                         }
16942                                 }
16943                         }
16944                 }
16945                 printf("\n");
16946         }
16947         printf("\n");
16948         free(pctype);
16949
16950 no_print_pctypes:
16951
16952         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16953                                         sizeof(ptype_num),
16954                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16955         if (ret || !ptype_num)
16956                 goto no_print_return;
16957
16958         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16959         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16960         if (!ptype)
16961                 goto no_print_return;
16962
16963         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16964                                         buff_size,
16965                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16966         if (ret) {
16967                 free(ptype);
16968                 goto no_print_return;
16969         }
16970         printf("List of defined packet types:\n");
16971         for (i = 0; i < ptype_num; i++) {
16972                 printf("  %2u:", ptype[i].ptype_id);
16973                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16974                         proto_id = ptype[i].protocols[j];
16975                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16976                                 for (n = 0; n < proto_num; n++) {
16977                                         if (proto[n].proto_id == proto_id) {
16978                                                 printf(" %s", proto[n].name);
16979                                                 break;
16980                                         }
16981                                 }
16982                         }
16983                 }
16984                 printf("\n");
16985         }
16986         free(ptype);
16987         printf("\n");
16988
16989         ret = 0;
16990 no_print_return:
16991         if (proto)
16992                 free(proto);
16993 #endif
16994         if (ret == -ENOTSUP)
16995                 printf("Function not supported in PMD driver\n");
16996         close_file(pkg);
16997 }
16998
16999 cmdline_parse_inst_t cmd_ddp_get_info = {
17000         .f = cmd_ddp_info_parsed,
17001         .data = NULL,
17002         .help_str = "ddp get info <profile_path>",
17003         .tokens = {
17004                 (void *)&cmd_ddp_info_ddp,
17005                 (void *)&cmd_ddp_info_get,
17006                 (void *)&cmd_ddp_info_info,
17007                 (void *)&cmd_ddp_info_filepath,
17008                 NULL,
17009         },
17010 };
17011
17012 /* Get dynamic device personalization profile info list*/
17013 #define PROFILE_INFO_SIZE 48
17014 #define MAX_PROFILE_NUM 16
17015
17016 struct cmd_ddp_get_list_result {
17017         cmdline_fixed_string_t ddp;
17018         cmdline_fixed_string_t get;
17019         cmdline_fixed_string_t list;
17020         portid_t port_id;
17021 };
17022
17023 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
17024         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
17025 cmdline_parse_token_string_t cmd_ddp_get_list_get =
17026         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
17027 cmdline_parse_token_string_t cmd_ddp_get_list_list =
17028         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
17029 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
17030         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
17031
17032 static void
17033 cmd_ddp_get_list_parsed(
17034         __rte_unused void *parsed_result,
17035         __rte_unused struct cmdline *cl,
17036         __rte_unused void *data)
17037 {
17038 #ifdef RTE_LIBRTE_I40E_PMD
17039         struct cmd_ddp_get_list_result *res = parsed_result;
17040         struct rte_pmd_i40e_profile_list *p_list;
17041         struct rte_pmd_i40e_profile_info *p_info;
17042         uint32_t p_num;
17043         uint32_t size;
17044         uint32_t i;
17045 #endif
17046         int ret = -ENOTSUP;
17047
17048 #ifdef RTE_LIBRTE_I40E_PMD
17049         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
17050         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
17051         if (!p_list) {
17052                 printf("%s: Failed to malloc buffer\n", __func__);
17053                 return;
17054         }
17055
17056         if (ret == -ENOTSUP)
17057                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
17058                                                 (uint8_t *)p_list, size);
17059
17060         if (!ret) {
17061                 p_num = p_list->p_count;
17062                 printf("Profile number is: %d\n\n", p_num);
17063
17064                 for (i = 0; i < p_num; i++) {
17065                         p_info = &p_list->p_info[i];
17066                         printf("Profile %d:\n", i);
17067                         printf("Track id:     0x%x\n", p_info->track_id);
17068                         printf("Version:      %d.%d.%d.%d\n",
17069                                p_info->version.major,
17070                                p_info->version.minor,
17071                                p_info->version.update,
17072                                p_info->version.draft);
17073                         printf("Profile name: %s\n\n", p_info->name);
17074                 }
17075         }
17076
17077         free(p_list);
17078 #endif
17079
17080         if (ret < 0)
17081                 printf("Failed to get ddp list\n");
17082 }
17083
17084 cmdline_parse_inst_t cmd_ddp_get_list = {
17085         .f = cmd_ddp_get_list_parsed,
17086         .data = NULL,
17087         .help_str = "ddp get list <port_id>",
17088         .tokens = {
17089                 (void *)&cmd_ddp_get_list_ddp,
17090                 (void *)&cmd_ddp_get_list_get,
17091                 (void *)&cmd_ddp_get_list_list,
17092                 (void *)&cmd_ddp_get_list_port_id,
17093                 NULL,
17094         },
17095 };
17096
17097 /* Configure input set */
17098 struct cmd_cfg_input_set_result {
17099         cmdline_fixed_string_t port;
17100         cmdline_fixed_string_t cfg;
17101         portid_t port_id;
17102         cmdline_fixed_string_t pctype;
17103         uint8_t pctype_id;
17104         cmdline_fixed_string_t inset_type;
17105         cmdline_fixed_string_t opt;
17106         cmdline_fixed_string_t field;
17107         uint8_t field_idx;
17108 };
17109
17110 static void
17111 cmd_cfg_input_set_parsed(
17112         __rte_unused void *parsed_result,
17113         __rte_unused struct cmdline *cl,
17114         __rte_unused void *data)
17115 {
17116 #ifdef RTE_LIBRTE_I40E_PMD
17117         struct cmd_cfg_input_set_result *res = parsed_result;
17118         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17119         struct rte_pmd_i40e_inset inset;
17120 #endif
17121         int ret = -ENOTSUP;
17122
17123         if (!all_ports_stopped()) {
17124                 printf("Please stop all ports first\n");
17125                 return;
17126         }
17127
17128 #ifdef RTE_LIBRTE_I40E_PMD
17129         if (!strcmp(res->inset_type, "hash_inset"))
17130                 inset_type = INSET_HASH;
17131         else if (!strcmp(res->inset_type, "fdir_inset"))
17132                 inset_type = INSET_FDIR;
17133         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17134                 inset_type = INSET_FDIR_FLX;
17135         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
17136                                      &inset, inset_type);
17137         if (ret) {
17138                 printf("Failed to get input set.\n");
17139                 return;
17140         }
17141
17142         if (!strcmp(res->opt, "get")) {
17143                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
17144                                                    res->field_idx);
17145                 if (ret)
17146                         printf("Field index %d is enabled.\n", res->field_idx);
17147                 else
17148                         printf("Field index %d is disabled.\n", res->field_idx);
17149                 return;
17150         } else if (!strcmp(res->opt, "set"))
17151                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
17152                                                    res->field_idx);
17153         else if (!strcmp(res->opt, "clear"))
17154                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
17155                                                      res->field_idx);
17156         if (ret) {
17157                 printf("Failed to configure input set field.\n");
17158                 return;
17159         }
17160
17161         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17162                                      &inset, inset_type);
17163         if (ret) {
17164                 printf("Failed to set input set.\n");
17165                 return;
17166         }
17167 #endif
17168
17169         if (ret == -ENOTSUP)
17170                 printf("Function not supported\n");
17171 }
17172
17173 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17174         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17175                                  port, "port");
17176 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17177         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17178                                  cfg, "config");
17179 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17180         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17181                               port_id, UINT16);
17182 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17183         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17184                                  pctype, "pctype");
17185 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17186         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17187                               pctype_id, UINT8);
17188 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17189         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17190                                  inset_type,
17191                                  "hash_inset#fdir_inset#fdir_flx_inset");
17192 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17193         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17194                                  opt, "get#set#clear");
17195 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17196         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17197                                  field, "field");
17198 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17199         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17200                               field_idx, UINT8);
17201
17202 cmdline_parse_inst_t cmd_cfg_input_set = {
17203         .f = cmd_cfg_input_set_parsed,
17204         .data = NULL,
17205         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17206                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17207         .tokens = {
17208                 (void *)&cmd_cfg_input_set_port,
17209                 (void *)&cmd_cfg_input_set_cfg,
17210                 (void *)&cmd_cfg_input_set_port_id,
17211                 (void *)&cmd_cfg_input_set_pctype,
17212                 (void *)&cmd_cfg_input_set_pctype_id,
17213                 (void *)&cmd_cfg_input_set_inset_type,
17214                 (void *)&cmd_cfg_input_set_opt,
17215                 (void *)&cmd_cfg_input_set_field,
17216                 (void *)&cmd_cfg_input_set_field_idx,
17217                 NULL,
17218         },
17219 };
17220
17221 /* Clear input set */
17222 struct cmd_clear_input_set_result {
17223         cmdline_fixed_string_t port;
17224         cmdline_fixed_string_t cfg;
17225         portid_t port_id;
17226         cmdline_fixed_string_t pctype;
17227         uint8_t pctype_id;
17228         cmdline_fixed_string_t inset_type;
17229         cmdline_fixed_string_t clear;
17230         cmdline_fixed_string_t all;
17231 };
17232
17233 static void
17234 cmd_clear_input_set_parsed(
17235         __rte_unused void *parsed_result,
17236         __rte_unused struct cmdline *cl,
17237         __rte_unused void *data)
17238 {
17239 #ifdef RTE_LIBRTE_I40E_PMD
17240         struct cmd_clear_input_set_result *res = parsed_result;
17241         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17242         struct rte_pmd_i40e_inset inset;
17243 #endif
17244         int ret = -ENOTSUP;
17245
17246         if (!all_ports_stopped()) {
17247                 printf("Please stop all ports first\n");
17248                 return;
17249         }
17250
17251 #ifdef RTE_LIBRTE_I40E_PMD
17252         if (!strcmp(res->inset_type, "hash_inset"))
17253                 inset_type = INSET_HASH;
17254         else if (!strcmp(res->inset_type, "fdir_inset"))
17255                 inset_type = INSET_FDIR;
17256         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17257                 inset_type = INSET_FDIR_FLX;
17258
17259         memset(&inset, 0, sizeof(inset));
17260
17261         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17262                                      &inset, inset_type);
17263         if (ret) {
17264                 printf("Failed to clear input set.\n");
17265                 return;
17266         }
17267
17268 #endif
17269
17270         if (ret == -ENOTSUP)
17271                 printf("Function not supported\n");
17272 }
17273
17274 cmdline_parse_token_string_t cmd_clear_input_set_port =
17275         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17276                                  port, "port");
17277 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17278         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17279                                  cfg, "config");
17280 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17281         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17282                               port_id, UINT16);
17283 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17284         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17285                                  pctype, "pctype");
17286 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17287         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17288                               pctype_id, UINT8);
17289 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17290         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17291                                  inset_type,
17292                                  "hash_inset#fdir_inset#fdir_flx_inset");
17293 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17294         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17295                                  clear, "clear");
17296 cmdline_parse_token_string_t cmd_clear_input_set_all =
17297         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17298                                  all, "all");
17299
17300 cmdline_parse_inst_t cmd_clear_input_set = {
17301         .f = cmd_clear_input_set_parsed,
17302         .data = NULL,
17303         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17304                     "fdir_inset|fdir_flx_inset clear all",
17305         .tokens = {
17306                 (void *)&cmd_clear_input_set_port,
17307                 (void *)&cmd_clear_input_set_cfg,
17308                 (void *)&cmd_clear_input_set_port_id,
17309                 (void *)&cmd_clear_input_set_pctype,
17310                 (void *)&cmd_clear_input_set_pctype_id,
17311                 (void *)&cmd_clear_input_set_inset_type,
17312                 (void *)&cmd_clear_input_set_clear,
17313                 (void *)&cmd_clear_input_set_all,
17314                 NULL,
17315         },
17316 };
17317
17318 /* show vf stats */
17319
17320 /* Common result structure for show vf stats */
17321 struct cmd_show_vf_stats_result {
17322         cmdline_fixed_string_t show;
17323         cmdline_fixed_string_t vf;
17324         cmdline_fixed_string_t stats;
17325         portid_t port_id;
17326         uint16_t vf_id;
17327 };
17328
17329 /* Common CLI fields show vf stats*/
17330 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17331         TOKEN_STRING_INITIALIZER
17332                 (struct cmd_show_vf_stats_result,
17333                  show, "show");
17334 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17335         TOKEN_STRING_INITIALIZER
17336                 (struct cmd_show_vf_stats_result,
17337                  vf, "vf");
17338 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17339         TOKEN_STRING_INITIALIZER
17340                 (struct cmd_show_vf_stats_result,
17341                  stats, "stats");
17342 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17343         TOKEN_NUM_INITIALIZER
17344                 (struct cmd_show_vf_stats_result,
17345                  port_id, UINT16);
17346 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17347         TOKEN_NUM_INITIALIZER
17348                 (struct cmd_show_vf_stats_result,
17349                  vf_id, UINT16);
17350
17351 static void
17352 cmd_show_vf_stats_parsed(
17353         void *parsed_result,
17354         __rte_unused struct cmdline *cl,
17355         __rte_unused void *data)
17356 {
17357         struct cmd_show_vf_stats_result *res = parsed_result;
17358         struct rte_eth_stats stats;
17359         int ret = -ENOTSUP;
17360         static const char *nic_stats_border = "########################";
17361
17362         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17363                 return;
17364
17365         memset(&stats, 0, sizeof(stats));
17366
17367 #ifdef RTE_LIBRTE_I40E_PMD
17368         if (ret == -ENOTSUP)
17369                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17370                                                 res->vf_id,
17371                                                 &stats);
17372 #endif
17373 #ifdef RTE_LIBRTE_BNXT_PMD
17374         if (ret == -ENOTSUP)
17375                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17376                                                 res->vf_id,
17377                                                 &stats);
17378 #endif
17379
17380         switch (ret) {
17381         case 0:
17382                 break;
17383         case -EINVAL:
17384                 printf("invalid vf_id %d\n", res->vf_id);
17385                 break;
17386         case -ENODEV:
17387                 printf("invalid port_id %d\n", res->port_id);
17388                 break;
17389         case -ENOTSUP:
17390                 printf("function not implemented\n");
17391                 break;
17392         default:
17393                 printf("programming error: (%s)\n", strerror(-ret));
17394         }
17395
17396         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17397                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17398
17399         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17400                "%-"PRIu64"\n",
17401                stats.ipackets, stats.imissed, stats.ibytes);
17402         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17403         printf("  RX-nombuf:  %-10"PRIu64"\n",
17404                stats.rx_nombuf);
17405         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17406                "%-"PRIu64"\n",
17407                stats.opackets, stats.oerrors, stats.obytes);
17408
17409         printf("  %s############################%s\n",
17410                                nic_stats_border, nic_stats_border);
17411 }
17412
17413 cmdline_parse_inst_t cmd_show_vf_stats = {
17414         .f = cmd_show_vf_stats_parsed,
17415         .data = NULL,
17416         .help_str = "show vf stats <port_id> <vf_id>",
17417         .tokens = {
17418                 (void *)&cmd_show_vf_stats_show,
17419                 (void *)&cmd_show_vf_stats_vf,
17420                 (void *)&cmd_show_vf_stats_stats,
17421                 (void *)&cmd_show_vf_stats_port_id,
17422                 (void *)&cmd_show_vf_stats_vf_id,
17423                 NULL,
17424         },
17425 };
17426
17427 /* clear vf stats */
17428
17429 /* Common result structure for clear vf stats */
17430 struct cmd_clear_vf_stats_result {
17431         cmdline_fixed_string_t clear;
17432         cmdline_fixed_string_t vf;
17433         cmdline_fixed_string_t stats;
17434         portid_t port_id;
17435         uint16_t vf_id;
17436 };
17437
17438 /* Common CLI fields clear vf stats*/
17439 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17440         TOKEN_STRING_INITIALIZER
17441                 (struct cmd_clear_vf_stats_result,
17442                  clear, "clear");
17443 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17444         TOKEN_STRING_INITIALIZER
17445                 (struct cmd_clear_vf_stats_result,
17446                  vf, "vf");
17447 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17448         TOKEN_STRING_INITIALIZER
17449                 (struct cmd_clear_vf_stats_result,
17450                  stats, "stats");
17451 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17452         TOKEN_NUM_INITIALIZER
17453                 (struct cmd_clear_vf_stats_result,
17454                  port_id, UINT16);
17455 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17456         TOKEN_NUM_INITIALIZER
17457                 (struct cmd_clear_vf_stats_result,
17458                  vf_id, UINT16);
17459
17460 static void
17461 cmd_clear_vf_stats_parsed(
17462         void *parsed_result,
17463         __rte_unused struct cmdline *cl,
17464         __rte_unused void *data)
17465 {
17466         struct cmd_clear_vf_stats_result *res = parsed_result;
17467         int ret = -ENOTSUP;
17468
17469         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17470                 return;
17471
17472 #ifdef RTE_LIBRTE_I40E_PMD
17473         if (ret == -ENOTSUP)
17474                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17475                                                   res->vf_id);
17476 #endif
17477 #ifdef RTE_LIBRTE_BNXT_PMD
17478         if (ret == -ENOTSUP)
17479                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17480                                                   res->vf_id);
17481 #endif
17482
17483         switch (ret) {
17484         case 0:
17485                 break;
17486         case -EINVAL:
17487                 printf("invalid vf_id %d\n", res->vf_id);
17488                 break;
17489         case -ENODEV:
17490                 printf("invalid port_id %d\n", res->port_id);
17491                 break;
17492         case -ENOTSUP:
17493                 printf("function not implemented\n");
17494                 break;
17495         default:
17496                 printf("programming error: (%s)\n", strerror(-ret));
17497         }
17498 }
17499
17500 cmdline_parse_inst_t cmd_clear_vf_stats = {
17501         .f = cmd_clear_vf_stats_parsed,
17502         .data = NULL,
17503         .help_str = "clear vf stats <port_id> <vf_id>",
17504         .tokens = {
17505                 (void *)&cmd_clear_vf_stats_clear,
17506                 (void *)&cmd_clear_vf_stats_vf,
17507                 (void *)&cmd_clear_vf_stats_stats,
17508                 (void *)&cmd_clear_vf_stats_port_id,
17509                 (void *)&cmd_clear_vf_stats_vf_id,
17510                 NULL,
17511         },
17512 };
17513
17514 /* port config pctype mapping reset */
17515
17516 /* Common result structure for port config pctype mapping reset */
17517 struct cmd_pctype_mapping_reset_result {
17518         cmdline_fixed_string_t port;
17519         cmdline_fixed_string_t config;
17520         portid_t port_id;
17521         cmdline_fixed_string_t pctype;
17522         cmdline_fixed_string_t mapping;
17523         cmdline_fixed_string_t reset;
17524 };
17525
17526 /* Common CLI fields for port config pctype mapping reset*/
17527 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17528         TOKEN_STRING_INITIALIZER
17529                 (struct cmd_pctype_mapping_reset_result,
17530                  port, "port");
17531 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17532         TOKEN_STRING_INITIALIZER
17533                 (struct cmd_pctype_mapping_reset_result,
17534                  config, "config");
17535 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17536         TOKEN_NUM_INITIALIZER
17537                 (struct cmd_pctype_mapping_reset_result,
17538                  port_id, UINT16);
17539 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17540         TOKEN_STRING_INITIALIZER
17541                 (struct cmd_pctype_mapping_reset_result,
17542                  pctype, "pctype");
17543 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17544         TOKEN_STRING_INITIALIZER
17545                 (struct cmd_pctype_mapping_reset_result,
17546                  mapping, "mapping");
17547 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17548         TOKEN_STRING_INITIALIZER
17549                 (struct cmd_pctype_mapping_reset_result,
17550                  reset, "reset");
17551
17552 static void
17553 cmd_pctype_mapping_reset_parsed(
17554         void *parsed_result,
17555         __rte_unused struct cmdline *cl,
17556         __rte_unused void *data)
17557 {
17558         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17559         int ret = -ENOTSUP;
17560
17561         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17562                 return;
17563
17564 #ifdef RTE_LIBRTE_I40E_PMD
17565         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17566 #endif
17567
17568         switch (ret) {
17569         case 0:
17570                 break;
17571         case -ENODEV:
17572                 printf("invalid port_id %d\n", res->port_id);
17573                 break;
17574         case -ENOTSUP:
17575                 printf("function not implemented\n");
17576                 break;
17577         default:
17578                 printf("programming error: (%s)\n", strerror(-ret));
17579         }
17580 }
17581
17582 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17583         .f = cmd_pctype_mapping_reset_parsed,
17584         .data = NULL,
17585         .help_str = "port config <port_id> pctype mapping reset",
17586         .tokens = {
17587                 (void *)&cmd_pctype_mapping_reset_port,
17588                 (void *)&cmd_pctype_mapping_reset_config,
17589                 (void *)&cmd_pctype_mapping_reset_port_id,
17590                 (void *)&cmd_pctype_mapping_reset_pctype,
17591                 (void *)&cmd_pctype_mapping_reset_mapping,
17592                 (void *)&cmd_pctype_mapping_reset_reset,
17593                 NULL,
17594         },
17595 };
17596
17597 /* show port pctype mapping */
17598
17599 /* Common result structure for show port pctype mapping */
17600 struct cmd_pctype_mapping_get_result {
17601         cmdline_fixed_string_t show;
17602         cmdline_fixed_string_t port;
17603         portid_t port_id;
17604         cmdline_fixed_string_t pctype;
17605         cmdline_fixed_string_t mapping;
17606 };
17607
17608 /* Common CLI fields for pctype mapping get */
17609 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17610         TOKEN_STRING_INITIALIZER
17611                 (struct cmd_pctype_mapping_get_result,
17612                  show, "show");
17613 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17614         TOKEN_STRING_INITIALIZER
17615                 (struct cmd_pctype_mapping_get_result,
17616                  port, "port");
17617 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17618         TOKEN_NUM_INITIALIZER
17619                 (struct cmd_pctype_mapping_get_result,
17620                  port_id, UINT16);
17621 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17622         TOKEN_STRING_INITIALIZER
17623                 (struct cmd_pctype_mapping_get_result,
17624                  pctype, "pctype");
17625 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17626         TOKEN_STRING_INITIALIZER
17627                 (struct cmd_pctype_mapping_get_result,
17628                  mapping, "mapping");
17629
17630 static void
17631 cmd_pctype_mapping_get_parsed(
17632         void *parsed_result,
17633         __rte_unused struct cmdline *cl,
17634         __rte_unused void *data)
17635 {
17636         struct cmd_pctype_mapping_get_result *res = parsed_result;
17637         int ret = -ENOTSUP;
17638 #ifdef RTE_LIBRTE_I40E_PMD
17639         struct rte_pmd_i40e_flow_type_mapping
17640                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17641         int i, j, first_pctype;
17642 #endif
17643
17644         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17645                 return;
17646
17647 #ifdef RTE_LIBRTE_I40E_PMD
17648         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17649 #endif
17650
17651         switch (ret) {
17652         case 0:
17653                 break;
17654         case -ENODEV:
17655                 printf("invalid port_id %d\n", res->port_id);
17656                 return;
17657         case -ENOTSUP:
17658                 printf("function not implemented\n");
17659                 return;
17660         default:
17661                 printf("programming error: (%s)\n", strerror(-ret));
17662                 return;
17663         }
17664
17665 #ifdef RTE_LIBRTE_I40E_PMD
17666         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17667                 if (mapping[i].pctype != 0ULL) {
17668                         first_pctype = 1;
17669
17670                         printf("pctype: ");
17671                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17672                                 if (mapping[i].pctype & (1ULL << j)) {
17673                                         printf(first_pctype ?
17674                                                "%02d" : ",%02d", j);
17675                                         first_pctype = 0;
17676                                 }
17677                         }
17678                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17679                 }
17680         }
17681 #endif
17682 }
17683
17684 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17685         .f = cmd_pctype_mapping_get_parsed,
17686         .data = NULL,
17687         .help_str = "show port <port_id> pctype mapping",
17688         .tokens = {
17689                 (void *)&cmd_pctype_mapping_get_show,
17690                 (void *)&cmd_pctype_mapping_get_port,
17691                 (void *)&cmd_pctype_mapping_get_port_id,
17692                 (void *)&cmd_pctype_mapping_get_pctype,
17693                 (void *)&cmd_pctype_mapping_get_mapping,
17694                 NULL,
17695         },
17696 };
17697
17698 /* port config pctype mapping update */
17699
17700 /* Common result structure for port config pctype mapping update */
17701 struct cmd_pctype_mapping_update_result {
17702         cmdline_fixed_string_t port;
17703         cmdline_fixed_string_t config;
17704         portid_t port_id;
17705         cmdline_fixed_string_t pctype;
17706         cmdline_fixed_string_t mapping;
17707         cmdline_fixed_string_t update;
17708         cmdline_fixed_string_t pctype_list;
17709         uint16_t flow_type;
17710 };
17711
17712 /* Common CLI fields for pctype mapping update*/
17713 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17714         TOKEN_STRING_INITIALIZER
17715                 (struct cmd_pctype_mapping_update_result,
17716                  port, "port");
17717 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17718         TOKEN_STRING_INITIALIZER
17719                 (struct cmd_pctype_mapping_update_result,
17720                  config, "config");
17721 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17722         TOKEN_NUM_INITIALIZER
17723                 (struct cmd_pctype_mapping_update_result,
17724                  port_id, UINT16);
17725 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17726         TOKEN_STRING_INITIALIZER
17727                 (struct cmd_pctype_mapping_update_result,
17728                  pctype, "pctype");
17729 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17730         TOKEN_STRING_INITIALIZER
17731                 (struct cmd_pctype_mapping_update_result,
17732                  mapping, "mapping");
17733 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17734         TOKEN_STRING_INITIALIZER
17735                 (struct cmd_pctype_mapping_update_result,
17736                  update, "update");
17737 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17738         TOKEN_STRING_INITIALIZER
17739                 (struct cmd_pctype_mapping_update_result,
17740                  pctype_list, NULL);
17741 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17742         TOKEN_NUM_INITIALIZER
17743                 (struct cmd_pctype_mapping_update_result,
17744                  flow_type, UINT16);
17745
17746 static void
17747 cmd_pctype_mapping_update_parsed(
17748         void *parsed_result,
17749         __rte_unused struct cmdline *cl,
17750         __rte_unused void *data)
17751 {
17752         struct cmd_pctype_mapping_update_result *res = parsed_result;
17753         int ret = -ENOTSUP;
17754 #ifdef RTE_LIBRTE_I40E_PMD
17755         struct rte_pmd_i40e_flow_type_mapping mapping;
17756         unsigned int i;
17757         unsigned int nb_item;
17758         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17759 #endif
17760
17761         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17762                 return;
17763
17764 #ifdef RTE_LIBRTE_I40E_PMD
17765         nb_item = parse_item_list(res->pctype_list, "pctypes",
17766                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17767         mapping.flow_type = res->flow_type;
17768         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17769                 mapping.pctype |= (1ULL << pctype_list[i]);
17770         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17771                                                 &mapping,
17772                                                 1,
17773                                                 0);
17774 #endif
17775
17776         switch (ret) {
17777         case 0:
17778                 break;
17779         case -EINVAL:
17780                 printf("invalid pctype or flow type\n");
17781                 break;
17782         case -ENODEV:
17783                 printf("invalid port_id %d\n", res->port_id);
17784                 break;
17785         case -ENOTSUP:
17786                 printf("function not implemented\n");
17787                 break;
17788         default:
17789                 printf("programming error: (%s)\n", strerror(-ret));
17790         }
17791 }
17792
17793 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17794         .f = cmd_pctype_mapping_update_parsed,
17795         .data = NULL,
17796         .help_str = "port config <port_id> pctype mapping update"
17797         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17798         .tokens = {
17799                 (void *)&cmd_pctype_mapping_update_port,
17800                 (void *)&cmd_pctype_mapping_update_config,
17801                 (void *)&cmd_pctype_mapping_update_port_id,
17802                 (void *)&cmd_pctype_mapping_update_pctype,
17803                 (void *)&cmd_pctype_mapping_update_mapping,
17804                 (void *)&cmd_pctype_mapping_update_update,
17805                 (void *)&cmd_pctype_mapping_update_pc_type,
17806                 (void *)&cmd_pctype_mapping_update_flow_type,
17807                 NULL,
17808         },
17809 };
17810
17811 /* ptype mapping get */
17812
17813 /* Common result structure for ptype mapping get */
17814 struct cmd_ptype_mapping_get_result {
17815         cmdline_fixed_string_t ptype;
17816         cmdline_fixed_string_t mapping;
17817         cmdline_fixed_string_t get;
17818         portid_t port_id;
17819         uint8_t valid_only;
17820 };
17821
17822 /* Common CLI fields for ptype mapping get */
17823 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17824         TOKEN_STRING_INITIALIZER
17825                 (struct cmd_ptype_mapping_get_result,
17826                  ptype, "ptype");
17827 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17828         TOKEN_STRING_INITIALIZER
17829                 (struct cmd_ptype_mapping_get_result,
17830                  mapping, "mapping");
17831 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17832         TOKEN_STRING_INITIALIZER
17833                 (struct cmd_ptype_mapping_get_result,
17834                  get, "get");
17835 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17836         TOKEN_NUM_INITIALIZER
17837                 (struct cmd_ptype_mapping_get_result,
17838                  port_id, UINT16);
17839 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17840         TOKEN_NUM_INITIALIZER
17841                 (struct cmd_ptype_mapping_get_result,
17842                  valid_only, UINT8);
17843
17844 static void
17845 cmd_ptype_mapping_get_parsed(
17846         void *parsed_result,
17847         __rte_unused struct cmdline *cl,
17848         __rte_unused void *data)
17849 {
17850         struct cmd_ptype_mapping_get_result *res = parsed_result;
17851         int ret = -ENOTSUP;
17852 #ifdef RTE_LIBRTE_I40E_PMD
17853         int max_ptype_num = 256;
17854         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17855         uint16_t count;
17856         int i;
17857 #endif
17858
17859         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17860                 return;
17861
17862 #ifdef RTE_LIBRTE_I40E_PMD
17863         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17864                                         mapping,
17865                                         max_ptype_num,
17866                                         &count,
17867                                         res->valid_only);
17868 #endif
17869
17870         switch (ret) {
17871         case 0:
17872                 break;
17873         case -ENODEV:
17874                 printf("invalid port_id %d\n", res->port_id);
17875                 break;
17876         case -ENOTSUP:
17877                 printf("function not implemented\n");
17878                 break;
17879         default:
17880                 printf("programming error: (%s)\n", strerror(-ret));
17881         }
17882
17883 #ifdef RTE_LIBRTE_I40E_PMD
17884         if (!ret) {
17885                 for (i = 0; i < count; i++)
17886                         printf("%3d\t0x%08x\n",
17887                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17888         }
17889 #endif
17890 }
17891
17892 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17893         .f = cmd_ptype_mapping_get_parsed,
17894         .data = NULL,
17895         .help_str = "ptype mapping get <port_id> <valid_only>",
17896         .tokens = {
17897                 (void *)&cmd_ptype_mapping_get_ptype,
17898                 (void *)&cmd_ptype_mapping_get_mapping,
17899                 (void *)&cmd_ptype_mapping_get_get,
17900                 (void *)&cmd_ptype_mapping_get_port_id,
17901                 (void *)&cmd_ptype_mapping_get_valid_only,
17902                 NULL,
17903         },
17904 };
17905
17906 /* ptype mapping replace */
17907
17908 /* Common result structure for ptype mapping replace */
17909 struct cmd_ptype_mapping_replace_result {
17910         cmdline_fixed_string_t ptype;
17911         cmdline_fixed_string_t mapping;
17912         cmdline_fixed_string_t replace;
17913         portid_t port_id;
17914         uint32_t target;
17915         uint8_t mask;
17916         uint32_t pkt_type;
17917 };
17918
17919 /* Common CLI fields for ptype mapping replace */
17920 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17921         TOKEN_STRING_INITIALIZER
17922                 (struct cmd_ptype_mapping_replace_result,
17923                  ptype, "ptype");
17924 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17925         TOKEN_STRING_INITIALIZER
17926                 (struct cmd_ptype_mapping_replace_result,
17927                  mapping, "mapping");
17928 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17929         TOKEN_STRING_INITIALIZER
17930                 (struct cmd_ptype_mapping_replace_result,
17931                  replace, "replace");
17932 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17933         TOKEN_NUM_INITIALIZER
17934                 (struct cmd_ptype_mapping_replace_result,
17935                  port_id, UINT16);
17936 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17937         TOKEN_NUM_INITIALIZER
17938                 (struct cmd_ptype_mapping_replace_result,
17939                  target, UINT32);
17940 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17941         TOKEN_NUM_INITIALIZER
17942                 (struct cmd_ptype_mapping_replace_result,
17943                  mask, UINT8);
17944 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17945         TOKEN_NUM_INITIALIZER
17946                 (struct cmd_ptype_mapping_replace_result,
17947                  pkt_type, UINT32);
17948
17949 static void
17950 cmd_ptype_mapping_replace_parsed(
17951         void *parsed_result,
17952         __rte_unused struct cmdline *cl,
17953         __rte_unused void *data)
17954 {
17955         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17956         int ret = -ENOTSUP;
17957
17958         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17959                 return;
17960
17961 #ifdef RTE_LIBRTE_I40E_PMD
17962         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17963                                         res->target,
17964                                         res->mask,
17965                                         res->pkt_type);
17966 #endif
17967
17968         switch (ret) {
17969         case 0:
17970                 break;
17971         case -EINVAL:
17972                 printf("invalid ptype 0x%8x or 0x%8x\n",
17973                                 res->target, res->pkt_type);
17974                 break;
17975         case -ENODEV:
17976                 printf("invalid port_id %d\n", res->port_id);
17977                 break;
17978         case -ENOTSUP:
17979                 printf("function not implemented\n");
17980                 break;
17981         default:
17982                 printf("programming error: (%s)\n", strerror(-ret));
17983         }
17984 }
17985
17986 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17987         .f = cmd_ptype_mapping_replace_parsed,
17988         .data = NULL,
17989         .help_str =
17990                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17991         .tokens = {
17992                 (void *)&cmd_ptype_mapping_replace_ptype,
17993                 (void *)&cmd_ptype_mapping_replace_mapping,
17994                 (void *)&cmd_ptype_mapping_replace_replace,
17995                 (void *)&cmd_ptype_mapping_replace_port_id,
17996                 (void *)&cmd_ptype_mapping_replace_target,
17997                 (void *)&cmd_ptype_mapping_replace_mask,
17998                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17999                 NULL,
18000         },
18001 };
18002
18003 /* ptype mapping reset */
18004
18005 /* Common result structure for ptype mapping reset */
18006 struct cmd_ptype_mapping_reset_result {
18007         cmdline_fixed_string_t ptype;
18008         cmdline_fixed_string_t mapping;
18009         cmdline_fixed_string_t reset;
18010         portid_t port_id;
18011 };
18012
18013 /* Common CLI fields for ptype mapping reset*/
18014 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
18015         TOKEN_STRING_INITIALIZER
18016                 (struct cmd_ptype_mapping_reset_result,
18017                  ptype, "ptype");
18018 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
18019         TOKEN_STRING_INITIALIZER
18020                 (struct cmd_ptype_mapping_reset_result,
18021                  mapping, "mapping");
18022 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
18023         TOKEN_STRING_INITIALIZER
18024                 (struct cmd_ptype_mapping_reset_result,
18025                  reset, "reset");
18026 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
18027         TOKEN_NUM_INITIALIZER
18028                 (struct cmd_ptype_mapping_reset_result,
18029                  port_id, UINT16);
18030
18031 static void
18032 cmd_ptype_mapping_reset_parsed(
18033         void *parsed_result,
18034         __rte_unused struct cmdline *cl,
18035         __rte_unused void *data)
18036 {
18037         struct cmd_ptype_mapping_reset_result *res = parsed_result;
18038         int ret = -ENOTSUP;
18039
18040         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18041                 return;
18042
18043 #ifdef RTE_LIBRTE_I40E_PMD
18044         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
18045 #endif
18046
18047         switch (ret) {
18048         case 0:
18049                 break;
18050         case -ENODEV:
18051                 printf("invalid port_id %d\n", res->port_id);
18052                 break;
18053         case -ENOTSUP:
18054                 printf("function not implemented\n");
18055                 break;
18056         default:
18057                 printf("programming error: (%s)\n", strerror(-ret));
18058         }
18059 }
18060
18061 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
18062         .f = cmd_ptype_mapping_reset_parsed,
18063         .data = NULL,
18064         .help_str = "ptype mapping reset <port_id>",
18065         .tokens = {
18066                 (void *)&cmd_ptype_mapping_reset_ptype,
18067                 (void *)&cmd_ptype_mapping_reset_mapping,
18068                 (void *)&cmd_ptype_mapping_reset_reset,
18069                 (void *)&cmd_ptype_mapping_reset_port_id,
18070                 NULL,
18071         },
18072 };
18073
18074 /* ptype mapping update */
18075
18076 /* Common result structure for ptype mapping update */
18077 struct cmd_ptype_mapping_update_result {
18078         cmdline_fixed_string_t ptype;
18079         cmdline_fixed_string_t mapping;
18080         cmdline_fixed_string_t reset;
18081         portid_t port_id;
18082         uint8_t hw_ptype;
18083         uint32_t sw_ptype;
18084 };
18085
18086 /* Common CLI fields for ptype mapping update*/
18087 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
18088         TOKEN_STRING_INITIALIZER
18089                 (struct cmd_ptype_mapping_update_result,
18090                  ptype, "ptype");
18091 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
18092         TOKEN_STRING_INITIALIZER
18093                 (struct cmd_ptype_mapping_update_result,
18094                  mapping, "mapping");
18095 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
18096         TOKEN_STRING_INITIALIZER
18097                 (struct cmd_ptype_mapping_update_result,
18098                  reset, "update");
18099 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
18100         TOKEN_NUM_INITIALIZER
18101                 (struct cmd_ptype_mapping_update_result,
18102                  port_id, UINT16);
18103 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
18104         TOKEN_NUM_INITIALIZER
18105                 (struct cmd_ptype_mapping_update_result,
18106                  hw_ptype, UINT8);
18107 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
18108         TOKEN_NUM_INITIALIZER
18109                 (struct cmd_ptype_mapping_update_result,
18110                  sw_ptype, UINT32);
18111
18112 static void
18113 cmd_ptype_mapping_update_parsed(
18114         void *parsed_result,
18115         __rte_unused struct cmdline *cl,
18116         __rte_unused void *data)
18117 {
18118         struct cmd_ptype_mapping_update_result *res = parsed_result;
18119         int ret = -ENOTSUP;
18120 #ifdef RTE_LIBRTE_I40E_PMD
18121         struct rte_pmd_i40e_ptype_mapping mapping;
18122 #endif
18123         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18124                 return;
18125
18126 #ifdef RTE_LIBRTE_I40E_PMD
18127         mapping.hw_ptype = res->hw_ptype;
18128         mapping.sw_ptype = res->sw_ptype;
18129         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
18130                                                 &mapping,
18131                                                 1,
18132                                                 0);
18133 #endif
18134
18135         switch (ret) {
18136         case 0:
18137                 break;
18138         case -EINVAL:
18139                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
18140                 break;
18141         case -ENODEV:
18142                 printf("invalid port_id %d\n", res->port_id);
18143                 break;
18144         case -ENOTSUP:
18145                 printf("function not implemented\n");
18146                 break;
18147         default:
18148                 printf("programming error: (%s)\n", strerror(-ret));
18149         }
18150 }
18151
18152 cmdline_parse_inst_t cmd_ptype_mapping_update = {
18153         .f = cmd_ptype_mapping_update_parsed,
18154         .data = NULL,
18155         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
18156         .tokens = {
18157                 (void *)&cmd_ptype_mapping_update_ptype,
18158                 (void *)&cmd_ptype_mapping_update_mapping,
18159                 (void *)&cmd_ptype_mapping_update_update,
18160                 (void *)&cmd_ptype_mapping_update_port_id,
18161                 (void *)&cmd_ptype_mapping_update_hw_ptype,
18162                 (void *)&cmd_ptype_mapping_update_sw_ptype,
18163                 NULL,
18164         },
18165 };
18166
18167 /* Common result structure for file commands */
18168 struct cmd_cmdfile_result {
18169         cmdline_fixed_string_t load;
18170         cmdline_fixed_string_t filename;
18171 };
18172
18173 /* Common CLI fields for file commands */
18174 cmdline_parse_token_string_t cmd_load_cmdfile =
18175         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18176 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18177         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18178
18179 static void
18180 cmd_load_from_file_parsed(
18181         void *parsed_result,
18182         __rte_unused struct cmdline *cl,
18183         __rte_unused void *data)
18184 {
18185         struct cmd_cmdfile_result *res = parsed_result;
18186
18187         cmdline_read_from_file(res->filename);
18188 }
18189
18190 cmdline_parse_inst_t cmd_load_from_file = {
18191         .f = cmd_load_from_file_parsed,
18192         .data = NULL,
18193         .help_str = "load <filename>",
18194         .tokens = {
18195                 (void *)&cmd_load_cmdfile,
18196                 (void *)&cmd_load_cmdfile_filename,
18197                 NULL,
18198         },
18199 };
18200
18201 /* Get Rx offloads capabilities */
18202 struct cmd_rx_offload_get_capa_result {
18203         cmdline_fixed_string_t show;
18204         cmdline_fixed_string_t port;
18205         portid_t port_id;
18206         cmdline_fixed_string_t rx_offload;
18207         cmdline_fixed_string_t capabilities;
18208 };
18209
18210 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18211         TOKEN_STRING_INITIALIZER
18212                 (struct cmd_rx_offload_get_capa_result,
18213                  show, "show");
18214 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18215         TOKEN_STRING_INITIALIZER
18216                 (struct cmd_rx_offload_get_capa_result,
18217                  port, "port");
18218 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18219         TOKEN_NUM_INITIALIZER
18220                 (struct cmd_rx_offload_get_capa_result,
18221                  port_id, UINT16);
18222 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18223         TOKEN_STRING_INITIALIZER
18224                 (struct cmd_rx_offload_get_capa_result,
18225                  rx_offload, "rx_offload");
18226 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18227         TOKEN_STRING_INITIALIZER
18228                 (struct cmd_rx_offload_get_capa_result,
18229                  capabilities, "capabilities");
18230
18231 static void
18232 print_rx_offloads(uint64_t offloads)
18233 {
18234         uint64_t single_offload;
18235         int begin;
18236         int end;
18237         int bit;
18238
18239         if (offloads == 0)
18240                 return;
18241
18242         begin = __builtin_ctzll(offloads);
18243         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18244
18245         single_offload = 1ULL << begin;
18246         for (bit = begin; bit < end; bit++) {
18247                 if (offloads & single_offload)
18248                         printf(" %s",
18249                                rte_eth_dev_rx_offload_name(single_offload));
18250                 single_offload <<= 1;
18251         }
18252 }
18253
18254 static void
18255 cmd_rx_offload_get_capa_parsed(
18256         void *parsed_result,
18257         __rte_unused struct cmdline *cl,
18258         __rte_unused void *data)
18259 {
18260         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18261         struct rte_eth_dev_info dev_info;
18262         portid_t port_id = res->port_id;
18263         uint64_t queue_offloads;
18264         uint64_t port_offloads;
18265         int ret;
18266
18267         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18268         if (ret != 0)
18269                 return;
18270
18271         queue_offloads = dev_info.rx_queue_offload_capa;
18272         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18273
18274         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18275         printf("  Per Queue :");
18276         print_rx_offloads(queue_offloads);
18277
18278         printf("\n");
18279         printf("  Per Port  :");
18280         print_rx_offloads(port_offloads);
18281         printf("\n\n");
18282 }
18283
18284 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18285         .f = cmd_rx_offload_get_capa_parsed,
18286         .data = NULL,
18287         .help_str = "show port <port_id> rx_offload capabilities",
18288         .tokens = {
18289                 (void *)&cmd_rx_offload_get_capa_show,
18290                 (void *)&cmd_rx_offload_get_capa_port,
18291                 (void *)&cmd_rx_offload_get_capa_port_id,
18292                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18293                 (void *)&cmd_rx_offload_get_capa_capabilities,
18294                 NULL,
18295         }
18296 };
18297
18298 /* Get Rx offloads configuration */
18299 struct cmd_rx_offload_get_configuration_result {
18300         cmdline_fixed_string_t show;
18301         cmdline_fixed_string_t port;
18302         portid_t port_id;
18303         cmdline_fixed_string_t rx_offload;
18304         cmdline_fixed_string_t configuration;
18305 };
18306
18307 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18308         TOKEN_STRING_INITIALIZER
18309                 (struct cmd_rx_offload_get_configuration_result,
18310                  show, "show");
18311 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18312         TOKEN_STRING_INITIALIZER
18313                 (struct cmd_rx_offload_get_configuration_result,
18314                  port, "port");
18315 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18316         TOKEN_NUM_INITIALIZER
18317                 (struct cmd_rx_offload_get_configuration_result,
18318                  port_id, UINT16);
18319 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18320         TOKEN_STRING_INITIALIZER
18321                 (struct cmd_rx_offload_get_configuration_result,
18322                  rx_offload, "rx_offload");
18323 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18324         TOKEN_STRING_INITIALIZER
18325                 (struct cmd_rx_offload_get_configuration_result,
18326                  configuration, "configuration");
18327
18328 static void
18329 cmd_rx_offload_get_configuration_parsed(
18330         void *parsed_result,
18331         __rte_unused struct cmdline *cl,
18332         __rte_unused void *data)
18333 {
18334         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18335         struct rte_eth_dev_info dev_info;
18336         portid_t port_id = res->port_id;
18337         struct rte_port *port = &ports[port_id];
18338         uint64_t port_offloads;
18339         uint64_t queue_offloads;
18340         uint16_t nb_rx_queues;
18341         int q;
18342         int ret;
18343
18344         printf("Rx Offloading Configuration of port %d :\n", port_id);
18345
18346         port_offloads = port->dev_conf.rxmode.offloads;
18347         printf("  Port :");
18348         print_rx_offloads(port_offloads);
18349         printf("\n");
18350
18351         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18352         if (ret != 0)
18353                 return;
18354
18355         nb_rx_queues = dev_info.nb_rx_queues;
18356         for (q = 0; q < nb_rx_queues; q++) {
18357                 queue_offloads = port->rx_conf[q].offloads;
18358                 printf("  Queue[%2d] :", q);
18359                 print_rx_offloads(queue_offloads);
18360                 printf("\n");
18361         }
18362         printf("\n");
18363 }
18364
18365 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18366         .f = cmd_rx_offload_get_configuration_parsed,
18367         .data = NULL,
18368         .help_str = "show port <port_id> rx_offload configuration",
18369         .tokens = {
18370                 (void *)&cmd_rx_offload_get_configuration_show,
18371                 (void *)&cmd_rx_offload_get_configuration_port,
18372                 (void *)&cmd_rx_offload_get_configuration_port_id,
18373                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18374                 (void *)&cmd_rx_offload_get_configuration_configuration,
18375                 NULL,
18376         }
18377 };
18378
18379 /* Enable/Disable a per port offloading */
18380 struct cmd_config_per_port_rx_offload_result {
18381         cmdline_fixed_string_t port;
18382         cmdline_fixed_string_t config;
18383         portid_t port_id;
18384         cmdline_fixed_string_t rx_offload;
18385         cmdline_fixed_string_t offload;
18386         cmdline_fixed_string_t on_off;
18387 };
18388
18389 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18390         TOKEN_STRING_INITIALIZER
18391                 (struct cmd_config_per_port_rx_offload_result,
18392                  port, "port");
18393 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18394         TOKEN_STRING_INITIALIZER
18395                 (struct cmd_config_per_port_rx_offload_result,
18396                  config, "config");
18397 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18398         TOKEN_NUM_INITIALIZER
18399                 (struct cmd_config_per_port_rx_offload_result,
18400                  port_id, UINT16);
18401 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18402         TOKEN_STRING_INITIALIZER
18403                 (struct cmd_config_per_port_rx_offload_result,
18404                  rx_offload, "rx_offload");
18405 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18406         TOKEN_STRING_INITIALIZER
18407                 (struct cmd_config_per_port_rx_offload_result,
18408                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18409                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18410                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18411                            "scatter#timestamp#security#keep_crc#rss_hash");
18412 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18413         TOKEN_STRING_INITIALIZER
18414                 (struct cmd_config_per_port_rx_offload_result,
18415                  on_off, "on#off");
18416
18417 static uint64_t
18418 search_rx_offload(const char *name)
18419 {
18420         uint64_t single_offload;
18421         const char *single_name;
18422         int found = 0;
18423         unsigned int bit;
18424
18425         single_offload = 1;
18426         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18427                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18428                 if (!strcasecmp(single_name, name)) {
18429                         found = 1;
18430                         break;
18431                 }
18432                 single_offload <<= 1;
18433         }
18434
18435         if (found)
18436                 return single_offload;
18437
18438         return 0;
18439 }
18440
18441 static void
18442 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18443                                 __rte_unused struct cmdline *cl,
18444                                 __rte_unused void *data)
18445 {
18446         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18447         portid_t port_id = res->port_id;
18448         struct rte_eth_dev_info dev_info;
18449         struct rte_port *port = &ports[port_id];
18450         uint64_t single_offload;
18451         uint16_t nb_rx_queues;
18452         int q;
18453         int ret;
18454
18455         if (port->port_status != RTE_PORT_STOPPED) {
18456                 printf("Error: Can't config offload when Port %d "
18457                        "is not stopped\n", port_id);
18458                 return;
18459         }
18460
18461         single_offload = search_rx_offload(res->offload);
18462         if (single_offload == 0) {
18463                 printf("Unknown offload name: %s\n", res->offload);
18464                 return;
18465         }
18466
18467         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18468         if (ret != 0)
18469                 return;
18470
18471         nb_rx_queues = dev_info.nb_rx_queues;
18472         if (!strcmp(res->on_off, "on")) {
18473                 port->dev_conf.rxmode.offloads |= single_offload;
18474                 for (q = 0; q < nb_rx_queues; q++)
18475                         port->rx_conf[q].offloads |= single_offload;
18476         } else {
18477                 port->dev_conf.rxmode.offloads &= ~single_offload;
18478                 for (q = 0; q < nb_rx_queues; q++)
18479                         port->rx_conf[q].offloads &= ~single_offload;
18480         }
18481
18482         cmd_reconfig_device_queue(port_id, 1, 1);
18483 }
18484
18485 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18486         .f = cmd_config_per_port_rx_offload_parsed,
18487         .data = NULL,
18488         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18489                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18490                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18491                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18492                     "on|off",
18493         .tokens = {
18494                 (void *)&cmd_config_per_port_rx_offload_result_port,
18495                 (void *)&cmd_config_per_port_rx_offload_result_config,
18496                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18497                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18498                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18499                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18500                 NULL,
18501         }
18502 };
18503
18504 /* Enable/Disable a per queue offloading */
18505 struct cmd_config_per_queue_rx_offload_result {
18506         cmdline_fixed_string_t port;
18507         portid_t port_id;
18508         cmdline_fixed_string_t rxq;
18509         uint16_t queue_id;
18510         cmdline_fixed_string_t rx_offload;
18511         cmdline_fixed_string_t offload;
18512         cmdline_fixed_string_t on_off;
18513 };
18514
18515 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18516         TOKEN_STRING_INITIALIZER
18517                 (struct cmd_config_per_queue_rx_offload_result,
18518                  port, "port");
18519 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18520         TOKEN_NUM_INITIALIZER
18521                 (struct cmd_config_per_queue_rx_offload_result,
18522                  port_id, UINT16);
18523 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18524         TOKEN_STRING_INITIALIZER
18525                 (struct cmd_config_per_queue_rx_offload_result,
18526                  rxq, "rxq");
18527 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18528         TOKEN_NUM_INITIALIZER
18529                 (struct cmd_config_per_queue_rx_offload_result,
18530                  queue_id, UINT16);
18531 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18532         TOKEN_STRING_INITIALIZER
18533                 (struct cmd_config_per_queue_rx_offload_result,
18534                  rx_offload, "rx_offload");
18535 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18536         TOKEN_STRING_INITIALIZER
18537                 (struct cmd_config_per_queue_rx_offload_result,
18538                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18539                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18540                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18541                            "scatter#timestamp#security#keep_crc");
18542 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18543         TOKEN_STRING_INITIALIZER
18544                 (struct cmd_config_per_queue_rx_offload_result,
18545                  on_off, "on#off");
18546
18547 static void
18548 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18549                                 __rte_unused struct cmdline *cl,
18550                                 __rte_unused void *data)
18551 {
18552         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18553         struct rte_eth_dev_info dev_info;
18554         portid_t port_id = res->port_id;
18555         uint16_t queue_id = res->queue_id;
18556         struct rte_port *port = &ports[port_id];
18557         uint64_t single_offload;
18558         int ret;
18559
18560         if (port->port_status != RTE_PORT_STOPPED) {
18561                 printf("Error: Can't config offload when Port %d "
18562                        "is not stopped\n", port_id);
18563                 return;
18564         }
18565
18566         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18567         if (ret != 0)
18568                 return;
18569
18570         if (queue_id >= dev_info.nb_rx_queues) {
18571                 printf("Error: input queue_id should be 0 ... "
18572                        "%d\n", dev_info.nb_rx_queues - 1);
18573                 return;
18574         }
18575
18576         single_offload = search_rx_offload(res->offload);
18577         if (single_offload == 0) {
18578                 printf("Unknown offload name: %s\n", res->offload);
18579                 return;
18580         }
18581
18582         if (!strcmp(res->on_off, "on"))
18583                 port->rx_conf[queue_id].offloads |= single_offload;
18584         else
18585                 port->rx_conf[queue_id].offloads &= ~single_offload;
18586
18587         cmd_reconfig_device_queue(port_id, 1, 1);
18588 }
18589
18590 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18591         .f = cmd_config_per_queue_rx_offload_parsed,
18592         .data = NULL,
18593         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18594                     "vlan_strip|ipv4_cksum|"
18595                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18596                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18597                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18598                     "on|off",
18599         .tokens = {
18600                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18601                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18602                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18603                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18604                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18605                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18606                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18607                 NULL,
18608         }
18609 };
18610
18611 /* Get Tx offloads capabilities */
18612 struct cmd_tx_offload_get_capa_result {
18613         cmdline_fixed_string_t show;
18614         cmdline_fixed_string_t port;
18615         portid_t port_id;
18616         cmdline_fixed_string_t tx_offload;
18617         cmdline_fixed_string_t capabilities;
18618 };
18619
18620 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18621         TOKEN_STRING_INITIALIZER
18622                 (struct cmd_tx_offload_get_capa_result,
18623                  show, "show");
18624 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18625         TOKEN_STRING_INITIALIZER
18626                 (struct cmd_tx_offload_get_capa_result,
18627                  port, "port");
18628 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18629         TOKEN_NUM_INITIALIZER
18630                 (struct cmd_tx_offload_get_capa_result,
18631                  port_id, UINT16);
18632 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18633         TOKEN_STRING_INITIALIZER
18634                 (struct cmd_tx_offload_get_capa_result,
18635                  tx_offload, "tx_offload");
18636 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18637         TOKEN_STRING_INITIALIZER
18638                 (struct cmd_tx_offload_get_capa_result,
18639                  capabilities, "capabilities");
18640
18641 static void
18642 print_tx_offloads(uint64_t offloads)
18643 {
18644         uint64_t single_offload;
18645         int begin;
18646         int end;
18647         int bit;
18648
18649         if (offloads == 0)
18650                 return;
18651
18652         begin = __builtin_ctzll(offloads);
18653         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18654
18655         single_offload = 1ULL << begin;
18656         for (bit = begin; bit < end; bit++) {
18657                 if (offloads & single_offload)
18658                         printf(" %s",
18659                                rte_eth_dev_tx_offload_name(single_offload));
18660                 single_offload <<= 1;
18661         }
18662 }
18663
18664 static void
18665 cmd_tx_offload_get_capa_parsed(
18666         void *parsed_result,
18667         __rte_unused struct cmdline *cl,
18668         __rte_unused void *data)
18669 {
18670         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18671         struct rte_eth_dev_info dev_info;
18672         portid_t port_id = res->port_id;
18673         uint64_t queue_offloads;
18674         uint64_t port_offloads;
18675         int ret;
18676
18677         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18678         if (ret != 0)
18679                 return;
18680
18681         queue_offloads = dev_info.tx_queue_offload_capa;
18682         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18683
18684         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18685         printf("  Per Queue :");
18686         print_tx_offloads(queue_offloads);
18687
18688         printf("\n");
18689         printf("  Per Port  :");
18690         print_tx_offloads(port_offloads);
18691         printf("\n\n");
18692 }
18693
18694 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18695         .f = cmd_tx_offload_get_capa_parsed,
18696         .data = NULL,
18697         .help_str = "show port <port_id> tx_offload capabilities",
18698         .tokens = {
18699                 (void *)&cmd_tx_offload_get_capa_show,
18700                 (void *)&cmd_tx_offload_get_capa_port,
18701                 (void *)&cmd_tx_offload_get_capa_port_id,
18702                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18703                 (void *)&cmd_tx_offload_get_capa_capabilities,
18704                 NULL,
18705         }
18706 };
18707
18708 /* Get Tx offloads configuration */
18709 struct cmd_tx_offload_get_configuration_result {
18710         cmdline_fixed_string_t show;
18711         cmdline_fixed_string_t port;
18712         portid_t port_id;
18713         cmdline_fixed_string_t tx_offload;
18714         cmdline_fixed_string_t configuration;
18715 };
18716
18717 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18718         TOKEN_STRING_INITIALIZER
18719                 (struct cmd_tx_offload_get_configuration_result,
18720                  show, "show");
18721 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18722         TOKEN_STRING_INITIALIZER
18723                 (struct cmd_tx_offload_get_configuration_result,
18724                  port, "port");
18725 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18726         TOKEN_NUM_INITIALIZER
18727                 (struct cmd_tx_offload_get_configuration_result,
18728                  port_id, UINT16);
18729 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18730         TOKEN_STRING_INITIALIZER
18731                 (struct cmd_tx_offload_get_configuration_result,
18732                  tx_offload, "tx_offload");
18733 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18734         TOKEN_STRING_INITIALIZER
18735                 (struct cmd_tx_offload_get_configuration_result,
18736                  configuration, "configuration");
18737
18738 static void
18739 cmd_tx_offload_get_configuration_parsed(
18740         void *parsed_result,
18741         __rte_unused struct cmdline *cl,
18742         __rte_unused void *data)
18743 {
18744         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18745         struct rte_eth_dev_info dev_info;
18746         portid_t port_id = res->port_id;
18747         struct rte_port *port = &ports[port_id];
18748         uint64_t port_offloads;
18749         uint64_t queue_offloads;
18750         uint16_t nb_tx_queues;
18751         int q;
18752         int ret;
18753
18754         printf("Tx Offloading Configuration of port %d :\n", port_id);
18755
18756         port_offloads = port->dev_conf.txmode.offloads;
18757         printf("  Port :");
18758         print_tx_offloads(port_offloads);
18759         printf("\n");
18760
18761         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18762         if (ret != 0)
18763                 return;
18764
18765         nb_tx_queues = dev_info.nb_tx_queues;
18766         for (q = 0; q < nb_tx_queues; q++) {
18767                 queue_offloads = port->tx_conf[q].offloads;
18768                 printf("  Queue[%2d] :", q);
18769                 print_tx_offloads(queue_offloads);
18770                 printf("\n");
18771         }
18772         printf("\n");
18773 }
18774
18775 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18776         .f = cmd_tx_offload_get_configuration_parsed,
18777         .data = NULL,
18778         .help_str = "show port <port_id> tx_offload configuration",
18779         .tokens = {
18780                 (void *)&cmd_tx_offload_get_configuration_show,
18781                 (void *)&cmd_tx_offload_get_configuration_port,
18782                 (void *)&cmd_tx_offload_get_configuration_port_id,
18783                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18784                 (void *)&cmd_tx_offload_get_configuration_configuration,
18785                 NULL,
18786         }
18787 };
18788
18789 /* Enable/Disable a per port offloading */
18790 struct cmd_config_per_port_tx_offload_result {
18791         cmdline_fixed_string_t port;
18792         cmdline_fixed_string_t config;
18793         portid_t port_id;
18794         cmdline_fixed_string_t tx_offload;
18795         cmdline_fixed_string_t offload;
18796         cmdline_fixed_string_t on_off;
18797 };
18798
18799 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18800         TOKEN_STRING_INITIALIZER
18801                 (struct cmd_config_per_port_tx_offload_result,
18802                  port, "port");
18803 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18804         TOKEN_STRING_INITIALIZER
18805                 (struct cmd_config_per_port_tx_offload_result,
18806                  config, "config");
18807 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18808         TOKEN_NUM_INITIALIZER
18809                 (struct cmd_config_per_port_tx_offload_result,
18810                  port_id, UINT16);
18811 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18812         TOKEN_STRING_INITIALIZER
18813                 (struct cmd_config_per_port_tx_offload_result,
18814                  tx_offload, "tx_offload");
18815 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18816         TOKEN_STRING_INITIALIZER
18817                 (struct cmd_config_per_port_tx_offload_result,
18818                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18819                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18820                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18821                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18822                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18823                           "send_on_timestamp");
18824 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18825         TOKEN_STRING_INITIALIZER
18826                 (struct cmd_config_per_port_tx_offload_result,
18827                  on_off, "on#off");
18828
18829 static uint64_t
18830 search_tx_offload(const char *name)
18831 {
18832         uint64_t single_offload;
18833         const char *single_name;
18834         int found = 0;
18835         unsigned int bit;
18836
18837         single_offload = 1;
18838         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18839                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18840                 if (single_name == NULL)
18841                         break;
18842                 if (!strcasecmp(single_name, name)) {
18843                         found = 1;
18844                         break;
18845                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18846                         break;
18847                 single_offload <<= 1;
18848         }
18849
18850         if (found)
18851                 return single_offload;
18852
18853         return 0;
18854 }
18855
18856 static void
18857 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18858                                 __rte_unused struct cmdline *cl,
18859                                 __rte_unused void *data)
18860 {
18861         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18862         portid_t port_id = res->port_id;
18863         struct rte_eth_dev_info dev_info;
18864         struct rte_port *port = &ports[port_id];
18865         uint64_t single_offload;
18866         uint16_t nb_tx_queues;
18867         int q;
18868         int ret;
18869
18870         if (port->port_status != RTE_PORT_STOPPED) {
18871                 printf("Error: Can't config offload when Port %d "
18872                        "is not stopped\n", port_id);
18873                 return;
18874         }
18875
18876         single_offload = search_tx_offload(res->offload);
18877         if (single_offload == 0) {
18878                 printf("Unknown offload name: %s\n", res->offload);
18879                 return;
18880         }
18881
18882         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18883         if (ret != 0)
18884                 return;
18885
18886         nb_tx_queues = dev_info.nb_tx_queues;
18887         if (!strcmp(res->on_off, "on")) {
18888                 port->dev_conf.txmode.offloads |= single_offload;
18889                 for (q = 0; q < nb_tx_queues; q++)
18890                         port->tx_conf[q].offloads |= single_offload;
18891         } else {
18892                 port->dev_conf.txmode.offloads &= ~single_offload;
18893                 for (q = 0; q < nb_tx_queues; q++)
18894                         port->tx_conf[q].offloads &= ~single_offload;
18895         }
18896
18897         cmd_reconfig_device_queue(port_id, 1, 1);
18898 }
18899
18900 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18901         .f = cmd_config_per_port_tx_offload_parsed,
18902         .data = NULL,
18903         .help_str = "port config <port_id> tx_offload "
18904                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18905                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18906                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18907                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18908                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18909                     "send_on_timestamp on|off",
18910         .tokens = {
18911                 (void *)&cmd_config_per_port_tx_offload_result_port,
18912                 (void *)&cmd_config_per_port_tx_offload_result_config,
18913                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18914                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18915                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18916                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18917                 NULL,
18918         }
18919 };
18920
18921 /* Enable/Disable a per queue offloading */
18922 struct cmd_config_per_queue_tx_offload_result {
18923         cmdline_fixed_string_t port;
18924         portid_t port_id;
18925         cmdline_fixed_string_t txq;
18926         uint16_t queue_id;
18927         cmdline_fixed_string_t tx_offload;
18928         cmdline_fixed_string_t offload;
18929         cmdline_fixed_string_t on_off;
18930 };
18931
18932 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18933         TOKEN_STRING_INITIALIZER
18934                 (struct cmd_config_per_queue_tx_offload_result,
18935                  port, "port");
18936 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18937         TOKEN_NUM_INITIALIZER
18938                 (struct cmd_config_per_queue_tx_offload_result,
18939                  port_id, UINT16);
18940 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18941         TOKEN_STRING_INITIALIZER
18942                 (struct cmd_config_per_queue_tx_offload_result,
18943                  txq, "txq");
18944 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18945         TOKEN_NUM_INITIALIZER
18946                 (struct cmd_config_per_queue_tx_offload_result,
18947                  queue_id, UINT16);
18948 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18949         TOKEN_STRING_INITIALIZER
18950                 (struct cmd_config_per_queue_tx_offload_result,
18951                  tx_offload, "tx_offload");
18952 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18953         TOKEN_STRING_INITIALIZER
18954                 (struct cmd_config_per_queue_tx_offload_result,
18955                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18956                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18957                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18958                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18959                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18960 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18961         TOKEN_STRING_INITIALIZER
18962                 (struct cmd_config_per_queue_tx_offload_result,
18963                  on_off, "on#off");
18964
18965 static void
18966 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18967                                 __rte_unused struct cmdline *cl,
18968                                 __rte_unused void *data)
18969 {
18970         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18971         struct rte_eth_dev_info dev_info;
18972         portid_t port_id = res->port_id;
18973         uint16_t queue_id = res->queue_id;
18974         struct rte_port *port = &ports[port_id];
18975         uint64_t single_offload;
18976         int ret;
18977
18978         if (port->port_status != RTE_PORT_STOPPED) {
18979                 printf("Error: Can't config offload when Port %d "
18980                        "is not stopped\n", port_id);
18981                 return;
18982         }
18983
18984         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18985         if (ret != 0)
18986                 return;
18987
18988         if (queue_id >= dev_info.nb_tx_queues) {
18989                 printf("Error: input queue_id should be 0 ... "
18990                        "%d\n", dev_info.nb_tx_queues - 1);
18991                 return;
18992         }
18993
18994         single_offload = search_tx_offload(res->offload);
18995         if (single_offload == 0) {
18996                 printf("Unknown offload name: %s\n", res->offload);
18997                 return;
18998         }
18999
19000         if (!strcmp(res->on_off, "on"))
19001                 port->tx_conf[queue_id].offloads |= single_offload;
19002         else
19003                 port->tx_conf[queue_id].offloads &= ~single_offload;
19004
19005         cmd_reconfig_device_queue(port_id, 1, 1);
19006 }
19007
19008 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
19009         .f = cmd_config_per_queue_tx_offload_parsed,
19010         .data = NULL,
19011         .help_str = "port <port_id> txq <queue_id> tx_offload "
19012                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
19013                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
19014                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
19015                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
19016                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
19017                     "on|off",
19018         .tokens = {
19019                 (void *)&cmd_config_per_queue_tx_offload_result_port,
19020                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
19021                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
19022                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
19023                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
19024                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
19025                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
19026                 NULL,
19027         }
19028 };
19029
19030 /* *** configure tx_metadata for specific port *** */
19031 struct cmd_config_tx_metadata_specific_result {
19032         cmdline_fixed_string_t port;
19033         cmdline_fixed_string_t keyword;
19034         uint16_t port_id;
19035         cmdline_fixed_string_t item;
19036         uint32_t value;
19037 };
19038
19039 static void
19040 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
19041                                 __rte_unused struct cmdline *cl,
19042                                 __rte_unused void *data)
19043 {
19044         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
19045
19046         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19047                 return;
19048         ports[res->port_id].tx_metadata = res->value;
19049         /* Add/remove callback to insert valid metadata in every Tx packet. */
19050         if (ports[res->port_id].tx_metadata)
19051                 add_tx_md_callback(res->port_id);
19052         else
19053                 remove_tx_md_callback(res->port_id);
19054         rte_flow_dynf_metadata_register();
19055 }
19056
19057 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
19058         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19059                         port, "port");
19060 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
19061         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19062                         keyword, "config");
19063 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
19064         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19065                         port_id, UINT16);
19066 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
19067         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19068                         item, "tx_metadata");
19069 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
19070         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19071                         value, UINT32);
19072
19073 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
19074         .f = cmd_config_tx_metadata_specific_parsed,
19075         .data = NULL,
19076         .help_str = "port config <port_id> tx_metadata <value>",
19077         .tokens = {
19078                 (void *)&cmd_config_tx_metadata_specific_port,
19079                 (void *)&cmd_config_tx_metadata_specific_keyword,
19080                 (void *)&cmd_config_tx_metadata_specific_id,
19081                 (void *)&cmd_config_tx_metadata_specific_item,
19082                 (void *)&cmd_config_tx_metadata_specific_value,
19083                 NULL,
19084         },
19085 };
19086
19087 /* *** set dynf *** */
19088 struct cmd_config_tx_dynf_specific_result {
19089         cmdline_fixed_string_t port;
19090         cmdline_fixed_string_t keyword;
19091         uint16_t port_id;
19092         cmdline_fixed_string_t item;
19093         cmdline_fixed_string_t name;
19094         cmdline_fixed_string_t value;
19095 };
19096
19097 static void
19098 cmd_config_dynf_specific_parsed(void *parsed_result,
19099                                 __rte_unused struct cmdline *cl,
19100                                 __rte_unused void *data)
19101 {
19102         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
19103         struct rte_mbuf_dynflag desc_flag;
19104         int flag;
19105         uint64_t old_port_flags;
19106
19107         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19108                 return;
19109         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
19110         if (flag <= 0) {
19111                 if (strlcpy(desc_flag.name, res->name,
19112                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
19113                         printf("Flag name too long\n");
19114                         return;
19115                 }
19116                 desc_flag.flags = 0;
19117                 flag = rte_mbuf_dynflag_register(&desc_flag);
19118                 if (flag < 0) {
19119                         printf("Can't register flag\n");
19120                         return;
19121                 }
19122                 strcpy(dynf_names[flag], desc_flag.name);
19123         }
19124         old_port_flags = ports[res->port_id].mbuf_dynf;
19125         if (!strcmp(res->value, "set")) {
19126                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
19127                 if (old_port_flags == 0)
19128                         add_tx_dynf_callback(res->port_id);
19129         } else {
19130                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
19131                 if (ports[res->port_id].mbuf_dynf == 0)
19132                         remove_tx_dynf_callback(res->port_id);
19133         }
19134 }
19135
19136 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
19137         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19138                         keyword, "port");
19139 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
19140         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19141                         keyword, "config");
19142 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
19143         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19144                         port_id, UINT16);
19145 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
19146         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19147                         item, "dynf");
19148 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
19149         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19150                         name, NULL);
19151 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
19152         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19153                         value, "set#clear");
19154
19155 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
19156         .f = cmd_config_dynf_specific_parsed,
19157         .data = NULL,
19158         .help_str = "port config <port id> dynf <name> set|clear",
19159         .tokens = {
19160                 (void *)&cmd_config_tx_dynf_specific_port,
19161                 (void *)&cmd_config_tx_dynf_specific_keyword,
19162                 (void *)&cmd_config_tx_dynf_specific_port_id,
19163                 (void *)&cmd_config_tx_dynf_specific_item,
19164                 (void *)&cmd_config_tx_dynf_specific_name,
19165                 (void *)&cmd_config_tx_dynf_specific_value,
19166                 NULL,
19167         },
19168 };
19169
19170 /* *** display tx_metadata per port configuration *** */
19171 struct cmd_show_tx_metadata_result {
19172         cmdline_fixed_string_t cmd_show;
19173         cmdline_fixed_string_t cmd_port;
19174         cmdline_fixed_string_t cmd_keyword;
19175         portid_t cmd_pid;
19176 };
19177
19178 static void
19179 cmd_show_tx_metadata_parsed(void *parsed_result,
19180                 __rte_unused struct cmdline *cl,
19181                 __rte_unused void *data)
19182 {
19183         struct cmd_show_tx_metadata_result *res = parsed_result;
19184
19185         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19186                 printf("invalid port id %u\n", res->cmd_pid);
19187                 return;
19188         }
19189         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19190                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19191                        ports[res->cmd_pid].tx_metadata);
19192         }
19193 }
19194
19195 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19196         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19197                         cmd_show, "show");
19198 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19199         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19200                         cmd_port, "port");
19201 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19202         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19203                         cmd_pid, UINT16);
19204 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19205         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19206                         cmd_keyword, "tx_metadata");
19207
19208 cmdline_parse_inst_t cmd_show_tx_metadata = {
19209         .f = cmd_show_tx_metadata_parsed,
19210         .data = NULL,
19211         .help_str = "show port <port_id> tx_metadata",
19212         .tokens = {
19213                 (void *)&cmd_show_tx_metadata_show,
19214                 (void *)&cmd_show_tx_metadata_port,
19215                 (void *)&cmd_show_tx_metadata_pid,
19216                 (void *)&cmd_show_tx_metadata_keyword,
19217                 NULL,
19218         },
19219 };
19220
19221 /* show port supported ptypes */
19222
19223 /* Common result structure for show port ptypes */
19224 struct cmd_show_port_supported_ptypes_result {
19225         cmdline_fixed_string_t show;
19226         cmdline_fixed_string_t port;
19227         portid_t port_id;
19228         cmdline_fixed_string_t ptypes;
19229 };
19230
19231 /* Common CLI fields for show port ptypes */
19232 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19233         TOKEN_STRING_INITIALIZER
19234                 (struct cmd_show_port_supported_ptypes_result,
19235                  show, "show");
19236 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19237         TOKEN_STRING_INITIALIZER
19238                 (struct cmd_show_port_supported_ptypes_result,
19239                  port, "port");
19240 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19241         TOKEN_NUM_INITIALIZER
19242                 (struct cmd_show_port_supported_ptypes_result,
19243                  port_id, UINT16);
19244 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19245         TOKEN_STRING_INITIALIZER
19246                 (struct cmd_show_port_supported_ptypes_result,
19247                  ptypes, "ptypes");
19248
19249 static void
19250 cmd_show_port_supported_ptypes_parsed(
19251         void *parsed_result,
19252         __rte_unused struct cmdline *cl,
19253         __rte_unused void *data)
19254 {
19255 #define RSVD_PTYPE_MASK       0xf0000000
19256 #define MAX_PTYPES_PER_LAYER  16
19257 #define LTYPE_NAMESIZE        32
19258 #define PTYPE_NAMESIZE        256
19259         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19260         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19261         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19262         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19263         uint16_t port_id = res->port_id;
19264         int ret, i;
19265
19266         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19267         if (ret < 0)
19268                 return;
19269
19270         while (ptype_mask != RSVD_PTYPE_MASK) {
19271
19272                 switch (ptype_mask) {
19273                 case RTE_PTYPE_L2_MASK:
19274                         strlcpy(ltype, "L2", sizeof(ltype));
19275                         break;
19276                 case RTE_PTYPE_L3_MASK:
19277                         strlcpy(ltype, "L3", sizeof(ltype));
19278                         break;
19279                 case RTE_PTYPE_L4_MASK:
19280                         strlcpy(ltype, "L4", sizeof(ltype));
19281                         break;
19282                 case RTE_PTYPE_TUNNEL_MASK:
19283                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19284                         break;
19285                 case RTE_PTYPE_INNER_L2_MASK:
19286                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19287                         break;
19288                 case RTE_PTYPE_INNER_L3_MASK:
19289                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19290                         break;
19291                 case RTE_PTYPE_INNER_L4_MASK:
19292                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19293                         break;
19294                 default:
19295                         return;
19296                 }
19297
19298                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19299                                                        ptype_mask, ptypes,
19300                                                        MAX_PTYPES_PER_LAYER);
19301
19302                 if (ret > 0)
19303                         printf("Supported %s ptypes:\n", ltype);
19304                 else
19305                         printf("%s ptypes unsupported\n", ltype);
19306
19307                 for (i = 0; i < ret; ++i) {
19308                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19309                         printf("%s\n", buf);
19310                 }
19311
19312                 ptype_mask <<= 4;
19313         }
19314 }
19315
19316 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19317         .f = cmd_show_port_supported_ptypes_parsed,
19318         .data = NULL,
19319         .help_str = "show port <port_id> ptypes",
19320         .tokens = {
19321                 (void *)&cmd_show_port_supported_ptypes_show,
19322                 (void *)&cmd_show_port_supported_ptypes_port,
19323                 (void *)&cmd_show_port_supported_ptypes_port_id,
19324                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19325                 NULL,
19326         },
19327 };
19328
19329 /* *** display rx/tx descriptor status *** */
19330 struct cmd_show_rx_tx_desc_status_result {
19331         cmdline_fixed_string_t cmd_show;
19332         cmdline_fixed_string_t cmd_port;
19333         cmdline_fixed_string_t cmd_keyword;
19334         cmdline_fixed_string_t cmd_desc;
19335         cmdline_fixed_string_t cmd_status;
19336         portid_t cmd_pid;
19337         portid_t cmd_qid;
19338         portid_t cmd_did;
19339 };
19340
19341 static void
19342 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19343                 __rte_unused struct cmdline *cl,
19344                 __rte_unused void *data)
19345 {
19346         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19347         int rc;
19348
19349         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19350                 printf("invalid port id %u\n", res->cmd_pid);
19351                 return;
19352         }
19353
19354         if (!strcmp(res->cmd_keyword, "rxq")) {
19355                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19356                                              res->cmd_did);
19357                 if (rc < 0) {
19358                         printf("Invalid queueid = %d\n", res->cmd_qid);
19359                         return;
19360                 }
19361                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19362                         printf("Desc status = AVAILABLE\n");
19363                 else if (rc == RTE_ETH_RX_DESC_DONE)
19364                         printf("Desc status = DONE\n");
19365                 else
19366                         printf("Desc status = UNAVAILABLE\n");
19367         } else if (!strcmp(res->cmd_keyword, "txq")) {
19368                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19369                                              res->cmd_did);
19370                 if (rc < 0) {
19371                         printf("Invalid queueid = %d\n", res->cmd_qid);
19372                         return;
19373                 }
19374                 if (rc == RTE_ETH_TX_DESC_FULL)
19375                         printf("Desc status = FULL\n");
19376                 else if (rc == RTE_ETH_TX_DESC_DONE)
19377                         printf("Desc status = DONE\n");
19378                 else
19379                         printf("Desc status = UNAVAILABLE\n");
19380         }
19381 }
19382
19383 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19384         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19385                         cmd_show, "show");
19386 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19387         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19388                         cmd_port, "port");
19389 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19390         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19391                         cmd_pid, UINT16);
19392 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19393         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19394                         cmd_keyword, "rxq#txq");
19395 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19396         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19397                         cmd_qid, UINT16);
19398 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19399         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19400                         cmd_desc, "desc");
19401 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19402         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19403                         cmd_did, UINT16);
19404 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19405         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19406                         cmd_status, "status");
19407 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19408         .f = cmd_show_rx_tx_desc_status_parsed,
19409         .data = NULL,
19410         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19411                 "status",
19412         .tokens = {
19413                 (void *)&cmd_show_rx_tx_desc_status_show,
19414                 (void *)&cmd_show_rx_tx_desc_status_port,
19415                 (void *)&cmd_show_rx_tx_desc_status_pid,
19416                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19417                 (void *)&cmd_show_rx_tx_desc_status_qid,
19418                 (void *)&cmd_show_rx_tx_desc_status_desc,
19419                 (void *)&cmd_show_rx_tx_desc_status_did,
19420                 (void *)&cmd_show_rx_tx_desc_status_status,
19421                 NULL,
19422         },
19423 };
19424
19425 /* Common result structure for set port ptypes */
19426 struct cmd_set_port_ptypes_result {
19427         cmdline_fixed_string_t set;
19428         cmdline_fixed_string_t port;
19429         portid_t port_id;
19430         cmdline_fixed_string_t ptype_mask;
19431         uint32_t mask;
19432 };
19433
19434 /* Common CLI fields for set port ptypes */
19435 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19436         TOKEN_STRING_INITIALIZER
19437                 (struct cmd_set_port_ptypes_result,
19438                  set, "set");
19439 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19440         TOKEN_STRING_INITIALIZER
19441                 (struct cmd_set_port_ptypes_result,
19442                  port, "port");
19443 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19444         TOKEN_NUM_INITIALIZER
19445                 (struct cmd_set_port_ptypes_result,
19446                  port_id, UINT16);
19447 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19448         TOKEN_STRING_INITIALIZER
19449                 (struct cmd_set_port_ptypes_result,
19450                  ptype_mask, "ptype_mask");
19451 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19452         TOKEN_NUM_INITIALIZER
19453                 (struct cmd_set_port_ptypes_result,
19454                  mask, UINT32);
19455
19456 static void
19457 cmd_set_port_ptypes_parsed(
19458         void *parsed_result,
19459         __rte_unused struct cmdline *cl,
19460         __rte_unused void *data)
19461 {
19462         struct cmd_set_port_ptypes_result *res = parsed_result;
19463 #define PTYPE_NAMESIZE        256
19464         char ptype_name[PTYPE_NAMESIZE];
19465         uint16_t port_id = res->port_id;
19466         uint32_t ptype_mask = res->mask;
19467         int ret, i;
19468
19469         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19470                                                NULL, 0);
19471         if (ret <= 0) {
19472                 printf("Port %d doesn't support any ptypes.\n", port_id);
19473                 return;
19474         }
19475
19476         uint32_t ptypes[ret];
19477
19478         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19479         if (ret < 0) {
19480                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19481                 return;
19482         }
19483
19484         printf("Successfully set following ptypes for Port %d\n", port_id);
19485         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19486                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19487                 printf("%s\n", ptype_name);
19488         }
19489
19490         clear_ptypes = false;
19491 }
19492
19493 cmdline_parse_inst_t cmd_set_port_ptypes = {
19494         .f = cmd_set_port_ptypes_parsed,
19495         .data = NULL,
19496         .help_str = "set port <port_id> ptype_mask <mask>",
19497         .tokens = {
19498                 (void *)&cmd_set_port_ptypes_set,
19499                 (void *)&cmd_set_port_ptypes_port,
19500                 (void *)&cmd_set_port_ptypes_port_id,
19501                 (void *)&cmd_set_port_ptypes_mask_str,
19502                 (void *)&cmd_set_port_ptypes_mask_u32,
19503                 NULL,
19504         },
19505 };
19506
19507 /* *** display mac addresses added to a port *** */
19508 struct cmd_showport_macs_result {
19509         cmdline_fixed_string_t cmd_show;
19510         cmdline_fixed_string_t cmd_port;
19511         cmdline_fixed_string_t cmd_keyword;
19512         portid_t cmd_pid;
19513 };
19514
19515 static void
19516 cmd_showport_macs_parsed(void *parsed_result,
19517                 __rte_unused struct cmdline *cl,
19518                 __rte_unused void *data)
19519 {
19520         struct cmd_showport_macs_result *res = parsed_result;
19521
19522         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19523                 return;
19524
19525         if (!strcmp(res->cmd_keyword, "macs"))
19526                 show_macs(res->cmd_pid);
19527         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19528                 show_mcast_macs(res->cmd_pid);
19529 }
19530
19531 cmdline_parse_token_string_t cmd_showport_macs_show =
19532         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19533                         cmd_show, "show");
19534 cmdline_parse_token_string_t cmd_showport_macs_port =
19535         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19536                         cmd_port, "port");
19537 cmdline_parse_token_num_t cmd_showport_macs_pid =
19538         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19539                         cmd_pid, UINT16);
19540 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19541         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19542                         cmd_keyword, "macs#mcast_macs");
19543
19544 cmdline_parse_inst_t cmd_showport_macs = {
19545         .f = cmd_showport_macs_parsed,
19546         .data = NULL,
19547         .help_str = "show port <port_id> macs|mcast_macs",
19548         .tokens = {
19549                 (void *)&cmd_showport_macs_show,
19550                 (void *)&cmd_showport_macs_port,
19551                 (void *)&cmd_showport_macs_pid,
19552                 (void *)&cmd_showport_macs_keyword,
19553                 NULL,
19554         },
19555 };
19556
19557 /* ******************************************************************************** */
19558
19559 /* list of instructions */
19560 cmdline_parse_ctx_t main_ctx[] = {
19561         (cmdline_parse_inst_t *)&cmd_help_brief,
19562         (cmdline_parse_inst_t *)&cmd_help_long,
19563         (cmdline_parse_inst_t *)&cmd_quit,
19564         (cmdline_parse_inst_t *)&cmd_load_from_file,
19565         (cmdline_parse_inst_t *)&cmd_showport,
19566         (cmdline_parse_inst_t *)&cmd_showqueue,
19567         (cmdline_parse_inst_t *)&cmd_showeeprom,
19568         (cmdline_parse_inst_t *)&cmd_showportall,
19569         (cmdline_parse_inst_t *)&cmd_showdevice,
19570         (cmdline_parse_inst_t *)&cmd_showcfg,
19571         (cmdline_parse_inst_t *)&cmd_showfwdall,
19572         (cmdline_parse_inst_t *)&cmd_start,
19573         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19574         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19575         (cmdline_parse_inst_t *)&cmd_set_link_up,
19576         (cmdline_parse_inst_t *)&cmd_set_link_down,
19577         (cmdline_parse_inst_t *)&cmd_reset,
19578         (cmdline_parse_inst_t *)&cmd_set_numbers,
19579         (cmdline_parse_inst_t *)&cmd_set_log,
19580         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19581         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19582         (cmdline_parse_inst_t *)&cmd_set_txtimes,
19583         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19584         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19585         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19586         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19587         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19588         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19589         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19590         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19591         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19592         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19593         (cmdline_parse_inst_t *)&cmd_set_link_check,
19594         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19595         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19596         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19597         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19598 #ifdef RTE_LIBRTE_PMD_BOND
19599         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19600         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19601         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19602         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19603         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19604         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19605         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19606         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19607         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19608         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19609         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19610 #endif
19611         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19612         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19613         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19614         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19615         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19616         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19617         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19618         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19619         (cmdline_parse_inst_t *)&cmd_csum_set,
19620         (cmdline_parse_inst_t *)&cmd_csum_show,
19621         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19622         (cmdline_parse_inst_t *)&cmd_tso_set,
19623         (cmdline_parse_inst_t *)&cmd_tso_show,
19624         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19625         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19626         (cmdline_parse_inst_t *)&cmd_gro_enable,
19627         (cmdline_parse_inst_t *)&cmd_gro_flush,
19628         (cmdline_parse_inst_t *)&cmd_gro_show,
19629         (cmdline_parse_inst_t *)&cmd_gso_enable,
19630         (cmdline_parse_inst_t *)&cmd_gso_size,
19631         (cmdline_parse_inst_t *)&cmd_gso_show,
19632         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19633         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19634         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19635         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19636         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19637         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19638         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19639         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19640         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19641         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19642         (cmdline_parse_inst_t *)&cmd_config_dcb,
19643         (cmdline_parse_inst_t *)&cmd_read_reg,
19644         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19645         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19646         (cmdline_parse_inst_t *)&cmd_write_reg,
19647         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19648         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19649         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19650         (cmdline_parse_inst_t *)&cmd_stop,
19651         (cmdline_parse_inst_t *)&cmd_mac_addr,
19652         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19653         (cmdline_parse_inst_t *)&cmd_set_qmap,
19654         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19655         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
19656         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
19657         (cmdline_parse_inst_t *)&cmd_operate_port,
19658         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19659         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19660         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19661         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19662         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19663         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19664         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19665         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19666         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19667         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19668         (cmdline_parse_inst_t *)&cmd_config_mtu,
19669         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19670         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19671         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19672         (cmdline_parse_inst_t *)&cmd_config_rss,
19673         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19674         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19675         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19676         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19677         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19678         (cmdline_parse_inst_t *)&cmd_showport_reta,
19679         (cmdline_parse_inst_t *)&cmd_showport_macs,
19680         (cmdline_parse_inst_t *)&cmd_config_burst,
19681         (cmdline_parse_inst_t *)&cmd_config_thresh,
19682         (cmdline_parse_inst_t *)&cmd_config_threshold,
19683         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19684         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19685         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19686         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19687         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19688         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19689         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19690         (cmdline_parse_inst_t *)&cmd_global_config,
19691         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19692         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19693         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19694         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19695         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19696         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19697         (cmdline_parse_inst_t *)&cmd_dump,
19698         (cmdline_parse_inst_t *)&cmd_dump_one,
19699         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19700         (cmdline_parse_inst_t *)&cmd_syn_filter,
19701         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19702         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19703         (cmdline_parse_inst_t *)&cmd_flex_filter,
19704         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19705         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19706         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19707         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19708         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19709         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19710         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19711         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19712         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19713         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19714         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19715         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19716         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19717         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19718         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19719         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19720         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19721         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19722         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19723         (cmdline_parse_inst_t *)&cmd_flow,
19724         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19725         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19726         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19727         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19728         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19729         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19730         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19731         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19732         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19733         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19734         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19735         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19736         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19737         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19738         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19739         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19740         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19741         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19742         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19743         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19744         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19745         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19746         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19747         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19748         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19749         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19750         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19751         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19752         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19753         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19754         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19755         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19756         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19757         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19758         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19759         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19760         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19761         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19762         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19763         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19764         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19765         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19766         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19767         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19768         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19769         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19770         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19771         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19772         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19773         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19774         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19775         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19776         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19777         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19778         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19779         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19780         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19781         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19782         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19783         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19784         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19785         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19786         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19787         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19788         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19789         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19790         (cmdline_parse_inst_t *)&cmd_ddp_add,
19791         (cmdline_parse_inst_t *)&cmd_ddp_del,
19792         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19793         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19794         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19795         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19796         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19797         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19798         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19799         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19800         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19801         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19802         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19803         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19804
19805         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19806         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19807         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19808         (cmdline_parse_inst_t *)&cmd_queue_region,
19809         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19810         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19811         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19812         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19813         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19814         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19815         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19816         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19817         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19818         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19819         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19820         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19821         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19822         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19823         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19824         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19825         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19826         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
19827         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19828         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19829         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19830         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19831         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19832         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19833         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19834         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19835         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19836         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19837         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19838         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19839         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19840         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19841         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19842         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19843         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19844         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19845 #ifdef RTE_LIBRTE_BPF
19846         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19847         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19848 #endif
19849         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19850         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19851         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19852         (cmdline_parse_inst_t *)&cmd_set_raw,
19853         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19854         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19855         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19856         NULL,
19857 };
19858
19859 /* read cmdline commands from file */
19860 void
19861 cmdline_read_from_file(const char *filename)
19862 {
19863         struct cmdline *cl;
19864
19865         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19866         if (cl == NULL) {
19867                 printf("Failed to create file based cmdline context: %s\n",
19868                        filename);
19869                 return;
19870         }
19871
19872         cmdline_interact(cl);
19873         cmdline_quit(cl);
19874
19875         cmdline_free(cl);
19876
19877         printf("Read CLI commands from %s\n", filename);
19878 }
19879
19880 /* prompt function, called from main on MASTER lcore */
19881 void
19882 prompt(void)
19883 {
19884         /* initialize non-constant commands */
19885         cmd_set_fwd_mode_init();
19886         cmd_set_fwd_retry_mode_init();
19887
19888         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19889         if (testpmd_cl == NULL)
19890                 return;
19891         cmdline_interact(testpmd_cl);
19892         cmdline_stdin_exit(testpmd_cl);
19893 }
19894
19895 void
19896 prompt_exit(void)
19897 {
19898         if (testpmd_cl != NULL)
19899                 cmdline_quit(testpmd_cl);
19900 }
19901
19902 static void
19903 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19904 {
19905         if (id == (portid_t)RTE_PORT_ALL) {
19906                 portid_t pid;
19907
19908                 RTE_ETH_FOREACH_DEV(pid) {
19909                         /* check if need_reconfig has been set to 1 */
19910                         if (ports[pid].need_reconfig == 0)
19911                                 ports[pid].need_reconfig = dev;
19912                         /* check if need_reconfig_queues has been set to 1 */
19913                         if (ports[pid].need_reconfig_queues == 0)
19914                                 ports[pid].need_reconfig_queues = queue;
19915                 }
19916         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19917                 /* check if need_reconfig has been set to 1 */
19918                 if (ports[id].need_reconfig == 0)
19919                         ports[id].need_reconfig = dev;
19920                 /* check if need_reconfig_queues has been set to 1 */
19921                 if (ports[id].need_reconfig_queues == 0)
19922                         ports[id].need_reconfig_queues = queue;
19923         }
19924 }