b040630c54498cdbbe2e97e8cb523c376f95af1e
[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 X rss reta (size) (mask0,mask1,...)\n"
170                         "    Display the rss redirection table entry indicated"
171                         " by masks on port X. size is used to indicate the"
172                         " hardware supported reta size\n\n"
173
174                         "show port (port_id) rss-hash [key]\n"
175                         "    Display the RSS hash functions and RSS hash key of port\n\n"
176
177                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
178                         "    Clear information for port_id, or all.\n\n"
179
180                         "show (rxq|txq) info (port_id) (queue_id)\n"
181                         "    Display information for configured RX/TX queue.\n\n"
182
183                         "show config (rxtx|cores|fwd|txpkts)\n"
184                         "    Display the given configuration.\n\n"
185
186                         "read rxd (port_id) (queue_id) (rxd_id)\n"
187                         "    Display an RX descriptor of a port RX queue.\n\n"
188
189                         "read txd (port_id) (queue_id) (txd_id)\n"
190                         "    Display a TX descriptor of a port TX queue.\n\n"
191
192                         "ddp get list (port_id)\n"
193                         "    Get ddp profile info list\n\n"
194
195                         "ddp get info (profile_path)\n"
196                         "    Get ddp profile information.\n\n"
197
198                         "show vf stats (port_id) (vf_id)\n"
199                         "    Display a VF's statistics.\n\n"
200
201                         "clear vf stats (port_id) (vf_id)\n"
202                         "    Reset a VF's statistics.\n\n"
203
204                         "show port (port_id) pctype mapping\n"
205                         "    Get flow ptype to pctype mapping on a port\n\n"
206
207                         "show port meter stats (port_id) (meter_id) (clear)\n"
208                         "    Get meter stats on a port\n\n"
209
210                         "show fwd stats all\n"
211                         "    Display statistics for all fwd engines.\n\n"
212
213                         "clear fwd stats all\n"
214                         "    Clear statistics for all fwd engines.\n\n"
215
216                         "show port (port_id) rx_offload capabilities\n"
217                         "    List all per queue and per port Rx offloading"
218                         " capabilities of a port\n\n"
219
220                         "show port (port_id) rx_offload configuration\n"
221                         "    List port level and all queue level"
222                         " Rx offloading configuration\n\n"
223
224                         "show port (port_id) tx_offload capabilities\n"
225                         "    List all per queue and per port"
226                         " Tx offloading capabilities of a port\n\n"
227
228                         "show port (port_id) tx_offload configuration\n"
229                         "    List port level and all queue level"
230                         " Tx offloading configuration\n\n"
231
232                         "show port (port_id) tx_metadata\n"
233                         "    Show Tx metadata value set"
234                         " for a specific port\n\n"
235
236                         "show port (port_id) ptypes\n"
237                         "    Show port supported ptypes"
238                         " for a specific port\n\n"
239
240                         "show device info (<identifier>|all)"
241                         "       Show general information about devices probed.\n\n"
242
243                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
244                         "       Show status of rx|tx descriptor.\n\n"
245
246                         "show port (port_id) macs|mcast_macs"
247                         "       Display list of mac addresses added to port.\n\n"
248                 );
249         }
250
251         if (show_all || !strcmp(res->section, "config")) {
252                 cmdline_printf(
253                         cl,
254                         "\n"
255                         "Configuration:\n"
256                         "--------------\n"
257                         "Configuration changes only become active when"
258                         " forwarding is started/restarted.\n\n"
259
260                         "set default\n"
261                         "    Reset forwarding to the default configuration.\n\n"
262
263                         "set verbose (level)\n"
264                         "    Set the debug verbosity level X.\n\n"
265
266                         "set log global|(type) (level)\n"
267                         "    Set the log level.\n\n"
268
269                         "set nbport (num)\n"
270                         "    Set number of ports.\n\n"
271
272                         "set nbcore (num)\n"
273                         "    Set number of cores.\n\n"
274
275                         "set coremask (mask)\n"
276                         "    Set the forwarding cores hexadecimal mask.\n\n"
277
278                         "set portmask (mask)\n"
279                         "    Set the forwarding ports hexadecimal mask.\n\n"
280
281                         "set burst (num)\n"
282                         "    Set number of packets per burst.\n\n"
283
284                         "set burst tx delay (microseconds) retry (num)\n"
285                         "    Set the transmit delay time and number of retries,"
286                         " effective when retry is enabled.\n\n"
287
288                         "set txpkts (x[,y]*)\n"
289                         "    Set the length of each segment of TXONLY"
290                         " and optionally CSUM packets.\n\n"
291
292                         "set txsplit (off|on|rand)\n"
293                         "    Set the split policy for the TX packets."
294                         " Right now only applicable for CSUM and TXONLY"
295                         " modes\n\n"
296
297                         "set corelist (x[,y]*)\n"
298                         "    Set the list of forwarding cores.\n\n"
299
300                         "set portlist (x[,y]*)\n"
301                         "    Set the list of forwarding ports.\n\n"
302
303                         "set port setup on (iterator|event)\n"
304                         "    Select how attached port is retrieved for setup.\n\n"
305
306                         "set tx loopback (port_id) (on|off)\n"
307                         "    Enable or disable tx loopback.\n\n"
308
309                         "set all queues drop (port_id) (on|off)\n"
310                         "    Set drop enable bit for all queues.\n\n"
311
312                         "set vf split drop (port_id) (vf_id) (on|off)\n"
313                         "    Set split drop enable bit for a VF from the PF.\n\n"
314
315                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
316                         "    Set MAC antispoof for a VF from the PF.\n\n"
317
318                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
319                         "    Enable MACsec offload.\n\n"
320
321                         "set macsec offload (port_id) off\n"
322                         "    Disable MACsec offload.\n\n"
323
324                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
325                         "    Configure MACsec secure connection (SC).\n\n"
326
327                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
328                         "    Configure MACsec secure association (SA).\n\n"
329
330                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
331                         "    Set VF broadcast for a VF from the PF.\n\n"
332
333                         "vlan set stripq (on|off) (port_id,queue_id)\n"
334                         "    Set the VLAN strip for a queue on a port.\n\n"
335
336                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
337                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
338
339                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
340                         "    Set VLAN insert for a VF from the PF.\n\n"
341
342                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
343                         "    Set VLAN antispoof for a VF from the PF.\n\n"
344
345                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
346                         "    Set VLAN tag for a VF from the PF.\n\n"
347
348                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
349                         "    Set a VF's max bandwidth(Mbps).\n\n"
350
351                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
352                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
353
354                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
355                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
356
357                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
358                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
359
360                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
361                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
362
363                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
364                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
365
366                         "vlan set (inner|outer) tpid (value) (port_id)\n"
367                         "    Set the VLAN TPID for Packet Filtering on"
368                         " a port\n\n"
369
370                         "rx_vlan add (vlan_id|all) (port_id)\n"
371                         "    Add a vlan_id, or all identifiers, to the set"
372                         " of VLAN identifiers filtered by port_id.\n\n"
373
374                         "rx_vlan rm (vlan_id|all) (port_id)\n"
375                         "    Remove a vlan_id, or all identifiers, from the set"
376                         " of VLAN identifiers filtered by port_id.\n\n"
377
378                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
379                         "    Add a vlan_id, to the set of VLAN identifiers"
380                         "filtered for VF(s) from port_id.\n\n"
381
382                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
383                         "    Remove a vlan_id, to the set of VLAN identifiers"
384                         "filtered for VF(s) from port_id.\n\n"
385
386                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
387                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
388                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
389                         "   add a tunnel filter of a port.\n\n"
390
391                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
392                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
393                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
394                         "   remove a tunnel filter of a port.\n\n"
395
396                         "rx_vxlan_port add (udp_port) (port_id)\n"
397                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
398
399                         "rx_vxlan_port rm (udp_port) (port_id)\n"
400                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
401
402                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
403                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
404                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
405
406                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
407                         "    Set port based TX VLAN insertion.\n\n"
408
409                         "tx_vlan reset (port_id)\n"
410                         "    Disable hardware insertion of a VLAN header in"
411                         " packets sent on a port.\n\n"
412
413                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
414                         "    Select hardware or software calculation of the"
415                         " checksum when transmitting a packet using the"
416                         " csum forward engine.\n"
417                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
418                         "    outer-ip concerns the outer IP layer in"
419                         "    outer-udp concerns the outer UDP layer in"
420                         " case the packet is recognized as a tunnel packet by"
421                         " the forward engine (vxlan, gre and ipip are supported)\n"
422                         "    Please check the NIC datasheet for HW limits.\n\n"
423
424                         "csum parse-tunnel (on|off) (tx_port_id)\n"
425                         "    If disabled, treat tunnel packets as non-tunneled"
426                         " packets (treat inner headers as payload). The port\n"
427                         "    argument is the port used for TX in csum forward"
428                         " engine.\n\n"
429
430                         "csum show (port_id)\n"
431                         "    Display tx checksum offload configuration\n\n"
432
433                         "tso set (segsize) (portid)\n"
434                         "    Enable TCP Segmentation Offload in csum forward"
435                         " engine.\n"
436                         "    Please check the NIC datasheet for HW limits.\n\n"
437
438                         "tso show (portid)"
439                         "    Display the status of TCP Segmentation Offload.\n\n"
440
441                         "set port (port_id) gro on|off\n"
442                         "    Enable or disable Generic Receive Offload in"
443                         " csum forwarding engine.\n\n"
444
445                         "show port (port_id) gro\n"
446                         "    Display GRO configuration.\n\n"
447
448                         "set gro flush (cycles)\n"
449                         "    Set the cycle to flush GROed packets from"
450                         " reassembly tables.\n\n"
451
452                         "set port (port_id) gso (on|off)"
453                         "    Enable or disable Generic Segmentation Offload in"
454                         " csum forwarding engine.\n\n"
455
456                         "set gso segsz (length)\n"
457                         "    Set max packet length for output GSO segments,"
458                         " including packet header and payload.\n\n"
459
460                         "show port (port_id) gso\n"
461                         "    Show GSO configuration.\n\n"
462
463                         "set fwd (%s)\n"
464                         "    Set packet forwarding mode.\n\n"
465
466                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
467                         "    Add a MAC address on port_id.\n\n"
468
469                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
470                         "    Remove a MAC address from port_id.\n\n"
471
472                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
473                         "    Set the default MAC address for port_id.\n\n"
474
475                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
476                         "    Add a MAC address for a VF on the port.\n\n"
477
478                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
479                         "    Set the MAC address for a VF from the PF.\n\n"
480
481                         "set eth-peer (port_id) (peer_addr)\n"
482                         "    set the peer address for certain port.\n\n"
483
484                         "set port (port_id) uta (mac_address|all) (on|off)\n"
485                         "    Add/Remove a or all unicast hash filter(s)"
486                         "from port X.\n\n"
487
488                         "set promisc (port_id|all) (on|off)\n"
489                         "    Set the promiscuous mode on port_id, or all.\n\n"
490
491                         "set allmulti (port_id|all) (on|off)\n"
492                         "    Set the allmulti mode on port_id, or all.\n\n"
493
494                         "set vf promisc (port_id) (vf_id) (on|off)\n"
495                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
496
497                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
498                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
499
500                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
501                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
502                         " (on|off) autoneg (on|off) (port_id)\n"
503                         "set flow_ctrl rx (on|off) (portid)\n"
504                         "set flow_ctrl tx (on|off) (portid)\n"
505                         "set flow_ctrl high_water (high_water) (portid)\n"
506                         "set flow_ctrl low_water (low_water) (portid)\n"
507                         "set flow_ctrl pause_time (pause_time) (portid)\n"
508                         "set flow_ctrl send_xon (send_xon) (portid)\n"
509                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
510                         "set flow_ctrl autoneg (on|off) (port_id)\n"
511                         "    Set the link flow control parameter on a port.\n\n"
512
513                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
514                         " (low_water) (pause_time) (priority) (port_id)\n"
515                         "    Set the priority flow control parameter on a"
516                         " port.\n\n"
517
518                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
519                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
520                         " queue on port.\n"
521                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
522                         " on port 0 to mapping 5.\n\n"
523
524                         "set xstats-hide-zero on|off\n"
525                         "    Set the option to hide the zero values"
526                         " for xstats display.\n"
527
528                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
529                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
530
531                         "set port (port_id) vf (vf_id) (mac_addr)"
532                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
533                         "   Add/Remove unicast or multicast MAC addr filter"
534                         " for a VF.\n\n"
535
536                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
537                         "|MPE) (on|off)\n"
538                         "    AUPE:accepts untagged VLAN;"
539                         "ROPE:accept unicast hash\n\n"
540                         "    BAM:accepts broadcast packets;"
541                         "MPE:accepts all multicast packets\n\n"
542                         "    Enable/Disable a VF receive mode of a port\n\n"
543
544                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
545                         "    Set rate limit for a queue of a port\n\n"
546
547                         "set port (port_id) vf (vf_id) rate (rate_num) "
548                         "queue_mask (queue_mask_value)\n"
549                         "    Set rate limit for queues in VF of a port\n\n"
550
551                         "set port (port_id) mirror-rule (rule_id)"
552                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
553                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
554                         "   Set pool or vlan type mirror rule on a port.\n"
555                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
556                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
557                         " to pool 0.\n\n"
558
559                         "set port (port_id) mirror-rule (rule_id)"
560                         " (uplink-mirror|downlink-mirror) dst-pool"
561                         " (pool_id) (on|off)\n"
562                         "   Set uplink or downlink type mirror rule on a port.\n"
563                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
564                         " 0 on' enable mirror income traffic to pool 0.\n\n"
565
566                         "reset port (port_id) mirror-rule (rule_id)\n"
567                         "   Reset a mirror rule.\n\n"
568
569                         "set flush_rx (on|off)\n"
570                         "   Flush (default) or don't flush RX streams before"
571                         " forwarding. Mainly used with PCAP drivers.\n\n"
572
573                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
574                         "   Set the bypass mode for the lowest port on bypass enabled"
575                         " NIC.\n\n"
576
577                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
578                         "mode (normal|bypass|isolate) (port_id)\n"
579                         "   Set the event required to initiate specified bypass mode for"
580                         " the lowest port on a bypass enabled NIC where:\n"
581                         "       timeout   = enable bypass after watchdog timeout.\n"
582                         "       os_on     = enable bypass when OS/board is powered on.\n"
583                         "       os_off    = enable bypass when OS/board is powered off.\n"
584                         "       power_on  = enable bypass when power supply is turned on.\n"
585                         "       power_off = enable bypass when power supply is turned off."
586                         "\n\n"
587
588                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
589                         "   Set the bypass watchdog timeout to 'n' seconds"
590                         " where 0 = instant.\n\n"
591
592                         "show bypass config (port_id)\n"
593                         "   Show the bypass configuration for a bypass enabled NIC"
594                         " using the lowest port on the NIC.\n\n"
595
596 #ifdef RTE_LIBRTE_PMD_BOND
597                         "create bonded device (mode) (socket)\n"
598                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
599
600                         "add bonding slave (slave_id) (port_id)\n"
601                         "       Add a slave device to a bonded device.\n\n"
602
603                         "remove bonding slave (slave_id) (port_id)\n"
604                         "       Remove a slave device from a bonded device.\n\n"
605
606                         "set bonding mode (value) (port_id)\n"
607                         "       Set the bonding mode on a bonded device.\n\n"
608
609                         "set bonding primary (slave_id) (port_id)\n"
610                         "       Set the primary slave for a bonded device.\n\n"
611
612                         "show bonding config (port_id)\n"
613                         "       Show the bonding config for port_id.\n\n"
614
615                         "set bonding mac_addr (port_id) (address)\n"
616                         "       Set the MAC address of a bonded device.\n\n"
617
618                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
619                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
620
621                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
622                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
623
624                         "set bonding mon_period (port_id) (value)\n"
625                         "       Set the bonding link status monitoring polling period in ms.\n\n"
626
627                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
628                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
629
630 #endif
631                         "set link-up port (port_id)\n"
632                         "       Set link up for a port.\n\n"
633
634                         "set link-down port (port_id)\n"
635                         "       Set link down for a port.\n\n"
636
637                         "E-tag set insertion on port-tag-id (value)"
638                         " port (port_id) vf (vf_id)\n"
639                         "    Enable E-tag insertion for a VF on a port\n\n"
640
641                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
642                         "    Disable E-tag insertion for a VF on a port\n\n"
643
644                         "E-tag set stripping (on|off) port (port_id)\n"
645                         "    Enable/disable E-tag stripping on a port\n\n"
646
647                         "E-tag set forwarding (on|off) port (port_id)\n"
648                         "    Enable/disable E-tag based forwarding"
649                         " on a port\n\n"
650
651                         "E-tag set filter add e-tag-id (value) dst-pool"
652                         " (pool_id) port (port_id)\n"
653                         "    Add an E-tag forwarding filter on a port\n\n"
654
655                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
656                         "    Delete an E-tag forwarding filter on a port\n\n"
657
658                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
659                         "    Load a profile package on a port\n\n"
660
661                         "ddp del (port_id) (backup_profile_path)\n"
662                         "    Delete a profile package from a port\n\n"
663
664                         "ptype mapping get (port_id) (valid_only)\n"
665                         "    Get ptype mapping on a port\n\n"
666
667                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
668                         "    Replace target with the pkt_type in ptype mapping\n\n"
669
670                         "ptype mapping reset (port_id)\n"
671                         "    Reset ptype mapping on a port\n\n"
672
673                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
674                         "    Update a ptype mapping item on a port\n\n"
675
676                         "set port (port_id) ptype_mask (ptype_mask)\n"
677                         "    set packet types classification for a specific port\n\n"
678
679                         "set port (port_id) queue-region region_id (value) "
680                         "queue_start_index (value) queue_num (value)\n"
681                         "    Set a queue region on a port\n\n"
682
683                         "set port (port_id) queue-region region_id (value) "
684                         "flowtype (value)\n"
685                         "    Set a flowtype region index on a port\n\n"
686
687                         "set port (port_id) queue-region UP (value) region_id (value)\n"
688                         "    Set the mapping of User Priority to "
689                         "queue region on a port\n\n"
690
691                         "set port (port_id) queue-region flush (on|off)\n"
692                         "    flush all queue region related configuration\n\n"
693
694                         "show port meter cap (port_id)\n"
695                         "    Show port meter capability information\n\n"
696
697                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
698                         "    meter profile add - srtcm rfc 2697\n\n"
699
700                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
701                         "    meter profile add - trtcm rfc 2698\n\n"
702
703                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
704                         "    meter profile add - trtcm rfc 4115\n\n"
705
706                         "del port meter profile (port_id) (profile_id)\n"
707                         "    meter profile delete\n\n"
708
709                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
710                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
711                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
712                         "(dscp_tbl_entry63)]\n"
713                         "    meter create\n\n"
714
715                         "enable port meter (port_id) (mtr_id)\n"
716                         "    meter enable\n\n"
717
718                         "disable port meter (port_id) (mtr_id)\n"
719                         "    meter disable\n\n"
720
721                         "del port meter (port_id) (mtr_id)\n"
722                         "    meter delete\n\n"
723
724                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
725                         "    meter update meter profile\n\n"
726
727                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
728                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
729                         "    update meter dscp table entries\n\n"
730
731                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
732                         "(action0) [(action1) (action2)]\n"
733                         "    meter update policer action\n\n"
734
735                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
736                         "    meter update stats\n\n"
737
738                         "show port (port_id) queue-region\n"
739                         "    show all queue region related configuration info\n\n"
740
741                         , list_pkt_forwarding_modes()
742                 );
743         }
744
745         if (show_all || !strcmp(res->section, "ports")) {
746
747                 cmdline_printf(
748                         cl,
749                         "\n"
750                         "Port Operations:\n"
751                         "----------------\n\n"
752
753                         "port start (port_id|all)\n"
754                         "    Start all ports or port_id.\n\n"
755
756                         "port stop (port_id|all)\n"
757                         "    Stop all ports or port_id.\n\n"
758
759                         "port close (port_id|all)\n"
760                         "    Close all ports or port_id.\n\n"
761
762                         "port reset (port_id|all)\n"
763                         "    Reset all ports or port_id.\n\n"
764
765                         "port attach (ident)\n"
766                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
767
768                         "port detach (port_id)\n"
769                         "    Detach physical or virtual dev by port_id\n\n"
770
771                         "port config (port_id|all)"
772                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
773                         " duplex (half|full|auto)\n"
774                         "    Set speed and duplex for all ports or port_id\n\n"
775
776                         "port config (port_id|all) loopback (mode)\n"
777                         "    Set loopback mode for all ports or port_id\n\n"
778
779                         "port config all (rxq|txq|rxd|txd) (value)\n"
780                         "    Set number for rxq/txq/rxd/txd.\n\n"
781
782                         "port config all max-pkt-len (value)\n"
783                         "    Set the max packet length.\n\n"
784
785                         "port config all max-lro-pkt-size (value)\n"
786                         "    Set the max LRO aggregated packet size.\n\n"
787
788                         "port config all drop-en (on|off)\n"
789                         "    Enable or disable packet drop on all RX queues of all ports when no "
790                         "receive buffers available.\n\n"
791
792                         "port config all rss (all|default|ip|tcp|udp|sctp|"
793                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
794                         "    Set the RSS mode.\n\n"
795
796                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
797                         "    Set the RSS redirection table.\n\n"
798
799                         "port config (port_id) dcb vt (on|off) (traffic_class)"
800                         " pfc (on|off)\n"
801                         "    Set the DCB mode.\n\n"
802
803                         "port config all burst (value)\n"
804                         "    Set the number of packets per burst.\n\n"
805
806                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
807                         " (value)\n"
808                         "    Set the ring prefetch/host/writeback threshold"
809                         " for tx/rx queue.\n\n"
810
811                         "port config all (txfreet|txrst|rxfreet) (value)\n"
812                         "    Set free threshold for rx/tx, or set"
813                         " tx rs bit threshold.\n\n"
814                         "port config mtu X value\n"
815                         "    Set the MTU of port X to a given value\n\n"
816
817                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
818                         "    Set a rx/tx queue's ring size configuration, the new"
819                         " value will take effect after command that (re-)start the port"
820                         " or command that setup the specific queue\n\n"
821
822                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
823                         "    Start/stop a rx/tx queue of port X. Only take effect"
824                         " when port X is started\n\n"
825
826                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
827                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
828                         " take effect when port X is stopped.\n\n"
829
830                         "port (port_id) (rxq|txq) (queue_id) setup\n"
831                         "    Setup a rx/tx queue of port X.\n\n"
832
833                         "port config (port_id|all) l2-tunnel E-tag ether-type"
834                         " (value)\n"
835                         "    Set the value of E-tag ether-type.\n\n"
836
837                         "port config (port_id|all) l2-tunnel E-tag"
838                         " (enable|disable)\n"
839                         "    Enable/disable the E-tag support.\n\n"
840
841                         "port config (port_id) pctype mapping reset\n"
842                         "    Reset flow type to pctype mapping on a port\n\n"
843
844                         "port config (port_id) pctype mapping update"
845                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
846                         "    Update a flow type to pctype mapping item on a port\n\n"
847
848                         "port config (port_id) pctype (pctype_id) hash_inset|"
849                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
850                         " (field_idx)\n"
851                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
852
853                         "port config (port_id) pctype (pctype_id) hash_inset|"
854                         "fdir_inset|fdir_flx_inset clear all"
855                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
856
857                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
858                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
859
860                         "port config <port_id> rx_offload vlan_strip|"
861                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
862                         "outer_ipv4_cksum|macsec_strip|header_split|"
863                         "vlan_filter|vlan_extend|jumbo_frame|"
864                         "scatter|timestamp|security|keep_crc on|off\n"
865                         "     Enable or disable a per port Rx offloading"
866                         " on all Rx queues of a port\n\n"
867
868                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
869                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
870                         "outer_ipv4_cksum|macsec_strip|header_split|"
871                         "vlan_filter|vlan_extend|jumbo_frame|"
872                         "scatter|timestamp|security|keep_crc on|off\n"
873                         "    Enable or disable a per queue Rx offloading"
874                         " only on a specific Rx queue\n\n"
875
876                         "port config (port_id) tx_offload vlan_insert|"
877                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
878                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
879                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
880                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
881                         "security on|off\n"
882                         "    Enable or disable a per port Tx offloading"
883                         " on all Tx queues of a port\n\n"
884
885                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
886                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
887                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
888                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
889                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
890                         " on|off\n"
891                         "    Enable or disable a per queue Tx offloading"
892                         " only on a specific Tx queue\n\n"
893
894                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
895                         "    Load an eBPF program as a callback"
896                         " for particular RX/TX queue\n\n"
897
898                         "bpf-unload rx|tx (port) (queue)\n"
899                         "    Unload previously loaded eBPF program"
900                         " for particular RX/TX queue\n\n"
901
902                         "port config (port_id) tx_metadata (value)\n"
903                         "    Set Tx metadata value per port. Testpmd will add this value"
904                         " to any Tx packet sent from this port\n\n"
905
906                         "port config (port_id) dynf (name) set|clear\n"
907                         "    Register a dynf and Set/clear this flag on Tx. "
908                         "Testpmd will set this value to any Tx packet "
909                         "sent from this port\n\n"
910                 );
911         }
912
913         if (show_all || !strcmp(res->section, "registers")) {
914
915                 cmdline_printf(
916                         cl,
917                         "\n"
918                         "Registers:\n"
919                         "----------\n\n"
920
921                         "read reg (port_id) (address)\n"
922                         "    Display value of a port register.\n\n"
923
924                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
925                         "    Display a port register bit field.\n\n"
926
927                         "read regbit (port_id) (address) (bit_x)\n"
928                         "    Display a single port register bit.\n\n"
929
930                         "write reg (port_id) (address) (value)\n"
931                         "    Set value of a port register.\n\n"
932
933                         "write regfield (port_id) (address) (bit_x) (bit_y)"
934                         " (value)\n"
935                         "    Set bit field of a port register.\n\n"
936
937                         "write regbit (port_id) (address) (bit_x) (value)\n"
938                         "    Set single bit value of a port register.\n\n"
939                 );
940         }
941         if (show_all || !strcmp(res->section, "filters")) {
942
943                 cmdline_printf(
944                         cl,
945                         "\n"
946                         "filters:\n"
947                         "--------\n\n"
948
949                         "ethertype_filter (port_id) (add|del)"
950                         " (mac_addr|mac_ignr) (mac_address) ethertype"
951                         " (ether_type) (drop|fwd) queue (queue_id)\n"
952                         "    Add/Del an ethertype filter.\n\n"
953
954                         "2tuple_filter (port_id) (add|del)"
955                         " dst_port (dst_port_value) protocol (protocol_value)"
956                         " mask (mask_value) tcp_flags (tcp_flags_value)"
957                         " priority (prio_value) queue (queue_id)\n"
958                         "    Add/Del a 2tuple filter.\n\n"
959
960                         "5tuple_filter (port_id) (add|del)"
961                         " dst_ip (dst_address) src_ip (src_address)"
962                         " dst_port (dst_port_value) src_port (src_port_value)"
963                         " protocol (protocol_value)"
964                         " mask (mask_value) tcp_flags (tcp_flags_value)"
965                         " priority (prio_value) queue (queue_id)\n"
966                         "    Add/Del a 5tuple filter.\n\n"
967
968                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
969                         "    Add/Del syn filter.\n\n"
970
971                         "flex_filter (port_id) (add|del) len (len_value)"
972                         " bytes (bytes_value) mask (mask_value)"
973                         " priority (prio_value) queue (queue_id)\n"
974                         "    Add/Del a flex filter.\n\n"
975
976                         "flow_director_filter (port_id) mode IP (add|del|update)"
977                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
978                         " src (src_ip_address) dst (dst_ip_address)"
979                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
980                         " vlan (vlan_value) flexbytes (flexbytes_value)"
981                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
982                         " fd_id (fd_id_value)\n"
983                         "    Add/Del an IP type flow director filter.\n\n"
984
985                         "flow_director_filter (port_id) mode IP (add|del|update)"
986                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
987                         " src (src_ip_address) (src_port)"
988                         " dst (dst_ip_address) (dst_port)"
989                         " tos (tos_value) ttl (ttl_value)"
990                         " vlan (vlan_value) flexbytes (flexbytes_value)"
991                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
992                         " fd_id (fd_id_value)\n"
993                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
994
995                         "flow_director_filter (port_id) mode IP (add|del|update)"
996                         " flow (ipv4-sctp|ipv6-sctp)"
997                         " src (src_ip_address) (src_port)"
998                         " dst (dst_ip_address) (dst_port)"
999                         " tag (verification_tag) "
1000                         " tos (tos_value) ttl (ttl_value)"
1001                         " vlan (vlan_value)"
1002                         " flexbytes (flexbytes_value) (drop|fwd)"
1003                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1004                         "    Add/Del a SCTP type flow director filter.\n\n"
1005
1006                         "flow_director_filter (port_id) mode IP (add|del|update)"
1007                         " flow l2_payload ether (ethertype)"
1008                         " flexbytes (flexbytes_value) (drop|fwd)"
1009                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1010                         "    Add/Del a l2 payload type flow director filter.\n\n"
1011
1012                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1013                         " mac (mac_address) vlan (vlan_value)"
1014                         " flexbytes (flexbytes_value) (drop|fwd)"
1015                         " queue (queue_id) fd_id (fd_id_value)\n"
1016                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1017
1018                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1019                         " mac (mac_address) vlan (vlan_value)"
1020                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1021                         " flexbytes (flexbytes_value) (drop|fwd)"
1022                         " queue (queue_id) fd_id (fd_id_value)\n"
1023                         "    Add/Del a Tunnel flow director filter.\n\n"
1024
1025                         "flow_director_filter (port_id) mode raw (add|del|update)"
1026                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1027                         " fd_id (fd_id_value) packet (packet file name)\n"
1028                         "    Add/Del a raw type flow director filter.\n\n"
1029
1030                         "flush_flow_director (port_id)\n"
1031                         "    Flush all flow director entries of a device.\n\n"
1032
1033                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1034                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1035                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1036                         "    Set flow director IP mask.\n\n"
1037
1038                         "flow_director_mask (port_id) mode MAC-VLAN"
1039                         " vlan (vlan_value)\n"
1040                         "    Set flow director MAC-VLAN mask.\n\n"
1041
1042                         "flow_director_mask (port_id) mode Tunnel"
1043                         " vlan (vlan_value) mac (mac_value)"
1044                         " tunnel-type (tunnel_type_value)"
1045                         " tunnel-id (tunnel_id_value)\n"
1046                         "    Set flow director Tunnel mask.\n\n"
1047
1048                         "flow_director_flex_mask (port_id)"
1049                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1050                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1051                         " (mask)\n"
1052                         "    Configure mask of flex payload.\n\n"
1053
1054                         "flow_director_flex_payload (port_id)"
1055                         " (raw|l2|l3|l4) (config)\n"
1056                         "    Configure flex payload selection.\n\n"
1057
1058                         "get_sym_hash_ena_per_port (port_id)\n"
1059                         "    get symmetric hash enable configuration per port.\n\n"
1060
1061                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1062                         "    set symmetric hash enable configuration per port"
1063                         " to enable or disable.\n\n"
1064
1065                         "get_hash_global_config (port_id)\n"
1066                         "    Get the global configurations of hash filters.\n\n"
1067
1068                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1069                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1070                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1071                         " (enable|disable)\n"
1072                         "    Set the global configurations of hash filters.\n\n"
1073
1074                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1075                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1076                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1077                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1078                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1079                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1080                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1081                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1082                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1083                         "fld-8th|none) (select|add)\n"
1084                         "    Set the input set for hash.\n\n"
1085
1086                         "set_fdir_input_set (port_id) "
1087                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1088                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1089                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1090                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1091                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1092                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1093                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1094                         " (select|add)\n"
1095                         "    Set the input set for FDir.\n\n"
1096
1097                         "flow validate {port_id}"
1098                         " [group {group_id}] [priority {level}]"
1099                         " [ingress] [egress]"
1100                         " pattern {item} [/ {item} [...]] / end"
1101                         " actions {action} [/ {action} [...]] / end\n"
1102                         "    Check whether a flow rule can be created.\n\n"
1103
1104                         "flow create {port_id}"
1105                         " [group {group_id}] [priority {level}]"
1106                         " [ingress] [egress]"
1107                         " pattern {item} [/ {item} [...]] / end"
1108                         " actions {action} [/ {action} [...]] / end\n"
1109                         "    Create a flow rule.\n\n"
1110
1111                         "flow destroy {port_id} rule {rule_id} [...]\n"
1112                         "    Destroy specific flow rules.\n\n"
1113
1114                         "flow flush {port_id}\n"
1115                         "    Destroy all flow rules.\n\n"
1116
1117                         "flow query {port_id} {rule_id} {action}\n"
1118                         "    Query an existing flow rule.\n\n"
1119
1120                         "flow list {port_id} [group {group_id}] [...]\n"
1121                         "    List existing flow rules sorted by priority,"
1122                         " filtered by group identifiers.\n\n"
1123
1124                         "flow isolate {port_id} {boolean}\n"
1125                         "    Restrict ingress traffic to the defined"
1126                         " flow rules\n\n"
1127
1128                         "flow aged {port_id} [destroy]\n"
1129                         "    List and destroy aged flows"
1130                         " flow rules\n\n"
1131
1132                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1133                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1134                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1135                         "       Configure the VXLAN encapsulation for flows.\n\n"
1136
1137                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1138                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1139                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1140                         " eth-dst (eth-dst)\n"
1141                         "       Configure the VXLAN encapsulation for flows.\n\n"
1142
1143                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1144                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1145                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1146                         " eth-dst (eth-dst)\n"
1147                         "       Configure the VXLAN encapsulation for flows.\n\n"
1148
1149                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1150                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1151                         " (eth-dst)\n"
1152                         "       Configure the NVGRE encapsulation for flows.\n\n"
1153
1154                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1155                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1156                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1157                         "       Configure the NVGRE encapsulation for flows.\n\n"
1158
1159                         "set raw_encap {flow items}\n"
1160                         "       Configure the encapsulation with raw data.\n\n"
1161
1162                         "set raw_decap {flow items}\n"
1163                         "       Configure the decapsulation with raw data.\n\n"
1164
1165                 );
1166         }
1167
1168         if (show_all || !strcmp(res->section, "traffic_management")) {
1169                 cmdline_printf(
1170                         cl,
1171                         "\n"
1172                         "Traffic Management:\n"
1173                         "--------------\n"
1174                         "show port tm cap (port_id)\n"
1175                         "       Display the port TM capability.\n\n"
1176
1177                         "show port tm level cap (port_id) (level_id)\n"
1178                         "       Display the port TM hierarchical level capability.\n\n"
1179
1180                         "show port tm node cap (port_id) (node_id)\n"
1181                         "       Display the port TM node capability.\n\n"
1182
1183                         "show port tm node type (port_id) (node_id)\n"
1184                         "       Display the port TM node type.\n\n"
1185
1186                         "show port tm node stats (port_id) (node_id) (clear)\n"
1187                         "       Display the port TM node stats.\n\n"
1188
1189 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1190                         "set port tm hierarchy default (port_id)\n"
1191                         "       Set default traffic Management hierarchy on a port\n\n"
1192 #endif
1193
1194                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1195                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1196                         " (packet_length_adjust)\n"
1197                         "       Add port tm node private shaper profile.\n\n"
1198
1199                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1200                         "       Delete port tm node private shaper profile.\n\n"
1201
1202                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1203                         " (shaper_profile_id)\n"
1204                         "       Add/update port tm node shared shaper.\n\n"
1205
1206                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1207                         "       Delete port tm node shared shaper.\n\n"
1208
1209                         "set port tm node shaper profile (port_id) (node_id)"
1210                         " (shaper_profile_id)\n"
1211                         "       Set port tm node shaper profile.\n\n"
1212
1213                         "add port tm node wred profile (port_id) (wred_profile_id)"
1214                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1215                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1216                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1217                         "       Add port tm node wred profile.\n\n"
1218
1219                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1220                         "       Delete port tm node wred profile.\n\n"
1221
1222                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1223                         " (priority) (weight) (level_id) (shaper_profile_id)"
1224                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1225                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1226                         "       Add port tm nonleaf node.\n\n"
1227
1228                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1229                         " (priority) (weight) (level_id) (shaper_profile_id)"
1230                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1231                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1232                         "       Add port tm leaf node.\n\n"
1233
1234                         "del port tm node (port_id) (node_id)\n"
1235                         "       Delete port tm node.\n\n"
1236
1237                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1238                         " (priority) (weight)\n"
1239                         "       Set port tm node parent.\n\n"
1240
1241                         "suspend port tm node (port_id) (node_id)"
1242                         "       Suspend tm node.\n\n"
1243
1244                         "resume port tm node (port_id) (node_id)"
1245                         "       Resume tm node.\n\n"
1246
1247                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1248                         "       Commit tm hierarchy.\n\n"
1249
1250                         "set port tm mark ip_ecn (port) (green) (yellow)"
1251                         " (red)\n"
1252                         "    Enables/Disables the traffic management marking"
1253                         " for IP ECN (Explicit Congestion Notification)"
1254                         " packets on a given port\n\n"
1255
1256                         "set port tm mark ip_dscp (port) (green) (yellow)"
1257                         " (red)\n"
1258                         "    Enables/Disables the traffic management marking"
1259                         " on the port for IP dscp packets\n\n"
1260
1261                         "set port tm mark vlan_dei (port) (green) (yellow)"
1262                         " (red)\n"
1263                         "    Enables/Disables the traffic management marking"
1264                         " on the port for VLAN packets with DEI enabled\n\n"
1265                 );
1266         }
1267
1268         if (show_all || !strcmp(res->section, "devices")) {
1269                 cmdline_printf(
1270                         cl,
1271                         "\n"
1272                         "Device Operations:\n"
1273                         "--------------\n"
1274                         "device detach (identifier)\n"
1275                         "       Detach device by identifier.\n\n"
1276                 );
1277         }
1278
1279 }
1280
1281 cmdline_parse_token_string_t cmd_help_long_help =
1282         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1283
1284 cmdline_parse_token_string_t cmd_help_long_section =
1285         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1286                         "all#control#display#config#"
1287                         "ports#registers#filters#traffic_management#devices");
1288
1289 cmdline_parse_inst_t cmd_help_long = {
1290         .f = cmd_help_long_parsed,
1291         .data = NULL,
1292         .help_str = "help all|control|display|config|ports|register|"
1293                 "filters|traffic_management|devices: "
1294                 "Show help",
1295         .tokens = {
1296                 (void *)&cmd_help_long_help,
1297                 (void *)&cmd_help_long_section,
1298                 NULL,
1299         },
1300 };
1301
1302
1303 /* *** start/stop/close all ports *** */
1304 struct cmd_operate_port_result {
1305         cmdline_fixed_string_t keyword;
1306         cmdline_fixed_string_t name;
1307         cmdline_fixed_string_t value;
1308 };
1309
1310 static void cmd_operate_port_parsed(void *parsed_result,
1311                                 __rte_unused struct cmdline *cl,
1312                                 __rte_unused void *data)
1313 {
1314         struct cmd_operate_port_result *res = parsed_result;
1315
1316         if (!strcmp(res->name, "start"))
1317                 start_port(RTE_PORT_ALL);
1318         else if (!strcmp(res->name, "stop"))
1319                 stop_port(RTE_PORT_ALL);
1320         else if (!strcmp(res->name, "close"))
1321                 close_port(RTE_PORT_ALL);
1322         else if (!strcmp(res->name, "reset"))
1323                 reset_port(RTE_PORT_ALL);
1324         else
1325                 printf("Unknown parameter\n");
1326 }
1327
1328 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1329         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1330                                                                 "port");
1331 cmdline_parse_token_string_t cmd_operate_port_all_port =
1332         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1333                                                 "start#stop#close#reset");
1334 cmdline_parse_token_string_t cmd_operate_port_all_all =
1335         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1336
1337 cmdline_parse_inst_t cmd_operate_port = {
1338         .f = cmd_operate_port_parsed,
1339         .data = NULL,
1340         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1341         .tokens = {
1342                 (void *)&cmd_operate_port_all_cmd,
1343                 (void *)&cmd_operate_port_all_port,
1344                 (void *)&cmd_operate_port_all_all,
1345                 NULL,
1346         },
1347 };
1348
1349 /* *** start/stop/close specific port *** */
1350 struct cmd_operate_specific_port_result {
1351         cmdline_fixed_string_t keyword;
1352         cmdline_fixed_string_t name;
1353         uint8_t value;
1354 };
1355
1356 static void cmd_operate_specific_port_parsed(void *parsed_result,
1357                         __rte_unused struct cmdline *cl,
1358                                 __rte_unused void *data)
1359 {
1360         struct cmd_operate_specific_port_result *res = parsed_result;
1361
1362         if (!strcmp(res->name, "start"))
1363                 start_port(res->value);
1364         else if (!strcmp(res->name, "stop"))
1365                 stop_port(res->value);
1366         else if (!strcmp(res->name, "close"))
1367                 close_port(res->value);
1368         else if (!strcmp(res->name, "reset"))
1369                 reset_port(res->value);
1370         else
1371                 printf("Unknown parameter\n");
1372 }
1373
1374 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1375         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1376                                                         keyword, "port");
1377 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1378         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1379                                                 name, "start#stop#close#reset");
1380 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1381         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1382                                                         value, UINT8);
1383
1384 cmdline_parse_inst_t cmd_operate_specific_port = {
1385         .f = cmd_operate_specific_port_parsed,
1386         .data = NULL,
1387         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1388         .tokens = {
1389                 (void *)&cmd_operate_specific_port_cmd,
1390                 (void *)&cmd_operate_specific_port_port,
1391                 (void *)&cmd_operate_specific_port_id,
1392                 NULL,
1393         },
1394 };
1395
1396 /* *** enable port setup (after attach) via iterator or event *** */
1397 struct cmd_set_port_setup_on_result {
1398         cmdline_fixed_string_t set;
1399         cmdline_fixed_string_t port;
1400         cmdline_fixed_string_t setup;
1401         cmdline_fixed_string_t on;
1402         cmdline_fixed_string_t mode;
1403 };
1404
1405 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1406                                 __rte_unused struct cmdline *cl,
1407                                 __rte_unused void *data)
1408 {
1409         struct cmd_set_port_setup_on_result *res = parsed_result;
1410
1411         if (strcmp(res->mode, "event") == 0)
1412                 setup_on_probe_event = true;
1413         else if (strcmp(res->mode, "iterator") == 0)
1414                 setup_on_probe_event = false;
1415         else
1416                 printf("Unknown mode\n");
1417 }
1418
1419 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1420         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1421                         set, "set");
1422 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1423         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1424                         port, "port");
1425 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1426         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1427                         setup, "setup");
1428 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1429         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1430                         on, "on");
1431 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1432         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1433                         mode, "iterator#event");
1434
1435 cmdline_parse_inst_t cmd_set_port_setup_on = {
1436         .f = cmd_set_port_setup_on_parsed,
1437         .data = NULL,
1438         .help_str = "set port setup on iterator|event",
1439         .tokens = {
1440                 (void *)&cmd_set_port_setup_on_set,
1441                 (void *)&cmd_set_port_setup_on_port,
1442                 (void *)&cmd_set_port_setup_on_setup,
1443                 (void *)&cmd_set_port_setup_on_on,
1444                 (void *)&cmd_set_port_setup_on_mode,
1445                 NULL,
1446         },
1447 };
1448
1449 /* *** attach a specified port *** */
1450 struct cmd_operate_attach_port_result {
1451         cmdline_fixed_string_t port;
1452         cmdline_fixed_string_t keyword;
1453         cmdline_multi_string_t identifier;
1454 };
1455
1456 static void cmd_operate_attach_port_parsed(void *parsed_result,
1457                                 __rte_unused struct cmdline *cl,
1458                                 __rte_unused void *data)
1459 {
1460         struct cmd_operate_attach_port_result *res = parsed_result;
1461
1462         if (!strcmp(res->keyword, "attach"))
1463                 attach_port(res->identifier);
1464         else
1465                 printf("Unknown parameter\n");
1466 }
1467
1468 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1469         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1470                         port, "port");
1471 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1472         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1473                         keyword, "attach");
1474 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1475         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1476                         identifier, TOKEN_STRING_MULTI);
1477
1478 cmdline_parse_inst_t cmd_operate_attach_port = {
1479         .f = cmd_operate_attach_port_parsed,
1480         .data = NULL,
1481         .help_str = "port attach <identifier>: "
1482                 "(identifier: pci address or virtual dev name)",
1483         .tokens = {
1484                 (void *)&cmd_operate_attach_port_port,
1485                 (void *)&cmd_operate_attach_port_keyword,
1486                 (void *)&cmd_operate_attach_port_identifier,
1487                 NULL,
1488         },
1489 };
1490
1491 /* *** detach a specified port *** */
1492 struct cmd_operate_detach_port_result {
1493         cmdline_fixed_string_t port;
1494         cmdline_fixed_string_t keyword;
1495         portid_t port_id;
1496 };
1497
1498 static void cmd_operate_detach_port_parsed(void *parsed_result,
1499                                 __rte_unused struct cmdline *cl,
1500                                 __rte_unused void *data)
1501 {
1502         struct cmd_operate_detach_port_result *res = parsed_result;
1503
1504         if (!strcmp(res->keyword, "detach")) {
1505                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1506                 detach_port_device(res->port_id);
1507         } else {
1508                 printf("Unknown parameter\n");
1509         }
1510 }
1511
1512 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1513         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1514                         port, "port");
1515 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1516         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1517                         keyword, "detach");
1518 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1519         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1520                         port_id, UINT16);
1521
1522 cmdline_parse_inst_t cmd_operate_detach_port = {
1523         .f = cmd_operate_detach_port_parsed,
1524         .data = NULL,
1525         .help_str = "port detach <port_id>",
1526         .tokens = {
1527                 (void *)&cmd_operate_detach_port_port,
1528                 (void *)&cmd_operate_detach_port_keyword,
1529                 (void *)&cmd_operate_detach_port_port_id,
1530                 NULL,
1531         },
1532 };
1533
1534 /* *** detach device by identifier *** */
1535 struct cmd_operate_detach_device_result {
1536         cmdline_fixed_string_t device;
1537         cmdline_fixed_string_t keyword;
1538         cmdline_fixed_string_t identifier;
1539 };
1540
1541 static void cmd_operate_detach_device_parsed(void *parsed_result,
1542                                 __rte_unused struct cmdline *cl,
1543                                 __rte_unused void *data)
1544 {
1545         struct cmd_operate_detach_device_result *res = parsed_result;
1546
1547         if (!strcmp(res->keyword, "detach"))
1548                 detach_devargs(res->identifier);
1549         else
1550                 printf("Unknown parameter\n");
1551 }
1552
1553 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1554         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1555                         device, "device");
1556 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1557         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1558                         keyword, "detach");
1559 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1560         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1561                         identifier, NULL);
1562
1563 cmdline_parse_inst_t cmd_operate_detach_device = {
1564         .f = cmd_operate_detach_device_parsed,
1565         .data = NULL,
1566         .help_str = "device detach <identifier>:"
1567                 "(identifier: pci address or virtual dev name)",
1568         .tokens = {
1569                 (void *)&cmd_operate_detach_device_device,
1570                 (void *)&cmd_operate_detach_device_keyword,
1571                 (void *)&cmd_operate_detach_device_identifier,
1572                 NULL,
1573         },
1574 };
1575 /* *** configure speed for all ports *** */
1576 struct cmd_config_speed_all {
1577         cmdline_fixed_string_t port;
1578         cmdline_fixed_string_t keyword;
1579         cmdline_fixed_string_t all;
1580         cmdline_fixed_string_t item1;
1581         cmdline_fixed_string_t item2;
1582         cmdline_fixed_string_t value1;
1583         cmdline_fixed_string_t value2;
1584 };
1585
1586 static int
1587 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1588 {
1589
1590         int duplex;
1591
1592         if (!strcmp(duplexstr, "half")) {
1593                 duplex = ETH_LINK_HALF_DUPLEX;
1594         } else if (!strcmp(duplexstr, "full")) {
1595                 duplex = ETH_LINK_FULL_DUPLEX;
1596         } else if (!strcmp(duplexstr, "auto")) {
1597                 duplex = ETH_LINK_FULL_DUPLEX;
1598         } else {
1599                 printf("Unknown duplex parameter\n");
1600                 return -1;
1601         }
1602
1603         if (!strcmp(speedstr, "10")) {
1604                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1605                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1606         } else if (!strcmp(speedstr, "100")) {
1607                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1608                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1609         } else {
1610                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1611                         printf("Invalid speed/duplex parameters\n");
1612                         return -1;
1613                 }
1614                 if (!strcmp(speedstr, "1000")) {
1615                         *speed = ETH_LINK_SPEED_1G;
1616                 } else if (!strcmp(speedstr, "10000")) {
1617                         *speed = ETH_LINK_SPEED_10G;
1618                 } else if (!strcmp(speedstr, "25000")) {
1619                         *speed = ETH_LINK_SPEED_25G;
1620                 } else if (!strcmp(speedstr, "40000")) {
1621                         *speed = ETH_LINK_SPEED_40G;
1622                 } else if (!strcmp(speedstr, "50000")) {
1623                         *speed = ETH_LINK_SPEED_50G;
1624                 } else if (!strcmp(speedstr, "100000")) {
1625                         *speed = ETH_LINK_SPEED_100G;
1626                 } else if (!strcmp(speedstr, "200000")) {
1627                         *speed = ETH_LINK_SPEED_200G;
1628                 } else if (!strcmp(speedstr, "auto")) {
1629                         *speed = ETH_LINK_SPEED_AUTONEG;
1630                 } else {
1631                         printf("Unknown speed parameter\n");
1632                         return -1;
1633                 }
1634         }
1635
1636         return 0;
1637 }
1638
1639 static void
1640 cmd_config_speed_all_parsed(void *parsed_result,
1641                         __rte_unused struct cmdline *cl,
1642                         __rte_unused void *data)
1643 {
1644         struct cmd_config_speed_all *res = parsed_result;
1645         uint32_t link_speed;
1646         portid_t pid;
1647
1648         if (!all_ports_stopped()) {
1649                 printf("Please stop all ports first\n");
1650                 return;
1651         }
1652
1653         if (parse_and_check_speed_duplex(res->value1, res->value2,
1654                         &link_speed) < 0)
1655                 return;
1656
1657         RTE_ETH_FOREACH_DEV(pid) {
1658                 ports[pid].dev_conf.link_speeds = link_speed;
1659         }
1660
1661         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1662 }
1663
1664 cmdline_parse_token_string_t cmd_config_speed_all_port =
1665         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1666 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1667         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1668                                                         "config");
1669 cmdline_parse_token_string_t cmd_config_speed_all_all =
1670         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1671 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1672         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1673 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1674         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1675                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1676 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1677         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1678 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1679         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1680                                                 "half#full#auto");
1681
1682 cmdline_parse_inst_t cmd_config_speed_all = {
1683         .f = cmd_config_speed_all_parsed,
1684         .data = NULL,
1685         .help_str = "port config all speed "
1686                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1687                                                         "half|full|auto",
1688         .tokens = {
1689                 (void *)&cmd_config_speed_all_port,
1690                 (void *)&cmd_config_speed_all_keyword,
1691                 (void *)&cmd_config_speed_all_all,
1692                 (void *)&cmd_config_speed_all_item1,
1693                 (void *)&cmd_config_speed_all_value1,
1694                 (void *)&cmd_config_speed_all_item2,
1695                 (void *)&cmd_config_speed_all_value2,
1696                 NULL,
1697         },
1698 };
1699
1700 /* *** configure speed for specific port *** */
1701 struct cmd_config_speed_specific {
1702         cmdline_fixed_string_t port;
1703         cmdline_fixed_string_t keyword;
1704         portid_t id;
1705         cmdline_fixed_string_t item1;
1706         cmdline_fixed_string_t item2;
1707         cmdline_fixed_string_t value1;
1708         cmdline_fixed_string_t value2;
1709 };
1710
1711 static void
1712 cmd_config_speed_specific_parsed(void *parsed_result,
1713                                 __rte_unused struct cmdline *cl,
1714                                 __rte_unused void *data)
1715 {
1716         struct cmd_config_speed_specific *res = parsed_result;
1717         uint32_t link_speed;
1718
1719         if (!all_ports_stopped()) {
1720                 printf("Please stop all ports first\n");
1721                 return;
1722         }
1723
1724         if (port_id_is_invalid(res->id, ENABLED_WARN))
1725                 return;
1726
1727         if (parse_and_check_speed_duplex(res->value1, res->value2,
1728                         &link_speed) < 0)
1729                 return;
1730
1731         ports[res->id].dev_conf.link_speeds = link_speed;
1732
1733         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1734 }
1735
1736
1737 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1738         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1739                                                                 "port");
1740 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1741         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1742                                                                 "config");
1743 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1744         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1745 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1746         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1747                                                                 "speed");
1748 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1749         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1750                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1751 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1752         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1753                                                                 "duplex");
1754 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1755         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1756                                                         "half#full#auto");
1757
1758 cmdline_parse_inst_t cmd_config_speed_specific = {
1759         .f = cmd_config_speed_specific_parsed,
1760         .data = NULL,
1761         .help_str = "port config <port_id> speed "
1762                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1763                                                         "half|full|auto",
1764         .tokens = {
1765                 (void *)&cmd_config_speed_specific_port,
1766                 (void *)&cmd_config_speed_specific_keyword,
1767                 (void *)&cmd_config_speed_specific_id,
1768                 (void *)&cmd_config_speed_specific_item1,
1769                 (void *)&cmd_config_speed_specific_value1,
1770                 (void *)&cmd_config_speed_specific_item2,
1771                 (void *)&cmd_config_speed_specific_value2,
1772                 NULL,
1773         },
1774 };
1775
1776 /* *** configure loopback for all ports *** */
1777 struct cmd_config_loopback_all {
1778         cmdline_fixed_string_t port;
1779         cmdline_fixed_string_t keyword;
1780         cmdline_fixed_string_t all;
1781         cmdline_fixed_string_t item;
1782         uint32_t mode;
1783 };
1784
1785 static void
1786 cmd_config_loopback_all_parsed(void *parsed_result,
1787                         __rte_unused struct cmdline *cl,
1788                         __rte_unused void *data)
1789 {
1790         struct cmd_config_loopback_all *res = parsed_result;
1791         portid_t pid;
1792
1793         if (!all_ports_stopped()) {
1794                 printf("Please stop all ports first\n");
1795                 return;
1796         }
1797
1798         RTE_ETH_FOREACH_DEV(pid) {
1799                 ports[pid].dev_conf.lpbk_mode = res->mode;
1800         }
1801
1802         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1803 }
1804
1805 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1806         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1807 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1808         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1809                                                         "config");
1810 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1811         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1812 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1813         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1814                                                         "loopback");
1815 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1816         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1817
1818 cmdline_parse_inst_t cmd_config_loopback_all = {
1819         .f = cmd_config_loopback_all_parsed,
1820         .data = NULL,
1821         .help_str = "port config all loopback <mode>",
1822         .tokens = {
1823                 (void *)&cmd_config_loopback_all_port,
1824                 (void *)&cmd_config_loopback_all_keyword,
1825                 (void *)&cmd_config_loopback_all_all,
1826                 (void *)&cmd_config_loopback_all_item,
1827                 (void *)&cmd_config_loopback_all_mode,
1828                 NULL,
1829         },
1830 };
1831
1832 /* *** configure loopback for specific port *** */
1833 struct cmd_config_loopback_specific {
1834         cmdline_fixed_string_t port;
1835         cmdline_fixed_string_t keyword;
1836         uint16_t port_id;
1837         cmdline_fixed_string_t item;
1838         uint32_t mode;
1839 };
1840
1841 static void
1842 cmd_config_loopback_specific_parsed(void *parsed_result,
1843                                 __rte_unused struct cmdline *cl,
1844                                 __rte_unused void *data)
1845 {
1846         struct cmd_config_loopback_specific *res = parsed_result;
1847
1848         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1849                 return;
1850
1851         if (!port_is_stopped(res->port_id)) {
1852                 printf("Please stop port %u first\n", res->port_id);
1853                 return;
1854         }
1855
1856         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1857
1858         cmd_reconfig_device_queue(res->port_id, 1, 1);
1859 }
1860
1861
1862 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1863         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1864                                                                 "port");
1865 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1866         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1867                                                                 "config");
1868 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1869         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1870                                                                 UINT16);
1871 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1872         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1873                                                                 "loopback");
1874 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1875         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1876                               UINT32);
1877
1878 cmdline_parse_inst_t cmd_config_loopback_specific = {
1879         .f = cmd_config_loopback_specific_parsed,
1880         .data = NULL,
1881         .help_str = "port config <port_id> loopback <mode>",
1882         .tokens = {
1883                 (void *)&cmd_config_loopback_specific_port,
1884                 (void *)&cmd_config_loopback_specific_keyword,
1885                 (void *)&cmd_config_loopback_specific_id,
1886                 (void *)&cmd_config_loopback_specific_item,
1887                 (void *)&cmd_config_loopback_specific_mode,
1888                 NULL,
1889         },
1890 };
1891
1892 /* *** configure txq/rxq, txd/rxd *** */
1893 struct cmd_config_rx_tx {
1894         cmdline_fixed_string_t port;
1895         cmdline_fixed_string_t keyword;
1896         cmdline_fixed_string_t all;
1897         cmdline_fixed_string_t name;
1898         uint16_t value;
1899 };
1900
1901 static void
1902 cmd_config_rx_tx_parsed(void *parsed_result,
1903                         __rte_unused struct cmdline *cl,
1904                         __rte_unused void *data)
1905 {
1906         struct cmd_config_rx_tx *res = parsed_result;
1907
1908         if (!all_ports_stopped()) {
1909                 printf("Please stop all ports first\n");
1910                 return;
1911         }
1912         if (!strcmp(res->name, "rxq")) {
1913                 if (!res->value && !nb_txq) {
1914                         printf("Warning: Either rx or tx queues should be non zero\n");
1915                         return;
1916                 }
1917                 if (check_nb_rxq(res->value) != 0)
1918                         return;
1919                 nb_rxq = res->value;
1920         }
1921         else if (!strcmp(res->name, "txq")) {
1922                 if (!res->value && !nb_rxq) {
1923                         printf("Warning: Either rx or tx queues should be non zero\n");
1924                         return;
1925                 }
1926                 if (check_nb_txq(res->value) != 0)
1927                         return;
1928                 nb_txq = res->value;
1929         }
1930         else if (!strcmp(res->name, "rxd")) {
1931                 if (check_nb_rxd(res->value) != 0)
1932                         return;
1933                 nb_rxd = res->value;
1934         } else if (!strcmp(res->name, "txd")) {
1935                 if (check_nb_txd(res->value) != 0)
1936                         return;
1937
1938                 nb_txd = res->value;
1939         } else {
1940                 printf("Unknown parameter\n");
1941                 return;
1942         }
1943
1944         fwd_config_setup();
1945
1946         init_port_config();
1947
1948         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1949 }
1950
1951 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1952         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1953 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1954         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1955 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1956         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1957 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1958         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1959                                                 "rxq#txq#rxd#txd");
1960 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1961         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1962
1963 cmdline_parse_inst_t cmd_config_rx_tx = {
1964         .f = cmd_config_rx_tx_parsed,
1965         .data = NULL,
1966         .help_str = "port config all rxq|txq|rxd|txd <value>",
1967         .tokens = {
1968                 (void *)&cmd_config_rx_tx_port,
1969                 (void *)&cmd_config_rx_tx_keyword,
1970                 (void *)&cmd_config_rx_tx_all,
1971                 (void *)&cmd_config_rx_tx_name,
1972                 (void *)&cmd_config_rx_tx_value,
1973                 NULL,
1974         },
1975 };
1976
1977 /* *** config max packet length *** */
1978 struct cmd_config_max_pkt_len_result {
1979         cmdline_fixed_string_t port;
1980         cmdline_fixed_string_t keyword;
1981         cmdline_fixed_string_t all;
1982         cmdline_fixed_string_t name;
1983         uint32_t value;
1984 };
1985
1986 static void
1987 cmd_config_max_pkt_len_parsed(void *parsed_result,
1988                                 __rte_unused struct cmdline *cl,
1989                                 __rte_unused void *data)
1990 {
1991         struct cmd_config_max_pkt_len_result *res = parsed_result;
1992         portid_t pid;
1993
1994         if (!all_ports_stopped()) {
1995                 printf("Please stop all ports first\n");
1996                 return;
1997         }
1998
1999         RTE_ETH_FOREACH_DEV(pid) {
2000                 struct rte_port *port = &ports[pid];
2001                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2002
2003                 if (!strcmp(res->name, "max-pkt-len")) {
2004                         if (res->value < RTE_ETHER_MIN_LEN) {
2005                                 printf("max-pkt-len can not be less than %d\n",
2006                                                 RTE_ETHER_MIN_LEN);
2007                                 return;
2008                         }
2009                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2010                                 return;
2011
2012                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2013                         if (res->value > RTE_ETHER_MAX_LEN)
2014                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2015                         else
2016                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2017                         port->dev_conf.rxmode.offloads = rx_offloads;
2018                 } else {
2019                         printf("Unknown parameter\n");
2020                         return;
2021                 }
2022         }
2023
2024         init_port_config();
2025
2026         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2027 }
2028
2029 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2030         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2031                                                                 "port");
2032 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2033         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2034                                                                 "config");
2035 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2036         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2037                                                                 "all");
2038 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2039         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2040                                                                 "max-pkt-len");
2041 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2042         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2043                                                                 UINT32);
2044
2045 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2046         .f = cmd_config_max_pkt_len_parsed,
2047         .data = NULL,
2048         .help_str = "port config all max-pkt-len <value>",
2049         .tokens = {
2050                 (void *)&cmd_config_max_pkt_len_port,
2051                 (void *)&cmd_config_max_pkt_len_keyword,
2052                 (void *)&cmd_config_max_pkt_len_all,
2053                 (void *)&cmd_config_max_pkt_len_name,
2054                 (void *)&cmd_config_max_pkt_len_value,
2055                 NULL,
2056         },
2057 };
2058
2059 /* *** config max LRO aggregated packet size *** */
2060 struct cmd_config_max_lro_pkt_size_result {
2061         cmdline_fixed_string_t port;
2062         cmdline_fixed_string_t keyword;
2063         cmdline_fixed_string_t all;
2064         cmdline_fixed_string_t name;
2065         uint32_t value;
2066 };
2067
2068 static void
2069 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2070                                 __rte_unused struct cmdline *cl,
2071                                 __rte_unused void *data)
2072 {
2073         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2074         portid_t pid;
2075
2076         if (!all_ports_stopped()) {
2077                 printf("Please stop all ports first\n");
2078                 return;
2079         }
2080
2081         RTE_ETH_FOREACH_DEV(pid) {
2082                 struct rte_port *port = &ports[pid];
2083
2084                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2085                         if (res->value ==
2086                                         port->dev_conf.rxmode.max_lro_pkt_size)
2087                                 return;
2088
2089                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2090                 } else {
2091                         printf("Unknown parameter\n");
2092                         return;
2093                 }
2094         }
2095
2096         init_port_config();
2097
2098         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2099 }
2100
2101 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2102         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2103                                  port, "port");
2104 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2105         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2106                                  keyword, "config");
2107 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2108         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2109                                  all, "all");
2110 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2111         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2112                                  name, "max-lro-pkt-size");
2113 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2114         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2115                               value, UINT32);
2116
2117 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2118         .f = cmd_config_max_lro_pkt_size_parsed,
2119         .data = NULL,
2120         .help_str = "port config all max-lro-pkt-size <value>",
2121         .tokens = {
2122                 (void *)&cmd_config_max_lro_pkt_size_port,
2123                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2124                 (void *)&cmd_config_max_lro_pkt_size_all,
2125                 (void *)&cmd_config_max_lro_pkt_size_name,
2126                 (void *)&cmd_config_max_lro_pkt_size_value,
2127                 NULL,
2128         },
2129 };
2130
2131 /* *** configure port MTU *** */
2132 struct cmd_config_mtu_result {
2133         cmdline_fixed_string_t port;
2134         cmdline_fixed_string_t keyword;
2135         cmdline_fixed_string_t mtu;
2136         portid_t port_id;
2137         uint16_t value;
2138 };
2139
2140 static void
2141 cmd_config_mtu_parsed(void *parsed_result,
2142                       __rte_unused struct cmdline *cl,
2143                       __rte_unused void *data)
2144 {
2145         struct cmd_config_mtu_result *res = parsed_result;
2146
2147         if (res->value < RTE_ETHER_MIN_LEN) {
2148                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2149                 return;
2150         }
2151         port_mtu_set(res->port_id, res->value);
2152 }
2153
2154 cmdline_parse_token_string_t cmd_config_mtu_port =
2155         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2156                                  "port");
2157 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2158         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2159                                  "config");
2160 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2161         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2162                                  "mtu");
2163 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2164         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2165 cmdline_parse_token_num_t cmd_config_mtu_value =
2166         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2167
2168 cmdline_parse_inst_t cmd_config_mtu = {
2169         .f = cmd_config_mtu_parsed,
2170         .data = NULL,
2171         .help_str = "port config mtu <port_id> <value>",
2172         .tokens = {
2173                 (void *)&cmd_config_mtu_port,
2174                 (void *)&cmd_config_mtu_keyword,
2175                 (void *)&cmd_config_mtu_mtu,
2176                 (void *)&cmd_config_mtu_port_id,
2177                 (void *)&cmd_config_mtu_value,
2178                 NULL,
2179         },
2180 };
2181
2182 /* *** configure rx mode *** */
2183 struct cmd_config_rx_mode_flag {
2184         cmdline_fixed_string_t port;
2185         cmdline_fixed_string_t keyword;
2186         cmdline_fixed_string_t all;
2187         cmdline_fixed_string_t name;
2188         cmdline_fixed_string_t value;
2189 };
2190
2191 static void
2192 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2193                                 __rte_unused struct cmdline *cl,
2194                                 __rte_unused void *data)
2195 {
2196         struct cmd_config_rx_mode_flag *res = parsed_result;
2197
2198         if (!all_ports_stopped()) {
2199                 printf("Please stop all ports first\n");
2200                 return;
2201         }
2202
2203         if (!strcmp(res->name, "drop-en")) {
2204                 if (!strcmp(res->value, "on"))
2205                         rx_drop_en = 1;
2206                 else if (!strcmp(res->value, "off"))
2207                         rx_drop_en = 0;
2208                 else {
2209                         printf("Unknown parameter\n");
2210                         return;
2211                 }
2212         } else {
2213                 printf("Unknown parameter\n");
2214                 return;
2215         }
2216
2217         init_port_config();
2218
2219         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2220 }
2221
2222 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2223         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2224 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2225         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2226                                                                 "config");
2227 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2228         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2229 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2230         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2231                                         "drop-en");
2232 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2233         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2234                                                         "on#off");
2235
2236 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2237         .f = cmd_config_rx_mode_flag_parsed,
2238         .data = NULL,
2239         .help_str = "port config all drop-en on|off",
2240         .tokens = {
2241                 (void *)&cmd_config_rx_mode_flag_port,
2242                 (void *)&cmd_config_rx_mode_flag_keyword,
2243                 (void *)&cmd_config_rx_mode_flag_all,
2244                 (void *)&cmd_config_rx_mode_flag_name,
2245                 (void *)&cmd_config_rx_mode_flag_value,
2246                 NULL,
2247         },
2248 };
2249
2250 /* *** configure rss *** */
2251 struct cmd_config_rss {
2252         cmdline_fixed_string_t port;
2253         cmdline_fixed_string_t keyword;
2254         cmdline_fixed_string_t all;
2255         cmdline_fixed_string_t name;
2256         cmdline_fixed_string_t value;
2257 };
2258
2259 static void
2260 cmd_config_rss_parsed(void *parsed_result,
2261                         __rte_unused struct cmdline *cl,
2262                         __rte_unused void *data)
2263 {
2264         struct cmd_config_rss *res = parsed_result;
2265         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2266         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2267         int use_default = 0;
2268         int all_updated = 1;
2269         int diag;
2270         uint16_t i;
2271         int ret;
2272
2273         if (!strcmp(res->value, "all"))
2274                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2275                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2276                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2277                         ETH_RSS_AH | ETH_RSS_PFCP;
2278         else if (!strcmp(res->value, "eth"))
2279                 rss_conf.rss_hf = ETH_RSS_ETH;
2280         else if (!strcmp(res->value, "vlan"))
2281                 rss_conf.rss_hf = ETH_RSS_VLAN;
2282         else if (!strcmp(res->value, "ip"))
2283                 rss_conf.rss_hf = ETH_RSS_IP;
2284         else if (!strcmp(res->value, "udp"))
2285                 rss_conf.rss_hf = ETH_RSS_UDP;
2286         else if (!strcmp(res->value, "tcp"))
2287                 rss_conf.rss_hf = ETH_RSS_TCP;
2288         else if (!strcmp(res->value, "sctp"))
2289                 rss_conf.rss_hf = ETH_RSS_SCTP;
2290         else if (!strcmp(res->value, "ether"))
2291                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2292         else if (!strcmp(res->value, "port"))
2293                 rss_conf.rss_hf = ETH_RSS_PORT;
2294         else if (!strcmp(res->value, "vxlan"))
2295                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2296         else if (!strcmp(res->value, "geneve"))
2297                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2298         else if (!strcmp(res->value, "nvgre"))
2299                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2300         else if (!strcmp(res->value, "l3-src-only"))
2301                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2302         else if (!strcmp(res->value, "l3-dst-only"))
2303                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2304         else if (!strcmp(res->value, "l4-src-only"))
2305                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2306         else if (!strcmp(res->value, "l4-dst-only"))
2307                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2308         else if (!strcmp(res->value, "l2-src-only"))
2309                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2310         else if (!strcmp(res->value, "l2-dst-only"))
2311                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2312         else if (!strcmp(res->value, "l2tpv3"))
2313                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2314         else if (!strcmp(res->value, "esp"))
2315                 rss_conf.rss_hf = ETH_RSS_ESP;
2316         else if (!strcmp(res->value, "ah"))
2317                 rss_conf.rss_hf = ETH_RSS_AH;
2318         else if (!strcmp(res->value, "pfcp"))
2319                 rss_conf.rss_hf = ETH_RSS_PFCP;
2320         else if (!strcmp(res->value, "none"))
2321                 rss_conf.rss_hf = 0;
2322         else if (!strcmp(res->value, "default"))
2323                 use_default = 1;
2324         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2325                                                 atoi(res->value) < 64)
2326                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2327         else {
2328                 printf("Unknown parameter\n");
2329                 return;
2330         }
2331         rss_conf.rss_key = NULL;
2332         /* Update global configuration for RSS types. */
2333         RTE_ETH_FOREACH_DEV(i) {
2334                 struct rte_eth_rss_conf local_rss_conf;
2335
2336                 ret = eth_dev_info_get_print_err(i, &dev_info);
2337                 if (ret != 0)
2338                         return;
2339
2340                 if (use_default)
2341                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2342
2343                 local_rss_conf = rss_conf;
2344                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2345                         dev_info.flow_type_rss_offloads;
2346                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2347                         printf("Port %u modified RSS hash function based on hardware support,"
2348                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2349                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2350                 }
2351                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2352                 if (diag < 0) {
2353                         all_updated = 0;
2354                         printf("Configuration of RSS hash at ethernet port %d "
2355                                 "failed with error (%d): %s.\n",
2356                                 i, -diag, strerror(-diag));
2357                 }
2358         }
2359         if (all_updated && !use_default) {
2360                 rss_hf = rss_conf.rss_hf;
2361                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2362         }
2363 }
2364
2365 cmdline_parse_token_string_t cmd_config_rss_port =
2366         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2367 cmdline_parse_token_string_t cmd_config_rss_keyword =
2368         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2369 cmdline_parse_token_string_t cmd_config_rss_all =
2370         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2371 cmdline_parse_token_string_t cmd_config_rss_name =
2372         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2373 cmdline_parse_token_string_t cmd_config_rss_value =
2374         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2375
2376 cmdline_parse_inst_t cmd_config_rss = {
2377         .f = cmd_config_rss_parsed,
2378         .data = NULL,
2379         .help_str = "port config all rss "
2380                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2381                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|<flowtype_id>",
2382         .tokens = {
2383                 (void *)&cmd_config_rss_port,
2384                 (void *)&cmd_config_rss_keyword,
2385                 (void *)&cmd_config_rss_all,
2386                 (void *)&cmd_config_rss_name,
2387                 (void *)&cmd_config_rss_value,
2388                 NULL,
2389         },
2390 };
2391
2392 /* *** configure rss hash key *** */
2393 struct cmd_config_rss_hash_key {
2394         cmdline_fixed_string_t port;
2395         cmdline_fixed_string_t config;
2396         portid_t port_id;
2397         cmdline_fixed_string_t rss_hash_key;
2398         cmdline_fixed_string_t rss_type;
2399         cmdline_fixed_string_t key;
2400 };
2401
2402 static uint8_t
2403 hexa_digit_to_value(char hexa_digit)
2404 {
2405         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2406                 return (uint8_t) (hexa_digit - '0');
2407         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2408                 return (uint8_t) ((hexa_digit - 'a') + 10);
2409         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2410                 return (uint8_t) ((hexa_digit - 'A') + 10);
2411         /* Invalid hexa digit */
2412         return 0xFF;
2413 }
2414
2415 static uint8_t
2416 parse_and_check_key_hexa_digit(char *key, int idx)
2417 {
2418         uint8_t hexa_v;
2419
2420         hexa_v = hexa_digit_to_value(key[idx]);
2421         if (hexa_v == 0xFF)
2422                 printf("invalid key: character %c at position %d is not a "
2423                        "valid hexa digit\n", key[idx], idx);
2424         return hexa_v;
2425 }
2426
2427 static void
2428 cmd_config_rss_hash_key_parsed(void *parsed_result,
2429                                __rte_unused struct cmdline *cl,
2430                                __rte_unused void *data)
2431 {
2432         struct cmd_config_rss_hash_key *res = parsed_result;
2433         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2434         uint8_t xdgt0;
2435         uint8_t xdgt1;
2436         int i;
2437         struct rte_eth_dev_info dev_info;
2438         uint8_t hash_key_size;
2439         uint32_t key_len;
2440         int ret;
2441
2442         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2443         if (ret != 0)
2444                 return;
2445
2446         if (dev_info.hash_key_size > 0 &&
2447                         dev_info.hash_key_size <= sizeof(hash_key))
2448                 hash_key_size = dev_info.hash_key_size;
2449         else {
2450                 printf("dev_info did not provide a valid hash key size\n");
2451                 return;
2452         }
2453         /* Check the length of the RSS hash key */
2454         key_len = strlen(res->key);
2455         if (key_len != (hash_key_size * 2)) {
2456                 printf("key length: %d invalid - key must be a string of %d"
2457                            " hexa-decimal numbers\n",
2458                            (int) key_len, hash_key_size * 2);
2459                 return;
2460         }
2461         /* Translate RSS hash key into binary representation */
2462         for (i = 0; i < hash_key_size; i++) {
2463                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2464                 if (xdgt0 == 0xFF)
2465                         return;
2466                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2467                 if (xdgt1 == 0xFF)
2468                         return;
2469                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2470         }
2471         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2472                         hash_key_size);
2473 }
2474
2475 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2476         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2477 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2478         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2479                                  "config");
2480 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2481         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2482 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2483         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2484                                  rss_hash_key, "rss-hash-key");
2485 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2486         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2487                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2488                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2489                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2490                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2491                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2492                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2493                                  "l2tpv3#esp#ah#pfcp");
2494 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2495         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2496
2497 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2498         .f = cmd_config_rss_hash_key_parsed,
2499         .data = NULL,
2500         .help_str = "port config <port_id> rss-hash-key "
2501                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2502                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2503                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2504                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2505                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2506                 "l2tpv3|esp|ah|pfcp "
2507                 "<string of hex digits (variable length, NIC dependent)>",
2508         .tokens = {
2509                 (void *)&cmd_config_rss_hash_key_port,
2510                 (void *)&cmd_config_rss_hash_key_config,
2511                 (void *)&cmd_config_rss_hash_key_port_id,
2512                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2513                 (void *)&cmd_config_rss_hash_key_rss_type,
2514                 (void *)&cmd_config_rss_hash_key_value,
2515                 NULL,
2516         },
2517 };
2518
2519 /* *** configure port rxq/txq ring size *** */
2520 struct cmd_config_rxtx_ring_size {
2521         cmdline_fixed_string_t port;
2522         cmdline_fixed_string_t config;
2523         portid_t portid;
2524         cmdline_fixed_string_t rxtxq;
2525         uint16_t qid;
2526         cmdline_fixed_string_t rsize;
2527         uint16_t size;
2528 };
2529
2530 static void
2531 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2532                                  __rte_unused struct cmdline *cl,
2533                                  __rte_unused void *data)
2534 {
2535         struct cmd_config_rxtx_ring_size *res = parsed_result;
2536         struct rte_port *port;
2537         uint8_t isrx;
2538
2539         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2540                 return;
2541
2542         if (res->portid == (portid_t)RTE_PORT_ALL) {
2543                 printf("Invalid port id\n");
2544                 return;
2545         }
2546
2547         port = &ports[res->portid];
2548
2549         if (!strcmp(res->rxtxq, "rxq"))
2550                 isrx = 1;
2551         else if (!strcmp(res->rxtxq, "txq"))
2552                 isrx = 0;
2553         else {
2554                 printf("Unknown parameter\n");
2555                 return;
2556         }
2557
2558         if (isrx && rx_queue_id_is_invalid(res->qid))
2559                 return;
2560         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2561                 return;
2562
2563         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2564                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2565                        rx_free_thresh);
2566                 return;
2567         }
2568
2569         if (isrx)
2570                 port->nb_rx_desc[res->qid] = res->size;
2571         else
2572                 port->nb_tx_desc[res->qid] = res->size;
2573
2574         cmd_reconfig_device_queue(res->portid, 0, 1);
2575 }
2576
2577 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2578         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2579                                  port, "port");
2580 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2581         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2582                                  config, "config");
2583 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2584         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2585                                  portid, UINT16);
2586 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2587         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2588                                  rxtxq, "rxq#txq");
2589 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2590         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2591                               qid, UINT16);
2592 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2593         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2594                                  rsize, "ring_size");
2595 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2596         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2597                               size, UINT16);
2598
2599 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2600         .f = cmd_config_rxtx_ring_size_parsed,
2601         .data = NULL,
2602         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2603         .tokens = {
2604                 (void *)&cmd_config_rxtx_ring_size_port,
2605                 (void *)&cmd_config_rxtx_ring_size_config,
2606                 (void *)&cmd_config_rxtx_ring_size_portid,
2607                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2608                 (void *)&cmd_config_rxtx_ring_size_qid,
2609                 (void *)&cmd_config_rxtx_ring_size_rsize,
2610                 (void *)&cmd_config_rxtx_ring_size_size,
2611                 NULL,
2612         },
2613 };
2614
2615 /* *** configure port rxq/txq start/stop *** */
2616 struct cmd_config_rxtx_queue {
2617         cmdline_fixed_string_t port;
2618         portid_t portid;
2619         cmdline_fixed_string_t rxtxq;
2620         uint16_t qid;
2621         cmdline_fixed_string_t opname;
2622 };
2623
2624 static void
2625 cmd_config_rxtx_queue_parsed(void *parsed_result,
2626                         __rte_unused struct cmdline *cl,
2627                         __rte_unused void *data)
2628 {
2629         struct cmd_config_rxtx_queue *res = parsed_result;
2630         uint8_t isrx;
2631         uint8_t isstart;
2632         int ret = 0;
2633
2634         if (test_done == 0) {
2635                 printf("Please stop forwarding first\n");
2636                 return;
2637         }
2638
2639         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2640                 return;
2641
2642         if (port_is_started(res->portid) != 1) {
2643                 printf("Please start port %u first\n", res->portid);
2644                 return;
2645         }
2646
2647         if (!strcmp(res->rxtxq, "rxq"))
2648                 isrx = 1;
2649         else if (!strcmp(res->rxtxq, "txq"))
2650                 isrx = 0;
2651         else {
2652                 printf("Unknown parameter\n");
2653                 return;
2654         }
2655
2656         if (isrx && rx_queue_id_is_invalid(res->qid))
2657                 return;
2658         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2659                 return;
2660
2661         if (!strcmp(res->opname, "start"))
2662                 isstart = 1;
2663         else if (!strcmp(res->opname, "stop"))
2664                 isstart = 0;
2665         else {
2666                 printf("Unknown parameter\n");
2667                 return;
2668         }
2669
2670         if (isstart && isrx)
2671                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2672         else if (!isstart && isrx)
2673                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2674         else if (isstart && !isrx)
2675                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2676         else
2677                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2678
2679         if (ret == -ENOTSUP)
2680                 printf("Function not supported in PMD driver\n");
2681 }
2682
2683 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2684         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2685 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2686         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2687 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2688         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2689 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2690         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2691 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2692         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2693                                                 "start#stop");
2694
2695 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2696         .f = cmd_config_rxtx_queue_parsed,
2697         .data = NULL,
2698         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2699         .tokens = {
2700                 (void *)&cmd_config_rxtx_queue_port,
2701                 (void *)&cmd_config_rxtx_queue_portid,
2702                 (void *)&cmd_config_rxtx_queue_rxtxq,
2703                 (void *)&cmd_config_rxtx_queue_qid,
2704                 (void *)&cmd_config_rxtx_queue_opname,
2705                 NULL,
2706         },
2707 };
2708
2709 /* *** configure port rxq/txq deferred start on/off *** */
2710 struct cmd_config_deferred_start_rxtx_queue {
2711         cmdline_fixed_string_t port;
2712         portid_t port_id;
2713         cmdline_fixed_string_t rxtxq;
2714         uint16_t qid;
2715         cmdline_fixed_string_t opname;
2716         cmdline_fixed_string_t state;
2717 };
2718
2719 static void
2720 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2721                         __rte_unused struct cmdline *cl,
2722                         __rte_unused void *data)
2723 {
2724         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2725         struct rte_port *port;
2726         uint8_t isrx;
2727         uint8_t ison;
2728         uint8_t needreconfig = 0;
2729
2730         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2731                 return;
2732
2733         if (port_is_started(res->port_id) != 0) {
2734                 printf("Please stop port %u first\n", res->port_id);
2735                 return;
2736         }
2737
2738         port = &ports[res->port_id];
2739
2740         isrx = !strcmp(res->rxtxq, "rxq");
2741
2742         if (isrx && rx_queue_id_is_invalid(res->qid))
2743                 return;
2744         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2745                 return;
2746
2747         ison = !strcmp(res->state, "on");
2748
2749         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2750                 port->rx_conf[res->qid].rx_deferred_start = ison;
2751                 needreconfig = 1;
2752         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2753                 port->tx_conf[res->qid].tx_deferred_start = ison;
2754                 needreconfig = 1;
2755         }
2756
2757         if (needreconfig)
2758                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2759 }
2760
2761 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2762         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2763                                                 port, "port");
2764 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2765         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2766                                                 port_id, UINT16);
2767 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2768         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2769                                                 rxtxq, "rxq#txq");
2770 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2771         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2772                                                 qid, UINT16);
2773 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2774         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2775                                                 opname, "deferred_start");
2776 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2777         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2778                                                 state, "on#off");
2779
2780 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2781         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2782         .data = NULL,
2783         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2784         .tokens = {
2785                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2786                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2787                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2788                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2789                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2790                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2791                 NULL,
2792         },
2793 };
2794
2795 /* *** configure port rxq/txq setup *** */
2796 struct cmd_setup_rxtx_queue {
2797         cmdline_fixed_string_t port;
2798         portid_t portid;
2799         cmdline_fixed_string_t rxtxq;
2800         uint16_t qid;
2801         cmdline_fixed_string_t setup;
2802 };
2803
2804 /* Common CLI fields for queue setup */
2805 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2806         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2807 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2808         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2809 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2810         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2811 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2812         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2813 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2814         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2815
2816 static void
2817 cmd_setup_rxtx_queue_parsed(
2818         void *parsed_result,
2819         __rte_unused struct cmdline *cl,
2820         __rte_unused void *data)
2821 {
2822         struct cmd_setup_rxtx_queue *res = parsed_result;
2823         struct rte_port *port;
2824         struct rte_mempool *mp;
2825         unsigned int socket_id;
2826         uint8_t isrx = 0;
2827         int ret;
2828
2829         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2830                 return;
2831
2832         if (res->portid == (portid_t)RTE_PORT_ALL) {
2833                 printf("Invalid port id\n");
2834                 return;
2835         }
2836
2837         if (!strcmp(res->rxtxq, "rxq"))
2838                 isrx = 1;
2839         else if (!strcmp(res->rxtxq, "txq"))
2840                 isrx = 0;
2841         else {
2842                 printf("Unknown parameter\n");
2843                 return;
2844         }
2845
2846         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2847                 printf("Invalid rx queue\n");
2848                 return;
2849         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2850                 printf("Invalid tx queue\n");
2851                 return;
2852         }
2853
2854         port = &ports[res->portid];
2855         if (isrx) {
2856                 socket_id = rxring_numa[res->portid];
2857                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2858                         socket_id = port->socket_id;
2859
2860                 mp = mbuf_pool_find(socket_id);
2861                 if (mp == NULL) {
2862                         printf("Failed to setup RX queue: "
2863                                 "No mempool allocation"
2864                                 " on the socket %d\n",
2865                                 rxring_numa[res->portid]);
2866                         return;
2867                 }
2868                 ret = rte_eth_rx_queue_setup(res->portid,
2869                                              res->qid,
2870                                              port->nb_rx_desc[res->qid],
2871                                              socket_id,
2872                                              &port->rx_conf[res->qid],
2873                                              mp);
2874                 if (ret)
2875                         printf("Failed to setup RX queue\n");
2876         } else {
2877                 socket_id = txring_numa[res->portid];
2878                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2879                         socket_id = port->socket_id;
2880
2881                 ret = rte_eth_tx_queue_setup(res->portid,
2882                                              res->qid,
2883                                              port->nb_tx_desc[res->qid],
2884                                              socket_id,
2885                                              &port->tx_conf[res->qid]);
2886                 if (ret)
2887                         printf("Failed to setup TX queue\n");
2888         }
2889 }
2890
2891 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2892         .f = cmd_setup_rxtx_queue_parsed,
2893         .data = NULL,
2894         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2895         .tokens = {
2896                 (void *)&cmd_setup_rxtx_queue_port,
2897                 (void *)&cmd_setup_rxtx_queue_portid,
2898                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2899                 (void *)&cmd_setup_rxtx_queue_qid,
2900                 (void *)&cmd_setup_rxtx_queue_setup,
2901                 NULL,
2902         },
2903 };
2904
2905
2906 /* *** Configure RSS RETA *** */
2907 struct cmd_config_rss_reta {
2908         cmdline_fixed_string_t port;
2909         cmdline_fixed_string_t keyword;
2910         portid_t port_id;
2911         cmdline_fixed_string_t name;
2912         cmdline_fixed_string_t list_name;
2913         cmdline_fixed_string_t list_of_items;
2914 };
2915
2916 static int
2917 parse_reta_config(const char *str,
2918                   struct rte_eth_rss_reta_entry64 *reta_conf,
2919                   uint16_t nb_entries)
2920 {
2921         int i;
2922         unsigned size;
2923         uint16_t hash_index, idx, shift;
2924         uint16_t nb_queue;
2925         char s[256];
2926         const char *p, *p0 = str;
2927         char *end;
2928         enum fieldnames {
2929                 FLD_HASH_INDEX = 0,
2930                 FLD_QUEUE,
2931                 _NUM_FLD
2932         };
2933         unsigned long int_fld[_NUM_FLD];
2934         char *str_fld[_NUM_FLD];
2935
2936         while ((p = strchr(p0,'(')) != NULL) {
2937                 ++p;
2938                 if((p0 = strchr(p,')')) == NULL)
2939                         return -1;
2940
2941                 size = p0 - p;
2942                 if(size >= sizeof(s))
2943                         return -1;
2944
2945                 snprintf(s, sizeof(s), "%.*s", size, p);
2946                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2947                         return -1;
2948                 for (i = 0; i < _NUM_FLD; i++) {
2949                         errno = 0;
2950                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2951                         if (errno != 0 || end == str_fld[i] ||
2952                                         int_fld[i] > 65535)
2953                                 return -1;
2954                 }
2955
2956                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2957                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2958
2959                 if (hash_index >= nb_entries) {
2960                         printf("Invalid RETA hash index=%d\n", hash_index);
2961                         return -1;
2962                 }
2963
2964                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2965                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2966                 reta_conf[idx].mask |= (1ULL << shift);
2967                 reta_conf[idx].reta[shift] = nb_queue;
2968         }
2969
2970         return 0;
2971 }
2972
2973 static void
2974 cmd_set_rss_reta_parsed(void *parsed_result,
2975                         __rte_unused struct cmdline *cl,
2976                         __rte_unused void *data)
2977 {
2978         int ret;
2979         struct rte_eth_dev_info dev_info;
2980         struct rte_eth_rss_reta_entry64 reta_conf[8];
2981         struct cmd_config_rss_reta *res = parsed_result;
2982
2983         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2984         if (ret != 0)
2985                 return;
2986
2987         if (dev_info.reta_size == 0) {
2988                 printf("Redirection table size is 0 which is "
2989                                         "invalid for RSS\n");
2990                 return;
2991         } else
2992                 printf("The reta size of port %d is %u\n",
2993                         res->port_id, dev_info.reta_size);
2994         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2995                 printf("Currently do not support more than %u entries of "
2996                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2997                 return;
2998         }
2999
3000         memset(reta_conf, 0, sizeof(reta_conf));
3001         if (!strcmp(res->list_name, "reta")) {
3002                 if (parse_reta_config(res->list_of_items, reta_conf,
3003                                                 dev_info.reta_size)) {
3004                         printf("Invalid RSS Redirection Table "
3005                                         "config entered\n");
3006                         return;
3007                 }
3008                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3009                                 reta_conf, dev_info.reta_size);
3010                 if (ret != 0)
3011                         printf("Bad redirection table parameter, "
3012                                         "return code = %d \n", ret);
3013         }
3014 }
3015
3016 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3017         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3018 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3019         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3020 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3021         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3022 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3023         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3024 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3025         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3026 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3027         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3028                                  NULL);
3029 cmdline_parse_inst_t cmd_config_rss_reta = {
3030         .f = cmd_set_rss_reta_parsed,
3031         .data = NULL,
3032         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3033         .tokens = {
3034                 (void *)&cmd_config_rss_reta_port,
3035                 (void *)&cmd_config_rss_reta_keyword,
3036                 (void *)&cmd_config_rss_reta_port_id,
3037                 (void *)&cmd_config_rss_reta_name,
3038                 (void *)&cmd_config_rss_reta_list_name,
3039                 (void *)&cmd_config_rss_reta_list_of_items,
3040                 NULL,
3041         },
3042 };
3043
3044 /* *** SHOW PORT RETA INFO *** */
3045 struct cmd_showport_reta {
3046         cmdline_fixed_string_t show;
3047         cmdline_fixed_string_t port;
3048         portid_t port_id;
3049         cmdline_fixed_string_t rss;
3050         cmdline_fixed_string_t reta;
3051         uint16_t size;
3052         cmdline_fixed_string_t list_of_items;
3053 };
3054
3055 static int
3056 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3057                            uint16_t nb_entries,
3058                            char *str)
3059 {
3060         uint32_t size;
3061         const char *p, *p0 = str;
3062         char s[256];
3063         char *end;
3064         char *str_fld[8];
3065         uint16_t i;
3066         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3067                         RTE_RETA_GROUP_SIZE;
3068         int ret;
3069
3070         p = strchr(p0, '(');
3071         if (p == NULL)
3072                 return -1;
3073         p++;
3074         p0 = strchr(p, ')');
3075         if (p0 == NULL)
3076                 return -1;
3077         size = p0 - p;
3078         if (size >= sizeof(s)) {
3079                 printf("The string size exceeds the internal buffer size\n");
3080                 return -1;
3081         }
3082         snprintf(s, sizeof(s), "%.*s", size, p);
3083         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3084         if (ret <= 0 || ret != num) {
3085                 printf("The bits of masks do not match the number of "
3086                                         "reta entries: %u\n", num);
3087                 return -1;
3088         }
3089         for (i = 0; i < ret; i++)
3090                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3091
3092         return 0;
3093 }
3094
3095 static void
3096 cmd_showport_reta_parsed(void *parsed_result,
3097                          __rte_unused struct cmdline *cl,
3098                          __rte_unused void *data)
3099 {
3100         struct cmd_showport_reta *res = parsed_result;
3101         struct rte_eth_rss_reta_entry64 reta_conf[8];
3102         struct rte_eth_dev_info dev_info;
3103         uint16_t max_reta_size;
3104         int ret;
3105
3106         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3107         if (ret != 0)
3108                 return;
3109
3110         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3111         if (res->size == 0 || res->size > max_reta_size) {
3112                 printf("Invalid redirection table size: %u (1-%u)\n",
3113                         res->size, max_reta_size);
3114                 return;
3115         }
3116
3117         memset(reta_conf, 0, sizeof(reta_conf));
3118         if (showport_parse_reta_config(reta_conf, res->size,
3119                                 res->list_of_items) < 0) {
3120                 printf("Invalid string: %s for reta masks\n",
3121                                         res->list_of_items);
3122                 return;
3123         }
3124         port_rss_reta_info(res->port_id, reta_conf, res->size);
3125 }
3126
3127 cmdline_parse_token_string_t cmd_showport_reta_show =
3128         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3129 cmdline_parse_token_string_t cmd_showport_reta_port =
3130         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3131 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3132         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3133 cmdline_parse_token_string_t cmd_showport_reta_rss =
3134         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3135 cmdline_parse_token_string_t cmd_showport_reta_reta =
3136         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3137 cmdline_parse_token_num_t cmd_showport_reta_size =
3138         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3139 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3140         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3141                                         list_of_items, NULL);
3142
3143 cmdline_parse_inst_t cmd_showport_reta = {
3144         .f = cmd_showport_reta_parsed,
3145         .data = NULL,
3146         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3147         .tokens = {
3148                 (void *)&cmd_showport_reta_show,
3149                 (void *)&cmd_showport_reta_port,
3150                 (void *)&cmd_showport_reta_port_id,
3151                 (void *)&cmd_showport_reta_rss,
3152                 (void *)&cmd_showport_reta_reta,
3153                 (void *)&cmd_showport_reta_size,
3154                 (void *)&cmd_showport_reta_list_of_items,
3155                 NULL,
3156         },
3157 };
3158
3159 /* *** Show RSS hash configuration *** */
3160 struct cmd_showport_rss_hash {
3161         cmdline_fixed_string_t show;
3162         cmdline_fixed_string_t port;
3163         portid_t port_id;
3164         cmdline_fixed_string_t rss_hash;
3165         cmdline_fixed_string_t rss_type;
3166         cmdline_fixed_string_t key; /* optional argument */
3167 };
3168
3169 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3170                                 __rte_unused struct cmdline *cl,
3171                                 void *show_rss_key)
3172 {
3173         struct cmd_showport_rss_hash *res = parsed_result;
3174
3175         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3176 }
3177
3178 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3179         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3180 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3181         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3182 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3183         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3184 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3185         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3186                                  "rss-hash");
3187 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3188         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3189
3190 cmdline_parse_inst_t cmd_showport_rss_hash = {
3191         .f = cmd_showport_rss_hash_parsed,
3192         .data = NULL,
3193         .help_str = "show port <port_id> rss-hash",
3194         .tokens = {
3195                 (void *)&cmd_showport_rss_hash_show,
3196                 (void *)&cmd_showport_rss_hash_port,
3197                 (void *)&cmd_showport_rss_hash_port_id,
3198                 (void *)&cmd_showport_rss_hash_rss_hash,
3199                 NULL,
3200         },
3201 };
3202
3203 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3204         .f = cmd_showport_rss_hash_parsed,
3205         .data = (void *)1,
3206         .help_str = "show port <port_id> rss-hash key",
3207         .tokens = {
3208                 (void *)&cmd_showport_rss_hash_show,
3209                 (void *)&cmd_showport_rss_hash_port,
3210                 (void *)&cmd_showport_rss_hash_port_id,
3211                 (void *)&cmd_showport_rss_hash_rss_hash,
3212                 (void *)&cmd_showport_rss_hash_rss_key,
3213                 NULL,
3214         },
3215 };
3216
3217 /* *** Configure DCB *** */
3218 struct cmd_config_dcb {
3219         cmdline_fixed_string_t port;
3220         cmdline_fixed_string_t config;
3221         portid_t port_id;
3222         cmdline_fixed_string_t dcb;
3223         cmdline_fixed_string_t vt;
3224         cmdline_fixed_string_t vt_en;
3225         uint8_t num_tcs;
3226         cmdline_fixed_string_t pfc;
3227         cmdline_fixed_string_t pfc_en;
3228 };
3229
3230 static void
3231 cmd_config_dcb_parsed(void *parsed_result,
3232                         __rte_unused struct cmdline *cl,
3233                         __rte_unused void *data)
3234 {
3235         struct cmd_config_dcb *res = parsed_result;
3236         portid_t port_id = res->port_id;
3237         struct rte_port *port;
3238         uint8_t pfc_en;
3239         int ret;
3240
3241         port = &ports[port_id];
3242         /** Check if the port is not started **/
3243         if (port->port_status != RTE_PORT_STOPPED) {
3244                 printf("Please stop port %d first\n", port_id);
3245                 return;
3246         }
3247
3248         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3249                 printf("The invalid number of traffic class,"
3250                         " only 4 or 8 allowed.\n");
3251                 return;
3252         }
3253
3254         if (nb_fwd_lcores < res->num_tcs) {
3255                 printf("nb_cores shouldn't be less than number of TCs.\n");
3256                 return;
3257         }
3258         if (!strncmp(res->pfc_en, "on", 2))
3259                 pfc_en = 1;
3260         else
3261                 pfc_en = 0;
3262
3263         /* DCB in VT mode */
3264         if (!strncmp(res->vt_en, "on", 2))
3265                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3266                                 (enum rte_eth_nb_tcs)res->num_tcs,
3267                                 pfc_en);
3268         else
3269                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3270                                 (enum rte_eth_nb_tcs)res->num_tcs,
3271                                 pfc_en);
3272
3273
3274         if (ret != 0) {
3275                 printf("Cannot initialize network ports.\n");
3276                 return;
3277         }
3278
3279         cmd_reconfig_device_queue(port_id, 1, 1);
3280 }
3281
3282 cmdline_parse_token_string_t cmd_config_dcb_port =
3283         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3284 cmdline_parse_token_string_t cmd_config_dcb_config =
3285         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3286 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3287         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3288 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3289         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3290 cmdline_parse_token_string_t cmd_config_dcb_vt =
3291         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3292 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3293         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3294 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3295         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3296 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3297         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3298 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3299         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3300
3301 cmdline_parse_inst_t cmd_config_dcb = {
3302         .f = cmd_config_dcb_parsed,
3303         .data = NULL,
3304         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3305         .tokens = {
3306                 (void *)&cmd_config_dcb_port,
3307                 (void *)&cmd_config_dcb_config,
3308                 (void *)&cmd_config_dcb_port_id,
3309                 (void *)&cmd_config_dcb_dcb,
3310                 (void *)&cmd_config_dcb_vt,
3311                 (void *)&cmd_config_dcb_vt_en,
3312                 (void *)&cmd_config_dcb_num_tcs,
3313                 (void *)&cmd_config_dcb_pfc,
3314                 (void *)&cmd_config_dcb_pfc_en,
3315                 NULL,
3316         },
3317 };
3318
3319 /* *** configure number of packets per burst *** */
3320 struct cmd_config_burst {
3321         cmdline_fixed_string_t port;
3322         cmdline_fixed_string_t keyword;
3323         cmdline_fixed_string_t all;
3324         cmdline_fixed_string_t name;
3325         uint16_t value;
3326 };
3327
3328 static void
3329 cmd_config_burst_parsed(void *parsed_result,
3330                         __rte_unused struct cmdline *cl,
3331                         __rte_unused void *data)
3332 {
3333         struct cmd_config_burst *res = parsed_result;
3334         struct rte_eth_dev_info dev_info;
3335         uint16_t rec_nb_pkts;
3336         int ret;
3337
3338         if (!all_ports_stopped()) {
3339                 printf("Please stop all ports first\n");
3340                 return;
3341         }
3342
3343         if (!strcmp(res->name, "burst")) {
3344                 if (res->value == 0) {
3345                         /* If user gives a value of zero, query the PMD for
3346                          * its recommended Rx burst size. Testpmd uses a single
3347                          * size for all ports, so assume all ports are the same
3348                          * NIC model and use the values from Port 0.
3349                          */
3350                         ret = eth_dev_info_get_print_err(0, &dev_info);
3351                         if (ret != 0)
3352                                 return;
3353
3354                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3355
3356                         if (rec_nb_pkts == 0) {
3357                                 printf("PMD does not recommend a burst size.\n"
3358                                         "User provided value must be between"
3359                                         " 1 and %d\n", MAX_PKT_BURST);
3360                                 return;
3361                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3362                                 printf("PMD recommended burst size of %d"
3363                                         " exceeds maximum value of %d\n",
3364                                         rec_nb_pkts, MAX_PKT_BURST);
3365                                 return;
3366                         }
3367                         printf("Using PMD-provided burst value of %d\n",
3368                                 rec_nb_pkts);
3369                         nb_pkt_per_burst = rec_nb_pkts;
3370                 } else if (res->value > MAX_PKT_BURST) {
3371                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3372                         return;
3373                 } else
3374                         nb_pkt_per_burst = res->value;
3375         } else {
3376                 printf("Unknown parameter\n");
3377                 return;
3378         }
3379
3380         init_port_config();
3381
3382         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3383 }
3384
3385 cmdline_parse_token_string_t cmd_config_burst_port =
3386         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3387 cmdline_parse_token_string_t cmd_config_burst_keyword =
3388         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3389 cmdline_parse_token_string_t cmd_config_burst_all =
3390         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3391 cmdline_parse_token_string_t cmd_config_burst_name =
3392         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3393 cmdline_parse_token_num_t cmd_config_burst_value =
3394         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3395
3396 cmdline_parse_inst_t cmd_config_burst = {
3397         .f = cmd_config_burst_parsed,
3398         .data = NULL,
3399         .help_str = "port config all burst <value>",
3400         .tokens = {
3401                 (void *)&cmd_config_burst_port,
3402                 (void *)&cmd_config_burst_keyword,
3403                 (void *)&cmd_config_burst_all,
3404                 (void *)&cmd_config_burst_name,
3405                 (void *)&cmd_config_burst_value,
3406                 NULL,
3407         },
3408 };
3409
3410 /* *** configure rx/tx queues *** */
3411 struct cmd_config_thresh {
3412         cmdline_fixed_string_t port;
3413         cmdline_fixed_string_t keyword;
3414         cmdline_fixed_string_t all;
3415         cmdline_fixed_string_t name;
3416         uint8_t value;
3417 };
3418
3419 static void
3420 cmd_config_thresh_parsed(void *parsed_result,
3421                         __rte_unused struct cmdline *cl,
3422                         __rte_unused void *data)
3423 {
3424         struct cmd_config_thresh *res = parsed_result;
3425
3426         if (!all_ports_stopped()) {
3427                 printf("Please stop all ports first\n");
3428                 return;
3429         }
3430
3431         if (!strcmp(res->name, "txpt"))
3432                 tx_pthresh = res->value;
3433         else if(!strcmp(res->name, "txht"))
3434                 tx_hthresh = res->value;
3435         else if(!strcmp(res->name, "txwt"))
3436                 tx_wthresh = res->value;
3437         else if(!strcmp(res->name, "rxpt"))
3438                 rx_pthresh = res->value;
3439         else if(!strcmp(res->name, "rxht"))
3440                 rx_hthresh = res->value;
3441         else if(!strcmp(res->name, "rxwt"))
3442                 rx_wthresh = res->value;
3443         else {
3444                 printf("Unknown parameter\n");
3445                 return;
3446         }
3447
3448         init_port_config();
3449
3450         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3451 }
3452
3453 cmdline_parse_token_string_t cmd_config_thresh_port =
3454         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3455 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3456         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3457 cmdline_parse_token_string_t cmd_config_thresh_all =
3458         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3459 cmdline_parse_token_string_t cmd_config_thresh_name =
3460         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3461                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3462 cmdline_parse_token_num_t cmd_config_thresh_value =
3463         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3464
3465 cmdline_parse_inst_t cmd_config_thresh = {
3466         .f = cmd_config_thresh_parsed,
3467         .data = NULL,
3468         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3469         .tokens = {
3470                 (void *)&cmd_config_thresh_port,
3471                 (void *)&cmd_config_thresh_keyword,
3472                 (void *)&cmd_config_thresh_all,
3473                 (void *)&cmd_config_thresh_name,
3474                 (void *)&cmd_config_thresh_value,
3475                 NULL,
3476         },
3477 };
3478
3479 /* *** configure free/rs threshold *** */
3480 struct cmd_config_threshold {
3481         cmdline_fixed_string_t port;
3482         cmdline_fixed_string_t keyword;
3483         cmdline_fixed_string_t all;
3484         cmdline_fixed_string_t name;
3485         uint16_t value;
3486 };
3487
3488 static void
3489 cmd_config_threshold_parsed(void *parsed_result,
3490                         __rte_unused struct cmdline *cl,
3491                         __rte_unused void *data)
3492 {
3493         struct cmd_config_threshold *res = parsed_result;
3494
3495         if (!all_ports_stopped()) {
3496                 printf("Please stop all ports first\n");
3497                 return;
3498         }
3499
3500         if (!strcmp(res->name, "txfreet"))
3501                 tx_free_thresh = res->value;
3502         else if (!strcmp(res->name, "txrst"))
3503                 tx_rs_thresh = res->value;
3504         else if (!strcmp(res->name, "rxfreet"))
3505                 rx_free_thresh = res->value;
3506         else {
3507                 printf("Unknown parameter\n");
3508                 return;
3509         }
3510
3511         init_port_config();
3512
3513         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3514 }
3515
3516 cmdline_parse_token_string_t cmd_config_threshold_port =
3517         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3518 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3519         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3520                                                                 "config");
3521 cmdline_parse_token_string_t cmd_config_threshold_all =
3522         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3523 cmdline_parse_token_string_t cmd_config_threshold_name =
3524         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3525                                                 "txfreet#txrst#rxfreet");
3526 cmdline_parse_token_num_t cmd_config_threshold_value =
3527         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3528
3529 cmdline_parse_inst_t cmd_config_threshold = {
3530         .f = cmd_config_threshold_parsed,
3531         .data = NULL,
3532         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3533         .tokens = {
3534                 (void *)&cmd_config_threshold_port,
3535                 (void *)&cmd_config_threshold_keyword,
3536                 (void *)&cmd_config_threshold_all,
3537                 (void *)&cmd_config_threshold_name,
3538                 (void *)&cmd_config_threshold_value,
3539                 NULL,
3540         },
3541 };
3542
3543 /* *** stop *** */
3544 struct cmd_stop_result {
3545         cmdline_fixed_string_t stop;
3546 };
3547
3548 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3549                             __rte_unused struct cmdline *cl,
3550                             __rte_unused void *data)
3551 {
3552         stop_packet_forwarding();
3553 }
3554
3555 cmdline_parse_token_string_t cmd_stop_stop =
3556         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3557
3558 cmdline_parse_inst_t cmd_stop = {
3559         .f = cmd_stop_parsed,
3560         .data = NULL,
3561         .help_str = "stop: Stop packet forwarding",
3562         .tokens = {
3563                 (void *)&cmd_stop_stop,
3564                 NULL,
3565         },
3566 };
3567
3568 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3569
3570 unsigned int
3571 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3572                 unsigned int *parsed_items, int check_unique_values)
3573 {
3574         unsigned int nb_item;
3575         unsigned int value;
3576         unsigned int i;
3577         unsigned int j;
3578         int value_ok;
3579         char c;
3580
3581         /*
3582          * First parse all items in the list and store their value.
3583          */
3584         value = 0;
3585         nb_item = 0;
3586         value_ok = 0;
3587         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3588                 c = str[i];
3589                 if ((c >= '0') && (c <= '9')) {
3590                         value = (unsigned int) (value * 10 + (c - '0'));
3591                         value_ok = 1;
3592                         continue;
3593                 }
3594                 if (c != ',') {
3595                         printf("character %c is not a decimal digit\n", c);
3596                         return 0;
3597                 }
3598                 if (! value_ok) {
3599                         printf("No valid value before comma\n");
3600                         return 0;
3601                 }
3602                 if (nb_item < max_items) {
3603                         parsed_items[nb_item] = value;
3604                         value_ok = 0;
3605                         value = 0;
3606                 }
3607                 nb_item++;
3608         }
3609         if (nb_item >= max_items) {
3610                 printf("Number of %s = %u > %u (maximum items)\n",
3611                        item_name, nb_item + 1, max_items);
3612                 return 0;
3613         }
3614         parsed_items[nb_item++] = value;
3615         if (! check_unique_values)
3616                 return nb_item;
3617
3618         /*
3619          * Then, check that all values in the list are differents.
3620          * No optimization here...
3621          */
3622         for (i = 0; i < nb_item; i++) {
3623                 for (j = i + 1; j < nb_item; j++) {
3624                         if (parsed_items[j] == parsed_items[i]) {
3625                                 printf("duplicated %s %u at index %u and %u\n",
3626                                        item_name, parsed_items[i], i, j);
3627                                 return 0;
3628                         }
3629                 }
3630         }
3631         return nb_item;
3632 }
3633
3634 struct cmd_set_list_result {
3635         cmdline_fixed_string_t cmd_keyword;
3636         cmdline_fixed_string_t list_name;
3637         cmdline_fixed_string_t list_of_items;
3638 };
3639
3640 static void cmd_set_list_parsed(void *parsed_result,
3641                                 __rte_unused struct cmdline *cl,
3642                                 __rte_unused void *data)
3643 {
3644         struct cmd_set_list_result *res;
3645         union {
3646                 unsigned int lcorelist[RTE_MAX_LCORE];
3647                 unsigned int portlist[RTE_MAX_ETHPORTS];
3648         } parsed_items;
3649         unsigned int nb_item;
3650
3651         if (test_done == 0) {
3652                 printf("Please stop forwarding first\n");
3653                 return;
3654         }
3655
3656         res = parsed_result;
3657         if (!strcmp(res->list_name, "corelist")) {
3658                 nb_item = parse_item_list(res->list_of_items, "core",
3659                                           RTE_MAX_LCORE,
3660                                           parsed_items.lcorelist, 1);
3661                 if (nb_item > 0) {
3662                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3663                         fwd_config_setup();
3664                 }
3665                 return;
3666         }
3667         if (!strcmp(res->list_name, "portlist")) {
3668                 nb_item = parse_item_list(res->list_of_items, "port",
3669                                           RTE_MAX_ETHPORTS,
3670                                           parsed_items.portlist, 1);
3671                 if (nb_item > 0) {
3672                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3673                         fwd_config_setup();
3674                 }
3675         }
3676 }
3677
3678 cmdline_parse_token_string_t cmd_set_list_keyword =
3679         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3680                                  "set");
3681 cmdline_parse_token_string_t cmd_set_list_name =
3682         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3683                                  "corelist#portlist");
3684 cmdline_parse_token_string_t cmd_set_list_of_items =
3685         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3686                                  NULL);
3687
3688 cmdline_parse_inst_t cmd_set_fwd_list = {
3689         .f = cmd_set_list_parsed,
3690         .data = NULL,
3691         .help_str = "set corelist|portlist <list0[,list1]*>",
3692         .tokens = {
3693                 (void *)&cmd_set_list_keyword,
3694                 (void *)&cmd_set_list_name,
3695                 (void *)&cmd_set_list_of_items,
3696                 NULL,
3697         },
3698 };
3699
3700 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3701
3702 struct cmd_setmask_result {
3703         cmdline_fixed_string_t set;
3704         cmdline_fixed_string_t mask;
3705         uint64_t hexavalue;
3706 };
3707
3708 static void cmd_set_mask_parsed(void *parsed_result,
3709                                 __rte_unused struct cmdline *cl,
3710                                 __rte_unused void *data)
3711 {
3712         struct cmd_setmask_result *res = parsed_result;
3713
3714         if (test_done == 0) {
3715                 printf("Please stop forwarding first\n");
3716                 return;
3717         }
3718         if (!strcmp(res->mask, "coremask")) {
3719                 set_fwd_lcores_mask(res->hexavalue);
3720                 fwd_config_setup();
3721         } else if (!strcmp(res->mask, "portmask")) {
3722                 set_fwd_ports_mask(res->hexavalue);
3723                 fwd_config_setup();
3724         }
3725 }
3726
3727 cmdline_parse_token_string_t cmd_setmask_set =
3728         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3729 cmdline_parse_token_string_t cmd_setmask_mask =
3730         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3731                                  "coremask#portmask");
3732 cmdline_parse_token_num_t cmd_setmask_value =
3733         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3734
3735 cmdline_parse_inst_t cmd_set_fwd_mask = {
3736         .f = cmd_set_mask_parsed,
3737         .data = NULL,
3738         .help_str = "set coremask|portmask <hexadecimal value>",
3739         .tokens = {
3740                 (void *)&cmd_setmask_set,
3741                 (void *)&cmd_setmask_mask,
3742                 (void *)&cmd_setmask_value,
3743                 NULL,
3744         },
3745 };
3746
3747 /*
3748  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3749  */
3750 struct cmd_set_result {
3751         cmdline_fixed_string_t set;
3752         cmdline_fixed_string_t what;
3753         uint16_t value;
3754 };
3755
3756 static void cmd_set_parsed(void *parsed_result,
3757                            __rte_unused struct cmdline *cl,
3758                            __rte_unused void *data)
3759 {
3760         struct cmd_set_result *res = parsed_result;
3761         if (!strcmp(res->what, "nbport")) {
3762                 set_fwd_ports_number(res->value);
3763                 fwd_config_setup();
3764         } else if (!strcmp(res->what, "nbcore")) {
3765                 set_fwd_lcores_number(res->value);
3766                 fwd_config_setup();
3767         } else if (!strcmp(res->what, "burst"))
3768                 set_nb_pkt_per_burst(res->value);
3769         else if (!strcmp(res->what, "verbose"))
3770                 set_verbose_level(res->value);
3771 }
3772
3773 cmdline_parse_token_string_t cmd_set_set =
3774         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3775 cmdline_parse_token_string_t cmd_set_what =
3776         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3777                                  "nbport#nbcore#burst#verbose");
3778 cmdline_parse_token_num_t cmd_set_value =
3779         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3780
3781 cmdline_parse_inst_t cmd_set_numbers = {
3782         .f = cmd_set_parsed,
3783         .data = NULL,
3784         .help_str = "set nbport|nbcore|burst|verbose <value>",
3785         .tokens = {
3786                 (void *)&cmd_set_set,
3787                 (void *)&cmd_set_what,
3788                 (void *)&cmd_set_value,
3789                 NULL,
3790         },
3791 };
3792
3793 /* *** SET LOG LEVEL CONFIGURATION *** */
3794
3795 struct cmd_set_log_result {
3796         cmdline_fixed_string_t set;
3797         cmdline_fixed_string_t log;
3798         cmdline_fixed_string_t type;
3799         uint32_t level;
3800 };
3801
3802 static void
3803 cmd_set_log_parsed(void *parsed_result,
3804                    __rte_unused struct cmdline *cl,
3805                    __rte_unused void *data)
3806 {
3807         struct cmd_set_log_result *res;
3808         int ret;
3809
3810         res = parsed_result;
3811         if (!strcmp(res->type, "global"))
3812                 rte_log_set_global_level(res->level);
3813         else {
3814                 ret = rte_log_set_level_regexp(res->type, res->level);
3815                 if (ret < 0)
3816                         printf("Unable to set log level\n");
3817         }
3818 }
3819
3820 cmdline_parse_token_string_t cmd_set_log_set =
3821         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3822 cmdline_parse_token_string_t cmd_set_log_log =
3823         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3824 cmdline_parse_token_string_t cmd_set_log_type =
3825         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3826 cmdline_parse_token_num_t cmd_set_log_level =
3827         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3828
3829 cmdline_parse_inst_t cmd_set_log = {
3830         .f = cmd_set_log_parsed,
3831         .data = NULL,
3832         .help_str = "set log global|<type> <level>",
3833         .tokens = {
3834                 (void *)&cmd_set_log_set,
3835                 (void *)&cmd_set_log_log,
3836                 (void *)&cmd_set_log_type,
3837                 (void *)&cmd_set_log_level,
3838                 NULL,
3839         },
3840 };
3841
3842 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3843
3844 struct cmd_set_txpkts_result {
3845         cmdline_fixed_string_t cmd_keyword;
3846         cmdline_fixed_string_t txpkts;
3847         cmdline_fixed_string_t seg_lengths;
3848 };
3849
3850 static void
3851 cmd_set_txpkts_parsed(void *parsed_result,
3852                       __rte_unused struct cmdline *cl,
3853                       __rte_unused void *data)
3854 {
3855         struct cmd_set_txpkts_result *res;
3856         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3857         unsigned int nb_segs;
3858
3859         res = parsed_result;
3860         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3861                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3862         if (nb_segs > 0)
3863                 set_tx_pkt_segments(seg_lengths, nb_segs);
3864 }
3865
3866 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3867         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3868                                  cmd_keyword, "set");
3869 cmdline_parse_token_string_t cmd_set_txpkts_name =
3870         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3871                                  txpkts, "txpkts");
3872 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3873         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3874                                  seg_lengths, NULL);
3875
3876 cmdline_parse_inst_t cmd_set_txpkts = {
3877         .f = cmd_set_txpkts_parsed,
3878         .data = NULL,
3879         .help_str = "set txpkts <len0[,len1]*>",
3880         .tokens = {
3881                 (void *)&cmd_set_txpkts_keyword,
3882                 (void *)&cmd_set_txpkts_name,
3883                 (void *)&cmd_set_txpkts_lengths,
3884                 NULL,
3885         },
3886 };
3887
3888 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3889
3890 struct cmd_set_txsplit_result {
3891         cmdline_fixed_string_t cmd_keyword;
3892         cmdline_fixed_string_t txsplit;
3893         cmdline_fixed_string_t mode;
3894 };
3895
3896 static void
3897 cmd_set_txsplit_parsed(void *parsed_result,
3898                       __rte_unused struct cmdline *cl,
3899                       __rte_unused void *data)
3900 {
3901         struct cmd_set_txsplit_result *res;
3902
3903         res = parsed_result;
3904         set_tx_pkt_split(res->mode);
3905 }
3906
3907 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3908         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3909                                  cmd_keyword, "set");
3910 cmdline_parse_token_string_t cmd_set_txsplit_name =
3911         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3912                                  txsplit, "txsplit");
3913 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3914         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3915                                  mode, NULL);
3916
3917 cmdline_parse_inst_t cmd_set_txsplit = {
3918         .f = cmd_set_txsplit_parsed,
3919         .data = NULL,
3920         .help_str = "set txsplit on|off|rand",
3921         .tokens = {
3922                 (void *)&cmd_set_txsplit_keyword,
3923                 (void *)&cmd_set_txsplit_name,
3924                 (void *)&cmd_set_txsplit_mode,
3925                 NULL,
3926         },
3927 };
3928
3929 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3930 struct cmd_rx_vlan_filter_all_result {
3931         cmdline_fixed_string_t rx_vlan;
3932         cmdline_fixed_string_t what;
3933         cmdline_fixed_string_t all;
3934         portid_t port_id;
3935 };
3936
3937 static void
3938 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3939                               __rte_unused struct cmdline *cl,
3940                               __rte_unused void *data)
3941 {
3942         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3943
3944         if (!strcmp(res->what, "add"))
3945                 rx_vlan_all_filter_set(res->port_id, 1);
3946         else
3947                 rx_vlan_all_filter_set(res->port_id, 0);
3948 }
3949
3950 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3951         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3952                                  rx_vlan, "rx_vlan");
3953 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3954         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3955                                  what, "add#rm");
3956 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3957         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3958                                  all, "all");
3959 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3960         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3961                               port_id, UINT16);
3962
3963 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3964         .f = cmd_rx_vlan_filter_all_parsed,
3965         .data = NULL,
3966         .help_str = "rx_vlan add|rm all <port_id>: "
3967                 "Add/Remove all identifiers to/from the set of VLAN "
3968                 "identifiers filtered by a port",
3969         .tokens = {
3970                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3971                 (void *)&cmd_rx_vlan_filter_all_what,
3972                 (void *)&cmd_rx_vlan_filter_all_all,
3973                 (void *)&cmd_rx_vlan_filter_all_portid,
3974                 NULL,
3975         },
3976 };
3977
3978 /* *** VLAN OFFLOAD SET ON A PORT *** */
3979 struct cmd_vlan_offload_result {
3980         cmdline_fixed_string_t vlan;
3981         cmdline_fixed_string_t set;
3982         cmdline_fixed_string_t vlan_type;
3983         cmdline_fixed_string_t what;
3984         cmdline_fixed_string_t on;
3985         cmdline_fixed_string_t port_id;
3986 };
3987
3988 static void
3989 cmd_vlan_offload_parsed(void *parsed_result,
3990                           __rte_unused struct cmdline *cl,
3991                           __rte_unused void *data)
3992 {
3993         int on;
3994         struct cmd_vlan_offload_result *res = parsed_result;
3995         char *str;
3996         int i, len = 0;
3997         portid_t port_id = 0;
3998         unsigned int tmp;
3999
4000         str = res->port_id;
4001         len = strnlen(str, STR_TOKEN_SIZE);
4002         i = 0;
4003         /* Get port_id first */
4004         while(i < len){
4005                 if(str[i] == ',')
4006                         break;
4007
4008                 i++;
4009         }
4010         str[i]='\0';
4011         tmp = strtoul(str, NULL, 0);
4012         /* If port_id greater that what portid_t can represent, return */
4013         if(tmp >= RTE_MAX_ETHPORTS)
4014                 return;
4015         port_id = (portid_t)tmp;
4016
4017         if (!strcmp(res->on, "on"))
4018                 on = 1;
4019         else
4020                 on = 0;
4021
4022         if (!strcmp(res->what, "strip"))
4023                 rx_vlan_strip_set(port_id,  on);
4024         else if(!strcmp(res->what, "stripq")){
4025                 uint16_t queue_id = 0;
4026
4027                 /* No queue_id, return */
4028                 if(i + 1 >= len) {
4029                         printf("must specify (port,queue_id)\n");
4030                         return;
4031                 }
4032                 tmp = strtoul(str + i + 1, NULL, 0);
4033                 /* If queue_id greater that what 16-bits can represent, return */
4034                 if(tmp > 0xffff)
4035                         return;
4036
4037                 queue_id = (uint16_t)tmp;
4038                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4039         }
4040         else if (!strcmp(res->what, "filter"))
4041                 rx_vlan_filter_set(port_id, on);
4042         else if (!strcmp(res->what, "qinq_strip"))
4043                 rx_vlan_qinq_strip_set(port_id, on);
4044         else
4045                 vlan_extend_set(port_id, on);
4046
4047         return;
4048 }
4049
4050 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4051         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4052                                  vlan, "vlan");
4053 cmdline_parse_token_string_t cmd_vlan_offload_set =
4054         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4055                                  set, "set");
4056 cmdline_parse_token_string_t cmd_vlan_offload_what =
4057         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4058                                 what, "strip#filter#qinq_strip#extend#stripq");
4059 cmdline_parse_token_string_t cmd_vlan_offload_on =
4060         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4061                               on, "on#off");
4062 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4063         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4064                               port_id, NULL);
4065
4066 cmdline_parse_inst_t cmd_vlan_offload = {
4067         .f = cmd_vlan_offload_parsed,
4068         .data = NULL,
4069         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4070                 "<port_id[,queue_id]>: "
4071                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4072         .tokens = {
4073                 (void *)&cmd_vlan_offload_vlan,
4074                 (void *)&cmd_vlan_offload_set,
4075                 (void *)&cmd_vlan_offload_what,
4076                 (void *)&cmd_vlan_offload_on,
4077                 (void *)&cmd_vlan_offload_portid,
4078                 NULL,
4079         },
4080 };
4081
4082 /* *** VLAN TPID SET ON A PORT *** */
4083 struct cmd_vlan_tpid_result {
4084         cmdline_fixed_string_t vlan;
4085         cmdline_fixed_string_t set;
4086         cmdline_fixed_string_t vlan_type;
4087         cmdline_fixed_string_t what;
4088         uint16_t tp_id;
4089         portid_t port_id;
4090 };
4091
4092 static void
4093 cmd_vlan_tpid_parsed(void *parsed_result,
4094                           __rte_unused struct cmdline *cl,
4095                           __rte_unused void *data)
4096 {
4097         struct cmd_vlan_tpid_result *res = parsed_result;
4098         enum rte_vlan_type vlan_type;
4099
4100         if (!strcmp(res->vlan_type, "inner"))
4101                 vlan_type = ETH_VLAN_TYPE_INNER;
4102         else if (!strcmp(res->vlan_type, "outer"))
4103                 vlan_type = ETH_VLAN_TYPE_OUTER;
4104         else {
4105                 printf("Unknown vlan type\n");
4106                 return;
4107         }
4108         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4109 }
4110
4111 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4112         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4113                                  vlan, "vlan");
4114 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4115         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4116                                  set, "set");
4117 cmdline_parse_token_string_t cmd_vlan_type =
4118         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4119                                  vlan_type, "inner#outer");
4120 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4121         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4122                                  what, "tpid");
4123 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4124         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4125                               tp_id, UINT16);
4126 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4127         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4128                               port_id, UINT16);
4129
4130 cmdline_parse_inst_t cmd_vlan_tpid = {
4131         .f = cmd_vlan_tpid_parsed,
4132         .data = NULL,
4133         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4134                 "Set the VLAN Ether type",
4135         .tokens = {
4136                 (void *)&cmd_vlan_tpid_vlan,
4137                 (void *)&cmd_vlan_tpid_set,
4138                 (void *)&cmd_vlan_type,
4139                 (void *)&cmd_vlan_tpid_what,
4140                 (void *)&cmd_vlan_tpid_tpid,
4141                 (void *)&cmd_vlan_tpid_portid,
4142                 NULL,
4143         },
4144 };
4145
4146 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4147 struct cmd_rx_vlan_filter_result {
4148         cmdline_fixed_string_t rx_vlan;
4149         cmdline_fixed_string_t what;
4150         uint16_t vlan_id;
4151         portid_t port_id;
4152 };
4153
4154 static void
4155 cmd_rx_vlan_filter_parsed(void *parsed_result,
4156                           __rte_unused struct cmdline *cl,
4157                           __rte_unused void *data)
4158 {
4159         struct cmd_rx_vlan_filter_result *res = parsed_result;
4160
4161         if (!strcmp(res->what, "add"))
4162                 rx_vft_set(res->port_id, res->vlan_id, 1);
4163         else
4164                 rx_vft_set(res->port_id, res->vlan_id, 0);
4165 }
4166
4167 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4168         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4169                                  rx_vlan, "rx_vlan");
4170 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4171         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4172                                  what, "add#rm");
4173 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4174         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4175                               vlan_id, UINT16);
4176 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4177         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4178                               port_id, UINT16);
4179
4180 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4181         .f = cmd_rx_vlan_filter_parsed,
4182         .data = NULL,
4183         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4184                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4185                 "identifiers filtered by a port",
4186         .tokens = {
4187                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4188                 (void *)&cmd_rx_vlan_filter_what,
4189                 (void *)&cmd_rx_vlan_filter_vlanid,
4190                 (void *)&cmd_rx_vlan_filter_portid,
4191                 NULL,
4192         },
4193 };
4194
4195 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4196 struct cmd_tx_vlan_set_result {
4197         cmdline_fixed_string_t tx_vlan;
4198         cmdline_fixed_string_t set;
4199         portid_t port_id;
4200         uint16_t vlan_id;
4201 };
4202
4203 static void
4204 cmd_tx_vlan_set_parsed(void *parsed_result,
4205                        __rte_unused struct cmdline *cl,
4206                        __rte_unused void *data)
4207 {
4208         struct cmd_tx_vlan_set_result *res = parsed_result;
4209
4210         if (!port_is_stopped(res->port_id)) {
4211                 printf("Please stop port %d first\n", res->port_id);
4212                 return;
4213         }
4214
4215         tx_vlan_set(res->port_id, res->vlan_id);
4216
4217         cmd_reconfig_device_queue(res->port_id, 1, 1);
4218 }
4219
4220 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4221         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4222                                  tx_vlan, "tx_vlan");
4223 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4224         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4225                                  set, "set");
4226 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4227         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4228                               port_id, UINT16);
4229 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4230         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4231                               vlan_id, UINT16);
4232
4233 cmdline_parse_inst_t cmd_tx_vlan_set = {
4234         .f = cmd_tx_vlan_set_parsed,
4235         .data = NULL,
4236         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4237                 "Enable hardware insertion of a single VLAN header "
4238                 "with a given TAG Identifier in packets sent on a port",
4239         .tokens = {
4240                 (void *)&cmd_tx_vlan_set_tx_vlan,
4241                 (void *)&cmd_tx_vlan_set_set,
4242                 (void *)&cmd_tx_vlan_set_portid,
4243                 (void *)&cmd_tx_vlan_set_vlanid,
4244                 NULL,
4245         },
4246 };
4247
4248 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4249 struct cmd_tx_vlan_set_qinq_result {
4250         cmdline_fixed_string_t tx_vlan;
4251         cmdline_fixed_string_t set;
4252         portid_t port_id;
4253         uint16_t vlan_id;
4254         uint16_t vlan_id_outer;
4255 };
4256
4257 static void
4258 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4259                             __rte_unused struct cmdline *cl,
4260                             __rte_unused void *data)
4261 {
4262         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4263
4264         if (!port_is_stopped(res->port_id)) {
4265                 printf("Please stop port %d first\n", res->port_id);
4266                 return;
4267         }
4268
4269         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4270
4271         cmd_reconfig_device_queue(res->port_id, 1, 1);
4272 }
4273
4274 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4275         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4276                 tx_vlan, "tx_vlan");
4277 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4278         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4279                 set, "set");
4280 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4281         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4282                 port_id, UINT16);
4283 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4284         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4285                 vlan_id, UINT16);
4286 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4287         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4288                 vlan_id_outer, UINT16);
4289
4290 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4291         .f = cmd_tx_vlan_set_qinq_parsed,
4292         .data = NULL,
4293         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4294                 "Enable hardware insertion of double VLAN header "
4295                 "with given TAG Identifiers in packets sent on a port",
4296         .tokens = {
4297                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4298                 (void *)&cmd_tx_vlan_set_qinq_set,
4299                 (void *)&cmd_tx_vlan_set_qinq_portid,
4300                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4301                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4302                 NULL,
4303         },
4304 };
4305
4306 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4307 struct cmd_tx_vlan_set_pvid_result {
4308         cmdline_fixed_string_t tx_vlan;
4309         cmdline_fixed_string_t set;
4310         cmdline_fixed_string_t pvid;
4311         portid_t port_id;
4312         uint16_t vlan_id;
4313         cmdline_fixed_string_t mode;
4314 };
4315
4316 static void
4317 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4318                             __rte_unused struct cmdline *cl,
4319                             __rte_unused void *data)
4320 {
4321         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4322
4323         if (strcmp(res->mode, "on") == 0)
4324                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4325         else
4326                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4327 }
4328
4329 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4330         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4331                                  tx_vlan, "tx_vlan");
4332 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4333         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4334                                  set, "set");
4335 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4336         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4337                                  pvid, "pvid");
4338 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4339         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4340                              port_id, UINT16);
4341 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4342         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4343                               vlan_id, UINT16);
4344 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4345         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4346                                  mode, "on#off");
4347
4348 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4349         .f = cmd_tx_vlan_set_pvid_parsed,
4350         .data = NULL,
4351         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4352         .tokens = {
4353                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4354                 (void *)&cmd_tx_vlan_set_pvid_set,
4355                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4356                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4357                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4358                 (void *)&cmd_tx_vlan_set_pvid_mode,
4359                 NULL,
4360         },
4361 };
4362
4363 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4364 struct cmd_tx_vlan_reset_result {
4365         cmdline_fixed_string_t tx_vlan;
4366         cmdline_fixed_string_t reset;
4367         portid_t port_id;
4368 };
4369
4370 static void
4371 cmd_tx_vlan_reset_parsed(void *parsed_result,
4372                          __rte_unused struct cmdline *cl,
4373                          __rte_unused void *data)
4374 {
4375         struct cmd_tx_vlan_reset_result *res = parsed_result;
4376
4377         if (!port_is_stopped(res->port_id)) {
4378                 printf("Please stop port %d first\n", res->port_id);
4379                 return;
4380         }
4381
4382         tx_vlan_reset(res->port_id);
4383
4384         cmd_reconfig_device_queue(res->port_id, 1, 1);
4385 }
4386
4387 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4388         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4389                                  tx_vlan, "tx_vlan");
4390 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4391         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4392                                  reset, "reset");
4393 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4394         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4395                               port_id, UINT16);
4396
4397 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4398         .f = cmd_tx_vlan_reset_parsed,
4399         .data = NULL,
4400         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4401                 "VLAN header in packets sent on a port",
4402         .tokens = {
4403                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4404                 (void *)&cmd_tx_vlan_reset_reset,
4405                 (void *)&cmd_tx_vlan_reset_portid,
4406                 NULL,
4407         },
4408 };
4409
4410
4411 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4412 struct cmd_csum_result {
4413         cmdline_fixed_string_t csum;
4414         cmdline_fixed_string_t mode;
4415         cmdline_fixed_string_t proto;
4416         cmdline_fixed_string_t hwsw;
4417         portid_t port_id;
4418 };
4419
4420 static void
4421 csum_show(int port_id)
4422 {
4423         struct rte_eth_dev_info dev_info;
4424         uint64_t tx_offloads;
4425         int ret;
4426
4427         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4428         printf("Parse tunnel is %s\n",
4429                 (ports[port_id].parse_tunnel) ? "on" : "off");
4430         printf("IP checksum offload is %s\n",
4431                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4432         printf("UDP checksum offload is %s\n",
4433                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4434         printf("TCP checksum offload is %s\n",
4435                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4436         printf("SCTP checksum offload is %s\n",
4437                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4438         printf("Outer-Ip checksum offload is %s\n",
4439                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4440         printf("Outer-Udp checksum offload is %s\n",
4441                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4442
4443         /* display warnings if configuration is not supported by the NIC */
4444         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4445         if (ret != 0)
4446                 return;
4447
4448         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4449                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4450                 printf("Warning: hardware IP checksum enabled but not "
4451                         "supported by port %d\n", port_id);
4452         }
4453         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4454                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4455                 printf("Warning: hardware UDP checksum enabled but not "
4456                         "supported by port %d\n", port_id);
4457         }
4458         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4459                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4460                 printf("Warning: hardware TCP checksum enabled but not "
4461                         "supported by port %d\n", port_id);
4462         }
4463         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4464                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4465                 printf("Warning: hardware SCTP checksum enabled but not "
4466                         "supported by port %d\n", port_id);
4467         }
4468         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4469                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4470                 printf("Warning: hardware outer IP checksum enabled but not "
4471                         "supported by port %d\n", port_id);
4472         }
4473         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4474                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4475                         == 0) {
4476                 printf("Warning: hardware outer UDP checksum enabled but not "
4477                         "supported by port %d\n", port_id);
4478         }
4479 }
4480
4481 static void
4482 cmd_config_queue_tx_offloads(struct rte_port *port)
4483 {
4484         int k;
4485
4486         /* Apply queue tx offloads configuration */
4487         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4488                 port->tx_conf[k].offloads =
4489                         port->dev_conf.txmode.offloads;
4490 }
4491
4492 static void
4493 cmd_csum_parsed(void *parsed_result,
4494                        __rte_unused struct cmdline *cl,
4495                        __rte_unused void *data)
4496 {
4497         struct cmd_csum_result *res = parsed_result;
4498         int hw = 0;
4499         uint64_t csum_offloads = 0;
4500         struct rte_eth_dev_info dev_info;
4501         int ret;
4502
4503         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4504                 printf("invalid port %d\n", res->port_id);
4505                 return;
4506         }
4507         if (!port_is_stopped(res->port_id)) {
4508                 printf("Please stop port %d first\n", res->port_id);
4509                 return;
4510         }
4511
4512         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4513         if (ret != 0)
4514                 return;
4515
4516         if (!strcmp(res->mode, "set")) {
4517
4518                 if (!strcmp(res->hwsw, "hw"))
4519                         hw = 1;
4520
4521                 if (!strcmp(res->proto, "ip")) {
4522                         if (hw == 0 || (dev_info.tx_offload_capa &
4523                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4524                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4525                         } else {
4526                                 printf("IP checksum offload is not supported "
4527                                        "by port %u\n", res->port_id);
4528                         }
4529                 } else if (!strcmp(res->proto, "udp")) {
4530                         if (hw == 0 || (dev_info.tx_offload_capa &
4531                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4532                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4533                         } else {
4534                                 printf("UDP checksum offload is not supported "
4535                                        "by port %u\n", res->port_id);
4536                         }
4537                 } else if (!strcmp(res->proto, "tcp")) {
4538                         if (hw == 0 || (dev_info.tx_offload_capa &
4539                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4540                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4541                         } else {
4542                                 printf("TCP checksum offload is not supported "
4543                                        "by port %u\n", res->port_id);
4544                         }
4545                 } else if (!strcmp(res->proto, "sctp")) {
4546                         if (hw == 0 || (dev_info.tx_offload_capa &
4547                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4548                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4549                         } else {
4550                                 printf("SCTP checksum offload is not supported "
4551                                        "by port %u\n", res->port_id);
4552                         }
4553                 } else if (!strcmp(res->proto, "outer-ip")) {
4554                         if (hw == 0 || (dev_info.tx_offload_capa &
4555                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4556                                 csum_offloads |=
4557                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4558                         } else {
4559                                 printf("Outer IP checksum offload is not "
4560                                        "supported by port %u\n", res->port_id);
4561                         }
4562                 } else if (!strcmp(res->proto, "outer-udp")) {
4563                         if (hw == 0 || (dev_info.tx_offload_capa &
4564                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4565                                 csum_offloads |=
4566                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4567                         } else {
4568                                 printf("Outer UDP checksum offload is not "
4569                                        "supported by port %u\n", res->port_id);
4570                         }
4571                 }
4572
4573                 if (hw) {
4574                         ports[res->port_id].dev_conf.txmode.offloads |=
4575                                                         csum_offloads;
4576                 } else {
4577                         ports[res->port_id].dev_conf.txmode.offloads &=
4578                                                         (~csum_offloads);
4579                 }
4580                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4581         }
4582         csum_show(res->port_id);
4583
4584         cmd_reconfig_device_queue(res->port_id, 1, 1);
4585 }
4586
4587 cmdline_parse_token_string_t cmd_csum_csum =
4588         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4589                                 csum, "csum");
4590 cmdline_parse_token_string_t cmd_csum_mode =
4591         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4592                                 mode, "set");
4593 cmdline_parse_token_string_t cmd_csum_proto =
4594         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4595                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4596 cmdline_parse_token_string_t cmd_csum_hwsw =
4597         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4598                                 hwsw, "hw#sw");
4599 cmdline_parse_token_num_t cmd_csum_portid =
4600         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4601                                 port_id, UINT16);
4602
4603 cmdline_parse_inst_t cmd_csum_set = {
4604         .f = cmd_csum_parsed,
4605         .data = NULL,
4606         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4607                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4608                 "using csum forward engine",
4609         .tokens = {
4610                 (void *)&cmd_csum_csum,
4611                 (void *)&cmd_csum_mode,
4612                 (void *)&cmd_csum_proto,
4613                 (void *)&cmd_csum_hwsw,
4614                 (void *)&cmd_csum_portid,
4615                 NULL,
4616         },
4617 };
4618
4619 cmdline_parse_token_string_t cmd_csum_mode_show =
4620         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4621                                 mode, "show");
4622
4623 cmdline_parse_inst_t cmd_csum_show = {
4624         .f = cmd_csum_parsed,
4625         .data = NULL,
4626         .help_str = "csum show <port_id>: Show checksum offload configuration",
4627         .tokens = {
4628                 (void *)&cmd_csum_csum,
4629                 (void *)&cmd_csum_mode_show,
4630                 (void *)&cmd_csum_portid,
4631                 NULL,
4632         },
4633 };
4634
4635 /* Enable/disable tunnel parsing */
4636 struct cmd_csum_tunnel_result {
4637         cmdline_fixed_string_t csum;
4638         cmdline_fixed_string_t parse;
4639         cmdline_fixed_string_t onoff;
4640         portid_t port_id;
4641 };
4642
4643 static void
4644 cmd_csum_tunnel_parsed(void *parsed_result,
4645                        __rte_unused struct cmdline *cl,
4646                        __rte_unused void *data)
4647 {
4648         struct cmd_csum_tunnel_result *res = parsed_result;
4649
4650         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4651                 return;
4652
4653         if (!strcmp(res->onoff, "on"))
4654                 ports[res->port_id].parse_tunnel = 1;
4655         else
4656                 ports[res->port_id].parse_tunnel = 0;
4657
4658         csum_show(res->port_id);
4659 }
4660
4661 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4662         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4663                                 csum, "csum");
4664 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4665         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4666                                 parse, "parse-tunnel");
4667 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4668         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4669                                 onoff, "on#off");
4670 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4671         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4672                                 port_id, UINT16);
4673
4674 cmdline_parse_inst_t cmd_csum_tunnel = {
4675         .f = cmd_csum_tunnel_parsed,
4676         .data = NULL,
4677         .help_str = "csum parse-tunnel on|off <port_id>: "
4678                 "Enable/Disable parsing of tunnels for csum engine",
4679         .tokens = {
4680                 (void *)&cmd_csum_tunnel_csum,
4681                 (void *)&cmd_csum_tunnel_parse,
4682                 (void *)&cmd_csum_tunnel_onoff,
4683                 (void *)&cmd_csum_tunnel_portid,
4684                 NULL,
4685         },
4686 };
4687
4688 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4689 struct cmd_tso_set_result {
4690         cmdline_fixed_string_t tso;
4691         cmdline_fixed_string_t mode;
4692         uint16_t tso_segsz;
4693         portid_t port_id;
4694 };
4695
4696 static void
4697 cmd_tso_set_parsed(void *parsed_result,
4698                        __rte_unused struct cmdline *cl,
4699                        __rte_unused void *data)
4700 {
4701         struct cmd_tso_set_result *res = parsed_result;
4702         struct rte_eth_dev_info dev_info;
4703         int ret;
4704
4705         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4706                 return;
4707         if (!port_is_stopped(res->port_id)) {
4708                 printf("Please stop port %d first\n", res->port_id);
4709                 return;
4710         }
4711
4712         if (!strcmp(res->mode, "set"))
4713                 ports[res->port_id].tso_segsz = res->tso_segsz;
4714
4715         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4716         if (ret != 0)
4717                 return;
4718
4719         if ((ports[res->port_id].tso_segsz != 0) &&
4720                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4721                 printf("Error: TSO is not supported by port %d\n",
4722                        res->port_id);
4723                 return;
4724         }
4725
4726         if (ports[res->port_id].tso_segsz == 0) {
4727                 ports[res->port_id].dev_conf.txmode.offloads &=
4728                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4729                 printf("TSO for non-tunneled packets is disabled\n");
4730         } else {
4731                 ports[res->port_id].dev_conf.txmode.offloads |=
4732                                                 DEV_TX_OFFLOAD_TCP_TSO;
4733                 printf("TSO segment size for non-tunneled packets is %d\n",
4734                         ports[res->port_id].tso_segsz);
4735         }
4736         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4737
4738         /* display warnings if configuration is not supported by the NIC */
4739         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4740         if (ret != 0)
4741                 return;
4742
4743         if ((ports[res->port_id].tso_segsz != 0) &&
4744                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4745                 printf("Warning: TSO enabled but not "
4746                         "supported by port %d\n", res->port_id);
4747         }
4748
4749         cmd_reconfig_device_queue(res->port_id, 1, 1);
4750 }
4751
4752 cmdline_parse_token_string_t cmd_tso_set_tso =
4753         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4754                                 tso, "tso");
4755 cmdline_parse_token_string_t cmd_tso_set_mode =
4756         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4757                                 mode, "set");
4758 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4759         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4760                                 tso_segsz, UINT16);
4761 cmdline_parse_token_num_t cmd_tso_set_portid =
4762         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4763                                 port_id, UINT16);
4764
4765 cmdline_parse_inst_t cmd_tso_set = {
4766         .f = cmd_tso_set_parsed,
4767         .data = NULL,
4768         .help_str = "tso set <tso_segsz> <port_id>: "
4769                 "Set TSO segment size of non-tunneled packets for csum engine "
4770                 "(0 to disable)",
4771         .tokens = {
4772                 (void *)&cmd_tso_set_tso,
4773                 (void *)&cmd_tso_set_mode,
4774                 (void *)&cmd_tso_set_tso_segsz,
4775                 (void *)&cmd_tso_set_portid,
4776                 NULL,
4777         },
4778 };
4779
4780 cmdline_parse_token_string_t cmd_tso_show_mode =
4781         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4782                                 mode, "show");
4783
4784
4785 cmdline_parse_inst_t cmd_tso_show = {
4786         .f = cmd_tso_set_parsed,
4787         .data = NULL,
4788         .help_str = "tso show <port_id>: "
4789                 "Show TSO segment size of non-tunneled packets for csum engine",
4790         .tokens = {
4791                 (void *)&cmd_tso_set_tso,
4792                 (void *)&cmd_tso_show_mode,
4793                 (void *)&cmd_tso_set_portid,
4794                 NULL,
4795         },
4796 };
4797
4798 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4799 struct cmd_tunnel_tso_set_result {
4800         cmdline_fixed_string_t tso;
4801         cmdline_fixed_string_t mode;
4802         uint16_t tso_segsz;
4803         portid_t port_id;
4804 };
4805
4806 static struct rte_eth_dev_info
4807 check_tunnel_tso_nic_support(portid_t port_id)
4808 {
4809         struct rte_eth_dev_info dev_info;
4810
4811         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4812                 return dev_info;
4813
4814         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4815                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4816                        "not enabled for port %d\n", port_id);
4817         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4818                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4819                        "not enabled for port %d\n", port_id);
4820         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4821                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4822                        "not enabled for port %d\n", port_id);
4823         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4824                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4825                        "not enabled for port %d\n", port_id);
4826         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4827                 printf("Warning: IP TUNNEL TSO not supported therefore "
4828                        "not enabled for port %d\n", port_id);
4829         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4830                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4831                        "not enabled for port %d\n", port_id);
4832         return dev_info;
4833 }
4834
4835 static void
4836 cmd_tunnel_tso_set_parsed(void *parsed_result,
4837                           __rte_unused struct cmdline *cl,
4838                           __rte_unused void *data)
4839 {
4840         struct cmd_tunnel_tso_set_result *res = parsed_result;
4841         struct rte_eth_dev_info dev_info;
4842
4843         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4844                 return;
4845         if (!port_is_stopped(res->port_id)) {
4846                 printf("Please stop port %d first\n", res->port_id);
4847                 return;
4848         }
4849
4850         if (!strcmp(res->mode, "set"))
4851                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4852
4853         dev_info = check_tunnel_tso_nic_support(res->port_id);
4854         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4855                 ports[res->port_id].dev_conf.txmode.offloads &=
4856                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4857                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4858                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4859                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4860                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4861                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4862                 printf("TSO for tunneled packets is disabled\n");
4863         } else {
4864                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4865                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4866                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4867                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4868                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4869                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4870
4871                 ports[res->port_id].dev_conf.txmode.offloads |=
4872                         (tso_offloads & dev_info.tx_offload_capa);
4873                 printf("TSO segment size for tunneled packets is %d\n",
4874                         ports[res->port_id].tunnel_tso_segsz);
4875
4876                 /* Below conditions are needed to make it work:
4877                  * (1) tunnel TSO is supported by the NIC;
4878                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4879                  * are recognized;
4880                  * (3) for tunneled pkts with outer L3 of IPv4,
4881                  * "csum set outer-ip" must be set to hw, because after tso,
4882                  * total_len of outer IP header is changed, and the checksum
4883                  * of outer IP header calculated by sw should be wrong; that
4884                  * is not necessary for IPv6 tunneled pkts because there's no
4885                  * checksum in IP header anymore.
4886                  */
4887
4888                 if (!ports[res->port_id].parse_tunnel)
4889                         printf("Warning: csum parse_tunnel must be set "
4890                                 "so that tunneled packets are recognized\n");
4891                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4892                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4893                         printf("Warning: csum set outer-ip must be set to hw "
4894                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4895         }
4896
4897         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4898         cmd_reconfig_device_queue(res->port_id, 1, 1);
4899 }
4900
4901 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4902         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4903                                 tso, "tunnel_tso");
4904 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4905         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4906                                 mode, "set");
4907 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4908         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4909                                 tso_segsz, UINT16);
4910 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4911         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4912                                 port_id, UINT16);
4913
4914 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4915         .f = cmd_tunnel_tso_set_parsed,
4916         .data = NULL,
4917         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4918                 "Set TSO segment size of tunneled packets for csum engine "
4919                 "(0 to disable)",
4920         .tokens = {
4921                 (void *)&cmd_tunnel_tso_set_tso,
4922                 (void *)&cmd_tunnel_tso_set_mode,
4923                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4924                 (void *)&cmd_tunnel_tso_set_portid,
4925                 NULL,
4926         },
4927 };
4928
4929 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4930         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4931                                 mode, "show");
4932
4933
4934 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4935         .f = cmd_tunnel_tso_set_parsed,
4936         .data = NULL,
4937         .help_str = "tunnel_tso show <port_id> "
4938                 "Show TSO segment size of tunneled packets for csum engine",
4939         .tokens = {
4940                 (void *)&cmd_tunnel_tso_set_tso,
4941                 (void *)&cmd_tunnel_tso_show_mode,
4942                 (void *)&cmd_tunnel_tso_set_portid,
4943                 NULL,
4944         },
4945 };
4946
4947 /* *** SET GRO FOR A PORT *** */
4948 struct cmd_gro_enable_result {
4949         cmdline_fixed_string_t cmd_set;
4950         cmdline_fixed_string_t cmd_port;
4951         cmdline_fixed_string_t cmd_keyword;
4952         cmdline_fixed_string_t cmd_onoff;
4953         portid_t cmd_pid;
4954 };
4955
4956 static void
4957 cmd_gro_enable_parsed(void *parsed_result,
4958                 __rte_unused struct cmdline *cl,
4959                 __rte_unused void *data)
4960 {
4961         struct cmd_gro_enable_result *res;
4962
4963         res = parsed_result;
4964         if (!strcmp(res->cmd_keyword, "gro"))
4965                 setup_gro(res->cmd_onoff, res->cmd_pid);
4966 }
4967
4968 cmdline_parse_token_string_t cmd_gro_enable_set =
4969         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4970                         cmd_set, "set");
4971 cmdline_parse_token_string_t cmd_gro_enable_port =
4972         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4973                         cmd_keyword, "port");
4974 cmdline_parse_token_num_t cmd_gro_enable_pid =
4975         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4976                         cmd_pid, UINT16);
4977 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4978         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4979                         cmd_keyword, "gro");
4980 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4981         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4982                         cmd_onoff, "on#off");
4983
4984 cmdline_parse_inst_t cmd_gro_enable = {
4985         .f = cmd_gro_enable_parsed,
4986         .data = NULL,
4987         .help_str = "set port <port_id> gro on|off",
4988         .tokens = {
4989                 (void *)&cmd_gro_enable_set,
4990                 (void *)&cmd_gro_enable_port,
4991                 (void *)&cmd_gro_enable_pid,
4992                 (void *)&cmd_gro_enable_keyword,
4993                 (void *)&cmd_gro_enable_onoff,
4994                 NULL,
4995         },
4996 };
4997
4998 /* *** DISPLAY GRO CONFIGURATION *** */
4999 struct cmd_gro_show_result {
5000         cmdline_fixed_string_t cmd_show;
5001         cmdline_fixed_string_t cmd_port;
5002         cmdline_fixed_string_t cmd_keyword;
5003         portid_t cmd_pid;
5004 };
5005
5006 static void
5007 cmd_gro_show_parsed(void *parsed_result,
5008                 __rte_unused struct cmdline *cl,
5009                 __rte_unused void *data)
5010 {
5011         struct cmd_gro_show_result *res;
5012
5013         res = parsed_result;
5014         if (!strcmp(res->cmd_keyword, "gro"))
5015                 show_gro(res->cmd_pid);
5016 }
5017
5018 cmdline_parse_token_string_t cmd_gro_show_show =
5019         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5020                         cmd_show, "show");
5021 cmdline_parse_token_string_t cmd_gro_show_port =
5022         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5023                         cmd_port, "port");
5024 cmdline_parse_token_num_t cmd_gro_show_pid =
5025         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5026                         cmd_pid, UINT16);
5027 cmdline_parse_token_string_t cmd_gro_show_keyword =
5028         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5029                         cmd_keyword, "gro");
5030
5031 cmdline_parse_inst_t cmd_gro_show = {
5032         .f = cmd_gro_show_parsed,
5033         .data = NULL,
5034         .help_str = "show port <port_id> gro",
5035         .tokens = {
5036                 (void *)&cmd_gro_show_show,
5037                 (void *)&cmd_gro_show_port,
5038                 (void *)&cmd_gro_show_pid,
5039                 (void *)&cmd_gro_show_keyword,
5040                 NULL,
5041         },
5042 };
5043
5044 /* *** SET FLUSH CYCLES FOR GRO *** */
5045 struct cmd_gro_flush_result {
5046         cmdline_fixed_string_t cmd_set;
5047         cmdline_fixed_string_t cmd_keyword;
5048         cmdline_fixed_string_t cmd_flush;
5049         uint8_t cmd_cycles;
5050 };
5051
5052 static void
5053 cmd_gro_flush_parsed(void *parsed_result,
5054                 __rte_unused struct cmdline *cl,
5055                 __rte_unused void *data)
5056 {
5057         struct cmd_gro_flush_result *res;
5058
5059         res = parsed_result;
5060         if ((!strcmp(res->cmd_keyword, "gro")) &&
5061                         (!strcmp(res->cmd_flush, "flush")))
5062                 setup_gro_flush_cycles(res->cmd_cycles);
5063 }
5064
5065 cmdline_parse_token_string_t cmd_gro_flush_set =
5066         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5067                         cmd_set, "set");
5068 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5069         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5070                         cmd_keyword, "gro");
5071 cmdline_parse_token_string_t cmd_gro_flush_flush =
5072         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5073                         cmd_flush, "flush");
5074 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5075         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5076                         cmd_cycles, UINT8);
5077
5078 cmdline_parse_inst_t cmd_gro_flush = {
5079         .f = cmd_gro_flush_parsed,
5080         .data = NULL,
5081         .help_str = "set gro flush <cycles>",
5082         .tokens = {
5083                 (void *)&cmd_gro_flush_set,
5084                 (void *)&cmd_gro_flush_keyword,
5085                 (void *)&cmd_gro_flush_flush,
5086                 (void *)&cmd_gro_flush_cycles,
5087                 NULL,
5088         },
5089 };
5090
5091 /* *** ENABLE/DISABLE GSO *** */
5092 struct cmd_gso_enable_result {
5093         cmdline_fixed_string_t cmd_set;
5094         cmdline_fixed_string_t cmd_port;
5095         cmdline_fixed_string_t cmd_keyword;
5096         cmdline_fixed_string_t cmd_mode;
5097         portid_t cmd_pid;
5098 };
5099
5100 static void
5101 cmd_gso_enable_parsed(void *parsed_result,
5102                 __rte_unused struct cmdline *cl,
5103                 __rte_unused void *data)
5104 {
5105         struct cmd_gso_enable_result *res;
5106
5107         res = parsed_result;
5108         if (!strcmp(res->cmd_keyword, "gso"))
5109                 setup_gso(res->cmd_mode, res->cmd_pid);
5110 }
5111
5112 cmdline_parse_token_string_t cmd_gso_enable_set =
5113         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5114                         cmd_set, "set");
5115 cmdline_parse_token_string_t cmd_gso_enable_port =
5116         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5117                         cmd_port, "port");
5118 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5119         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5120                         cmd_keyword, "gso");
5121 cmdline_parse_token_string_t cmd_gso_enable_mode =
5122         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5123                         cmd_mode, "on#off");
5124 cmdline_parse_token_num_t cmd_gso_enable_pid =
5125         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5126                         cmd_pid, UINT16);
5127
5128 cmdline_parse_inst_t cmd_gso_enable = {
5129         .f = cmd_gso_enable_parsed,
5130         .data = NULL,
5131         .help_str = "set port <port_id> gso on|off",
5132         .tokens = {
5133                 (void *)&cmd_gso_enable_set,
5134                 (void *)&cmd_gso_enable_port,
5135                 (void *)&cmd_gso_enable_pid,
5136                 (void *)&cmd_gso_enable_keyword,
5137                 (void *)&cmd_gso_enable_mode,
5138                 NULL,
5139         },
5140 };
5141
5142 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5143 struct cmd_gso_size_result {
5144         cmdline_fixed_string_t cmd_set;
5145         cmdline_fixed_string_t cmd_keyword;
5146         cmdline_fixed_string_t cmd_segsz;
5147         uint16_t cmd_size;
5148 };
5149
5150 static void
5151 cmd_gso_size_parsed(void *parsed_result,
5152                        __rte_unused struct cmdline *cl,
5153                        __rte_unused void *data)
5154 {
5155         struct cmd_gso_size_result *res = parsed_result;
5156
5157         if (test_done == 0) {
5158                 printf("Before setting GSO segsz, please first"
5159                                 " stop forwarding\n");
5160                 return;
5161         }
5162
5163         if (!strcmp(res->cmd_keyword, "gso") &&
5164                         !strcmp(res->cmd_segsz, "segsz")) {
5165                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5166                         printf("gso_size should be larger than %zu."
5167                                         " Please input a legal value\n",
5168                                         RTE_GSO_SEG_SIZE_MIN);
5169                 else
5170                         gso_max_segment_size = res->cmd_size;
5171         }
5172 }
5173
5174 cmdline_parse_token_string_t cmd_gso_size_set =
5175         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5176                                 cmd_set, "set");
5177 cmdline_parse_token_string_t cmd_gso_size_keyword =
5178         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5179                                 cmd_keyword, "gso");
5180 cmdline_parse_token_string_t cmd_gso_size_segsz =
5181         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5182                                 cmd_segsz, "segsz");
5183 cmdline_parse_token_num_t cmd_gso_size_size =
5184         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5185                                 cmd_size, UINT16);
5186
5187 cmdline_parse_inst_t cmd_gso_size = {
5188         .f = cmd_gso_size_parsed,
5189         .data = NULL,
5190         .help_str = "set gso segsz <length>",
5191         .tokens = {
5192                 (void *)&cmd_gso_size_set,
5193                 (void *)&cmd_gso_size_keyword,
5194                 (void *)&cmd_gso_size_segsz,
5195                 (void *)&cmd_gso_size_size,
5196                 NULL,
5197         },
5198 };
5199
5200 /* *** SHOW GSO CONFIGURATION *** */
5201 struct cmd_gso_show_result {
5202         cmdline_fixed_string_t cmd_show;
5203         cmdline_fixed_string_t cmd_port;
5204         cmdline_fixed_string_t cmd_keyword;
5205         portid_t cmd_pid;
5206 };
5207
5208 static void
5209 cmd_gso_show_parsed(void *parsed_result,
5210                        __rte_unused struct cmdline *cl,
5211                        __rte_unused void *data)
5212 {
5213         struct cmd_gso_show_result *res = parsed_result;
5214
5215         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5216                 printf("invalid port id %u\n", res->cmd_pid);
5217                 return;
5218         }
5219         if (!strcmp(res->cmd_keyword, "gso")) {
5220                 if (gso_ports[res->cmd_pid].enable) {
5221                         printf("Max GSO'd packet size: %uB\n"
5222                                         "Supported GSO types: TCP/IPv4, "
5223                                         "UDP/IPv4, VxLAN with inner "
5224                                         "TCP/IPv4 packet, GRE with inner "
5225                                         "TCP/IPv4 packet\n",
5226                                         gso_max_segment_size);
5227                 } else
5228                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5229         }
5230 }
5231
5232 cmdline_parse_token_string_t cmd_gso_show_show =
5233 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5234                 cmd_show, "show");
5235 cmdline_parse_token_string_t cmd_gso_show_port =
5236 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5237                 cmd_port, "port");
5238 cmdline_parse_token_string_t cmd_gso_show_keyword =
5239         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5240                                 cmd_keyword, "gso");
5241 cmdline_parse_token_num_t cmd_gso_show_pid =
5242         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5243                                 cmd_pid, UINT16);
5244
5245 cmdline_parse_inst_t cmd_gso_show = {
5246         .f = cmd_gso_show_parsed,
5247         .data = NULL,
5248         .help_str = "show port <port_id> gso",
5249         .tokens = {
5250                 (void *)&cmd_gso_show_show,
5251                 (void *)&cmd_gso_show_port,
5252                 (void *)&cmd_gso_show_pid,
5253                 (void *)&cmd_gso_show_keyword,
5254                 NULL,
5255         },
5256 };
5257
5258 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5259 struct cmd_set_flush_rx {
5260         cmdline_fixed_string_t set;
5261         cmdline_fixed_string_t flush_rx;
5262         cmdline_fixed_string_t mode;
5263 };
5264
5265 static void
5266 cmd_set_flush_rx_parsed(void *parsed_result,
5267                 __rte_unused struct cmdline *cl,
5268                 __rte_unused void *data)
5269 {
5270         struct cmd_set_flush_rx *res = parsed_result;
5271         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5272 }
5273
5274 cmdline_parse_token_string_t cmd_setflushrx_set =
5275         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5276                         set, "set");
5277 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5278         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5279                         flush_rx, "flush_rx");
5280 cmdline_parse_token_string_t cmd_setflushrx_mode =
5281         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5282                         mode, "on#off");
5283
5284
5285 cmdline_parse_inst_t cmd_set_flush_rx = {
5286         .f = cmd_set_flush_rx_parsed,
5287         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5288         .data = NULL,
5289         .tokens = {
5290                 (void *)&cmd_setflushrx_set,
5291                 (void *)&cmd_setflushrx_flush_rx,
5292                 (void *)&cmd_setflushrx_mode,
5293                 NULL,
5294         },
5295 };
5296
5297 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5298 struct cmd_set_link_check {
5299         cmdline_fixed_string_t set;
5300         cmdline_fixed_string_t link_check;
5301         cmdline_fixed_string_t mode;
5302 };
5303
5304 static void
5305 cmd_set_link_check_parsed(void *parsed_result,
5306                 __rte_unused struct cmdline *cl,
5307                 __rte_unused void *data)
5308 {
5309         struct cmd_set_link_check *res = parsed_result;
5310         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5311 }
5312
5313 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5314         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5315                         set, "set");
5316 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5317         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5318                         link_check, "link_check");
5319 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5320         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5321                         mode, "on#off");
5322
5323
5324 cmdline_parse_inst_t cmd_set_link_check = {
5325         .f = cmd_set_link_check_parsed,
5326         .help_str = "set link_check on|off: Enable/Disable link status check "
5327                     "when starting/stopping a port",
5328         .data = NULL,
5329         .tokens = {
5330                 (void *)&cmd_setlinkcheck_set,
5331                 (void *)&cmd_setlinkcheck_link_check,
5332                 (void *)&cmd_setlinkcheck_mode,
5333                 NULL,
5334         },
5335 };
5336
5337 /* *** SET NIC BYPASS MODE *** */
5338 struct cmd_set_bypass_mode_result {
5339         cmdline_fixed_string_t set;
5340         cmdline_fixed_string_t bypass;
5341         cmdline_fixed_string_t mode;
5342         cmdline_fixed_string_t value;
5343         portid_t port_id;
5344 };
5345
5346 static void
5347 cmd_set_bypass_mode_parsed(void *parsed_result,
5348                 __rte_unused struct cmdline *cl,
5349                 __rte_unused void *data)
5350 {
5351         struct cmd_set_bypass_mode_result *res = parsed_result;
5352         portid_t port_id = res->port_id;
5353         int32_t rc = -EINVAL;
5354
5355 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5356         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5357
5358         if (!strcmp(res->value, "bypass"))
5359                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5360         else if (!strcmp(res->value, "isolate"))
5361                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5362         else
5363                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5364
5365         /* Set the bypass mode for the relevant port. */
5366         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5367 #endif
5368         if (rc != 0)
5369                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5370 }
5371
5372 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5373         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5374                         set, "set");
5375 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5376         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5377                         bypass, "bypass");
5378 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5379         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5380                         mode, "mode");
5381 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5382         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5383                         value, "normal#bypass#isolate");
5384 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5385         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5386                                 port_id, UINT16);
5387
5388 cmdline_parse_inst_t cmd_set_bypass_mode = {
5389         .f = cmd_set_bypass_mode_parsed,
5390         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5391                     "Set the NIC bypass mode for port_id",
5392         .data = NULL,
5393         .tokens = {
5394                 (void *)&cmd_setbypass_mode_set,
5395                 (void *)&cmd_setbypass_mode_bypass,
5396                 (void *)&cmd_setbypass_mode_mode,
5397                 (void *)&cmd_setbypass_mode_value,
5398                 (void *)&cmd_setbypass_mode_port,
5399                 NULL,
5400         },
5401 };
5402
5403 /* *** SET NIC BYPASS EVENT *** */
5404 struct cmd_set_bypass_event_result {
5405         cmdline_fixed_string_t set;
5406         cmdline_fixed_string_t bypass;
5407         cmdline_fixed_string_t event;
5408         cmdline_fixed_string_t event_value;
5409         cmdline_fixed_string_t mode;
5410         cmdline_fixed_string_t mode_value;
5411         portid_t port_id;
5412 };
5413
5414 static void
5415 cmd_set_bypass_event_parsed(void *parsed_result,
5416                 __rte_unused struct cmdline *cl,
5417                 __rte_unused void *data)
5418 {
5419         int32_t rc = -EINVAL;
5420         struct cmd_set_bypass_event_result *res = parsed_result;
5421         portid_t port_id = res->port_id;
5422
5423 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5424         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5425         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5426
5427         if (!strcmp(res->event_value, "timeout"))
5428                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5429         else if (!strcmp(res->event_value, "os_on"))
5430                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5431         else if (!strcmp(res->event_value, "os_off"))
5432                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5433         else if (!strcmp(res->event_value, "power_on"))
5434                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5435         else if (!strcmp(res->event_value, "power_off"))
5436                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5437         else
5438                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5439
5440         if (!strcmp(res->mode_value, "bypass"))
5441                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5442         else if (!strcmp(res->mode_value, "isolate"))
5443                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5444         else
5445                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5446
5447         /* Set the watchdog timeout. */
5448         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5449
5450                 rc = -EINVAL;
5451                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5452                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5453                                                            bypass_timeout);
5454                 }
5455                 if (rc != 0) {
5456                         printf("Failed to set timeout value %u "
5457                         "for port %d, errto code: %d.\n",
5458                         bypass_timeout, port_id, rc);
5459                 }
5460         }
5461
5462         /* Set the bypass event to transition to bypass mode. */
5463         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5464                                               bypass_mode);
5465 #endif
5466
5467         if (rc != 0)
5468                 printf("\t Failed to set bypass event for port = %d.\n",
5469                        port_id);
5470 }
5471
5472 cmdline_parse_token_string_t cmd_setbypass_event_set =
5473         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5474                         set, "set");
5475 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5476         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5477                         bypass, "bypass");
5478 cmdline_parse_token_string_t cmd_setbypass_event_event =
5479         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5480                         event, "event");
5481 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5482         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5483                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5484 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5485         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5486                         mode, "mode");
5487 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5488         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5489                         mode_value, "normal#bypass#isolate");
5490 cmdline_parse_token_num_t cmd_setbypass_event_port =
5491         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5492                                 port_id, UINT16);
5493
5494 cmdline_parse_inst_t cmd_set_bypass_event = {
5495         .f = cmd_set_bypass_event_parsed,
5496         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5497                 "power_off mode normal|bypass|isolate <port_id>: "
5498                 "Set the NIC bypass event mode for port_id",
5499         .data = NULL,
5500         .tokens = {
5501                 (void *)&cmd_setbypass_event_set,
5502                 (void *)&cmd_setbypass_event_bypass,
5503                 (void *)&cmd_setbypass_event_event,
5504                 (void *)&cmd_setbypass_event_event_value,
5505                 (void *)&cmd_setbypass_event_mode,
5506                 (void *)&cmd_setbypass_event_mode_value,
5507                 (void *)&cmd_setbypass_event_port,
5508                 NULL,
5509         },
5510 };
5511
5512
5513 /* *** SET NIC BYPASS TIMEOUT *** */
5514 struct cmd_set_bypass_timeout_result {
5515         cmdline_fixed_string_t set;
5516         cmdline_fixed_string_t bypass;
5517         cmdline_fixed_string_t timeout;
5518         cmdline_fixed_string_t value;
5519 };
5520
5521 static void
5522 cmd_set_bypass_timeout_parsed(void *parsed_result,
5523                 __rte_unused struct cmdline *cl,
5524                 __rte_unused void *data)
5525 {
5526         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5527
5528 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5529         if (!strcmp(res->value, "1.5"))
5530                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5531         else if (!strcmp(res->value, "2"))
5532                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5533         else if (!strcmp(res->value, "3"))
5534                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5535         else if (!strcmp(res->value, "4"))
5536                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5537         else if (!strcmp(res->value, "8"))
5538                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5539         else if (!strcmp(res->value, "16"))
5540                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5541         else if (!strcmp(res->value, "32"))
5542                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5543         else
5544                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5545 #endif
5546 }
5547
5548 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5549         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5550                         set, "set");
5551 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5552         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5553                         bypass, "bypass");
5554 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5555         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5556                         timeout, "timeout");
5557 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5558         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5559                         value, "0#1.5#2#3#4#8#16#32");
5560
5561 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5562         .f = cmd_set_bypass_timeout_parsed,
5563         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5564                 "Set the NIC bypass watchdog timeout in seconds",
5565         .data = NULL,
5566         .tokens = {
5567                 (void *)&cmd_setbypass_timeout_set,
5568                 (void *)&cmd_setbypass_timeout_bypass,
5569                 (void *)&cmd_setbypass_timeout_timeout,
5570                 (void *)&cmd_setbypass_timeout_value,
5571                 NULL,
5572         },
5573 };
5574
5575 /* *** SHOW NIC BYPASS MODE *** */
5576 struct cmd_show_bypass_config_result {
5577         cmdline_fixed_string_t show;
5578         cmdline_fixed_string_t bypass;
5579         cmdline_fixed_string_t config;
5580         portid_t port_id;
5581 };
5582
5583 static void
5584 cmd_show_bypass_config_parsed(void *parsed_result,
5585                 __rte_unused struct cmdline *cl,
5586                 __rte_unused void *data)
5587 {
5588         struct cmd_show_bypass_config_result *res = parsed_result;
5589         portid_t port_id = res->port_id;
5590         int rc = -EINVAL;
5591 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5592         uint32_t event_mode;
5593         uint32_t bypass_mode;
5594         uint32_t timeout = bypass_timeout;
5595         unsigned int i;
5596
5597         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5598                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5599         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5600                 {"UNKNOWN", "normal", "bypass", "isolate"};
5601         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5602                 "NONE",
5603                 "OS/board on",
5604                 "power supply on",
5605                 "OS/board off",
5606                 "power supply off",
5607                 "timeout"};
5608
5609         /* Display the bypass mode.*/
5610         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5611                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5612                 return;
5613         }
5614         else {
5615                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5616                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5617
5618                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5619         }
5620
5621         /* Display the bypass timeout.*/
5622         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5623                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5624
5625         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5626
5627         /* Display the bypass events and associated modes. */
5628         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5629
5630                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5631                         printf("\tFailed to get bypass mode for event = %s\n",
5632                                 events[i]);
5633                 } else {
5634                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5635                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5636
5637                         printf("\tbypass event: %-16s = %s\n", events[i],
5638                                 modes[event_mode]);
5639                 }
5640         }
5641 #endif
5642         if (rc != 0)
5643                 printf("\tFailed to get bypass configuration for port = %d\n",
5644                        port_id);
5645 }
5646
5647 cmdline_parse_token_string_t cmd_showbypass_config_show =
5648         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5649                         show, "show");
5650 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5651         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5652                         bypass, "bypass");
5653 cmdline_parse_token_string_t cmd_showbypass_config_config =
5654         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5655                         config, "config");
5656 cmdline_parse_token_num_t cmd_showbypass_config_port =
5657         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5658                                 port_id, UINT16);
5659
5660 cmdline_parse_inst_t cmd_show_bypass_config = {
5661         .f = cmd_show_bypass_config_parsed,
5662         .help_str = "show bypass config <port_id>: "
5663                     "Show the NIC bypass config for port_id",
5664         .data = NULL,
5665         .tokens = {
5666                 (void *)&cmd_showbypass_config_show,
5667                 (void *)&cmd_showbypass_config_bypass,
5668                 (void *)&cmd_showbypass_config_config,
5669                 (void *)&cmd_showbypass_config_port,
5670                 NULL,
5671         },
5672 };
5673
5674 #ifdef RTE_LIBRTE_PMD_BOND
5675 /* *** SET BONDING MODE *** */
5676 struct cmd_set_bonding_mode_result {
5677         cmdline_fixed_string_t set;
5678         cmdline_fixed_string_t bonding;
5679         cmdline_fixed_string_t mode;
5680         uint8_t value;
5681         portid_t port_id;
5682 };
5683
5684 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5685                 __rte_unused  struct cmdline *cl,
5686                 __rte_unused void *data)
5687 {
5688         struct cmd_set_bonding_mode_result *res = parsed_result;
5689         portid_t port_id = res->port_id;
5690
5691         /* Set the bonding mode for the relevant port. */
5692         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5693                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5694 }
5695
5696 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5697 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5698                 set, "set");
5699 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5700 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5701                 bonding, "bonding");
5702 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5703 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5704                 mode, "mode");
5705 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5706 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5707                 value, UINT8);
5708 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5709 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5710                 port_id, UINT16);
5711
5712 cmdline_parse_inst_t cmd_set_bonding_mode = {
5713                 .f = cmd_set_bonding_mode_parsed,
5714                 .help_str = "set bonding mode <mode_value> <port_id>: "
5715                         "Set the bonding mode for port_id",
5716                 .data = NULL,
5717                 .tokens = {
5718                                 (void *) &cmd_setbonding_mode_set,
5719                                 (void *) &cmd_setbonding_mode_bonding,
5720                                 (void *) &cmd_setbonding_mode_mode,
5721                                 (void *) &cmd_setbonding_mode_value,
5722                                 (void *) &cmd_setbonding_mode_port,
5723                                 NULL
5724                 }
5725 };
5726
5727 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5728 struct cmd_set_bonding_lacp_dedicated_queues_result {
5729         cmdline_fixed_string_t set;
5730         cmdline_fixed_string_t bonding;
5731         cmdline_fixed_string_t lacp;
5732         cmdline_fixed_string_t dedicated_queues;
5733         portid_t port_id;
5734         cmdline_fixed_string_t mode;
5735 };
5736
5737 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5738                 __rte_unused  struct cmdline *cl,
5739                 __rte_unused void *data)
5740 {
5741         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5742         portid_t port_id = res->port_id;
5743         struct rte_port *port;
5744
5745         port = &ports[port_id];
5746
5747         /** Check if the port is not started **/
5748         if (port->port_status != RTE_PORT_STOPPED) {
5749                 printf("Please stop port %d first\n", port_id);
5750                 return;
5751         }
5752
5753         if (!strcmp(res->mode, "enable")) {
5754                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5755                         printf("Dedicate queues for LACP control packets"
5756                                         " enabled\n");
5757                 else
5758                         printf("Enabling dedicate queues for LACP control "
5759                                         "packets on port %d failed\n", port_id);
5760         } else if (!strcmp(res->mode, "disable")) {
5761                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5762                         printf("Dedicated queues for LACP control packets "
5763                                         "disabled\n");
5764                 else
5765                         printf("Disabling dedicated queues for LACP control "
5766                                         "traffic on port %d failed\n", port_id);
5767         }
5768 }
5769
5770 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5771 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5772                 set, "set");
5773 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5774 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5775                 bonding, "bonding");
5776 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5777 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5778                 lacp, "lacp");
5779 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5780 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5781                 dedicated_queues, "dedicated_queues");
5782 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5783 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5784                 port_id, UINT16);
5785 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5786 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5787                 mode, "enable#disable");
5788
5789 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5790                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5791                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5792                         "enable|disable: "
5793                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5794                 .data = NULL,
5795                 .tokens = {
5796                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5797                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5798                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5799                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5800                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5801                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5802                         NULL
5803                 }
5804 };
5805
5806 /* *** SET BALANCE XMIT POLICY *** */
5807 struct cmd_set_bonding_balance_xmit_policy_result {
5808         cmdline_fixed_string_t set;
5809         cmdline_fixed_string_t bonding;
5810         cmdline_fixed_string_t balance_xmit_policy;
5811         portid_t port_id;
5812         cmdline_fixed_string_t policy;
5813 };
5814
5815 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5816                 __rte_unused  struct cmdline *cl,
5817                 __rte_unused void *data)
5818 {
5819         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5820         portid_t port_id = res->port_id;
5821         uint8_t policy;
5822
5823         if (!strcmp(res->policy, "l2")) {
5824                 policy = BALANCE_XMIT_POLICY_LAYER2;
5825         } else if (!strcmp(res->policy, "l23")) {
5826                 policy = BALANCE_XMIT_POLICY_LAYER23;
5827         } else if (!strcmp(res->policy, "l34")) {
5828                 policy = BALANCE_XMIT_POLICY_LAYER34;
5829         } else {
5830                 printf("\t Invalid xmit policy selection");
5831                 return;
5832         }
5833
5834         /* Set the bonding mode for the relevant port. */
5835         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5836                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5837                                 port_id);
5838         }
5839 }
5840
5841 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5842 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5843                 set, "set");
5844 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5845 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5846                 bonding, "bonding");
5847 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5848 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5849                 balance_xmit_policy, "balance_xmit_policy");
5850 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5851 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5852                 port_id, UINT16);
5853 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5854 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5855                 policy, "l2#l23#l34");
5856
5857 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5858                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5859                 .help_str = "set bonding balance_xmit_policy <port_id> "
5860                         "l2|l23|l34: "
5861                         "Set the bonding balance_xmit_policy for port_id",
5862                 .data = NULL,
5863                 .tokens = {
5864                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5865                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5866                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5867                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5868                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5869                                 NULL
5870                 }
5871 };
5872
5873 /* *** SHOW NIC BONDING CONFIGURATION *** */
5874 struct cmd_show_bonding_config_result {
5875         cmdline_fixed_string_t show;
5876         cmdline_fixed_string_t bonding;
5877         cmdline_fixed_string_t config;
5878         portid_t port_id;
5879 };
5880
5881 static void cmd_show_bonding_config_parsed(void *parsed_result,
5882                 __rte_unused  struct cmdline *cl,
5883                 __rte_unused void *data)
5884 {
5885         struct cmd_show_bonding_config_result *res = parsed_result;
5886         int bonding_mode, agg_mode;
5887         portid_t slaves[RTE_MAX_ETHPORTS];
5888         int num_slaves, num_active_slaves;
5889         int primary_id;
5890         int i;
5891         portid_t port_id = res->port_id;
5892
5893         /* Display the bonding mode.*/
5894         bonding_mode = rte_eth_bond_mode_get(port_id);
5895         if (bonding_mode < 0) {
5896                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5897                 return;
5898         } else
5899                 printf("\tBonding mode: %d\n", bonding_mode);
5900
5901         if (bonding_mode == BONDING_MODE_BALANCE) {
5902                 int balance_xmit_policy;
5903
5904                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5905                 if (balance_xmit_policy < 0) {
5906                         printf("\tFailed to get balance xmit policy for port = %d\n",
5907                                         port_id);
5908                         return;
5909                 } else {
5910                         printf("\tBalance Xmit Policy: ");
5911
5912                         switch (balance_xmit_policy) {
5913                         case BALANCE_XMIT_POLICY_LAYER2:
5914                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5915                                 break;
5916                         case BALANCE_XMIT_POLICY_LAYER23:
5917                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5918                                 break;
5919                         case BALANCE_XMIT_POLICY_LAYER34:
5920                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5921                                 break;
5922                         }
5923                         printf("\n");
5924                 }
5925         }
5926
5927         if (bonding_mode == BONDING_MODE_8023AD) {
5928                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5929                 printf("\tIEEE802.3AD Aggregator Mode: ");
5930                 switch (agg_mode) {
5931                 case AGG_BANDWIDTH:
5932                         printf("bandwidth");
5933                         break;
5934                 case AGG_STABLE:
5935                         printf("stable");
5936                         break;
5937                 case AGG_COUNT:
5938                         printf("count");
5939                         break;
5940                 }
5941                 printf("\n");
5942         }
5943
5944         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5945
5946         if (num_slaves < 0) {
5947                 printf("\tFailed to get slave list for port = %d\n", port_id);
5948                 return;
5949         }
5950         if (num_slaves > 0) {
5951                 printf("\tSlaves (%d): [", num_slaves);
5952                 for (i = 0; i < num_slaves - 1; i++)
5953                         printf("%d ", slaves[i]);
5954
5955                 printf("%d]\n", slaves[num_slaves - 1]);
5956         } else {
5957                 printf("\tSlaves: []\n");
5958
5959         }
5960
5961         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5962                         RTE_MAX_ETHPORTS);
5963
5964         if (num_active_slaves < 0) {
5965                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5966                 return;
5967         }
5968         if (num_active_slaves > 0) {
5969                 printf("\tActive Slaves (%d): [", num_active_slaves);
5970                 for (i = 0; i < num_active_slaves - 1; i++)
5971                         printf("%d ", slaves[i]);
5972
5973                 printf("%d]\n", slaves[num_active_slaves - 1]);
5974
5975         } else {
5976                 printf("\tActive Slaves: []\n");
5977
5978         }
5979
5980         primary_id = rte_eth_bond_primary_get(port_id);
5981         if (primary_id < 0) {
5982                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5983                 return;
5984         } else
5985                 printf("\tPrimary: [%d]\n", primary_id);
5986
5987 }
5988
5989 cmdline_parse_token_string_t cmd_showbonding_config_show =
5990 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5991                 show, "show");
5992 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5993 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5994                 bonding, "bonding");
5995 cmdline_parse_token_string_t cmd_showbonding_config_config =
5996 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5997                 config, "config");
5998 cmdline_parse_token_num_t cmd_showbonding_config_port =
5999 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6000                 port_id, UINT16);
6001
6002 cmdline_parse_inst_t cmd_show_bonding_config = {
6003                 .f = cmd_show_bonding_config_parsed,
6004                 .help_str = "show bonding config <port_id>: "
6005                         "Show the bonding config for port_id",
6006                 .data = NULL,
6007                 .tokens = {
6008                                 (void *)&cmd_showbonding_config_show,
6009                                 (void *)&cmd_showbonding_config_bonding,
6010                                 (void *)&cmd_showbonding_config_config,
6011                                 (void *)&cmd_showbonding_config_port,
6012                                 NULL
6013                 }
6014 };
6015
6016 /* *** SET BONDING PRIMARY *** */
6017 struct cmd_set_bonding_primary_result {
6018         cmdline_fixed_string_t set;
6019         cmdline_fixed_string_t bonding;
6020         cmdline_fixed_string_t primary;
6021         portid_t slave_id;
6022         portid_t port_id;
6023 };
6024
6025 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6026                 __rte_unused  struct cmdline *cl,
6027                 __rte_unused void *data)
6028 {
6029         struct cmd_set_bonding_primary_result *res = parsed_result;
6030         portid_t master_port_id = res->port_id;
6031         portid_t slave_port_id = res->slave_id;
6032
6033         /* Set the primary slave for a bonded device. */
6034         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6035                 printf("\t Failed to set primary slave for port = %d.\n",
6036                                 master_port_id);
6037                 return;
6038         }
6039         init_port_config();
6040 }
6041
6042 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6043 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6044                 set, "set");
6045 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6046 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6047                 bonding, "bonding");
6048 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6049 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6050                 primary, "primary");
6051 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6052 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6053                 slave_id, UINT16);
6054 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6055 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6056                 port_id, UINT16);
6057
6058 cmdline_parse_inst_t cmd_set_bonding_primary = {
6059                 .f = cmd_set_bonding_primary_parsed,
6060                 .help_str = "set bonding primary <slave_id> <port_id>: "
6061                         "Set the primary slave for port_id",
6062                 .data = NULL,
6063                 .tokens = {
6064                                 (void *)&cmd_setbonding_primary_set,
6065                                 (void *)&cmd_setbonding_primary_bonding,
6066                                 (void *)&cmd_setbonding_primary_primary,
6067                                 (void *)&cmd_setbonding_primary_slave,
6068                                 (void *)&cmd_setbonding_primary_port,
6069                                 NULL
6070                 }
6071 };
6072
6073 /* *** ADD SLAVE *** */
6074 struct cmd_add_bonding_slave_result {
6075         cmdline_fixed_string_t add;
6076         cmdline_fixed_string_t bonding;
6077         cmdline_fixed_string_t slave;
6078         portid_t slave_id;
6079         portid_t port_id;
6080 };
6081
6082 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6083                 __rte_unused  struct cmdline *cl,
6084                 __rte_unused void *data)
6085 {
6086         struct cmd_add_bonding_slave_result *res = parsed_result;
6087         portid_t master_port_id = res->port_id;
6088         portid_t slave_port_id = res->slave_id;
6089
6090         /* add the slave for a bonded device. */
6091         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6092                 printf("\t Failed to add slave %d to master port = %d.\n",
6093                                 slave_port_id, master_port_id);
6094                 return;
6095         }
6096         init_port_config();
6097         set_port_slave_flag(slave_port_id);
6098 }
6099
6100 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6101 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6102                 add, "add");
6103 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6104 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6105                 bonding, "bonding");
6106 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6107 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6108                 slave, "slave");
6109 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6110 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6111                 slave_id, UINT16);
6112 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6113 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6114                 port_id, UINT16);
6115
6116 cmdline_parse_inst_t cmd_add_bonding_slave = {
6117                 .f = cmd_add_bonding_slave_parsed,
6118                 .help_str = "add bonding slave <slave_id> <port_id>: "
6119                         "Add a slave device to a bonded device",
6120                 .data = NULL,
6121                 .tokens = {
6122                                 (void *)&cmd_addbonding_slave_add,
6123                                 (void *)&cmd_addbonding_slave_bonding,
6124                                 (void *)&cmd_addbonding_slave_slave,
6125                                 (void *)&cmd_addbonding_slave_slaveid,
6126                                 (void *)&cmd_addbonding_slave_port,
6127                                 NULL
6128                 }
6129 };
6130
6131 /* *** REMOVE SLAVE *** */
6132 struct cmd_remove_bonding_slave_result {
6133         cmdline_fixed_string_t remove;
6134         cmdline_fixed_string_t bonding;
6135         cmdline_fixed_string_t slave;
6136         portid_t slave_id;
6137         portid_t port_id;
6138 };
6139
6140 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6141                 __rte_unused  struct cmdline *cl,
6142                 __rte_unused void *data)
6143 {
6144         struct cmd_remove_bonding_slave_result *res = parsed_result;
6145         portid_t master_port_id = res->port_id;
6146         portid_t slave_port_id = res->slave_id;
6147
6148         /* remove the slave from a bonded device. */
6149         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6150                 printf("\t Failed to remove slave %d from master port = %d.\n",
6151                                 slave_port_id, master_port_id);
6152                 return;
6153         }
6154         init_port_config();
6155         clear_port_slave_flag(slave_port_id);
6156 }
6157
6158 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6159                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6160                                 remove, "remove");
6161 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6162                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6163                                 bonding, "bonding");
6164 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6165                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6166                                 slave, "slave");
6167 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6168                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6169                                 slave_id, UINT16);
6170 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6171                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6172                                 port_id, UINT16);
6173
6174 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6175                 .f = cmd_remove_bonding_slave_parsed,
6176                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6177                         "Remove a slave device from a bonded device",
6178                 .data = NULL,
6179                 .tokens = {
6180                                 (void *)&cmd_removebonding_slave_remove,
6181                                 (void *)&cmd_removebonding_slave_bonding,
6182                                 (void *)&cmd_removebonding_slave_slave,
6183                                 (void *)&cmd_removebonding_slave_slaveid,
6184                                 (void *)&cmd_removebonding_slave_port,
6185                                 NULL
6186                 }
6187 };
6188
6189 /* *** CREATE BONDED DEVICE *** */
6190 struct cmd_create_bonded_device_result {
6191         cmdline_fixed_string_t create;
6192         cmdline_fixed_string_t bonded;
6193         cmdline_fixed_string_t device;
6194         uint8_t mode;
6195         uint8_t socket;
6196 };
6197
6198 static int bond_dev_num = 0;
6199
6200 static void cmd_create_bonded_device_parsed(void *parsed_result,
6201                 __rte_unused  struct cmdline *cl,
6202                 __rte_unused void *data)
6203 {
6204         struct cmd_create_bonded_device_result *res = parsed_result;
6205         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6206         int port_id;
6207         int ret;
6208
6209         if (test_done == 0) {
6210                 printf("Please stop forwarding first\n");
6211                 return;
6212         }
6213
6214         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6215                         bond_dev_num++);
6216
6217         /* Create a new bonded device. */
6218         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6219         if (port_id < 0) {
6220                 printf("\t Failed to create bonded device.\n");
6221                 return;
6222         } else {
6223                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6224                                 port_id);
6225
6226                 /* Update number of ports */
6227                 nb_ports = rte_eth_dev_count_avail();
6228                 reconfig(port_id, res->socket);
6229                 ret = rte_eth_promiscuous_enable(port_id);
6230                 if (ret != 0)
6231                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6232                                 port_id, rte_strerror(-ret));
6233
6234                 ports[port_id].need_setup = 0;
6235                 ports[port_id].port_status = RTE_PORT_STOPPED;
6236         }
6237
6238 }
6239
6240 cmdline_parse_token_string_t cmd_createbonded_device_create =
6241                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6242                                 create, "create");
6243 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6244                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6245                                 bonded, "bonded");
6246 cmdline_parse_token_string_t cmd_createbonded_device_device =
6247                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6248                                 device, "device");
6249 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6250                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6251                                 mode, UINT8);
6252 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6253                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6254                                 socket, UINT8);
6255
6256 cmdline_parse_inst_t cmd_create_bonded_device = {
6257                 .f = cmd_create_bonded_device_parsed,
6258                 .help_str = "create bonded device <mode> <socket>: "
6259                         "Create a new bonded device with specific bonding mode and socket",
6260                 .data = NULL,
6261                 .tokens = {
6262                                 (void *)&cmd_createbonded_device_create,
6263                                 (void *)&cmd_createbonded_device_bonded,
6264                                 (void *)&cmd_createbonded_device_device,
6265                                 (void *)&cmd_createbonded_device_mode,
6266                                 (void *)&cmd_createbonded_device_socket,
6267                                 NULL
6268                 }
6269 };
6270
6271 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6272 struct cmd_set_bond_mac_addr_result {
6273         cmdline_fixed_string_t set;
6274         cmdline_fixed_string_t bonding;
6275         cmdline_fixed_string_t mac_addr;
6276         uint16_t port_num;
6277         struct rte_ether_addr address;
6278 };
6279
6280 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6281                 __rte_unused  struct cmdline *cl,
6282                 __rte_unused void *data)
6283 {
6284         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6285         int ret;
6286
6287         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6288                 return;
6289
6290         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6291
6292         /* check the return value and print it if is < 0 */
6293         if (ret < 0)
6294                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6295 }
6296
6297 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6298                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6299 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6300                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6301                                 "bonding");
6302 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6303                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6304                                 "mac_addr");
6305 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6306                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6307                                 port_num, UINT16);
6308 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6309                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6310
6311 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6312                 .f = cmd_set_bond_mac_addr_parsed,
6313                 .data = (void *) 0,
6314                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6315                 .tokens = {
6316                                 (void *)&cmd_set_bond_mac_addr_set,
6317                                 (void *)&cmd_set_bond_mac_addr_bonding,
6318                                 (void *)&cmd_set_bond_mac_addr_mac,
6319                                 (void *)&cmd_set_bond_mac_addr_portnum,
6320                                 (void *)&cmd_set_bond_mac_addr_addr,
6321                                 NULL
6322                 }
6323 };
6324
6325
6326 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6327 struct cmd_set_bond_mon_period_result {
6328         cmdline_fixed_string_t set;
6329         cmdline_fixed_string_t bonding;
6330         cmdline_fixed_string_t mon_period;
6331         uint16_t port_num;
6332         uint32_t period_ms;
6333 };
6334
6335 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6336                 __rte_unused  struct cmdline *cl,
6337                 __rte_unused void *data)
6338 {
6339         struct cmd_set_bond_mon_period_result *res = parsed_result;
6340         int ret;
6341
6342         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6343
6344         /* check the return value and print it if is < 0 */
6345         if (ret < 0)
6346                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6347 }
6348
6349 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6350                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6351                                 set, "set");
6352 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6353                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6354                                 bonding, "bonding");
6355 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6356                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6357                                 mon_period,     "mon_period");
6358 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6359                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6360                                 port_num, UINT16);
6361 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6362                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6363                                 period_ms, UINT32);
6364
6365 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6366                 .f = cmd_set_bond_mon_period_parsed,
6367                 .data = (void *) 0,
6368                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6369                 .tokens = {
6370                                 (void *)&cmd_set_bond_mon_period_set,
6371                                 (void *)&cmd_set_bond_mon_period_bonding,
6372                                 (void *)&cmd_set_bond_mon_period_mon_period,
6373                                 (void *)&cmd_set_bond_mon_period_portnum,
6374                                 (void *)&cmd_set_bond_mon_period_period_ms,
6375                                 NULL
6376                 }
6377 };
6378
6379
6380
6381 struct cmd_set_bonding_agg_mode_policy_result {
6382         cmdline_fixed_string_t set;
6383         cmdline_fixed_string_t bonding;
6384         cmdline_fixed_string_t agg_mode;
6385         uint16_t port_num;
6386         cmdline_fixed_string_t policy;
6387 };
6388
6389
6390 static void
6391 cmd_set_bonding_agg_mode(void *parsed_result,
6392                 __rte_unused struct cmdline *cl,
6393                 __rte_unused void *data)
6394 {
6395         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6396         uint8_t policy = AGG_BANDWIDTH;
6397
6398         if (!strcmp(res->policy, "bandwidth"))
6399                 policy = AGG_BANDWIDTH;
6400         else if (!strcmp(res->policy, "stable"))
6401                 policy = AGG_STABLE;
6402         else if (!strcmp(res->policy, "count"))
6403                 policy = AGG_COUNT;
6404
6405         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6406 }
6407
6408
6409 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6410         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6411                                 set, "set");
6412 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6413         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6414                                 bonding, "bonding");
6415
6416 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6417         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6418                                 agg_mode, "agg_mode");
6419
6420 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6421         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6422                                 port_num, UINT16);
6423
6424 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6425         TOKEN_STRING_INITIALIZER(
6426                         struct cmd_set_bonding_balance_xmit_policy_result,
6427                 policy, "stable#bandwidth#count");
6428
6429 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6430         .f = cmd_set_bonding_agg_mode,
6431         .data = (void *) 0,
6432         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6433         .tokens = {
6434                         (void *)&cmd_set_bonding_agg_mode_set,
6435                         (void *)&cmd_set_bonding_agg_mode_bonding,
6436                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6437                         (void *)&cmd_set_bonding_agg_mode_portnum,
6438                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6439                         NULL
6440                 }
6441 };
6442
6443
6444 #endif /* RTE_LIBRTE_PMD_BOND */
6445
6446 /* *** SET FORWARDING MODE *** */
6447 struct cmd_set_fwd_mode_result {
6448         cmdline_fixed_string_t set;
6449         cmdline_fixed_string_t fwd;
6450         cmdline_fixed_string_t mode;
6451 };
6452
6453 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6454                                     __rte_unused struct cmdline *cl,
6455                                     __rte_unused void *data)
6456 {
6457         struct cmd_set_fwd_mode_result *res = parsed_result;
6458
6459         retry_enabled = 0;
6460         set_pkt_forwarding_mode(res->mode);
6461 }
6462
6463 cmdline_parse_token_string_t cmd_setfwd_set =
6464         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6465 cmdline_parse_token_string_t cmd_setfwd_fwd =
6466         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6467 cmdline_parse_token_string_t cmd_setfwd_mode =
6468         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6469                 "" /* defined at init */);
6470
6471 cmdline_parse_inst_t cmd_set_fwd_mode = {
6472         .f = cmd_set_fwd_mode_parsed,
6473         .data = NULL,
6474         .help_str = NULL, /* defined at init */
6475         .tokens = {
6476                 (void *)&cmd_setfwd_set,
6477                 (void *)&cmd_setfwd_fwd,
6478                 (void *)&cmd_setfwd_mode,
6479                 NULL,
6480         },
6481 };
6482
6483 static void cmd_set_fwd_mode_init(void)
6484 {
6485         char *modes, *c;
6486         static char token[128];
6487         static char help[256];
6488         cmdline_parse_token_string_t *token_struct;
6489
6490         modes = list_pkt_forwarding_modes();
6491         snprintf(help, sizeof(help), "set fwd %s: "
6492                 "Set packet forwarding mode", modes);
6493         cmd_set_fwd_mode.help_str = help;
6494
6495         /* string token separator is # */
6496         for (c = token; *modes != '\0'; modes++)
6497                 if (*modes == '|')
6498                         *c++ = '#';
6499                 else
6500                         *c++ = *modes;
6501         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6502         token_struct->string_data.str = token;
6503 }
6504
6505 /* *** SET RETRY FORWARDING MODE *** */
6506 struct cmd_set_fwd_retry_mode_result {
6507         cmdline_fixed_string_t set;
6508         cmdline_fixed_string_t fwd;
6509         cmdline_fixed_string_t mode;
6510         cmdline_fixed_string_t retry;
6511 };
6512
6513 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6514                             __rte_unused struct cmdline *cl,
6515                             __rte_unused void *data)
6516 {
6517         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6518
6519         retry_enabled = 1;
6520         set_pkt_forwarding_mode(res->mode);
6521 }
6522
6523 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6524         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6525                         set, "set");
6526 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6527         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6528                         fwd, "fwd");
6529 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6530         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6531                         mode,
6532                 "" /* defined at init */);
6533 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6534         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6535                         retry, "retry");
6536
6537 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6538         .f = cmd_set_fwd_retry_mode_parsed,
6539         .data = NULL,
6540         .help_str = NULL, /* defined at init */
6541         .tokens = {
6542                 (void *)&cmd_setfwd_retry_set,
6543                 (void *)&cmd_setfwd_retry_fwd,
6544                 (void *)&cmd_setfwd_retry_mode,
6545                 (void *)&cmd_setfwd_retry_retry,
6546                 NULL,
6547         },
6548 };
6549
6550 static void cmd_set_fwd_retry_mode_init(void)
6551 {
6552         char *modes, *c;
6553         static char token[128];
6554         static char help[256];
6555         cmdline_parse_token_string_t *token_struct;
6556
6557         modes = list_pkt_forwarding_retry_modes();
6558         snprintf(help, sizeof(help), "set fwd %s retry: "
6559                 "Set packet forwarding mode with retry", modes);
6560         cmd_set_fwd_retry_mode.help_str = help;
6561
6562         /* string token separator is # */
6563         for (c = token; *modes != '\0'; modes++)
6564                 if (*modes == '|')
6565                         *c++ = '#';
6566                 else
6567                         *c++ = *modes;
6568         token_struct = (cmdline_parse_token_string_t *)
6569                 cmd_set_fwd_retry_mode.tokens[2];
6570         token_struct->string_data.str = token;
6571 }
6572
6573 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6574 struct cmd_set_burst_tx_retry_result {
6575         cmdline_fixed_string_t set;
6576         cmdline_fixed_string_t burst;
6577         cmdline_fixed_string_t tx;
6578         cmdline_fixed_string_t delay;
6579         uint32_t time;
6580         cmdline_fixed_string_t retry;
6581         uint32_t retry_num;
6582 };
6583
6584 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6585                                         __rte_unused struct cmdline *cl,
6586                                         __rte_unused void *data)
6587 {
6588         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6589
6590         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6591                 && !strcmp(res->tx, "tx")) {
6592                 if (!strcmp(res->delay, "delay"))
6593                         burst_tx_delay_time = res->time;
6594                 if (!strcmp(res->retry, "retry"))
6595                         burst_tx_retry_num = res->retry_num;
6596         }
6597
6598 }
6599
6600 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6601         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6602 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6603         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6604                                  "burst");
6605 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6606         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6607 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6608         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6609 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6610         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6611 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6612         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6613 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6614         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6615
6616 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6617         .f = cmd_set_burst_tx_retry_parsed,
6618         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6619         .tokens = {
6620                 (void *)&cmd_set_burst_tx_retry_set,
6621                 (void *)&cmd_set_burst_tx_retry_burst,
6622                 (void *)&cmd_set_burst_tx_retry_tx,
6623                 (void *)&cmd_set_burst_tx_retry_delay,
6624                 (void *)&cmd_set_burst_tx_retry_time,
6625                 (void *)&cmd_set_burst_tx_retry_retry,
6626                 (void *)&cmd_set_burst_tx_retry_retry_num,
6627                 NULL,
6628         },
6629 };
6630
6631 /* *** SET PROMISC MODE *** */
6632 struct cmd_set_promisc_mode_result {
6633         cmdline_fixed_string_t set;
6634         cmdline_fixed_string_t promisc;
6635         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6636         uint16_t port_num;               /* valid if "allports" argument == 0 */
6637         cmdline_fixed_string_t mode;
6638 };
6639
6640 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6641                                         __rte_unused struct cmdline *cl,
6642                                         void *allports)
6643 {
6644         struct cmd_set_promisc_mode_result *res = parsed_result;
6645         int enable;
6646         portid_t i;
6647
6648         if (!strcmp(res->mode, "on"))
6649                 enable = 1;
6650         else
6651                 enable = 0;
6652
6653         /* all ports */
6654         if (allports) {
6655                 RTE_ETH_FOREACH_DEV(i)
6656                         eth_set_promisc_mode(i, enable);
6657         } else {
6658                 eth_set_promisc_mode(res->port_num, enable);
6659         }
6660 }
6661
6662 cmdline_parse_token_string_t cmd_setpromisc_set =
6663         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6664 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6665         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6666                                  "promisc");
6667 cmdline_parse_token_string_t cmd_setpromisc_portall =
6668         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6669                                  "all");
6670 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6671         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6672                               UINT16);
6673 cmdline_parse_token_string_t cmd_setpromisc_mode =
6674         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6675                                  "on#off");
6676
6677 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6678         .f = cmd_set_promisc_mode_parsed,
6679         .data = (void *)1,
6680         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6681         .tokens = {
6682                 (void *)&cmd_setpromisc_set,
6683                 (void *)&cmd_setpromisc_promisc,
6684                 (void *)&cmd_setpromisc_portall,
6685                 (void *)&cmd_setpromisc_mode,
6686                 NULL,
6687         },
6688 };
6689
6690 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6691         .f = cmd_set_promisc_mode_parsed,
6692         .data = (void *)0,
6693         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6694         .tokens = {
6695                 (void *)&cmd_setpromisc_set,
6696                 (void *)&cmd_setpromisc_promisc,
6697                 (void *)&cmd_setpromisc_portnum,
6698                 (void *)&cmd_setpromisc_mode,
6699                 NULL,
6700         },
6701 };
6702
6703 /* *** SET ALLMULTI MODE *** */
6704 struct cmd_set_allmulti_mode_result {
6705         cmdline_fixed_string_t set;
6706         cmdline_fixed_string_t allmulti;
6707         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6708         uint16_t port_num;               /* valid if "allports" argument == 0 */
6709         cmdline_fixed_string_t mode;
6710 };
6711
6712 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6713                                         __rte_unused struct cmdline *cl,
6714                                         void *allports)
6715 {
6716         struct cmd_set_allmulti_mode_result *res = parsed_result;
6717         int enable;
6718         portid_t i;
6719
6720         if (!strcmp(res->mode, "on"))
6721                 enable = 1;
6722         else
6723                 enable = 0;
6724
6725         /* all ports */
6726         if (allports) {
6727                 RTE_ETH_FOREACH_DEV(i) {
6728                         eth_set_allmulticast_mode(i, enable);
6729                 }
6730         }
6731         else {
6732                 eth_set_allmulticast_mode(res->port_num, enable);
6733         }
6734 }
6735
6736 cmdline_parse_token_string_t cmd_setallmulti_set =
6737         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6738 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6739         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6740                                  "allmulti");
6741 cmdline_parse_token_string_t cmd_setallmulti_portall =
6742         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6743                                  "all");
6744 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6745         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6746                               UINT16);
6747 cmdline_parse_token_string_t cmd_setallmulti_mode =
6748         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6749                                  "on#off");
6750
6751 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6752         .f = cmd_set_allmulti_mode_parsed,
6753         .data = (void *)1,
6754         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6755         .tokens = {
6756                 (void *)&cmd_setallmulti_set,
6757                 (void *)&cmd_setallmulti_allmulti,
6758                 (void *)&cmd_setallmulti_portall,
6759                 (void *)&cmd_setallmulti_mode,
6760                 NULL,
6761         },
6762 };
6763
6764 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6765         .f = cmd_set_allmulti_mode_parsed,
6766         .data = (void *)0,
6767         .help_str = "set allmulti <port_id> on|off: "
6768                 "Set allmulti mode on port_id",
6769         .tokens = {
6770                 (void *)&cmd_setallmulti_set,
6771                 (void *)&cmd_setallmulti_allmulti,
6772                 (void *)&cmd_setallmulti_portnum,
6773                 (void *)&cmd_setallmulti_mode,
6774                 NULL,
6775         },
6776 };
6777
6778 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6779 struct cmd_link_flow_ctrl_set_result {
6780         cmdline_fixed_string_t set;
6781         cmdline_fixed_string_t flow_ctrl;
6782         cmdline_fixed_string_t rx;
6783         cmdline_fixed_string_t rx_lfc_mode;
6784         cmdline_fixed_string_t tx;
6785         cmdline_fixed_string_t tx_lfc_mode;
6786         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6787         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6788         cmdline_fixed_string_t autoneg_str;
6789         cmdline_fixed_string_t autoneg;
6790         cmdline_fixed_string_t hw_str;
6791         uint32_t high_water;
6792         cmdline_fixed_string_t lw_str;
6793         uint32_t low_water;
6794         cmdline_fixed_string_t pt_str;
6795         uint16_t pause_time;
6796         cmdline_fixed_string_t xon_str;
6797         uint16_t send_xon;
6798         portid_t port_id;
6799 };
6800
6801 cmdline_parse_token_string_t cmd_lfc_set_set =
6802         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6803                                 set, "set");
6804 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6805         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6806                                 flow_ctrl, "flow_ctrl");
6807 cmdline_parse_token_string_t cmd_lfc_set_rx =
6808         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6809                                 rx, "rx");
6810 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6811         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6812                                 rx_lfc_mode, "on#off");
6813 cmdline_parse_token_string_t cmd_lfc_set_tx =
6814         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6815                                 tx, "tx");
6816 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6817         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6818                                 tx_lfc_mode, "on#off");
6819 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6820         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6821                                 hw_str, "high_water");
6822 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6823         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6824                                 high_water, UINT32);
6825 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6826         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6827                                 lw_str, "low_water");
6828 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6829         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6830                                 low_water, UINT32);
6831 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6832         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6833                                 pt_str, "pause_time");
6834 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6835         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6836                                 pause_time, UINT16);
6837 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6838         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6839                                 xon_str, "send_xon");
6840 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6841         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6842                                 send_xon, UINT16);
6843 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6844         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6845                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6846 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6847         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6848                                 mac_ctrl_frame_fwd_mode, "on#off");
6849 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6850         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6851                                 autoneg_str, "autoneg");
6852 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6853         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6854                                 autoneg, "on#off");
6855 cmdline_parse_token_num_t cmd_lfc_set_portid =
6856         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6857                                 port_id, UINT16);
6858
6859 /* forward declaration */
6860 static void
6861 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6862                               void *data);
6863
6864 cmdline_parse_inst_t cmd_link_flow_control_set = {
6865         .f = cmd_link_flow_ctrl_set_parsed,
6866         .data = NULL,
6867         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6868                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6869                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6870         .tokens = {
6871                 (void *)&cmd_lfc_set_set,
6872                 (void *)&cmd_lfc_set_flow_ctrl,
6873                 (void *)&cmd_lfc_set_rx,
6874                 (void *)&cmd_lfc_set_rx_mode,
6875                 (void *)&cmd_lfc_set_tx,
6876                 (void *)&cmd_lfc_set_tx_mode,
6877                 (void *)&cmd_lfc_set_high_water,
6878                 (void *)&cmd_lfc_set_low_water,
6879                 (void *)&cmd_lfc_set_pause_time,
6880                 (void *)&cmd_lfc_set_send_xon,
6881                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6882                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6883                 (void *)&cmd_lfc_set_autoneg_str,
6884                 (void *)&cmd_lfc_set_autoneg,
6885                 (void *)&cmd_lfc_set_portid,
6886                 NULL,
6887         },
6888 };
6889
6890 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6891         .f = cmd_link_flow_ctrl_set_parsed,
6892         .data = (void *)&cmd_link_flow_control_set_rx,
6893         .help_str = "set flow_ctrl rx on|off <port_id>: "
6894                 "Change rx flow control parameter",
6895         .tokens = {
6896                 (void *)&cmd_lfc_set_set,
6897                 (void *)&cmd_lfc_set_flow_ctrl,
6898                 (void *)&cmd_lfc_set_rx,
6899                 (void *)&cmd_lfc_set_rx_mode,
6900                 (void *)&cmd_lfc_set_portid,
6901                 NULL,
6902         },
6903 };
6904
6905 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6906         .f = cmd_link_flow_ctrl_set_parsed,
6907         .data = (void *)&cmd_link_flow_control_set_tx,
6908         .help_str = "set flow_ctrl tx on|off <port_id>: "
6909                 "Change tx flow control parameter",
6910         .tokens = {
6911                 (void *)&cmd_lfc_set_set,
6912                 (void *)&cmd_lfc_set_flow_ctrl,
6913                 (void *)&cmd_lfc_set_tx,
6914                 (void *)&cmd_lfc_set_tx_mode,
6915                 (void *)&cmd_lfc_set_portid,
6916                 NULL,
6917         },
6918 };
6919
6920 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6921         .f = cmd_link_flow_ctrl_set_parsed,
6922         .data = (void *)&cmd_link_flow_control_set_hw,
6923         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6924                 "Change high water flow control parameter",
6925         .tokens = {
6926                 (void *)&cmd_lfc_set_set,
6927                 (void *)&cmd_lfc_set_flow_ctrl,
6928                 (void *)&cmd_lfc_set_high_water_str,
6929                 (void *)&cmd_lfc_set_high_water,
6930                 (void *)&cmd_lfc_set_portid,
6931                 NULL,
6932         },
6933 };
6934
6935 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6936         .f = cmd_link_flow_ctrl_set_parsed,
6937         .data = (void *)&cmd_link_flow_control_set_lw,
6938         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6939                 "Change low water flow control parameter",
6940         .tokens = {
6941                 (void *)&cmd_lfc_set_set,
6942                 (void *)&cmd_lfc_set_flow_ctrl,
6943                 (void *)&cmd_lfc_set_low_water_str,
6944                 (void *)&cmd_lfc_set_low_water,
6945                 (void *)&cmd_lfc_set_portid,
6946                 NULL,
6947         },
6948 };
6949
6950 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6951         .f = cmd_link_flow_ctrl_set_parsed,
6952         .data = (void *)&cmd_link_flow_control_set_pt,
6953         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6954                 "Change pause time flow control parameter",
6955         .tokens = {
6956                 (void *)&cmd_lfc_set_set,
6957                 (void *)&cmd_lfc_set_flow_ctrl,
6958                 (void *)&cmd_lfc_set_pause_time_str,
6959                 (void *)&cmd_lfc_set_pause_time,
6960                 (void *)&cmd_lfc_set_portid,
6961                 NULL,
6962         },
6963 };
6964
6965 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6966         .f = cmd_link_flow_ctrl_set_parsed,
6967         .data = (void *)&cmd_link_flow_control_set_xon,
6968         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6969                 "Change send_xon flow control parameter",
6970         .tokens = {
6971                 (void *)&cmd_lfc_set_set,
6972                 (void *)&cmd_lfc_set_flow_ctrl,
6973                 (void *)&cmd_lfc_set_send_xon_str,
6974                 (void *)&cmd_lfc_set_send_xon,
6975                 (void *)&cmd_lfc_set_portid,
6976                 NULL,
6977         },
6978 };
6979
6980 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6981         .f = cmd_link_flow_ctrl_set_parsed,
6982         .data = (void *)&cmd_link_flow_control_set_macfwd,
6983         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6984                 "Change mac ctrl fwd flow control parameter",
6985         .tokens = {
6986                 (void *)&cmd_lfc_set_set,
6987                 (void *)&cmd_lfc_set_flow_ctrl,
6988                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6989                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6990                 (void *)&cmd_lfc_set_portid,
6991                 NULL,
6992         },
6993 };
6994
6995 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6996         .f = cmd_link_flow_ctrl_set_parsed,
6997         .data = (void *)&cmd_link_flow_control_set_autoneg,
6998         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6999                 "Change autoneg flow control parameter",
7000         .tokens = {
7001                 (void *)&cmd_lfc_set_set,
7002                 (void *)&cmd_lfc_set_flow_ctrl,
7003                 (void *)&cmd_lfc_set_autoneg_str,
7004                 (void *)&cmd_lfc_set_autoneg,
7005                 (void *)&cmd_lfc_set_portid,
7006                 NULL,
7007         },
7008 };
7009
7010 static void
7011 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7012                               __rte_unused struct cmdline *cl,
7013                               void *data)
7014 {
7015         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7016         cmdline_parse_inst_t *cmd = data;
7017         struct rte_eth_fc_conf fc_conf;
7018         int rx_fc_en = 0;
7019         int tx_fc_en = 0;
7020         int ret;
7021
7022         /*
7023          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7024          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7025          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7026          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7027          */
7028         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7029                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7030         };
7031
7032         /* Partial command line, retrieve current configuration */
7033         if (cmd) {
7034                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7035                 if (ret != 0) {
7036                         printf("cannot get current flow ctrl parameters, return"
7037                                "code = %d\n", ret);
7038                         return;
7039                 }
7040
7041                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7042                     (fc_conf.mode == RTE_FC_FULL))
7043                         rx_fc_en = 1;
7044                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7045                     (fc_conf.mode == RTE_FC_FULL))
7046                         tx_fc_en = 1;
7047         }
7048
7049         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7050                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7051
7052         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7053                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7054
7055         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7056
7057         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7058                 fc_conf.high_water = res->high_water;
7059
7060         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7061                 fc_conf.low_water = res->low_water;
7062
7063         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7064                 fc_conf.pause_time = res->pause_time;
7065
7066         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7067                 fc_conf.send_xon = res->send_xon;
7068
7069         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7070                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7071                         fc_conf.mac_ctrl_frame_fwd = 1;
7072                 else
7073                         fc_conf.mac_ctrl_frame_fwd = 0;
7074         }
7075
7076         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7077                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7078
7079         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7080         if (ret != 0)
7081                 printf("bad flow contrl parameter, return code = %d \n", ret);
7082 }
7083
7084 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7085 struct cmd_priority_flow_ctrl_set_result {
7086         cmdline_fixed_string_t set;
7087         cmdline_fixed_string_t pfc_ctrl;
7088         cmdline_fixed_string_t rx;
7089         cmdline_fixed_string_t rx_pfc_mode;
7090         cmdline_fixed_string_t tx;
7091         cmdline_fixed_string_t tx_pfc_mode;
7092         uint32_t high_water;
7093         uint32_t low_water;
7094         uint16_t pause_time;
7095         uint8_t  priority;
7096         portid_t port_id;
7097 };
7098
7099 static void
7100 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7101                        __rte_unused struct cmdline *cl,
7102                        __rte_unused void *data)
7103 {
7104         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7105         struct rte_eth_pfc_conf pfc_conf;
7106         int rx_fc_enable, tx_fc_enable;
7107         int ret;
7108
7109         /*
7110          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7111          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7112          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7113          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7114          */
7115         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7116                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7117         };
7118
7119         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7120         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7121         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7122         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7123         pfc_conf.fc.high_water = res->high_water;
7124         pfc_conf.fc.low_water  = res->low_water;
7125         pfc_conf.fc.pause_time = res->pause_time;
7126         pfc_conf.priority      = res->priority;
7127
7128         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7129         if (ret != 0)
7130                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7131 }
7132
7133 cmdline_parse_token_string_t cmd_pfc_set_set =
7134         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7135                                 set, "set");
7136 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7137         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7138                                 pfc_ctrl, "pfc_ctrl");
7139 cmdline_parse_token_string_t cmd_pfc_set_rx =
7140         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7141                                 rx, "rx");
7142 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7143         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7144                                 rx_pfc_mode, "on#off");
7145 cmdline_parse_token_string_t cmd_pfc_set_tx =
7146         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7147                                 tx, "tx");
7148 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7149         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7150                                 tx_pfc_mode, "on#off");
7151 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7152         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7153                                 high_water, UINT32);
7154 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7155         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7156                                 low_water, UINT32);
7157 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7158         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7159                                 pause_time, UINT16);
7160 cmdline_parse_token_num_t cmd_pfc_set_priority =
7161         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7162                                 priority, UINT8);
7163 cmdline_parse_token_num_t cmd_pfc_set_portid =
7164         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7165                                 port_id, UINT16);
7166
7167 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7168         .f = cmd_priority_flow_ctrl_set_parsed,
7169         .data = NULL,
7170         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7171                 "<pause_time> <priority> <port_id>: "
7172                 "Configure the Ethernet priority flow control",
7173         .tokens = {
7174                 (void *)&cmd_pfc_set_set,
7175                 (void *)&cmd_pfc_set_flow_ctrl,
7176                 (void *)&cmd_pfc_set_rx,
7177                 (void *)&cmd_pfc_set_rx_mode,
7178                 (void *)&cmd_pfc_set_tx,
7179                 (void *)&cmd_pfc_set_tx_mode,
7180                 (void *)&cmd_pfc_set_high_water,
7181                 (void *)&cmd_pfc_set_low_water,
7182                 (void *)&cmd_pfc_set_pause_time,
7183                 (void *)&cmd_pfc_set_priority,
7184                 (void *)&cmd_pfc_set_portid,
7185                 NULL,
7186         },
7187 };
7188
7189 /* *** RESET CONFIGURATION *** */
7190 struct cmd_reset_result {
7191         cmdline_fixed_string_t reset;
7192         cmdline_fixed_string_t def;
7193 };
7194
7195 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7196                              struct cmdline *cl,
7197                              __rte_unused void *data)
7198 {
7199         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7200         set_def_fwd_config();
7201 }
7202
7203 cmdline_parse_token_string_t cmd_reset_set =
7204         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7205 cmdline_parse_token_string_t cmd_reset_def =
7206         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7207                                  "default");
7208
7209 cmdline_parse_inst_t cmd_reset = {
7210         .f = cmd_reset_parsed,
7211         .data = NULL,
7212         .help_str = "set default: Reset default forwarding configuration",
7213         .tokens = {
7214                 (void *)&cmd_reset_set,
7215                 (void *)&cmd_reset_def,
7216                 NULL,
7217         },
7218 };
7219
7220 /* *** START FORWARDING *** */
7221 struct cmd_start_result {
7222         cmdline_fixed_string_t start;
7223 };
7224
7225 cmdline_parse_token_string_t cmd_start_start =
7226         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7227
7228 static void cmd_start_parsed(__rte_unused void *parsed_result,
7229                              __rte_unused struct cmdline *cl,
7230                              __rte_unused void *data)
7231 {
7232         start_packet_forwarding(0);
7233 }
7234
7235 cmdline_parse_inst_t cmd_start = {
7236         .f = cmd_start_parsed,
7237         .data = NULL,
7238         .help_str = "start: Start packet forwarding",
7239         .tokens = {
7240                 (void *)&cmd_start_start,
7241                 NULL,
7242         },
7243 };
7244
7245 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7246 struct cmd_start_tx_first_result {
7247         cmdline_fixed_string_t start;
7248         cmdline_fixed_string_t tx_first;
7249 };
7250
7251 static void
7252 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7253                           __rte_unused struct cmdline *cl,
7254                           __rte_unused void *data)
7255 {
7256         start_packet_forwarding(1);
7257 }
7258
7259 cmdline_parse_token_string_t cmd_start_tx_first_start =
7260         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7261                                  "start");
7262 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7263         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7264                                  tx_first, "tx_first");
7265
7266 cmdline_parse_inst_t cmd_start_tx_first = {
7267         .f = cmd_start_tx_first_parsed,
7268         .data = NULL,
7269         .help_str = "start tx_first: Start packet forwarding, "
7270                 "after sending 1 burst of packets",
7271         .tokens = {
7272                 (void *)&cmd_start_tx_first_start,
7273                 (void *)&cmd_start_tx_first_tx_first,
7274                 NULL,
7275         },
7276 };
7277
7278 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7279 struct cmd_start_tx_first_n_result {
7280         cmdline_fixed_string_t start;
7281         cmdline_fixed_string_t tx_first;
7282         uint32_t tx_num;
7283 };
7284
7285 static void
7286 cmd_start_tx_first_n_parsed(void *parsed_result,
7287                           __rte_unused struct cmdline *cl,
7288                           __rte_unused void *data)
7289 {
7290         struct cmd_start_tx_first_n_result *res = parsed_result;
7291
7292         start_packet_forwarding(res->tx_num);
7293 }
7294
7295 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7296         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7297                         start, "start");
7298 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7299         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7300                         tx_first, "tx_first");
7301 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7302         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7303                         tx_num, UINT32);
7304
7305 cmdline_parse_inst_t cmd_start_tx_first_n = {
7306         .f = cmd_start_tx_first_n_parsed,
7307         .data = NULL,
7308         .help_str = "start tx_first <num>: "
7309                 "packet forwarding, after sending <num> bursts of packets",
7310         .tokens = {
7311                 (void *)&cmd_start_tx_first_n_start,
7312                 (void *)&cmd_start_tx_first_n_tx_first,
7313                 (void *)&cmd_start_tx_first_n_tx_num,
7314                 NULL,
7315         },
7316 };
7317
7318 /* *** SET LINK UP *** */
7319 struct cmd_set_link_up_result {
7320         cmdline_fixed_string_t set;
7321         cmdline_fixed_string_t link_up;
7322         cmdline_fixed_string_t port;
7323         portid_t port_id;
7324 };
7325
7326 cmdline_parse_token_string_t cmd_set_link_up_set =
7327         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7328 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7329         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7330                                 "link-up");
7331 cmdline_parse_token_string_t cmd_set_link_up_port =
7332         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7333 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7334         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7335
7336 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7337                              __rte_unused struct cmdline *cl,
7338                              __rte_unused void *data)
7339 {
7340         struct cmd_set_link_up_result *res = parsed_result;
7341         dev_set_link_up(res->port_id);
7342 }
7343
7344 cmdline_parse_inst_t cmd_set_link_up = {
7345         .f = cmd_set_link_up_parsed,
7346         .data = NULL,
7347         .help_str = "set link-up port <port id>",
7348         .tokens = {
7349                 (void *)&cmd_set_link_up_set,
7350                 (void *)&cmd_set_link_up_link_up,
7351                 (void *)&cmd_set_link_up_port,
7352                 (void *)&cmd_set_link_up_port_id,
7353                 NULL,
7354         },
7355 };
7356
7357 /* *** SET LINK DOWN *** */
7358 struct cmd_set_link_down_result {
7359         cmdline_fixed_string_t set;
7360         cmdline_fixed_string_t link_down;
7361         cmdline_fixed_string_t port;
7362         portid_t port_id;
7363 };
7364
7365 cmdline_parse_token_string_t cmd_set_link_down_set =
7366         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7367 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7368         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7369                                 "link-down");
7370 cmdline_parse_token_string_t cmd_set_link_down_port =
7371         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7372 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7373         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7374
7375 static void cmd_set_link_down_parsed(
7376                                 __rte_unused void *parsed_result,
7377                                 __rte_unused struct cmdline *cl,
7378                                 __rte_unused void *data)
7379 {
7380         struct cmd_set_link_down_result *res = parsed_result;
7381         dev_set_link_down(res->port_id);
7382 }
7383
7384 cmdline_parse_inst_t cmd_set_link_down = {
7385         .f = cmd_set_link_down_parsed,
7386         .data = NULL,
7387         .help_str = "set link-down port <port id>",
7388         .tokens = {
7389                 (void *)&cmd_set_link_down_set,
7390                 (void *)&cmd_set_link_down_link_down,
7391                 (void *)&cmd_set_link_down_port,
7392                 (void *)&cmd_set_link_down_port_id,
7393                 NULL,
7394         },
7395 };
7396
7397 /* *** SHOW CFG *** */
7398 struct cmd_showcfg_result {
7399         cmdline_fixed_string_t show;
7400         cmdline_fixed_string_t cfg;
7401         cmdline_fixed_string_t what;
7402 };
7403
7404 static void cmd_showcfg_parsed(void *parsed_result,
7405                                __rte_unused struct cmdline *cl,
7406                                __rte_unused void *data)
7407 {
7408         struct cmd_showcfg_result *res = parsed_result;
7409         if (!strcmp(res->what, "rxtx"))
7410                 rxtx_config_display();
7411         else if (!strcmp(res->what, "cores"))
7412                 fwd_lcores_config_display();
7413         else if (!strcmp(res->what, "fwd"))
7414                 pkt_fwd_config_display(&cur_fwd_config);
7415         else if (!strcmp(res->what, "txpkts"))
7416                 show_tx_pkt_segments();
7417 }
7418
7419 cmdline_parse_token_string_t cmd_showcfg_show =
7420         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7421 cmdline_parse_token_string_t cmd_showcfg_port =
7422         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7423 cmdline_parse_token_string_t cmd_showcfg_what =
7424         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7425                                  "rxtx#cores#fwd#txpkts");
7426
7427 cmdline_parse_inst_t cmd_showcfg = {
7428         .f = cmd_showcfg_parsed,
7429         .data = NULL,
7430         .help_str = "show config rxtx|cores|fwd|txpkts",
7431         .tokens = {
7432                 (void *)&cmd_showcfg_show,
7433                 (void *)&cmd_showcfg_port,
7434                 (void *)&cmd_showcfg_what,
7435                 NULL,
7436         },
7437 };
7438
7439 /* *** SHOW ALL PORT INFO *** */
7440 struct cmd_showportall_result {
7441         cmdline_fixed_string_t show;
7442         cmdline_fixed_string_t port;
7443         cmdline_fixed_string_t what;
7444         cmdline_fixed_string_t all;
7445 };
7446
7447 static void cmd_showportall_parsed(void *parsed_result,
7448                                 __rte_unused struct cmdline *cl,
7449                                 __rte_unused void *data)
7450 {
7451         portid_t i;
7452
7453         struct cmd_showportall_result *res = parsed_result;
7454         if (!strcmp(res->show, "clear")) {
7455                 if (!strcmp(res->what, "stats"))
7456                         RTE_ETH_FOREACH_DEV(i)
7457                                 nic_stats_clear(i);
7458                 else if (!strcmp(res->what, "xstats"))
7459                         RTE_ETH_FOREACH_DEV(i)
7460                                 nic_xstats_clear(i);
7461         } else if (!strcmp(res->what, "info"))
7462                 RTE_ETH_FOREACH_DEV(i)
7463                         port_infos_display(i);
7464         else if (!strcmp(res->what, "summary")) {
7465                 port_summary_header_display();
7466                 RTE_ETH_FOREACH_DEV(i)
7467                         port_summary_display(i);
7468         }
7469         else if (!strcmp(res->what, "stats"))
7470                 RTE_ETH_FOREACH_DEV(i)
7471                         nic_stats_display(i);
7472         else if (!strcmp(res->what, "xstats"))
7473                 RTE_ETH_FOREACH_DEV(i)
7474                         nic_xstats_display(i);
7475         else if (!strcmp(res->what, "fdir"))
7476                 RTE_ETH_FOREACH_DEV(i)
7477                         fdir_get_infos(i);
7478         else if (!strcmp(res->what, "stat_qmap"))
7479                 RTE_ETH_FOREACH_DEV(i)
7480                         nic_stats_mapping_display(i);
7481         else if (!strcmp(res->what, "dcb_tc"))
7482                 RTE_ETH_FOREACH_DEV(i)
7483                         port_dcb_info_display(i);
7484         else if (!strcmp(res->what, "cap"))
7485                 RTE_ETH_FOREACH_DEV(i)
7486                         port_offload_cap_display(i);
7487 }
7488
7489 cmdline_parse_token_string_t cmd_showportall_show =
7490         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7491                                  "show#clear");
7492 cmdline_parse_token_string_t cmd_showportall_port =
7493         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7494 cmdline_parse_token_string_t cmd_showportall_what =
7495         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7496                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7497 cmdline_parse_token_string_t cmd_showportall_all =
7498         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7499 cmdline_parse_inst_t cmd_showportall = {
7500         .f = cmd_showportall_parsed,
7501         .data = NULL,
7502         .help_str = "show|clear port "
7503                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7504         .tokens = {
7505                 (void *)&cmd_showportall_show,
7506                 (void *)&cmd_showportall_port,
7507                 (void *)&cmd_showportall_what,
7508                 (void *)&cmd_showportall_all,
7509                 NULL,
7510         },
7511 };
7512
7513 /* *** SHOW PORT INFO *** */
7514 struct cmd_showport_result {
7515         cmdline_fixed_string_t show;
7516         cmdline_fixed_string_t port;
7517         cmdline_fixed_string_t what;
7518         uint16_t portnum;
7519 };
7520
7521 static void cmd_showport_parsed(void *parsed_result,
7522                                 __rte_unused struct cmdline *cl,
7523                                 __rte_unused void *data)
7524 {
7525         struct cmd_showport_result *res = parsed_result;
7526         if (!strcmp(res->show, "clear")) {
7527                 if (!strcmp(res->what, "stats"))
7528                         nic_stats_clear(res->portnum);
7529                 else if (!strcmp(res->what, "xstats"))
7530                         nic_xstats_clear(res->portnum);
7531         } else if (!strcmp(res->what, "info"))
7532                 port_infos_display(res->portnum);
7533         else if (!strcmp(res->what, "summary")) {
7534                 port_summary_header_display();
7535                 port_summary_display(res->portnum);
7536         }
7537         else if (!strcmp(res->what, "stats"))
7538                 nic_stats_display(res->portnum);
7539         else if (!strcmp(res->what, "xstats"))
7540                 nic_xstats_display(res->portnum);
7541         else if (!strcmp(res->what, "fdir"))
7542                  fdir_get_infos(res->portnum);
7543         else if (!strcmp(res->what, "stat_qmap"))
7544                 nic_stats_mapping_display(res->portnum);
7545         else if (!strcmp(res->what, "dcb_tc"))
7546                 port_dcb_info_display(res->portnum);
7547         else if (!strcmp(res->what, "cap"))
7548                 port_offload_cap_display(res->portnum);
7549 }
7550
7551 cmdline_parse_token_string_t cmd_showport_show =
7552         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7553                                  "show#clear");
7554 cmdline_parse_token_string_t cmd_showport_port =
7555         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7556 cmdline_parse_token_string_t cmd_showport_what =
7557         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7558                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7559 cmdline_parse_token_num_t cmd_showport_portnum =
7560         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7561
7562 cmdline_parse_inst_t cmd_showport = {
7563         .f = cmd_showport_parsed,
7564         .data = NULL,
7565         .help_str = "show|clear port "
7566                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7567                 "<port_id>",
7568         .tokens = {
7569                 (void *)&cmd_showport_show,
7570                 (void *)&cmd_showport_port,
7571                 (void *)&cmd_showport_what,
7572                 (void *)&cmd_showport_portnum,
7573                 NULL,
7574         },
7575 };
7576
7577 /* *** SHOW DEVICE INFO *** */
7578 struct cmd_showdevice_result {
7579         cmdline_fixed_string_t show;
7580         cmdline_fixed_string_t device;
7581         cmdline_fixed_string_t what;
7582         cmdline_fixed_string_t identifier;
7583 };
7584
7585 static void cmd_showdevice_parsed(void *parsed_result,
7586                                 __rte_unused struct cmdline *cl,
7587                                 __rte_unused void *data)
7588 {
7589         struct cmd_showdevice_result *res = parsed_result;
7590         if (!strcmp(res->what, "info")) {
7591                 if (!strcmp(res->identifier, "all"))
7592                         device_infos_display(NULL);
7593                 else
7594                         device_infos_display(res->identifier);
7595         }
7596 }
7597
7598 cmdline_parse_token_string_t cmd_showdevice_show =
7599         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7600                                  "show");
7601 cmdline_parse_token_string_t cmd_showdevice_device =
7602         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7603 cmdline_parse_token_string_t cmd_showdevice_what =
7604         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7605                                  "info");
7606 cmdline_parse_token_string_t cmd_showdevice_identifier =
7607         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7608                         identifier, NULL);
7609
7610 cmdline_parse_inst_t cmd_showdevice = {
7611         .f = cmd_showdevice_parsed,
7612         .data = NULL,
7613         .help_str = "show device info <identifier>|all",
7614         .tokens = {
7615                 (void *)&cmd_showdevice_show,
7616                 (void *)&cmd_showdevice_device,
7617                 (void *)&cmd_showdevice_what,
7618                 (void *)&cmd_showdevice_identifier,
7619                 NULL,
7620         },
7621 };
7622 /* *** SHOW QUEUE INFO *** */
7623 struct cmd_showqueue_result {
7624         cmdline_fixed_string_t show;
7625         cmdline_fixed_string_t type;
7626         cmdline_fixed_string_t what;
7627         uint16_t portnum;
7628         uint16_t queuenum;
7629 };
7630
7631 static void
7632 cmd_showqueue_parsed(void *parsed_result,
7633         __rte_unused struct cmdline *cl,
7634         __rte_unused void *data)
7635 {
7636         struct cmd_showqueue_result *res = parsed_result;
7637
7638         if (!strcmp(res->type, "rxq"))
7639                 rx_queue_infos_display(res->portnum, res->queuenum);
7640         else if (!strcmp(res->type, "txq"))
7641                 tx_queue_infos_display(res->portnum, res->queuenum);
7642 }
7643
7644 cmdline_parse_token_string_t cmd_showqueue_show =
7645         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7646 cmdline_parse_token_string_t cmd_showqueue_type =
7647         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7648 cmdline_parse_token_string_t cmd_showqueue_what =
7649         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7650 cmdline_parse_token_num_t cmd_showqueue_portnum =
7651         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7652 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7653         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7654
7655 cmdline_parse_inst_t cmd_showqueue = {
7656         .f = cmd_showqueue_parsed,
7657         .data = NULL,
7658         .help_str = "show rxq|txq info <port_id> <queue_id>",
7659         .tokens = {
7660                 (void *)&cmd_showqueue_show,
7661                 (void *)&cmd_showqueue_type,
7662                 (void *)&cmd_showqueue_what,
7663                 (void *)&cmd_showqueue_portnum,
7664                 (void *)&cmd_showqueue_queuenum,
7665                 NULL,
7666         },
7667 };
7668
7669 /* show/clear fwd engine statistics */
7670 struct fwd_result {
7671         cmdline_fixed_string_t action;
7672         cmdline_fixed_string_t fwd;
7673         cmdline_fixed_string_t stats;
7674         cmdline_fixed_string_t all;
7675 };
7676
7677 cmdline_parse_token_string_t cmd_fwd_action =
7678         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7679 cmdline_parse_token_string_t cmd_fwd_fwd =
7680         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7681 cmdline_parse_token_string_t cmd_fwd_stats =
7682         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7683 cmdline_parse_token_string_t cmd_fwd_all =
7684         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7685
7686 static void
7687 cmd_showfwdall_parsed(void *parsed_result,
7688                       __rte_unused struct cmdline *cl,
7689                       __rte_unused void *data)
7690 {
7691         struct fwd_result *res = parsed_result;
7692
7693         if (!strcmp(res->action, "show"))
7694                 fwd_stats_display();
7695         else
7696                 fwd_stats_reset();
7697 }
7698
7699 static cmdline_parse_inst_t cmd_showfwdall = {
7700         .f = cmd_showfwdall_parsed,
7701         .data = NULL,
7702         .help_str = "show|clear fwd stats all",
7703         .tokens = {
7704                 (void *)&cmd_fwd_action,
7705                 (void *)&cmd_fwd_fwd,
7706                 (void *)&cmd_fwd_stats,
7707                 (void *)&cmd_fwd_all,
7708                 NULL,
7709         },
7710 };
7711
7712 /* *** READ PORT REGISTER *** */
7713 struct cmd_read_reg_result {
7714         cmdline_fixed_string_t read;
7715         cmdline_fixed_string_t reg;
7716         portid_t port_id;
7717         uint32_t reg_off;
7718 };
7719
7720 static void
7721 cmd_read_reg_parsed(void *parsed_result,
7722                     __rte_unused struct cmdline *cl,
7723                     __rte_unused void *data)
7724 {
7725         struct cmd_read_reg_result *res = parsed_result;
7726         port_reg_display(res->port_id, res->reg_off);
7727 }
7728
7729 cmdline_parse_token_string_t cmd_read_reg_read =
7730         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7731 cmdline_parse_token_string_t cmd_read_reg_reg =
7732         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7733 cmdline_parse_token_num_t cmd_read_reg_port_id =
7734         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7735 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7736         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7737
7738 cmdline_parse_inst_t cmd_read_reg = {
7739         .f = cmd_read_reg_parsed,
7740         .data = NULL,
7741         .help_str = "read reg <port_id> <reg_off>",
7742         .tokens = {
7743                 (void *)&cmd_read_reg_read,
7744                 (void *)&cmd_read_reg_reg,
7745                 (void *)&cmd_read_reg_port_id,
7746                 (void *)&cmd_read_reg_reg_off,
7747                 NULL,
7748         },
7749 };
7750
7751 /* *** READ PORT REGISTER BIT FIELD *** */
7752 struct cmd_read_reg_bit_field_result {
7753         cmdline_fixed_string_t read;
7754         cmdline_fixed_string_t regfield;
7755         portid_t port_id;
7756         uint32_t reg_off;
7757         uint8_t bit1_pos;
7758         uint8_t bit2_pos;
7759 };
7760
7761 static void
7762 cmd_read_reg_bit_field_parsed(void *parsed_result,
7763                               __rte_unused struct cmdline *cl,
7764                               __rte_unused void *data)
7765 {
7766         struct cmd_read_reg_bit_field_result *res = parsed_result;
7767         port_reg_bit_field_display(res->port_id, res->reg_off,
7768                                    res->bit1_pos, res->bit2_pos);
7769 }
7770
7771 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7772         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7773                                  "read");
7774 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7775         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7776                                  regfield, "regfield");
7777 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7778         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7779                               UINT16);
7780 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7781         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7782                               UINT32);
7783 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7784         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7785                               UINT8);
7786 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7787         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7788                               UINT8);
7789
7790 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7791         .f = cmd_read_reg_bit_field_parsed,
7792         .data = NULL,
7793         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7794         "Read register bit field between bit_x and bit_y included",
7795         .tokens = {
7796                 (void *)&cmd_read_reg_bit_field_read,
7797                 (void *)&cmd_read_reg_bit_field_regfield,
7798                 (void *)&cmd_read_reg_bit_field_port_id,
7799                 (void *)&cmd_read_reg_bit_field_reg_off,
7800                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7801                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7802                 NULL,
7803         },
7804 };
7805
7806 /* *** READ PORT REGISTER BIT *** */
7807 struct cmd_read_reg_bit_result {
7808         cmdline_fixed_string_t read;
7809         cmdline_fixed_string_t regbit;
7810         portid_t port_id;
7811         uint32_t reg_off;
7812         uint8_t bit_pos;
7813 };
7814
7815 static void
7816 cmd_read_reg_bit_parsed(void *parsed_result,
7817                         __rte_unused struct cmdline *cl,
7818                         __rte_unused void *data)
7819 {
7820         struct cmd_read_reg_bit_result *res = parsed_result;
7821         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7822 }
7823
7824 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7825         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7826 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7827         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7828                                  regbit, "regbit");
7829 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7830         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7831 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7832         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7833 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7834         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7835
7836 cmdline_parse_inst_t cmd_read_reg_bit = {
7837         .f = cmd_read_reg_bit_parsed,
7838         .data = NULL,
7839         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7840         .tokens = {
7841                 (void *)&cmd_read_reg_bit_read,
7842                 (void *)&cmd_read_reg_bit_regbit,
7843                 (void *)&cmd_read_reg_bit_port_id,
7844                 (void *)&cmd_read_reg_bit_reg_off,
7845                 (void *)&cmd_read_reg_bit_bit_pos,
7846                 NULL,
7847         },
7848 };
7849
7850 /* *** WRITE PORT REGISTER *** */
7851 struct cmd_write_reg_result {
7852         cmdline_fixed_string_t write;
7853         cmdline_fixed_string_t reg;
7854         portid_t port_id;
7855         uint32_t reg_off;
7856         uint32_t value;
7857 };
7858
7859 static void
7860 cmd_write_reg_parsed(void *parsed_result,
7861                      __rte_unused struct cmdline *cl,
7862                      __rte_unused void *data)
7863 {
7864         struct cmd_write_reg_result *res = parsed_result;
7865         port_reg_set(res->port_id, res->reg_off, res->value);
7866 }
7867
7868 cmdline_parse_token_string_t cmd_write_reg_write =
7869         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7870 cmdline_parse_token_string_t cmd_write_reg_reg =
7871         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7872 cmdline_parse_token_num_t cmd_write_reg_port_id =
7873         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7874 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7875         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7876 cmdline_parse_token_num_t cmd_write_reg_value =
7877         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7878
7879 cmdline_parse_inst_t cmd_write_reg = {
7880         .f = cmd_write_reg_parsed,
7881         .data = NULL,
7882         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7883         .tokens = {
7884                 (void *)&cmd_write_reg_write,
7885                 (void *)&cmd_write_reg_reg,
7886                 (void *)&cmd_write_reg_port_id,
7887                 (void *)&cmd_write_reg_reg_off,
7888                 (void *)&cmd_write_reg_value,
7889                 NULL,
7890         },
7891 };
7892
7893 /* *** WRITE PORT REGISTER BIT FIELD *** */
7894 struct cmd_write_reg_bit_field_result {
7895         cmdline_fixed_string_t write;
7896         cmdline_fixed_string_t regfield;
7897         portid_t port_id;
7898         uint32_t reg_off;
7899         uint8_t bit1_pos;
7900         uint8_t bit2_pos;
7901         uint32_t value;
7902 };
7903
7904 static void
7905 cmd_write_reg_bit_field_parsed(void *parsed_result,
7906                                __rte_unused struct cmdline *cl,
7907                                __rte_unused void *data)
7908 {
7909         struct cmd_write_reg_bit_field_result *res = parsed_result;
7910         port_reg_bit_field_set(res->port_id, res->reg_off,
7911                           res->bit1_pos, res->bit2_pos, res->value);
7912 }
7913
7914 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7915         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7916                                  "write");
7917 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7918         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7919                                  regfield, "regfield");
7920 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7921         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7922                               UINT16);
7923 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7924         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7925                               UINT32);
7926 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7927         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7928                               UINT8);
7929 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7930         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7931                               UINT8);
7932 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7933         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7934                               UINT32);
7935
7936 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7937         .f = cmd_write_reg_bit_field_parsed,
7938         .data = NULL,
7939         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7940                 "<reg_value>: "
7941                 "Set register bit field between bit_x and bit_y included",
7942         .tokens = {
7943                 (void *)&cmd_write_reg_bit_field_write,
7944                 (void *)&cmd_write_reg_bit_field_regfield,
7945                 (void *)&cmd_write_reg_bit_field_port_id,
7946                 (void *)&cmd_write_reg_bit_field_reg_off,
7947                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7948                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7949                 (void *)&cmd_write_reg_bit_field_value,
7950                 NULL,
7951         },
7952 };
7953
7954 /* *** WRITE PORT REGISTER BIT *** */
7955 struct cmd_write_reg_bit_result {
7956         cmdline_fixed_string_t write;
7957         cmdline_fixed_string_t regbit;
7958         portid_t port_id;
7959         uint32_t reg_off;
7960         uint8_t bit_pos;
7961         uint8_t value;
7962 };
7963
7964 static void
7965 cmd_write_reg_bit_parsed(void *parsed_result,
7966                          __rte_unused struct cmdline *cl,
7967                          __rte_unused void *data)
7968 {
7969         struct cmd_write_reg_bit_result *res = parsed_result;
7970         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7971 }
7972
7973 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7974         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7975                                  "write");
7976 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7977         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7978                                  regbit, "regbit");
7979 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7980         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7981 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7982         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7983 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7984         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7985 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7986         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7987
7988 cmdline_parse_inst_t cmd_write_reg_bit = {
7989         .f = cmd_write_reg_bit_parsed,
7990         .data = NULL,
7991         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7992                 "0 <= bit_x <= 31",
7993         .tokens = {
7994                 (void *)&cmd_write_reg_bit_write,
7995                 (void *)&cmd_write_reg_bit_regbit,
7996                 (void *)&cmd_write_reg_bit_port_id,
7997                 (void *)&cmd_write_reg_bit_reg_off,
7998                 (void *)&cmd_write_reg_bit_bit_pos,
7999                 (void *)&cmd_write_reg_bit_value,
8000                 NULL,
8001         },
8002 };
8003
8004 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8005 struct cmd_read_rxd_txd_result {
8006         cmdline_fixed_string_t read;
8007         cmdline_fixed_string_t rxd_txd;
8008         portid_t port_id;
8009         uint16_t queue_id;
8010         uint16_t desc_id;
8011 };
8012
8013 static void
8014 cmd_read_rxd_txd_parsed(void *parsed_result,
8015                         __rte_unused struct cmdline *cl,
8016                         __rte_unused void *data)
8017 {
8018         struct cmd_read_rxd_txd_result *res = parsed_result;
8019
8020         if (!strcmp(res->rxd_txd, "rxd"))
8021                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8022         else if (!strcmp(res->rxd_txd, "txd"))
8023                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8024 }
8025
8026 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8027         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8028 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8029         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8030                                  "rxd#txd");
8031 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8032         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8033 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8034         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8035 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8036         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8037
8038 cmdline_parse_inst_t cmd_read_rxd_txd = {
8039         .f = cmd_read_rxd_txd_parsed,
8040         .data = NULL,
8041         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8042         .tokens = {
8043                 (void *)&cmd_read_rxd_txd_read,
8044                 (void *)&cmd_read_rxd_txd_rxd_txd,
8045                 (void *)&cmd_read_rxd_txd_port_id,
8046                 (void *)&cmd_read_rxd_txd_queue_id,
8047                 (void *)&cmd_read_rxd_txd_desc_id,
8048                 NULL,
8049         },
8050 };
8051
8052 /* *** QUIT *** */
8053 struct cmd_quit_result {
8054         cmdline_fixed_string_t quit;
8055 };
8056
8057 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8058                             struct cmdline *cl,
8059                             __rte_unused void *data)
8060 {
8061         cmdline_quit(cl);
8062 }
8063
8064 cmdline_parse_token_string_t cmd_quit_quit =
8065         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8066
8067 cmdline_parse_inst_t cmd_quit = {
8068         .f = cmd_quit_parsed,
8069         .data = NULL,
8070         .help_str = "quit: Exit application",
8071         .tokens = {
8072                 (void *)&cmd_quit_quit,
8073                 NULL,
8074         },
8075 };
8076
8077 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8078 struct cmd_mac_addr_result {
8079         cmdline_fixed_string_t mac_addr_cmd;
8080         cmdline_fixed_string_t what;
8081         uint16_t port_num;
8082         struct rte_ether_addr address;
8083 };
8084
8085 static void cmd_mac_addr_parsed(void *parsed_result,
8086                 __rte_unused struct cmdline *cl,
8087                 __rte_unused void *data)
8088 {
8089         struct cmd_mac_addr_result *res = parsed_result;
8090         int ret;
8091
8092         if (strcmp(res->what, "add") == 0)
8093                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8094         else if (strcmp(res->what, "set") == 0)
8095                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8096                                                        &res->address);
8097         else
8098                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8099
8100         /* check the return value and print it if is < 0 */
8101         if(ret < 0)
8102                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8103
8104 }
8105
8106 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8107         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8108                                 "mac_addr");
8109 cmdline_parse_token_string_t cmd_mac_addr_what =
8110         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8111                                 "add#remove#set");
8112 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8113                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8114                                         UINT16);
8115 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8116                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8117
8118 cmdline_parse_inst_t cmd_mac_addr = {
8119         .f = cmd_mac_addr_parsed,
8120         .data = (void *)0,
8121         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8122                         "Add/Remove/Set MAC address on port_id",
8123         .tokens = {
8124                 (void *)&cmd_mac_addr_cmd,
8125                 (void *)&cmd_mac_addr_what,
8126                 (void *)&cmd_mac_addr_portnum,
8127                 (void *)&cmd_mac_addr_addr,
8128                 NULL,
8129         },
8130 };
8131
8132 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8133 struct cmd_eth_peer_result {
8134         cmdline_fixed_string_t set;
8135         cmdline_fixed_string_t eth_peer;
8136         portid_t port_id;
8137         cmdline_fixed_string_t peer_addr;
8138 };
8139
8140 static void cmd_set_eth_peer_parsed(void *parsed_result,
8141                         __rte_unused struct cmdline *cl,
8142                         __rte_unused void *data)
8143 {
8144                 struct cmd_eth_peer_result *res = parsed_result;
8145
8146                 if (test_done == 0) {
8147                         printf("Please stop forwarding first\n");
8148                         return;
8149                 }
8150                 if (!strcmp(res->eth_peer, "eth-peer")) {
8151                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8152                         fwd_config_setup();
8153                 }
8154 }
8155 cmdline_parse_token_string_t cmd_eth_peer_set =
8156         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8157 cmdline_parse_token_string_t cmd_eth_peer =
8158         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8159 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8160         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8161 cmdline_parse_token_string_t cmd_eth_peer_addr =
8162         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8163
8164 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8165         .f = cmd_set_eth_peer_parsed,
8166         .data = NULL,
8167         .help_str = "set eth-peer <port_id> <peer_mac>",
8168         .tokens = {
8169                 (void *)&cmd_eth_peer_set,
8170                 (void *)&cmd_eth_peer,
8171                 (void *)&cmd_eth_peer_port_id,
8172                 (void *)&cmd_eth_peer_addr,
8173                 NULL,
8174         },
8175 };
8176
8177 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8178 struct cmd_set_qmap_result {
8179         cmdline_fixed_string_t set;
8180         cmdline_fixed_string_t qmap;
8181         cmdline_fixed_string_t what;
8182         portid_t port_id;
8183         uint16_t queue_id;
8184         uint8_t map_value;
8185 };
8186
8187 static void
8188 cmd_set_qmap_parsed(void *parsed_result,
8189                        __rte_unused struct cmdline *cl,
8190                        __rte_unused void *data)
8191 {
8192         struct cmd_set_qmap_result *res = parsed_result;
8193         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8194
8195         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8196 }
8197
8198 cmdline_parse_token_string_t cmd_setqmap_set =
8199         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8200                                  set, "set");
8201 cmdline_parse_token_string_t cmd_setqmap_qmap =
8202         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8203                                  qmap, "stat_qmap");
8204 cmdline_parse_token_string_t cmd_setqmap_what =
8205         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8206                                  what, "tx#rx");
8207 cmdline_parse_token_num_t cmd_setqmap_portid =
8208         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8209                               port_id, UINT16);
8210 cmdline_parse_token_num_t cmd_setqmap_queueid =
8211         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8212                               queue_id, UINT16);
8213 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8214         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8215                               map_value, UINT8);
8216
8217 cmdline_parse_inst_t cmd_set_qmap = {
8218         .f = cmd_set_qmap_parsed,
8219         .data = NULL,
8220         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8221                 "Set statistics mapping value on tx|rx queue_id of port_id",
8222         .tokens = {
8223                 (void *)&cmd_setqmap_set,
8224                 (void *)&cmd_setqmap_qmap,
8225                 (void *)&cmd_setqmap_what,
8226                 (void *)&cmd_setqmap_portid,
8227                 (void *)&cmd_setqmap_queueid,
8228                 (void *)&cmd_setqmap_mapvalue,
8229                 NULL,
8230         },
8231 };
8232
8233 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8234 struct cmd_set_xstats_hide_zero_result {
8235         cmdline_fixed_string_t keyword;
8236         cmdline_fixed_string_t name;
8237         cmdline_fixed_string_t on_off;
8238 };
8239
8240 static void
8241 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8242                         __rte_unused struct cmdline *cl,
8243                         __rte_unused void *data)
8244 {
8245         struct cmd_set_xstats_hide_zero_result *res;
8246         uint16_t on_off = 0;
8247
8248         res = parsed_result;
8249         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8250         set_xstats_hide_zero(on_off);
8251 }
8252
8253 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8254         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8255                                  keyword, "set");
8256 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8257         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8258                                  name, "xstats-hide-zero");
8259 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8260         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8261                                  on_off, "on#off");
8262
8263 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8264         .f = cmd_set_xstats_hide_zero_parsed,
8265         .data = NULL,
8266         .help_str = "set xstats-hide-zero on|off",
8267         .tokens = {
8268                 (void *)&cmd_set_xstats_hide_zero_keyword,
8269                 (void *)&cmd_set_xstats_hide_zero_name,
8270                 (void *)&cmd_set_xstats_hide_zero_on_off,
8271                 NULL,
8272         },
8273 };
8274
8275 /* *** CONFIGURE UNICAST HASH TABLE *** */
8276 struct cmd_set_uc_hash_table {
8277         cmdline_fixed_string_t set;
8278         cmdline_fixed_string_t port;
8279         portid_t port_id;
8280         cmdline_fixed_string_t what;
8281         struct rte_ether_addr address;
8282         cmdline_fixed_string_t mode;
8283 };
8284
8285 static void
8286 cmd_set_uc_hash_parsed(void *parsed_result,
8287                        __rte_unused struct cmdline *cl,
8288                        __rte_unused void *data)
8289 {
8290         int ret=0;
8291         struct cmd_set_uc_hash_table *res = parsed_result;
8292
8293         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8294
8295         if (strcmp(res->what, "uta") == 0)
8296                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8297                                                 &res->address,(uint8_t)is_on);
8298         if (ret < 0)
8299                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8300
8301 }
8302
8303 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8304         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8305                                  set, "set");
8306 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8307         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8308                                  port, "port");
8309 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8310         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8311                               port_id, UINT16);
8312 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8313         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8314                                  what, "uta");
8315 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8316         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8317                                 address);
8318 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8319         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8320                                  mode, "on#off");
8321
8322 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8323         .f = cmd_set_uc_hash_parsed,
8324         .data = NULL,
8325         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8326         .tokens = {
8327                 (void *)&cmd_set_uc_hash_set,
8328                 (void *)&cmd_set_uc_hash_port,
8329                 (void *)&cmd_set_uc_hash_portid,
8330                 (void *)&cmd_set_uc_hash_what,
8331                 (void *)&cmd_set_uc_hash_mac,
8332                 (void *)&cmd_set_uc_hash_mode,
8333                 NULL,
8334         },
8335 };
8336
8337 struct cmd_set_uc_all_hash_table {
8338         cmdline_fixed_string_t set;
8339         cmdline_fixed_string_t port;
8340         portid_t port_id;
8341         cmdline_fixed_string_t what;
8342         cmdline_fixed_string_t value;
8343         cmdline_fixed_string_t mode;
8344 };
8345
8346 static void
8347 cmd_set_uc_all_hash_parsed(void *parsed_result,
8348                        __rte_unused struct cmdline *cl,
8349                        __rte_unused void *data)
8350 {
8351         int ret=0;
8352         struct cmd_set_uc_all_hash_table *res = parsed_result;
8353
8354         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8355
8356         if ((strcmp(res->what, "uta") == 0) &&
8357                 (strcmp(res->value, "all") == 0))
8358                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8359         if (ret < 0)
8360                 printf("bad unicast hash table parameter,"
8361                         "return code = %d \n", ret);
8362 }
8363
8364 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8365         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8366                                  set, "set");
8367 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8368         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8369                                  port, "port");
8370 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8371         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8372                               port_id, UINT16);
8373 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8374         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8375                                  what, "uta");
8376 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8377         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8378                                 value,"all");
8379 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8380         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8381                                  mode, "on#off");
8382
8383 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8384         .f = cmd_set_uc_all_hash_parsed,
8385         .data = NULL,
8386         .help_str = "set port <port_id> uta all on|off",
8387         .tokens = {
8388                 (void *)&cmd_set_uc_all_hash_set,
8389                 (void *)&cmd_set_uc_all_hash_port,
8390                 (void *)&cmd_set_uc_all_hash_portid,
8391                 (void *)&cmd_set_uc_all_hash_what,
8392                 (void *)&cmd_set_uc_all_hash_value,
8393                 (void *)&cmd_set_uc_all_hash_mode,
8394                 NULL,
8395         },
8396 };
8397
8398 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8399 struct cmd_set_vf_macvlan_filter {
8400         cmdline_fixed_string_t set;
8401         cmdline_fixed_string_t port;
8402         portid_t port_id;
8403         cmdline_fixed_string_t vf;
8404         uint8_t vf_id;
8405         struct rte_ether_addr address;
8406         cmdline_fixed_string_t filter_type;
8407         cmdline_fixed_string_t mode;
8408 };
8409
8410 static void
8411 cmd_set_vf_macvlan_parsed(void *parsed_result,
8412                        __rte_unused struct cmdline *cl,
8413                        __rte_unused void *data)
8414 {
8415         int is_on, ret = 0;
8416         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8417         struct rte_eth_mac_filter filter;
8418
8419         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8420
8421         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8422
8423         /* set VF MAC filter */
8424         filter.is_vf = 1;
8425
8426         /* set VF ID */
8427         filter.dst_id = res->vf_id;
8428
8429         if (!strcmp(res->filter_type, "exact-mac"))
8430                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8431         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8432                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8433         else if (!strcmp(res->filter_type, "hashmac"))
8434                 filter.filter_type = RTE_MAC_HASH_MATCH;
8435         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8436                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8437
8438         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8439
8440         if (is_on)
8441                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8442                                         RTE_ETH_FILTER_MACVLAN,
8443                                         RTE_ETH_FILTER_ADD,
8444                                          &filter);
8445         else
8446                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8447                                         RTE_ETH_FILTER_MACVLAN,
8448                                         RTE_ETH_FILTER_DELETE,
8449                                         &filter);
8450
8451         if (ret < 0)
8452                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8453
8454 }
8455
8456 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8457         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8458                                  set, "set");
8459 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8460         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8461                                  port, "port");
8462 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8463         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8464                               port_id, UINT16);
8465 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8466         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8467                                  vf, "vf");
8468 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8469         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8470                                 vf_id, UINT8);
8471 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8472         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8473                                 address);
8474 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8475         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8476                                 filter_type, "exact-mac#exact-mac-vlan"
8477                                 "#hashmac#hashmac-vlan");
8478 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8479         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8480                                  mode, "on#off");
8481
8482 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8483         .f = cmd_set_vf_macvlan_parsed,
8484         .data = NULL,
8485         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8486                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8487                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8488                 "hash match rule: hash match of MAC and exact match of VLAN",
8489         .tokens = {
8490                 (void *)&cmd_set_vf_macvlan_set,
8491                 (void *)&cmd_set_vf_macvlan_port,
8492                 (void *)&cmd_set_vf_macvlan_portid,
8493                 (void *)&cmd_set_vf_macvlan_vf,
8494                 (void *)&cmd_set_vf_macvlan_vf_id,
8495                 (void *)&cmd_set_vf_macvlan_mac,
8496                 (void *)&cmd_set_vf_macvlan_filter_type,
8497                 (void *)&cmd_set_vf_macvlan_mode,
8498                 NULL,
8499         },
8500 };
8501
8502 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8503 struct cmd_set_vf_traffic {
8504         cmdline_fixed_string_t set;
8505         cmdline_fixed_string_t port;
8506         portid_t port_id;
8507         cmdline_fixed_string_t vf;
8508         uint8_t vf_id;
8509         cmdline_fixed_string_t what;
8510         cmdline_fixed_string_t mode;
8511 };
8512
8513 static void
8514 cmd_set_vf_traffic_parsed(void *parsed_result,
8515                        __rte_unused struct cmdline *cl,
8516                        __rte_unused void *data)
8517 {
8518         struct cmd_set_vf_traffic *res = parsed_result;
8519         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8520         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8521
8522         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8523 }
8524
8525 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8526         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8527                                  set, "set");
8528 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8529         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8530                                  port, "port");
8531 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8532         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8533                               port_id, UINT16);
8534 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8535         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8536                                  vf, "vf");
8537 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8538         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8539                               vf_id, UINT8);
8540 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8541         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8542                                  what, "tx#rx");
8543 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8544         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8545                                  mode, "on#off");
8546
8547 cmdline_parse_inst_t cmd_set_vf_traffic = {
8548         .f = cmd_set_vf_traffic_parsed,
8549         .data = NULL,
8550         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8551         .tokens = {
8552                 (void *)&cmd_setvf_traffic_set,
8553                 (void *)&cmd_setvf_traffic_port,
8554                 (void *)&cmd_setvf_traffic_portid,
8555                 (void *)&cmd_setvf_traffic_vf,
8556                 (void *)&cmd_setvf_traffic_vfid,
8557                 (void *)&cmd_setvf_traffic_what,
8558                 (void *)&cmd_setvf_traffic_mode,
8559                 NULL,
8560         },
8561 };
8562
8563 /* *** CONFIGURE VF RECEIVE MODE *** */
8564 struct cmd_set_vf_rxmode {
8565         cmdline_fixed_string_t set;
8566         cmdline_fixed_string_t port;
8567         portid_t port_id;
8568         cmdline_fixed_string_t vf;
8569         uint8_t vf_id;
8570         cmdline_fixed_string_t what;
8571         cmdline_fixed_string_t mode;
8572         cmdline_fixed_string_t on;
8573 };
8574
8575 static void
8576 cmd_set_vf_rxmode_parsed(void *parsed_result,
8577                        __rte_unused struct cmdline *cl,
8578                        __rte_unused void *data)
8579 {
8580         int ret = -ENOTSUP;
8581         uint16_t vf_rxmode = 0;
8582         struct cmd_set_vf_rxmode *res = parsed_result;
8583
8584         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8585         if (!strcmp(res->what,"rxmode")) {
8586                 if (!strcmp(res->mode, "AUPE"))
8587                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8588                 else if (!strcmp(res->mode, "ROPE"))
8589                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8590                 else if (!strcmp(res->mode, "BAM"))
8591                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8592                 else if (!strncmp(res->mode, "MPE",3))
8593                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8594         }
8595
8596         RTE_SET_USED(is_on);
8597
8598 #ifdef RTE_LIBRTE_IXGBE_PMD
8599         if (ret == -ENOTSUP)
8600                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8601                                                   vf_rxmode, (uint8_t)is_on);
8602 #endif
8603 #ifdef RTE_LIBRTE_BNXT_PMD
8604         if (ret == -ENOTSUP)
8605                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8606                                                  vf_rxmode, (uint8_t)is_on);
8607 #endif
8608         if (ret < 0)
8609                 printf("bad VF receive mode parameter, return code = %d \n",
8610                 ret);
8611 }
8612
8613 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8614         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8615                                  set, "set");
8616 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8617         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8618                                  port, "port");
8619 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8620         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8621                               port_id, UINT16);
8622 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8623         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8624                                  vf, "vf");
8625 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8626         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8627                               vf_id, UINT8);
8628 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8629         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8630                                  what, "rxmode");
8631 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8632         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8633                                  mode, "AUPE#ROPE#BAM#MPE");
8634 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8635         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8636                                  on, "on#off");
8637
8638 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8639         .f = cmd_set_vf_rxmode_parsed,
8640         .data = NULL,
8641         .help_str = "set port <port_id> vf <vf_id> rxmode "
8642                 "AUPE|ROPE|BAM|MPE on|off",
8643         .tokens = {
8644                 (void *)&cmd_set_vf_rxmode_set,
8645                 (void *)&cmd_set_vf_rxmode_port,
8646                 (void *)&cmd_set_vf_rxmode_portid,
8647                 (void *)&cmd_set_vf_rxmode_vf,
8648                 (void *)&cmd_set_vf_rxmode_vfid,
8649                 (void *)&cmd_set_vf_rxmode_what,
8650                 (void *)&cmd_set_vf_rxmode_mode,
8651                 (void *)&cmd_set_vf_rxmode_on,
8652                 NULL,
8653         },
8654 };
8655
8656 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8657 struct cmd_vf_mac_addr_result {
8658         cmdline_fixed_string_t mac_addr_cmd;
8659         cmdline_fixed_string_t what;
8660         cmdline_fixed_string_t port;
8661         uint16_t port_num;
8662         cmdline_fixed_string_t vf;
8663         uint8_t vf_num;
8664         struct rte_ether_addr address;
8665 };
8666
8667 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8668                 __rte_unused struct cmdline *cl,
8669                 __rte_unused void *data)
8670 {
8671         struct cmd_vf_mac_addr_result *res = parsed_result;
8672         int ret = -ENOTSUP;
8673
8674         if (strcmp(res->what, "add") != 0)
8675                 return;
8676
8677 #ifdef RTE_LIBRTE_I40E_PMD
8678         if (ret == -ENOTSUP)
8679                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8680                                                    &res->address);
8681 #endif
8682 #ifdef RTE_LIBRTE_BNXT_PMD
8683         if (ret == -ENOTSUP)
8684                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8685                                                 res->vf_num);
8686 #endif
8687
8688         if(ret < 0)
8689                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8690
8691 }
8692
8693 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8694         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8695                                 mac_addr_cmd,"mac_addr");
8696 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8697         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8698                                 what,"add");
8699 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8700         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8701                                 port,"port");
8702 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8703         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8704                                 port_num, UINT16);
8705 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8706         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8707                                 vf,"vf");
8708 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8709         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8710                                 vf_num, UINT8);
8711 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8712         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8713                                 address);
8714
8715 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8716         .f = cmd_vf_mac_addr_parsed,
8717         .data = (void *)0,
8718         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8719                 "Add MAC address filtering for a VF on port_id",
8720         .tokens = {
8721                 (void *)&cmd_vf_mac_addr_cmd,
8722                 (void *)&cmd_vf_mac_addr_what,
8723                 (void *)&cmd_vf_mac_addr_port,
8724                 (void *)&cmd_vf_mac_addr_portnum,
8725                 (void *)&cmd_vf_mac_addr_vf,
8726                 (void *)&cmd_vf_mac_addr_vfnum,
8727                 (void *)&cmd_vf_mac_addr_addr,
8728                 NULL,
8729         },
8730 };
8731
8732 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8733 struct cmd_vf_rx_vlan_filter {
8734         cmdline_fixed_string_t rx_vlan;
8735         cmdline_fixed_string_t what;
8736         uint16_t vlan_id;
8737         cmdline_fixed_string_t port;
8738         portid_t port_id;
8739         cmdline_fixed_string_t vf;
8740         uint64_t vf_mask;
8741 };
8742
8743 static void
8744 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8745                           __rte_unused struct cmdline *cl,
8746                           __rte_unused void *data)
8747 {
8748         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8749         int ret = -ENOTSUP;
8750
8751         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8752
8753 #ifdef RTE_LIBRTE_IXGBE_PMD
8754         if (ret == -ENOTSUP)
8755                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8756                                 res->vlan_id, res->vf_mask, is_add);
8757 #endif
8758 #ifdef RTE_LIBRTE_I40E_PMD
8759         if (ret == -ENOTSUP)
8760                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8761                                 res->vlan_id, res->vf_mask, is_add);
8762 #endif
8763 #ifdef RTE_LIBRTE_BNXT_PMD
8764         if (ret == -ENOTSUP)
8765                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8766                                 res->vlan_id, res->vf_mask, is_add);
8767 #endif
8768
8769         switch (ret) {
8770         case 0:
8771                 break;
8772         case -EINVAL:
8773                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8774                                 res->vlan_id, res->vf_mask);
8775                 break;
8776         case -ENODEV:
8777                 printf("invalid port_id %d\n", res->port_id);
8778                 break;
8779         case -ENOTSUP:
8780                 printf("function not implemented or supported\n");
8781                 break;
8782         default:
8783                 printf("programming error: (%s)\n", strerror(-ret));
8784         }
8785 }
8786
8787 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8788         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8789                                  rx_vlan, "rx_vlan");
8790 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8791         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8792                                  what, "add#rm");
8793 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8794         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8795                               vlan_id, UINT16);
8796 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8797         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8798                                  port, "port");
8799 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8800         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8801                               port_id, UINT16);
8802 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8803         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8804                                  vf, "vf");
8805 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8806         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8807                               vf_mask, UINT64);
8808
8809 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8810         .f = cmd_vf_rx_vlan_filter_parsed,
8811         .data = NULL,
8812         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8813                 "(vf_mask = hexadecimal VF mask)",
8814         .tokens = {
8815                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8816                 (void *)&cmd_vf_rx_vlan_filter_what,
8817                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8818                 (void *)&cmd_vf_rx_vlan_filter_port,
8819                 (void *)&cmd_vf_rx_vlan_filter_portid,
8820                 (void *)&cmd_vf_rx_vlan_filter_vf,
8821                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8822                 NULL,
8823         },
8824 };
8825
8826 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8827 struct cmd_queue_rate_limit_result {
8828         cmdline_fixed_string_t set;
8829         cmdline_fixed_string_t port;
8830         uint16_t port_num;
8831         cmdline_fixed_string_t queue;
8832         uint8_t queue_num;
8833         cmdline_fixed_string_t rate;
8834         uint16_t rate_num;
8835 };
8836
8837 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8838                 __rte_unused struct cmdline *cl,
8839                 __rte_unused void *data)
8840 {
8841         struct cmd_queue_rate_limit_result *res = parsed_result;
8842         int ret = 0;
8843
8844         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8845                 && (strcmp(res->queue, "queue") == 0)
8846                 && (strcmp(res->rate, "rate") == 0))
8847                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8848                                         res->rate_num);
8849         if (ret < 0)
8850                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8851
8852 }
8853
8854 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8855         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8856                                 set, "set");
8857 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8858         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8859                                 port, "port");
8860 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8861         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8862                                 port_num, UINT16);
8863 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8864         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8865                                 queue, "queue");
8866 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8867         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8868                                 queue_num, UINT8);
8869 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8870         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8871                                 rate, "rate");
8872 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8873         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8874                                 rate_num, UINT16);
8875
8876 cmdline_parse_inst_t cmd_queue_rate_limit = {
8877         .f = cmd_queue_rate_limit_parsed,
8878         .data = (void *)0,
8879         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8880                 "Set rate limit for a queue on port_id",
8881         .tokens = {
8882                 (void *)&cmd_queue_rate_limit_set,
8883                 (void *)&cmd_queue_rate_limit_port,
8884                 (void *)&cmd_queue_rate_limit_portnum,
8885                 (void *)&cmd_queue_rate_limit_queue,
8886                 (void *)&cmd_queue_rate_limit_queuenum,
8887                 (void *)&cmd_queue_rate_limit_rate,
8888                 (void *)&cmd_queue_rate_limit_ratenum,
8889                 NULL,
8890         },
8891 };
8892
8893 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8894 struct cmd_vf_rate_limit_result {
8895         cmdline_fixed_string_t set;
8896         cmdline_fixed_string_t port;
8897         uint16_t port_num;
8898         cmdline_fixed_string_t vf;
8899         uint8_t vf_num;
8900         cmdline_fixed_string_t rate;
8901         uint16_t rate_num;
8902         cmdline_fixed_string_t q_msk;
8903         uint64_t q_msk_val;
8904 };
8905
8906 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8907                 __rte_unused struct cmdline *cl,
8908                 __rte_unused void *data)
8909 {
8910         struct cmd_vf_rate_limit_result *res = parsed_result;
8911         int ret = 0;
8912
8913         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8914                 && (strcmp(res->vf, "vf") == 0)
8915                 && (strcmp(res->rate, "rate") == 0)
8916                 && (strcmp(res->q_msk, "queue_mask") == 0))
8917                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8918                                         res->rate_num, res->q_msk_val);
8919         if (ret < 0)
8920                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8921
8922 }
8923
8924 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8925         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8926                                 set, "set");
8927 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8928         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8929                                 port, "port");
8930 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8931         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8932                                 port_num, UINT16);
8933 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8934         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8935                                 vf, "vf");
8936 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8937         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8938                                 vf_num, UINT8);
8939 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8940         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8941                                 rate, "rate");
8942 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8943         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8944                                 rate_num, UINT16);
8945 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8946         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8947                                 q_msk, "queue_mask");
8948 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8949         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8950                                 q_msk_val, UINT64);
8951
8952 cmdline_parse_inst_t cmd_vf_rate_limit = {
8953         .f = cmd_vf_rate_limit_parsed,
8954         .data = (void *)0,
8955         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8956                 "queue_mask <queue_mask_value>: "
8957                 "Set rate limit for queues of VF on port_id",
8958         .tokens = {
8959                 (void *)&cmd_vf_rate_limit_set,
8960                 (void *)&cmd_vf_rate_limit_port,
8961                 (void *)&cmd_vf_rate_limit_portnum,
8962                 (void *)&cmd_vf_rate_limit_vf,
8963                 (void *)&cmd_vf_rate_limit_vfnum,
8964                 (void *)&cmd_vf_rate_limit_rate,
8965                 (void *)&cmd_vf_rate_limit_ratenum,
8966                 (void *)&cmd_vf_rate_limit_q_msk,
8967                 (void *)&cmd_vf_rate_limit_q_msk_val,
8968                 NULL,
8969         },
8970 };
8971
8972 /* *** ADD TUNNEL FILTER OF A PORT *** */
8973 struct cmd_tunnel_filter_result {
8974         cmdline_fixed_string_t cmd;
8975         cmdline_fixed_string_t what;
8976         portid_t port_id;
8977         struct rte_ether_addr outer_mac;
8978         struct rte_ether_addr inner_mac;
8979         cmdline_ipaddr_t ip_value;
8980         uint16_t inner_vlan;
8981         cmdline_fixed_string_t tunnel_type;
8982         cmdline_fixed_string_t filter_type;
8983         uint32_t tenant_id;
8984         uint16_t queue_num;
8985 };
8986
8987 static void
8988 cmd_tunnel_filter_parsed(void *parsed_result,
8989                           __rte_unused struct cmdline *cl,
8990                           __rte_unused void *data)
8991 {
8992         struct cmd_tunnel_filter_result *res = parsed_result;
8993         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8994         int ret = 0;
8995
8996         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8997
8998         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8999         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9000         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9001
9002         if (res->ip_value.family == AF_INET) {
9003                 tunnel_filter_conf.ip_addr.ipv4_addr =
9004                         res->ip_value.addr.ipv4.s_addr;
9005                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9006         } else {
9007                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9008                         &(res->ip_value.addr.ipv6),
9009                         sizeof(struct in6_addr));
9010                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9011         }
9012
9013         if (!strcmp(res->filter_type, "imac-ivlan"))
9014                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9015         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9016                 tunnel_filter_conf.filter_type =
9017                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9018         else if (!strcmp(res->filter_type, "imac-tenid"))
9019                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9020         else if (!strcmp(res->filter_type, "imac"))
9021                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9022         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9023                 tunnel_filter_conf.filter_type =
9024                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9025         else if (!strcmp(res->filter_type, "oip"))
9026                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9027         else if (!strcmp(res->filter_type, "iip"))
9028                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9029         else {
9030                 printf("The filter type is not supported");
9031                 return;
9032         }
9033
9034         if (!strcmp(res->tunnel_type, "vxlan"))
9035                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9036         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9037                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9038         else if (!strcmp(res->tunnel_type, "nvgre"))
9039                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9040         else if (!strcmp(res->tunnel_type, "ipingre"))
9041                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9042         else {
9043                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9044                 return;
9045         }
9046
9047         tunnel_filter_conf.tenant_id = res->tenant_id;
9048         tunnel_filter_conf.queue_id = res->queue_num;
9049         if (!strcmp(res->what, "add"))
9050                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9051                                         RTE_ETH_FILTER_TUNNEL,
9052                                         RTE_ETH_FILTER_ADD,
9053                                         &tunnel_filter_conf);
9054         else
9055                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9056                                         RTE_ETH_FILTER_TUNNEL,
9057                                         RTE_ETH_FILTER_DELETE,
9058                                         &tunnel_filter_conf);
9059         if (ret < 0)
9060                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9061                                 strerror(-ret));
9062
9063 }
9064 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9065         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9066         cmd, "tunnel_filter");
9067 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9068         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9069         what, "add#rm");
9070 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9071         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9072         port_id, UINT16);
9073 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9074         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9075         outer_mac);
9076 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9077         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9078         inner_mac);
9079 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9080         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9081         inner_vlan, UINT16);
9082 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9083         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9084         ip_value);
9085 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9086         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9087         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9088
9089 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9090         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9091         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9092                 "imac#omac-imac-tenid");
9093 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9094         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9095         tenant_id, UINT32);
9096 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9097         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9098         queue_num, UINT16);
9099
9100 cmdline_parse_inst_t cmd_tunnel_filter = {
9101         .f = cmd_tunnel_filter_parsed,
9102         .data = (void *)0,
9103         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9104                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9105                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9106                 "<queue_id>: Add/Rm tunnel filter of a port",
9107         .tokens = {
9108                 (void *)&cmd_tunnel_filter_cmd,
9109                 (void *)&cmd_tunnel_filter_what,
9110                 (void *)&cmd_tunnel_filter_port_id,
9111                 (void *)&cmd_tunnel_filter_outer_mac,
9112                 (void *)&cmd_tunnel_filter_inner_mac,
9113                 (void *)&cmd_tunnel_filter_ip_value,
9114                 (void *)&cmd_tunnel_filter_innner_vlan,
9115                 (void *)&cmd_tunnel_filter_tunnel_type,
9116                 (void *)&cmd_tunnel_filter_filter_type,
9117                 (void *)&cmd_tunnel_filter_tenant_id,
9118                 (void *)&cmd_tunnel_filter_queue_num,
9119                 NULL,
9120         },
9121 };
9122
9123 /* *** CONFIGURE TUNNEL UDP PORT *** */
9124 struct cmd_tunnel_udp_config {
9125         cmdline_fixed_string_t cmd;
9126         cmdline_fixed_string_t what;
9127         uint16_t udp_port;
9128         portid_t port_id;
9129 };
9130
9131 static void
9132 cmd_tunnel_udp_config_parsed(void *parsed_result,
9133                           __rte_unused struct cmdline *cl,
9134                           __rte_unused void *data)
9135 {
9136         struct cmd_tunnel_udp_config *res = parsed_result;
9137         struct rte_eth_udp_tunnel tunnel_udp;
9138         int ret;
9139
9140         tunnel_udp.udp_port = res->udp_port;
9141
9142         if (!strcmp(res->cmd, "rx_vxlan_port"))
9143                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9144
9145         if (!strcmp(res->what, "add"))
9146                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9147                                                       &tunnel_udp);
9148         else
9149                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9150                                                          &tunnel_udp);
9151
9152         if (ret < 0)
9153                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9154 }
9155
9156 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9157         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9158                                 cmd, "rx_vxlan_port");
9159 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9160         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9161                                 what, "add#rm");
9162 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9163         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9164                                 udp_port, UINT16);
9165 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9166         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9167                                 port_id, UINT16);
9168
9169 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9170         .f = cmd_tunnel_udp_config_parsed,
9171         .data = (void *)0,
9172         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9173                 "Add/Remove a tunneling UDP port filter",
9174         .tokens = {
9175                 (void *)&cmd_tunnel_udp_config_cmd,
9176                 (void *)&cmd_tunnel_udp_config_what,
9177                 (void *)&cmd_tunnel_udp_config_udp_port,
9178                 (void *)&cmd_tunnel_udp_config_port_id,
9179                 NULL,
9180         },
9181 };
9182
9183 struct cmd_config_tunnel_udp_port {
9184         cmdline_fixed_string_t port;
9185         cmdline_fixed_string_t config;
9186         portid_t port_id;
9187         cmdline_fixed_string_t udp_tunnel_port;
9188         cmdline_fixed_string_t action;
9189         cmdline_fixed_string_t tunnel_type;
9190         uint16_t udp_port;
9191 };
9192
9193 static void
9194 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9195                                __rte_unused struct cmdline *cl,
9196                                __rte_unused void *data)
9197 {
9198         struct cmd_config_tunnel_udp_port *res = parsed_result;
9199         struct rte_eth_udp_tunnel tunnel_udp;
9200         int ret = 0;
9201
9202         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9203                 return;
9204
9205         tunnel_udp.udp_port = res->udp_port;
9206
9207         if (!strcmp(res->tunnel_type, "vxlan")) {
9208                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9209         } else if (!strcmp(res->tunnel_type, "geneve")) {
9210                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9211         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9212                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9213         } else {
9214                 printf("Invalid tunnel type\n");
9215                 return;
9216         }
9217
9218         if (!strcmp(res->action, "add"))
9219                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9220                                                       &tunnel_udp);
9221         else
9222                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9223                                                          &tunnel_udp);
9224
9225         if (ret < 0)
9226                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9227 }
9228
9229 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9230         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9231                                  "port");
9232 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9233         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9234                                  "config");
9235 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9236         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9237                               UINT16);
9238 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9239         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9240                                  udp_tunnel_port,
9241                                  "udp_tunnel_port");
9242 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9243         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9244                                  "add#rm");
9245 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9246         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9247                                  "vxlan#geneve#vxlan-gpe");
9248 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9249         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9250                               UINT16);
9251
9252 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9253         .f = cmd_cfg_tunnel_udp_port_parsed,
9254         .data = NULL,
9255         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9256         .tokens = {
9257                 (void *)&cmd_config_tunnel_udp_port_port,
9258                 (void *)&cmd_config_tunnel_udp_port_config,
9259                 (void *)&cmd_config_tunnel_udp_port_port_id,
9260                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9261                 (void *)&cmd_config_tunnel_udp_port_action,
9262                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9263                 (void *)&cmd_config_tunnel_udp_port_value,
9264                 NULL,
9265         },
9266 };
9267
9268 /* *** GLOBAL CONFIG *** */
9269 struct cmd_global_config_result {
9270         cmdline_fixed_string_t cmd;
9271         portid_t port_id;
9272         cmdline_fixed_string_t cfg_type;
9273         uint8_t len;
9274 };
9275
9276 static void
9277 cmd_global_config_parsed(void *parsed_result,
9278                          __rte_unused struct cmdline *cl,
9279                          __rte_unused void *data)
9280 {
9281         struct cmd_global_config_result *res = parsed_result;
9282         struct rte_eth_global_cfg conf;
9283         int ret;
9284
9285         memset(&conf, 0, sizeof(conf));
9286         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9287         conf.cfg.gre_key_len = res->len;
9288         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9289                                       RTE_ETH_FILTER_SET, &conf);
9290         if (ret != 0)
9291                 printf("Global config error\n");
9292 }
9293
9294 cmdline_parse_token_string_t cmd_global_config_cmd =
9295         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9296                 "global_config");
9297 cmdline_parse_token_num_t cmd_global_config_port_id =
9298         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9299                                UINT16);
9300 cmdline_parse_token_string_t cmd_global_config_type =
9301         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9302                 cfg_type, "gre-key-len");
9303 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9304         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9305                 len, UINT8);
9306
9307 cmdline_parse_inst_t cmd_global_config = {
9308         .f = cmd_global_config_parsed,
9309         .data = (void *)NULL,
9310         .help_str = "global_config <port_id> gre-key-len <key_len>",
9311         .tokens = {
9312                 (void *)&cmd_global_config_cmd,
9313                 (void *)&cmd_global_config_port_id,
9314                 (void *)&cmd_global_config_type,
9315                 (void *)&cmd_global_config_gre_key_len,
9316                 NULL,
9317         },
9318 };
9319
9320 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9321 struct cmd_set_mirror_mask_result {
9322         cmdline_fixed_string_t set;
9323         cmdline_fixed_string_t port;
9324         portid_t port_id;
9325         cmdline_fixed_string_t mirror;
9326         uint8_t rule_id;
9327         cmdline_fixed_string_t what;
9328         cmdline_fixed_string_t value;
9329         cmdline_fixed_string_t dstpool;
9330         uint8_t dstpool_id;
9331         cmdline_fixed_string_t on;
9332 };
9333
9334 cmdline_parse_token_string_t cmd_mirror_mask_set =
9335         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9336                                 set, "set");
9337 cmdline_parse_token_string_t cmd_mirror_mask_port =
9338         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9339                                 port, "port");
9340 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9341         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9342                                 port_id, UINT16);
9343 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9344         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9345                                 mirror, "mirror-rule");
9346 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9347         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9348                                 rule_id, UINT8);
9349 cmdline_parse_token_string_t cmd_mirror_mask_what =
9350         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9351                                 what, "pool-mirror-up#pool-mirror-down"
9352                                       "#vlan-mirror");
9353 cmdline_parse_token_string_t cmd_mirror_mask_value =
9354         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9355                                 value, NULL);
9356 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9357         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9358                                 dstpool, "dst-pool");
9359 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9360         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9361                                 dstpool_id, UINT8);
9362 cmdline_parse_token_string_t cmd_mirror_mask_on =
9363         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9364                                 on, "on#off");
9365
9366 static void
9367 cmd_set_mirror_mask_parsed(void *parsed_result,
9368                        __rte_unused struct cmdline *cl,
9369                        __rte_unused void *data)
9370 {
9371         int ret,nb_item,i;
9372         struct cmd_set_mirror_mask_result *res = parsed_result;
9373         struct rte_eth_mirror_conf mr_conf;
9374
9375         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9376
9377         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9378
9379         mr_conf.dst_pool = res->dstpool_id;
9380
9381         if (!strcmp(res->what, "pool-mirror-up")) {
9382                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9383                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9384         } else if (!strcmp(res->what, "pool-mirror-down")) {
9385                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9386                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9387         } else if (!strcmp(res->what, "vlan-mirror")) {
9388                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9389                 nb_item = parse_item_list(res->value, "vlan",
9390                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9391                 if (nb_item <= 0)
9392                         return;
9393
9394                 for (i = 0; i < nb_item; i++) {
9395                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9396                                 printf("Invalid vlan_id: must be < 4096\n");
9397                                 return;
9398                         }
9399
9400                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9401                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9402                 }
9403         }
9404
9405         if (!strcmp(res->on, "on"))
9406                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9407                                                 res->rule_id, 1);
9408         else
9409                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9410                                                 res->rule_id, 0);
9411         if (ret < 0)
9412                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9413 }
9414
9415 cmdline_parse_inst_t cmd_set_mirror_mask = {
9416                 .f = cmd_set_mirror_mask_parsed,
9417                 .data = NULL,
9418                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9419                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9420                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9421                 .tokens = {
9422                         (void *)&cmd_mirror_mask_set,
9423                         (void *)&cmd_mirror_mask_port,
9424                         (void *)&cmd_mirror_mask_portid,
9425                         (void *)&cmd_mirror_mask_mirror,
9426                         (void *)&cmd_mirror_mask_ruleid,
9427                         (void *)&cmd_mirror_mask_what,
9428                         (void *)&cmd_mirror_mask_value,
9429                         (void *)&cmd_mirror_mask_dstpool,
9430                         (void *)&cmd_mirror_mask_poolid,
9431                         (void *)&cmd_mirror_mask_on,
9432                         NULL,
9433                 },
9434 };
9435
9436 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9437 struct cmd_set_mirror_link_result {
9438         cmdline_fixed_string_t set;
9439         cmdline_fixed_string_t port;
9440         portid_t port_id;
9441         cmdline_fixed_string_t mirror;
9442         uint8_t rule_id;
9443         cmdline_fixed_string_t what;
9444         cmdline_fixed_string_t dstpool;
9445         uint8_t dstpool_id;
9446         cmdline_fixed_string_t on;
9447 };
9448
9449 cmdline_parse_token_string_t cmd_mirror_link_set =
9450         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9451                                  set, "set");
9452 cmdline_parse_token_string_t cmd_mirror_link_port =
9453         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9454                                 port, "port");
9455 cmdline_parse_token_num_t cmd_mirror_link_portid =
9456         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9457                                 port_id, UINT16);
9458 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9459         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9460                                 mirror, "mirror-rule");
9461 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9462         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9463                             rule_id, UINT8);
9464 cmdline_parse_token_string_t cmd_mirror_link_what =
9465         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9466                                 what, "uplink-mirror#downlink-mirror");
9467 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9468         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9469                                 dstpool, "dst-pool");
9470 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9471         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9472                                 dstpool_id, UINT8);
9473 cmdline_parse_token_string_t cmd_mirror_link_on =
9474         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9475                                 on, "on#off");
9476
9477 static void
9478 cmd_set_mirror_link_parsed(void *parsed_result,
9479                        __rte_unused struct cmdline *cl,
9480                        __rte_unused void *data)
9481 {
9482         int ret;
9483         struct cmd_set_mirror_link_result *res = parsed_result;
9484         struct rte_eth_mirror_conf mr_conf;
9485
9486         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9487         if (!strcmp(res->what, "uplink-mirror"))
9488                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9489         else
9490                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9491
9492         mr_conf.dst_pool = res->dstpool_id;
9493
9494         if (!strcmp(res->on, "on"))
9495                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9496                                                 res->rule_id, 1);
9497         else
9498                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9499                                                 res->rule_id, 0);
9500
9501         /* check the return value and print it if is < 0 */
9502         if (ret < 0)
9503                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9504
9505 }
9506
9507 cmdline_parse_inst_t cmd_set_mirror_link = {
9508                 .f = cmd_set_mirror_link_parsed,
9509                 .data = NULL,
9510                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9511                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9512                 .tokens = {
9513                         (void *)&cmd_mirror_link_set,
9514                         (void *)&cmd_mirror_link_port,
9515                         (void *)&cmd_mirror_link_portid,
9516                         (void *)&cmd_mirror_link_mirror,
9517                         (void *)&cmd_mirror_link_ruleid,
9518                         (void *)&cmd_mirror_link_what,
9519                         (void *)&cmd_mirror_link_dstpool,
9520                         (void *)&cmd_mirror_link_poolid,
9521                         (void *)&cmd_mirror_link_on,
9522                         NULL,
9523                 },
9524 };
9525
9526 /* *** RESET VM MIRROR RULE *** */
9527 struct cmd_rm_mirror_rule_result {
9528         cmdline_fixed_string_t reset;
9529         cmdline_fixed_string_t port;
9530         portid_t port_id;
9531         cmdline_fixed_string_t mirror;
9532         uint8_t rule_id;
9533 };
9534
9535 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9536         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9537                                  reset, "reset");
9538 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9539         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9540                                 port, "port");
9541 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9542         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9543                                 port_id, UINT16);
9544 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9545         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9546                                 mirror, "mirror-rule");
9547 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9548         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9549                                 rule_id, UINT8);
9550
9551 static void
9552 cmd_reset_mirror_rule_parsed(void *parsed_result,
9553                        __rte_unused struct cmdline *cl,
9554                        __rte_unused void *data)
9555 {
9556         int ret;
9557         struct cmd_set_mirror_link_result *res = parsed_result;
9558         /* check rule_id */
9559         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9560         if(ret < 0)
9561                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9562 }
9563
9564 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9565                 .f = cmd_reset_mirror_rule_parsed,
9566                 .data = NULL,
9567                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9568                 .tokens = {
9569                         (void *)&cmd_rm_mirror_rule_reset,
9570                         (void *)&cmd_rm_mirror_rule_port,
9571                         (void *)&cmd_rm_mirror_rule_portid,
9572                         (void *)&cmd_rm_mirror_rule_mirror,
9573                         (void *)&cmd_rm_mirror_rule_ruleid,
9574                         NULL,
9575                 },
9576 };
9577
9578 /* ******************************************************************************** */
9579
9580 struct cmd_dump_result {
9581         cmdline_fixed_string_t dump;
9582 };
9583
9584 static void
9585 dump_struct_sizes(void)
9586 {
9587 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9588         DUMP_SIZE(struct rte_mbuf);
9589         DUMP_SIZE(struct rte_mempool);
9590         DUMP_SIZE(struct rte_ring);
9591 #undef DUMP_SIZE
9592 }
9593
9594
9595 /* Dump the socket memory statistics on console */
9596 static void
9597 dump_socket_mem(FILE *f)
9598 {
9599         struct rte_malloc_socket_stats socket_stats;
9600         unsigned int i;
9601         size_t total = 0;
9602         size_t alloc = 0;
9603         size_t free = 0;
9604         unsigned int n_alloc = 0;
9605         unsigned int n_free = 0;
9606         static size_t last_allocs;
9607         static size_t last_total;
9608
9609
9610         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9611                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9612                     !socket_stats.heap_totalsz_bytes)
9613                         continue;
9614                 total += socket_stats.heap_totalsz_bytes;
9615                 alloc += socket_stats.heap_allocsz_bytes;
9616                 free += socket_stats.heap_freesz_bytes;
9617                 n_alloc += socket_stats.alloc_count;
9618                 n_free += socket_stats.free_count;
9619                 fprintf(f,
9620                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9621                         i,
9622                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9623                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9624                         (double)socket_stats.heap_allocsz_bytes * 100 /
9625                         (double)socket_stats.heap_totalsz_bytes,
9626                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9627                         socket_stats.alloc_count,
9628                         socket_stats.free_count);
9629         }
9630         fprintf(f,
9631                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9632                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9633                 (double)alloc * 100 / (double)total,
9634                 (double)free / (1024 * 1024),
9635                 n_alloc, n_free);
9636         if (last_allocs)
9637                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9638                         ((double)total - (double)last_total) / (1024 * 1024),
9639                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9640         last_allocs = alloc;
9641         last_total = total;
9642 }
9643
9644 static void cmd_dump_parsed(void *parsed_result,
9645                             __rte_unused struct cmdline *cl,
9646                             __rte_unused void *data)
9647 {
9648         struct cmd_dump_result *res = parsed_result;
9649
9650         if (!strcmp(res->dump, "dump_physmem"))
9651                 rte_dump_physmem_layout(stdout);
9652         else if (!strcmp(res->dump, "dump_socket_mem"))
9653                 dump_socket_mem(stdout);
9654         else if (!strcmp(res->dump, "dump_memzone"))
9655                 rte_memzone_dump(stdout);
9656         else if (!strcmp(res->dump, "dump_struct_sizes"))
9657                 dump_struct_sizes();
9658         else if (!strcmp(res->dump, "dump_ring"))
9659                 rte_ring_list_dump(stdout);
9660         else if (!strcmp(res->dump, "dump_mempool"))
9661                 rte_mempool_list_dump(stdout);
9662         else if (!strcmp(res->dump, "dump_devargs"))
9663                 rte_devargs_dump(stdout);
9664         else if (!strcmp(res->dump, "dump_log_types"))
9665                 rte_log_dump(stdout);
9666 }
9667
9668 cmdline_parse_token_string_t cmd_dump_dump =
9669         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9670                 "dump_physmem#"
9671                 "dump_memzone#"
9672                 "dump_socket_mem#"
9673                 "dump_struct_sizes#"
9674                 "dump_ring#"
9675                 "dump_mempool#"
9676                 "dump_devargs#"
9677                 "dump_log_types");
9678
9679 cmdline_parse_inst_t cmd_dump = {
9680         .f = cmd_dump_parsed,  /* function to call */
9681         .data = NULL,      /* 2nd arg of func */
9682         .help_str = "Dump status",
9683         .tokens = {        /* token list, NULL terminated */
9684                 (void *)&cmd_dump_dump,
9685                 NULL,
9686         },
9687 };
9688
9689 /* ******************************************************************************** */
9690
9691 struct cmd_dump_one_result {
9692         cmdline_fixed_string_t dump;
9693         cmdline_fixed_string_t name;
9694 };
9695
9696 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9697                                 __rte_unused void *data)
9698 {
9699         struct cmd_dump_one_result *res = parsed_result;
9700
9701         if (!strcmp(res->dump, "dump_ring")) {
9702                 struct rte_ring *r;
9703                 r = rte_ring_lookup(res->name);
9704                 if (r == NULL) {
9705                         cmdline_printf(cl, "Cannot find ring\n");
9706                         return;
9707                 }
9708                 rte_ring_dump(stdout, r);
9709         } else if (!strcmp(res->dump, "dump_mempool")) {
9710                 struct rte_mempool *mp;
9711                 mp = rte_mempool_lookup(res->name);
9712                 if (mp == NULL) {
9713                         cmdline_printf(cl, "Cannot find mempool\n");
9714                         return;
9715                 }
9716                 rte_mempool_dump(stdout, mp);
9717         }
9718 }
9719
9720 cmdline_parse_token_string_t cmd_dump_one_dump =
9721         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9722                                  "dump_ring#dump_mempool");
9723
9724 cmdline_parse_token_string_t cmd_dump_one_name =
9725         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9726
9727 cmdline_parse_inst_t cmd_dump_one = {
9728         .f = cmd_dump_one_parsed,  /* function to call */
9729         .data = NULL,      /* 2nd arg of func */
9730         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9731         .tokens = {        /* token list, NULL terminated */
9732                 (void *)&cmd_dump_one_dump,
9733                 (void *)&cmd_dump_one_name,
9734                 NULL,
9735         },
9736 };
9737
9738 /* *** Add/Del syn filter *** */
9739 struct cmd_syn_filter_result {
9740         cmdline_fixed_string_t filter;
9741         portid_t port_id;
9742         cmdline_fixed_string_t ops;
9743         cmdline_fixed_string_t priority;
9744         cmdline_fixed_string_t high;
9745         cmdline_fixed_string_t queue;
9746         uint16_t queue_id;
9747 };
9748
9749 static void
9750 cmd_syn_filter_parsed(void *parsed_result,
9751                         __rte_unused struct cmdline *cl,
9752                         __rte_unused void *data)
9753 {
9754         struct cmd_syn_filter_result *res = parsed_result;
9755         struct rte_eth_syn_filter syn_filter;
9756         int ret = 0;
9757
9758         ret = rte_eth_dev_filter_supported(res->port_id,
9759                                         RTE_ETH_FILTER_SYN);
9760         if (ret < 0) {
9761                 printf("syn filter is not supported on port %u.\n",
9762                                 res->port_id);
9763                 return;
9764         }
9765
9766         memset(&syn_filter, 0, sizeof(syn_filter));
9767
9768         if (!strcmp(res->ops, "add")) {
9769                 if (!strcmp(res->high, "high"))
9770                         syn_filter.hig_pri = 1;
9771                 else
9772                         syn_filter.hig_pri = 0;
9773
9774                 syn_filter.queue = res->queue_id;
9775                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9776                                                 RTE_ETH_FILTER_SYN,
9777                                                 RTE_ETH_FILTER_ADD,
9778                                                 &syn_filter);
9779         } else
9780                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9781                                                 RTE_ETH_FILTER_SYN,
9782                                                 RTE_ETH_FILTER_DELETE,
9783                                                 &syn_filter);
9784
9785         if (ret < 0)
9786                 printf("syn filter programming error: (%s)\n",
9787                                 strerror(-ret));
9788 }
9789
9790 cmdline_parse_token_string_t cmd_syn_filter_filter =
9791         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9792         filter, "syn_filter");
9793 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9794         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9795         port_id, UINT16);
9796 cmdline_parse_token_string_t cmd_syn_filter_ops =
9797         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9798         ops, "add#del");
9799 cmdline_parse_token_string_t cmd_syn_filter_priority =
9800         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9801                                 priority, "priority");
9802 cmdline_parse_token_string_t cmd_syn_filter_high =
9803         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9804                                 high, "high#low");
9805 cmdline_parse_token_string_t cmd_syn_filter_queue =
9806         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9807                                 queue, "queue");
9808 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9809         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9810                                 queue_id, UINT16);
9811
9812 cmdline_parse_inst_t cmd_syn_filter = {
9813         .f = cmd_syn_filter_parsed,
9814         .data = NULL,
9815         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9816                 "<queue_id>: Add/Delete syn filter",
9817         .tokens = {
9818                 (void *)&cmd_syn_filter_filter,
9819                 (void *)&cmd_syn_filter_port_id,
9820                 (void *)&cmd_syn_filter_ops,
9821                 (void *)&cmd_syn_filter_priority,
9822                 (void *)&cmd_syn_filter_high,
9823                 (void *)&cmd_syn_filter_queue,
9824                 (void *)&cmd_syn_filter_queue_id,
9825                 NULL,
9826         },
9827 };
9828
9829 /* *** queue region set *** */
9830 struct cmd_queue_region_result {
9831         cmdline_fixed_string_t set;
9832         cmdline_fixed_string_t port;
9833         portid_t port_id;
9834         cmdline_fixed_string_t cmd;
9835         cmdline_fixed_string_t region;
9836         uint8_t  region_id;
9837         cmdline_fixed_string_t queue_start_index;
9838         uint8_t  queue_id;
9839         cmdline_fixed_string_t queue_num;
9840         uint8_t  queue_num_value;
9841 };
9842
9843 static void
9844 cmd_queue_region_parsed(void *parsed_result,
9845                         __rte_unused struct cmdline *cl,
9846                         __rte_unused void *data)
9847 {
9848         struct cmd_queue_region_result *res = parsed_result;
9849         int ret = -ENOTSUP;
9850 #ifdef RTE_LIBRTE_I40E_PMD
9851         struct rte_pmd_i40e_queue_region_conf region_conf;
9852         enum rte_pmd_i40e_queue_region_op op_type;
9853 #endif
9854
9855         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9856                 return;
9857
9858 #ifdef RTE_LIBRTE_I40E_PMD
9859         memset(&region_conf, 0, sizeof(region_conf));
9860         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9861         region_conf.region_id = res->region_id;
9862         region_conf.queue_num = res->queue_num_value;
9863         region_conf.queue_start_index = res->queue_id;
9864
9865         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9866                                 op_type, &region_conf);
9867 #endif
9868
9869         switch (ret) {
9870         case 0:
9871                 break;
9872         case -ENOTSUP:
9873                 printf("function not implemented or supported\n");
9874                 break;
9875         default:
9876                 printf("queue region config error: (%s)\n", strerror(-ret));
9877         }
9878 }
9879
9880 cmdline_parse_token_string_t cmd_queue_region_set =
9881 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9882                 set, "set");
9883 cmdline_parse_token_string_t cmd_queue_region_port =
9884         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9885 cmdline_parse_token_num_t cmd_queue_region_port_id =
9886         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9887                                 port_id, UINT16);
9888 cmdline_parse_token_string_t cmd_queue_region_cmd =
9889         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9890                                  cmd, "queue-region");
9891 cmdline_parse_token_string_t cmd_queue_region_id =
9892         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9893                                 region, "region_id");
9894 cmdline_parse_token_num_t cmd_queue_region_index =
9895         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9896                                 region_id, UINT8);
9897 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9898         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9899                                 queue_start_index, "queue_start_index");
9900 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9901         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9902                                 queue_id, UINT8);
9903 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9904         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9905                                 queue_num, "queue_num");
9906 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9907         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9908                                 queue_num_value, UINT8);
9909
9910 cmdline_parse_inst_t cmd_queue_region = {
9911         .f = cmd_queue_region_parsed,
9912         .data = NULL,
9913         .help_str = "set port <port_id> queue-region region_id <value> "
9914                 "queue_start_index <value> queue_num <value>: Set a queue region",
9915         .tokens = {
9916                 (void *)&cmd_queue_region_set,
9917                 (void *)&cmd_queue_region_port,
9918                 (void *)&cmd_queue_region_port_id,
9919                 (void *)&cmd_queue_region_cmd,
9920                 (void *)&cmd_queue_region_id,
9921                 (void *)&cmd_queue_region_index,
9922                 (void *)&cmd_queue_region_queue_start_index,
9923                 (void *)&cmd_queue_region_queue_id,
9924                 (void *)&cmd_queue_region_queue_num,
9925                 (void *)&cmd_queue_region_queue_num_value,
9926                 NULL,
9927         },
9928 };
9929
9930 /* *** queue region and flowtype set *** */
9931 struct cmd_region_flowtype_result {
9932         cmdline_fixed_string_t set;
9933         cmdline_fixed_string_t port;
9934         portid_t port_id;
9935         cmdline_fixed_string_t cmd;
9936         cmdline_fixed_string_t region;
9937         uint8_t  region_id;
9938         cmdline_fixed_string_t flowtype;
9939         uint8_t  flowtype_id;
9940 };
9941
9942 static void
9943 cmd_region_flowtype_parsed(void *parsed_result,
9944                         __rte_unused struct cmdline *cl,
9945                         __rte_unused void *data)
9946 {
9947         struct cmd_region_flowtype_result *res = parsed_result;
9948         int ret = -ENOTSUP;
9949 #ifdef RTE_LIBRTE_I40E_PMD
9950         struct rte_pmd_i40e_queue_region_conf region_conf;
9951         enum rte_pmd_i40e_queue_region_op op_type;
9952 #endif
9953
9954         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9955                 return;
9956
9957 #ifdef RTE_LIBRTE_I40E_PMD
9958         memset(&region_conf, 0, sizeof(region_conf));
9959
9960         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9961         region_conf.region_id = res->region_id;
9962         region_conf.hw_flowtype = res->flowtype_id;
9963
9964         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9965                         op_type, &region_conf);
9966 #endif
9967
9968         switch (ret) {
9969         case 0:
9970                 break;
9971         case -ENOTSUP:
9972                 printf("function not implemented or supported\n");
9973                 break;
9974         default:
9975                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9976         }
9977 }
9978
9979 cmdline_parse_token_string_t cmd_region_flowtype_set =
9980 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9981                                 set, "set");
9982 cmdline_parse_token_string_t cmd_region_flowtype_port =
9983         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9984                                 port, "port");
9985 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9986         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9987                                 port_id, UINT16);
9988 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9989         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9990                                 cmd, "queue-region");
9991 cmdline_parse_token_string_t cmd_region_flowtype_index =
9992         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9993                                 region, "region_id");
9994 cmdline_parse_token_num_t cmd_region_flowtype_id =
9995         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9996                                 region_id, UINT8);
9997 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9998         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9999                                 flowtype, "flowtype");
10000 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10001         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10002                                 flowtype_id, UINT8);
10003 cmdline_parse_inst_t cmd_region_flowtype = {
10004         .f = cmd_region_flowtype_parsed,
10005         .data = NULL,
10006         .help_str = "set port <port_id> queue-region region_id <value> "
10007                 "flowtype <value>: Set a flowtype region index",
10008         .tokens = {
10009                 (void *)&cmd_region_flowtype_set,
10010                 (void *)&cmd_region_flowtype_port,
10011                 (void *)&cmd_region_flowtype_port_index,
10012                 (void *)&cmd_region_flowtype_cmd,
10013                 (void *)&cmd_region_flowtype_index,
10014                 (void *)&cmd_region_flowtype_id,
10015                 (void *)&cmd_region_flowtype_flow_index,
10016                 (void *)&cmd_region_flowtype_flow_id,
10017                 NULL,
10018         },
10019 };
10020
10021 /* *** User Priority (UP) to queue region (region_id) set *** */
10022 struct cmd_user_priority_region_result {
10023         cmdline_fixed_string_t set;
10024         cmdline_fixed_string_t port;
10025         portid_t port_id;
10026         cmdline_fixed_string_t cmd;
10027         cmdline_fixed_string_t user_priority;
10028         uint8_t  user_priority_id;
10029         cmdline_fixed_string_t region;
10030         uint8_t  region_id;
10031 };
10032
10033 static void
10034 cmd_user_priority_region_parsed(void *parsed_result,
10035                         __rte_unused struct cmdline *cl,
10036                         __rte_unused void *data)
10037 {
10038         struct cmd_user_priority_region_result *res = parsed_result;
10039         int ret = -ENOTSUP;
10040 #ifdef RTE_LIBRTE_I40E_PMD
10041         struct rte_pmd_i40e_queue_region_conf region_conf;
10042         enum rte_pmd_i40e_queue_region_op op_type;
10043 #endif
10044
10045         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10046                 return;
10047
10048 #ifdef RTE_LIBRTE_I40E_PMD
10049         memset(&region_conf, 0, sizeof(region_conf));
10050         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10051         region_conf.user_priority = res->user_priority_id;
10052         region_conf.region_id = res->region_id;
10053
10054         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10055                                 op_type, &region_conf);
10056 #endif
10057
10058         switch (ret) {
10059         case 0:
10060                 break;
10061         case -ENOTSUP:
10062                 printf("function not implemented or supported\n");
10063                 break;
10064         default:
10065                 printf("user_priority region config error: (%s)\n",
10066                                 strerror(-ret));
10067         }
10068 }
10069
10070 cmdline_parse_token_string_t cmd_user_priority_region_set =
10071         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10072                                 set, "set");
10073 cmdline_parse_token_string_t cmd_user_priority_region_port =
10074         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10075                                 port, "port");
10076 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10077         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10078                                 port_id, UINT16);
10079 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10080         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10081                                 cmd, "queue-region");
10082 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10083         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10084                                 user_priority, "UP");
10085 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10086         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10087                                 user_priority_id, UINT8);
10088 cmdline_parse_token_string_t cmd_user_priority_region_region =
10089         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10090                                 region, "region_id");
10091 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10092         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10093                                 region_id, UINT8);
10094
10095 cmdline_parse_inst_t cmd_user_priority_region = {
10096         .f = cmd_user_priority_region_parsed,
10097         .data = NULL,
10098         .help_str = "set port <port_id> queue-region UP <value> "
10099                 "region_id <value>: Set the mapping of User Priority (UP) "
10100                 "to queue region (region_id) ",
10101         .tokens = {
10102                 (void *)&cmd_user_priority_region_set,
10103                 (void *)&cmd_user_priority_region_port,
10104                 (void *)&cmd_user_priority_region_port_index,
10105                 (void *)&cmd_user_priority_region_cmd,
10106                 (void *)&cmd_user_priority_region_UP,
10107                 (void *)&cmd_user_priority_region_UP_id,
10108                 (void *)&cmd_user_priority_region_region,
10109                 (void *)&cmd_user_priority_region_region_id,
10110                 NULL,
10111         },
10112 };
10113
10114 /* *** flush all queue region related configuration *** */
10115 struct cmd_flush_queue_region_result {
10116         cmdline_fixed_string_t set;
10117         cmdline_fixed_string_t port;
10118         portid_t port_id;
10119         cmdline_fixed_string_t cmd;
10120         cmdline_fixed_string_t flush;
10121         cmdline_fixed_string_t what;
10122 };
10123
10124 static void
10125 cmd_flush_queue_region_parsed(void *parsed_result,
10126                         __rte_unused struct cmdline *cl,
10127                         __rte_unused void *data)
10128 {
10129         struct cmd_flush_queue_region_result *res = parsed_result;
10130         int ret = -ENOTSUP;
10131 #ifdef RTE_LIBRTE_I40E_PMD
10132         struct rte_pmd_i40e_queue_region_conf region_conf;
10133         enum rte_pmd_i40e_queue_region_op op_type;
10134 #endif
10135
10136         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10137                 return;
10138
10139 #ifdef RTE_LIBRTE_I40E_PMD
10140         memset(&region_conf, 0, sizeof(region_conf));
10141
10142         if (strcmp(res->what, "on") == 0)
10143                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10144         else
10145                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10146
10147         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10148                                 op_type, &region_conf);
10149 #endif
10150
10151         switch (ret) {
10152         case 0:
10153                 break;
10154         case -ENOTSUP:
10155                 printf("function not implemented or supported\n");
10156                 break;
10157         default:
10158                 printf("queue region config flush error: (%s)\n",
10159                                 strerror(-ret));
10160         }
10161 }
10162
10163 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10164         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10165                                 set, "set");
10166 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10167         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10168                                 port, "port");
10169 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10170         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10171                                 port_id, UINT16);
10172 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10173         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10174                                 cmd, "queue-region");
10175 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10176         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10177                                 flush, "flush");
10178 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10179         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10180                                 what, "on#off");
10181
10182 cmdline_parse_inst_t cmd_flush_queue_region = {
10183         .f = cmd_flush_queue_region_parsed,
10184         .data = NULL,
10185         .help_str = "set port <port_id> queue-region flush on|off"
10186                 ": flush all queue region related configuration",
10187         .tokens = {
10188                 (void *)&cmd_flush_queue_region_set,
10189                 (void *)&cmd_flush_queue_region_port,
10190                 (void *)&cmd_flush_queue_region_port_index,
10191                 (void *)&cmd_flush_queue_region_cmd,
10192                 (void *)&cmd_flush_queue_region_flush,
10193                 (void *)&cmd_flush_queue_region_what,
10194                 NULL,
10195         },
10196 };
10197
10198 /* *** get all queue region related configuration info *** */
10199 struct cmd_show_queue_region_info {
10200         cmdline_fixed_string_t show;
10201         cmdline_fixed_string_t port;
10202         portid_t port_id;
10203         cmdline_fixed_string_t cmd;
10204 };
10205
10206 static void
10207 cmd_show_queue_region_info_parsed(void *parsed_result,
10208                         __rte_unused struct cmdline *cl,
10209                         __rte_unused void *data)
10210 {
10211         struct cmd_show_queue_region_info *res = parsed_result;
10212         int ret = -ENOTSUP;
10213 #ifdef RTE_LIBRTE_I40E_PMD
10214         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10215         enum rte_pmd_i40e_queue_region_op op_type;
10216 #endif
10217
10218         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10219                 return;
10220
10221 #ifdef RTE_LIBRTE_I40E_PMD
10222         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10223
10224         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10225
10226         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10227                                         op_type, &rte_pmd_regions);
10228
10229         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10230 #endif
10231
10232         switch (ret) {
10233         case 0:
10234                 break;
10235         case -ENOTSUP:
10236                 printf("function not implemented or supported\n");
10237                 break;
10238         default:
10239                 printf("queue region config info show error: (%s)\n",
10240                                 strerror(-ret));
10241         }
10242 }
10243
10244 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10245 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10246                                 show, "show");
10247 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10248         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10249                                 port, "port");
10250 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10251         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10252                                 port_id, UINT16);
10253 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10254         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10255                                 cmd, "queue-region");
10256
10257 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10258         .f = cmd_show_queue_region_info_parsed,
10259         .data = NULL,
10260         .help_str = "show port <port_id> queue-region"
10261                 ": show all queue region related configuration info",
10262         .tokens = {
10263                 (void *)&cmd_show_queue_region_info_get,
10264                 (void *)&cmd_show_queue_region_info_port,
10265                 (void *)&cmd_show_queue_region_info_port_index,
10266                 (void *)&cmd_show_queue_region_info_cmd,
10267                 NULL,
10268         },
10269 };
10270
10271 /* *** ADD/REMOVE A 2tuple FILTER *** */
10272 struct cmd_2tuple_filter_result {
10273         cmdline_fixed_string_t filter;
10274         portid_t port_id;
10275         cmdline_fixed_string_t ops;
10276         cmdline_fixed_string_t dst_port;
10277         uint16_t dst_port_value;
10278         cmdline_fixed_string_t protocol;
10279         uint8_t protocol_value;
10280         cmdline_fixed_string_t mask;
10281         uint8_t  mask_value;
10282         cmdline_fixed_string_t tcp_flags;
10283         uint8_t tcp_flags_value;
10284         cmdline_fixed_string_t priority;
10285         uint8_t  priority_value;
10286         cmdline_fixed_string_t queue;
10287         uint16_t  queue_id;
10288 };
10289
10290 static void
10291 cmd_2tuple_filter_parsed(void *parsed_result,
10292                         __rte_unused struct cmdline *cl,
10293                         __rte_unused void *data)
10294 {
10295         struct rte_eth_ntuple_filter filter;
10296         struct cmd_2tuple_filter_result *res = parsed_result;
10297         int ret = 0;
10298
10299         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10300         if (ret < 0) {
10301                 printf("ntuple filter is not supported on port %u.\n",
10302                         res->port_id);
10303                 return;
10304         }
10305
10306         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10307
10308         filter.flags = RTE_2TUPLE_FLAGS;
10309         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10310         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10311         filter.proto = res->protocol_value;
10312         filter.priority = res->priority_value;
10313         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10314                 printf("nonzero tcp_flags is only meaningful"
10315                         " when protocol is TCP.\n");
10316                 return;
10317         }
10318         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10319                 printf("invalid TCP flags.\n");
10320                 return;
10321         }
10322
10323         if (res->tcp_flags_value != 0) {
10324                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10325                 filter.tcp_flags = res->tcp_flags_value;
10326         }
10327
10328         /* need convert to big endian. */
10329         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10330         filter.queue = res->queue_id;
10331
10332         if (!strcmp(res->ops, "add"))
10333                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10334                                 RTE_ETH_FILTER_NTUPLE,
10335                                 RTE_ETH_FILTER_ADD,
10336                                 &filter);
10337         else
10338                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10339                                 RTE_ETH_FILTER_NTUPLE,
10340                                 RTE_ETH_FILTER_DELETE,
10341                                 &filter);
10342         if (ret < 0)
10343                 printf("2tuple filter programming error: (%s)\n",
10344                         strerror(-ret));
10345
10346 }
10347
10348 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10349         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10350                                  filter, "2tuple_filter");
10351 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10352         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10353                                 port_id, UINT16);
10354 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10355         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10356                                  ops, "add#del");
10357 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10358         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10359                                 dst_port, "dst_port");
10360 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10361         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10362                                 dst_port_value, UINT16);
10363 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10364         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10365                                 protocol, "protocol");
10366 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10367         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10368                                 protocol_value, UINT8);
10369 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10370         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10371                                 mask, "mask");
10372 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10373         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10374                                 mask_value, INT8);
10375 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10376         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10377                                 tcp_flags, "tcp_flags");
10378 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10379         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10380                                 tcp_flags_value, UINT8);
10381 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10382         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10383                                 priority, "priority");
10384 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10385         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10386                                 priority_value, UINT8);
10387 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10388         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10389                                 queue, "queue");
10390 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10391         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10392                                 queue_id, UINT16);
10393
10394 cmdline_parse_inst_t cmd_2tuple_filter = {
10395         .f = cmd_2tuple_filter_parsed,
10396         .data = NULL,
10397         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10398                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10399                 "<queue_id>: Add a 2tuple filter",
10400         .tokens = {
10401                 (void *)&cmd_2tuple_filter_filter,
10402                 (void *)&cmd_2tuple_filter_port_id,
10403                 (void *)&cmd_2tuple_filter_ops,
10404                 (void *)&cmd_2tuple_filter_dst_port,
10405                 (void *)&cmd_2tuple_filter_dst_port_value,
10406                 (void *)&cmd_2tuple_filter_protocol,
10407                 (void *)&cmd_2tuple_filter_protocol_value,
10408                 (void *)&cmd_2tuple_filter_mask,
10409                 (void *)&cmd_2tuple_filter_mask_value,
10410                 (void *)&cmd_2tuple_filter_tcp_flags,
10411                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10412                 (void *)&cmd_2tuple_filter_priority,
10413                 (void *)&cmd_2tuple_filter_priority_value,
10414                 (void *)&cmd_2tuple_filter_queue,
10415                 (void *)&cmd_2tuple_filter_queue_id,
10416                 NULL,
10417         },
10418 };
10419
10420 /* *** ADD/REMOVE A 5tuple FILTER *** */
10421 struct cmd_5tuple_filter_result {
10422         cmdline_fixed_string_t filter;
10423         portid_t port_id;
10424         cmdline_fixed_string_t ops;
10425         cmdline_fixed_string_t dst_ip;
10426         cmdline_ipaddr_t dst_ip_value;
10427         cmdline_fixed_string_t src_ip;
10428         cmdline_ipaddr_t src_ip_value;
10429         cmdline_fixed_string_t dst_port;
10430         uint16_t dst_port_value;
10431         cmdline_fixed_string_t src_port;
10432         uint16_t src_port_value;
10433         cmdline_fixed_string_t protocol;
10434         uint8_t protocol_value;
10435         cmdline_fixed_string_t mask;
10436         uint8_t  mask_value;
10437         cmdline_fixed_string_t tcp_flags;
10438         uint8_t tcp_flags_value;
10439         cmdline_fixed_string_t priority;
10440         uint8_t  priority_value;
10441         cmdline_fixed_string_t queue;
10442         uint16_t  queue_id;
10443 };
10444
10445 static void
10446 cmd_5tuple_filter_parsed(void *parsed_result,
10447                         __rte_unused struct cmdline *cl,
10448                         __rte_unused void *data)
10449 {
10450         struct rte_eth_ntuple_filter filter;
10451         struct cmd_5tuple_filter_result *res = parsed_result;
10452         int ret = 0;
10453
10454         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10455         if (ret < 0) {
10456                 printf("ntuple filter is not supported on port %u.\n",
10457                         res->port_id);
10458                 return;
10459         }
10460
10461         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10462
10463         filter.flags = RTE_5TUPLE_FLAGS;
10464         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10465         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10466         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10467         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10468         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10469         filter.proto = res->protocol_value;
10470         filter.priority = res->priority_value;
10471         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10472                 printf("nonzero tcp_flags is only meaningful"
10473                         " when protocol is TCP.\n");
10474                 return;
10475         }
10476         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10477                 printf("invalid TCP flags.\n");
10478                 return;
10479         }
10480
10481         if (res->tcp_flags_value != 0) {
10482                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10483                 filter.tcp_flags = res->tcp_flags_value;
10484         }
10485
10486         if (res->dst_ip_value.family == AF_INET)
10487                 /* no need to convert, already big endian. */
10488                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10489         else {
10490                 if (filter.dst_ip_mask == 0) {
10491                         printf("can not support ipv6 involved compare.\n");
10492                         return;
10493                 }
10494                 filter.dst_ip = 0;
10495         }
10496
10497         if (res->src_ip_value.family == AF_INET)
10498                 /* no need to convert, already big endian. */
10499                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10500         else {
10501                 if (filter.src_ip_mask == 0) {
10502                         printf("can not support ipv6 involved compare.\n");
10503                         return;
10504                 }
10505                 filter.src_ip = 0;
10506         }
10507         /* need convert to big endian. */
10508         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10509         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10510         filter.queue = res->queue_id;
10511
10512         if (!strcmp(res->ops, "add"))
10513                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10514                                 RTE_ETH_FILTER_NTUPLE,
10515                                 RTE_ETH_FILTER_ADD,
10516                                 &filter);
10517         else
10518                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10519                                 RTE_ETH_FILTER_NTUPLE,
10520                                 RTE_ETH_FILTER_DELETE,
10521                                 &filter);
10522         if (ret < 0)
10523                 printf("5tuple filter programming error: (%s)\n",
10524                         strerror(-ret));
10525 }
10526
10527 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10528         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10529                                  filter, "5tuple_filter");
10530 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10531         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10532                                 port_id, UINT16);
10533 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10534         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10535                                  ops, "add#del");
10536 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10537         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10538                                 dst_ip, "dst_ip");
10539 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10540         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10541                                 dst_ip_value);
10542 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10543         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10544                                 src_ip, "src_ip");
10545 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10546         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10547                                 src_ip_value);
10548 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10549         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10550                                 dst_port, "dst_port");
10551 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10552         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10553                                 dst_port_value, UINT16);
10554 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10555         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10556                                 src_port, "src_port");
10557 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10558         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10559                                 src_port_value, UINT16);
10560 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10561         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10562                                 protocol, "protocol");
10563 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10564         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10565                                 protocol_value, UINT8);
10566 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10567         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10568                                 mask, "mask");
10569 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10570         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10571                                 mask_value, INT8);
10572 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10573         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10574                                 tcp_flags, "tcp_flags");
10575 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10576         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10577                                 tcp_flags_value, UINT8);
10578 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10579         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10580                                 priority, "priority");
10581 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10582         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10583                                 priority_value, UINT8);
10584 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10585         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10586                                 queue, "queue");
10587 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10588         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10589                                 queue_id, UINT16);
10590
10591 cmdline_parse_inst_t cmd_5tuple_filter = {
10592         .f = cmd_5tuple_filter_parsed,
10593         .data = NULL,
10594         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10595                 "src_ip <value> dst_port <value> src_port <value> "
10596                 "protocol <value>  mask <value> tcp_flags <value> "
10597                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10598         .tokens = {
10599                 (void *)&cmd_5tuple_filter_filter,
10600                 (void *)&cmd_5tuple_filter_port_id,
10601                 (void *)&cmd_5tuple_filter_ops,
10602                 (void *)&cmd_5tuple_filter_dst_ip,
10603                 (void *)&cmd_5tuple_filter_dst_ip_value,
10604                 (void *)&cmd_5tuple_filter_src_ip,
10605                 (void *)&cmd_5tuple_filter_src_ip_value,
10606                 (void *)&cmd_5tuple_filter_dst_port,
10607                 (void *)&cmd_5tuple_filter_dst_port_value,
10608                 (void *)&cmd_5tuple_filter_src_port,
10609                 (void *)&cmd_5tuple_filter_src_port_value,
10610                 (void *)&cmd_5tuple_filter_protocol,
10611                 (void *)&cmd_5tuple_filter_protocol_value,
10612                 (void *)&cmd_5tuple_filter_mask,
10613                 (void *)&cmd_5tuple_filter_mask_value,
10614                 (void *)&cmd_5tuple_filter_tcp_flags,
10615                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10616                 (void *)&cmd_5tuple_filter_priority,
10617                 (void *)&cmd_5tuple_filter_priority_value,
10618                 (void *)&cmd_5tuple_filter_queue,
10619                 (void *)&cmd_5tuple_filter_queue_id,
10620                 NULL,
10621         },
10622 };
10623
10624 /* *** ADD/REMOVE A flex FILTER *** */
10625 struct cmd_flex_filter_result {
10626         cmdline_fixed_string_t filter;
10627         cmdline_fixed_string_t ops;
10628         portid_t port_id;
10629         cmdline_fixed_string_t len;
10630         uint8_t len_value;
10631         cmdline_fixed_string_t bytes;
10632         cmdline_fixed_string_t bytes_value;
10633         cmdline_fixed_string_t mask;
10634         cmdline_fixed_string_t mask_value;
10635         cmdline_fixed_string_t priority;
10636         uint8_t priority_value;
10637         cmdline_fixed_string_t queue;
10638         uint16_t queue_id;
10639 };
10640
10641 static int xdigit2val(unsigned char c)
10642 {
10643         int val;
10644         if (isdigit(c))
10645                 val = c - '0';
10646         else if (isupper(c))
10647                 val = c - 'A' + 10;
10648         else
10649                 val = c - 'a' + 10;
10650         return val;
10651 }
10652
10653 static void
10654 cmd_flex_filter_parsed(void *parsed_result,
10655                           __rte_unused struct cmdline *cl,
10656                           __rte_unused void *data)
10657 {
10658         int ret = 0;
10659         struct rte_eth_flex_filter filter;
10660         struct cmd_flex_filter_result *res = parsed_result;
10661         char *bytes_ptr, *mask_ptr;
10662         uint16_t len, i, j = 0;
10663         char c;
10664         int val;
10665         uint8_t byte = 0;
10666
10667         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10668                 printf("the len exceed the max length 128\n");
10669                 return;
10670         }
10671         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10672         filter.len = res->len_value;
10673         filter.priority = res->priority_value;
10674         filter.queue = res->queue_id;
10675         bytes_ptr = res->bytes_value;
10676         mask_ptr = res->mask_value;
10677
10678          /* translate bytes string to array. */
10679         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10680                 (bytes_ptr[1] == 'X')))
10681                 bytes_ptr += 2;
10682         len = strnlen(bytes_ptr, res->len_value * 2);
10683         if (len == 0 || (len % 8 != 0)) {
10684                 printf("please check len and bytes input\n");
10685                 return;
10686         }
10687         for (i = 0; i < len; i++) {
10688                 c = bytes_ptr[i];
10689                 if (isxdigit(c) == 0) {
10690                         /* invalid characters. */
10691                         printf("invalid input\n");
10692                         return;
10693                 }
10694                 val = xdigit2val(c);
10695                 if (i % 2) {
10696                         byte |= val;
10697                         filter.bytes[j] = byte;
10698                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10699                         j++;
10700                         byte = 0;
10701                 } else
10702                         byte |= val << 4;
10703         }
10704         printf("\n");
10705          /* translate mask string to uint8_t array. */
10706         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10707                 (mask_ptr[1] == 'X')))
10708                 mask_ptr += 2;
10709         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10710         if (len == 0) {
10711                 printf("invalid input\n");
10712                 return;
10713         }
10714         j = 0;
10715         byte = 0;
10716         for (i = 0; i < len; i++) {
10717                 c = mask_ptr[i];
10718                 if (isxdigit(c) == 0) {
10719                         /* invalid characters. */
10720                         printf("invalid input\n");
10721                         return;
10722                 }
10723                 val = xdigit2val(c);
10724                 if (i % 2) {
10725                         byte |= val;
10726                         filter.mask[j] = byte;
10727                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10728                         j++;
10729                         byte = 0;
10730                 } else
10731                         byte |= val << 4;
10732         }
10733         printf("\n");
10734
10735         if (!strcmp(res->ops, "add"))
10736                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10737                                 RTE_ETH_FILTER_FLEXIBLE,
10738                                 RTE_ETH_FILTER_ADD,
10739                                 &filter);
10740         else
10741                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10742                                 RTE_ETH_FILTER_FLEXIBLE,
10743                                 RTE_ETH_FILTER_DELETE,
10744                                 &filter);
10745
10746         if (ret < 0)
10747                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10748 }
10749
10750 cmdline_parse_token_string_t cmd_flex_filter_filter =
10751         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10752                                 filter, "flex_filter");
10753 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10754         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10755                                 port_id, UINT16);
10756 cmdline_parse_token_string_t cmd_flex_filter_ops =
10757         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10758                                 ops, "add#del");
10759 cmdline_parse_token_string_t cmd_flex_filter_len =
10760         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10761                                 len, "len");
10762 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10763         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10764                                 len_value, UINT8);
10765 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10766         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10767                                 bytes, "bytes");
10768 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10769         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10770                                 bytes_value, NULL);
10771 cmdline_parse_token_string_t cmd_flex_filter_mask =
10772         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10773                                 mask, "mask");
10774 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10775         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10776                                 mask_value, NULL);
10777 cmdline_parse_token_string_t cmd_flex_filter_priority =
10778         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10779                                 priority, "priority");
10780 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10781         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10782                                 priority_value, UINT8);
10783 cmdline_parse_token_string_t cmd_flex_filter_queue =
10784         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10785                                 queue, "queue");
10786 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10787         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10788                                 queue_id, UINT16);
10789 cmdline_parse_inst_t cmd_flex_filter = {
10790         .f = cmd_flex_filter_parsed,
10791         .data = NULL,
10792         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10793                 "<value> mask <value> priority <value> queue <queue_id>: "
10794                 "Add/Del a flex filter",
10795         .tokens = {
10796                 (void *)&cmd_flex_filter_filter,
10797                 (void *)&cmd_flex_filter_port_id,
10798                 (void *)&cmd_flex_filter_ops,
10799                 (void *)&cmd_flex_filter_len,
10800                 (void *)&cmd_flex_filter_len_value,
10801                 (void *)&cmd_flex_filter_bytes,
10802                 (void *)&cmd_flex_filter_bytes_value,
10803                 (void *)&cmd_flex_filter_mask,
10804                 (void *)&cmd_flex_filter_mask_value,
10805                 (void *)&cmd_flex_filter_priority,
10806                 (void *)&cmd_flex_filter_priority_value,
10807                 (void *)&cmd_flex_filter_queue,
10808                 (void *)&cmd_flex_filter_queue_id,
10809                 NULL,
10810         },
10811 };
10812
10813 /* *** Filters Control *** */
10814
10815 /* *** deal with ethertype filter *** */
10816 struct cmd_ethertype_filter_result {
10817         cmdline_fixed_string_t filter;
10818         portid_t port_id;
10819         cmdline_fixed_string_t ops;
10820         cmdline_fixed_string_t mac;
10821         struct rte_ether_addr mac_addr;
10822         cmdline_fixed_string_t ethertype;
10823         uint16_t ethertype_value;
10824         cmdline_fixed_string_t drop;
10825         cmdline_fixed_string_t queue;
10826         uint16_t  queue_id;
10827 };
10828
10829 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10830         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10831                                  filter, "ethertype_filter");
10832 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10833         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10834                               port_id, UINT16);
10835 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10836         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10837                                  ops, "add#del");
10838 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10839         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10840                                  mac, "mac_addr#mac_ignr");
10841 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10842         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10843                                      mac_addr);
10844 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10845         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10846                                  ethertype, "ethertype");
10847 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10848         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10849                               ethertype_value, UINT16);
10850 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10851         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10852                                  drop, "drop#fwd");
10853 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10854         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10855                                  queue, "queue");
10856 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10857         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10858                               queue_id, UINT16);
10859
10860 static void
10861 cmd_ethertype_filter_parsed(void *parsed_result,
10862                           __rte_unused struct cmdline *cl,
10863                           __rte_unused void *data)
10864 {
10865         struct cmd_ethertype_filter_result *res = parsed_result;
10866         struct rte_eth_ethertype_filter filter;
10867         int ret = 0;
10868
10869         ret = rte_eth_dev_filter_supported(res->port_id,
10870                         RTE_ETH_FILTER_ETHERTYPE);
10871         if (ret < 0) {
10872                 printf("ethertype filter is not supported on port %u.\n",
10873                         res->port_id);
10874                 return;
10875         }
10876
10877         memset(&filter, 0, sizeof(filter));
10878         if (!strcmp(res->mac, "mac_addr")) {
10879                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10880                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10881                         sizeof(struct rte_ether_addr));
10882         }
10883         if (!strcmp(res->drop, "drop"))
10884                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10885         filter.ether_type = res->ethertype_value;
10886         filter.queue = res->queue_id;
10887
10888         if (!strcmp(res->ops, "add"))
10889                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10890                                 RTE_ETH_FILTER_ETHERTYPE,
10891                                 RTE_ETH_FILTER_ADD,
10892                                 &filter);
10893         else
10894                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10895                                 RTE_ETH_FILTER_ETHERTYPE,
10896                                 RTE_ETH_FILTER_DELETE,
10897                                 &filter);
10898         if (ret < 0)
10899                 printf("ethertype filter programming error: (%s)\n",
10900                         strerror(-ret));
10901 }
10902
10903 cmdline_parse_inst_t cmd_ethertype_filter = {
10904         .f = cmd_ethertype_filter_parsed,
10905         .data = NULL,
10906         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10907                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10908                 "Add or delete an ethertype filter entry",
10909         .tokens = {
10910                 (void *)&cmd_ethertype_filter_filter,
10911                 (void *)&cmd_ethertype_filter_port_id,
10912                 (void *)&cmd_ethertype_filter_ops,
10913                 (void *)&cmd_ethertype_filter_mac,
10914                 (void *)&cmd_ethertype_filter_mac_addr,
10915                 (void *)&cmd_ethertype_filter_ethertype,
10916                 (void *)&cmd_ethertype_filter_ethertype_value,
10917                 (void *)&cmd_ethertype_filter_drop,
10918                 (void *)&cmd_ethertype_filter_queue,
10919                 (void *)&cmd_ethertype_filter_queue_id,
10920                 NULL,
10921         },
10922 };
10923
10924 /* *** deal with flow director filter *** */
10925 struct cmd_flow_director_result {
10926         cmdline_fixed_string_t flow_director_filter;
10927         portid_t port_id;
10928         cmdline_fixed_string_t mode;
10929         cmdline_fixed_string_t mode_value;
10930         cmdline_fixed_string_t ops;
10931         cmdline_fixed_string_t flow;
10932         cmdline_fixed_string_t flow_type;
10933         cmdline_fixed_string_t ether;
10934         uint16_t ether_type;
10935         cmdline_fixed_string_t src;
10936         cmdline_ipaddr_t ip_src;
10937         uint16_t port_src;
10938         cmdline_fixed_string_t dst;
10939         cmdline_ipaddr_t ip_dst;
10940         uint16_t port_dst;
10941         cmdline_fixed_string_t verify_tag;
10942         uint32_t verify_tag_value;
10943         cmdline_fixed_string_t tos;
10944         uint8_t tos_value;
10945         cmdline_fixed_string_t proto;
10946         uint8_t proto_value;
10947         cmdline_fixed_string_t ttl;
10948         uint8_t ttl_value;
10949         cmdline_fixed_string_t vlan;
10950         uint16_t vlan_value;
10951         cmdline_fixed_string_t flexbytes;
10952         cmdline_fixed_string_t flexbytes_value;
10953         cmdline_fixed_string_t pf_vf;
10954         cmdline_fixed_string_t drop;
10955         cmdline_fixed_string_t queue;
10956         uint16_t  queue_id;
10957         cmdline_fixed_string_t fd_id;
10958         uint32_t  fd_id_value;
10959         cmdline_fixed_string_t mac;
10960         struct rte_ether_addr mac_addr;
10961         cmdline_fixed_string_t tunnel;
10962         cmdline_fixed_string_t tunnel_type;
10963         cmdline_fixed_string_t tunnel_id;
10964         uint32_t tunnel_id_value;
10965         cmdline_fixed_string_t packet;
10966         char filepath[];
10967 };
10968
10969 static inline int
10970 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10971 {
10972         char s[256];
10973         const char *p, *p0 = q_arg;
10974         char *end;
10975         unsigned long int_fld;
10976         char *str_fld[max_num];
10977         int i;
10978         unsigned size;
10979         int ret = -1;
10980
10981         p = strchr(p0, '(');
10982         if (p == NULL)
10983                 return -1;
10984         ++p;
10985         p0 = strchr(p, ')');
10986         if (p0 == NULL)
10987                 return -1;
10988
10989         size = p0 - p;
10990         if (size >= sizeof(s))
10991                 return -1;
10992
10993         snprintf(s, sizeof(s), "%.*s", size, p);
10994         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10995         if (ret < 0 || ret > max_num)
10996                 return -1;
10997         for (i = 0; i < ret; i++) {
10998                 errno = 0;
10999                 int_fld = strtoul(str_fld[i], &end, 0);
11000                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11001                         return -1;
11002                 flexbytes[i] = (uint8_t)int_fld;
11003         }
11004         return ret;
11005 }
11006
11007 static uint16_t
11008 str2flowtype(char *string)
11009 {
11010         uint8_t i = 0;
11011         static const struct {
11012                 char str[32];
11013                 uint16_t type;
11014         } flowtype_str[] = {
11015                 {"raw", RTE_ETH_FLOW_RAW},
11016                 {"ipv4", RTE_ETH_FLOW_IPV4},
11017                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11018                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11019                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11020                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11021                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11022                 {"ipv6", RTE_ETH_FLOW_IPV6},
11023                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11024                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11025                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11026                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11027                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11028                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11029         };
11030
11031         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11032                 if (!strcmp(flowtype_str[i].str, string))
11033                         return flowtype_str[i].type;
11034         }
11035
11036         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11037                 return (uint16_t)atoi(string);
11038
11039         return RTE_ETH_FLOW_UNKNOWN;
11040 }
11041
11042 static enum rte_eth_fdir_tunnel_type
11043 str2fdir_tunneltype(char *string)
11044 {
11045         uint8_t i = 0;
11046
11047         static const struct {
11048                 char str[32];
11049                 enum rte_eth_fdir_tunnel_type type;
11050         } tunneltype_str[] = {
11051                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11052                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11053         };
11054
11055         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11056                 if (!strcmp(tunneltype_str[i].str, string))
11057                         return tunneltype_str[i].type;
11058         }
11059         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11060 }
11061
11062 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11063 do { \
11064         if ((ip_addr).family == AF_INET) \
11065                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11066         else { \
11067                 printf("invalid parameter.\n"); \
11068                 return; \
11069         } \
11070 } while (0)
11071
11072 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11073 do { \
11074         if ((ip_addr).family == AF_INET6) \
11075                 rte_memcpy(&(ip), \
11076                                  &((ip_addr).addr.ipv6), \
11077                                  sizeof(struct in6_addr)); \
11078         else { \
11079                 printf("invalid parameter.\n"); \
11080                 return; \
11081         } \
11082 } while (0)
11083
11084 static void
11085 cmd_flow_director_filter_parsed(void *parsed_result,
11086                           __rte_unused struct cmdline *cl,
11087                           __rte_unused void *data)
11088 {
11089         struct cmd_flow_director_result *res = parsed_result;
11090         struct rte_eth_fdir_filter entry;
11091         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11092         char *end;
11093         unsigned long vf_id;
11094         int ret = 0;
11095
11096         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11097         if (ret < 0) {
11098                 printf("flow director is not supported on port %u.\n",
11099                         res->port_id);
11100                 return;
11101         }
11102         memset(flexbytes, 0, sizeof(flexbytes));
11103         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11104
11105         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11106                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11107                         printf("Please set mode to MAC-VLAN.\n");
11108                         return;
11109                 }
11110         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11111                 if (strcmp(res->mode_value, "Tunnel")) {
11112                         printf("Please set mode to Tunnel.\n");
11113                         return;
11114                 }
11115         } else {
11116                 if (!strcmp(res->mode_value, "raw")) {
11117 #ifdef RTE_LIBRTE_I40E_PMD
11118                         struct rte_pmd_i40e_flow_type_mapping
11119                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11120                         struct rte_pmd_i40e_pkt_template_conf conf;
11121                         uint16_t flow_type = str2flowtype(res->flow_type);
11122                         uint16_t i, port = res->port_id;
11123                         uint8_t add;
11124
11125                         memset(&conf, 0, sizeof(conf));
11126
11127                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11128                                 printf("Invalid flow type specified.\n");
11129                                 return;
11130                         }
11131                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11132                                                                  mapping);
11133                         if (ret)
11134                                 return;
11135                         if (mapping[flow_type].pctype == 0ULL) {
11136                                 printf("Invalid flow type specified.\n");
11137                                 return;
11138                         }
11139                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11140                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11141                                         conf.input.pctype = i;
11142                                         break;
11143                                 }
11144                         }
11145
11146                         conf.input.packet = open_file(res->filepath,
11147                                                 &conf.input.length);
11148                         if (!conf.input.packet)
11149                                 return;
11150                         if (!strcmp(res->drop, "drop"))
11151                                 conf.action.behavior =
11152                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11153                         else
11154                                 conf.action.behavior =
11155                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11156                         conf.action.report_status =
11157                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11158                         conf.action.rx_queue = res->queue_id;
11159                         conf.soft_id = res->fd_id_value;
11160                         add  = strcmp(res->ops, "del") ? 1 : 0;
11161                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11162                                                                         &conf,
11163                                                                         add);
11164                         if (ret < 0)
11165                                 printf("flow director config error: (%s)\n",
11166                                        strerror(-ret));
11167                         close_file(conf.input.packet);
11168 #endif
11169                         return;
11170                 } else if (strcmp(res->mode_value, "IP")) {
11171                         printf("Please set mode to IP or raw.\n");
11172                         return;
11173                 }
11174                 entry.input.flow_type = str2flowtype(res->flow_type);
11175         }
11176
11177         ret = parse_flexbytes(res->flexbytes_value,
11178                                         flexbytes,
11179                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11180         if (ret < 0) {
11181                 printf("error: Cannot parse flexbytes input.\n");
11182                 return;
11183         }
11184
11185         switch (entry.input.flow_type) {
11186         case RTE_ETH_FLOW_FRAG_IPV4:
11187         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11188                 entry.input.flow.ip4_flow.proto = res->proto_value;
11189                 /* fall-through */
11190         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11191         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11192                 IPV4_ADDR_TO_UINT(res->ip_dst,
11193                         entry.input.flow.ip4_flow.dst_ip);
11194                 IPV4_ADDR_TO_UINT(res->ip_src,
11195                         entry.input.flow.ip4_flow.src_ip);
11196                 entry.input.flow.ip4_flow.tos = res->tos_value;
11197                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11198                 /* need convert to big endian. */
11199                 entry.input.flow.udp4_flow.dst_port =
11200                                 rte_cpu_to_be_16(res->port_dst);
11201                 entry.input.flow.udp4_flow.src_port =
11202                                 rte_cpu_to_be_16(res->port_src);
11203                 break;
11204         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11205                 IPV4_ADDR_TO_UINT(res->ip_dst,
11206                         entry.input.flow.sctp4_flow.ip.dst_ip);
11207                 IPV4_ADDR_TO_UINT(res->ip_src,
11208                         entry.input.flow.sctp4_flow.ip.src_ip);
11209                 entry.input.flow.ip4_flow.tos = res->tos_value;
11210                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11211                 /* need convert to big endian. */
11212                 entry.input.flow.sctp4_flow.dst_port =
11213                                 rte_cpu_to_be_16(res->port_dst);
11214                 entry.input.flow.sctp4_flow.src_port =
11215                                 rte_cpu_to_be_16(res->port_src);
11216                 entry.input.flow.sctp4_flow.verify_tag =
11217                                 rte_cpu_to_be_32(res->verify_tag_value);
11218                 break;
11219         case RTE_ETH_FLOW_FRAG_IPV6:
11220         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11221                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11222                 /* fall-through */
11223         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11224         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11225                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11226                         entry.input.flow.ipv6_flow.dst_ip);
11227                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11228                         entry.input.flow.ipv6_flow.src_ip);
11229                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11230                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11231                 /* need convert to big endian. */
11232                 entry.input.flow.udp6_flow.dst_port =
11233                                 rte_cpu_to_be_16(res->port_dst);
11234                 entry.input.flow.udp6_flow.src_port =
11235                                 rte_cpu_to_be_16(res->port_src);
11236                 break;
11237         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11238                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11239                         entry.input.flow.sctp6_flow.ip.dst_ip);
11240                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11241                         entry.input.flow.sctp6_flow.ip.src_ip);
11242                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11243                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11244                 /* need convert to big endian. */
11245                 entry.input.flow.sctp6_flow.dst_port =
11246                                 rte_cpu_to_be_16(res->port_dst);
11247                 entry.input.flow.sctp6_flow.src_port =
11248                                 rte_cpu_to_be_16(res->port_src);
11249                 entry.input.flow.sctp6_flow.verify_tag =
11250                                 rte_cpu_to_be_32(res->verify_tag_value);
11251                 break;
11252         case RTE_ETH_FLOW_L2_PAYLOAD:
11253                 entry.input.flow.l2_flow.ether_type =
11254                         rte_cpu_to_be_16(res->ether_type);
11255                 break;
11256         default:
11257                 break;
11258         }
11259
11260         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11261                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11262                                  &res->mac_addr,
11263                                  sizeof(struct rte_ether_addr));
11264
11265         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11266                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11267                                  &res->mac_addr,
11268                                  sizeof(struct rte_ether_addr));
11269                 entry.input.flow.tunnel_flow.tunnel_type =
11270                         str2fdir_tunneltype(res->tunnel_type);
11271                 entry.input.flow.tunnel_flow.tunnel_id =
11272                         rte_cpu_to_be_32(res->tunnel_id_value);
11273         }
11274
11275         rte_memcpy(entry.input.flow_ext.flexbytes,
11276                    flexbytes,
11277                    RTE_ETH_FDIR_MAX_FLEXLEN);
11278
11279         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11280
11281         entry.action.flex_off = 0;  /*use 0 by default */
11282         if (!strcmp(res->drop, "drop"))
11283                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11284         else
11285                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11286
11287         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11288             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11289                 if (!strcmp(res->pf_vf, "pf"))
11290                         entry.input.flow_ext.is_vf = 0;
11291                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11292                         struct rte_eth_dev_info dev_info;
11293
11294                         ret = eth_dev_info_get_print_err(res->port_id,
11295                                                 &dev_info);
11296                         if (ret != 0)
11297                                 return;
11298
11299                         errno = 0;
11300                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11301                         if (errno != 0 || *end != '\0' ||
11302                             vf_id >= dev_info.max_vfs) {
11303                                 printf("invalid parameter %s.\n", res->pf_vf);
11304                                 return;
11305                         }
11306                         entry.input.flow_ext.is_vf = 1;
11307                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11308                 } else {
11309                         printf("invalid parameter %s.\n", res->pf_vf);
11310                         return;
11311                 }
11312         }
11313
11314         /* set to report FD ID by default */
11315         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11316         entry.action.rx_queue = res->queue_id;
11317         entry.soft_id = res->fd_id_value;
11318         if (!strcmp(res->ops, "add"))
11319                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11320                                              RTE_ETH_FILTER_ADD, &entry);
11321         else if (!strcmp(res->ops, "del"))
11322                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11323                                              RTE_ETH_FILTER_DELETE, &entry);
11324         else
11325                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11326                                              RTE_ETH_FILTER_UPDATE, &entry);
11327         if (ret < 0)
11328                 printf("flow director programming error: (%s)\n",
11329                         strerror(-ret));
11330 }
11331
11332 cmdline_parse_token_string_t cmd_flow_director_filter =
11333         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11334                                  flow_director_filter, "flow_director_filter");
11335 cmdline_parse_token_num_t cmd_flow_director_port_id =
11336         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11337                               port_id, UINT16);
11338 cmdline_parse_token_string_t cmd_flow_director_ops =
11339         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11340                                  ops, "add#del#update");
11341 cmdline_parse_token_string_t cmd_flow_director_flow =
11342         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11343                                  flow, "flow");
11344 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11345         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11346                 flow_type, NULL);
11347 cmdline_parse_token_string_t cmd_flow_director_ether =
11348         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11349                                  ether, "ether");
11350 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11351         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11352                               ether_type, UINT16);
11353 cmdline_parse_token_string_t cmd_flow_director_src =
11354         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11355                                  src, "src");
11356 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11357         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11358                                  ip_src);
11359 cmdline_parse_token_num_t cmd_flow_director_port_src =
11360         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11361                               port_src, UINT16);
11362 cmdline_parse_token_string_t cmd_flow_director_dst =
11363         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11364                                  dst, "dst");
11365 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11366         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11367                                  ip_dst);
11368 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11369         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11370                               port_dst, UINT16);
11371 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11372         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11373                                   verify_tag, "verify_tag");
11374 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11375         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11376                               verify_tag_value, UINT32);
11377 cmdline_parse_token_string_t cmd_flow_director_tos =
11378         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11379                                  tos, "tos");
11380 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11381         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11382                               tos_value, UINT8);
11383 cmdline_parse_token_string_t cmd_flow_director_proto =
11384         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11385                                  proto, "proto");
11386 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11387         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11388                               proto_value, UINT8);
11389 cmdline_parse_token_string_t cmd_flow_director_ttl =
11390         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11391                                  ttl, "ttl");
11392 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11393         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11394                               ttl_value, UINT8);
11395 cmdline_parse_token_string_t cmd_flow_director_vlan =
11396         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11397                                  vlan, "vlan");
11398 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11399         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11400                               vlan_value, UINT16);
11401 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11402         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11403                                  flexbytes, "flexbytes");
11404 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11405         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11406                               flexbytes_value, NULL);
11407 cmdline_parse_token_string_t cmd_flow_director_drop =
11408         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11409                                  drop, "drop#fwd");
11410 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11411         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11412                               pf_vf, NULL);
11413 cmdline_parse_token_string_t cmd_flow_director_queue =
11414         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11415                                  queue, "queue");
11416 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11417         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11418                               queue_id, UINT16);
11419 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11420         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11421                                  fd_id, "fd_id");
11422 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11423         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11424                               fd_id_value, UINT32);
11425
11426 cmdline_parse_token_string_t cmd_flow_director_mode =
11427         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11428                                  mode, "mode");
11429 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11430         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11431                                  mode_value, "IP");
11432 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11433         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11434                                  mode_value, "MAC-VLAN");
11435 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11436         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11437                                  mode_value, "Tunnel");
11438 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11439         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11440                                  mode_value, "raw");
11441 cmdline_parse_token_string_t cmd_flow_director_mac =
11442         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11443                                  mac, "mac");
11444 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11445         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11446                                     mac_addr);
11447 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11448         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11449                                  tunnel, "tunnel");
11450 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11451         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11452                                  tunnel_type, "NVGRE#VxLAN");
11453 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11454         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11455                                  tunnel_id, "tunnel-id");
11456 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11457         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11458                               tunnel_id_value, UINT32);
11459 cmdline_parse_token_string_t cmd_flow_director_packet =
11460         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11461                                  packet, "packet");
11462 cmdline_parse_token_string_t cmd_flow_director_filepath =
11463         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11464                                  filepath, NULL);
11465
11466 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11467         .f = cmd_flow_director_filter_parsed,
11468         .data = NULL,
11469         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11470                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11471                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11472                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11473                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11474                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11475                 "fd_id <fd_id_value>: "
11476                 "Add or delete an ip flow director entry on NIC",
11477         .tokens = {
11478                 (void *)&cmd_flow_director_filter,
11479                 (void *)&cmd_flow_director_port_id,
11480                 (void *)&cmd_flow_director_mode,
11481                 (void *)&cmd_flow_director_mode_ip,
11482                 (void *)&cmd_flow_director_ops,
11483                 (void *)&cmd_flow_director_flow,
11484                 (void *)&cmd_flow_director_flow_type,
11485                 (void *)&cmd_flow_director_src,
11486                 (void *)&cmd_flow_director_ip_src,
11487                 (void *)&cmd_flow_director_dst,
11488                 (void *)&cmd_flow_director_ip_dst,
11489                 (void *)&cmd_flow_director_tos,
11490                 (void *)&cmd_flow_director_tos_value,
11491                 (void *)&cmd_flow_director_proto,
11492                 (void *)&cmd_flow_director_proto_value,
11493                 (void *)&cmd_flow_director_ttl,
11494                 (void *)&cmd_flow_director_ttl_value,
11495                 (void *)&cmd_flow_director_vlan,
11496                 (void *)&cmd_flow_director_vlan_value,
11497                 (void *)&cmd_flow_director_flexbytes,
11498                 (void *)&cmd_flow_director_flexbytes_value,
11499                 (void *)&cmd_flow_director_drop,
11500                 (void *)&cmd_flow_director_pf_vf,
11501                 (void *)&cmd_flow_director_queue,
11502                 (void *)&cmd_flow_director_queue_id,
11503                 (void *)&cmd_flow_director_fd_id,
11504                 (void *)&cmd_flow_director_fd_id_value,
11505                 NULL,
11506         },
11507 };
11508
11509 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11510         .f = cmd_flow_director_filter_parsed,
11511         .data = NULL,
11512         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11513                 "director entry on NIC",
11514         .tokens = {
11515                 (void *)&cmd_flow_director_filter,
11516                 (void *)&cmd_flow_director_port_id,
11517                 (void *)&cmd_flow_director_mode,
11518                 (void *)&cmd_flow_director_mode_ip,
11519                 (void *)&cmd_flow_director_ops,
11520                 (void *)&cmd_flow_director_flow,
11521                 (void *)&cmd_flow_director_flow_type,
11522                 (void *)&cmd_flow_director_src,
11523                 (void *)&cmd_flow_director_ip_src,
11524                 (void *)&cmd_flow_director_port_src,
11525                 (void *)&cmd_flow_director_dst,
11526                 (void *)&cmd_flow_director_ip_dst,
11527                 (void *)&cmd_flow_director_port_dst,
11528                 (void *)&cmd_flow_director_tos,
11529                 (void *)&cmd_flow_director_tos_value,
11530                 (void *)&cmd_flow_director_ttl,
11531                 (void *)&cmd_flow_director_ttl_value,
11532                 (void *)&cmd_flow_director_vlan,
11533                 (void *)&cmd_flow_director_vlan_value,
11534                 (void *)&cmd_flow_director_flexbytes,
11535                 (void *)&cmd_flow_director_flexbytes_value,
11536                 (void *)&cmd_flow_director_drop,
11537                 (void *)&cmd_flow_director_pf_vf,
11538                 (void *)&cmd_flow_director_queue,
11539                 (void *)&cmd_flow_director_queue_id,
11540                 (void *)&cmd_flow_director_fd_id,
11541                 (void *)&cmd_flow_director_fd_id_value,
11542                 NULL,
11543         },
11544 };
11545
11546 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11547         .f = cmd_flow_director_filter_parsed,
11548         .data = NULL,
11549         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11550                 "director entry on NIC",
11551         .tokens = {
11552                 (void *)&cmd_flow_director_filter,
11553                 (void *)&cmd_flow_director_port_id,
11554                 (void *)&cmd_flow_director_mode,
11555                 (void *)&cmd_flow_director_mode_ip,
11556                 (void *)&cmd_flow_director_ops,
11557                 (void *)&cmd_flow_director_flow,
11558                 (void *)&cmd_flow_director_flow_type,
11559                 (void *)&cmd_flow_director_src,
11560                 (void *)&cmd_flow_director_ip_src,
11561                 (void *)&cmd_flow_director_port_src,
11562                 (void *)&cmd_flow_director_dst,
11563                 (void *)&cmd_flow_director_ip_dst,
11564                 (void *)&cmd_flow_director_port_dst,
11565                 (void *)&cmd_flow_director_verify_tag,
11566                 (void *)&cmd_flow_director_verify_tag_value,
11567                 (void *)&cmd_flow_director_tos,
11568                 (void *)&cmd_flow_director_tos_value,
11569                 (void *)&cmd_flow_director_ttl,
11570                 (void *)&cmd_flow_director_ttl_value,
11571                 (void *)&cmd_flow_director_vlan,
11572                 (void *)&cmd_flow_director_vlan_value,
11573                 (void *)&cmd_flow_director_flexbytes,
11574                 (void *)&cmd_flow_director_flexbytes_value,
11575                 (void *)&cmd_flow_director_drop,
11576                 (void *)&cmd_flow_director_pf_vf,
11577                 (void *)&cmd_flow_director_queue,
11578                 (void *)&cmd_flow_director_queue_id,
11579                 (void *)&cmd_flow_director_fd_id,
11580                 (void *)&cmd_flow_director_fd_id_value,
11581                 NULL,
11582         },
11583 };
11584
11585 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11586         .f = cmd_flow_director_filter_parsed,
11587         .data = NULL,
11588         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11589                 "director entry on NIC",
11590         .tokens = {
11591                 (void *)&cmd_flow_director_filter,
11592                 (void *)&cmd_flow_director_port_id,
11593                 (void *)&cmd_flow_director_mode,
11594                 (void *)&cmd_flow_director_mode_ip,
11595                 (void *)&cmd_flow_director_ops,
11596                 (void *)&cmd_flow_director_flow,
11597                 (void *)&cmd_flow_director_flow_type,
11598                 (void *)&cmd_flow_director_ether,
11599                 (void *)&cmd_flow_director_ether_type,
11600                 (void *)&cmd_flow_director_flexbytes,
11601                 (void *)&cmd_flow_director_flexbytes_value,
11602                 (void *)&cmd_flow_director_drop,
11603                 (void *)&cmd_flow_director_pf_vf,
11604                 (void *)&cmd_flow_director_queue,
11605                 (void *)&cmd_flow_director_queue_id,
11606                 (void *)&cmd_flow_director_fd_id,
11607                 (void *)&cmd_flow_director_fd_id_value,
11608                 NULL,
11609         },
11610 };
11611
11612 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11613         .f = cmd_flow_director_filter_parsed,
11614         .data = NULL,
11615         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11616                 "director entry on NIC",
11617         .tokens = {
11618                 (void *)&cmd_flow_director_filter,
11619                 (void *)&cmd_flow_director_port_id,
11620                 (void *)&cmd_flow_director_mode,
11621                 (void *)&cmd_flow_director_mode_mac_vlan,
11622                 (void *)&cmd_flow_director_ops,
11623                 (void *)&cmd_flow_director_mac,
11624                 (void *)&cmd_flow_director_mac_addr,
11625                 (void *)&cmd_flow_director_vlan,
11626                 (void *)&cmd_flow_director_vlan_value,
11627                 (void *)&cmd_flow_director_flexbytes,
11628                 (void *)&cmd_flow_director_flexbytes_value,
11629                 (void *)&cmd_flow_director_drop,
11630                 (void *)&cmd_flow_director_queue,
11631                 (void *)&cmd_flow_director_queue_id,
11632                 (void *)&cmd_flow_director_fd_id,
11633                 (void *)&cmd_flow_director_fd_id_value,
11634                 NULL,
11635         },
11636 };
11637
11638 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11639         .f = cmd_flow_director_filter_parsed,
11640         .data = NULL,
11641         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11642                 "director entry on NIC",
11643         .tokens = {
11644                 (void *)&cmd_flow_director_filter,
11645                 (void *)&cmd_flow_director_port_id,
11646                 (void *)&cmd_flow_director_mode,
11647                 (void *)&cmd_flow_director_mode_tunnel,
11648                 (void *)&cmd_flow_director_ops,
11649                 (void *)&cmd_flow_director_mac,
11650                 (void *)&cmd_flow_director_mac_addr,
11651                 (void *)&cmd_flow_director_vlan,
11652                 (void *)&cmd_flow_director_vlan_value,
11653                 (void *)&cmd_flow_director_tunnel,
11654                 (void *)&cmd_flow_director_tunnel_type,
11655                 (void *)&cmd_flow_director_tunnel_id,
11656                 (void *)&cmd_flow_director_tunnel_id_value,
11657                 (void *)&cmd_flow_director_flexbytes,
11658                 (void *)&cmd_flow_director_flexbytes_value,
11659                 (void *)&cmd_flow_director_drop,
11660                 (void *)&cmd_flow_director_queue,
11661                 (void *)&cmd_flow_director_queue_id,
11662                 (void *)&cmd_flow_director_fd_id,
11663                 (void *)&cmd_flow_director_fd_id_value,
11664                 NULL,
11665         },
11666 };
11667
11668 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11669         .f = cmd_flow_director_filter_parsed,
11670         .data = NULL,
11671         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11672                 "director entry on NIC",
11673         .tokens = {
11674                 (void *)&cmd_flow_director_filter,
11675                 (void *)&cmd_flow_director_port_id,
11676                 (void *)&cmd_flow_director_mode,
11677                 (void *)&cmd_flow_director_mode_raw,
11678                 (void *)&cmd_flow_director_ops,
11679                 (void *)&cmd_flow_director_flow,
11680                 (void *)&cmd_flow_director_flow_type,
11681                 (void *)&cmd_flow_director_drop,
11682                 (void *)&cmd_flow_director_queue,
11683                 (void *)&cmd_flow_director_queue_id,
11684                 (void *)&cmd_flow_director_fd_id,
11685                 (void *)&cmd_flow_director_fd_id_value,
11686                 (void *)&cmd_flow_director_packet,
11687                 (void *)&cmd_flow_director_filepath,
11688                 NULL,
11689         },
11690 };
11691
11692 struct cmd_flush_flow_director_result {
11693         cmdline_fixed_string_t flush_flow_director;
11694         portid_t port_id;
11695 };
11696
11697 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11698         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11699                                  flush_flow_director, "flush_flow_director");
11700 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11701         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11702                               port_id, UINT16);
11703
11704 static void
11705 cmd_flush_flow_director_parsed(void *parsed_result,
11706                           __rte_unused struct cmdline *cl,
11707                           __rte_unused void *data)
11708 {
11709         struct cmd_flow_director_result *res = parsed_result;
11710         int ret = 0;
11711
11712         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11713         if (ret < 0) {
11714                 printf("flow director is not supported on port %u.\n",
11715                         res->port_id);
11716                 return;
11717         }
11718
11719         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11720                         RTE_ETH_FILTER_FLUSH, NULL);
11721         if (ret < 0)
11722                 printf("flow director table flushing error: (%s)\n",
11723                         strerror(-ret));
11724 }
11725
11726 cmdline_parse_inst_t cmd_flush_flow_director = {
11727         .f = cmd_flush_flow_director_parsed,
11728         .data = NULL,
11729         .help_str = "flush_flow_director <port_id>: "
11730                 "Flush all flow director entries of a device on NIC",
11731         .tokens = {
11732                 (void *)&cmd_flush_flow_director_flush,
11733                 (void *)&cmd_flush_flow_director_port_id,
11734                 NULL,
11735         },
11736 };
11737
11738 /* *** deal with flow director mask *** */
11739 struct cmd_flow_director_mask_result {
11740         cmdline_fixed_string_t flow_director_mask;
11741         portid_t port_id;
11742         cmdline_fixed_string_t mode;
11743         cmdline_fixed_string_t mode_value;
11744         cmdline_fixed_string_t vlan;
11745         uint16_t vlan_mask;
11746         cmdline_fixed_string_t src_mask;
11747         cmdline_ipaddr_t ipv4_src;
11748         cmdline_ipaddr_t ipv6_src;
11749         uint16_t port_src;
11750         cmdline_fixed_string_t dst_mask;
11751         cmdline_ipaddr_t ipv4_dst;
11752         cmdline_ipaddr_t ipv6_dst;
11753         uint16_t port_dst;
11754         cmdline_fixed_string_t mac;
11755         uint8_t mac_addr_byte_mask;
11756         cmdline_fixed_string_t tunnel_id;
11757         uint32_t tunnel_id_mask;
11758         cmdline_fixed_string_t tunnel_type;
11759         uint8_t tunnel_type_mask;
11760 };
11761
11762 static void
11763 cmd_flow_director_mask_parsed(void *parsed_result,
11764                           __rte_unused struct cmdline *cl,
11765                           __rte_unused void *data)
11766 {
11767         struct cmd_flow_director_mask_result *res = parsed_result;
11768         struct rte_eth_fdir_masks *mask;
11769         struct rte_port *port;
11770
11771         port = &ports[res->port_id];
11772         /** Check if the port is not started **/
11773         if (port->port_status != RTE_PORT_STOPPED) {
11774                 printf("Please stop port %d first\n", res->port_id);
11775                 return;
11776         }
11777
11778         mask = &port->dev_conf.fdir_conf.mask;
11779
11780         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11781                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11782                         printf("Please set mode to MAC-VLAN.\n");
11783                         return;
11784                 }
11785
11786                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11787         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11788                 if (strcmp(res->mode_value, "Tunnel")) {
11789                         printf("Please set mode to Tunnel.\n");
11790                         return;
11791                 }
11792
11793                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11794                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11795                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11796                 mask->tunnel_type_mask = res->tunnel_type_mask;
11797         } else {
11798                 if (strcmp(res->mode_value, "IP")) {
11799                         printf("Please set mode to IP.\n");
11800                         return;
11801                 }
11802
11803                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11804                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11805                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11806                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11807                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11808                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11809                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11810         }
11811
11812         cmd_reconfig_device_queue(res->port_id, 1, 1);
11813 }
11814
11815 cmdline_parse_token_string_t cmd_flow_director_mask =
11816         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11817                                  flow_director_mask, "flow_director_mask");
11818 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11819         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11820                               port_id, UINT16);
11821 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11822         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11823                                  vlan, "vlan");
11824 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11825         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11826                               vlan_mask, UINT16);
11827 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11828         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11829                                  src_mask, "src_mask");
11830 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11831         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11832                                  ipv4_src);
11833 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11834         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11835                                  ipv6_src);
11836 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11837         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11838                               port_src, UINT16);
11839 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11840         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11841                                  dst_mask, "dst_mask");
11842 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11843         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11844                                  ipv4_dst);
11845 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11846         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11847                                  ipv6_dst);
11848 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11849         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11850                               port_dst, UINT16);
11851
11852 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11853         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11854                                  mode, "mode");
11855 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11856         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11857                                  mode_value, "IP");
11858 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11859         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11860                                  mode_value, "MAC-VLAN");
11861 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11862         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11863                                  mode_value, "Tunnel");
11864 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11865         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11866                                  mac, "mac");
11867 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11868         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11869                               mac_addr_byte_mask, UINT8);
11870 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11871         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11872                                  tunnel_type, "tunnel-type");
11873 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11874         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11875                               tunnel_type_mask, UINT8);
11876 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11877         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11878                                  tunnel_id, "tunnel-id");
11879 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11880         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11881                               tunnel_id_mask, UINT32);
11882
11883 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11884         .f = cmd_flow_director_mask_parsed,
11885         .data = NULL,
11886         .help_str = "flow_director_mask ... : "
11887                 "Set IP mode flow director's mask on NIC",
11888         .tokens = {
11889                 (void *)&cmd_flow_director_mask,
11890                 (void *)&cmd_flow_director_mask_port_id,
11891                 (void *)&cmd_flow_director_mask_mode,
11892                 (void *)&cmd_flow_director_mask_mode_ip,
11893                 (void *)&cmd_flow_director_mask_vlan,
11894                 (void *)&cmd_flow_director_mask_vlan_value,
11895                 (void *)&cmd_flow_director_mask_src,
11896                 (void *)&cmd_flow_director_mask_ipv4_src,
11897                 (void *)&cmd_flow_director_mask_ipv6_src,
11898                 (void *)&cmd_flow_director_mask_port_src,
11899                 (void *)&cmd_flow_director_mask_dst,
11900                 (void *)&cmd_flow_director_mask_ipv4_dst,
11901                 (void *)&cmd_flow_director_mask_ipv6_dst,
11902                 (void *)&cmd_flow_director_mask_port_dst,
11903                 NULL,
11904         },
11905 };
11906
11907 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11908         .f = cmd_flow_director_mask_parsed,
11909         .data = NULL,
11910         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11911                 "flow director's mask on NIC",
11912         .tokens = {
11913                 (void *)&cmd_flow_director_mask,
11914                 (void *)&cmd_flow_director_mask_port_id,
11915                 (void *)&cmd_flow_director_mask_mode,
11916                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11917                 (void *)&cmd_flow_director_mask_vlan,
11918                 (void *)&cmd_flow_director_mask_vlan_value,
11919                 NULL,
11920         },
11921 };
11922
11923 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11924         .f = cmd_flow_director_mask_parsed,
11925         .data = NULL,
11926         .help_str = "flow_director_mask ... : Set tunnel mode "
11927                 "flow director's mask on NIC",
11928         .tokens = {
11929                 (void *)&cmd_flow_director_mask,
11930                 (void *)&cmd_flow_director_mask_port_id,
11931                 (void *)&cmd_flow_director_mask_mode,
11932                 (void *)&cmd_flow_director_mask_mode_tunnel,
11933                 (void *)&cmd_flow_director_mask_vlan,
11934                 (void *)&cmd_flow_director_mask_vlan_value,
11935                 (void *)&cmd_flow_director_mask_mac,
11936                 (void *)&cmd_flow_director_mask_mac_value,
11937                 (void *)&cmd_flow_director_mask_tunnel_type,
11938                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11939                 (void *)&cmd_flow_director_mask_tunnel_id,
11940                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11941                 NULL,
11942         },
11943 };
11944
11945 /* *** deal with flow director mask on flexible payload *** */
11946 struct cmd_flow_director_flex_mask_result {
11947         cmdline_fixed_string_t flow_director_flexmask;
11948         portid_t port_id;
11949         cmdline_fixed_string_t flow;
11950         cmdline_fixed_string_t flow_type;
11951         cmdline_fixed_string_t mask;
11952 };
11953
11954 static void
11955 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11956                           __rte_unused struct cmdline *cl,
11957                           __rte_unused void *data)
11958 {
11959         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11960         struct rte_eth_fdir_info fdir_info;
11961         struct rte_eth_fdir_flex_mask flex_mask;
11962         struct rte_port *port;
11963         uint64_t flow_type_mask;
11964         uint16_t i;
11965         int ret;
11966
11967         port = &ports[res->port_id];
11968         /** Check if the port is not started **/
11969         if (port->port_status != RTE_PORT_STOPPED) {
11970                 printf("Please stop port %d first\n", res->port_id);
11971                 return;
11972         }
11973
11974         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11975         ret = parse_flexbytes(res->mask,
11976                         flex_mask.mask,
11977                         RTE_ETH_FDIR_MAX_FLEXLEN);
11978         if (ret < 0) {
11979                 printf("error: Cannot parse mask input.\n");
11980                 return;
11981         }
11982
11983         memset(&fdir_info, 0, sizeof(fdir_info));
11984         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11985                                 RTE_ETH_FILTER_INFO, &fdir_info);
11986         if (ret < 0) {
11987                 printf("Cannot get FDir filter info\n");
11988                 return;
11989         }
11990
11991         if (!strcmp(res->flow_type, "none")) {
11992                 /* means don't specify the flow type */
11993                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11994                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11995                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11996                                0, sizeof(struct rte_eth_fdir_flex_mask));
11997                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11998                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11999                                  &flex_mask,
12000                                  sizeof(struct rte_eth_fdir_flex_mask));
12001                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12002                 return;
12003         }
12004         flow_type_mask = fdir_info.flow_types_mask[0];
12005         if (!strcmp(res->flow_type, "all")) {
12006                 if (!flow_type_mask) {
12007                         printf("No flow type supported\n");
12008                         return;
12009                 }
12010                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12011                         if (flow_type_mask & (1ULL << i)) {
12012                                 flex_mask.flow_type = i;
12013                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12014                         }
12015                 }
12016                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12017                 return;
12018         }
12019         flex_mask.flow_type = str2flowtype(res->flow_type);
12020         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12021                 printf("Flow type %s not supported on port %d\n",
12022                                 res->flow_type, res->port_id);
12023                 return;
12024         }
12025         fdir_set_flex_mask(res->port_id, &flex_mask);
12026         cmd_reconfig_device_queue(res->port_id, 1, 1);
12027 }
12028
12029 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12030         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12031                                  flow_director_flexmask,
12032                                  "flow_director_flex_mask");
12033 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12034         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12035                               port_id, UINT16);
12036 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12037         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12038                                  flow, "flow");
12039 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12040         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12041                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12042                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12043 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12044         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12045                                  mask, NULL);
12046
12047 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12048         .f = cmd_flow_director_flex_mask_parsed,
12049         .data = NULL,
12050         .help_str = "flow_director_flex_mask ... : "
12051                 "Set flow director's flex mask on NIC",
12052         .tokens = {
12053                 (void *)&cmd_flow_director_flexmask,
12054                 (void *)&cmd_flow_director_flexmask_port_id,
12055                 (void *)&cmd_flow_director_flexmask_flow,
12056                 (void *)&cmd_flow_director_flexmask_flow_type,
12057                 (void *)&cmd_flow_director_flexmask_mask,
12058                 NULL,
12059         },
12060 };
12061
12062 /* *** deal with flow director flexible payload configuration *** */
12063 struct cmd_flow_director_flexpayload_result {
12064         cmdline_fixed_string_t flow_director_flexpayload;
12065         portid_t port_id;
12066         cmdline_fixed_string_t payload_layer;
12067         cmdline_fixed_string_t payload_cfg;
12068 };
12069
12070 static inline int
12071 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12072 {
12073         char s[256];
12074         const char *p, *p0 = q_arg;
12075         char *end;
12076         unsigned long int_fld;
12077         char *str_fld[max_num];
12078         int i;
12079         unsigned size;
12080         int ret = -1;
12081
12082         p = strchr(p0, '(');
12083         if (p == NULL)
12084                 return -1;
12085         ++p;
12086         p0 = strchr(p, ')');
12087         if (p0 == NULL)
12088                 return -1;
12089
12090         size = p0 - p;
12091         if (size >= sizeof(s))
12092                 return -1;
12093
12094         snprintf(s, sizeof(s), "%.*s", size, p);
12095         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12096         if (ret < 0 || ret > max_num)
12097                 return -1;
12098         for (i = 0; i < ret; i++) {
12099                 errno = 0;
12100                 int_fld = strtoul(str_fld[i], &end, 0);
12101                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12102                         return -1;
12103                 offsets[i] = (uint16_t)int_fld;
12104         }
12105         return ret;
12106 }
12107
12108 static void
12109 cmd_flow_director_flxpld_parsed(void *parsed_result,
12110                           __rte_unused struct cmdline *cl,
12111                           __rte_unused void *data)
12112 {
12113         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12114         struct rte_eth_flex_payload_cfg flex_cfg;
12115         struct rte_port *port;
12116         int ret = 0;
12117
12118         port = &ports[res->port_id];
12119         /** Check if the port is not started **/
12120         if (port->port_status != RTE_PORT_STOPPED) {
12121                 printf("Please stop port %d first\n", res->port_id);
12122                 return;
12123         }
12124
12125         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12126
12127         if (!strcmp(res->payload_layer, "raw"))
12128                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12129         else if (!strcmp(res->payload_layer, "l2"))
12130                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12131         else if (!strcmp(res->payload_layer, "l3"))
12132                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12133         else if (!strcmp(res->payload_layer, "l4"))
12134                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12135
12136         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12137                             RTE_ETH_FDIR_MAX_FLEXLEN);
12138         if (ret < 0) {
12139                 printf("error: Cannot parse flex payload input.\n");
12140                 return;
12141         }
12142
12143         fdir_set_flex_payload(res->port_id, &flex_cfg);
12144         cmd_reconfig_device_queue(res->port_id, 1, 1);
12145 }
12146
12147 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12148         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12149                                  flow_director_flexpayload,
12150                                  "flow_director_flex_payload");
12151 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12152         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12153                               port_id, UINT16);
12154 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12155         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12156                                  payload_layer, "raw#l2#l3#l4");
12157 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12158         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12159                                  payload_cfg, NULL);
12160
12161 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12162         .f = cmd_flow_director_flxpld_parsed,
12163         .data = NULL,
12164         .help_str = "flow_director_flexpayload ... : "
12165                 "Set flow director's flex payload on NIC",
12166         .tokens = {
12167                 (void *)&cmd_flow_director_flexpayload,
12168                 (void *)&cmd_flow_director_flexpayload_port_id,
12169                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12170                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12171                 NULL,
12172         },
12173 };
12174
12175 /* Generic flow interface command. */
12176 extern cmdline_parse_inst_t cmd_flow;
12177
12178 /* *** Classification Filters Control *** */
12179 /* *** Get symmetric hash enable per port *** */
12180 struct cmd_get_sym_hash_ena_per_port_result {
12181         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12182         portid_t port_id;
12183 };
12184
12185 static void
12186 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12187                                  __rte_unused struct cmdline *cl,
12188                                  __rte_unused void *data)
12189 {
12190         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12191         struct rte_eth_hash_filter_info info;
12192         int ret;
12193
12194         if (rte_eth_dev_filter_supported(res->port_id,
12195                                 RTE_ETH_FILTER_HASH) < 0) {
12196                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12197                                                         res->port_id);
12198                 return;
12199         }
12200
12201         memset(&info, 0, sizeof(info));
12202         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12203         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12204                                                 RTE_ETH_FILTER_GET, &info);
12205
12206         if (ret < 0) {
12207                 printf("Cannot get symmetric hash enable per port "
12208                                         "on port %u\n", res->port_id);
12209                 return;
12210         }
12211
12212         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12213                                 "enabled" : "disabled", res->port_id);
12214 }
12215
12216 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12217         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12218                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12219 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12220         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12221                 port_id, UINT16);
12222
12223 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12224         .f = cmd_get_sym_hash_per_port_parsed,
12225         .data = NULL,
12226         .help_str = "get_sym_hash_ena_per_port <port_id>",
12227         .tokens = {
12228                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12229                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12230                 NULL,
12231         },
12232 };
12233
12234 /* *** Set symmetric hash enable per port *** */
12235 struct cmd_set_sym_hash_ena_per_port_result {
12236         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12237         cmdline_fixed_string_t enable;
12238         portid_t port_id;
12239 };
12240
12241 static void
12242 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12243                                  __rte_unused struct cmdline *cl,
12244                                  __rte_unused void *data)
12245 {
12246         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12247         struct rte_eth_hash_filter_info info;
12248         int ret;
12249
12250         if (rte_eth_dev_filter_supported(res->port_id,
12251                                 RTE_ETH_FILTER_HASH) < 0) {
12252                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12253                                                         res->port_id);
12254                 return;
12255         }
12256
12257         memset(&info, 0, sizeof(info));
12258         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12259         if (!strcmp(res->enable, "enable"))
12260                 info.info.enable = 1;
12261         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12262                                         RTE_ETH_FILTER_SET, &info);
12263         if (ret < 0) {
12264                 printf("Cannot set symmetric hash enable per port on "
12265                                         "port %u\n", res->port_id);
12266                 return;
12267         }
12268         printf("Symmetric hash has been set to %s on port %u\n",
12269                                         res->enable, res->port_id);
12270 }
12271
12272 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12273         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12274                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12275 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12276         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12277                 port_id, UINT16);
12278 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12279         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12280                 enable, "enable#disable");
12281
12282 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12283         .f = cmd_set_sym_hash_per_port_parsed,
12284         .data = NULL,
12285         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12286         .tokens = {
12287                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12288                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12289                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12290                 NULL,
12291         },
12292 };
12293
12294 /* Get global config of hash function */
12295 struct cmd_get_hash_global_config_result {
12296         cmdline_fixed_string_t get_hash_global_config;
12297         portid_t port_id;
12298 };
12299
12300 static char *
12301 flowtype_to_str(uint16_t ftype)
12302 {
12303         uint16_t i;
12304         static struct {
12305                 char str[16];
12306                 uint16_t ftype;
12307         } ftype_table[] = {
12308                 {"ipv4", RTE_ETH_FLOW_IPV4},
12309                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12310                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12311                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12312                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12313                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12314                 {"ipv6", RTE_ETH_FLOW_IPV6},
12315                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12316                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12317                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12318                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12319                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12320                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12321                 {"port", RTE_ETH_FLOW_PORT},
12322                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12323                 {"geneve", RTE_ETH_FLOW_GENEVE},
12324                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12325                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12326         };
12327
12328         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12329                 if (ftype_table[i].ftype == ftype)
12330                         return ftype_table[i].str;
12331         }
12332
12333         return NULL;
12334 }
12335
12336 static void
12337 cmd_get_hash_global_config_parsed(void *parsed_result,
12338                                   __rte_unused struct cmdline *cl,
12339                                   __rte_unused void *data)
12340 {
12341         struct cmd_get_hash_global_config_result *res = parsed_result;
12342         struct rte_eth_hash_filter_info info;
12343         uint32_t idx, offset;
12344         uint16_t i;
12345         char *str;
12346         int ret;
12347
12348         if (rte_eth_dev_filter_supported(res->port_id,
12349                         RTE_ETH_FILTER_HASH) < 0) {
12350                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12351                                                         res->port_id);
12352                 return;
12353         }
12354
12355         memset(&info, 0, sizeof(info));
12356         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12357         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12358                                         RTE_ETH_FILTER_GET, &info);
12359         if (ret < 0) {
12360                 printf("Cannot get hash global configurations by port %d\n",
12361                                                         res->port_id);
12362                 return;
12363         }
12364
12365         switch (info.info.global_conf.hash_func) {
12366         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12367                 printf("Hash function is Toeplitz\n");
12368                 break;
12369         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12370                 printf("Hash function is Simple XOR\n");
12371                 break;
12372         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12373                 printf("Hash function is Symmetric Toeplitz\n");
12374                 break;
12375         default:
12376                 printf("Unknown hash function\n");
12377                 break;
12378         }
12379
12380         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12381                 idx = i / UINT64_BIT;
12382                 offset = i % UINT64_BIT;
12383                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12384                                                 (1ULL << offset)))
12385                         continue;
12386                 str = flowtype_to_str(i);
12387                 if (!str)
12388                         continue;
12389                 printf("Symmetric hash is %s globally for flow type %s "
12390                                                         "by port %d\n",
12391                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12392                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12393                                                         res->port_id);
12394         }
12395 }
12396
12397 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12398         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12399                 get_hash_global_config, "get_hash_global_config");
12400 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12401         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12402                 port_id, UINT16);
12403
12404 cmdline_parse_inst_t cmd_get_hash_global_config = {
12405         .f = cmd_get_hash_global_config_parsed,
12406         .data = NULL,
12407         .help_str = "get_hash_global_config <port_id>",
12408         .tokens = {
12409                 (void *)&cmd_get_hash_global_config_all,
12410                 (void *)&cmd_get_hash_global_config_port_id,
12411                 NULL,
12412         },
12413 };
12414
12415 /* Set global config of hash function */
12416 struct cmd_set_hash_global_config_result {
12417         cmdline_fixed_string_t set_hash_global_config;
12418         portid_t port_id;
12419         cmdline_fixed_string_t hash_func;
12420         cmdline_fixed_string_t flow_type;
12421         cmdline_fixed_string_t enable;
12422 };
12423
12424 static void
12425 cmd_set_hash_global_config_parsed(void *parsed_result,
12426                                   __rte_unused struct cmdline *cl,
12427                                   __rte_unused void *data)
12428 {
12429         struct cmd_set_hash_global_config_result *res = parsed_result;
12430         struct rte_eth_hash_filter_info info;
12431         uint32_t ftype, idx, offset;
12432         int ret;
12433
12434         if (rte_eth_dev_filter_supported(res->port_id,
12435                                 RTE_ETH_FILTER_HASH) < 0) {
12436                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12437                                                         res->port_id);
12438                 return;
12439         }
12440         memset(&info, 0, sizeof(info));
12441         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12442         if (!strcmp(res->hash_func, "toeplitz"))
12443                 info.info.global_conf.hash_func =
12444                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12445         else if (!strcmp(res->hash_func, "simple_xor"))
12446                 info.info.global_conf.hash_func =
12447                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12448         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12449                 info.info.global_conf.hash_func =
12450                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12451         else if (!strcmp(res->hash_func, "default"))
12452                 info.info.global_conf.hash_func =
12453                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12454
12455         ftype = str2flowtype(res->flow_type);
12456         idx = ftype / UINT64_BIT;
12457         offset = ftype % UINT64_BIT;
12458         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12459         if (!strcmp(res->enable, "enable"))
12460                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12461                                                 (1ULL << offset);
12462         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12463                                         RTE_ETH_FILTER_SET, &info);
12464         if (ret < 0)
12465                 printf("Cannot set global hash configurations by port %d\n",
12466                                                         res->port_id);
12467         else
12468                 printf("Global hash configurations have been set "
12469                         "successfully by port %d\n", res->port_id);
12470 }
12471
12472 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12473         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12474                 set_hash_global_config, "set_hash_global_config");
12475 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12476         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12477                 port_id, UINT16);
12478 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12479         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12480                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12481 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12482         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12483                 flow_type,
12484                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12485                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12486 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12487         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12488                 enable, "enable#disable");
12489
12490 cmdline_parse_inst_t cmd_set_hash_global_config = {
12491         .f = cmd_set_hash_global_config_parsed,
12492         .data = NULL,
12493         .help_str = "set_hash_global_config <port_id> "
12494                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12495                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12496                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12497                 "l2_payload enable|disable",
12498         .tokens = {
12499                 (void *)&cmd_set_hash_global_config_all,
12500                 (void *)&cmd_set_hash_global_config_port_id,
12501                 (void *)&cmd_set_hash_global_config_hash_func,
12502                 (void *)&cmd_set_hash_global_config_flow_type,
12503                 (void *)&cmd_set_hash_global_config_enable,
12504                 NULL,
12505         },
12506 };
12507
12508 /* Set hash input set */
12509 struct cmd_set_hash_input_set_result {
12510         cmdline_fixed_string_t set_hash_input_set;
12511         portid_t port_id;
12512         cmdline_fixed_string_t flow_type;
12513         cmdline_fixed_string_t inset_field;
12514         cmdline_fixed_string_t select;
12515 };
12516
12517 static enum rte_eth_input_set_field
12518 str2inset(char *string)
12519 {
12520         uint16_t i;
12521
12522         static const struct {
12523                 char str[32];
12524                 enum rte_eth_input_set_field inset;
12525         } inset_table[] = {
12526                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12527                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12528                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12529                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12530                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12531                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12532                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12533                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12534                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12535                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12536                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12537                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12538                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12539                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12540                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12541                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12542                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12543                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12544                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12545                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12546                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12547                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12548                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12549                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12550                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12551                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12552                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12553                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12554                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12555                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12556                 {"none", RTE_ETH_INPUT_SET_NONE},
12557         };
12558
12559         for (i = 0; i < RTE_DIM(inset_table); i++) {
12560                 if (!strcmp(string, inset_table[i].str))
12561                         return inset_table[i].inset;
12562         }
12563
12564         return RTE_ETH_INPUT_SET_UNKNOWN;
12565 }
12566
12567 static void
12568 cmd_set_hash_input_set_parsed(void *parsed_result,
12569                               __rte_unused struct cmdline *cl,
12570                               __rte_unused void *data)
12571 {
12572         struct cmd_set_hash_input_set_result *res = parsed_result;
12573         struct rte_eth_hash_filter_info info;
12574
12575         memset(&info, 0, sizeof(info));
12576         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12577         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12578         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12579         info.info.input_set_conf.inset_size = 1;
12580         if (!strcmp(res->select, "select"))
12581                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12582         else if (!strcmp(res->select, "add"))
12583                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12584         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12585                                 RTE_ETH_FILTER_SET, &info);
12586 }
12587
12588 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12589         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12590                 set_hash_input_set, "set_hash_input_set");
12591 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12592         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12593                 port_id, UINT16);
12594 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12595         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12596                 flow_type, NULL);
12597 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12598         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12599                 inset_field,
12600                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12601                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12602                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12603                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12604                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12605                 "fld-8th#none");
12606 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12607         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12608                 select, "select#add");
12609
12610 cmdline_parse_inst_t cmd_set_hash_input_set = {
12611         .f = cmd_set_hash_input_set_parsed,
12612         .data = NULL,
12613         .help_str = "set_hash_input_set <port_id> "
12614         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12615         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12616         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12617         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12618         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12619         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12620         "fld-7th|fld-8th|none select|add",
12621         .tokens = {
12622                 (void *)&cmd_set_hash_input_set_cmd,
12623                 (void *)&cmd_set_hash_input_set_port_id,
12624                 (void *)&cmd_set_hash_input_set_flow_type,
12625                 (void *)&cmd_set_hash_input_set_field,
12626                 (void *)&cmd_set_hash_input_set_select,
12627                 NULL,
12628         },
12629 };
12630
12631 /* Set flow director input set */
12632 struct cmd_set_fdir_input_set_result {
12633         cmdline_fixed_string_t set_fdir_input_set;
12634         portid_t port_id;
12635         cmdline_fixed_string_t flow_type;
12636         cmdline_fixed_string_t inset_field;
12637         cmdline_fixed_string_t select;
12638 };
12639
12640 static void
12641 cmd_set_fdir_input_set_parsed(void *parsed_result,
12642         __rte_unused struct cmdline *cl,
12643         __rte_unused void *data)
12644 {
12645         struct cmd_set_fdir_input_set_result *res = parsed_result;
12646         struct rte_eth_fdir_filter_info info;
12647
12648         memset(&info, 0, sizeof(info));
12649         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12650         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12651         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12652         info.info.input_set_conf.inset_size = 1;
12653         if (!strcmp(res->select, "select"))
12654                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12655         else if (!strcmp(res->select, "add"))
12656                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12657         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12658                 RTE_ETH_FILTER_SET, &info);
12659 }
12660
12661 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12662         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12663         set_fdir_input_set, "set_fdir_input_set");
12664 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12665         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12666         port_id, UINT16);
12667 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12668         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12669         flow_type,
12670         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12671         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12672 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12673         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12674         inset_field,
12675         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12676         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12677         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12678         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12679         "sctp-veri-tag#none");
12680 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12681         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12682         select, "select#add");
12683
12684 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12685         .f = cmd_set_fdir_input_set_parsed,
12686         .data = NULL,
12687         .help_str = "set_fdir_input_set <port_id> "
12688         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12689         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12690         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12691         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12692         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12693         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12694         "sctp-veri-tag|none select|add",
12695         .tokens = {
12696                 (void *)&cmd_set_fdir_input_set_cmd,
12697                 (void *)&cmd_set_fdir_input_set_port_id,
12698                 (void *)&cmd_set_fdir_input_set_flow_type,
12699                 (void *)&cmd_set_fdir_input_set_field,
12700                 (void *)&cmd_set_fdir_input_set_select,
12701                 NULL,
12702         },
12703 };
12704
12705 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12706 struct cmd_mcast_addr_result {
12707         cmdline_fixed_string_t mcast_addr_cmd;
12708         cmdline_fixed_string_t what;
12709         uint16_t port_num;
12710         struct rte_ether_addr mc_addr;
12711 };
12712
12713 static void cmd_mcast_addr_parsed(void *parsed_result,
12714                 __rte_unused struct cmdline *cl,
12715                 __rte_unused void *data)
12716 {
12717         struct cmd_mcast_addr_result *res = parsed_result;
12718
12719         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12720                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12721                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12722                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12723                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12724                 return;
12725         }
12726         if (strcmp(res->what, "add") == 0)
12727                 mcast_addr_add(res->port_num, &res->mc_addr);
12728         else
12729                 mcast_addr_remove(res->port_num, &res->mc_addr);
12730 }
12731
12732 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12733         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12734                                  mcast_addr_cmd, "mcast_addr");
12735 cmdline_parse_token_string_t cmd_mcast_addr_what =
12736         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12737                                  "add#remove");
12738 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12739         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12740 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12741         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12742
12743 cmdline_parse_inst_t cmd_mcast_addr = {
12744         .f = cmd_mcast_addr_parsed,
12745         .data = (void *)0,
12746         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12747                 "Add/Remove multicast MAC address on port_id",
12748         .tokens = {
12749                 (void *)&cmd_mcast_addr_cmd,
12750                 (void *)&cmd_mcast_addr_what,
12751                 (void *)&cmd_mcast_addr_portnum,
12752                 (void *)&cmd_mcast_addr_addr,
12753                 NULL,
12754         },
12755 };
12756
12757 /* l2 tunnel config
12758  * only support E-tag now.
12759  */
12760
12761 /* Ether type config */
12762 struct cmd_config_l2_tunnel_eth_type_result {
12763         cmdline_fixed_string_t port;
12764         cmdline_fixed_string_t config;
12765         cmdline_fixed_string_t all;
12766         portid_t id;
12767         cmdline_fixed_string_t l2_tunnel;
12768         cmdline_fixed_string_t l2_tunnel_type;
12769         cmdline_fixed_string_t eth_type;
12770         uint16_t eth_type_val;
12771 };
12772
12773 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12774         TOKEN_STRING_INITIALIZER
12775                 (struct cmd_config_l2_tunnel_eth_type_result,
12776                  port, "port");
12777 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12778         TOKEN_STRING_INITIALIZER
12779                 (struct cmd_config_l2_tunnel_eth_type_result,
12780                  config, "config");
12781 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12782         TOKEN_STRING_INITIALIZER
12783                 (struct cmd_config_l2_tunnel_eth_type_result,
12784                  all, "all");
12785 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12786         TOKEN_NUM_INITIALIZER
12787                 (struct cmd_config_l2_tunnel_eth_type_result,
12788                  id, UINT16);
12789 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12790         TOKEN_STRING_INITIALIZER
12791                 (struct cmd_config_l2_tunnel_eth_type_result,
12792                  l2_tunnel, "l2-tunnel");
12793 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12794         TOKEN_STRING_INITIALIZER
12795                 (struct cmd_config_l2_tunnel_eth_type_result,
12796                  l2_tunnel_type, "E-tag");
12797 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12798         TOKEN_STRING_INITIALIZER
12799                 (struct cmd_config_l2_tunnel_eth_type_result,
12800                  eth_type, "ether-type");
12801 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12802         TOKEN_NUM_INITIALIZER
12803                 (struct cmd_config_l2_tunnel_eth_type_result,
12804                  eth_type_val, UINT16);
12805
12806 static enum rte_eth_tunnel_type
12807 str2fdir_l2_tunnel_type(char *string)
12808 {
12809         uint32_t i = 0;
12810
12811         static const struct {
12812                 char str[32];
12813                 enum rte_eth_tunnel_type type;
12814         } l2_tunnel_type_str[] = {
12815                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12816         };
12817
12818         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12819                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12820                         return l2_tunnel_type_str[i].type;
12821         }
12822         return RTE_TUNNEL_TYPE_NONE;
12823 }
12824
12825 /* ether type config for all ports */
12826 static void
12827 cmd_config_l2_tunnel_eth_type_all_parsed
12828         (void *parsed_result,
12829          __rte_unused struct cmdline *cl,
12830          __rte_unused void *data)
12831 {
12832         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12833         struct rte_eth_l2_tunnel_conf entry;
12834         portid_t pid;
12835
12836         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12837         entry.ether_type = res->eth_type_val;
12838
12839         RTE_ETH_FOREACH_DEV(pid) {
12840                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12841         }
12842 }
12843
12844 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12845         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12846         .data = NULL,
12847         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12848         .tokens = {
12849                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12850                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12851                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12852                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12853                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12854                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12855                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12856                 NULL,
12857         },
12858 };
12859
12860 /* ether type config for a specific port */
12861 static void
12862 cmd_config_l2_tunnel_eth_type_specific_parsed(
12863         void *parsed_result,
12864         __rte_unused struct cmdline *cl,
12865         __rte_unused void *data)
12866 {
12867         struct cmd_config_l2_tunnel_eth_type_result *res =
12868                  parsed_result;
12869         struct rte_eth_l2_tunnel_conf entry;
12870
12871         if (port_id_is_invalid(res->id, ENABLED_WARN))
12872                 return;
12873
12874         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12875         entry.ether_type = res->eth_type_val;
12876
12877         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12878 }
12879
12880 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12881         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12882         .data = NULL,
12883         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12884         .tokens = {
12885                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12886                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12887                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12888                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12889                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12890                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12891                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12892                 NULL,
12893         },
12894 };
12895
12896 /* Enable/disable l2 tunnel */
12897 struct cmd_config_l2_tunnel_en_dis_result {
12898         cmdline_fixed_string_t port;
12899         cmdline_fixed_string_t config;
12900         cmdline_fixed_string_t all;
12901         portid_t id;
12902         cmdline_fixed_string_t l2_tunnel;
12903         cmdline_fixed_string_t l2_tunnel_type;
12904         cmdline_fixed_string_t en_dis;
12905 };
12906
12907 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12908         TOKEN_STRING_INITIALIZER
12909                 (struct cmd_config_l2_tunnel_en_dis_result,
12910                  port, "port");
12911 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12912         TOKEN_STRING_INITIALIZER
12913                 (struct cmd_config_l2_tunnel_en_dis_result,
12914                  config, "config");
12915 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12916         TOKEN_STRING_INITIALIZER
12917                 (struct cmd_config_l2_tunnel_en_dis_result,
12918                  all, "all");
12919 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12920         TOKEN_NUM_INITIALIZER
12921                 (struct cmd_config_l2_tunnel_en_dis_result,
12922                  id, UINT16);
12923 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12924         TOKEN_STRING_INITIALIZER
12925                 (struct cmd_config_l2_tunnel_en_dis_result,
12926                  l2_tunnel, "l2-tunnel");
12927 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12928         TOKEN_STRING_INITIALIZER
12929                 (struct cmd_config_l2_tunnel_en_dis_result,
12930                  l2_tunnel_type, "E-tag");
12931 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12932         TOKEN_STRING_INITIALIZER
12933                 (struct cmd_config_l2_tunnel_en_dis_result,
12934                  en_dis, "enable#disable");
12935
12936 /* enable/disable l2 tunnel for all ports */
12937 static void
12938 cmd_config_l2_tunnel_en_dis_all_parsed(
12939         void *parsed_result,
12940         __rte_unused struct cmdline *cl,
12941         __rte_unused void *data)
12942 {
12943         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12944         struct rte_eth_l2_tunnel_conf entry;
12945         portid_t pid;
12946         uint8_t en;
12947
12948         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12949
12950         if (!strcmp("enable", res->en_dis))
12951                 en = 1;
12952         else
12953                 en = 0;
12954
12955         RTE_ETH_FOREACH_DEV(pid) {
12956                 rte_eth_dev_l2_tunnel_offload_set(pid,
12957                                                   &entry,
12958                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12959                                                   en);
12960         }
12961 }
12962
12963 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12964         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12965         .data = NULL,
12966         .help_str = "port config all l2-tunnel E-tag enable|disable",
12967         .tokens = {
12968                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12969                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12970                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12971                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12972                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12973                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12974                 NULL,
12975         },
12976 };
12977
12978 /* enable/disable l2 tunnel for a port */
12979 static void
12980 cmd_config_l2_tunnel_en_dis_specific_parsed(
12981         void *parsed_result,
12982         __rte_unused struct cmdline *cl,
12983         __rte_unused void *data)
12984 {
12985         struct cmd_config_l2_tunnel_en_dis_result *res =
12986                 parsed_result;
12987         struct rte_eth_l2_tunnel_conf entry;
12988
12989         if (port_id_is_invalid(res->id, ENABLED_WARN))
12990                 return;
12991
12992         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12993
12994         if (!strcmp("enable", res->en_dis))
12995                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12996                                                   &entry,
12997                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12998                                                   1);
12999         else
13000                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13001                                                   &entry,
13002                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13003                                                   0);
13004 }
13005
13006 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13007         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13008         .data = NULL,
13009         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13010         .tokens = {
13011                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13012                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13013                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13014                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13015                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13016                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13017                 NULL,
13018         },
13019 };
13020
13021 /* E-tag configuration */
13022
13023 /* Common result structure for all E-tag configuration */
13024 struct cmd_config_e_tag_result {
13025         cmdline_fixed_string_t e_tag;
13026         cmdline_fixed_string_t set;
13027         cmdline_fixed_string_t insertion;
13028         cmdline_fixed_string_t stripping;
13029         cmdline_fixed_string_t forwarding;
13030         cmdline_fixed_string_t filter;
13031         cmdline_fixed_string_t add;
13032         cmdline_fixed_string_t del;
13033         cmdline_fixed_string_t on;
13034         cmdline_fixed_string_t off;
13035         cmdline_fixed_string_t on_off;
13036         cmdline_fixed_string_t port_tag_id;
13037         uint32_t port_tag_id_val;
13038         cmdline_fixed_string_t e_tag_id;
13039         uint16_t e_tag_id_val;
13040         cmdline_fixed_string_t dst_pool;
13041         uint8_t dst_pool_val;
13042         cmdline_fixed_string_t port;
13043         portid_t port_id;
13044         cmdline_fixed_string_t vf;
13045         uint8_t vf_id;
13046 };
13047
13048 /* Common CLI fields for all E-tag configuration */
13049 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13050         TOKEN_STRING_INITIALIZER
13051                 (struct cmd_config_e_tag_result,
13052                  e_tag, "E-tag");
13053 cmdline_parse_token_string_t cmd_config_e_tag_set =
13054         TOKEN_STRING_INITIALIZER
13055                 (struct cmd_config_e_tag_result,
13056                  set, "set");
13057 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13058         TOKEN_STRING_INITIALIZER
13059                 (struct cmd_config_e_tag_result,
13060                  insertion, "insertion");
13061 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13062         TOKEN_STRING_INITIALIZER
13063                 (struct cmd_config_e_tag_result,
13064                  stripping, "stripping");
13065 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13066         TOKEN_STRING_INITIALIZER
13067                 (struct cmd_config_e_tag_result,
13068                  forwarding, "forwarding");
13069 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13070         TOKEN_STRING_INITIALIZER
13071                 (struct cmd_config_e_tag_result,
13072                  filter, "filter");
13073 cmdline_parse_token_string_t cmd_config_e_tag_add =
13074         TOKEN_STRING_INITIALIZER
13075                 (struct cmd_config_e_tag_result,
13076                  add, "add");
13077 cmdline_parse_token_string_t cmd_config_e_tag_del =
13078         TOKEN_STRING_INITIALIZER
13079                 (struct cmd_config_e_tag_result,
13080                  del, "del");
13081 cmdline_parse_token_string_t cmd_config_e_tag_on =
13082         TOKEN_STRING_INITIALIZER
13083                 (struct cmd_config_e_tag_result,
13084                  on, "on");
13085 cmdline_parse_token_string_t cmd_config_e_tag_off =
13086         TOKEN_STRING_INITIALIZER
13087                 (struct cmd_config_e_tag_result,
13088                  off, "off");
13089 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13090         TOKEN_STRING_INITIALIZER
13091                 (struct cmd_config_e_tag_result,
13092                  on_off, "on#off");
13093 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13094         TOKEN_STRING_INITIALIZER
13095                 (struct cmd_config_e_tag_result,
13096                  port_tag_id, "port-tag-id");
13097 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13098         TOKEN_NUM_INITIALIZER
13099                 (struct cmd_config_e_tag_result,
13100                  port_tag_id_val, UINT32);
13101 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13102         TOKEN_STRING_INITIALIZER
13103                 (struct cmd_config_e_tag_result,
13104                  e_tag_id, "e-tag-id");
13105 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13106         TOKEN_NUM_INITIALIZER
13107                 (struct cmd_config_e_tag_result,
13108                  e_tag_id_val, UINT16);
13109 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13110         TOKEN_STRING_INITIALIZER
13111                 (struct cmd_config_e_tag_result,
13112                  dst_pool, "dst-pool");
13113 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13114         TOKEN_NUM_INITIALIZER
13115                 (struct cmd_config_e_tag_result,
13116                  dst_pool_val, UINT8);
13117 cmdline_parse_token_string_t cmd_config_e_tag_port =
13118         TOKEN_STRING_INITIALIZER
13119                 (struct cmd_config_e_tag_result,
13120                  port, "port");
13121 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13122         TOKEN_NUM_INITIALIZER
13123                 (struct cmd_config_e_tag_result,
13124                  port_id, UINT16);
13125 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13126         TOKEN_STRING_INITIALIZER
13127                 (struct cmd_config_e_tag_result,
13128                  vf, "vf");
13129 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13130         TOKEN_NUM_INITIALIZER
13131                 (struct cmd_config_e_tag_result,
13132                  vf_id, UINT8);
13133
13134 /* E-tag insertion configuration */
13135 static void
13136 cmd_config_e_tag_insertion_en_parsed(
13137         void *parsed_result,
13138         __rte_unused struct cmdline *cl,
13139         __rte_unused void *data)
13140 {
13141         struct cmd_config_e_tag_result *res =
13142                 parsed_result;
13143         struct rte_eth_l2_tunnel_conf entry;
13144
13145         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13146                 return;
13147
13148         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13149         entry.tunnel_id = res->port_tag_id_val;
13150         entry.vf_id = res->vf_id;
13151         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13152                                           &entry,
13153                                           ETH_L2_TUNNEL_INSERTION_MASK,
13154                                           1);
13155 }
13156
13157 static void
13158 cmd_config_e_tag_insertion_dis_parsed(
13159         void *parsed_result,
13160         __rte_unused struct cmdline *cl,
13161         __rte_unused void *data)
13162 {
13163         struct cmd_config_e_tag_result *res =
13164                 parsed_result;
13165         struct rte_eth_l2_tunnel_conf entry;
13166
13167         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13168                 return;
13169
13170         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13171         entry.vf_id = res->vf_id;
13172
13173         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13174                                           &entry,
13175                                           ETH_L2_TUNNEL_INSERTION_MASK,
13176                                           0);
13177 }
13178
13179 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13180         .f = cmd_config_e_tag_insertion_en_parsed,
13181         .data = NULL,
13182         .help_str = "E-tag ... : E-tag insertion enable",
13183         .tokens = {
13184                 (void *)&cmd_config_e_tag_e_tag,
13185                 (void *)&cmd_config_e_tag_set,
13186                 (void *)&cmd_config_e_tag_insertion,
13187                 (void *)&cmd_config_e_tag_on,
13188                 (void *)&cmd_config_e_tag_port_tag_id,
13189                 (void *)&cmd_config_e_tag_port_tag_id_val,
13190                 (void *)&cmd_config_e_tag_port,
13191                 (void *)&cmd_config_e_tag_port_id,
13192                 (void *)&cmd_config_e_tag_vf,
13193                 (void *)&cmd_config_e_tag_vf_id,
13194                 NULL,
13195         },
13196 };
13197
13198 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13199         .f = cmd_config_e_tag_insertion_dis_parsed,
13200         .data = NULL,
13201         .help_str = "E-tag ... : E-tag insertion disable",
13202         .tokens = {
13203                 (void *)&cmd_config_e_tag_e_tag,
13204                 (void *)&cmd_config_e_tag_set,
13205                 (void *)&cmd_config_e_tag_insertion,
13206                 (void *)&cmd_config_e_tag_off,
13207                 (void *)&cmd_config_e_tag_port,
13208                 (void *)&cmd_config_e_tag_port_id,
13209                 (void *)&cmd_config_e_tag_vf,
13210                 (void *)&cmd_config_e_tag_vf_id,
13211                 NULL,
13212         },
13213 };
13214
13215 /* E-tag stripping configuration */
13216 static void
13217 cmd_config_e_tag_stripping_parsed(
13218         void *parsed_result,
13219         __rte_unused struct cmdline *cl,
13220         __rte_unused void *data)
13221 {
13222         struct cmd_config_e_tag_result *res =
13223                 parsed_result;
13224         struct rte_eth_l2_tunnel_conf entry;
13225
13226         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13227                 return;
13228
13229         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13230
13231         if (!strcmp(res->on_off, "on"))
13232                 rte_eth_dev_l2_tunnel_offload_set
13233                         (res->port_id,
13234                          &entry,
13235                          ETH_L2_TUNNEL_STRIPPING_MASK,
13236                          1);
13237         else
13238                 rte_eth_dev_l2_tunnel_offload_set
13239                         (res->port_id,
13240                          &entry,
13241                          ETH_L2_TUNNEL_STRIPPING_MASK,
13242                          0);
13243 }
13244
13245 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13246         .f = cmd_config_e_tag_stripping_parsed,
13247         .data = NULL,
13248         .help_str = "E-tag ... : E-tag stripping enable/disable",
13249         .tokens = {
13250                 (void *)&cmd_config_e_tag_e_tag,
13251                 (void *)&cmd_config_e_tag_set,
13252                 (void *)&cmd_config_e_tag_stripping,
13253                 (void *)&cmd_config_e_tag_on_off,
13254                 (void *)&cmd_config_e_tag_port,
13255                 (void *)&cmd_config_e_tag_port_id,
13256                 NULL,
13257         },
13258 };
13259
13260 /* E-tag forwarding configuration */
13261 static void
13262 cmd_config_e_tag_forwarding_parsed(
13263         void *parsed_result,
13264         __rte_unused struct cmdline *cl,
13265         __rte_unused void *data)
13266 {
13267         struct cmd_config_e_tag_result *res = parsed_result;
13268         struct rte_eth_l2_tunnel_conf entry;
13269
13270         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13271                 return;
13272
13273         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13274
13275         if (!strcmp(res->on_off, "on"))
13276                 rte_eth_dev_l2_tunnel_offload_set
13277                         (res->port_id,
13278                          &entry,
13279                          ETH_L2_TUNNEL_FORWARDING_MASK,
13280                          1);
13281         else
13282                 rte_eth_dev_l2_tunnel_offload_set
13283                         (res->port_id,
13284                          &entry,
13285                          ETH_L2_TUNNEL_FORWARDING_MASK,
13286                          0);
13287 }
13288
13289 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13290         .f = cmd_config_e_tag_forwarding_parsed,
13291         .data = NULL,
13292         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13293         .tokens = {
13294                 (void *)&cmd_config_e_tag_e_tag,
13295                 (void *)&cmd_config_e_tag_set,
13296                 (void *)&cmd_config_e_tag_forwarding,
13297                 (void *)&cmd_config_e_tag_on_off,
13298                 (void *)&cmd_config_e_tag_port,
13299                 (void *)&cmd_config_e_tag_port_id,
13300                 NULL,
13301         },
13302 };
13303
13304 /* E-tag filter configuration */
13305 static void
13306 cmd_config_e_tag_filter_add_parsed(
13307         void *parsed_result,
13308         __rte_unused struct cmdline *cl,
13309         __rte_unused void *data)
13310 {
13311         struct cmd_config_e_tag_result *res = parsed_result;
13312         struct rte_eth_l2_tunnel_conf entry;
13313         int ret = 0;
13314
13315         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13316                 return;
13317
13318         if (res->e_tag_id_val > 0x3fff) {
13319                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13320                 return;
13321         }
13322
13323         ret = rte_eth_dev_filter_supported(res->port_id,
13324                                            RTE_ETH_FILTER_L2_TUNNEL);
13325         if (ret < 0) {
13326                 printf("E-tag filter is not supported on port %u.\n",
13327                        res->port_id);
13328                 return;
13329         }
13330
13331         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13332         entry.tunnel_id = res->e_tag_id_val;
13333         entry.pool = res->dst_pool_val;
13334
13335         ret = rte_eth_dev_filter_ctrl(res->port_id,
13336                                       RTE_ETH_FILTER_L2_TUNNEL,
13337                                       RTE_ETH_FILTER_ADD,
13338                                       &entry);
13339         if (ret < 0)
13340                 printf("E-tag filter programming error: (%s)\n",
13341                        strerror(-ret));
13342 }
13343
13344 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13345         .f = cmd_config_e_tag_filter_add_parsed,
13346         .data = NULL,
13347         .help_str = "E-tag ... : E-tag filter add",
13348         .tokens = {
13349                 (void *)&cmd_config_e_tag_e_tag,
13350                 (void *)&cmd_config_e_tag_set,
13351                 (void *)&cmd_config_e_tag_filter,
13352                 (void *)&cmd_config_e_tag_add,
13353                 (void *)&cmd_config_e_tag_e_tag_id,
13354                 (void *)&cmd_config_e_tag_e_tag_id_val,
13355                 (void *)&cmd_config_e_tag_dst_pool,
13356                 (void *)&cmd_config_e_tag_dst_pool_val,
13357                 (void *)&cmd_config_e_tag_port,
13358                 (void *)&cmd_config_e_tag_port_id,
13359                 NULL,
13360         },
13361 };
13362
13363 static void
13364 cmd_config_e_tag_filter_del_parsed(
13365         void *parsed_result,
13366         __rte_unused struct cmdline *cl,
13367         __rte_unused void *data)
13368 {
13369         struct cmd_config_e_tag_result *res = parsed_result;
13370         struct rte_eth_l2_tunnel_conf entry;
13371         int ret = 0;
13372
13373         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13374                 return;
13375
13376         if (res->e_tag_id_val > 0x3fff) {
13377                 printf("e-tag-id must be less than 0x3fff.\n");
13378                 return;
13379         }
13380
13381         ret = rte_eth_dev_filter_supported(res->port_id,
13382                                            RTE_ETH_FILTER_L2_TUNNEL);
13383         if (ret < 0) {
13384                 printf("E-tag filter is not supported on port %u.\n",
13385                        res->port_id);
13386                 return;
13387         }
13388
13389         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13390         entry.tunnel_id = res->e_tag_id_val;
13391
13392         ret = rte_eth_dev_filter_ctrl(res->port_id,
13393                                       RTE_ETH_FILTER_L2_TUNNEL,
13394                                       RTE_ETH_FILTER_DELETE,
13395                                       &entry);
13396         if (ret < 0)
13397                 printf("E-tag filter programming error: (%s)\n",
13398                        strerror(-ret));
13399 }
13400
13401 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13402         .f = cmd_config_e_tag_filter_del_parsed,
13403         .data = NULL,
13404         .help_str = "E-tag ... : E-tag filter delete",
13405         .tokens = {
13406                 (void *)&cmd_config_e_tag_e_tag,
13407                 (void *)&cmd_config_e_tag_set,
13408                 (void *)&cmd_config_e_tag_filter,
13409                 (void *)&cmd_config_e_tag_del,
13410                 (void *)&cmd_config_e_tag_e_tag_id,
13411                 (void *)&cmd_config_e_tag_e_tag_id_val,
13412                 (void *)&cmd_config_e_tag_port,
13413                 (void *)&cmd_config_e_tag_port_id,
13414                 NULL,
13415         },
13416 };
13417
13418 /* vf vlan anti spoof configuration */
13419
13420 /* Common result structure for vf vlan anti spoof */
13421 struct cmd_vf_vlan_anti_spoof_result {
13422         cmdline_fixed_string_t set;
13423         cmdline_fixed_string_t vf;
13424         cmdline_fixed_string_t vlan;
13425         cmdline_fixed_string_t antispoof;
13426         portid_t port_id;
13427         uint32_t vf_id;
13428         cmdline_fixed_string_t on_off;
13429 };
13430
13431 /* Common CLI fields for vf vlan anti spoof enable disable */
13432 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13433         TOKEN_STRING_INITIALIZER
13434                 (struct cmd_vf_vlan_anti_spoof_result,
13435                  set, "set");
13436 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13437         TOKEN_STRING_INITIALIZER
13438                 (struct cmd_vf_vlan_anti_spoof_result,
13439                  vf, "vf");
13440 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13441         TOKEN_STRING_INITIALIZER
13442                 (struct cmd_vf_vlan_anti_spoof_result,
13443                  vlan, "vlan");
13444 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13445         TOKEN_STRING_INITIALIZER
13446                 (struct cmd_vf_vlan_anti_spoof_result,
13447                  antispoof, "antispoof");
13448 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13449         TOKEN_NUM_INITIALIZER
13450                 (struct cmd_vf_vlan_anti_spoof_result,
13451                  port_id, UINT16);
13452 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13453         TOKEN_NUM_INITIALIZER
13454                 (struct cmd_vf_vlan_anti_spoof_result,
13455                  vf_id, UINT32);
13456 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13457         TOKEN_STRING_INITIALIZER
13458                 (struct cmd_vf_vlan_anti_spoof_result,
13459                  on_off, "on#off");
13460
13461 static void
13462 cmd_set_vf_vlan_anti_spoof_parsed(
13463         void *parsed_result,
13464         __rte_unused struct cmdline *cl,
13465         __rte_unused void *data)
13466 {
13467         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13468         int ret = -ENOTSUP;
13469
13470         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13471
13472         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13473                 return;
13474
13475 #ifdef RTE_LIBRTE_IXGBE_PMD
13476         if (ret == -ENOTSUP)
13477                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13478                                 res->vf_id, is_on);
13479 #endif
13480 #ifdef RTE_LIBRTE_I40E_PMD
13481         if (ret == -ENOTSUP)
13482                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13483                                 res->vf_id, is_on);
13484 #endif
13485 #ifdef RTE_LIBRTE_BNXT_PMD
13486         if (ret == -ENOTSUP)
13487                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13488                                 res->vf_id, is_on);
13489 #endif
13490
13491         switch (ret) {
13492         case 0:
13493                 break;
13494         case -EINVAL:
13495                 printf("invalid vf_id %d\n", res->vf_id);
13496                 break;
13497         case -ENODEV:
13498                 printf("invalid port_id %d\n", res->port_id);
13499                 break;
13500         case -ENOTSUP:
13501                 printf("function not implemented\n");
13502                 break;
13503         default:
13504                 printf("programming error: (%s)\n", strerror(-ret));
13505         }
13506 }
13507
13508 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13509         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13510         .data = NULL,
13511         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13512         .tokens = {
13513                 (void *)&cmd_vf_vlan_anti_spoof_set,
13514                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13515                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13516                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13517                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13518                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13519                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13520                 NULL,
13521         },
13522 };
13523
13524 /* vf mac anti spoof configuration */
13525
13526 /* Common result structure for vf mac anti spoof */
13527 struct cmd_vf_mac_anti_spoof_result {
13528         cmdline_fixed_string_t set;
13529         cmdline_fixed_string_t vf;
13530         cmdline_fixed_string_t mac;
13531         cmdline_fixed_string_t antispoof;
13532         portid_t port_id;
13533         uint32_t vf_id;
13534         cmdline_fixed_string_t on_off;
13535 };
13536
13537 /* Common CLI fields for vf mac anti spoof enable disable */
13538 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13539         TOKEN_STRING_INITIALIZER
13540                 (struct cmd_vf_mac_anti_spoof_result,
13541                  set, "set");
13542 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13543         TOKEN_STRING_INITIALIZER
13544                 (struct cmd_vf_mac_anti_spoof_result,
13545                  vf, "vf");
13546 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13547         TOKEN_STRING_INITIALIZER
13548                 (struct cmd_vf_mac_anti_spoof_result,
13549                  mac, "mac");
13550 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13551         TOKEN_STRING_INITIALIZER
13552                 (struct cmd_vf_mac_anti_spoof_result,
13553                  antispoof, "antispoof");
13554 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13555         TOKEN_NUM_INITIALIZER
13556                 (struct cmd_vf_mac_anti_spoof_result,
13557                  port_id, UINT16);
13558 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13559         TOKEN_NUM_INITIALIZER
13560                 (struct cmd_vf_mac_anti_spoof_result,
13561                  vf_id, UINT32);
13562 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13563         TOKEN_STRING_INITIALIZER
13564                 (struct cmd_vf_mac_anti_spoof_result,
13565                  on_off, "on#off");
13566
13567 static void
13568 cmd_set_vf_mac_anti_spoof_parsed(
13569         void *parsed_result,
13570         __rte_unused struct cmdline *cl,
13571         __rte_unused void *data)
13572 {
13573         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13574         int ret = -ENOTSUP;
13575
13576         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13577
13578         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13579                 return;
13580
13581 #ifdef RTE_LIBRTE_IXGBE_PMD
13582         if (ret == -ENOTSUP)
13583                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13584                         res->vf_id, is_on);
13585 #endif
13586 #ifdef RTE_LIBRTE_I40E_PMD
13587         if (ret == -ENOTSUP)
13588                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13589                         res->vf_id, is_on);
13590 #endif
13591 #ifdef RTE_LIBRTE_BNXT_PMD
13592         if (ret == -ENOTSUP)
13593                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13594                         res->vf_id, is_on);
13595 #endif
13596
13597         switch (ret) {
13598         case 0:
13599                 break;
13600         case -EINVAL:
13601                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13602                 break;
13603         case -ENODEV:
13604                 printf("invalid port_id %d\n", res->port_id);
13605                 break;
13606         case -ENOTSUP:
13607                 printf("function not implemented\n");
13608                 break;
13609         default:
13610                 printf("programming error: (%s)\n", strerror(-ret));
13611         }
13612 }
13613
13614 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13615         .f = cmd_set_vf_mac_anti_spoof_parsed,
13616         .data = NULL,
13617         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13618         .tokens = {
13619                 (void *)&cmd_vf_mac_anti_spoof_set,
13620                 (void *)&cmd_vf_mac_anti_spoof_vf,
13621                 (void *)&cmd_vf_mac_anti_spoof_mac,
13622                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13623                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13624                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13625                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13626                 NULL,
13627         },
13628 };
13629
13630 /* vf vlan strip queue configuration */
13631
13632 /* Common result structure for vf mac anti spoof */
13633 struct cmd_vf_vlan_stripq_result {
13634         cmdline_fixed_string_t set;
13635         cmdline_fixed_string_t vf;
13636         cmdline_fixed_string_t vlan;
13637         cmdline_fixed_string_t stripq;
13638         portid_t port_id;
13639         uint16_t vf_id;
13640         cmdline_fixed_string_t on_off;
13641 };
13642
13643 /* Common CLI fields for vf vlan strip enable disable */
13644 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13645         TOKEN_STRING_INITIALIZER
13646                 (struct cmd_vf_vlan_stripq_result,
13647                  set, "set");
13648 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13649         TOKEN_STRING_INITIALIZER
13650                 (struct cmd_vf_vlan_stripq_result,
13651                  vf, "vf");
13652 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13653         TOKEN_STRING_INITIALIZER
13654                 (struct cmd_vf_vlan_stripq_result,
13655                  vlan, "vlan");
13656 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13657         TOKEN_STRING_INITIALIZER
13658                 (struct cmd_vf_vlan_stripq_result,
13659                  stripq, "stripq");
13660 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13661         TOKEN_NUM_INITIALIZER
13662                 (struct cmd_vf_vlan_stripq_result,
13663                  port_id, UINT16);
13664 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13665         TOKEN_NUM_INITIALIZER
13666                 (struct cmd_vf_vlan_stripq_result,
13667                  vf_id, UINT16);
13668 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13669         TOKEN_STRING_INITIALIZER
13670                 (struct cmd_vf_vlan_stripq_result,
13671                  on_off, "on#off");
13672
13673 static void
13674 cmd_set_vf_vlan_stripq_parsed(
13675         void *parsed_result,
13676         __rte_unused struct cmdline *cl,
13677         __rte_unused void *data)
13678 {
13679         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13680         int ret = -ENOTSUP;
13681
13682         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13683
13684         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13685                 return;
13686
13687 #ifdef RTE_LIBRTE_IXGBE_PMD
13688         if (ret == -ENOTSUP)
13689                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13690                         res->vf_id, is_on);
13691 #endif
13692 #ifdef RTE_LIBRTE_I40E_PMD
13693         if (ret == -ENOTSUP)
13694                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13695                         res->vf_id, is_on);
13696 #endif
13697 #ifdef RTE_LIBRTE_BNXT_PMD
13698         if (ret == -ENOTSUP)
13699                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13700                         res->vf_id, is_on);
13701 #endif
13702
13703         switch (ret) {
13704         case 0:
13705                 break;
13706         case -EINVAL:
13707                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13708                 break;
13709         case -ENODEV:
13710                 printf("invalid port_id %d\n", res->port_id);
13711                 break;
13712         case -ENOTSUP:
13713                 printf("function not implemented\n");
13714                 break;
13715         default:
13716                 printf("programming error: (%s)\n", strerror(-ret));
13717         }
13718 }
13719
13720 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13721         .f = cmd_set_vf_vlan_stripq_parsed,
13722         .data = NULL,
13723         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13724         .tokens = {
13725                 (void *)&cmd_vf_vlan_stripq_set,
13726                 (void *)&cmd_vf_vlan_stripq_vf,
13727                 (void *)&cmd_vf_vlan_stripq_vlan,
13728                 (void *)&cmd_vf_vlan_stripq_stripq,
13729                 (void *)&cmd_vf_vlan_stripq_port_id,
13730                 (void *)&cmd_vf_vlan_stripq_vf_id,
13731                 (void *)&cmd_vf_vlan_stripq_on_off,
13732                 NULL,
13733         },
13734 };
13735
13736 /* vf vlan insert configuration */
13737
13738 /* Common result structure for vf vlan insert */
13739 struct cmd_vf_vlan_insert_result {
13740         cmdline_fixed_string_t set;
13741         cmdline_fixed_string_t vf;
13742         cmdline_fixed_string_t vlan;
13743         cmdline_fixed_string_t insert;
13744         portid_t port_id;
13745         uint16_t vf_id;
13746         uint16_t vlan_id;
13747 };
13748
13749 /* Common CLI fields for vf vlan insert enable disable */
13750 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13751         TOKEN_STRING_INITIALIZER
13752                 (struct cmd_vf_vlan_insert_result,
13753                  set, "set");
13754 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13755         TOKEN_STRING_INITIALIZER
13756                 (struct cmd_vf_vlan_insert_result,
13757                  vf, "vf");
13758 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13759         TOKEN_STRING_INITIALIZER
13760                 (struct cmd_vf_vlan_insert_result,
13761                  vlan, "vlan");
13762 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13763         TOKEN_STRING_INITIALIZER
13764                 (struct cmd_vf_vlan_insert_result,
13765                  insert, "insert");
13766 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13767         TOKEN_NUM_INITIALIZER
13768                 (struct cmd_vf_vlan_insert_result,
13769                  port_id, UINT16);
13770 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13771         TOKEN_NUM_INITIALIZER
13772                 (struct cmd_vf_vlan_insert_result,
13773                  vf_id, UINT16);
13774 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13775         TOKEN_NUM_INITIALIZER
13776                 (struct cmd_vf_vlan_insert_result,
13777                  vlan_id, UINT16);
13778
13779 static void
13780 cmd_set_vf_vlan_insert_parsed(
13781         void *parsed_result,
13782         __rte_unused struct cmdline *cl,
13783         __rte_unused void *data)
13784 {
13785         struct cmd_vf_vlan_insert_result *res = parsed_result;
13786         int ret = -ENOTSUP;
13787
13788         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13789                 return;
13790
13791 #ifdef RTE_LIBRTE_IXGBE_PMD
13792         if (ret == -ENOTSUP)
13793                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13794                         res->vlan_id);
13795 #endif
13796 #ifdef RTE_LIBRTE_I40E_PMD
13797         if (ret == -ENOTSUP)
13798                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13799                         res->vlan_id);
13800 #endif
13801 #ifdef RTE_LIBRTE_BNXT_PMD
13802         if (ret == -ENOTSUP)
13803                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13804                         res->vlan_id);
13805 #endif
13806
13807         switch (ret) {
13808         case 0:
13809                 break;
13810         case -EINVAL:
13811                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13812                 break;
13813         case -ENODEV:
13814                 printf("invalid port_id %d\n", res->port_id);
13815                 break;
13816         case -ENOTSUP:
13817                 printf("function not implemented\n");
13818                 break;
13819         default:
13820                 printf("programming error: (%s)\n", strerror(-ret));
13821         }
13822 }
13823
13824 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13825         .f = cmd_set_vf_vlan_insert_parsed,
13826         .data = NULL,
13827         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13828         .tokens = {
13829                 (void *)&cmd_vf_vlan_insert_set,
13830                 (void *)&cmd_vf_vlan_insert_vf,
13831                 (void *)&cmd_vf_vlan_insert_vlan,
13832                 (void *)&cmd_vf_vlan_insert_insert,
13833                 (void *)&cmd_vf_vlan_insert_port_id,
13834                 (void *)&cmd_vf_vlan_insert_vf_id,
13835                 (void *)&cmd_vf_vlan_insert_vlan_id,
13836                 NULL,
13837         },
13838 };
13839
13840 /* tx loopback configuration */
13841
13842 /* Common result structure for tx loopback */
13843 struct cmd_tx_loopback_result {
13844         cmdline_fixed_string_t set;
13845         cmdline_fixed_string_t tx;
13846         cmdline_fixed_string_t loopback;
13847         portid_t port_id;
13848         cmdline_fixed_string_t on_off;
13849 };
13850
13851 /* Common CLI fields for tx loopback enable disable */
13852 cmdline_parse_token_string_t cmd_tx_loopback_set =
13853         TOKEN_STRING_INITIALIZER
13854                 (struct cmd_tx_loopback_result,
13855                  set, "set");
13856 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13857         TOKEN_STRING_INITIALIZER
13858                 (struct cmd_tx_loopback_result,
13859                  tx, "tx");
13860 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13861         TOKEN_STRING_INITIALIZER
13862                 (struct cmd_tx_loopback_result,
13863                  loopback, "loopback");
13864 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13865         TOKEN_NUM_INITIALIZER
13866                 (struct cmd_tx_loopback_result,
13867                  port_id, UINT16);
13868 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13869         TOKEN_STRING_INITIALIZER
13870                 (struct cmd_tx_loopback_result,
13871                  on_off, "on#off");
13872
13873 static void
13874 cmd_set_tx_loopback_parsed(
13875         void *parsed_result,
13876         __rte_unused struct cmdline *cl,
13877         __rte_unused void *data)
13878 {
13879         struct cmd_tx_loopback_result *res = parsed_result;
13880         int ret = -ENOTSUP;
13881
13882         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13883
13884         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13885                 return;
13886
13887 #ifdef RTE_LIBRTE_IXGBE_PMD
13888         if (ret == -ENOTSUP)
13889                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13890 #endif
13891 #ifdef RTE_LIBRTE_I40E_PMD
13892         if (ret == -ENOTSUP)
13893                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13894 #endif
13895 #ifdef RTE_LIBRTE_BNXT_PMD
13896         if (ret == -ENOTSUP)
13897                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13898 #endif
13899 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13900         if (ret == -ENOTSUP)
13901                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13902 #endif
13903
13904         switch (ret) {
13905         case 0:
13906                 break;
13907         case -EINVAL:
13908                 printf("invalid is_on %d\n", is_on);
13909                 break;
13910         case -ENODEV:
13911                 printf("invalid port_id %d\n", res->port_id);
13912                 break;
13913         case -ENOTSUP:
13914                 printf("function not implemented\n");
13915                 break;
13916         default:
13917                 printf("programming error: (%s)\n", strerror(-ret));
13918         }
13919 }
13920
13921 cmdline_parse_inst_t cmd_set_tx_loopback = {
13922         .f = cmd_set_tx_loopback_parsed,
13923         .data = NULL,
13924         .help_str = "set tx loopback <port_id> on|off",
13925         .tokens = {
13926                 (void *)&cmd_tx_loopback_set,
13927                 (void *)&cmd_tx_loopback_tx,
13928                 (void *)&cmd_tx_loopback_loopback,
13929                 (void *)&cmd_tx_loopback_port_id,
13930                 (void *)&cmd_tx_loopback_on_off,
13931                 NULL,
13932         },
13933 };
13934
13935 /* all queues drop enable configuration */
13936
13937 /* Common result structure for all queues drop enable */
13938 struct cmd_all_queues_drop_en_result {
13939         cmdline_fixed_string_t set;
13940         cmdline_fixed_string_t all;
13941         cmdline_fixed_string_t queues;
13942         cmdline_fixed_string_t drop;
13943         portid_t port_id;
13944         cmdline_fixed_string_t on_off;
13945 };
13946
13947 /* Common CLI fields for tx loopback enable disable */
13948 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13949         TOKEN_STRING_INITIALIZER
13950                 (struct cmd_all_queues_drop_en_result,
13951                  set, "set");
13952 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13953         TOKEN_STRING_INITIALIZER
13954                 (struct cmd_all_queues_drop_en_result,
13955                  all, "all");
13956 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13957         TOKEN_STRING_INITIALIZER
13958                 (struct cmd_all_queues_drop_en_result,
13959                  queues, "queues");
13960 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13961         TOKEN_STRING_INITIALIZER
13962                 (struct cmd_all_queues_drop_en_result,
13963                  drop, "drop");
13964 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13965         TOKEN_NUM_INITIALIZER
13966                 (struct cmd_all_queues_drop_en_result,
13967                  port_id, UINT16);
13968 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13969         TOKEN_STRING_INITIALIZER
13970                 (struct cmd_all_queues_drop_en_result,
13971                  on_off, "on#off");
13972
13973 static void
13974 cmd_set_all_queues_drop_en_parsed(
13975         void *parsed_result,
13976         __rte_unused struct cmdline *cl,
13977         __rte_unused void *data)
13978 {
13979         struct cmd_all_queues_drop_en_result *res = parsed_result;
13980         int ret = -ENOTSUP;
13981         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13982
13983         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13984                 return;
13985
13986 #ifdef RTE_LIBRTE_IXGBE_PMD
13987         if (ret == -ENOTSUP)
13988                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13989 #endif
13990 #ifdef RTE_LIBRTE_BNXT_PMD
13991         if (ret == -ENOTSUP)
13992                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13993 #endif
13994         switch (ret) {
13995         case 0:
13996                 break;
13997         case -EINVAL:
13998                 printf("invalid is_on %d\n", is_on);
13999                 break;
14000         case -ENODEV:
14001                 printf("invalid port_id %d\n", res->port_id);
14002                 break;
14003         case -ENOTSUP:
14004                 printf("function not implemented\n");
14005                 break;
14006         default:
14007                 printf("programming error: (%s)\n", strerror(-ret));
14008         }
14009 }
14010
14011 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14012         .f = cmd_set_all_queues_drop_en_parsed,
14013         .data = NULL,
14014         .help_str = "set all queues drop <port_id> on|off",
14015         .tokens = {
14016                 (void *)&cmd_all_queues_drop_en_set,
14017                 (void *)&cmd_all_queues_drop_en_all,
14018                 (void *)&cmd_all_queues_drop_en_queues,
14019                 (void *)&cmd_all_queues_drop_en_drop,
14020                 (void *)&cmd_all_queues_drop_en_port_id,
14021                 (void *)&cmd_all_queues_drop_en_on_off,
14022                 NULL,
14023         },
14024 };
14025
14026 /* vf split drop enable configuration */
14027
14028 /* Common result structure for vf split drop enable */
14029 struct cmd_vf_split_drop_en_result {
14030         cmdline_fixed_string_t set;
14031         cmdline_fixed_string_t vf;
14032         cmdline_fixed_string_t split;
14033         cmdline_fixed_string_t drop;
14034         portid_t port_id;
14035         uint16_t vf_id;
14036         cmdline_fixed_string_t on_off;
14037 };
14038
14039 /* Common CLI fields for vf split drop enable disable */
14040 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14041         TOKEN_STRING_INITIALIZER
14042                 (struct cmd_vf_split_drop_en_result,
14043                  set, "set");
14044 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14045         TOKEN_STRING_INITIALIZER
14046                 (struct cmd_vf_split_drop_en_result,
14047                  vf, "vf");
14048 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14049         TOKEN_STRING_INITIALIZER
14050                 (struct cmd_vf_split_drop_en_result,
14051                  split, "split");
14052 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14053         TOKEN_STRING_INITIALIZER
14054                 (struct cmd_vf_split_drop_en_result,
14055                  drop, "drop");
14056 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14057         TOKEN_NUM_INITIALIZER
14058                 (struct cmd_vf_split_drop_en_result,
14059                  port_id, UINT16);
14060 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14061         TOKEN_NUM_INITIALIZER
14062                 (struct cmd_vf_split_drop_en_result,
14063                  vf_id, UINT16);
14064 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14065         TOKEN_STRING_INITIALIZER
14066                 (struct cmd_vf_split_drop_en_result,
14067                  on_off, "on#off");
14068
14069 static void
14070 cmd_set_vf_split_drop_en_parsed(
14071         void *parsed_result,
14072         __rte_unused struct cmdline *cl,
14073         __rte_unused void *data)
14074 {
14075         struct cmd_vf_split_drop_en_result *res = parsed_result;
14076         int ret = -ENOTSUP;
14077         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14078
14079         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14080                 return;
14081
14082 #ifdef RTE_LIBRTE_IXGBE_PMD
14083         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14084                         is_on);
14085 #endif
14086         switch (ret) {
14087         case 0:
14088                 break;
14089         case -EINVAL:
14090                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14091                 break;
14092         case -ENODEV:
14093                 printf("invalid port_id %d\n", res->port_id);
14094                 break;
14095         case -ENOTSUP:
14096                 printf("not supported on port %d\n", res->port_id);
14097                 break;
14098         default:
14099                 printf("programming error: (%s)\n", strerror(-ret));
14100         }
14101 }
14102
14103 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14104         .f = cmd_set_vf_split_drop_en_parsed,
14105         .data = NULL,
14106         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14107         .tokens = {
14108                 (void *)&cmd_vf_split_drop_en_set,
14109                 (void *)&cmd_vf_split_drop_en_vf,
14110                 (void *)&cmd_vf_split_drop_en_split,
14111                 (void *)&cmd_vf_split_drop_en_drop,
14112                 (void *)&cmd_vf_split_drop_en_port_id,
14113                 (void *)&cmd_vf_split_drop_en_vf_id,
14114                 (void *)&cmd_vf_split_drop_en_on_off,
14115                 NULL,
14116         },
14117 };
14118
14119 /* vf mac address configuration */
14120
14121 /* Common result structure for vf mac address */
14122 struct cmd_set_vf_mac_addr_result {
14123         cmdline_fixed_string_t set;
14124         cmdline_fixed_string_t vf;
14125         cmdline_fixed_string_t mac;
14126         cmdline_fixed_string_t addr;
14127         portid_t port_id;
14128         uint16_t vf_id;
14129         struct rte_ether_addr mac_addr;
14130
14131 };
14132
14133 /* Common CLI fields for vf split drop enable disable */
14134 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14135         TOKEN_STRING_INITIALIZER
14136                 (struct cmd_set_vf_mac_addr_result,
14137                  set, "set");
14138 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14139         TOKEN_STRING_INITIALIZER
14140                 (struct cmd_set_vf_mac_addr_result,
14141                  vf, "vf");
14142 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14143         TOKEN_STRING_INITIALIZER
14144                 (struct cmd_set_vf_mac_addr_result,
14145                  mac, "mac");
14146 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14147         TOKEN_STRING_INITIALIZER
14148                 (struct cmd_set_vf_mac_addr_result,
14149                  addr, "addr");
14150 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14151         TOKEN_NUM_INITIALIZER
14152                 (struct cmd_set_vf_mac_addr_result,
14153                  port_id, UINT16);
14154 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14155         TOKEN_NUM_INITIALIZER
14156                 (struct cmd_set_vf_mac_addr_result,
14157                  vf_id, UINT16);
14158 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14159         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14160                  mac_addr);
14161
14162 static void
14163 cmd_set_vf_mac_addr_parsed(
14164         void *parsed_result,
14165         __rte_unused struct cmdline *cl,
14166         __rte_unused void *data)
14167 {
14168         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14169         int ret = -ENOTSUP;
14170
14171         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14172                 return;
14173
14174 #ifdef RTE_LIBRTE_IXGBE_PMD
14175         if (ret == -ENOTSUP)
14176                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14177                                 &res->mac_addr);
14178 #endif
14179 #ifdef RTE_LIBRTE_I40E_PMD
14180         if (ret == -ENOTSUP)
14181                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14182                                 &res->mac_addr);
14183 #endif
14184 #ifdef RTE_LIBRTE_BNXT_PMD
14185         if (ret == -ENOTSUP)
14186                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14187                                 &res->mac_addr);
14188 #endif
14189
14190         switch (ret) {
14191         case 0:
14192                 break;
14193         case -EINVAL:
14194                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14195                 break;
14196         case -ENODEV:
14197                 printf("invalid port_id %d\n", res->port_id);
14198                 break;
14199         case -ENOTSUP:
14200                 printf("function not implemented\n");
14201                 break;
14202         default:
14203                 printf("programming error: (%s)\n", strerror(-ret));
14204         }
14205 }
14206
14207 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14208         .f = cmd_set_vf_mac_addr_parsed,
14209         .data = NULL,
14210         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14211         .tokens = {
14212                 (void *)&cmd_set_vf_mac_addr_set,
14213                 (void *)&cmd_set_vf_mac_addr_vf,
14214                 (void *)&cmd_set_vf_mac_addr_mac,
14215                 (void *)&cmd_set_vf_mac_addr_addr,
14216                 (void *)&cmd_set_vf_mac_addr_port_id,
14217                 (void *)&cmd_set_vf_mac_addr_vf_id,
14218                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14219                 NULL,
14220         },
14221 };
14222
14223 /* MACsec configuration */
14224
14225 /* Common result structure for MACsec offload enable */
14226 struct cmd_macsec_offload_on_result {
14227         cmdline_fixed_string_t set;
14228         cmdline_fixed_string_t macsec;
14229         cmdline_fixed_string_t offload;
14230         portid_t port_id;
14231         cmdline_fixed_string_t on;
14232         cmdline_fixed_string_t encrypt;
14233         cmdline_fixed_string_t en_on_off;
14234         cmdline_fixed_string_t replay_protect;
14235         cmdline_fixed_string_t rp_on_off;
14236 };
14237
14238 /* Common CLI fields for MACsec offload disable */
14239 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14240         TOKEN_STRING_INITIALIZER
14241                 (struct cmd_macsec_offload_on_result,
14242                  set, "set");
14243 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14244         TOKEN_STRING_INITIALIZER
14245                 (struct cmd_macsec_offload_on_result,
14246                  macsec, "macsec");
14247 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14248         TOKEN_STRING_INITIALIZER
14249                 (struct cmd_macsec_offload_on_result,
14250                  offload, "offload");
14251 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14252         TOKEN_NUM_INITIALIZER
14253                 (struct cmd_macsec_offload_on_result,
14254                  port_id, UINT16);
14255 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14256         TOKEN_STRING_INITIALIZER
14257                 (struct cmd_macsec_offload_on_result,
14258                  on, "on");
14259 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14260         TOKEN_STRING_INITIALIZER
14261                 (struct cmd_macsec_offload_on_result,
14262                  encrypt, "encrypt");
14263 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14264         TOKEN_STRING_INITIALIZER
14265                 (struct cmd_macsec_offload_on_result,
14266                  en_on_off, "on#off");
14267 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14268         TOKEN_STRING_INITIALIZER
14269                 (struct cmd_macsec_offload_on_result,
14270                  replay_protect, "replay-protect");
14271 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14272         TOKEN_STRING_INITIALIZER
14273                 (struct cmd_macsec_offload_on_result,
14274                  rp_on_off, "on#off");
14275
14276 static void
14277 cmd_set_macsec_offload_on_parsed(
14278         void *parsed_result,
14279         __rte_unused struct cmdline *cl,
14280         __rte_unused void *data)
14281 {
14282         struct cmd_macsec_offload_on_result *res = parsed_result;
14283         int ret = -ENOTSUP;
14284         portid_t port_id = res->port_id;
14285         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14286         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14287         struct rte_eth_dev_info dev_info;
14288
14289         if (port_id_is_invalid(port_id, ENABLED_WARN))
14290                 return;
14291         if (!port_is_stopped(port_id)) {
14292                 printf("Please stop port %d first\n", port_id);
14293                 return;
14294         }
14295
14296         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14297         if (ret != 0)
14298                 return;
14299
14300         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14301 #ifdef RTE_LIBRTE_IXGBE_PMD
14302                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14303 #endif
14304         }
14305         RTE_SET_USED(en);
14306         RTE_SET_USED(rp);
14307
14308         switch (ret) {
14309         case 0:
14310                 ports[port_id].dev_conf.txmode.offloads |=
14311                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14312                 cmd_reconfig_device_queue(port_id, 1, 1);
14313                 break;
14314         case -ENODEV:
14315                 printf("invalid port_id %d\n", port_id);
14316                 break;
14317         case -ENOTSUP:
14318                 printf("not supported on port %d\n", port_id);
14319                 break;
14320         default:
14321                 printf("programming error: (%s)\n", strerror(-ret));
14322         }
14323 }
14324
14325 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14326         .f = cmd_set_macsec_offload_on_parsed,
14327         .data = NULL,
14328         .help_str = "set macsec offload <port_id> on "
14329                 "encrypt on|off replay-protect on|off",
14330         .tokens = {
14331                 (void *)&cmd_macsec_offload_on_set,
14332                 (void *)&cmd_macsec_offload_on_macsec,
14333                 (void *)&cmd_macsec_offload_on_offload,
14334                 (void *)&cmd_macsec_offload_on_port_id,
14335                 (void *)&cmd_macsec_offload_on_on,
14336                 (void *)&cmd_macsec_offload_on_encrypt,
14337                 (void *)&cmd_macsec_offload_on_en_on_off,
14338                 (void *)&cmd_macsec_offload_on_replay_protect,
14339                 (void *)&cmd_macsec_offload_on_rp_on_off,
14340                 NULL,
14341         },
14342 };
14343
14344 /* Common result structure for MACsec offload disable */
14345 struct cmd_macsec_offload_off_result {
14346         cmdline_fixed_string_t set;
14347         cmdline_fixed_string_t macsec;
14348         cmdline_fixed_string_t offload;
14349         portid_t port_id;
14350         cmdline_fixed_string_t off;
14351 };
14352
14353 /* Common CLI fields for MACsec offload disable */
14354 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14355         TOKEN_STRING_INITIALIZER
14356                 (struct cmd_macsec_offload_off_result,
14357                  set, "set");
14358 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14359         TOKEN_STRING_INITIALIZER
14360                 (struct cmd_macsec_offload_off_result,
14361                  macsec, "macsec");
14362 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14363         TOKEN_STRING_INITIALIZER
14364                 (struct cmd_macsec_offload_off_result,
14365                  offload, "offload");
14366 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14367         TOKEN_NUM_INITIALIZER
14368                 (struct cmd_macsec_offload_off_result,
14369                  port_id, UINT16);
14370 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14371         TOKEN_STRING_INITIALIZER
14372                 (struct cmd_macsec_offload_off_result,
14373                  off, "off");
14374
14375 static void
14376 cmd_set_macsec_offload_off_parsed(
14377         void *parsed_result,
14378         __rte_unused struct cmdline *cl,
14379         __rte_unused void *data)
14380 {
14381         struct cmd_macsec_offload_off_result *res = parsed_result;
14382         int ret = -ENOTSUP;
14383         struct rte_eth_dev_info dev_info;
14384         portid_t port_id = res->port_id;
14385
14386         if (port_id_is_invalid(port_id, ENABLED_WARN))
14387                 return;
14388         if (!port_is_stopped(port_id)) {
14389                 printf("Please stop port %d first\n", port_id);
14390                 return;
14391         }
14392
14393         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14394         if (ret != 0)
14395                 return;
14396
14397         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14398 #ifdef RTE_LIBRTE_IXGBE_PMD
14399                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14400 #endif
14401         }
14402         switch (ret) {
14403         case 0:
14404                 ports[port_id].dev_conf.txmode.offloads &=
14405                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14406                 cmd_reconfig_device_queue(port_id, 1, 1);
14407                 break;
14408         case -ENODEV:
14409                 printf("invalid port_id %d\n", port_id);
14410                 break;
14411         case -ENOTSUP:
14412                 printf("not supported on port %d\n", port_id);
14413                 break;
14414         default:
14415                 printf("programming error: (%s)\n", strerror(-ret));
14416         }
14417 }
14418
14419 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14420         .f = cmd_set_macsec_offload_off_parsed,
14421         .data = NULL,
14422         .help_str = "set macsec offload <port_id> off",
14423         .tokens = {
14424                 (void *)&cmd_macsec_offload_off_set,
14425                 (void *)&cmd_macsec_offload_off_macsec,
14426                 (void *)&cmd_macsec_offload_off_offload,
14427                 (void *)&cmd_macsec_offload_off_port_id,
14428                 (void *)&cmd_macsec_offload_off_off,
14429                 NULL,
14430         },
14431 };
14432
14433 /* Common result structure for MACsec secure connection configure */
14434 struct cmd_macsec_sc_result {
14435         cmdline_fixed_string_t set;
14436         cmdline_fixed_string_t macsec;
14437         cmdline_fixed_string_t sc;
14438         cmdline_fixed_string_t tx_rx;
14439         portid_t port_id;
14440         struct rte_ether_addr mac;
14441         uint16_t pi;
14442 };
14443
14444 /* Common CLI fields for MACsec secure connection configure */
14445 cmdline_parse_token_string_t cmd_macsec_sc_set =
14446         TOKEN_STRING_INITIALIZER
14447                 (struct cmd_macsec_sc_result,
14448                  set, "set");
14449 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14450         TOKEN_STRING_INITIALIZER
14451                 (struct cmd_macsec_sc_result,
14452                  macsec, "macsec");
14453 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14454         TOKEN_STRING_INITIALIZER
14455                 (struct cmd_macsec_sc_result,
14456                  sc, "sc");
14457 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14458         TOKEN_STRING_INITIALIZER
14459                 (struct cmd_macsec_sc_result,
14460                  tx_rx, "tx#rx");
14461 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14462         TOKEN_NUM_INITIALIZER
14463                 (struct cmd_macsec_sc_result,
14464                  port_id, UINT16);
14465 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14466         TOKEN_ETHERADDR_INITIALIZER
14467                 (struct cmd_macsec_sc_result,
14468                  mac);
14469 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14470         TOKEN_NUM_INITIALIZER
14471                 (struct cmd_macsec_sc_result,
14472                  pi, UINT16);
14473
14474 static void
14475 cmd_set_macsec_sc_parsed(
14476         void *parsed_result,
14477         __rte_unused struct cmdline *cl,
14478         __rte_unused void *data)
14479 {
14480         struct cmd_macsec_sc_result *res = parsed_result;
14481         int ret = -ENOTSUP;
14482         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14483
14484 #ifdef RTE_LIBRTE_IXGBE_PMD
14485         ret = is_tx ?
14486                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14487                                 res->mac.addr_bytes) :
14488                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14489                                 res->mac.addr_bytes, res->pi);
14490 #endif
14491         RTE_SET_USED(is_tx);
14492
14493         switch (ret) {
14494         case 0:
14495                 break;
14496         case -ENODEV:
14497                 printf("invalid port_id %d\n", res->port_id);
14498                 break;
14499         case -ENOTSUP:
14500                 printf("not supported on port %d\n", res->port_id);
14501                 break;
14502         default:
14503                 printf("programming error: (%s)\n", strerror(-ret));
14504         }
14505 }
14506
14507 cmdline_parse_inst_t cmd_set_macsec_sc = {
14508         .f = cmd_set_macsec_sc_parsed,
14509         .data = NULL,
14510         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14511         .tokens = {
14512                 (void *)&cmd_macsec_sc_set,
14513                 (void *)&cmd_macsec_sc_macsec,
14514                 (void *)&cmd_macsec_sc_sc,
14515                 (void *)&cmd_macsec_sc_tx_rx,
14516                 (void *)&cmd_macsec_sc_port_id,
14517                 (void *)&cmd_macsec_sc_mac,
14518                 (void *)&cmd_macsec_sc_pi,
14519                 NULL,
14520         },
14521 };
14522
14523 /* Common result structure for MACsec secure connection configure */
14524 struct cmd_macsec_sa_result {
14525         cmdline_fixed_string_t set;
14526         cmdline_fixed_string_t macsec;
14527         cmdline_fixed_string_t sa;
14528         cmdline_fixed_string_t tx_rx;
14529         portid_t port_id;
14530         uint8_t idx;
14531         uint8_t an;
14532         uint32_t pn;
14533         cmdline_fixed_string_t key;
14534 };
14535
14536 /* Common CLI fields for MACsec secure connection configure */
14537 cmdline_parse_token_string_t cmd_macsec_sa_set =
14538         TOKEN_STRING_INITIALIZER
14539                 (struct cmd_macsec_sa_result,
14540                  set, "set");
14541 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14542         TOKEN_STRING_INITIALIZER
14543                 (struct cmd_macsec_sa_result,
14544                  macsec, "macsec");
14545 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14546         TOKEN_STRING_INITIALIZER
14547                 (struct cmd_macsec_sa_result,
14548                  sa, "sa");
14549 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14550         TOKEN_STRING_INITIALIZER
14551                 (struct cmd_macsec_sa_result,
14552                  tx_rx, "tx#rx");
14553 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14554         TOKEN_NUM_INITIALIZER
14555                 (struct cmd_macsec_sa_result,
14556                  port_id, UINT16);
14557 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14558         TOKEN_NUM_INITIALIZER
14559                 (struct cmd_macsec_sa_result,
14560                  idx, UINT8);
14561 cmdline_parse_token_num_t cmd_macsec_sa_an =
14562         TOKEN_NUM_INITIALIZER
14563                 (struct cmd_macsec_sa_result,
14564                  an, UINT8);
14565 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14566         TOKEN_NUM_INITIALIZER
14567                 (struct cmd_macsec_sa_result,
14568                  pn, UINT32);
14569 cmdline_parse_token_string_t cmd_macsec_sa_key =
14570         TOKEN_STRING_INITIALIZER
14571                 (struct cmd_macsec_sa_result,
14572                  key, NULL);
14573
14574 static void
14575 cmd_set_macsec_sa_parsed(
14576         void *parsed_result,
14577         __rte_unused struct cmdline *cl,
14578         __rte_unused void *data)
14579 {
14580         struct cmd_macsec_sa_result *res = parsed_result;
14581         int ret = -ENOTSUP;
14582         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14583         uint8_t key[16] = { 0 };
14584         uint8_t xdgt0;
14585         uint8_t xdgt1;
14586         int key_len;
14587         int i;
14588
14589         key_len = strlen(res->key) / 2;
14590         if (key_len > 16)
14591                 key_len = 16;
14592
14593         for (i = 0; i < key_len; i++) {
14594                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14595                 if (xdgt0 == 0xFF)
14596                         return;
14597                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14598                 if (xdgt1 == 0xFF)
14599                         return;
14600                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14601         }
14602
14603 #ifdef RTE_LIBRTE_IXGBE_PMD
14604         ret = is_tx ?
14605                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14606                         res->idx, res->an, res->pn, key) :
14607                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14608                         res->idx, res->an, res->pn, key);
14609 #endif
14610         RTE_SET_USED(is_tx);
14611         RTE_SET_USED(key);
14612
14613         switch (ret) {
14614         case 0:
14615                 break;
14616         case -EINVAL:
14617                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14618                 break;
14619         case -ENODEV:
14620                 printf("invalid port_id %d\n", res->port_id);
14621                 break;
14622         case -ENOTSUP:
14623                 printf("not supported on port %d\n", res->port_id);
14624                 break;
14625         default:
14626                 printf("programming error: (%s)\n", strerror(-ret));
14627         }
14628 }
14629
14630 cmdline_parse_inst_t cmd_set_macsec_sa = {
14631         .f = cmd_set_macsec_sa_parsed,
14632         .data = NULL,
14633         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14634         .tokens = {
14635                 (void *)&cmd_macsec_sa_set,
14636                 (void *)&cmd_macsec_sa_macsec,
14637                 (void *)&cmd_macsec_sa_sa,
14638                 (void *)&cmd_macsec_sa_tx_rx,
14639                 (void *)&cmd_macsec_sa_port_id,
14640                 (void *)&cmd_macsec_sa_idx,
14641                 (void *)&cmd_macsec_sa_an,
14642                 (void *)&cmd_macsec_sa_pn,
14643                 (void *)&cmd_macsec_sa_key,
14644                 NULL,
14645         },
14646 };
14647
14648 /* VF unicast promiscuous mode configuration */
14649
14650 /* Common result structure for VF unicast promiscuous mode */
14651 struct cmd_vf_promisc_result {
14652         cmdline_fixed_string_t set;
14653         cmdline_fixed_string_t vf;
14654         cmdline_fixed_string_t promisc;
14655         portid_t port_id;
14656         uint32_t vf_id;
14657         cmdline_fixed_string_t on_off;
14658 };
14659
14660 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14661 cmdline_parse_token_string_t cmd_vf_promisc_set =
14662         TOKEN_STRING_INITIALIZER
14663                 (struct cmd_vf_promisc_result,
14664                  set, "set");
14665 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14666         TOKEN_STRING_INITIALIZER
14667                 (struct cmd_vf_promisc_result,
14668                  vf, "vf");
14669 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14670         TOKEN_STRING_INITIALIZER
14671                 (struct cmd_vf_promisc_result,
14672                  promisc, "promisc");
14673 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14674         TOKEN_NUM_INITIALIZER
14675                 (struct cmd_vf_promisc_result,
14676                  port_id, UINT16);
14677 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14678         TOKEN_NUM_INITIALIZER
14679                 (struct cmd_vf_promisc_result,
14680                  vf_id, UINT32);
14681 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14682         TOKEN_STRING_INITIALIZER
14683                 (struct cmd_vf_promisc_result,
14684                  on_off, "on#off");
14685
14686 static void
14687 cmd_set_vf_promisc_parsed(
14688         void *parsed_result,
14689         __rte_unused struct cmdline *cl,
14690         __rte_unused void *data)
14691 {
14692         struct cmd_vf_promisc_result *res = parsed_result;
14693         int ret = -ENOTSUP;
14694
14695         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14696
14697         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14698                 return;
14699
14700 #ifdef RTE_LIBRTE_I40E_PMD
14701         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14702                                                   res->vf_id, is_on);
14703 #endif
14704
14705         switch (ret) {
14706         case 0:
14707                 break;
14708         case -EINVAL:
14709                 printf("invalid vf_id %d\n", res->vf_id);
14710                 break;
14711         case -ENODEV:
14712                 printf("invalid port_id %d\n", res->port_id);
14713                 break;
14714         case -ENOTSUP:
14715                 printf("function not implemented\n");
14716                 break;
14717         default:
14718                 printf("programming error: (%s)\n", strerror(-ret));
14719         }
14720 }
14721
14722 cmdline_parse_inst_t cmd_set_vf_promisc = {
14723         .f = cmd_set_vf_promisc_parsed,
14724         .data = NULL,
14725         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14726                 "Set unicast promiscuous mode for a VF from the PF",
14727         .tokens = {
14728                 (void *)&cmd_vf_promisc_set,
14729                 (void *)&cmd_vf_promisc_vf,
14730                 (void *)&cmd_vf_promisc_promisc,
14731                 (void *)&cmd_vf_promisc_port_id,
14732                 (void *)&cmd_vf_promisc_vf_id,
14733                 (void *)&cmd_vf_promisc_on_off,
14734                 NULL,
14735         },
14736 };
14737
14738 /* VF multicast promiscuous mode configuration */
14739
14740 /* Common result structure for VF multicast promiscuous mode */
14741 struct cmd_vf_allmulti_result {
14742         cmdline_fixed_string_t set;
14743         cmdline_fixed_string_t vf;
14744         cmdline_fixed_string_t allmulti;
14745         portid_t port_id;
14746         uint32_t vf_id;
14747         cmdline_fixed_string_t on_off;
14748 };
14749
14750 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14751 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14752         TOKEN_STRING_INITIALIZER
14753                 (struct cmd_vf_allmulti_result,
14754                  set, "set");
14755 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14756         TOKEN_STRING_INITIALIZER
14757                 (struct cmd_vf_allmulti_result,
14758                  vf, "vf");
14759 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14760         TOKEN_STRING_INITIALIZER
14761                 (struct cmd_vf_allmulti_result,
14762                  allmulti, "allmulti");
14763 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14764         TOKEN_NUM_INITIALIZER
14765                 (struct cmd_vf_allmulti_result,
14766                  port_id, UINT16);
14767 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14768         TOKEN_NUM_INITIALIZER
14769                 (struct cmd_vf_allmulti_result,
14770                  vf_id, UINT32);
14771 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14772         TOKEN_STRING_INITIALIZER
14773                 (struct cmd_vf_allmulti_result,
14774                  on_off, "on#off");
14775
14776 static void
14777 cmd_set_vf_allmulti_parsed(
14778         void *parsed_result,
14779         __rte_unused struct cmdline *cl,
14780         __rte_unused void *data)
14781 {
14782         struct cmd_vf_allmulti_result *res = parsed_result;
14783         int ret = -ENOTSUP;
14784
14785         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14786
14787         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14788                 return;
14789
14790 #ifdef RTE_LIBRTE_I40E_PMD
14791         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14792                                                     res->vf_id, is_on);
14793 #endif
14794
14795         switch (ret) {
14796         case 0:
14797                 break;
14798         case -EINVAL:
14799                 printf("invalid vf_id %d\n", res->vf_id);
14800                 break;
14801         case -ENODEV:
14802                 printf("invalid port_id %d\n", res->port_id);
14803                 break;
14804         case -ENOTSUP:
14805                 printf("function not implemented\n");
14806                 break;
14807         default:
14808                 printf("programming error: (%s)\n", strerror(-ret));
14809         }
14810 }
14811
14812 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14813         .f = cmd_set_vf_allmulti_parsed,
14814         .data = NULL,
14815         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14816                 "Set multicast promiscuous mode for a VF from the PF",
14817         .tokens = {
14818                 (void *)&cmd_vf_allmulti_set,
14819                 (void *)&cmd_vf_allmulti_vf,
14820                 (void *)&cmd_vf_allmulti_allmulti,
14821                 (void *)&cmd_vf_allmulti_port_id,
14822                 (void *)&cmd_vf_allmulti_vf_id,
14823                 (void *)&cmd_vf_allmulti_on_off,
14824                 NULL,
14825         },
14826 };
14827
14828 /* vf broadcast mode configuration */
14829
14830 /* Common result structure for vf broadcast */
14831 struct cmd_set_vf_broadcast_result {
14832         cmdline_fixed_string_t set;
14833         cmdline_fixed_string_t vf;
14834         cmdline_fixed_string_t broadcast;
14835         portid_t port_id;
14836         uint16_t vf_id;
14837         cmdline_fixed_string_t on_off;
14838 };
14839
14840 /* Common CLI fields for vf broadcast enable disable */
14841 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14842         TOKEN_STRING_INITIALIZER
14843                 (struct cmd_set_vf_broadcast_result,
14844                  set, "set");
14845 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14846         TOKEN_STRING_INITIALIZER
14847                 (struct cmd_set_vf_broadcast_result,
14848                  vf, "vf");
14849 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14850         TOKEN_STRING_INITIALIZER
14851                 (struct cmd_set_vf_broadcast_result,
14852                  broadcast, "broadcast");
14853 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14854         TOKEN_NUM_INITIALIZER
14855                 (struct cmd_set_vf_broadcast_result,
14856                  port_id, UINT16);
14857 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14858         TOKEN_NUM_INITIALIZER
14859                 (struct cmd_set_vf_broadcast_result,
14860                  vf_id, UINT16);
14861 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14862         TOKEN_STRING_INITIALIZER
14863                 (struct cmd_set_vf_broadcast_result,
14864                  on_off, "on#off");
14865
14866 static void
14867 cmd_set_vf_broadcast_parsed(
14868         void *parsed_result,
14869         __rte_unused struct cmdline *cl,
14870         __rte_unused void *data)
14871 {
14872         struct cmd_set_vf_broadcast_result *res = parsed_result;
14873         int ret = -ENOTSUP;
14874
14875         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14876
14877         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14878                 return;
14879
14880 #ifdef RTE_LIBRTE_I40E_PMD
14881         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14882                                             res->vf_id, is_on);
14883 #endif
14884
14885         switch (ret) {
14886         case 0:
14887                 break;
14888         case -EINVAL:
14889                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14890                 break;
14891         case -ENODEV:
14892                 printf("invalid port_id %d\n", res->port_id);
14893                 break;
14894         case -ENOTSUP:
14895                 printf("function not implemented\n");
14896                 break;
14897         default:
14898                 printf("programming error: (%s)\n", strerror(-ret));
14899         }
14900 }
14901
14902 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14903         .f = cmd_set_vf_broadcast_parsed,
14904         .data = NULL,
14905         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14906         .tokens = {
14907                 (void *)&cmd_set_vf_broadcast_set,
14908                 (void *)&cmd_set_vf_broadcast_vf,
14909                 (void *)&cmd_set_vf_broadcast_broadcast,
14910                 (void *)&cmd_set_vf_broadcast_port_id,
14911                 (void *)&cmd_set_vf_broadcast_vf_id,
14912                 (void *)&cmd_set_vf_broadcast_on_off,
14913                 NULL,
14914         },
14915 };
14916
14917 /* vf vlan tag configuration */
14918
14919 /* Common result structure for vf vlan tag */
14920 struct cmd_set_vf_vlan_tag_result {
14921         cmdline_fixed_string_t set;
14922         cmdline_fixed_string_t vf;
14923         cmdline_fixed_string_t vlan;
14924         cmdline_fixed_string_t tag;
14925         portid_t port_id;
14926         uint16_t vf_id;
14927         cmdline_fixed_string_t on_off;
14928 };
14929
14930 /* Common CLI fields for vf vlan tag enable disable */
14931 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14932         TOKEN_STRING_INITIALIZER
14933                 (struct cmd_set_vf_vlan_tag_result,
14934                  set, "set");
14935 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14936         TOKEN_STRING_INITIALIZER
14937                 (struct cmd_set_vf_vlan_tag_result,
14938                  vf, "vf");
14939 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14940         TOKEN_STRING_INITIALIZER
14941                 (struct cmd_set_vf_vlan_tag_result,
14942                  vlan, "vlan");
14943 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14944         TOKEN_STRING_INITIALIZER
14945                 (struct cmd_set_vf_vlan_tag_result,
14946                  tag, "tag");
14947 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14948         TOKEN_NUM_INITIALIZER
14949                 (struct cmd_set_vf_vlan_tag_result,
14950                  port_id, UINT16);
14951 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14952         TOKEN_NUM_INITIALIZER
14953                 (struct cmd_set_vf_vlan_tag_result,
14954                  vf_id, UINT16);
14955 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14956         TOKEN_STRING_INITIALIZER
14957                 (struct cmd_set_vf_vlan_tag_result,
14958                  on_off, "on#off");
14959
14960 static void
14961 cmd_set_vf_vlan_tag_parsed(
14962         void *parsed_result,
14963         __rte_unused struct cmdline *cl,
14964         __rte_unused void *data)
14965 {
14966         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14967         int ret = -ENOTSUP;
14968
14969         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14970
14971         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14972                 return;
14973
14974 #ifdef RTE_LIBRTE_I40E_PMD
14975         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14976                                            res->vf_id, is_on);
14977 #endif
14978
14979         switch (ret) {
14980         case 0:
14981                 break;
14982         case -EINVAL:
14983                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14984                 break;
14985         case -ENODEV:
14986                 printf("invalid port_id %d\n", res->port_id);
14987                 break;
14988         case -ENOTSUP:
14989                 printf("function not implemented\n");
14990                 break;
14991         default:
14992                 printf("programming error: (%s)\n", strerror(-ret));
14993         }
14994 }
14995
14996 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14997         .f = cmd_set_vf_vlan_tag_parsed,
14998         .data = NULL,
14999         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15000         .tokens = {
15001                 (void *)&cmd_set_vf_vlan_tag_set,
15002                 (void *)&cmd_set_vf_vlan_tag_vf,
15003                 (void *)&cmd_set_vf_vlan_tag_vlan,
15004                 (void *)&cmd_set_vf_vlan_tag_tag,
15005                 (void *)&cmd_set_vf_vlan_tag_port_id,
15006                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15007                 (void *)&cmd_set_vf_vlan_tag_on_off,
15008                 NULL,
15009         },
15010 };
15011
15012 /* Common definition of VF and TC TX bandwidth configuration */
15013 struct cmd_vf_tc_bw_result {
15014         cmdline_fixed_string_t set;
15015         cmdline_fixed_string_t vf;
15016         cmdline_fixed_string_t tc;
15017         cmdline_fixed_string_t tx;
15018         cmdline_fixed_string_t min_bw;
15019         cmdline_fixed_string_t max_bw;
15020         cmdline_fixed_string_t strict_link_prio;
15021         portid_t port_id;
15022         uint16_t vf_id;
15023         uint8_t tc_no;
15024         uint32_t bw;
15025         cmdline_fixed_string_t bw_list;
15026         uint8_t tc_map;
15027 };
15028
15029 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15030         TOKEN_STRING_INITIALIZER
15031                 (struct cmd_vf_tc_bw_result,
15032                  set, "set");
15033 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15034         TOKEN_STRING_INITIALIZER
15035                 (struct cmd_vf_tc_bw_result,
15036                  vf, "vf");
15037 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15038         TOKEN_STRING_INITIALIZER
15039                 (struct cmd_vf_tc_bw_result,
15040                  tc, "tc");
15041 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15042         TOKEN_STRING_INITIALIZER
15043                 (struct cmd_vf_tc_bw_result,
15044                  tx, "tx");
15045 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15046         TOKEN_STRING_INITIALIZER
15047                 (struct cmd_vf_tc_bw_result,
15048                  strict_link_prio, "strict-link-priority");
15049 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15050         TOKEN_STRING_INITIALIZER
15051                 (struct cmd_vf_tc_bw_result,
15052                  min_bw, "min-bandwidth");
15053 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15054         TOKEN_STRING_INITIALIZER
15055                 (struct cmd_vf_tc_bw_result,
15056                  max_bw, "max-bandwidth");
15057 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15058         TOKEN_NUM_INITIALIZER
15059                 (struct cmd_vf_tc_bw_result,
15060                  port_id, UINT16);
15061 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15062         TOKEN_NUM_INITIALIZER
15063                 (struct cmd_vf_tc_bw_result,
15064                  vf_id, UINT16);
15065 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15066         TOKEN_NUM_INITIALIZER
15067                 (struct cmd_vf_tc_bw_result,
15068                  tc_no, UINT8);
15069 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15070         TOKEN_NUM_INITIALIZER
15071                 (struct cmd_vf_tc_bw_result,
15072                  bw, UINT32);
15073 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15074         TOKEN_STRING_INITIALIZER
15075                 (struct cmd_vf_tc_bw_result,
15076                  bw_list, NULL);
15077 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15078         TOKEN_NUM_INITIALIZER
15079                 (struct cmd_vf_tc_bw_result,
15080                  tc_map, UINT8);
15081
15082 /* VF max bandwidth setting */
15083 static void
15084 cmd_vf_max_bw_parsed(
15085         void *parsed_result,
15086         __rte_unused struct cmdline *cl,
15087         __rte_unused void *data)
15088 {
15089         struct cmd_vf_tc_bw_result *res = parsed_result;
15090         int ret = -ENOTSUP;
15091
15092         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15093                 return;
15094
15095 #ifdef RTE_LIBRTE_I40E_PMD
15096         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15097                                          res->vf_id, res->bw);
15098 #endif
15099
15100         switch (ret) {
15101         case 0:
15102                 break;
15103         case -EINVAL:
15104                 printf("invalid vf_id %d or bandwidth %d\n",
15105                        res->vf_id, res->bw);
15106                 break;
15107         case -ENODEV:
15108                 printf("invalid port_id %d\n", res->port_id);
15109                 break;
15110         case -ENOTSUP:
15111                 printf("function not implemented\n");
15112                 break;
15113         default:
15114                 printf("programming error: (%s)\n", strerror(-ret));
15115         }
15116 }
15117
15118 cmdline_parse_inst_t cmd_vf_max_bw = {
15119         .f = cmd_vf_max_bw_parsed,
15120         .data = NULL,
15121         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15122         .tokens = {
15123                 (void *)&cmd_vf_tc_bw_set,
15124                 (void *)&cmd_vf_tc_bw_vf,
15125                 (void *)&cmd_vf_tc_bw_tx,
15126                 (void *)&cmd_vf_tc_bw_max_bw,
15127                 (void *)&cmd_vf_tc_bw_port_id,
15128                 (void *)&cmd_vf_tc_bw_vf_id,
15129                 (void *)&cmd_vf_tc_bw_bw,
15130                 NULL,
15131         },
15132 };
15133
15134 static int
15135 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15136                            uint8_t *tc_num,
15137                            char *str)
15138 {
15139         uint32_t size;
15140         const char *p, *p0 = str;
15141         char s[256];
15142         char *end;
15143         char *str_fld[16];
15144         uint16_t i;
15145         int ret;
15146
15147         p = strchr(p0, '(');
15148         if (p == NULL) {
15149                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15150                 return -1;
15151         }
15152         p++;
15153         p0 = strchr(p, ')');
15154         if (p0 == NULL) {
15155                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15156                 return -1;
15157         }
15158         size = p0 - p;
15159         if (size >= sizeof(s)) {
15160                 printf("The string size exceeds the internal buffer size\n");
15161                 return -1;
15162         }
15163         snprintf(s, sizeof(s), "%.*s", size, p);
15164         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15165         if (ret <= 0) {
15166                 printf("Failed to get the bandwidth list. ");
15167                 return -1;
15168         }
15169         *tc_num = ret;
15170         for (i = 0; i < ret; i++)
15171                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15172
15173         return 0;
15174 }
15175
15176 /* TC min bandwidth setting */
15177 static void
15178 cmd_vf_tc_min_bw_parsed(
15179         void *parsed_result,
15180         __rte_unused struct cmdline *cl,
15181         __rte_unused void *data)
15182 {
15183         struct cmd_vf_tc_bw_result *res = parsed_result;
15184         uint8_t tc_num;
15185         uint8_t bw[16];
15186         int ret = -ENOTSUP;
15187
15188         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15189                 return;
15190
15191         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15192         if (ret)
15193                 return;
15194
15195 #ifdef RTE_LIBRTE_I40E_PMD
15196         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15197                                               tc_num, bw);
15198 #endif
15199
15200         switch (ret) {
15201         case 0:
15202                 break;
15203         case -EINVAL:
15204                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15205                 break;
15206         case -ENODEV:
15207                 printf("invalid port_id %d\n", res->port_id);
15208                 break;
15209         case -ENOTSUP:
15210                 printf("function not implemented\n");
15211                 break;
15212         default:
15213                 printf("programming error: (%s)\n", strerror(-ret));
15214         }
15215 }
15216
15217 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15218         .f = cmd_vf_tc_min_bw_parsed,
15219         .data = NULL,
15220         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15221                     " <bw1, bw2, ...>",
15222         .tokens = {
15223                 (void *)&cmd_vf_tc_bw_set,
15224                 (void *)&cmd_vf_tc_bw_vf,
15225                 (void *)&cmd_vf_tc_bw_tc,
15226                 (void *)&cmd_vf_tc_bw_tx,
15227                 (void *)&cmd_vf_tc_bw_min_bw,
15228                 (void *)&cmd_vf_tc_bw_port_id,
15229                 (void *)&cmd_vf_tc_bw_vf_id,
15230                 (void *)&cmd_vf_tc_bw_bw_list,
15231                 NULL,
15232         },
15233 };
15234
15235 static void
15236 cmd_tc_min_bw_parsed(
15237         void *parsed_result,
15238         __rte_unused struct cmdline *cl,
15239         __rte_unused void *data)
15240 {
15241         struct cmd_vf_tc_bw_result *res = parsed_result;
15242         struct rte_port *port;
15243         uint8_t tc_num;
15244         uint8_t bw[16];
15245         int ret = -ENOTSUP;
15246
15247         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15248                 return;
15249
15250         port = &ports[res->port_id];
15251         /** Check if the port is not started **/
15252         if (port->port_status != RTE_PORT_STOPPED) {
15253                 printf("Please stop port %d first\n", res->port_id);
15254                 return;
15255         }
15256
15257         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15258         if (ret)
15259                 return;
15260
15261 #ifdef RTE_LIBRTE_IXGBE_PMD
15262         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15263 #endif
15264
15265         switch (ret) {
15266         case 0:
15267                 break;
15268         case -EINVAL:
15269                 printf("invalid bandwidth\n");
15270                 break;
15271         case -ENODEV:
15272                 printf("invalid port_id %d\n", res->port_id);
15273                 break;
15274         case -ENOTSUP:
15275                 printf("function not implemented\n");
15276                 break;
15277         default:
15278                 printf("programming error: (%s)\n", strerror(-ret));
15279         }
15280 }
15281
15282 cmdline_parse_inst_t cmd_tc_min_bw = {
15283         .f = cmd_tc_min_bw_parsed,
15284         .data = NULL,
15285         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15286         .tokens = {
15287                 (void *)&cmd_vf_tc_bw_set,
15288                 (void *)&cmd_vf_tc_bw_tc,
15289                 (void *)&cmd_vf_tc_bw_tx,
15290                 (void *)&cmd_vf_tc_bw_min_bw,
15291                 (void *)&cmd_vf_tc_bw_port_id,
15292                 (void *)&cmd_vf_tc_bw_bw_list,
15293                 NULL,
15294         },
15295 };
15296
15297 /* TC max bandwidth setting */
15298 static void
15299 cmd_vf_tc_max_bw_parsed(
15300         void *parsed_result,
15301         __rte_unused struct cmdline *cl,
15302         __rte_unused void *data)
15303 {
15304         struct cmd_vf_tc_bw_result *res = parsed_result;
15305         int ret = -ENOTSUP;
15306
15307         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15308                 return;
15309
15310 #ifdef RTE_LIBRTE_I40E_PMD
15311         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15312                                             res->tc_no, res->bw);
15313 #endif
15314
15315         switch (ret) {
15316         case 0:
15317                 break;
15318         case -EINVAL:
15319                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15320                        res->vf_id, res->tc_no, res->bw);
15321                 break;
15322         case -ENODEV:
15323                 printf("invalid port_id %d\n", res->port_id);
15324                 break;
15325         case -ENOTSUP:
15326                 printf("function not implemented\n");
15327                 break;
15328         default:
15329                 printf("programming error: (%s)\n", strerror(-ret));
15330         }
15331 }
15332
15333 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15334         .f = cmd_vf_tc_max_bw_parsed,
15335         .data = NULL,
15336         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15337                     " <bandwidth>",
15338         .tokens = {
15339                 (void *)&cmd_vf_tc_bw_set,
15340                 (void *)&cmd_vf_tc_bw_vf,
15341                 (void *)&cmd_vf_tc_bw_tc,
15342                 (void *)&cmd_vf_tc_bw_tx,
15343                 (void *)&cmd_vf_tc_bw_max_bw,
15344                 (void *)&cmd_vf_tc_bw_port_id,
15345                 (void *)&cmd_vf_tc_bw_vf_id,
15346                 (void *)&cmd_vf_tc_bw_tc_no,
15347                 (void *)&cmd_vf_tc_bw_bw,
15348                 NULL,
15349         },
15350 };
15351
15352
15353 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15354
15355 /* *** Set Port default Traffic Management Hierarchy *** */
15356 struct cmd_set_port_tm_hierarchy_default_result {
15357         cmdline_fixed_string_t set;
15358         cmdline_fixed_string_t port;
15359         cmdline_fixed_string_t tm;
15360         cmdline_fixed_string_t hierarchy;
15361         cmdline_fixed_string_t def;
15362         portid_t port_id;
15363 };
15364
15365 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15366         TOKEN_STRING_INITIALIZER(
15367                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15368 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15369         TOKEN_STRING_INITIALIZER(
15370                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15371 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15372         TOKEN_STRING_INITIALIZER(
15373                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15374 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15375         TOKEN_STRING_INITIALIZER(
15376                 struct cmd_set_port_tm_hierarchy_default_result,
15377                         hierarchy, "hierarchy");
15378 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15379         TOKEN_STRING_INITIALIZER(
15380                 struct cmd_set_port_tm_hierarchy_default_result,
15381                         def, "default");
15382 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15383         TOKEN_NUM_INITIALIZER(
15384                 struct cmd_set_port_tm_hierarchy_default_result,
15385                         port_id, UINT16);
15386
15387 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15388         __rte_unused struct cmdline *cl,
15389         __rte_unused void *data)
15390 {
15391         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15392         struct rte_port *p;
15393         portid_t port_id = res->port_id;
15394
15395         if (port_id_is_invalid(port_id, ENABLED_WARN))
15396                 return;
15397
15398         p = &ports[port_id];
15399
15400         /* Forward mode: tm */
15401         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15402                 printf("  softnicfwd mode not enabled(error)\n");
15403                 return;
15404         }
15405
15406         /* Set the default tm hierarchy */
15407         p->softport.default_tm_hierarchy_enable = 1;
15408 }
15409
15410 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15411         .f = cmd_set_port_tm_hierarchy_default_parsed,
15412         .data = NULL,
15413         .help_str = "set port tm hierarchy default <port_id>",
15414         .tokens = {
15415                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15416                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15417                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15418                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15419                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15420                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15421                 NULL,
15422         },
15423 };
15424 #endif
15425
15426 /** Set VXLAN encapsulation details */
15427 struct cmd_set_vxlan_result {
15428         cmdline_fixed_string_t set;
15429         cmdline_fixed_string_t vxlan;
15430         cmdline_fixed_string_t pos_token;
15431         cmdline_fixed_string_t ip_version;
15432         uint32_t vlan_present:1;
15433         uint32_t vni;
15434         uint16_t udp_src;
15435         uint16_t udp_dst;
15436         cmdline_ipaddr_t ip_src;
15437         cmdline_ipaddr_t ip_dst;
15438         uint16_t tci;
15439         uint8_t tos;
15440         uint8_t ttl;
15441         struct rte_ether_addr eth_src;
15442         struct rte_ether_addr eth_dst;
15443 };
15444
15445 cmdline_parse_token_string_t cmd_set_vxlan_set =
15446         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15447 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15448         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15449 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15450         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15451                                  "vxlan-tos-ttl");
15452 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15453         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15454                                  "vxlan-with-vlan");
15455 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15456         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15457                                  "ip-version");
15458 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15459         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15460                                  "ipv4#ipv6");
15461 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15462         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15463                                  "vni");
15464 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15465         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15466 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15467         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15468                                  "udp-src");
15469 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15470         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15471 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15472         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15473                                  "udp-dst");
15474 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15475         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15476 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15477         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15478                                  "ip-tos");
15479 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15480         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15481 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15482         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15483                                  "ip-ttl");
15484 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15485         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15486 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15487         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15488                                  "ip-src");
15489 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15490         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15491 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15492         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15493                                  "ip-dst");
15494 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15495         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15496 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15497         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15498                                  "vlan-tci");
15499 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15500         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15501 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15502         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15503                                  "eth-src");
15504 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15505         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15506 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15507         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15508                                  "eth-dst");
15509 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15510         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15511
15512 static void cmd_set_vxlan_parsed(void *parsed_result,
15513         __rte_unused struct cmdline *cl,
15514         __rte_unused void *data)
15515 {
15516         struct cmd_set_vxlan_result *res = parsed_result;
15517         union {
15518                 uint32_t vxlan_id;
15519                 uint8_t vni[4];
15520         } id = {
15521                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15522         };
15523
15524         vxlan_encap_conf.select_tos_ttl = 0;
15525         if (strcmp(res->vxlan, "vxlan") == 0)
15526                 vxlan_encap_conf.select_vlan = 0;
15527         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15528                 vxlan_encap_conf.select_vlan = 1;
15529         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15530                 vxlan_encap_conf.select_vlan = 0;
15531                 vxlan_encap_conf.select_tos_ttl = 1;
15532         }
15533         if (strcmp(res->ip_version, "ipv4") == 0)
15534                 vxlan_encap_conf.select_ipv4 = 1;
15535         else if (strcmp(res->ip_version, "ipv6") == 0)
15536                 vxlan_encap_conf.select_ipv4 = 0;
15537         else
15538                 return;
15539         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15540         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15541         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15542         vxlan_encap_conf.ip_tos = res->tos;
15543         vxlan_encap_conf.ip_ttl = res->ttl;
15544         if (vxlan_encap_conf.select_ipv4) {
15545                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15546                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15547         } else {
15548                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15549                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15550         }
15551         if (vxlan_encap_conf.select_vlan)
15552                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15553         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15554                    RTE_ETHER_ADDR_LEN);
15555         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15556                    RTE_ETHER_ADDR_LEN);
15557 }
15558
15559 cmdline_parse_inst_t cmd_set_vxlan = {
15560         .f = cmd_set_vxlan_parsed,
15561         .data = NULL,
15562         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15563                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15564                 " eth-src <eth-src> eth-dst <eth-dst>",
15565         .tokens = {
15566                 (void *)&cmd_set_vxlan_set,
15567                 (void *)&cmd_set_vxlan_vxlan,
15568                 (void *)&cmd_set_vxlan_ip_version,
15569                 (void *)&cmd_set_vxlan_ip_version_value,
15570                 (void *)&cmd_set_vxlan_vni,
15571                 (void *)&cmd_set_vxlan_vni_value,
15572                 (void *)&cmd_set_vxlan_udp_src,
15573                 (void *)&cmd_set_vxlan_udp_src_value,
15574                 (void *)&cmd_set_vxlan_udp_dst,
15575                 (void *)&cmd_set_vxlan_udp_dst_value,
15576                 (void *)&cmd_set_vxlan_ip_src,
15577                 (void *)&cmd_set_vxlan_ip_src_value,
15578                 (void *)&cmd_set_vxlan_ip_dst,
15579                 (void *)&cmd_set_vxlan_ip_dst_value,
15580                 (void *)&cmd_set_vxlan_eth_src,
15581                 (void *)&cmd_set_vxlan_eth_src_value,
15582                 (void *)&cmd_set_vxlan_eth_dst,
15583                 (void *)&cmd_set_vxlan_eth_dst_value,
15584                 NULL,
15585         },
15586 };
15587
15588 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15589         .f = cmd_set_vxlan_parsed,
15590         .data = NULL,
15591         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15592                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15593                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15594                 " eth-dst <eth-dst>",
15595         .tokens = {
15596                 (void *)&cmd_set_vxlan_set,
15597                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15598                 (void *)&cmd_set_vxlan_ip_version,
15599                 (void *)&cmd_set_vxlan_ip_version_value,
15600                 (void *)&cmd_set_vxlan_vni,
15601                 (void *)&cmd_set_vxlan_vni_value,
15602                 (void *)&cmd_set_vxlan_udp_src,
15603                 (void *)&cmd_set_vxlan_udp_src_value,
15604                 (void *)&cmd_set_vxlan_udp_dst,
15605                 (void *)&cmd_set_vxlan_udp_dst_value,
15606                 (void *)&cmd_set_vxlan_ip_tos,
15607                 (void *)&cmd_set_vxlan_ip_tos_value,
15608                 (void *)&cmd_set_vxlan_ip_ttl,
15609                 (void *)&cmd_set_vxlan_ip_ttl_value,
15610                 (void *)&cmd_set_vxlan_ip_src,
15611                 (void *)&cmd_set_vxlan_ip_src_value,
15612                 (void *)&cmd_set_vxlan_ip_dst,
15613                 (void *)&cmd_set_vxlan_ip_dst_value,
15614                 (void *)&cmd_set_vxlan_eth_src,
15615                 (void *)&cmd_set_vxlan_eth_src_value,
15616                 (void *)&cmd_set_vxlan_eth_dst,
15617                 (void *)&cmd_set_vxlan_eth_dst_value,
15618                 NULL,
15619         },
15620 };
15621
15622 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15623         .f = cmd_set_vxlan_parsed,
15624         .data = NULL,
15625         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15626                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15627                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15628                 " <eth-dst>",
15629         .tokens = {
15630                 (void *)&cmd_set_vxlan_set,
15631                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15632                 (void *)&cmd_set_vxlan_ip_version,
15633                 (void *)&cmd_set_vxlan_ip_version_value,
15634                 (void *)&cmd_set_vxlan_vni,
15635                 (void *)&cmd_set_vxlan_vni_value,
15636                 (void *)&cmd_set_vxlan_udp_src,
15637                 (void *)&cmd_set_vxlan_udp_src_value,
15638                 (void *)&cmd_set_vxlan_udp_dst,
15639                 (void *)&cmd_set_vxlan_udp_dst_value,
15640                 (void *)&cmd_set_vxlan_ip_src,
15641                 (void *)&cmd_set_vxlan_ip_src_value,
15642                 (void *)&cmd_set_vxlan_ip_dst,
15643                 (void *)&cmd_set_vxlan_ip_dst_value,
15644                 (void *)&cmd_set_vxlan_vlan,
15645                 (void *)&cmd_set_vxlan_vlan_value,
15646                 (void *)&cmd_set_vxlan_eth_src,
15647                 (void *)&cmd_set_vxlan_eth_src_value,
15648                 (void *)&cmd_set_vxlan_eth_dst,
15649                 (void *)&cmd_set_vxlan_eth_dst_value,
15650                 NULL,
15651         },
15652 };
15653
15654 /** Set NVGRE encapsulation details */
15655 struct cmd_set_nvgre_result {
15656         cmdline_fixed_string_t set;
15657         cmdline_fixed_string_t nvgre;
15658         cmdline_fixed_string_t pos_token;
15659         cmdline_fixed_string_t ip_version;
15660         uint32_t tni;
15661         cmdline_ipaddr_t ip_src;
15662         cmdline_ipaddr_t ip_dst;
15663         uint16_t tci;
15664         struct rte_ether_addr eth_src;
15665         struct rte_ether_addr eth_dst;
15666 };
15667
15668 cmdline_parse_token_string_t cmd_set_nvgre_set =
15669         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15670 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15671         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15672 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15673         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15674                                  "nvgre-with-vlan");
15675 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15676         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15677                                  "ip-version");
15678 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15679         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15680                                  "ipv4#ipv6");
15681 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15682         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15683                                  "tni");
15684 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15685         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15686 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15687         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15688                                  "ip-src");
15689 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15690         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15691 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15692         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15693                                  "ip-dst");
15694 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15695         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15696 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15697         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15698                                  "vlan-tci");
15699 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15700         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15701 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15702         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15703                                  "eth-src");
15704 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15705         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15706 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15707         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15708                                  "eth-dst");
15709 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15710         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15711
15712 static void cmd_set_nvgre_parsed(void *parsed_result,
15713         __rte_unused struct cmdline *cl,
15714         __rte_unused void *data)
15715 {
15716         struct cmd_set_nvgre_result *res = parsed_result;
15717         union {
15718                 uint32_t nvgre_tni;
15719                 uint8_t tni[4];
15720         } id = {
15721                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15722         };
15723
15724         if (strcmp(res->nvgre, "nvgre") == 0)
15725                 nvgre_encap_conf.select_vlan = 0;
15726         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15727                 nvgre_encap_conf.select_vlan = 1;
15728         if (strcmp(res->ip_version, "ipv4") == 0)
15729                 nvgre_encap_conf.select_ipv4 = 1;
15730         else if (strcmp(res->ip_version, "ipv6") == 0)
15731                 nvgre_encap_conf.select_ipv4 = 0;
15732         else
15733                 return;
15734         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15735         if (nvgre_encap_conf.select_ipv4) {
15736                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15737                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15738         } else {
15739                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15740                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15741         }
15742         if (nvgre_encap_conf.select_vlan)
15743                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15744         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15745                    RTE_ETHER_ADDR_LEN);
15746         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15747                    RTE_ETHER_ADDR_LEN);
15748 }
15749
15750 cmdline_parse_inst_t cmd_set_nvgre = {
15751         .f = cmd_set_nvgre_parsed,
15752         .data = NULL,
15753         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15754                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15755                 " eth-dst <eth-dst>",
15756         .tokens = {
15757                 (void *)&cmd_set_nvgre_set,
15758                 (void *)&cmd_set_nvgre_nvgre,
15759                 (void *)&cmd_set_nvgre_ip_version,
15760                 (void *)&cmd_set_nvgre_ip_version_value,
15761                 (void *)&cmd_set_nvgre_tni,
15762                 (void *)&cmd_set_nvgre_tni_value,
15763                 (void *)&cmd_set_nvgre_ip_src,
15764                 (void *)&cmd_set_nvgre_ip_src_value,
15765                 (void *)&cmd_set_nvgre_ip_dst,
15766                 (void *)&cmd_set_nvgre_ip_dst_value,
15767                 (void *)&cmd_set_nvgre_eth_src,
15768                 (void *)&cmd_set_nvgre_eth_src_value,
15769                 (void *)&cmd_set_nvgre_eth_dst,
15770                 (void *)&cmd_set_nvgre_eth_dst_value,
15771                 NULL,
15772         },
15773 };
15774
15775 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15776         .f = cmd_set_nvgre_parsed,
15777         .data = NULL,
15778         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15779                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15780                 " eth-src <eth-src> eth-dst <eth-dst>",
15781         .tokens = {
15782                 (void *)&cmd_set_nvgre_set,
15783                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15784                 (void *)&cmd_set_nvgre_ip_version,
15785                 (void *)&cmd_set_nvgre_ip_version_value,
15786                 (void *)&cmd_set_nvgre_tni,
15787                 (void *)&cmd_set_nvgre_tni_value,
15788                 (void *)&cmd_set_nvgre_ip_src,
15789                 (void *)&cmd_set_nvgre_ip_src_value,
15790                 (void *)&cmd_set_nvgre_ip_dst,
15791                 (void *)&cmd_set_nvgre_ip_dst_value,
15792                 (void *)&cmd_set_nvgre_vlan,
15793                 (void *)&cmd_set_nvgre_vlan_value,
15794                 (void *)&cmd_set_nvgre_eth_src,
15795                 (void *)&cmd_set_nvgre_eth_src_value,
15796                 (void *)&cmd_set_nvgre_eth_dst,
15797                 (void *)&cmd_set_nvgre_eth_dst_value,
15798                 NULL,
15799         },
15800 };
15801
15802 /** Set L2 encapsulation details */
15803 struct cmd_set_l2_encap_result {
15804         cmdline_fixed_string_t set;
15805         cmdline_fixed_string_t l2_encap;
15806         cmdline_fixed_string_t pos_token;
15807         cmdline_fixed_string_t ip_version;
15808         uint32_t vlan_present:1;
15809         uint16_t tci;
15810         struct rte_ether_addr eth_src;
15811         struct rte_ether_addr eth_dst;
15812 };
15813
15814 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15815         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15816 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15817         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15818 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15819         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15820                                  "l2_encap-with-vlan");
15821 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15822         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15823                                  "ip-version");
15824 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15825         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15826                                  "ipv4#ipv6");
15827 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15828         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15829                                  "vlan-tci");
15830 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15831         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15832 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15833         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15834                                  "eth-src");
15835 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15836         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15837 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15838         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15839                                  "eth-dst");
15840 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15841         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15842
15843 static void cmd_set_l2_encap_parsed(void *parsed_result,
15844         __rte_unused struct cmdline *cl,
15845         __rte_unused void *data)
15846 {
15847         struct cmd_set_l2_encap_result *res = parsed_result;
15848
15849         if (strcmp(res->l2_encap, "l2_encap") == 0)
15850                 l2_encap_conf.select_vlan = 0;
15851         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15852                 l2_encap_conf.select_vlan = 1;
15853         if (strcmp(res->ip_version, "ipv4") == 0)
15854                 l2_encap_conf.select_ipv4 = 1;
15855         else if (strcmp(res->ip_version, "ipv6") == 0)
15856                 l2_encap_conf.select_ipv4 = 0;
15857         else
15858                 return;
15859         if (l2_encap_conf.select_vlan)
15860                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15861         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15862                    RTE_ETHER_ADDR_LEN);
15863         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15864                    RTE_ETHER_ADDR_LEN);
15865 }
15866
15867 cmdline_parse_inst_t cmd_set_l2_encap = {
15868         .f = cmd_set_l2_encap_parsed,
15869         .data = NULL,
15870         .help_str = "set l2_encap ip-version ipv4|ipv6"
15871                 " eth-src <eth-src> eth-dst <eth-dst>",
15872         .tokens = {
15873                 (void *)&cmd_set_l2_encap_set,
15874                 (void *)&cmd_set_l2_encap_l2_encap,
15875                 (void *)&cmd_set_l2_encap_ip_version,
15876                 (void *)&cmd_set_l2_encap_ip_version_value,
15877                 (void *)&cmd_set_l2_encap_eth_src,
15878                 (void *)&cmd_set_l2_encap_eth_src_value,
15879                 (void *)&cmd_set_l2_encap_eth_dst,
15880                 (void *)&cmd_set_l2_encap_eth_dst_value,
15881                 NULL,
15882         },
15883 };
15884
15885 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15886         .f = cmd_set_l2_encap_parsed,
15887         .data = NULL,
15888         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15889                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15890         .tokens = {
15891                 (void *)&cmd_set_l2_encap_set,
15892                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15893                 (void *)&cmd_set_l2_encap_ip_version,
15894                 (void *)&cmd_set_l2_encap_ip_version_value,
15895                 (void *)&cmd_set_l2_encap_vlan,
15896                 (void *)&cmd_set_l2_encap_vlan_value,
15897                 (void *)&cmd_set_l2_encap_eth_src,
15898                 (void *)&cmd_set_l2_encap_eth_src_value,
15899                 (void *)&cmd_set_l2_encap_eth_dst,
15900                 (void *)&cmd_set_l2_encap_eth_dst_value,
15901                 NULL,
15902         },
15903 };
15904
15905 /** Set L2 decapsulation details */
15906 struct cmd_set_l2_decap_result {
15907         cmdline_fixed_string_t set;
15908         cmdline_fixed_string_t l2_decap;
15909         cmdline_fixed_string_t pos_token;
15910         uint32_t vlan_present:1;
15911 };
15912
15913 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15914         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15915 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15916         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15917                                  "l2_decap");
15918 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15919         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15920                                  "l2_decap-with-vlan");
15921
15922 static void cmd_set_l2_decap_parsed(void *parsed_result,
15923         __rte_unused struct cmdline *cl,
15924         __rte_unused void *data)
15925 {
15926         struct cmd_set_l2_decap_result *res = parsed_result;
15927
15928         if (strcmp(res->l2_decap, "l2_decap") == 0)
15929                 l2_decap_conf.select_vlan = 0;
15930         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15931                 l2_decap_conf.select_vlan = 1;
15932 }
15933
15934 cmdline_parse_inst_t cmd_set_l2_decap = {
15935         .f = cmd_set_l2_decap_parsed,
15936         .data = NULL,
15937         .help_str = "set l2_decap",
15938         .tokens = {
15939                 (void *)&cmd_set_l2_decap_set,
15940                 (void *)&cmd_set_l2_decap_l2_decap,
15941                 NULL,
15942         },
15943 };
15944
15945 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15946         .f = cmd_set_l2_decap_parsed,
15947         .data = NULL,
15948         .help_str = "set l2_decap-with-vlan",
15949         .tokens = {
15950                 (void *)&cmd_set_l2_decap_set,
15951                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15952                 NULL,
15953         },
15954 };
15955
15956 /** Set MPLSoGRE encapsulation details */
15957 struct cmd_set_mplsogre_encap_result {
15958         cmdline_fixed_string_t set;
15959         cmdline_fixed_string_t mplsogre;
15960         cmdline_fixed_string_t pos_token;
15961         cmdline_fixed_string_t ip_version;
15962         uint32_t vlan_present:1;
15963         uint32_t label;
15964         cmdline_ipaddr_t ip_src;
15965         cmdline_ipaddr_t ip_dst;
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_mplsogre_encap_set =
15972         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15973                                  "set");
15974 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15975         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15976                                  "mplsogre_encap");
15977 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15978         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15979                                  mplsogre, "mplsogre_encap-with-vlan");
15980 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15981         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15982                                  pos_token, "ip-version");
15983 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15984         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15985                                  ip_version, "ipv4#ipv6");
15986 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15987         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15988                                  pos_token, "label");
15989 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15990         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15991                               UINT32);
15992 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15993         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15994                                  pos_token, "ip-src");
15995 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15996         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15997 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15998         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15999                                  pos_token, "ip-dst");
16000 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16001         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16002 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16003         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16004                                  pos_token, "vlan-tci");
16005 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16006         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16007                               UINT16);
16008 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16009         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16010                                  pos_token, "eth-src");
16011 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16012         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16013                                     eth_src);
16014 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16015         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16016                                  pos_token, "eth-dst");
16017 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16018         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16019                                     eth_dst);
16020
16021 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16022         __rte_unused struct cmdline *cl,
16023         __rte_unused void *data)
16024 {
16025         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16026         union {
16027                 uint32_t mplsogre_label;
16028                 uint8_t label[4];
16029         } id = {
16030                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16031         };
16032
16033         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16034                 mplsogre_encap_conf.select_vlan = 0;
16035         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16036                 mplsogre_encap_conf.select_vlan = 1;
16037         if (strcmp(res->ip_version, "ipv4") == 0)
16038                 mplsogre_encap_conf.select_ipv4 = 1;
16039         else if (strcmp(res->ip_version, "ipv6") == 0)
16040                 mplsogre_encap_conf.select_ipv4 = 0;
16041         else
16042                 return;
16043         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16044         if (mplsogre_encap_conf.select_ipv4) {
16045                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16046                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16047         } else {
16048                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16049                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16050         }
16051         if (mplsogre_encap_conf.select_vlan)
16052                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16053         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16054                    RTE_ETHER_ADDR_LEN);
16055         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16056                    RTE_ETHER_ADDR_LEN);
16057 }
16058
16059 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16060         .f = cmd_set_mplsogre_encap_parsed,
16061         .data = NULL,
16062         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16063                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16064                 " eth-dst <eth-dst>",
16065         .tokens = {
16066                 (void *)&cmd_set_mplsogre_encap_set,
16067                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16068                 (void *)&cmd_set_mplsogre_encap_ip_version,
16069                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16070                 (void *)&cmd_set_mplsogre_encap_label,
16071                 (void *)&cmd_set_mplsogre_encap_label_value,
16072                 (void *)&cmd_set_mplsogre_encap_ip_src,
16073                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16074                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16075                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16076                 (void *)&cmd_set_mplsogre_encap_eth_src,
16077                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16078                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16079                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16080                 NULL,
16081         },
16082 };
16083
16084 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16085         .f = cmd_set_mplsogre_encap_parsed,
16086         .data = NULL,
16087         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16088                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16089                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16090         .tokens = {
16091                 (void *)&cmd_set_mplsogre_encap_set,
16092                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16093                 (void *)&cmd_set_mplsogre_encap_ip_version,
16094                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16095                 (void *)&cmd_set_mplsogre_encap_label,
16096                 (void *)&cmd_set_mplsogre_encap_label_value,
16097                 (void *)&cmd_set_mplsogre_encap_ip_src,
16098                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16099                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16100                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16101                 (void *)&cmd_set_mplsogre_encap_vlan,
16102                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16103                 (void *)&cmd_set_mplsogre_encap_eth_src,
16104                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16105                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16106                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16107                 NULL,
16108         },
16109 };
16110
16111 /** Set MPLSoGRE decapsulation details */
16112 struct cmd_set_mplsogre_decap_result {
16113         cmdline_fixed_string_t set;
16114         cmdline_fixed_string_t mplsogre;
16115         cmdline_fixed_string_t pos_token;
16116         cmdline_fixed_string_t ip_version;
16117         uint32_t vlan_present:1;
16118 };
16119
16120 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16121         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16122                                  "set");
16123 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16124         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16125                                  "mplsogre_decap");
16126 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16127         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16128                                  mplsogre, "mplsogre_decap-with-vlan");
16129 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16130         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16131                                  pos_token, "ip-version");
16132 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16133         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16134                                  ip_version, "ipv4#ipv6");
16135
16136 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16137         __rte_unused struct cmdline *cl,
16138         __rte_unused void *data)
16139 {
16140         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16141
16142         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16143                 mplsogre_decap_conf.select_vlan = 0;
16144         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16145                 mplsogre_decap_conf.select_vlan = 1;
16146         if (strcmp(res->ip_version, "ipv4") == 0)
16147                 mplsogre_decap_conf.select_ipv4 = 1;
16148         else if (strcmp(res->ip_version, "ipv6") == 0)
16149                 mplsogre_decap_conf.select_ipv4 = 0;
16150 }
16151
16152 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16153         .f = cmd_set_mplsogre_decap_parsed,
16154         .data = NULL,
16155         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16156         .tokens = {
16157                 (void *)&cmd_set_mplsogre_decap_set,
16158                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16159                 (void *)&cmd_set_mplsogre_decap_ip_version,
16160                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16161                 NULL,
16162         },
16163 };
16164
16165 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16166         .f = cmd_set_mplsogre_decap_parsed,
16167         .data = NULL,
16168         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16169         .tokens = {
16170                 (void *)&cmd_set_mplsogre_decap_set,
16171                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16172                 (void *)&cmd_set_mplsogre_decap_ip_version,
16173                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16174                 NULL,
16175         },
16176 };
16177
16178 /** Set MPLSoUDP encapsulation details */
16179 struct cmd_set_mplsoudp_encap_result {
16180         cmdline_fixed_string_t set;
16181         cmdline_fixed_string_t mplsoudp;
16182         cmdline_fixed_string_t pos_token;
16183         cmdline_fixed_string_t ip_version;
16184         uint32_t vlan_present:1;
16185         uint32_t label;
16186         uint16_t udp_src;
16187         uint16_t udp_dst;
16188         cmdline_ipaddr_t ip_src;
16189         cmdline_ipaddr_t ip_dst;
16190         uint16_t tci;
16191         struct rte_ether_addr eth_src;
16192         struct rte_ether_addr eth_dst;
16193 };
16194
16195 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16196         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16197                                  "set");
16198 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16199         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16200                                  "mplsoudp_encap");
16201 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16202         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16203                                  mplsoudp, "mplsoudp_encap-with-vlan");
16204 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16205         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16206                                  pos_token, "ip-version");
16207 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16208         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16209                                  ip_version, "ipv4#ipv6");
16210 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16211         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16212                                  pos_token, "label");
16213 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16214         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16215                               UINT32);
16216 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16217         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16218                                  pos_token, "udp-src");
16219 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16220         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16221                               UINT16);
16222 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16223         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16224                                  pos_token, "udp-dst");
16225 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16226         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16227                               UINT16);
16228 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16229         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16230                                  pos_token, "ip-src");
16231 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16232         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16233 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16234         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16235                                  pos_token, "ip-dst");
16236 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16237         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16238 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16239         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16240                                  pos_token, "vlan-tci");
16241 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16242         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16243                               UINT16);
16244 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16245         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16246                                  pos_token, "eth-src");
16247 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16248         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16249                                     eth_src);
16250 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16251         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16252                                  pos_token, "eth-dst");
16253 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16254         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16255                                     eth_dst);
16256
16257 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16258         __rte_unused struct cmdline *cl,
16259         __rte_unused void *data)
16260 {
16261         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16262         union {
16263                 uint32_t mplsoudp_label;
16264                 uint8_t label[4];
16265         } id = {
16266                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16267         };
16268
16269         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16270                 mplsoudp_encap_conf.select_vlan = 0;
16271         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16272                 mplsoudp_encap_conf.select_vlan = 1;
16273         if (strcmp(res->ip_version, "ipv4") == 0)
16274                 mplsoudp_encap_conf.select_ipv4 = 1;
16275         else if (strcmp(res->ip_version, "ipv6") == 0)
16276                 mplsoudp_encap_conf.select_ipv4 = 0;
16277         else
16278                 return;
16279         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16280         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16281         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16282         if (mplsoudp_encap_conf.select_ipv4) {
16283                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16284                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16285         } else {
16286                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16287                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16288         }
16289         if (mplsoudp_encap_conf.select_vlan)
16290                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16291         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16292                    RTE_ETHER_ADDR_LEN);
16293         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16294                    RTE_ETHER_ADDR_LEN);
16295 }
16296
16297 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16298         .f = cmd_set_mplsoudp_encap_parsed,
16299         .data = NULL,
16300         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16301                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16302                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16303         .tokens = {
16304                 (void *)&cmd_set_mplsoudp_encap_set,
16305                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16306                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16307                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16308                 (void *)&cmd_set_mplsoudp_encap_label,
16309                 (void *)&cmd_set_mplsoudp_encap_label_value,
16310                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16311                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16312                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16313                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16314                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16315                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16316                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16317                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16318                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16319                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16320                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16321                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16322                 NULL,
16323         },
16324 };
16325
16326 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16327         .f = cmd_set_mplsoudp_encap_parsed,
16328         .data = NULL,
16329         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16330                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16331                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16332                 " eth-src <eth-src> eth-dst <eth-dst>",
16333         .tokens = {
16334                 (void *)&cmd_set_mplsoudp_encap_set,
16335                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16336                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16337                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16338                 (void *)&cmd_set_mplsoudp_encap_label,
16339                 (void *)&cmd_set_mplsoudp_encap_label_value,
16340                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16341                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16342                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16343                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16344                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16345                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16346                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16347                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16348                 (void *)&cmd_set_mplsoudp_encap_vlan,
16349                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16350                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16351                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16352                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16353                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16354                 NULL,
16355         },
16356 };
16357
16358 /** Set MPLSoUDP decapsulation details */
16359 struct cmd_set_mplsoudp_decap_result {
16360         cmdline_fixed_string_t set;
16361         cmdline_fixed_string_t mplsoudp;
16362         cmdline_fixed_string_t pos_token;
16363         cmdline_fixed_string_t ip_version;
16364         uint32_t vlan_present:1;
16365 };
16366
16367 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16368         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16369                                  "set");
16370 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16371         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16372                                  "mplsoudp_decap");
16373 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16374         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16375                                  mplsoudp, "mplsoudp_decap-with-vlan");
16376 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16377         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16378                                  pos_token, "ip-version");
16379 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16380         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16381                                  ip_version, "ipv4#ipv6");
16382
16383 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16384         __rte_unused struct cmdline *cl,
16385         __rte_unused void *data)
16386 {
16387         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16388
16389         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16390                 mplsoudp_decap_conf.select_vlan = 0;
16391         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16392                 mplsoudp_decap_conf.select_vlan = 1;
16393         if (strcmp(res->ip_version, "ipv4") == 0)
16394                 mplsoudp_decap_conf.select_ipv4 = 1;
16395         else if (strcmp(res->ip_version, "ipv6") == 0)
16396                 mplsoudp_decap_conf.select_ipv4 = 0;
16397 }
16398
16399 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16400         .f = cmd_set_mplsoudp_decap_parsed,
16401         .data = NULL,
16402         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16403         .tokens = {
16404                 (void *)&cmd_set_mplsoudp_decap_set,
16405                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16406                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16407                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16408                 NULL,
16409         },
16410 };
16411
16412 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16413         .f = cmd_set_mplsoudp_decap_parsed,
16414         .data = NULL,
16415         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16416         .tokens = {
16417                 (void *)&cmd_set_mplsoudp_decap_set,
16418                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16419                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16420                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16421                 NULL,
16422         },
16423 };
16424
16425 /* Strict link priority scheduling mode setting */
16426 static void
16427 cmd_strict_link_prio_parsed(
16428         void *parsed_result,
16429         __rte_unused struct cmdline *cl,
16430         __rte_unused void *data)
16431 {
16432         struct cmd_vf_tc_bw_result *res = parsed_result;
16433         int ret = -ENOTSUP;
16434
16435         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16436                 return;
16437
16438 #ifdef RTE_LIBRTE_I40E_PMD
16439         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16440 #endif
16441
16442         switch (ret) {
16443         case 0:
16444                 break;
16445         case -EINVAL:
16446                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16447                 break;
16448         case -ENODEV:
16449                 printf("invalid port_id %d\n", res->port_id);
16450                 break;
16451         case -ENOTSUP:
16452                 printf("function not implemented\n");
16453                 break;
16454         default:
16455                 printf("programming error: (%s)\n", strerror(-ret));
16456         }
16457 }
16458
16459 cmdline_parse_inst_t cmd_strict_link_prio = {
16460         .f = cmd_strict_link_prio_parsed,
16461         .data = NULL,
16462         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16463         .tokens = {
16464                 (void *)&cmd_vf_tc_bw_set,
16465                 (void *)&cmd_vf_tc_bw_tx,
16466                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16467                 (void *)&cmd_vf_tc_bw_port_id,
16468                 (void *)&cmd_vf_tc_bw_tc_map,
16469                 NULL,
16470         },
16471 };
16472
16473 /* Load dynamic device personalization*/
16474 struct cmd_ddp_add_result {
16475         cmdline_fixed_string_t ddp;
16476         cmdline_fixed_string_t add;
16477         portid_t port_id;
16478         char filepath[];
16479 };
16480
16481 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16482         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16483 cmdline_parse_token_string_t cmd_ddp_add_add =
16484         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16485 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16486         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16487 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16488         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16489
16490 static void
16491 cmd_ddp_add_parsed(
16492         void *parsed_result,
16493         __rte_unused struct cmdline *cl,
16494         __rte_unused void *data)
16495 {
16496         struct cmd_ddp_add_result *res = parsed_result;
16497         uint8_t *buff;
16498         uint32_t size;
16499         char *filepath;
16500         char *file_fld[2];
16501         int file_num;
16502         int ret = -ENOTSUP;
16503
16504         if (!all_ports_stopped()) {
16505                 printf("Please stop all ports first\n");
16506                 return;
16507         }
16508
16509         filepath = strdup(res->filepath);
16510         if (filepath == NULL) {
16511                 printf("Failed to allocate memory\n");
16512                 return;
16513         }
16514         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16515
16516         buff = open_file(file_fld[0], &size);
16517         if (!buff) {
16518                 free((void *)filepath);
16519                 return;
16520         }
16521
16522 #ifdef RTE_LIBRTE_I40E_PMD
16523         if (ret == -ENOTSUP)
16524                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16525                                                buff, size,
16526                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16527 #endif
16528
16529         if (ret == -EEXIST)
16530                 printf("Profile has already existed.\n");
16531         else if (ret < 0)
16532                 printf("Failed to load profile.\n");
16533         else if (file_num == 2)
16534                 save_file(file_fld[1], buff, size);
16535
16536         close_file(buff);
16537         free((void *)filepath);
16538 }
16539
16540 cmdline_parse_inst_t cmd_ddp_add = {
16541         .f = cmd_ddp_add_parsed,
16542         .data = NULL,
16543         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16544         .tokens = {
16545                 (void *)&cmd_ddp_add_ddp,
16546                 (void *)&cmd_ddp_add_add,
16547                 (void *)&cmd_ddp_add_port_id,
16548                 (void *)&cmd_ddp_add_filepath,
16549                 NULL,
16550         },
16551 };
16552
16553 /* Delete dynamic device personalization*/
16554 struct cmd_ddp_del_result {
16555         cmdline_fixed_string_t ddp;
16556         cmdline_fixed_string_t del;
16557         portid_t port_id;
16558         char filepath[];
16559 };
16560
16561 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16562         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16563 cmdline_parse_token_string_t cmd_ddp_del_del =
16564         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16565 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16566         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16567 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16568         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16569
16570 static void
16571 cmd_ddp_del_parsed(
16572         void *parsed_result,
16573         __rte_unused struct cmdline *cl,
16574         __rte_unused void *data)
16575 {
16576         struct cmd_ddp_del_result *res = parsed_result;
16577         uint8_t *buff;
16578         uint32_t size;
16579         int ret = -ENOTSUP;
16580
16581         if (!all_ports_stopped()) {
16582                 printf("Please stop all ports first\n");
16583                 return;
16584         }
16585
16586         buff = open_file(res->filepath, &size);
16587         if (!buff)
16588                 return;
16589
16590 #ifdef RTE_LIBRTE_I40E_PMD
16591         if (ret == -ENOTSUP)
16592                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16593                                                buff, size,
16594                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16595 #endif
16596
16597         if (ret == -EACCES)
16598                 printf("Profile does not exist.\n");
16599         else if (ret < 0)
16600                 printf("Failed to delete profile.\n");
16601
16602         close_file(buff);
16603 }
16604
16605 cmdline_parse_inst_t cmd_ddp_del = {
16606         .f = cmd_ddp_del_parsed,
16607         .data = NULL,
16608         .help_str = "ddp del <port_id> <backup_profile_path>",
16609         .tokens = {
16610                 (void *)&cmd_ddp_del_ddp,
16611                 (void *)&cmd_ddp_del_del,
16612                 (void *)&cmd_ddp_del_port_id,
16613                 (void *)&cmd_ddp_del_filepath,
16614                 NULL,
16615         },
16616 };
16617
16618 /* Get dynamic device personalization profile info */
16619 struct cmd_ddp_info_result {
16620         cmdline_fixed_string_t ddp;
16621         cmdline_fixed_string_t get;
16622         cmdline_fixed_string_t info;
16623         char filepath[];
16624 };
16625
16626 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16627         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16628 cmdline_parse_token_string_t cmd_ddp_info_get =
16629         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16630 cmdline_parse_token_string_t cmd_ddp_info_info =
16631         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16632 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16633         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16634
16635 static void
16636 cmd_ddp_info_parsed(
16637         void *parsed_result,
16638         __rte_unused struct cmdline *cl,
16639         __rte_unused void *data)
16640 {
16641         struct cmd_ddp_info_result *res = parsed_result;
16642         uint8_t *pkg;
16643         uint32_t pkg_size;
16644         int ret = -ENOTSUP;
16645 #ifdef RTE_LIBRTE_I40E_PMD
16646         uint32_t i, j, n;
16647         uint8_t *buff;
16648         uint32_t buff_size = 0;
16649         struct rte_pmd_i40e_profile_info info;
16650         uint32_t dev_num = 0;
16651         struct rte_pmd_i40e_ddp_device_id *devs;
16652         uint32_t proto_num = 0;
16653         struct rte_pmd_i40e_proto_info *proto = NULL;
16654         uint32_t pctype_num = 0;
16655         struct rte_pmd_i40e_ptype_info *pctype;
16656         uint32_t ptype_num = 0;
16657         struct rte_pmd_i40e_ptype_info *ptype;
16658         uint8_t proto_id;
16659
16660 #endif
16661
16662         pkg = open_file(res->filepath, &pkg_size);
16663         if (!pkg)
16664                 return;
16665
16666 #ifdef RTE_LIBRTE_I40E_PMD
16667         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16668                                 (uint8_t *)&info, sizeof(info),
16669                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16670         if (!ret) {
16671                 printf("Global Track id:       0x%x\n", info.track_id);
16672                 printf("Global Version:        %d.%d.%d.%d\n",
16673                         info.version.major,
16674                         info.version.minor,
16675                         info.version.update,
16676                         info.version.draft);
16677                 printf("Global Package name:   %s\n\n", info.name);
16678         }
16679
16680         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16681                                 (uint8_t *)&info, sizeof(info),
16682                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16683         if (!ret) {
16684                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16685                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16686                         info.version.major,
16687                         info.version.minor,
16688                         info.version.update,
16689                         info.version.draft);
16690                 printf("i40e Profile name:     %s\n\n", info.name);
16691         }
16692
16693         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16694                                 (uint8_t *)&buff_size, sizeof(buff_size),
16695                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16696         if (!ret && buff_size) {
16697                 buff = (uint8_t *)malloc(buff_size);
16698                 if (buff) {
16699                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16700                                                 buff, buff_size,
16701                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16702                         if (!ret)
16703                                 printf("Package Notes:\n%s\n\n", buff);
16704                         free(buff);
16705                 }
16706         }
16707
16708         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16709                                 (uint8_t *)&dev_num, sizeof(dev_num),
16710                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16711         if (!ret && dev_num) {
16712                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16713                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16714                 if (devs) {
16715                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16716                                                 (uint8_t *)devs, buff_size,
16717                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16718                         if (!ret) {
16719                                 printf("List of supported devices:\n");
16720                                 for (i = 0; i < dev_num; i++) {
16721                                         printf("  %04X:%04X %04X:%04X\n",
16722                                                 devs[i].vendor_dev_id >> 16,
16723                                                 devs[i].vendor_dev_id & 0xFFFF,
16724                                                 devs[i].sub_vendor_dev_id >> 16,
16725                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16726                                 }
16727                                 printf("\n");
16728                         }
16729                         free(devs);
16730                 }
16731         }
16732
16733         /* get information about protocols and packet types */
16734         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16735                 (uint8_t *)&proto_num, sizeof(proto_num),
16736                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16737         if (ret || !proto_num)
16738                 goto no_print_return;
16739
16740         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16741         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16742         if (!proto)
16743                 goto no_print_return;
16744
16745         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16746                                         buff_size,
16747                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16748         if (!ret) {
16749                 printf("List of used protocols:\n");
16750                 for (i = 0; i < proto_num; i++)
16751                         printf("  %2u: %s\n", proto[i].proto_id,
16752                                proto[i].name);
16753                 printf("\n");
16754         }
16755         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16756                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16757                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16758         if (ret || !pctype_num)
16759                 goto no_print_pctypes;
16760
16761         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16762         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16763         if (!pctype)
16764                 goto no_print_pctypes;
16765
16766         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16767                                         buff_size,
16768                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16769         if (ret) {
16770                 free(pctype);
16771                 goto no_print_pctypes;
16772         }
16773
16774         printf("List of defined packet classification types:\n");
16775         for (i = 0; i < pctype_num; i++) {
16776                 printf("  %2u:", pctype[i].ptype_id);
16777                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16778                         proto_id = pctype[i].protocols[j];
16779                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16780                                 for (n = 0; n < proto_num; n++) {
16781                                         if (proto[n].proto_id == proto_id) {
16782                                                 printf(" %s", proto[n].name);
16783                                                 break;
16784                                         }
16785                                 }
16786                         }
16787                 }
16788                 printf("\n");
16789         }
16790         printf("\n");
16791         free(pctype);
16792
16793 no_print_pctypes:
16794
16795         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16796                                         sizeof(ptype_num),
16797                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16798         if (ret || !ptype_num)
16799                 goto no_print_return;
16800
16801         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16802         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16803         if (!ptype)
16804                 goto no_print_return;
16805
16806         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16807                                         buff_size,
16808                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16809         if (ret) {
16810                 free(ptype);
16811                 goto no_print_return;
16812         }
16813         printf("List of defined packet types:\n");
16814         for (i = 0; i < ptype_num; i++) {
16815                 printf("  %2u:", ptype[i].ptype_id);
16816                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16817                         proto_id = ptype[i].protocols[j];
16818                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16819                                 for (n = 0; n < proto_num; n++) {
16820                                         if (proto[n].proto_id == proto_id) {
16821                                                 printf(" %s", proto[n].name);
16822                                                 break;
16823                                         }
16824                                 }
16825                         }
16826                 }
16827                 printf("\n");
16828         }
16829         free(ptype);
16830         printf("\n");
16831
16832         ret = 0;
16833 no_print_return:
16834         if (proto)
16835                 free(proto);
16836 #endif
16837         if (ret == -ENOTSUP)
16838                 printf("Function not supported in PMD driver\n");
16839         close_file(pkg);
16840 }
16841
16842 cmdline_parse_inst_t cmd_ddp_get_info = {
16843         .f = cmd_ddp_info_parsed,
16844         .data = NULL,
16845         .help_str = "ddp get info <profile_path>",
16846         .tokens = {
16847                 (void *)&cmd_ddp_info_ddp,
16848                 (void *)&cmd_ddp_info_get,
16849                 (void *)&cmd_ddp_info_info,
16850                 (void *)&cmd_ddp_info_filepath,
16851                 NULL,
16852         },
16853 };
16854
16855 /* Get dynamic device personalization profile info list*/
16856 #define PROFILE_INFO_SIZE 48
16857 #define MAX_PROFILE_NUM 16
16858
16859 struct cmd_ddp_get_list_result {
16860         cmdline_fixed_string_t ddp;
16861         cmdline_fixed_string_t get;
16862         cmdline_fixed_string_t list;
16863         portid_t port_id;
16864 };
16865
16866 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16867         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16868 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16869         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16870 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16871         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16872 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16873         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16874
16875 static void
16876 cmd_ddp_get_list_parsed(
16877         __rte_unused void *parsed_result,
16878         __rte_unused struct cmdline *cl,
16879         __rte_unused void *data)
16880 {
16881 #ifdef RTE_LIBRTE_I40E_PMD
16882         struct cmd_ddp_get_list_result *res = parsed_result;
16883         struct rte_pmd_i40e_profile_list *p_list;
16884         struct rte_pmd_i40e_profile_info *p_info;
16885         uint32_t p_num;
16886         uint32_t size;
16887         uint32_t i;
16888 #endif
16889         int ret = -ENOTSUP;
16890
16891 #ifdef RTE_LIBRTE_I40E_PMD
16892         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16893         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16894         if (!p_list)
16895                 printf("%s: Failed to malloc buffer\n", __func__);
16896
16897         if (ret == -ENOTSUP)
16898                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16899                                                 (uint8_t *)p_list, size);
16900
16901         if (!ret) {
16902                 p_num = p_list->p_count;
16903                 printf("Profile number is: %d\n\n", p_num);
16904
16905                 for (i = 0; i < p_num; i++) {
16906                         p_info = &p_list->p_info[i];
16907                         printf("Profile %d:\n", i);
16908                         printf("Track id:     0x%x\n", p_info->track_id);
16909                         printf("Version:      %d.%d.%d.%d\n",
16910                                p_info->version.major,
16911                                p_info->version.minor,
16912                                p_info->version.update,
16913                                p_info->version.draft);
16914                         printf("Profile name: %s\n\n", p_info->name);
16915                 }
16916         }
16917
16918         free(p_list);
16919 #endif
16920
16921         if (ret < 0)
16922                 printf("Failed to get ddp list\n");
16923 }
16924
16925 cmdline_parse_inst_t cmd_ddp_get_list = {
16926         .f = cmd_ddp_get_list_parsed,
16927         .data = NULL,
16928         .help_str = "ddp get list <port_id>",
16929         .tokens = {
16930                 (void *)&cmd_ddp_get_list_ddp,
16931                 (void *)&cmd_ddp_get_list_get,
16932                 (void *)&cmd_ddp_get_list_list,
16933                 (void *)&cmd_ddp_get_list_port_id,
16934                 NULL,
16935         },
16936 };
16937
16938 /* Configure input set */
16939 struct cmd_cfg_input_set_result {
16940         cmdline_fixed_string_t port;
16941         cmdline_fixed_string_t cfg;
16942         portid_t port_id;
16943         cmdline_fixed_string_t pctype;
16944         uint8_t pctype_id;
16945         cmdline_fixed_string_t inset_type;
16946         cmdline_fixed_string_t opt;
16947         cmdline_fixed_string_t field;
16948         uint8_t field_idx;
16949 };
16950
16951 static void
16952 cmd_cfg_input_set_parsed(
16953         __rte_unused void *parsed_result,
16954         __rte_unused struct cmdline *cl,
16955         __rte_unused void *data)
16956 {
16957 #ifdef RTE_LIBRTE_I40E_PMD
16958         struct cmd_cfg_input_set_result *res = parsed_result;
16959         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16960         struct rte_pmd_i40e_inset inset;
16961 #endif
16962         int ret = -ENOTSUP;
16963
16964         if (!all_ports_stopped()) {
16965                 printf("Please stop all ports first\n");
16966                 return;
16967         }
16968
16969 #ifdef RTE_LIBRTE_I40E_PMD
16970         if (!strcmp(res->inset_type, "hash_inset"))
16971                 inset_type = INSET_HASH;
16972         else if (!strcmp(res->inset_type, "fdir_inset"))
16973                 inset_type = INSET_FDIR;
16974         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16975                 inset_type = INSET_FDIR_FLX;
16976         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16977                                      &inset, inset_type);
16978         if (ret) {
16979                 printf("Failed to get input set.\n");
16980                 return;
16981         }
16982
16983         if (!strcmp(res->opt, "get")) {
16984                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16985                                                    res->field_idx);
16986                 if (ret)
16987                         printf("Field index %d is enabled.\n", res->field_idx);
16988                 else
16989                         printf("Field index %d is disabled.\n", res->field_idx);
16990                 return;
16991         } else if (!strcmp(res->opt, "set"))
16992                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16993                                                    res->field_idx);
16994         else if (!strcmp(res->opt, "clear"))
16995                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16996                                                      res->field_idx);
16997         if (ret) {
16998                 printf("Failed to configure input set field.\n");
16999                 return;
17000         }
17001
17002         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17003                                      &inset, inset_type);
17004         if (ret) {
17005                 printf("Failed to set input set.\n");
17006                 return;
17007         }
17008 #endif
17009
17010         if (ret == -ENOTSUP)
17011                 printf("Function not supported\n");
17012 }
17013
17014 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17015         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17016                                  port, "port");
17017 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17018         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17019                                  cfg, "config");
17020 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17021         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17022                               port_id, UINT16);
17023 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17024         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17025                                  pctype, "pctype");
17026 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17027         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17028                               pctype_id, UINT8);
17029 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17030         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17031                                  inset_type,
17032                                  "hash_inset#fdir_inset#fdir_flx_inset");
17033 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17034         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17035                                  opt, "get#set#clear");
17036 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17037         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17038                                  field, "field");
17039 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17040         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17041                               field_idx, UINT8);
17042
17043 cmdline_parse_inst_t cmd_cfg_input_set = {
17044         .f = cmd_cfg_input_set_parsed,
17045         .data = NULL,
17046         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17047                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17048         .tokens = {
17049                 (void *)&cmd_cfg_input_set_port,
17050                 (void *)&cmd_cfg_input_set_cfg,
17051                 (void *)&cmd_cfg_input_set_port_id,
17052                 (void *)&cmd_cfg_input_set_pctype,
17053                 (void *)&cmd_cfg_input_set_pctype_id,
17054                 (void *)&cmd_cfg_input_set_inset_type,
17055                 (void *)&cmd_cfg_input_set_opt,
17056                 (void *)&cmd_cfg_input_set_field,
17057                 (void *)&cmd_cfg_input_set_field_idx,
17058                 NULL,
17059         },
17060 };
17061
17062 /* Clear input set */
17063 struct cmd_clear_input_set_result {
17064         cmdline_fixed_string_t port;
17065         cmdline_fixed_string_t cfg;
17066         portid_t port_id;
17067         cmdline_fixed_string_t pctype;
17068         uint8_t pctype_id;
17069         cmdline_fixed_string_t inset_type;
17070         cmdline_fixed_string_t clear;
17071         cmdline_fixed_string_t all;
17072 };
17073
17074 static void
17075 cmd_clear_input_set_parsed(
17076         __rte_unused void *parsed_result,
17077         __rte_unused struct cmdline *cl,
17078         __rte_unused void *data)
17079 {
17080 #ifdef RTE_LIBRTE_I40E_PMD
17081         struct cmd_clear_input_set_result *res = parsed_result;
17082         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17083         struct rte_pmd_i40e_inset inset;
17084 #endif
17085         int ret = -ENOTSUP;
17086
17087         if (!all_ports_stopped()) {
17088                 printf("Please stop all ports first\n");
17089                 return;
17090         }
17091
17092 #ifdef RTE_LIBRTE_I40E_PMD
17093         if (!strcmp(res->inset_type, "hash_inset"))
17094                 inset_type = INSET_HASH;
17095         else if (!strcmp(res->inset_type, "fdir_inset"))
17096                 inset_type = INSET_FDIR;
17097         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17098                 inset_type = INSET_FDIR_FLX;
17099
17100         memset(&inset, 0, sizeof(inset));
17101
17102         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17103                                      &inset, inset_type);
17104         if (ret) {
17105                 printf("Failed to clear input set.\n");
17106                 return;
17107         }
17108
17109 #endif
17110
17111         if (ret == -ENOTSUP)
17112                 printf("Function not supported\n");
17113 }
17114
17115 cmdline_parse_token_string_t cmd_clear_input_set_port =
17116         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17117                                  port, "port");
17118 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17119         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17120                                  cfg, "config");
17121 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17122         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17123                               port_id, UINT16);
17124 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17125         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17126                                  pctype, "pctype");
17127 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17128         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17129                               pctype_id, UINT8);
17130 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17131         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17132                                  inset_type,
17133                                  "hash_inset#fdir_inset#fdir_flx_inset");
17134 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17135         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17136                                  clear, "clear");
17137 cmdline_parse_token_string_t cmd_clear_input_set_all =
17138         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17139                                  all, "all");
17140
17141 cmdline_parse_inst_t cmd_clear_input_set = {
17142         .f = cmd_clear_input_set_parsed,
17143         .data = NULL,
17144         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17145                     "fdir_inset|fdir_flx_inset clear all",
17146         .tokens = {
17147                 (void *)&cmd_clear_input_set_port,
17148                 (void *)&cmd_clear_input_set_cfg,
17149                 (void *)&cmd_clear_input_set_port_id,
17150                 (void *)&cmd_clear_input_set_pctype,
17151                 (void *)&cmd_clear_input_set_pctype_id,
17152                 (void *)&cmd_clear_input_set_inset_type,
17153                 (void *)&cmd_clear_input_set_clear,
17154                 (void *)&cmd_clear_input_set_all,
17155                 NULL,
17156         },
17157 };
17158
17159 /* show vf stats */
17160
17161 /* Common result structure for show vf stats */
17162 struct cmd_show_vf_stats_result {
17163         cmdline_fixed_string_t show;
17164         cmdline_fixed_string_t vf;
17165         cmdline_fixed_string_t stats;
17166         portid_t port_id;
17167         uint16_t vf_id;
17168 };
17169
17170 /* Common CLI fields show vf stats*/
17171 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17172         TOKEN_STRING_INITIALIZER
17173                 (struct cmd_show_vf_stats_result,
17174                  show, "show");
17175 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17176         TOKEN_STRING_INITIALIZER
17177                 (struct cmd_show_vf_stats_result,
17178                  vf, "vf");
17179 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17180         TOKEN_STRING_INITIALIZER
17181                 (struct cmd_show_vf_stats_result,
17182                  stats, "stats");
17183 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17184         TOKEN_NUM_INITIALIZER
17185                 (struct cmd_show_vf_stats_result,
17186                  port_id, UINT16);
17187 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17188         TOKEN_NUM_INITIALIZER
17189                 (struct cmd_show_vf_stats_result,
17190                  vf_id, UINT16);
17191
17192 static void
17193 cmd_show_vf_stats_parsed(
17194         void *parsed_result,
17195         __rte_unused struct cmdline *cl,
17196         __rte_unused void *data)
17197 {
17198         struct cmd_show_vf_stats_result *res = parsed_result;
17199         struct rte_eth_stats stats;
17200         int ret = -ENOTSUP;
17201         static const char *nic_stats_border = "########################";
17202
17203         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17204                 return;
17205
17206         memset(&stats, 0, sizeof(stats));
17207
17208 #ifdef RTE_LIBRTE_I40E_PMD
17209         if (ret == -ENOTSUP)
17210                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17211                                                 res->vf_id,
17212                                                 &stats);
17213 #endif
17214 #ifdef RTE_LIBRTE_BNXT_PMD
17215         if (ret == -ENOTSUP)
17216                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17217                                                 res->vf_id,
17218                                                 &stats);
17219 #endif
17220
17221         switch (ret) {
17222         case 0:
17223                 break;
17224         case -EINVAL:
17225                 printf("invalid vf_id %d\n", res->vf_id);
17226                 break;
17227         case -ENODEV:
17228                 printf("invalid port_id %d\n", res->port_id);
17229                 break;
17230         case -ENOTSUP:
17231                 printf("function not implemented\n");
17232                 break;
17233         default:
17234                 printf("programming error: (%s)\n", strerror(-ret));
17235         }
17236
17237         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17238                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17239
17240         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17241                "%-"PRIu64"\n",
17242                stats.ipackets, stats.imissed, stats.ibytes);
17243         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17244         printf("  RX-nombuf:  %-10"PRIu64"\n",
17245                stats.rx_nombuf);
17246         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17247                "%-"PRIu64"\n",
17248                stats.opackets, stats.oerrors, stats.obytes);
17249
17250         printf("  %s############################%s\n",
17251                                nic_stats_border, nic_stats_border);
17252 }
17253
17254 cmdline_parse_inst_t cmd_show_vf_stats = {
17255         .f = cmd_show_vf_stats_parsed,
17256         .data = NULL,
17257         .help_str = "show vf stats <port_id> <vf_id>",
17258         .tokens = {
17259                 (void *)&cmd_show_vf_stats_show,
17260                 (void *)&cmd_show_vf_stats_vf,
17261                 (void *)&cmd_show_vf_stats_stats,
17262                 (void *)&cmd_show_vf_stats_port_id,
17263                 (void *)&cmd_show_vf_stats_vf_id,
17264                 NULL,
17265         },
17266 };
17267
17268 /* clear vf stats */
17269
17270 /* Common result structure for clear vf stats */
17271 struct cmd_clear_vf_stats_result {
17272         cmdline_fixed_string_t clear;
17273         cmdline_fixed_string_t vf;
17274         cmdline_fixed_string_t stats;
17275         portid_t port_id;
17276         uint16_t vf_id;
17277 };
17278
17279 /* Common CLI fields clear vf stats*/
17280 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17281         TOKEN_STRING_INITIALIZER
17282                 (struct cmd_clear_vf_stats_result,
17283                  clear, "clear");
17284 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17285         TOKEN_STRING_INITIALIZER
17286                 (struct cmd_clear_vf_stats_result,
17287                  vf, "vf");
17288 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17289         TOKEN_STRING_INITIALIZER
17290                 (struct cmd_clear_vf_stats_result,
17291                  stats, "stats");
17292 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17293         TOKEN_NUM_INITIALIZER
17294                 (struct cmd_clear_vf_stats_result,
17295                  port_id, UINT16);
17296 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17297         TOKEN_NUM_INITIALIZER
17298                 (struct cmd_clear_vf_stats_result,
17299                  vf_id, UINT16);
17300
17301 static void
17302 cmd_clear_vf_stats_parsed(
17303         void *parsed_result,
17304         __rte_unused struct cmdline *cl,
17305         __rte_unused void *data)
17306 {
17307         struct cmd_clear_vf_stats_result *res = parsed_result;
17308         int ret = -ENOTSUP;
17309
17310         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17311                 return;
17312
17313 #ifdef RTE_LIBRTE_I40E_PMD
17314         if (ret == -ENOTSUP)
17315                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17316                                                   res->vf_id);
17317 #endif
17318 #ifdef RTE_LIBRTE_BNXT_PMD
17319         if (ret == -ENOTSUP)
17320                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17321                                                   res->vf_id);
17322 #endif
17323
17324         switch (ret) {
17325         case 0:
17326                 break;
17327         case -EINVAL:
17328                 printf("invalid vf_id %d\n", res->vf_id);
17329                 break;
17330         case -ENODEV:
17331                 printf("invalid port_id %d\n", res->port_id);
17332                 break;
17333         case -ENOTSUP:
17334                 printf("function not implemented\n");
17335                 break;
17336         default:
17337                 printf("programming error: (%s)\n", strerror(-ret));
17338         }
17339 }
17340
17341 cmdline_parse_inst_t cmd_clear_vf_stats = {
17342         .f = cmd_clear_vf_stats_parsed,
17343         .data = NULL,
17344         .help_str = "clear vf stats <port_id> <vf_id>",
17345         .tokens = {
17346                 (void *)&cmd_clear_vf_stats_clear,
17347                 (void *)&cmd_clear_vf_stats_vf,
17348                 (void *)&cmd_clear_vf_stats_stats,
17349                 (void *)&cmd_clear_vf_stats_port_id,
17350                 (void *)&cmd_clear_vf_stats_vf_id,
17351                 NULL,
17352         },
17353 };
17354
17355 /* port config pctype mapping reset */
17356
17357 /* Common result structure for port config pctype mapping reset */
17358 struct cmd_pctype_mapping_reset_result {
17359         cmdline_fixed_string_t port;
17360         cmdline_fixed_string_t config;
17361         portid_t port_id;
17362         cmdline_fixed_string_t pctype;
17363         cmdline_fixed_string_t mapping;
17364         cmdline_fixed_string_t reset;
17365 };
17366
17367 /* Common CLI fields for port config pctype mapping reset*/
17368 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17369         TOKEN_STRING_INITIALIZER
17370                 (struct cmd_pctype_mapping_reset_result,
17371                  port, "port");
17372 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17373         TOKEN_STRING_INITIALIZER
17374                 (struct cmd_pctype_mapping_reset_result,
17375                  config, "config");
17376 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17377         TOKEN_NUM_INITIALIZER
17378                 (struct cmd_pctype_mapping_reset_result,
17379                  port_id, UINT16);
17380 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17381         TOKEN_STRING_INITIALIZER
17382                 (struct cmd_pctype_mapping_reset_result,
17383                  pctype, "pctype");
17384 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17385         TOKEN_STRING_INITIALIZER
17386                 (struct cmd_pctype_mapping_reset_result,
17387                  mapping, "mapping");
17388 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17389         TOKEN_STRING_INITIALIZER
17390                 (struct cmd_pctype_mapping_reset_result,
17391                  reset, "reset");
17392
17393 static void
17394 cmd_pctype_mapping_reset_parsed(
17395         void *parsed_result,
17396         __rte_unused struct cmdline *cl,
17397         __rte_unused void *data)
17398 {
17399         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17400         int ret = -ENOTSUP;
17401
17402         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17403                 return;
17404
17405 #ifdef RTE_LIBRTE_I40E_PMD
17406         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17407 #endif
17408
17409         switch (ret) {
17410         case 0:
17411                 break;
17412         case -ENODEV:
17413                 printf("invalid port_id %d\n", res->port_id);
17414                 break;
17415         case -ENOTSUP:
17416                 printf("function not implemented\n");
17417                 break;
17418         default:
17419                 printf("programming error: (%s)\n", strerror(-ret));
17420         }
17421 }
17422
17423 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17424         .f = cmd_pctype_mapping_reset_parsed,
17425         .data = NULL,
17426         .help_str = "port config <port_id> pctype mapping reset",
17427         .tokens = {
17428                 (void *)&cmd_pctype_mapping_reset_port,
17429                 (void *)&cmd_pctype_mapping_reset_config,
17430                 (void *)&cmd_pctype_mapping_reset_port_id,
17431                 (void *)&cmd_pctype_mapping_reset_pctype,
17432                 (void *)&cmd_pctype_mapping_reset_mapping,
17433                 (void *)&cmd_pctype_mapping_reset_reset,
17434                 NULL,
17435         },
17436 };
17437
17438 /* show port pctype mapping */
17439
17440 /* Common result structure for show port pctype mapping */
17441 struct cmd_pctype_mapping_get_result {
17442         cmdline_fixed_string_t show;
17443         cmdline_fixed_string_t port;
17444         portid_t port_id;
17445         cmdline_fixed_string_t pctype;
17446         cmdline_fixed_string_t mapping;
17447 };
17448
17449 /* Common CLI fields for pctype mapping get */
17450 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17451         TOKEN_STRING_INITIALIZER
17452                 (struct cmd_pctype_mapping_get_result,
17453                  show, "show");
17454 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17455         TOKEN_STRING_INITIALIZER
17456                 (struct cmd_pctype_mapping_get_result,
17457                  port, "port");
17458 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17459         TOKEN_NUM_INITIALIZER
17460                 (struct cmd_pctype_mapping_get_result,
17461                  port_id, UINT16);
17462 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17463         TOKEN_STRING_INITIALIZER
17464                 (struct cmd_pctype_mapping_get_result,
17465                  pctype, "pctype");
17466 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17467         TOKEN_STRING_INITIALIZER
17468                 (struct cmd_pctype_mapping_get_result,
17469                  mapping, "mapping");
17470
17471 static void
17472 cmd_pctype_mapping_get_parsed(
17473         void *parsed_result,
17474         __rte_unused struct cmdline *cl,
17475         __rte_unused void *data)
17476 {
17477         struct cmd_pctype_mapping_get_result *res = parsed_result;
17478         int ret = -ENOTSUP;
17479 #ifdef RTE_LIBRTE_I40E_PMD
17480         struct rte_pmd_i40e_flow_type_mapping
17481                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17482         int i, j, first_pctype;
17483 #endif
17484
17485         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17486                 return;
17487
17488 #ifdef RTE_LIBRTE_I40E_PMD
17489         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17490 #endif
17491
17492         switch (ret) {
17493         case 0:
17494                 break;
17495         case -ENODEV:
17496                 printf("invalid port_id %d\n", res->port_id);
17497                 return;
17498         case -ENOTSUP:
17499                 printf("function not implemented\n");
17500                 return;
17501         default:
17502                 printf("programming error: (%s)\n", strerror(-ret));
17503                 return;
17504         }
17505
17506 #ifdef RTE_LIBRTE_I40E_PMD
17507         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17508                 if (mapping[i].pctype != 0ULL) {
17509                         first_pctype = 1;
17510
17511                         printf("pctype: ");
17512                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17513                                 if (mapping[i].pctype & (1ULL << j)) {
17514                                         printf(first_pctype ?
17515                                                "%02d" : ",%02d", j);
17516                                         first_pctype = 0;
17517                                 }
17518                         }
17519                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17520                 }
17521         }
17522 #endif
17523 }
17524
17525 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17526         .f = cmd_pctype_mapping_get_parsed,
17527         .data = NULL,
17528         .help_str = "show port <port_id> pctype mapping",
17529         .tokens = {
17530                 (void *)&cmd_pctype_mapping_get_show,
17531                 (void *)&cmd_pctype_mapping_get_port,
17532                 (void *)&cmd_pctype_mapping_get_port_id,
17533                 (void *)&cmd_pctype_mapping_get_pctype,
17534                 (void *)&cmd_pctype_mapping_get_mapping,
17535                 NULL,
17536         },
17537 };
17538
17539 /* port config pctype mapping update */
17540
17541 /* Common result structure for port config pctype mapping update */
17542 struct cmd_pctype_mapping_update_result {
17543         cmdline_fixed_string_t port;
17544         cmdline_fixed_string_t config;
17545         portid_t port_id;
17546         cmdline_fixed_string_t pctype;
17547         cmdline_fixed_string_t mapping;
17548         cmdline_fixed_string_t update;
17549         cmdline_fixed_string_t pctype_list;
17550         uint16_t flow_type;
17551 };
17552
17553 /* Common CLI fields for pctype mapping update*/
17554 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17555         TOKEN_STRING_INITIALIZER
17556                 (struct cmd_pctype_mapping_update_result,
17557                  port, "port");
17558 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17559         TOKEN_STRING_INITIALIZER
17560                 (struct cmd_pctype_mapping_update_result,
17561                  config, "config");
17562 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17563         TOKEN_NUM_INITIALIZER
17564                 (struct cmd_pctype_mapping_update_result,
17565                  port_id, UINT16);
17566 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17567         TOKEN_STRING_INITIALIZER
17568                 (struct cmd_pctype_mapping_update_result,
17569                  pctype, "pctype");
17570 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17571         TOKEN_STRING_INITIALIZER
17572                 (struct cmd_pctype_mapping_update_result,
17573                  mapping, "mapping");
17574 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17575         TOKEN_STRING_INITIALIZER
17576                 (struct cmd_pctype_mapping_update_result,
17577                  update, "update");
17578 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17579         TOKEN_STRING_INITIALIZER
17580                 (struct cmd_pctype_mapping_update_result,
17581                  pctype_list, NULL);
17582 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17583         TOKEN_NUM_INITIALIZER
17584                 (struct cmd_pctype_mapping_update_result,
17585                  flow_type, UINT16);
17586
17587 static void
17588 cmd_pctype_mapping_update_parsed(
17589         void *parsed_result,
17590         __rte_unused struct cmdline *cl,
17591         __rte_unused void *data)
17592 {
17593         struct cmd_pctype_mapping_update_result *res = parsed_result;
17594         int ret = -ENOTSUP;
17595 #ifdef RTE_LIBRTE_I40E_PMD
17596         struct rte_pmd_i40e_flow_type_mapping mapping;
17597         unsigned int i;
17598         unsigned int nb_item;
17599         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17600 #endif
17601
17602         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17603                 return;
17604
17605 #ifdef RTE_LIBRTE_I40E_PMD
17606         nb_item = parse_item_list(res->pctype_list, "pctypes",
17607                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17608         mapping.flow_type = res->flow_type;
17609         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17610                 mapping.pctype |= (1ULL << pctype_list[i]);
17611         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17612                                                 &mapping,
17613                                                 1,
17614                                                 0);
17615 #endif
17616
17617         switch (ret) {
17618         case 0:
17619                 break;
17620         case -EINVAL:
17621                 printf("invalid pctype or flow type\n");
17622                 break;
17623         case -ENODEV:
17624                 printf("invalid port_id %d\n", res->port_id);
17625                 break;
17626         case -ENOTSUP:
17627                 printf("function not implemented\n");
17628                 break;
17629         default:
17630                 printf("programming error: (%s)\n", strerror(-ret));
17631         }
17632 }
17633
17634 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17635         .f = cmd_pctype_mapping_update_parsed,
17636         .data = NULL,
17637         .help_str = "port config <port_id> pctype mapping update"
17638         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17639         .tokens = {
17640                 (void *)&cmd_pctype_mapping_update_port,
17641                 (void *)&cmd_pctype_mapping_update_config,
17642                 (void *)&cmd_pctype_mapping_update_port_id,
17643                 (void *)&cmd_pctype_mapping_update_pctype,
17644                 (void *)&cmd_pctype_mapping_update_mapping,
17645                 (void *)&cmd_pctype_mapping_update_update,
17646                 (void *)&cmd_pctype_mapping_update_pc_type,
17647                 (void *)&cmd_pctype_mapping_update_flow_type,
17648                 NULL,
17649         },
17650 };
17651
17652 /* ptype mapping get */
17653
17654 /* Common result structure for ptype mapping get */
17655 struct cmd_ptype_mapping_get_result {
17656         cmdline_fixed_string_t ptype;
17657         cmdline_fixed_string_t mapping;
17658         cmdline_fixed_string_t get;
17659         portid_t port_id;
17660         uint8_t valid_only;
17661 };
17662
17663 /* Common CLI fields for ptype mapping get */
17664 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17665         TOKEN_STRING_INITIALIZER
17666                 (struct cmd_ptype_mapping_get_result,
17667                  ptype, "ptype");
17668 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17669         TOKEN_STRING_INITIALIZER
17670                 (struct cmd_ptype_mapping_get_result,
17671                  mapping, "mapping");
17672 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17673         TOKEN_STRING_INITIALIZER
17674                 (struct cmd_ptype_mapping_get_result,
17675                  get, "get");
17676 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17677         TOKEN_NUM_INITIALIZER
17678                 (struct cmd_ptype_mapping_get_result,
17679                  port_id, UINT16);
17680 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17681         TOKEN_NUM_INITIALIZER
17682                 (struct cmd_ptype_mapping_get_result,
17683                  valid_only, UINT8);
17684
17685 static void
17686 cmd_ptype_mapping_get_parsed(
17687         void *parsed_result,
17688         __rte_unused struct cmdline *cl,
17689         __rte_unused void *data)
17690 {
17691         struct cmd_ptype_mapping_get_result *res = parsed_result;
17692         int ret = -ENOTSUP;
17693 #ifdef RTE_LIBRTE_I40E_PMD
17694         int max_ptype_num = 256;
17695         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17696         uint16_t count;
17697         int i;
17698 #endif
17699
17700         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17701                 return;
17702
17703 #ifdef RTE_LIBRTE_I40E_PMD
17704         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17705                                         mapping,
17706                                         max_ptype_num,
17707                                         &count,
17708                                         res->valid_only);
17709 #endif
17710
17711         switch (ret) {
17712         case 0:
17713                 break;
17714         case -ENODEV:
17715                 printf("invalid port_id %d\n", res->port_id);
17716                 break;
17717         case -ENOTSUP:
17718                 printf("function not implemented\n");
17719                 break;
17720         default:
17721                 printf("programming error: (%s)\n", strerror(-ret));
17722         }
17723
17724 #ifdef RTE_LIBRTE_I40E_PMD
17725         if (!ret) {
17726                 for (i = 0; i < count; i++)
17727                         printf("%3d\t0x%08x\n",
17728                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17729         }
17730 #endif
17731 }
17732
17733 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17734         .f = cmd_ptype_mapping_get_parsed,
17735         .data = NULL,
17736         .help_str = "ptype mapping get <port_id> <valid_only>",
17737         .tokens = {
17738                 (void *)&cmd_ptype_mapping_get_ptype,
17739                 (void *)&cmd_ptype_mapping_get_mapping,
17740                 (void *)&cmd_ptype_mapping_get_get,
17741                 (void *)&cmd_ptype_mapping_get_port_id,
17742                 (void *)&cmd_ptype_mapping_get_valid_only,
17743                 NULL,
17744         },
17745 };
17746
17747 /* ptype mapping replace */
17748
17749 /* Common result structure for ptype mapping replace */
17750 struct cmd_ptype_mapping_replace_result {
17751         cmdline_fixed_string_t ptype;
17752         cmdline_fixed_string_t mapping;
17753         cmdline_fixed_string_t replace;
17754         portid_t port_id;
17755         uint32_t target;
17756         uint8_t mask;
17757         uint32_t pkt_type;
17758 };
17759
17760 /* Common CLI fields for ptype mapping replace */
17761 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17762         TOKEN_STRING_INITIALIZER
17763                 (struct cmd_ptype_mapping_replace_result,
17764                  ptype, "ptype");
17765 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17766         TOKEN_STRING_INITIALIZER
17767                 (struct cmd_ptype_mapping_replace_result,
17768                  mapping, "mapping");
17769 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17770         TOKEN_STRING_INITIALIZER
17771                 (struct cmd_ptype_mapping_replace_result,
17772                  replace, "replace");
17773 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17774         TOKEN_NUM_INITIALIZER
17775                 (struct cmd_ptype_mapping_replace_result,
17776                  port_id, UINT16);
17777 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17778         TOKEN_NUM_INITIALIZER
17779                 (struct cmd_ptype_mapping_replace_result,
17780                  target, UINT32);
17781 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17782         TOKEN_NUM_INITIALIZER
17783                 (struct cmd_ptype_mapping_replace_result,
17784                  mask, UINT8);
17785 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17786         TOKEN_NUM_INITIALIZER
17787                 (struct cmd_ptype_mapping_replace_result,
17788                  pkt_type, UINT32);
17789
17790 static void
17791 cmd_ptype_mapping_replace_parsed(
17792         void *parsed_result,
17793         __rte_unused struct cmdline *cl,
17794         __rte_unused void *data)
17795 {
17796         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17797         int ret = -ENOTSUP;
17798
17799         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17800                 return;
17801
17802 #ifdef RTE_LIBRTE_I40E_PMD
17803         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17804                                         res->target,
17805                                         res->mask,
17806                                         res->pkt_type);
17807 #endif
17808
17809         switch (ret) {
17810         case 0:
17811                 break;
17812         case -EINVAL:
17813                 printf("invalid ptype 0x%8x or 0x%8x\n",
17814                                 res->target, res->pkt_type);
17815                 break;
17816         case -ENODEV:
17817                 printf("invalid port_id %d\n", res->port_id);
17818                 break;
17819         case -ENOTSUP:
17820                 printf("function not implemented\n");
17821                 break;
17822         default:
17823                 printf("programming error: (%s)\n", strerror(-ret));
17824         }
17825 }
17826
17827 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17828         .f = cmd_ptype_mapping_replace_parsed,
17829         .data = NULL,
17830         .help_str =
17831                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17832         .tokens = {
17833                 (void *)&cmd_ptype_mapping_replace_ptype,
17834                 (void *)&cmd_ptype_mapping_replace_mapping,
17835                 (void *)&cmd_ptype_mapping_replace_replace,
17836                 (void *)&cmd_ptype_mapping_replace_port_id,
17837                 (void *)&cmd_ptype_mapping_replace_target,
17838                 (void *)&cmd_ptype_mapping_replace_mask,
17839                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17840                 NULL,
17841         },
17842 };
17843
17844 /* ptype mapping reset */
17845
17846 /* Common result structure for ptype mapping reset */
17847 struct cmd_ptype_mapping_reset_result {
17848         cmdline_fixed_string_t ptype;
17849         cmdline_fixed_string_t mapping;
17850         cmdline_fixed_string_t reset;
17851         portid_t port_id;
17852 };
17853
17854 /* Common CLI fields for ptype mapping reset*/
17855 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17856         TOKEN_STRING_INITIALIZER
17857                 (struct cmd_ptype_mapping_reset_result,
17858                  ptype, "ptype");
17859 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17860         TOKEN_STRING_INITIALIZER
17861                 (struct cmd_ptype_mapping_reset_result,
17862                  mapping, "mapping");
17863 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17864         TOKEN_STRING_INITIALIZER
17865                 (struct cmd_ptype_mapping_reset_result,
17866                  reset, "reset");
17867 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17868         TOKEN_NUM_INITIALIZER
17869                 (struct cmd_ptype_mapping_reset_result,
17870                  port_id, UINT16);
17871
17872 static void
17873 cmd_ptype_mapping_reset_parsed(
17874         void *parsed_result,
17875         __rte_unused struct cmdline *cl,
17876         __rte_unused void *data)
17877 {
17878         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17879         int ret = -ENOTSUP;
17880
17881         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17882                 return;
17883
17884 #ifdef RTE_LIBRTE_I40E_PMD
17885         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17886 #endif
17887
17888         switch (ret) {
17889         case 0:
17890                 break;
17891         case -ENODEV:
17892                 printf("invalid port_id %d\n", res->port_id);
17893                 break;
17894         case -ENOTSUP:
17895                 printf("function not implemented\n");
17896                 break;
17897         default:
17898                 printf("programming error: (%s)\n", strerror(-ret));
17899         }
17900 }
17901
17902 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17903         .f = cmd_ptype_mapping_reset_parsed,
17904         .data = NULL,
17905         .help_str = "ptype mapping reset <port_id>",
17906         .tokens = {
17907                 (void *)&cmd_ptype_mapping_reset_ptype,
17908                 (void *)&cmd_ptype_mapping_reset_mapping,
17909                 (void *)&cmd_ptype_mapping_reset_reset,
17910                 (void *)&cmd_ptype_mapping_reset_port_id,
17911                 NULL,
17912         },
17913 };
17914
17915 /* ptype mapping update */
17916
17917 /* Common result structure for ptype mapping update */
17918 struct cmd_ptype_mapping_update_result {
17919         cmdline_fixed_string_t ptype;
17920         cmdline_fixed_string_t mapping;
17921         cmdline_fixed_string_t reset;
17922         portid_t port_id;
17923         uint8_t hw_ptype;
17924         uint32_t sw_ptype;
17925 };
17926
17927 /* Common CLI fields for ptype mapping update*/
17928 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17929         TOKEN_STRING_INITIALIZER
17930                 (struct cmd_ptype_mapping_update_result,
17931                  ptype, "ptype");
17932 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17933         TOKEN_STRING_INITIALIZER
17934                 (struct cmd_ptype_mapping_update_result,
17935                  mapping, "mapping");
17936 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17937         TOKEN_STRING_INITIALIZER
17938                 (struct cmd_ptype_mapping_update_result,
17939                  reset, "update");
17940 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17941         TOKEN_NUM_INITIALIZER
17942                 (struct cmd_ptype_mapping_update_result,
17943                  port_id, UINT16);
17944 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17945         TOKEN_NUM_INITIALIZER
17946                 (struct cmd_ptype_mapping_update_result,
17947                  hw_ptype, UINT8);
17948 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17949         TOKEN_NUM_INITIALIZER
17950                 (struct cmd_ptype_mapping_update_result,
17951                  sw_ptype, UINT32);
17952
17953 static void
17954 cmd_ptype_mapping_update_parsed(
17955         void *parsed_result,
17956         __rte_unused struct cmdline *cl,
17957         __rte_unused void *data)
17958 {
17959         struct cmd_ptype_mapping_update_result *res = parsed_result;
17960         int ret = -ENOTSUP;
17961 #ifdef RTE_LIBRTE_I40E_PMD
17962         struct rte_pmd_i40e_ptype_mapping mapping;
17963 #endif
17964         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17965                 return;
17966
17967 #ifdef RTE_LIBRTE_I40E_PMD
17968         mapping.hw_ptype = res->hw_ptype;
17969         mapping.sw_ptype = res->sw_ptype;
17970         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17971                                                 &mapping,
17972                                                 1,
17973                                                 0);
17974 #endif
17975
17976         switch (ret) {
17977         case 0:
17978                 break;
17979         case -EINVAL:
17980                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17981                 break;
17982         case -ENODEV:
17983                 printf("invalid port_id %d\n", res->port_id);
17984                 break;
17985         case -ENOTSUP:
17986                 printf("function not implemented\n");
17987                 break;
17988         default:
17989                 printf("programming error: (%s)\n", strerror(-ret));
17990         }
17991 }
17992
17993 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17994         .f = cmd_ptype_mapping_update_parsed,
17995         .data = NULL,
17996         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17997         .tokens = {
17998                 (void *)&cmd_ptype_mapping_update_ptype,
17999                 (void *)&cmd_ptype_mapping_update_mapping,
18000                 (void *)&cmd_ptype_mapping_update_update,
18001                 (void *)&cmd_ptype_mapping_update_port_id,
18002                 (void *)&cmd_ptype_mapping_update_hw_ptype,
18003                 (void *)&cmd_ptype_mapping_update_sw_ptype,
18004                 NULL,
18005         },
18006 };
18007
18008 /* Common result structure for file commands */
18009 struct cmd_cmdfile_result {
18010         cmdline_fixed_string_t load;
18011         cmdline_fixed_string_t filename;
18012 };
18013
18014 /* Common CLI fields for file commands */
18015 cmdline_parse_token_string_t cmd_load_cmdfile =
18016         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18017 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18018         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18019
18020 static void
18021 cmd_load_from_file_parsed(
18022         void *parsed_result,
18023         __rte_unused struct cmdline *cl,
18024         __rte_unused void *data)
18025 {
18026         struct cmd_cmdfile_result *res = parsed_result;
18027
18028         cmdline_read_from_file(res->filename);
18029 }
18030
18031 cmdline_parse_inst_t cmd_load_from_file = {
18032         .f = cmd_load_from_file_parsed,
18033         .data = NULL,
18034         .help_str = "load <filename>",
18035         .tokens = {
18036                 (void *)&cmd_load_cmdfile,
18037                 (void *)&cmd_load_cmdfile_filename,
18038                 NULL,
18039         },
18040 };
18041
18042 /* Get Rx offloads capabilities */
18043 struct cmd_rx_offload_get_capa_result {
18044         cmdline_fixed_string_t show;
18045         cmdline_fixed_string_t port;
18046         portid_t port_id;
18047         cmdline_fixed_string_t rx_offload;
18048         cmdline_fixed_string_t capabilities;
18049 };
18050
18051 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18052         TOKEN_STRING_INITIALIZER
18053                 (struct cmd_rx_offload_get_capa_result,
18054                  show, "show");
18055 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18056         TOKEN_STRING_INITIALIZER
18057                 (struct cmd_rx_offload_get_capa_result,
18058                  port, "port");
18059 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18060         TOKEN_NUM_INITIALIZER
18061                 (struct cmd_rx_offload_get_capa_result,
18062                  port_id, UINT16);
18063 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18064         TOKEN_STRING_INITIALIZER
18065                 (struct cmd_rx_offload_get_capa_result,
18066                  rx_offload, "rx_offload");
18067 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18068         TOKEN_STRING_INITIALIZER
18069                 (struct cmd_rx_offload_get_capa_result,
18070                  capabilities, "capabilities");
18071
18072 static void
18073 print_rx_offloads(uint64_t offloads)
18074 {
18075         uint64_t single_offload;
18076         int begin;
18077         int end;
18078         int bit;
18079
18080         if (offloads == 0)
18081                 return;
18082
18083         begin = __builtin_ctzll(offloads);
18084         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18085
18086         single_offload = 1ULL << begin;
18087         for (bit = begin; bit < end; bit++) {
18088                 if (offloads & single_offload)
18089                         printf(" %s",
18090                                rte_eth_dev_rx_offload_name(single_offload));
18091                 single_offload <<= 1;
18092         }
18093 }
18094
18095 static void
18096 cmd_rx_offload_get_capa_parsed(
18097         void *parsed_result,
18098         __rte_unused struct cmdline *cl,
18099         __rte_unused void *data)
18100 {
18101         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18102         struct rte_eth_dev_info dev_info;
18103         portid_t port_id = res->port_id;
18104         uint64_t queue_offloads;
18105         uint64_t port_offloads;
18106         int ret;
18107
18108         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18109         if (ret != 0)
18110                 return;
18111
18112         queue_offloads = dev_info.rx_queue_offload_capa;
18113         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18114
18115         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18116         printf("  Per Queue :");
18117         print_rx_offloads(queue_offloads);
18118
18119         printf("\n");
18120         printf("  Per Port  :");
18121         print_rx_offloads(port_offloads);
18122         printf("\n\n");
18123 }
18124
18125 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18126         .f = cmd_rx_offload_get_capa_parsed,
18127         .data = NULL,
18128         .help_str = "show port <port_id> rx_offload capabilities",
18129         .tokens = {
18130                 (void *)&cmd_rx_offload_get_capa_show,
18131                 (void *)&cmd_rx_offload_get_capa_port,
18132                 (void *)&cmd_rx_offload_get_capa_port_id,
18133                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18134                 (void *)&cmd_rx_offload_get_capa_capabilities,
18135                 NULL,
18136         }
18137 };
18138
18139 /* Get Rx offloads configuration */
18140 struct cmd_rx_offload_get_configuration_result {
18141         cmdline_fixed_string_t show;
18142         cmdline_fixed_string_t port;
18143         portid_t port_id;
18144         cmdline_fixed_string_t rx_offload;
18145         cmdline_fixed_string_t configuration;
18146 };
18147
18148 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18149         TOKEN_STRING_INITIALIZER
18150                 (struct cmd_rx_offload_get_configuration_result,
18151                  show, "show");
18152 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18153         TOKEN_STRING_INITIALIZER
18154                 (struct cmd_rx_offload_get_configuration_result,
18155                  port, "port");
18156 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18157         TOKEN_NUM_INITIALIZER
18158                 (struct cmd_rx_offload_get_configuration_result,
18159                  port_id, UINT16);
18160 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18161         TOKEN_STRING_INITIALIZER
18162                 (struct cmd_rx_offload_get_configuration_result,
18163                  rx_offload, "rx_offload");
18164 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18165         TOKEN_STRING_INITIALIZER
18166                 (struct cmd_rx_offload_get_configuration_result,
18167                  configuration, "configuration");
18168
18169 static void
18170 cmd_rx_offload_get_configuration_parsed(
18171         void *parsed_result,
18172         __rte_unused struct cmdline *cl,
18173         __rte_unused void *data)
18174 {
18175         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18176         struct rte_eth_dev_info dev_info;
18177         portid_t port_id = res->port_id;
18178         struct rte_port *port = &ports[port_id];
18179         uint64_t port_offloads;
18180         uint64_t queue_offloads;
18181         uint16_t nb_rx_queues;
18182         int q;
18183         int ret;
18184
18185         printf("Rx Offloading Configuration of port %d :\n", port_id);
18186
18187         port_offloads = port->dev_conf.rxmode.offloads;
18188         printf("  Port :");
18189         print_rx_offloads(port_offloads);
18190         printf("\n");
18191
18192         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18193         if (ret != 0)
18194                 return;
18195
18196         nb_rx_queues = dev_info.nb_rx_queues;
18197         for (q = 0; q < nb_rx_queues; q++) {
18198                 queue_offloads = port->rx_conf[q].offloads;
18199                 printf("  Queue[%2d] :", q);
18200                 print_rx_offloads(queue_offloads);
18201                 printf("\n");
18202         }
18203         printf("\n");
18204 }
18205
18206 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18207         .f = cmd_rx_offload_get_configuration_parsed,
18208         .data = NULL,
18209         .help_str = "show port <port_id> rx_offload configuration",
18210         .tokens = {
18211                 (void *)&cmd_rx_offload_get_configuration_show,
18212                 (void *)&cmd_rx_offload_get_configuration_port,
18213                 (void *)&cmd_rx_offload_get_configuration_port_id,
18214                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18215                 (void *)&cmd_rx_offload_get_configuration_configuration,
18216                 NULL,
18217         }
18218 };
18219
18220 /* Enable/Disable a per port offloading */
18221 struct cmd_config_per_port_rx_offload_result {
18222         cmdline_fixed_string_t port;
18223         cmdline_fixed_string_t config;
18224         portid_t port_id;
18225         cmdline_fixed_string_t rx_offload;
18226         cmdline_fixed_string_t offload;
18227         cmdline_fixed_string_t on_off;
18228 };
18229
18230 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18231         TOKEN_STRING_INITIALIZER
18232                 (struct cmd_config_per_port_rx_offload_result,
18233                  port, "port");
18234 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18235         TOKEN_STRING_INITIALIZER
18236                 (struct cmd_config_per_port_rx_offload_result,
18237                  config, "config");
18238 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18239         TOKEN_NUM_INITIALIZER
18240                 (struct cmd_config_per_port_rx_offload_result,
18241                  port_id, UINT16);
18242 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18243         TOKEN_STRING_INITIALIZER
18244                 (struct cmd_config_per_port_rx_offload_result,
18245                  rx_offload, "rx_offload");
18246 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18247         TOKEN_STRING_INITIALIZER
18248                 (struct cmd_config_per_port_rx_offload_result,
18249                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18250                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18251                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18252                            "scatter#timestamp#security#keep_crc#rss_hash");
18253 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18254         TOKEN_STRING_INITIALIZER
18255                 (struct cmd_config_per_port_rx_offload_result,
18256                  on_off, "on#off");
18257
18258 static uint64_t
18259 search_rx_offload(const char *name)
18260 {
18261         uint64_t single_offload;
18262         const char *single_name;
18263         int found = 0;
18264         unsigned int bit;
18265
18266         single_offload = 1;
18267         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18268                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18269                 if (!strcasecmp(single_name, name)) {
18270                         found = 1;
18271                         break;
18272                 }
18273                 single_offload <<= 1;
18274         }
18275
18276         if (found)
18277                 return single_offload;
18278
18279         return 0;
18280 }
18281
18282 static void
18283 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18284                                 __rte_unused struct cmdline *cl,
18285                                 __rte_unused void *data)
18286 {
18287         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18288         portid_t port_id = res->port_id;
18289         struct rte_eth_dev_info dev_info;
18290         struct rte_port *port = &ports[port_id];
18291         uint64_t single_offload;
18292         uint16_t nb_rx_queues;
18293         int q;
18294         int ret;
18295
18296         if (port->port_status != RTE_PORT_STOPPED) {
18297                 printf("Error: Can't config offload when Port %d "
18298                        "is not stopped\n", port_id);
18299                 return;
18300         }
18301
18302         single_offload = search_rx_offload(res->offload);
18303         if (single_offload == 0) {
18304                 printf("Unknown offload name: %s\n", res->offload);
18305                 return;
18306         }
18307
18308         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18309         if (ret != 0)
18310                 return;
18311
18312         nb_rx_queues = dev_info.nb_rx_queues;
18313         if (!strcmp(res->on_off, "on")) {
18314                 port->dev_conf.rxmode.offloads |= single_offload;
18315                 for (q = 0; q < nb_rx_queues; q++)
18316                         port->rx_conf[q].offloads |= single_offload;
18317         } else {
18318                 port->dev_conf.rxmode.offloads &= ~single_offload;
18319                 for (q = 0; q < nb_rx_queues; q++)
18320                         port->rx_conf[q].offloads &= ~single_offload;
18321         }
18322
18323         cmd_reconfig_device_queue(port_id, 1, 1);
18324 }
18325
18326 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18327         .f = cmd_config_per_port_rx_offload_parsed,
18328         .data = NULL,
18329         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18330                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18331                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18332                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18333                     "on|off",
18334         .tokens = {
18335                 (void *)&cmd_config_per_port_rx_offload_result_port,
18336                 (void *)&cmd_config_per_port_rx_offload_result_config,
18337                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18338                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18339                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18340                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18341                 NULL,
18342         }
18343 };
18344
18345 /* Enable/Disable a per queue offloading */
18346 struct cmd_config_per_queue_rx_offload_result {
18347         cmdline_fixed_string_t port;
18348         portid_t port_id;
18349         cmdline_fixed_string_t rxq;
18350         uint16_t queue_id;
18351         cmdline_fixed_string_t rx_offload;
18352         cmdline_fixed_string_t offload;
18353         cmdline_fixed_string_t on_off;
18354 };
18355
18356 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18357         TOKEN_STRING_INITIALIZER
18358                 (struct cmd_config_per_queue_rx_offload_result,
18359                  port, "port");
18360 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18361         TOKEN_NUM_INITIALIZER
18362                 (struct cmd_config_per_queue_rx_offload_result,
18363                  port_id, UINT16);
18364 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18365         TOKEN_STRING_INITIALIZER
18366                 (struct cmd_config_per_queue_rx_offload_result,
18367                  rxq, "rxq");
18368 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18369         TOKEN_NUM_INITIALIZER
18370                 (struct cmd_config_per_queue_rx_offload_result,
18371                  queue_id, UINT16);
18372 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18373         TOKEN_STRING_INITIALIZER
18374                 (struct cmd_config_per_queue_rx_offload_result,
18375                  rx_offload, "rx_offload");
18376 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18377         TOKEN_STRING_INITIALIZER
18378                 (struct cmd_config_per_queue_rx_offload_result,
18379                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18380                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18381                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18382                            "scatter#timestamp#security#keep_crc");
18383 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18384         TOKEN_STRING_INITIALIZER
18385                 (struct cmd_config_per_queue_rx_offload_result,
18386                  on_off, "on#off");
18387
18388 static void
18389 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18390                                 __rte_unused struct cmdline *cl,
18391                                 __rte_unused void *data)
18392 {
18393         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18394         struct rte_eth_dev_info dev_info;
18395         portid_t port_id = res->port_id;
18396         uint16_t queue_id = res->queue_id;
18397         struct rte_port *port = &ports[port_id];
18398         uint64_t single_offload;
18399         int ret;
18400
18401         if (port->port_status != RTE_PORT_STOPPED) {
18402                 printf("Error: Can't config offload when Port %d "
18403                        "is not stopped\n", port_id);
18404                 return;
18405         }
18406
18407         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18408         if (ret != 0)
18409                 return;
18410
18411         if (queue_id >= dev_info.nb_rx_queues) {
18412                 printf("Error: input queue_id should be 0 ... "
18413                        "%d\n", dev_info.nb_rx_queues - 1);
18414                 return;
18415         }
18416
18417         single_offload = search_rx_offload(res->offload);
18418         if (single_offload == 0) {
18419                 printf("Unknown offload name: %s\n", res->offload);
18420                 return;
18421         }
18422
18423         if (!strcmp(res->on_off, "on"))
18424                 port->rx_conf[queue_id].offloads |= single_offload;
18425         else
18426                 port->rx_conf[queue_id].offloads &= ~single_offload;
18427
18428         cmd_reconfig_device_queue(port_id, 1, 1);
18429 }
18430
18431 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18432         .f = cmd_config_per_queue_rx_offload_parsed,
18433         .data = NULL,
18434         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18435                     "vlan_strip|ipv4_cksum|"
18436                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18437                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18438                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18439                     "on|off",
18440         .tokens = {
18441                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18442                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18443                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18444                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18445                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18446                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18447                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18448                 NULL,
18449         }
18450 };
18451
18452 /* Get Tx offloads capabilities */
18453 struct cmd_tx_offload_get_capa_result {
18454         cmdline_fixed_string_t show;
18455         cmdline_fixed_string_t port;
18456         portid_t port_id;
18457         cmdline_fixed_string_t tx_offload;
18458         cmdline_fixed_string_t capabilities;
18459 };
18460
18461 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18462         TOKEN_STRING_INITIALIZER
18463                 (struct cmd_tx_offload_get_capa_result,
18464                  show, "show");
18465 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18466         TOKEN_STRING_INITIALIZER
18467                 (struct cmd_tx_offload_get_capa_result,
18468                  port, "port");
18469 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18470         TOKEN_NUM_INITIALIZER
18471                 (struct cmd_tx_offload_get_capa_result,
18472                  port_id, UINT16);
18473 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18474         TOKEN_STRING_INITIALIZER
18475                 (struct cmd_tx_offload_get_capa_result,
18476                  tx_offload, "tx_offload");
18477 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18478         TOKEN_STRING_INITIALIZER
18479                 (struct cmd_tx_offload_get_capa_result,
18480                  capabilities, "capabilities");
18481
18482 static void
18483 print_tx_offloads(uint64_t offloads)
18484 {
18485         uint64_t single_offload;
18486         int begin;
18487         int end;
18488         int bit;
18489
18490         if (offloads == 0)
18491                 return;
18492
18493         begin = __builtin_ctzll(offloads);
18494         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18495
18496         single_offload = 1ULL << begin;
18497         for (bit = begin; bit < end; bit++) {
18498                 if (offloads & single_offload)
18499                         printf(" %s",
18500                                rte_eth_dev_tx_offload_name(single_offload));
18501                 single_offload <<= 1;
18502         }
18503 }
18504
18505 static void
18506 cmd_tx_offload_get_capa_parsed(
18507         void *parsed_result,
18508         __rte_unused struct cmdline *cl,
18509         __rte_unused void *data)
18510 {
18511         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18512         struct rte_eth_dev_info dev_info;
18513         portid_t port_id = res->port_id;
18514         uint64_t queue_offloads;
18515         uint64_t port_offloads;
18516         int ret;
18517
18518         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18519         if (ret != 0)
18520                 return;
18521
18522         queue_offloads = dev_info.tx_queue_offload_capa;
18523         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18524
18525         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18526         printf("  Per Queue :");
18527         print_tx_offloads(queue_offloads);
18528
18529         printf("\n");
18530         printf("  Per Port  :");
18531         print_tx_offloads(port_offloads);
18532         printf("\n\n");
18533 }
18534
18535 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18536         .f = cmd_tx_offload_get_capa_parsed,
18537         .data = NULL,
18538         .help_str = "show port <port_id> tx_offload capabilities",
18539         .tokens = {
18540                 (void *)&cmd_tx_offload_get_capa_show,
18541                 (void *)&cmd_tx_offload_get_capa_port,
18542                 (void *)&cmd_tx_offload_get_capa_port_id,
18543                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18544                 (void *)&cmd_tx_offload_get_capa_capabilities,
18545                 NULL,
18546         }
18547 };
18548
18549 /* Get Tx offloads configuration */
18550 struct cmd_tx_offload_get_configuration_result {
18551         cmdline_fixed_string_t show;
18552         cmdline_fixed_string_t port;
18553         portid_t port_id;
18554         cmdline_fixed_string_t tx_offload;
18555         cmdline_fixed_string_t configuration;
18556 };
18557
18558 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18559         TOKEN_STRING_INITIALIZER
18560                 (struct cmd_tx_offload_get_configuration_result,
18561                  show, "show");
18562 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18563         TOKEN_STRING_INITIALIZER
18564                 (struct cmd_tx_offload_get_configuration_result,
18565                  port, "port");
18566 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18567         TOKEN_NUM_INITIALIZER
18568                 (struct cmd_tx_offload_get_configuration_result,
18569                  port_id, UINT16);
18570 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18571         TOKEN_STRING_INITIALIZER
18572                 (struct cmd_tx_offload_get_configuration_result,
18573                  tx_offload, "tx_offload");
18574 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18575         TOKEN_STRING_INITIALIZER
18576                 (struct cmd_tx_offload_get_configuration_result,
18577                  configuration, "configuration");
18578
18579 static void
18580 cmd_tx_offload_get_configuration_parsed(
18581         void *parsed_result,
18582         __rte_unused struct cmdline *cl,
18583         __rte_unused void *data)
18584 {
18585         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18586         struct rte_eth_dev_info dev_info;
18587         portid_t port_id = res->port_id;
18588         struct rte_port *port = &ports[port_id];
18589         uint64_t port_offloads;
18590         uint64_t queue_offloads;
18591         uint16_t nb_tx_queues;
18592         int q;
18593         int ret;
18594
18595         printf("Tx Offloading Configuration of port %d :\n", port_id);
18596
18597         port_offloads = port->dev_conf.txmode.offloads;
18598         printf("  Port :");
18599         print_tx_offloads(port_offloads);
18600         printf("\n");
18601
18602         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18603         if (ret != 0)
18604                 return;
18605
18606         nb_tx_queues = dev_info.nb_tx_queues;
18607         for (q = 0; q < nb_tx_queues; q++) {
18608                 queue_offloads = port->tx_conf[q].offloads;
18609                 printf("  Queue[%2d] :", q);
18610                 print_tx_offloads(queue_offloads);
18611                 printf("\n");
18612         }
18613         printf("\n");
18614 }
18615
18616 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18617         .f = cmd_tx_offload_get_configuration_parsed,
18618         .data = NULL,
18619         .help_str = "show port <port_id> tx_offload configuration",
18620         .tokens = {
18621                 (void *)&cmd_tx_offload_get_configuration_show,
18622                 (void *)&cmd_tx_offload_get_configuration_port,
18623                 (void *)&cmd_tx_offload_get_configuration_port_id,
18624                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18625                 (void *)&cmd_tx_offload_get_configuration_configuration,
18626                 NULL,
18627         }
18628 };
18629
18630 /* Enable/Disable a per port offloading */
18631 struct cmd_config_per_port_tx_offload_result {
18632         cmdline_fixed_string_t port;
18633         cmdline_fixed_string_t config;
18634         portid_t port_id;
18635         cmdline_fixed_string_t tx_offload;
18636         cmdline_fixed_string_t offload;
18637         cmdline_fixed_string_t on_off;
18638 };
18639
18640 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18641         TOKEN_STRING_INITIALIZER
18642                 (struct cmd_config_per_port_tx_offload_result,
18643                  port, "port");
18644 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18645         TOKEN_STRING_INITIALIZER
18646                 (struct cmd_config_per_port_tx_offload_result,
18647                  config, "config");
18648 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18649         TOKEN_NUM_INITIALIZER
18650                 (struct cmd_config_per_port_tx_offload_result,
18651                  port_id, UINT16);
18652 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18653         TOKEN_STRING_INITIALIZER
18654                 (struct cmd_config_per_port_tx_offload_result,
18655                  tx_offload, "tx_offload");
18656 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18657         TOKEN_STRING_INITIALIZER
18658                 (struct cmd_config_per_port_tx_offload_result,
18659                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18660                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18661                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18662                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18663                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18664 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18665         TOKEN_STRING_INITIALIZER
18666                 (struct cmd_config_per_port_tx_offload_result,
18667                  on_off, "on#off");
18668
18669 static uint64_t
18670 search_tx_offload(const char *name)
18671 {
18672         uint64_t single_offload;
18673         const char *single_name;
18674         int found = 0;
18675         unsigned int bit;
18676
18677         single_offload = 1;
18678         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18679                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18680                 if (single_name == NULL)
18681                         break;
18682                 if (!strcasecmp(single_name, name)) {
18683                         found = 1;
18684                         break;
18685                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18686                         break;
18687                 single_offload <<= 1;
18688         }
18689
18690         if (found)
18691                 return single_offload;
18692
18693         return 0;
18694 }
18695
18696 static void
18697 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18698                                 __rte_unused struct cmdline *cl,
18699                                 __rte_unused void *data)
18700 {
18701         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18702         portid_t port_id = res->port_id;
18703         struct rte_eth_dev_info dev_info;
18704         struct rte_port *port = &ports[port_id];
18705         uint64_t single_offload;
18706         uint16_t nb_tx_queues;
18707         int q;
18708         int ret;
18709
18710         if (port->port_status != RTE_PORT_STOPPED) {
18711                 printf("Error: Can't config offload when Port %d "
18712                        "is not stopped\n", port_id);
18713                 return;
18714         }
18715
18716         single_offload = search_tx_offload(res->offload);
18717         if (single_offload == 0) {
18718                 printf("Unknown offload name: %s\n", res->offload);
18719                 return;
18720         }
18721
18722         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18723         if (ret != 0)
18724                 return;
18725
18726         nb_tx_queues = dev_info.nb_tx_queues;
18727         if (!strcmp(res->on_off, "on")) {
18728                 port->dev_conf.txmode.offloads |= single_offload;
18729                 for (q = 0; q < nb_tx_queues; q++)
18730                         port->tx_conf[q].offloads |= single_offload;
18731         } else {
18732                 port->dev_conf.txmode.offloads &= ~single_offload;
18733                 for (q = 0; q < nb_tx_queues; q++)
18734                         port->tx_conf[q].offloads &= ~single_offload;
18735         }
18736
18737         cmd_reconfig_device_queue(port_id, 1, 1);
18738 }
18739
18740 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18741         .f = cmd_config_per_port_tx_offload_parsed,
18742         .data = NULL,
18743         .help_str = "port config <port_id> tx_offload "
18744                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18745                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18746                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18747                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18748                     "mt_lockfree|multi_segs|mbuf_fast_free|security on|off",
18749         .tokens = {
18750                 (void *)&cmd_config_per_port_tx_offload_result_port,
18751                 (void *)&cmd_config_per_port_tx_offload_result_config,
18752                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18753                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18754                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18755                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18756                 NULL,
18757         }
18758 };
18759
18760 /* Enable/Disable a per queue offloading */
18761 struct cmd_config_per_queue_tx_offload_result {
18762         cmdline_fixed_string_t port;
18763         portid_t port_id;
18764         cmdline_fixed_string_t txq;
18765         uint16_t queue_id;
18766         cmdline_fixed_string_t tx_offload;
18767         cmdline_fixed_string_t offload;
18768         cmdline_fixed_string_t on_off;
18769 };
18770
18771 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18772         TOKEN_STRING_INITIALIZER
18773                 (struct cmd_config_per_queue_tx_offload_result,
18774                  port, "port");
18775 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18776         TOKEN_NUM_INITIALIZER
18777                 (struct cmd_config_per_queue_tx_offload_result,
18778                  port_id, UINT16);
18779 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18780         TOKEN_STRING_INITIALIZER
18781                 (struct cmd_config_per_queue_tx_offload_result,
18782                  txq, "txq");
18783 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18784         TOKEN_NUM_INITIALIZER
18785                 (struct cmd_config_per_queue_tx_offload_result,
18786                  queue_id, UINT16);
18787 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18788         TOKEN_STRING_INITIALIZER
18789                 (struct cmd_config_per_queue_tx_offload_result,
18790                  tx_offload, "tx_offload");
18791 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18792         TOKEN_STRING_INITIALIZER
18793                 (struct cmd_config_per_queue_tx_offload_result,
18794                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18795                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18796                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18797                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18798                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18799 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18800         TOKEN_STRING_INITIALIZER
18801                 (struct cmd_config_per_queue_tx_offload_result,
18802                  on_off, "on#off");
18803
18804 static void
18805 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18806                                 __rte_unused struct cmdline *cl,
18807                                 __rte_unused void *data)
18808 {
18809         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18810         struct rte_eth_dev_info dev_info;
18811         portid_t port_id = res->port_id;
18812         uint16_t queue_id = res->queue_id;
18813         struct rte_port *port = &ports[port_id];
18814         uint64_t single_offload;
18815         int ret;
18816
18817         if (port->port_status != RTE_PORT_STOPPED) {
18818                 printf("Error: Can't config offload when Port %d "
18819                        "is not stopped\n", port_id);
18820                 return;
18821         }
18822
18823         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18824         if (ret != 0)
18825                 return;
18826
18827         if (queue_id >= dev_info.nb_tx_queues) {
18828                 printf("Error: input queue_id should be 0 ... "
18829                        "%d\n", dev_info.nb_tx_queues - 1);
18830                 return;
18831         }
18832
18833         single_offload = search_tx_offload(res->offload);
18834         if (single_offload == 0) {
18835                 printf("Unknown offload name: %s\n", res->offload);
18836                 return;
18837         }
18838
18839         if (!strcmp(res->on_off, "on"))
18840                 port->tx_conf[queue_id].offloads |= single_offload;
18841         else
18842                 port->tx_conf[queue_id].offloads &= ~single_offload;
18843
18844         cmd_reconfig_device_queue(port_id, 1, 1);
18845 }
18846
18847 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18848         .f = cmd_config_per_queue_tx_offload_parsed,
18849         .data = NULL,
18850         .help_str = "port <port_id> txq <queue_id> tx_offload "
18851                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18852                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18853                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18854                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18855                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18856                     "on|off",
18857         .tokens = {
18858                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18859                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18860                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18861                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18862                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18863                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18864                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18865                 NULL,
18866         }
18867 };
18868
18869 /* *** configure tx_metadata for specific port *** */
18870 struct cmd_config_tx_metadata_specific_result {
18871         cmdline_fixed_string_t port;
18872         cmdline_fixed_string_t keyword;
18873         uint16_t port_id;
18874         cmdline_fixed_string_t item;
18875         uint32_t value;
18876 };
18877
18878 static void
18879 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18880                                 __rte_unused struct cmdline *cl,
18881                                 __rte_unused void *data)
18882 {
18883         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18884
18885         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18886                 return;
18887         ports[res->port_id].tx_metadata = res->value;
18888         /* Add/remove callback to insert valid metadata in every Tx packet. */
18889         if (ports[res->port_id].tx_metadata)
18890                 add_tx_md_callback(res->port_id);
18891         else
18892                 remove_tx_md_callback(res->port_id);
18893         rte_flow_dynf_metadata_register();
18894 }
18895
18896 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18897         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18898                         port, "port");
18899 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18900         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18901                         keyword, "config");
18902 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18903         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18904                         port_id, UINT16);
18905 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18906         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18907                         item, "tx_metadata");
18908 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18909         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18910                         value, UINT32);
18911
18912 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18913         .f = cmd_config_tx_metadata_specific_parsed,
18914         .data = NULL,
18915         .help_str = "port config <port_id> tx_metadata <value>",
18916         .tokens = {
18917                 (void *)&cmd_config_tx_metadata_specific_port,
18918                 (void *)&cmd_config_tx_metadata_specific_keyword,
18919                 (void *)&cmd_config_tx_metadata_specific_id,
18920                 (void *)&cmd_config_tx_metadata_specific_item,
18921                 (void *)&cmd_config_tx_metadata_specific_value,
18922                 NULL,
18923         },
18924 };
18925
18926 /* *** set dynf *** */
18927 struct cmd_config_tx_dynf_specific_result {
18928         cmdline_fixed_string_t port;
18929         cmdline_fixed_string_t keyword;
18930         uint16_t port_id;
18931         cmdline_fixed_string_t item;
18932         cmdline_fixed_string_t name;
18933         cmdline_fixed_string_t value;
18934 };
18935
18936 static void
18937 cmd_config_dynf_specific_parsed(void *parsed_result,
18938                                 __rte_unused struct cmdline *cl,
18939                                 __rte_unused void *data)
18940 {
18941         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18942         struct rte_mbuf_dynflag desc_flag;
18943         int flag;
18944         uint64_t old_port_flags;
18945
18946         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18947                 return;
18948         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18949         if (flag <= 0) {
18950                 if (strlcpy(desc_flag.name, res->name,
18951                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18952                         printf("Flag name too long\n");
18953                         return;
18954                 }
18955                 desc_flag.flags = 0;
18956                 flag = rte_mbuf_dynflag_register(&desc_flag);
18957                 if (flag < 0) {
18958                         printf("Can't register flag\n");
18959                         return;
18960                 }
18961                 strcpy(dynf_names[flag], desc_flag.name);
18962         }
18963         old_port_flags = ports[res->port_id].mbuf_dynf;
18964         if (!strcmp(res->value, "set")) {
18965                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
18966                 if (old_port_flags == 0)
18967                         add_tx_dynf_callback(res->port_id);
18968         } else {
18969                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18970                 if (ports[res->port_id].mbuf_dynf == 0)
18971                         remove_tx_dynf_callback(res->port_id);
18972         }
18973 }
18974
18975 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18976         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18977                         keyword, "port");
18978 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18979         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18980                         keyword, "config");
18981 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18982         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18983                         port_id, UINT16);
18984 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18985         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18986                         item, "dynf");
18987 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18988         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18989                         name, NULL);
18990 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
18991         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18992                         value, "set#clear");
18993
18994 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
18995         .f = cmd_config_dynf_specific_parsed,
18996         .data = NULL,
18997         .help_str = "port config <port id> dynf <name> set|clear",
18998         .tokens = {
18999                 (void *)&cmd_config_tx_dynf_specific_port,
19000                 (void *)&cmd_config_tx_dynf_specific_keyword,
19001                 (void *)&cmd_config_tx_dynf_specific_port_id,
19002                 (void *)&cmd_config_tx_dynf_specific_item,
19003                 (void *)&cmd_config_tx_dynf_specific_name,
19004                 (void *)&cmd_config_tx_dynf_specific_value,
19005                 NULL,
19006         },
19007 };
19008
19009 /* *** display tx_metadata per port configuration *** */
19010 struct cmd_show_tx_metadata_result {
19011         cmdline_fixed_string_t cmd_show;
19012         cmdline_fixed_string_t cmd_port;
19013         cmdline_fixed_string_t cmd_keyword;
19014         portid_t cmd_pid;
19015 };
19016
19017 static void
19018 cmd_show_tx_metadata_parsed(void *parsed_result,
19019                 __rte_unused struct cmdline *cl,
19020                 __rte_unused void *data)
19021 {
19022         struct cmd_show_tx_metadata_result *res = parsed_result;
19023
19024         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19025                 printf("invalid port id %u\n", res->cmd_pid);
19026                 return;
19027         }
19028         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19029                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19030                        ports[res->cmd_pid].tx_metadata);
19031         }
19032 }
19033
19034 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19035         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19036                         cmd_show, "show");
19037 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19038         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19039                         cmd_port, "port");
19040 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19041         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19042                         cmd_pid, UINT16);
19043 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19044         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19045                         cmd_keyword, "tx_metadata");
19046
19047 cmdline_parse_inst_t cmd_show_tx_metadata = {
19048         .f = cmd_show_tx_metadata_parsed,
19049         .data = NULL,
19050         .help_str = "show port <port_id> tx_metadata",
19051         .tokens = {
19052                 (void *)&cmd_show_tx_metadata_show,
19053                 (void *)&cmd_show_tx_metadata_port,
19054                 (void *)&cmd_show_tx_metadata_pid,
19055                 (void *)&cmd_show_tx_metadata_keyword,
19056                 NULL,
19057         },
19058 };
19059
19060 /* show port supported ptypes */
19061
19062 /* Common result structure for show port ptypes */
19063 struct cmd_show_port_supported_ptypes_result {
19064         cmdline_fixed_string_t show;
19065         cmdline_fixed_string_t port;
19066         portid_t port_id;
19067         cmdline_fixed_string_t ptypes;
19068 };
19069
19070 /* Common CLI fields for show port ptypes */
19071 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19072         TOKEN_STRING_INITIALIZER
19073                 (struct cmd_show_port_supported_ptypes_result,
19074                  show, "show");
19075 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19076         TOKEN_STRING_INITIALIZER
19077                 (struct cmd_show_port_supported_ptypes_result,
19078                  port, "port");
19079 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19080         TOKEN_NUM_INITIALIZER
19081                 (struct cmd_show_port_supported_ptypes_result,
19082                  port_id, UINT16);
19083 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19084         TOKEN_STRING_INITIALIZER
19085                 (struct cmd_show_port_supported_ptypes_result,
19086                  ptypes, "ptypes");
19087
19088 static void
19089 cmd_show_port_supported_ptypes_parsed(
19090         void *parsed_result,
19091         __rte_unused struct cmdline *cl,
19092         __rte_unused void *data)
19093 {
19094 #define RSVD_PTYPE_MASK       0xf0000000
19095 #define MAX_PTYPES_PER_LAYER  16
19096 #define LTYPE_NAMESIZE        32
19097 #define PTYPE_NAMESIZE        256
19098         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19099         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19100         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19101         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19102         uint16_t port_id = res->port_id;
19103         int ret, i;
19104
19105         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19106         if (ret < 0)
19107                 return;
19108
19109         while (ptype_mask != RSVD_PTYPE_MASK) {
19110
19111                 switch (ptype_mask) {
19112                 case RTE_PTYPE_L2_MASK:
19113                         strlcpy(ltype, "L2", sizeof(ltype));
19114                         break;
19115                 case RTE_PTYPE_L3_MASK:
19116                         strlcpy(ltype, "L3", sizeof(ltype));
19117                         break;
19118                 case RTE_PTYPE_L4_MASK:
19119                         strlcpy(ltype, "L4", sizeof(ltype));
19120                         break;
19121                 case RTE_PTYPE_TUNNEL_MASK:
19122                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19123                         break;
19124                 case RTE_PTYPE_INNER_L2_MASK:
19125                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19126                         break;
19127                 case RTE_PTYPE_INNER_L3_MASK:
19128                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19129                         break;
19130                 case RTE_PTYPE_INNER_L4_MASK:
19131                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19132                         break;
19133                 default:
19134                         return;
19135                 }
19136
19137                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19138                                                        ptype_mask, ptypes,
19139                                                        MAX_PTYPES_PER_LAYER);
19140
19141                 if (ret > 0)
19142                         printf("Supported %s ptypes:\n", ltype);
19143                 else
19144                         printf("%s ptypes unsupported\n", ltype);
19145
19146                 for (i = 0; i < ret; ++i) {
19147                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19148                         printf("%s\n", buf);
19149                 }
19150
19151                 ptype_mask <<= 4;
19152         }
19153 }
19154
19155 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19156         .f = cmd_show_port_supported_ptypes_parsed,
19157         .data = NULL,
19158         .help_str = "show port <port_id> ptypes",
19159         .tokens = {
19160                 (void *)&cmd_show_port_supported_ptypes_show,
19161                 (void *)&cmd_show_port_supported_ptypes_port,
19162                 (void *)&cmd_show_port_supported_ptypes_port_id,
19163                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19164                 NULL,
19165         },
19166 };
19167
19168 /* *** display rx/tx descriptor status *** */
19169 struct cmd_show_rx_tx_desc_status_result {
19170         cmdline_fixed_string_t cmd_show;
19171         cmdline_fixed_string_t cmd_port;
19172         cmdline_fixed_string_t cmd_keyword;
19173         cmdline_fixed_string_t cmd_desc;
19174         cmdline_fixed_string_t cmd_status;
19175         portid_t cmd_pid;
19176         portid_t cmd_qid;
19177         portid_t cmd_did;
19178 };
19179
19180 static void
19181 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19182                 __rte_unused struct cmdline *cl,
19183                 __rte_unused void *data)
19184 {
19185         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19186         int rc;
19187
19188         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19189                 printf("invalid port id %u\n", res->cmd_pid);
19190                 return;
19191         }
19192
19193         if (!strcmp(res->cmd_keyword, "rxq")) {
19194                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19195                                              res->cmd_did);
19196                 if (rc < 0) {
19197                         printf("Invalid queueid = %d\n", res->cmd_qid);
19198                         return;
19199                 }
19200                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19201                         printf("Desc status = AVAILABLE\n");
19202                 else if (rc == RTE_ETH_RX_DESC_DONE)
19203                         printf("Desc status = DONE\n");
19204                 else
19205                         printf("Desc status = UNAVAILABLE\n");
19206         } else if (!strcmp(res->cmd_keyword, "txq")) {
19207                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19208                                              res->cmd_did);
19209                 if (rc < 0) {
19210                         printf("Invalid queueid = %d\n", res->cmd_qid);
19211                         return;
19212                 }
19213                 if (rc == RTE_ETH_TX_DESC_FULL)
19214                         printf("Desc status = FULL\n");
19215                 else if (rc == RTE_ETH_TX_DESC_DONE)
19216                         printf("Desc status = DONE\n");
19217                 else
19218                         printf("Desc status = UNAVAILABLE\n");
19219         }
19220 }
19221
19222 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19223         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19224                         cmd_show, "show");
19225 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19226         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19227                         cmd_port, "port");
19228 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19229         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19230                         cmd_pid, UINT16);
19231 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19232         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19233                         cmd_keyword, "rxq#txq");
19234 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19235         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19236                         cmd_qid, UINT16);
19237 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19238         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19239                         cmd_desc, "desc");
19240 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19241         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19242                         cmd_did, UINT16);
19243 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19244         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19245                         cmd_status, "status");
19246 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19247         .f = cmd_show_rx_tx_desc_status_parsed,
19248         .data = NULL,
19249         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19250                 "status",
19251         .tokens = {
19252                 (void *)&cmd_show_rx_tx_desc_status_show,
19253                 (void *)&cmd_show_rx_tx_desc_status_port,
19254                 (void *)&cmd_show_rx_tx_desc_status_pid,
19255                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19256                 (void *)&cmd_show_rx_tx_desc_status_qid,
19257                 (void *)&cmd_show_rx_tx_desc_status_desc,
19258                 (void *)&cmd_show_rx_tx_desc_status_did,
19259                 (void *)&cmd_show_rx_tx_desc_status_status,
19260                 NULL,
19261         },
19262 };
19263
19264 /* Common result structure for set port ptypes */
19265 struct cmd_set_port_ptypes_result {
19266         cmdline_fixed_string_t set;
19267         cmdline_fixed_string_t port;
19268         portid_t port_id;
19269         cmdline_fixed_string_t ptype_mask;
19270         uint32_t mask;
19271 };
19272
19273 /* Common CLI fields for set port ptypes */
19274 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19275         TOKEN_STRING_INITIALIZER
19276                 (struct cmd_set_port_ptypes_result,
19277                  set, "set");
19278 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19279         TOKEN_STRING_INITIALIZER
19280                 (struct cmd_set_port_ptypes_result,
19281                  port, "port");
19282 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19283         TOKEN_NUM_INITIALIZER
19284                 (struct cmd_set_port_ptypes_result,
19285                  port_id, UINT16);
19286 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19287         TOKEN_STRING_INITIALIZER
19288                 (struct cmd_set_port_ptypes_result,
19289                  ptype_mask, "ptype_mask");
19290 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19291         TOKEN_NUM_INITIALIZER
19292                 (struct cmd_set_port_ptypes_result,
19293                  mask, UINT32);
19294
19295 static void
19296 cmd_set_port_ptypes_parsed(
19297         void *parsed_result,
19298         __rte_unused struct cmdline *cl,
19299         __rte_unused void *data)
19300 {
19301         struct cmd_set_port_ptypes_result *res = parsed_result;
19302 #define PTYPE_NAMESIZE        256
19303         char ptype_name[PTYPE_NAMESIZE];
19304         uint16_t port_id = res->port_id;
19305         uint32_t ptype_mask = res->mask;
19306         int ret, i;
19307
19308         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19309                                                NULL, 0);
19310         if (ret <= 0) {
19311                 printf("Port %d doesn't support any ptypes.\n", port_id);
19312                 return;
19313         }
19314
19315         uint32_t ptypes[ret];
19316
19317         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19318         if (ret < 0) {
19319                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19320                 return;
19321         }
19322
19323         printf("Successfully set following ptypes for Port %d\n", port_id);
19324         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19325                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19326                 printf("%s\n", ptype_name);
19327         }
19328
19329         clear_ptypes = false;
19330 }
19331
19332 cmdline_parse_inst_t cmd_set_port_ptypes = {
19333         .f = cmd_set_port_ptypes_parsed,
19334         .data = NULL,
19335         .help_str = "set port <port_id> ptype_mask <mask>",
19336         .tokens = {
19337                 (void *)&cmd_set_port_ptypes_set,
19338                 (void *)&cmd_set_port_ptypes_port,
19339                 (void *)&cmd_set_port_ptypes_port_id,
19340                 (void *)&cmd_set_port_ptypes_mask_str,
19341                 (void *)&cmd_set_port_ptypes_mask_u32,
19342                 NULL,
19343         },
19344 };
19345
19346 /* *** display mac addresses added to a port *** */
19347 struct cmd_showport_macs_result {
19348         cmdline_fixed_string_t cmd_show;
19349         cmdline_fixed_string_t cmd_port;
19350         cmdline_fixed_string_t cmd_keyword;
19351         portid_t cmd_pid;
19352 };
19353
19354 static void
19355 cmd_showport_macs_parsed(void *parsed_result,
19356                 __rte_unused struct cmdline *cl,
19357                 __rte_unused void *data)
19358 {
19359         struct cmd_showport_macs_result *res = parsed_result;
19360
19361         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19362                 return;
19363
19364         if (!strcmp(res->cmd_keyword, "macs"))
19365                 show_macs(res->cmd_pid);
19366         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19367                 show_mcast_macs(res->cmd_pid);
19368 }
19369
19370 cmdline_parse_token_string_t cmd_showport_macs_show =
19371         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19372                         cmd_show, "show");
19373 cmdline_parse_token_string_t cmd_showport_macs_port =
19374         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19375                         cmd_port, "port");
19376 cmdline_parse_token_num_t cmd_showport_macs_pid =
19377         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19378                         cmd_pid, UINT16);
19379 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19380         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19381                         cmd_keyword, "macs#mcast_macs");
19382
19383 cmdline_parse_inst_t cmd_showport_macs = {
19384         .f = cmd_showport_macs_parsed,
19385         .data = NULL,
19386         .help_str = "show port <port_id> macs|mcast_macs",
19387         .tokens = {
19388                 (void *)&cmd_showport_macs_show,
19389                 (void *)&cmd_showport_macs_port,
19390                 (void *)&cmd_showport_macs_pid,
19391                 (void *)&cmd_showport_macs_keyword,
19392                 NULL,
19393         },
19394 };
19395
19396 /* ******************************************************************************** */
19397
19398 /* list of instructions */
19399 cmdline_parse_ctx_t main_ctx[] = {
19400         (cmdline_parse_inst_t *)&cmd_help_brief,
19401         (cmdline_parse_inst_t *)&cmd_help_long,
19402         (cmdline_parse_inst_t *)&cmd_quit,
19403         (cmdline_parse_inst_t *)&cmd_load_from_file,
19404         (cmdline_parse_inst_t *)&cmd_showport,
19405         (cmdline_parse_inst_t *)&cmd_showqueue,
19406         (cmdline_parse_inst_t *)&cmd_showportall,
19407         (cmdline_parse_inst_t *)&cmd_showdevice,
19408         (cmdline_parse_inst_t *)&cmd_showcfg,
19409         (cmdline_parse_inst_t *)&cmd_showfwdall,
19410         (cmdline_parse_inst_t *)&cmd_start,
19411         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19412         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19413         (cmdline_parse_inst_t *)&cmd_set_link_up,
19414         (cmdline_parse_inst_t *)&cmd_set_link_down,
19415         (cmdline_parse_inst_t *)&cmd_reset,
19416         (cmdline_parse_inst_t *)&cmd_set_numbers,
19417         (cmdline_parse_inst_t *)&cmd_set_log,
19418         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19419         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19420         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19421         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19422         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19423         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19424         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19425         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19426         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19427         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19428         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19429         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19430         (cmdline_parse_inst_t *)&cmd_set_link_check,
19431         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19432         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19433         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19434         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19435 #ifdef RTE_LIBRTE_PMD_BOND
19436         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19437         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19438         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19439         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19440         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19441         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19442         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19443         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19444         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19445         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19446         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19447 #endif
19448         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19449         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19450         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19451         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19452         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19453         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19454         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19455         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19456         (cmdline_parse_inst_t *)&cmd_csum_set,
19457         (cmdline_parse_inst_t *)&cmd_csum_show,
19458         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19459         (cmdline_parse_inst_t *)&cmd_tso_set,
19460         (cmdline_parse_inst_t *)&cmd_tso_show,
19461         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19462         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19463         (cmdline_parse_inst_t *)&cmd_gro_enable,
19464         (cmdline_parse_inst_t *)&cmd_gro_flush,
19465         (cmdline_parse_inst_t *)&cmd_gro_show,
19466         (cmdline_parse_inst_t *)&cmd_gso_enable,
19467         (cmdline_parse_inst_t *)&cmd_gso_size,
19468         (cmdline_parse_inst_t *)&cmd_gso_show,
19469         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19470         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19471         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19472         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19473         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19474         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19475         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19476         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19477         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19478         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19479         (cmdline_parse_inst_t *)&cmd_config_dcb,
19480         (cmdline_parse_inst_t *)&cmd_read_reg,
19481         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19482         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19483         (cmdline_parse_inst_t *)&cmd_write_reg,
19484         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19485         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19486         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19487         (cmdline_parse_inst_t *)&cmd_stop,
19488         (cmdline_parse_inst_t *)&cmd_mac_addr,
19489         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19490         (cmdline_parse_inst_t *)&cmd_set_qmap,
19491         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19492         (cmdline_parse_inst_t *)&cmd_operate_port,
19493         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19494         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19495         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19496         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19497         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19498         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19499         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19500         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19501         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19502         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19503         (cmdline_parse_inst_t *)&cmd_config_mtu,
19504         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19505         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19506         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19507         (cmdline_parse_inst_t *)&cmd_config_rss,
19508         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19509         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19510         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19511         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19512         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19513         (cmdline_parse_inst_t *)&cmd_showport_reta,
19514         (cmdline_parse_inst_t *)&cmd_showport_macs,
19515         (cmdline_parse_inst_t *)&cmd_config_burst,
19516         (cmdline_parse_inst_t *)&cmd_config_thresh,
19517         (cmdline_parse_inst_t *)&cmd_config_threshold,
19518         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19519         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19520         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19521         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19522         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19523         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19524         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19525         (cmdline_parse_inst_t *)&cmd_global_config,
19526         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19527         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19528         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19529         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19530         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19531         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19532         (cmdline_parse_inst_t *)&cmd_dump,
19533         (cmdline_parse_inst_t *)&cmd_dump_one,
19534         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19535         (cmdline_parse_inst_t *)&cmd_syn_filter,
19536         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19537         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19538         (cmdline_parse_inst_t *)&cmd_flex_filter,
19539         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19540         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19541         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19542         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19543         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19544         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19545         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19546         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19547         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19548         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19549         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19550         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19551         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19552         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19553         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19554         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19555         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19556         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19557         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19558         (cmdline_parse_inst_t *)&cmd_flow,
19559         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19560         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19561         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19562         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19563         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19564         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19565         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19566         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19567         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19568         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19569         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19570         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19571         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19572         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19573         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19574         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19575         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19576         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19577         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19578         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19579         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19580         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19581         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19582         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19583         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19584         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19585         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19586         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19587         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19588         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19589         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19590         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19591         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19592         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19593         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19594         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19595         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19596         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19597         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19598         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19599         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19600         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19601         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19602         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19603         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19604         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19605         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19606         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19607         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19608 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19609         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19610 #endif
19611         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19612         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19613         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19614         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19615         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19616         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19617         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19618         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19619         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19620         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19621         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19622         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19623         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19624         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19625         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19626         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19627         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19628         (cmdline_parse_inst_t *)&cmd_ddp_add,
19629         (cmdline_parse_inst_t *)&cmd_ddp_del,
19630         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19631         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19632         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19633         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19634         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19635         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19636         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19637         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19638         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19639         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19640         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19641         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19642
19643         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19644         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19645         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19646         (cmdline_parse_inst_t *)&cmd_queue_region,
19647         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19648         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19649         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19650         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19651         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19652         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19653         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19654         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19655         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19656         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19657         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19658         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19659         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19660         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19661         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19662         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19663         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19664         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19665         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19666         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19667         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19668         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19669         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19670         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19671         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19672         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19673         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19674         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19675         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19676         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19677         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19678         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19679         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19680         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19681         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19682 #ifdef RTE_LIBRTE_BPF
19683         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19684         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19685 #endif
19686         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19687         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19688         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19689         (cmdline_parse_inst_t *)&cmd_set_raw,
19690         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19691         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19692         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19693         NULL,
19694 };
19695
19696 /* read cmdline commands from file */
19697 void
19698 cmdline_read_from_file(const char *filename)
19699 {
19700         struct cmdline *cl;
19701
19702         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19703         if (cl == NULL) {
19704                 printf("Failed to create file based cmdline context: %s\n",
19705                        filename);
19706                 return;
19707         }
19708
19709         cmdline_interact(cl);
19710         cmdline_quit(cl);
19711
19712         cmdline_free(cl);
19713
19714         printf("Read CLI commands from %s\n", filename);
19715 }
19716
19717 /* prompt function, called from main on MASTER lcore */
19718 void
19719 prompt(void)
19720 {
19721         /* initialize non-constant commands */
19722         cmd_set_fwd_mode_init();
19723         cmd_set_fwd_retry_mode_init();
19724
19725         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19726         if (testpmd_cl == NULL)
19727                 return;
19728         cmdline_interact(testpmd_cl);
19729         cmdline_stdin_exit(testpmd_cl);
19730 }
19731
19732 void
19733 prompt_exit(void)
19734 {
19735         if (testpmd_cl != NULL)
19736                 cmdline_quit(testpmd_cl);
19737 }
19738
19739 static void
19740 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19741 {
19742         if (id == (portid_t)RTE_PORT_ALL) {
19743                 portid_t pid;
19744
19745                 RTE_ETH_FOREACH_DEV(pid) {
19746                         /* check if need_reconfig has been set to 1 */
19747                         if (ports[pid].need_reconfig == 0)
19748                                 ports[pid].need_reconfig = dev;
19749                         /* check if need_reconfig_queues has been set to 1 */
19750                         if (ports[pid].need_reconfig_queues == 0)
19751                                 ports[pid].need_reconfig_queues = queue;
19752                 }
19753         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19754                 /* check if need_reconfig has been set to 1 */
19755                 if (ports[id].need_reconfig == 0)
19756                         ports[id].need_reconfig = dev;
19757                 /* check if need_reconfig_queues has been set to 1 */
19758                 if (ports[id].need_reconfig_queues == 0)
19759                         ports[id].need_reconfig_queues = queue;
19760         }
19761 }