a36c505c598e1d058240b05ce85db8298a220bdf
[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 commmands.\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|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                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1129                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1130                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1131                         "       Configure the VXLAN encapsulation for flows.\n\n"
1132
1133                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1134                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1135                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1136                         " eth-dst (eth-dst)\n"
1137                         "       Configure the VXLAN encapsulation for flows.\n\n"
1138
1139                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1140                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1141                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1142                         " eth-dst (eth-dst)\n"
1143                         "       Configure the VXLAN encapsulation for flows.\n\n"
1144
1145                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1146                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1147                         " (eth-dst)\n"
1148                         "       Configure the NVGRE encapsulation for flows.\n\n"
1149
1150                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1151                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1152                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1153                         "       Configure the NVGRE encapsulation for flows.\n\n"
1154
1155                         "set raw_encap {flow items}\n"
1156                         "       Configure the encapsulation with raw data.\n\n"
1157
1158                         "set raw_decap {flow items}\n"
1159                         "       Configure the decapsulation with raw data.\n\n"
1160
1161                 );
1162         }
1163
1164         if (show_all || !strcmp(res->section, "traffic_management")) {
1165                 cmdline_printf(
1166                         cl,
1167                         "\n"
1168                         "Traffic Management:\n"
1169                         "--------------\n"
1170                         "show port tm cap (port_id)\n"
1171                         "       Display the port TM capability.\n\n"
1172
1173                         "show port tm level cap (port_id) (level_id)\n"
1174                         "       Display the port TM hierarchical level capability.\n\n"
1175
1176                         "show port tm node cap (port_id) (node_id)\n"
1177                         "       Display the port TM node capability.\n\n"
1178
1179                         "show port tm node type (port_id) (node_id)\n"
1180                         "       Display the port TM node type.\n\n"
1181
1182                         "show port tm node stats (port_id) (node_id) (clear)\n"
1183                         "       Display the port TM node stats.\n\n"
1184
1185 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1186                         "set port tm hierarchy default (port_id)\n"
1187                         "       Set default traffic Management hierarchy on a port\n\n"
1188 #endif
1189
1190                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1191                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1192                         " (packet_length_adjust)\n"
1193                         "       Add port tm node private shaper profile.\n\n"
1194
1195                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1196                         "       Delete port tm node private shaper profile.\n\n"
1197
1198                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1199                         " (shaper_profile_id)\n"
1200                         "       Add/update port tm node shared shaper.\n\n"
1201
1202                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1203                         "       Delete port tm node shared shaper.\n\n"
1204
1205                         "set port tm node shaper profile (port_id) (node_id)"
1206                         " (shaper_profile_id)\n"
1207                         "       Set port tm node shaper profile.\n\n"
1208
1209                         "add port tm node wred profile (port_id) (wred_profile_id)"
1210                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1211                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1212                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1213                         "       Add port tm node wred profile.\n\n"
1214
1215                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1216                         "       Delete port tm node wred profile.\n\n"
1217
1218                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1219                         " (priority) (weight) (level_id) (shaper_profile_id)"
1220                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1221                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1222                         "       Add port tm nonleaf node.\n\n"
1223
1224                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1225                         " (priority) (weight) (level_id) (shaper_profile_id)"
1226                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1227                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1228                         "       Add port tm leaf node.\n\n"
1229
1230                         "del port tm node (port_id) (node_id)\n"
1231                         "       Delete port tm node.\n\n"
1232
1233                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1234                         " (priority) (weight)\n"
1235                         "       Set port tm node parent.\n\n"
1236
1237                         "suspend port tm node (port_id) (node_id)"
1238                         "       Suspend tm node.\n\n"
1239
1240                         "resume port tm node (port_id) (node_id)"
1241                         "       Resume tm node.\n\n"
1242
1243                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1244                         "       Commit tm hierarchy.\n\n"
1245
1246                         "set port tm mark ip_ecn (port) (green) (yellow)"
1247                         " (red)\n"
1248                         "    Enables/Disables the traffic management marking"
1249                         " for IP ECN (Explicit Congestion Notification)"
1250                         " packets on a given port\n\n"
1251
1252                         "set port tm mark ip_dscp (port) (green) (yellow)"
1253                         " (red)\n"
1254                         "    Enables/Disables the traffic management marking"
1255                         " on the port for IP dscp packets\n\n"
1256
1257                         "set port tm mark vlan_dei (port) (green) (yellow)"
1258                         " (red)\n"
1259                         "    Enables/Disables the traffic management marking"
1260                         " on the port for VLAN packets with DEI enabled\n\n"
1261                 );
1262         }
1263
1264         if (show_all || !strcmp(res->section, "devices")) {
1265                 cmdline_printf(
1266                         cl,
1267                         "\n"
1268                         "Device Operations:\n"
1269                         "--------------\n"
1270                         "device detach (identifier)\n"
1271                         "       Detach device by identifier.\n\n"
1272                 );
1273         }
1274
1275 }
1276
1277 cmdline_parse_token_string_t cmd_help_long_help =
1278         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1279
1280 cmdline_parse_token_string_t cmd_help_long_section =
1281         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1282                         "all#control#display#config#"
1283                         "ports#registers#filters#traffic_management#devices");
1284
1285 cmdline_parse_inst_t cmd_help_long = {
1286         .f = cmd_help_long_parsed,
1287         .data = NULL,
1288         .help_str = "help all|control|display|config|ports|register|"
1289                 "filters|traffic_management|devices: "
1290                 "Show help",
1291         .tokens = {
1292                 (void *)&cmd_help_long_help,
1293                 (void *)&cmd_help_long_section,
1294                 NULL,
1295         },
1296 };
1297
1298
1299 /* *** start/stop/close all ports *** */
1300 struct cmd_operate_port_result {
1301         cmdline_fixed_string_t keyword;
1302         cmdline_fixed_string_t name;
1303         cmdline_fixed_string_t value;
1304 };
1305
1306 static void cmd_operate_port_parsed(void *parsed_result,
1307                                 __rte_unused struct cmdline *cl,
1308                                 __rte_unused void *data)
1309 {
1310         struct cmd_operate_port_result *res = parsed_result;
1311
1312         if (!strcmp(res->name, "start"))
1313                 start_port(RTE_PORT_ALL);
1314         else if (!strcmp(res->name, "stop"))
1315                 stop_port(RTE_PORT_ALL);
1316         else if (!strcmp(res->name, "close"))
1317                 close_port(RTE_PORT_ALL);
1318         else if (!strcmp(res->name, "reset"))
1319                 reset_port(RTE_PORT_ALL);
1320         else
1321                 printf("Unknown parameter\n");
1322 }
1323
1324 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1325         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1326                                                                 "port");
1327 cmdline_parse_token_string_t cmd_operate_port_all_port =
1328         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1329                                                 "start#stop#close#reset");
1330 cmdline_parse_token_string_t cmd_operate_port_all_all =
1331         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1332
1333 cmdline_parse_inst_t cmd_operate_port = {
1334         .f = cmd_operate_port_parsed,
1335         .data = NULL,
1336         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1337         .tokens = {
1338                 (void *)&cmd_operate_port_all_cmd,
1339                 (void *)&cmd_operate_port_all_port,
1340                 (void *)&cmd_operate_port_all_all,
1341                 NULL,
1342         },
1343 };
1344
1345 /* *** start/stop/close specific port *** */
1346 struct cmd_operate_specific_port_result {
1347         cmdline_fixed_string_t keyword;
1348         cmdline_fixed_string_t name;
1349         uint8_t value;
1350 };
1351
1352 static void cmd_operate_specific_port_parsed(void *parsed_result,
1353                         __rte_unused struct cmdline *cl,
1354                                 __rte_unused void *data)
1355 {
1356         struct cmd_operate_specific_port_result *res = parsed_result;
1357
1358         if (!strcmp(res->name, "start"))
1359                 start_port(res->value);
1360         else if (!strcmp(res->name, "stop"))
1361                 stop_port(res->value);
1362         else if (!strcmp(res->name, "close"))
1363                 close_port(res->value);
1364         else if (!strcmp(res->name, "reset"))
1365                 reset_port(res->value);
1366         else
1367                 printf("Unknown parameter\n");
1368 }
1369
1370 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1371         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1372                                                         keyword, "port");
1373 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1374         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1375                                                 name, "start#stop#close#reset");
1376 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1377         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1378                                                         value, UINT8);
1379
1380 cmdline_parse_inst_t cmd_operate_specific_port = {
1381         .f = cmd_operate_specific_port_parsed,
1382         .data = NULL,
1383         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1384         .tokens = {
1385                 (void *)&cmd_operate_specific_port_cmd,
1386                 (void *)&cmd_operate_specific_port_port,
1387                 (void *)&cmd_operate_specific_port_id,
1388                 NULL,
1389         },
1390 };
1391
1392 /* *** enable port setup (after attach) via iterator or event *** */
1393 struct cmd_set_port_setup_on_result {
1394         cmdline_fixed_string_t set;
1395         cmdline_fixed_string_t port;
1396         cmdline_fixed_string_t setup;
1397         cmdline_fixed_string_t on;
1398         cmdline_fixed_string_t mode;
1399 };
1400
1401 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1402                                 __rte_unused struct cmdline *cl,
1403                                 __rte_unused void *data)
1404 {
1405         struct cmd_set_port_setup_on_result *res = parsed_result;
1406
1407         if (strcmp(res->mode, "event") == 0)
1408                 setup_on_probe_event = true;
1409         else if (strcmp(res->mode, "iterator") == 0)
1410                 setup_on_probe_event = false;
1411         else
1412                 printf("Unknown mode\n");
1413 }
1414
1415 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1416         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1417                         set, "set");
1418 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1419         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1420                         port, "port");
1421 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1422         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1423                         setup, "setup");
1424 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1425         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1426                         on, "on");
1427 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1428         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1429                         mode, "iterator#event");
1430
1431 cmdline_parse_inst_t cmd_set_port_setup_on = {
1432         .f = cmd_set_port_setup_on_parsed,
1433         .data = NULL,
1434         .help_str = "set port setup on iterator|event",
1435         .tokens = {
1436                 (void *)&cmd_set_port_setup_on_set,
1437                 (void *)&cmd_set_port_setup_on_port,
1438                 (void *)&cmd_set_port_setup_on_setup,
1439                 (void *)&cmd_set_port_setup_on_on,
1440                 (void *)&cmd_set_port_setup_on_mode,
1441                 NULL,
1442         },
1443 };
1444
1445 /* *** attach a specified port *** */
1446 struct cmd_operate_attach_port_result {
1447         cmdline_fixed_string_t port;
1448         cmdline_fixed_string_t keyword;
1449         cmdline_multi_string_t identifier;
1450 };
1451
1452 static void cmd_operate_attach_port_parsed(void *parsed_result,
1453                                 __rte_unused struct cmdline *cl,
1454                                 __rte_unused void *data)
1455 {
1456         struct cmd_operate_attach_port_result *res = parsed_result;
1457
1458         if (!strcmp(res->keyword, "attach"))
1459                 attach_port(res->identifier);
1460         else
1461                 printf("Unknown parameter\n");
1462 }
1463
1464 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1465         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1466                         port, "port");
1467 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1468         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1469                         keyword, "attach");
1470 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1471         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1472                         identifier, TOKEN_STRING_MULTI);
1473
1474 cmdline_parse_inst_t cmd_operate_attach_port = {
1475         .f = cmd_operate_attach_port_parsed,
1476         .data = NULL,
1477         .help_str = "port attach <identifier>: "
1478                 "(identifier: pci address or virtual dev name)",
1479         .tokens = {
1480                 (void *)&cmd_operate_attach_port_port,
1481                 (void *)&cmd_operate_attach_port_keyword,
1482                 (void *)&cmd_operate_attach_port_identifier,
1483                 NULL,
1484         },
1485 };
1486
1487 /* *** detach a specified port *** */
1488 struct cmd_operate_detach_port_result {
1489         cmdline_fixed_string_t port;
1490         cmdline_fixed_string_t keyword;
1491         portid_t port_id;
1492 };
1493
1494 static void cmd_operate_detach_port_parsed(void *parsed_result,
1495                                 __rte_unused struct cmdline *cl,
1496                                 __rte_unused void *data)
1497 {
1498         struct cmd_operate_detach_port_result *res = parsed_result;
1499
1500         if (!strcmp(res->keyword, "detach")) {
1501                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1502                 detach_port_device(res->port_id);
1503         } else {
1504                 printf("Unknown parameter\n");
1505         }
1506 }
1507
1508 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1509         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1510                         port, "port");
1511 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1512         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1513                         keyword, "detach");
1514 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1515         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1516                         port_id, UINT16);
1517
1518 cmdline_parse_inst_t cmd_operate_detach_port = {
1519         .f = cmd_operate_detach_port_parsed,
1520         .data = NULL,
1521         .help_str = "port detach <port_id>",
1522         .tokens = {
1523                 (void *)&cmd_operate_detach_port_port,
1524                 (void *)&cmd_operate_detach_port_keyword,
1525                 (void *)&cmd_operate_detach_port_port_id,
1526                 NULL,
1527         },
1528 };
1529
1530 /* *** detach device by identifier *** */
1531 struct cmd_operate_detach_device_result {
1532         cmdline_fixed_string_t device;
1533         cmdline_fixed_string_t keyword;
1534         cmdline_fixed_string_t identifier;
1535 };
1536
1537 static void cmd_operate_detach_device_parsed(void *parsed_result,
1538                                 __rte_unused struct cmdline *cl,
1539                                 __rte_unused void *data)
1540 {
1541         struct cmd_operate_detach_device_result *res = parsed_result;
1542
1543         if (!strcmp(res->keyword, "detach"))
1544                 detach_devargs(res->identifier);
1545         else
1546                 printf("Unknown parameter\n");
1547 }
1548
1549 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1550         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1551                         device, "device");
1552 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1553         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1554                         keyword, "detach");
1555 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1556         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1557                         identifier, NULL);
1558
1559 cmdline_parse_inst_t cmd_operate_detach_device = {
1560         .f = cmd_operate_detach_device_parsed,
1561         .data = NULL,
1562         .help_str = "device detach <identifier>:"
1563                 "(identifier: pci address or virtual dev name)",
1564         .tokens = {
1565                 (void *)&cmd_operate_detach_device_device,
1566                 (void *)&cmd_operate_detach_device_keyword,
1567                 (void *)&cmd_operate_detach_device_identifier,
1568                 NULL,
1569         },
1570 };
1571 /* *** configure speed for all ports *** */
1572 struct cmd_config_speed_all {
1573         cmdline_fixed_string_t port;
1574         cmdline_fixed_string_t keyword;
1575         cmdline_fixed_string_t all;
1576         cmdline_fixed_string_t item1;
1577         cmdline_fixed_string_t item2;
1578         cmdline_fixed_string_t value1;
1579         cmdline_fixed_string_t value2;
1580 };
1581
1582 static int
1583 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1584 {
1585
1586         int duplex;
1587
1588         if (!strcmp(duplexstr, "half")) {
1589                 duplex = ETH_LINK_HALF_DUPLEX;
1590         } else if (!strcmp(duplexstr, "full")) {
1591                 duplex = ETH_LINK_FULL_DUPLEX;
1592         } else if (!strcmp(duplexstr, "auto")) {
1593                 duplex = ETH_LINK_FULL_DUPLEX;
1594         } else {
1595                 printf("Unknown duplex parameter\n");
1596                 return -1;
1597         }
1598
1599         if (!strcmp(speedstr, "10")) {
1600                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1601                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1602         } else if (!strcmp(speedstr, "100")) {
1603                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1604                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1605         } else {
1606                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1607                         printf("Invalid speed/duplex parameters\n");
1608                         return -1;
1609                 }
1610                 if (!strcmp(speedstr, "1000")) {
1611                         *speed = ETH_LINK_SPEED_1G;
1612                 } else if (!strcmp(speedstr, "10000")) {
1613                         *speed = ETH_LINK_SPEED_10G;
1614                 } else if (!strcmp(speedstr, "25000")) {
1615                         *speed = ETH_LINK_SPEED_25G;
1616                 } else if (!strcmp(speedstr, "40000")) {
1617                         *speed = ETH_LINK_SPEED_40G;
1618                 } else if (!strcmp(speedstr, "50000")) {
1619                         *speed = ETH_LINK_SPEED_50G;
1620                 } else if (!strcmp(speedstr, "100000")) {
1621                         *speed = ETH_LINK_SPEED_100G;
1622                 } else if (!strcmp(speedstr, "auto")) {
1623                         *speed = ETH_LINK_SPEED_AUTONEG;
1624                 } else {
1625                         printf("Unknown speed parameter\n");
1626                         return -1;
1627                 }
1628         }
1629
1630         return 0;
1631 }
1632
1633 static void
1634 cmd_config_speed_all_parsed(void *parsed_result,
1635                         __rte_unused struct cmdline *cl,
1636                         __rte_unused void *data)
1637 {
1638         struct cmd_config_speed_all *res = parsed_result;
1639         uint32_t link_speed;
1640         portid_t pid;
1641
1642         if (!all_ports_stopped()) {
1643                 printf("Please stop all ports first\n");
1644                 return;
1645         }
1646
1647         if (parse_and_check_speed_duplex(res->value1, res->value2,
1648                         &link_speed) < 0)
1649                 return;
1650
1651         RTE_ETH_FOREACH_DEV(pid) {
1652                 ports[pid].dev_conf.link_speeds = link_speed;
1653         }
1654
1655         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1656 }
1657
1658 cmdline_parse_token_string_t cmd_config_speed_all_port =
1659         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1660 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1661         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1662                                                         "config");
1663 cmdline_parse_token_string_t cmd_config_speed_all_all =
1664         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1665 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1666         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1667 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1668         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1669                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1670 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1671         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1672 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1673         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1674                                                 "half#full#auto");
1675
1676 cmdline_parse_inst_t cmd_config_speed_all = {
1677         .f = cmd_config_speed_all_parsed,
1678         .data = NULL,
1679         .help_str = "port config all speed "
1680                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1681                                                         "half|full|auto",
1682         .tokens = {
1683                 (void *)&cmd_config_speed_all_port,
1684                 (void *)&cmd_config_speed_all_keyword,
1685                 (void *)&cmd_config_speed_all_all,
1686                 (void *)&cmd_config_speed_all_item1,
1687                 (void *)&cmd_config_speed_all_value1,
1688                 (void *)&cmd_config_speed_all_item2,
1689                 (void *)&cmd_config_speed_all_value2,
1690                 NULL,
1691         },
1692 };
1693
1694 /* *** configure speed for specific port *** */
1695 struct cmd_config_speed_specific {
1696         cmdline_fixed_string_t port;
1697         cmdline_fixed_string_t keyword;
1698         portid_t id;
1699         cmdline_fixed_string_t item1;
1700         cmdline_fixed_string_t item2;
1701         cmdline_fixed_string_t value1;
1702         cmdline_fixed_string_t value2;
1703 };
1704
1705 static void
1706 cmd_config_speed_specific_parsed(void *parsed_result,
1707                                 __rte_unused struct cmdline *cl,
1708                                 __rte_unused void *data)
1709 {
1710         struct cmd_config_speed_specific *res = parsed_result;
1711         uint32_t link_speed;
1712
1713         if (!all_ports_stopped()) {
1714                 printf("Please stop all ports first\n");
1715                 return;
1716         }
1717
1718         if (port_id_is_invalid(res->id, ENABLED_WARN))
1719                 return;
1720
1721         if (parse_and_check_speed_duplex(res->value1, res->value2,
1722                         &link_speed) < 0)
1723                 return;
1724
1725         ports[res->id].dev_conf.link_speeds = link_speed;
1726
1727         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1728 }
1729
1730
1731 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1733                                                                 "port");
1734 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1735         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1736                                                                 "config");
1737 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1738         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1739 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1740         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1741                                                                 "speed");
1742 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1743         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1744                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1745 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1746         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1747                                                                 "duplex");
1748 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1749         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1750                                                         "half#full#auto");
1751
1752 cmdline_parse_inst_t cmd_config_speed_specific = {
1753         .f = cmd_config_speed_specific_parsed,
1754         .data = NULL,
1755         .help_str = "port config <port_id> speed "
1756                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1757                                                         "half|full|auto",
1758         .tokens = {
1759                 (void *)&cmd_config_speed_specific_port,
1760                 (void *)&cmd_config_speed_specific_keyword,
1761                 (void *)&cmd_config_speed_specific_id,
1762                 (void *)&cmd_config_speed_specific_item1,
1763                 (void *)&cmd_config_speed_specific_value1,
1764                 (void *)&cmd_config_speed_specific_item2,
1765                 (void *)&cmd_config_speed_specific_value2,
1766                 NULL,
1767         },
1768 };
1769
1770 /* *** configure loopback for all ports *** */
1771 struct cmd_config_loopback_all {
1772         cmdline_fixed_string_t port;
1773         cmdline_fixed_string_t keyword;
1774         cmdline_fixed_string_t all;
1775         cmdline_fixed_string_t item;
1776         uint32_t mode;
1777 };
1778
1779 static void
1780 cmd_config_loopback_all_parsed(void *parsed_result,
1781                         __rte_unused struct cmdline *cl,
1782                         __rte_unused void *data)
1783 {
1784         struct cmd_config_loopback_all *res = parsed_result;
1785         portid_t pid;
1786
1787         if (!all_ports_stopped()) {
1788                 printf("Please stop all ports first\n");
1789                 return;
1790         }
1791
1792         RTE_ETH_FOREACH_DEV(pid) {
1793                 ports[pid].dev_conf.lpbk_mode = res->mode;
1794         }
1795
1796         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1797 }
1798
1799 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1800         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1801 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1802         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1803                                                         "config");
1804 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1805         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1806 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1807         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1808                                                         "loopback");
1809 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1810         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1811
1812 cmdline_parse_inst_t cmd_config_loopback_all = {
1813         .f = cmd_config_loopback_all_parsed,
1814         .data = NULL,
1815         .help_str = "port config all loopback <mode>",
1816         .tokens = {
1817                 (void *)&cmd_config_loopback_all_port,
1818                 (void *)&cmd_config_loopback_all_keyword,
1819                 (void *)&cmd_config_loopback_all_all,
1820                 (void *)&cmd_config_loopback_all_item,
1821                 (void *)&cmd_config_loopback_all_mode,
1822                 NULL,
1823         },
1824 };
1825
1826 /* *** configure loopback for specific port *** */
1827 struct cmd_config_loopback_specific {
1828         cmdline_fixed_string_t port;
1829         cmdline_fixed_string_t keyword;
1830         uint16_t port_id;
1831         cmdline_fixed_string_t item;
1832         uint32_t mode;
1833 };
1834
1835 static void
1836 cmd_config_loopback_specific_parsed(void *parsed_result,
1837                                 __rte_unused struct cmdline *cl,
1838                                 __rte_unused void *data)
1839 {
1840         struct cmd_config_loopback_specific *res = parsed_result;
1841
1842         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1843                 return;
1844
1845         if (!port_is_stopped(res->port_id)) {
1846                 printf("Please stop port %u first\n", res->port_id);
1847                 return;
1848         }
1849
1850         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1851
1852         cmd_reconfig_device_queue(res->port_id, 1, 1);
1853 }
1854
1855
1856 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1857         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1858                                                                 "port");
1859 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1860         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1861                                                                 "config");
1862 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1863         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1864                                                                 UINT16);
1865 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1866         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1867                                                                 "loopback");
1868 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1869         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1870                               UINT32);
1871
1872 cmdline_parse_inst_t cmd_config_loopback_specific = {
1873         .f = cmd_config_loopback_specific_parsed,
1874         .data = NULL,
1875         .help_str = "port config <port_id> loopback <mode>",
1876         .tokens = {
1877                 (void *)&cmd_config_loopback_specific_port,
1878                 (void *)&cmd_config_loopback_specific_keyword,
1879                 (void *)&cmd_config_loopback_specific_id,
1880                 (void *)&cmd_config_loopback_specific_item,
1881                 (void *)&cmd_config_loopback_specific_mode,
1882                 NULL,
1883         },
1884 };
1885
1886 /* *** configure txq/rxq, txd/rxd *** */
1887 struct cmd_config_rx_tx {
1888         cmdline_fixed_string_t port;
1889         cmdline_fixed_string_t keyword;
1890         cmdline_fixed_string_t all;
1891         cmdline_fixed_string_t name;
1892         uint16_t value;
1893 };
1894
1895 static void
1896 cmd_config_rx_tx_parsed(void *parsed_result,
1897                         __rte_unused struct cmdline *cl,
1898                         __rte_unused void *data)
1899 {
1900         struct cmd_config_rx_tx *res = parsed_result;
1901
1902         if (!all_ports_stopped()) {
1903                 printf("Please stop all ports first\n");
1904                 return;
1905         }
1906         if (!strcmp(res->name, "rxq")) {
1907                 if (!res->value && !nb_txq) {
1908                         printf("Warning: Either rx or tx queues should be non zero\n");
1909                         return;
1910                 }
1911                 if (check_nb_rxq(res->value) != 0)
1912                         return;
1913                 nb_rxq = res->value;
1914         }
1915         else if (!strcmp(res->name, "txq")) {
1916                 if (!res->value && !nb_rxq) {
1917                         printf("Warning: Either rx or tx queues should be non zero\n");
1918                         return;
1919                 }
1920                 if (check_nb_txq(res->value) != 0)
1921                         return;
1922                 nb_txq = res->value;
1923         }
1924         else if (!strcmp(res->name, "rxd")) {
1925                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1926                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1927                                         res->value, RTE_TEST_RX_DESC_MAX);
1928                         return;
1929                 }
1930                 nb_rxd = res->value;
1931         } else if (!strcmp(res->name, "txd")) {
1932                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1933                         printf("txd %d invalid - must be > 0 && <= %d\n",
1934                                         res->value, RTE_TEST_TX_DESC_MAX);
1935                         return;
1936                 }
1937                 nb_txd = res->value;
1938         } else {
1939                 printf("Unknown parameter\n");
1940                 return;
1941         }
1942
1943         fwd_config_setup();
1944
1945         init_port_config();
1946
1947         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1948 }
1949
1950 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1951         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1952 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1953         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1954 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1955         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1956 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1957         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1958                                                 "rxq#txq#rxd#txd");
1959 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1960         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1961
1962 cmdline_parse_inst_t cmd_config_rx_tx = {
1963         .f = cmd_config_rx_tx_parsed,
1964         .data = NULL,
1965         .help_str = "port config all rxq|txq|rxd|txd <value>",
1966         .tokens = {
1967                 (void *)&cmd_config_rx_tx_port,
1968                 (void *)&cmd_config_rx_tx_keyword,
1969                 (void *)&cmd_config_rx_tx_all,
1970                 (void *)&cmd_config_rx_tx_name,
1971                 (void *)&cmd_config_rx_tx_value,
1972                 NULL,
1973         },
1974 };
1975
1976 /* *** config max packet length *** */
1977 struct cmd_config_max_pkt_len_result {
1978         cmdline_fixed_string_t port;
1979         cmdline_fixed_string_t keyword;
1980         cmdline_fixed_string_t all;
1981         cmdline_fixed_string_t name;
1982         uint32_t value;
1983 };
1984
1985 static void
1986 cmd_config_max_pkt_len_parsed(void *parsed_result,
1987                                 __rte_unused struct cmdline *cl,
1988                                 __rte_unused void *data)
1989 {
1990         struct cmd_config_max_pkt_len_result *res = parsed_result;
1991         portid_t pid;
1992
1993         if (!all_ports_stopped()) {
1994                 printf("Please stop all ports first\n");
1995                 return;
1996         }
1997
1998         RTE_ETH_FOREACH_DEV(pid) {
1999                 struct rte_port *port = &ports[pid];
2000                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2001
2002                 if (!strcmp(res->name, "max-pkt-len")) {
2003                         if (res->value < RTE_ETHER_MIN_LEN) {
2004                                 printf("max-pkt-len can not be less than %d\n",
2005                                                 RTE_ETHER_MIN_LEN);
2006                                 return;
2007                         }
2008                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2009                                 return;
2010
2011                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2012                         if (res->value > RTE_ETHER_MAX_LEN)
2013                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2014                         else
2015                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2016                         port->dev_conf.rxmode.offloads = rx_offloads;
2017                 } else {
2018                         printf("Unknown parameter\n");
2019                         return;
2020                 }
2021         }
2022
2023         init_port_config();
2024
2025         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2026 }
2027
2028 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2029         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2030                                                                 "port");
2031 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2032         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2033                                                                 "config");
2034 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2035         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2036                                                                 "all");
2037 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2038         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2039                                                                 "max-pkt-len");
2040 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2041         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2042                                                                 UINT32);
2043
2044 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2045         .f = cmd_config_max_pkt_len_parsed,
2046         .data = NULL,
2047         .help_str = "port config all max-pkt-len <value>",
2048         .tokens = {
2049                 (void *)&cmd_config_max_pkt_len_port,
2050                 (void *)&cmd_config_max_pkt_len_keyword,
2051                 (void *)&cmd_config_max_pkt_len_all,
2052                 (void *)&cmd_config_max_pkt_len_name,
2053                 (void *)&cmd_config_max_pkt_len_value,
2054                 NULL,
2055         },
2056 };
2057
2058 /* *** config max LRO aggregated packet size *** */
2059 struct cmd_config_max_lro_pkt_size_result {
2060         cmdline_fixed_string_t port;
2061         cmdline_fixed_string_t keyword;
2062         cmdline_fixed_string_t all;
2063         cmdline_fixed_string_t name;
2064         uint32_t value;
2065 };
2066
2067 static void
2068 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2069                                 __rte_unused struct cmdline *cl,
2070                                 __rte_unused void *data)
2071 {
2072         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2073         portid_t pid;
2074
2075         if (!all_ports_stopped()) {
2076                 printf("Please stop all ports first\n");
2077                 return;
2078         }
2079
2080         RTE_ETH_FOREACH_DEV(pid) {
2081                 struct rte_port *port = &ports[pid];
2082
2083                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2084                         if (res->value ==
2085                                         port->dev_conf.rxmode.max_lro_pkt_size)
2086                                 return;
2087
2088                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2089                 } else {
2090                         printf("Unknown parameter\n");
2091                         return;
2092                 }
2093         }
2094
2095         init_port_config();
2096
2097         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2098 }
2099
2100 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2101         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2102                                  port, "port");
2103 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2104         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2105                                  keyword, "config");
2106 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2107         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2108                                  all, "all");
2109 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2110         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2111                                  name, "max-lro-pkt-size");
2112 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2113         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2114                               value, UINT32);
2115
2116 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2117         .f = cmd_config_max_lro_pkt_size_parsed,
2118         .data = NULL,
2119         .help_str = "port config all max-lro-pkt-size <value>",
2120         .tokens = {
2121                 (void *)&cmd_config_max_lro_pkt_size_port,
2122                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2123                 (void *)&cmd_config_max_lro_pkt_size_all,
2124                 (void *)&cmd_config_max_lro_pkt_size_name,
2125                 (void *)&cmd_config_max_lro_pkt_size_value,
2126                 NULL,
2127         },
2128 };
2129
2130 /* *** configure port MTU *** */
2131 struct cmd_config_mtu_result {
2132         cmdline_fixed_string_t port;
2133         cmdline_fixed_string_t keyword;
2134         cmdline_fixed_string_t mtu;
2135         portid_t port_id;
2136         uint16_t value;
2137 };
2138
2139 static void
2140 cmd_config_mtu_parsed(void *parsed_result,
2141                       __rte_unused struct cmdline *cl,
2142                       __rte_unused void *data)
2143 {
2144         struct cmd_config_mtu_result *res = parsed_result;
2145
2146         if (res->value < RTE_ETHER_MIN_LEN) {
2147                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2148                 return;
2149         }
2150         port_mtu_set(res->port_id, res->value);
2151 }
2152
2153 cmdline_parse_token_string_t cmd_config_mtu_port =
2154         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2155                                  "port");
2156 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2157         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2158                                  "config");
2159 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2160         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2161                                  "mtu");
2162 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2163         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2164 cmdline_parse_token_num_t cmd_config_mtu_value =
2165         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2166
2167 cmdline_parse_inst_t cmd_config_mtu = {
2168         .f = cmd_config_mtu_parsed,
2169         .data = NULL,
2170         .help_str = "port config mtu <port_id> <value>",
2171         .tokens = {
2172                 (void *)&cmd_config_mtu_port,
2173                 (void *)&cmd_config_mtu_keyword,
2174                 (void *)&cmd_config_mtu_mtu,
2175                 (void *)&cmd_config_mtu_port_id,
2176                 (void *)&cmd_config_mtu_value,
2177                 NULL,
2178         },
2179 };
2180
2181 /* *** configure rx mode *** */
2182 struct cmd_config_rx_mode_flag {
2183         cmdline_fixed_string_t port;
2184         cmdline_fixed_string_t keyword;
2185         cmdline_fixed_string_t all;
2186         cmdline_fixed_string_t name;
2187         cmdline_fixed_string_t value;
2188 };
2189
2190 static void
2191 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2192                                 __rte_unused struct cmdline *cl,
2193                                 __rte_unused void *data)
2194 {
2195         struct cmd_config_rx_mode_flag *res = parsed_result;
2196
2197         if (!all_ports_stopped()) {
2198                 printf("Please stop all ports first\n");
2199                 return;
2200         }
2201
2202         if (!strcmp(res->name, "drop-en")) {
2203                 if (!strcmp(res->value, "on"))
2204                         rx_drop_en = 1;
2205                 else if (!strcmp(res->value, "off"))
2206                         rx_drop_en = 0;
2207                 else {
2208                         printf("Unknown parameter\n");
2209                         return;
2210                 }
2211         } else {
2212                 printf("Unknown parameter\n");
2213                 return;
2214         }
2215
2216         init_port_config();
2217
2218         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2219 }
2220
2221 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2222         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2223 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2224         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2225                                                                 "config");
2226 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2227         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2228 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2229         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2230                                         "drop-en");
2231 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2232         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2233                                                         "on#off");
2234
2235 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2236         .f = cmd_config_rx_mode_flag_parsed,
2237         .data = NULL,
2238         .help_str = "port config all drop-en on|off",
2239         .tokens = {
2240                 (void *)&cmd_config_rx_mode_flag_port,
2241                 (void *)&cmd_config_rx_mode_flag_keyword,
2242                 (void *)&cmd_config_rx_mode_flag_all,
2243                 (void *)&cmd_config_rx_mode_flag_name,
2244                 (void *)&cmd_config_rx_mode_flag_value,
2245                 NULL,
2246         },
2247 };
2248
2249 /* *** configure rss *** */
2250 struct cmd_config_rss {
2251         cmdline_fixed_string_t port;
2252         cmdline_fixed_string_t keyword;
2253         cmdline_fixed_string_t all;
2254         cmdline_fixed_string_t name;
2255         cmdline_fixed_string_t value;
2256 };
2257
2258 static void
2259 cmd_config_rss_parsed(void *parsed_result,
2260                         __rte_unused struct cmdline *cl,
2261                         __rte_unused void *data)
2262 {
2263         struct cmd_config_rss *res = parsed_result;
2264         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2265         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2266         int use_default = 0;
2267         int all_updated = 1;
2268         int diag;
2269         uint16_t i;
2270         int ret;
2271
2272         if (!strcmp(res->value, "all"))
2273                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
2274                                 ETH_RSS_UDP | ETH_RSS_SCTP |
2275                                         ETH_RSS_L2_PAYLOAD;
2276         else if (!strcmp(res->value, "ip"))
2277                 rss_conf.rss_hf = ETH_RSS_IP;
2278         else if (!strcmp(res->value, "udp"))
2279                 rss_conf.rss_hf = ETH_RSS_UDP;
2280         else if (!strcmp(res->value, "tcp"))
2281                 rss_conf.rss_hf = ETH_RSS_TCP;
2282         else if (!strcmp(res->value, "sctp"))
2283                 rss_conf.rss_hf = ETH_RSS_SCTP;
2284         else if (!strcmp(res->value, "ether"))
2285                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2286         else if (!strcmp(res->value, "port"))
2287                 rss_conf.rss_hf = ETH_RSS_PORT;
2288         else if (!strcmp(res->value, "vxlan"))
2289                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2290         else if (!strcmp(res->value, "geneve"))
2291                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2292         else if (!strcmp(res->value, "nvgre"))
2293                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2294         else if (!strcmp(res->value, "l3-src-only"))
2295                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2296         else if (!strcmp(res->value, "l3-dst-only"))
2297                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2298         else if (!strcmp(res->value, "l4-src-only"))
2299                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2300         else if (!strcmp(res->value, "l4-dst-only"))
2301                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2302         else if (!strcmp(res->value, "none"))
2303                 rss_conf.rss_hf = 0;
2304         else if (!strcmp(res->value, "default"))
2305                 use_default = 1;
2306         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2307                                                 atoi(res->value) < 64)
2308                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2309         else {
2310                 printf("Unknown parameter\n");
2311                 return;
2312         }
2313         rss_conf.rss_key = NULL;
2314         /* Update global configuration for RSS types. */
2315         RTE_ETH_FOREACH_DEV(i) {
2316                 struct rte_eth_rss_conf local_rss_conf;
2317
2318                 ret = eth_dev_info_get_print_err(i, &dev_info);
2319                 if (ret != 0)
2320                         return;
2321
2322                 if (use_default)
2323                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2324
2325                 local_rss_conf = rss_conf;
2326                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2327                         dev_info.flow_type_rss_offloads;
2328                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2329                         printf("Port %u modified RSS hash function based on hardware support,"
2330                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2331                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2332                 }
2333                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2334                 if (diag < 0) {
2335                         all_updated = 0;
2336                         printf("Configuration of RSS hash at ethernet port %d "
2337                                 "failed with error (%d): %s.\n",
2338                                 i, -diag, strerror(-diag));
2339                 }
2340         }
2341         if (all_updated && !use_default) {
2342                 rss_hf = rss_conf.rss_hf;
2343                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2344         }
2345 }
2346
2347 cmdline_parse_token_string_t cmd_config_rss_port =
2348         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2349 cmdline_parse_token_string_t cmd_config_rss_keyword =
2350         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2351 cmdline_parse_token_string_t cmd_config_rss_all =
2352         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2353 cmdline_parse_token_string_t cmd_config_rss_name =
2354         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2355 cmdline_parse_token_string_t cmd_config_rss_value =
2356         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2357
2358 cmdline_parse_inst_t cmd_config_rss = {
2359         .f = cmd_config_rss_parsed,
2360         .data = NULL,
2361         .help_str = "port config all rss "
2362                 "all|default|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>",
2363         .tokens = {
2364                 (void *)&cmd_config_rss_port,
2365                 (void *)&cmd_config_rss_keyword,
2366                 (void *)&cmd_config_rss_all,
2367                 (void *)&cmd_config_rss_name,
2368                 (void *)&cmd_config_rss_value,
2369                 NULL,
2370         },
2371 };
2372
2373 /* *** configure rss hash key *** */
2374 struct cmd_config_rss_hash_key {
2375         cmdline_fixed_string_t port;
2376         cmdline_fixed_string_t config;
2377         portid_t port_id;
2378         cmdline_fixed_string_t rss_hash_key;
2379         cmdline_fixed_string_t rss_type;
2380         cmdline_fixed_string_t key;
2381 };
2382
2383 static uint8_t
2384 hexa_digit_to_value(char hexa_digit)
2385 {
2386         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2387                 return (uint8_t) (hexa_digit - '0');
2388         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2389                 return (uint8_t) ((hexa_digit - 'a') + 10);
2390         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2391                 return (uint8_t) ((hexa_digit - 'A') + 10);
2392         /* Invalid hexa digit */
2393         return 0xFF;
2394 }
2395
2396 static uint8_t
2397 parse_and_check_key_hexa_digit(char *key, int idx)
2398 {
2399         uint8_t hexa_v;
2400
2401         hexa_v = hexa_digit_to_value(key[idx]);
2402         if (hexa_v == 0xFF)
2403                 printf("invalid key: character %c at position %d is not a "
2404                        "valid hexa digit\n", key[idx], idx);
2405         return hexa_v;
2406 }
2407
2408 static void
2409 cmd_config_rss_hash_key_parsed(void *parsed_result,
2410                                __rte_unused struct cmdline *cl,
2411                                __rte_unused void *data)
2412 {
2413         struct cmd_config_rss_hash_key *res = parsed_result;
2414         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2415         uint8_t xdgt0;
2416         uint8_t xdgt1;
2417         int i;
2418         struct rte_eth_dev_info dev_info;
2419         uint8_t hash_key_size;
2420         uint32_t key_len;
2421         int ret;
2422
2423         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2424         if (ret != 0)
2425                 return;
2426
2427         if (dev_info.hash_key_size > 0 &&
2428                         dev_info.hash_key_size <= sizeof(hash_key))
2429                 hash_key_size = dev_info.hash_key_size;
2430         else {
2431                 printf("dev_info did not provide a valid hash key size\n");
2432                 return;
2433         }
2434         /* Check the length of the RSS hash key */
2435         key_len = strlen(res->key);
2436         if (key_len != (hash_key_size * 2)) {
2437                 printf("key length: %d invalid - key must be a string of %d"
2438                            " hexa-decimal numbers\n",
2439                            (int) key_len, hash_key_size * 2);
2440                 return;
2441         }
2442         /* Translate RSS hash key into binary representation */
2443         for (i = 0; i < hash_key_size; i++) {
2444                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2445                 if (xdgt0 == 0xFF)
2446                         return;
2447                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2448                 if (xdgt1 == 0xFF)
2449                         return;
2450                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2451         }
2452         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2453                         hash_key_size);
2454 }
2455
2456 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2457         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2458 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2459         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2460                                  "config");
2461 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2462         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2463 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2464         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2465                                  rss_hash_key, "rss-hash-key");
2466 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2467         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2468                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2469                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2470                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2471                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2472                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only");
2473 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2474         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2475
2476 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2477         .f = cmd_config_rss_hash_key_parsed,
2478         .data = NULL,
2479         .help_str = "port config <port_id> rss-hash-key "
2480                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2481                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2482                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2483                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only "
2484                 "<string of hex digits (variable length, NIC dependent)>",
2485         .tokens = {
2486                 (void *)&cmd_config_rss_hash_key_port,
2487                 (void *)&cmd_config_rss_hash_key_config,
2488                 (void *)&cmd_config_rss_hash_key_port_id,
2489                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2490                 (void *)&cmd_config_rss_hash_key_rss_type,
2491                 (void *)&cmd_config_rss_hash_key_value,
2492                 NULL,
2493         },
2494 };
2495
2496 /* *** configure port rxq/txq ring size *** */
2497 struct cmd_config_rxtx_ring_size {
2498         cmdline_fixed_string_t port;
2499         cmdline_fixed_string_t config;
2500         portid_t portid;
2501         cmdline_fixed_string_t rxtxq;
2502         uint16_t qid;
2503         cmdline_fixed_string_t rsize;
2504         uint16_t size;
2505 };
2506
2507 static void
2508 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2509                                  __rte_unused struct cmdline *cl,
2510                                  __rte_unused void *data)
2511 {
2512         struct cmd_config_rxtx_ring_size *res = parsed_result;
2513         struct rte_port *port;
2514         uint8_t isrx;
2515
2516         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2517                 return;
2518
2519         if (res->portid == (portid_t)RTE_PORT_ALL) {
2520                 printf("Invalid port id\n");
2521                 return;
2522         }
2523
2524         port = &ports[res->portid];
2525
2526         if (!strcmp(res->rxtxq, "rxq"))
2527                 isrx = 1;
2528         else if (!strcmp(res->rxtxq, "txq"))
2529                 isrx = 0;
2530         else {
2531                 printf("Unknown parameter\n");
2532                 return;
2533         }
2534
2535         if (isrx && rx_queue_id_is_invalid(res->qid))
2536                 return;
2537         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2538                 return;
2539
2540         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2541                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2542                        rx_free_thresh);
2543                 return;
2544         }
2545
2546         if (isrx)
2547                 port->nb_rx_desc[res->qid] = res->size;
2548         else
2549                 port->nb_tx_desc[res->qid] = res->size;
2550
2551         cmd_reconfig_device_queue(res->portid, 0, 1);
2552 }
2553
2554 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2555         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2556                                  port, "port");
2557 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2558         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2559                                  config, "config");
2560 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2561         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2562                                  portid, UINT16);
2563 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2564         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2565                                  rxtxq, "rxq#txq");
2566 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2567         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2568                               qid, UINT16);
2569 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2570         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2571                                  rsize, "ring_size");
2572 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2573         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2574                               size, UINT16);
2575
2576 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2577         .f = cmd_config_rxtx_ring_size_parsed,
2578         .data = NULL,
2579         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2580         .tokens = {
2581                 (void *)&cmd_config_rxtx_ring_size_port,
2582                 (void *)&cmd_config_rxtx_ring_size_config,
2583                 (void *)&cmd_config_rxtx_ring_size_portid,
2584                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2585                 (void *)&cmd_config_rxtx_ring_size_qid,
2586                 (void *)&cmd_config_rxtx_ring_size_rsize,
2587                 (void *)&cmd_config_rxtx_ring_size_size,
2588                 NULL,
2589         },
2590 };
2591
2592 /* *** configure port rxq/txq start/stop *** */
2593 struct cmd_config_rxtx_queue {
2594         cmdline_fixed_string_t port;
2595         portid_t portid;
2596         cmdline_fixed_string_t rxtxq;
2597         uint16_t qid;
2598         cmdline_fixed_string_t opname;
2599 };
2600
2601 static void
2602 cmd_config_rxtx_queue_parsed(void *parsed_result,
2603                         __rte_unused struct cmdline *cl,
2604                         __rte_unused void *data)
2605 {
2606         struct cmd_config_rxtx_queue *res = parsed_result;
2607         uint8_t isrx;
2608         uint8_t isstart;
2609         int ret = 0;
2610
2611         if (test_done == 0) {
2612                 printf("Please stop forwarding first\n");
2613                 return;
2614         }
2615
2616         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2617                 return;
2618
2619         if (port_is_started(res->portid) != 1) {
2620                 printf("Please start port %u first\n", res->portid);
2621                 return;
2622         }
2623
2624         if (!strcmp(res->rxtxq, "rxq"))
2625                 isrx = 1;
2626         else if (!strcmp(res->rxtxq, "txq"))
2627                 isrx = 0;
2628         else {
2629                 printf("Unknown parameter\n");
2630                 return;
2631         }
2632
2633         if (isrx && rx_queue_id_is_invalid(res->qid))
2634                 return;
2635         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2636                 return;
2637
2638         if (!strcmp(res->opname, "start"))
2639                 isstart = 1;
2640         else if (!strcmp(res->opname, "stop"))
2641                 isstart = 0;
2642         else {
2643                 printf("Unknown parameter\n");
2644                 return;
2645         }
2646
2647         if (isstart && isrx)
2648                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2649         else if (!isstart && isrx)
2650                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2651         else if (isstart && !isrx)
2652                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2653         else
2654                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2655
2656         if (ret == -ENOTSUP)
2657                 printf("Function not supported in PMD driver\n");
2658 }
2659
2660 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2661         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2662 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2663         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2664 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2665         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2666 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2667         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2668 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2669         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2670                                                 "start#stop");
2671
2672 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2673         .f = cmd_config_rxtx_queue_parsed,
2674         .data = NULL,
2675         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2676         .tokens = {
2677                 (void *)&cmd_config_rxtx_queue_port,
2678                 (void *)&cmd_config_rxtx_queue_portid,
2679                 (void *)&cmd_config_rxtx_queue_rxtxq,
2680                 (void *)&cmd_config_rxtx_queue_qid,
2681                 (void *)&cmd_config_rxtx_queue_opname,
2682                 NULL,
2683         },
2684 };
2685
2686 /* *** configure port rxq/txq deferred start on/off *** */
2687 struct cmd_config_deferred_start_rxtx_queue {
2688         cmdline_fixed_string_t port;
2689         portid_t port_id;
2690         cmdline_fixed_string_t rxtxq;
2691         uint16_t qid;
2692         cmdline_fixed_string_t opname;
2693         cmdline_fixed_string_t state;
2694 };
2695
2696 static void
2697 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2698                         __rte_unused struct cmdline *cl,
2699                         __rte_unused void *data)
2700 {
2701         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2702         struct rte_port *port;
2703         uint8_t isrx;
2704         uint8_t ison;
2705         uint8_t needreconfig = 0;
2706
2707         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2708                 return;
2709
2710         if (port_is_started(res->port_id) != 0) {
2711                 printf("Please stop port %u first\n", res->port_id);
2712                 return;
2713         }
2714
2715         port = &ports[res->port_id];
2716
2717         isrx = !strcmp(res->rxtxq, "rxq");
2718
2719         if (isrx && rx_queue_id_is_invalid(res->qid))
2720                 return;
2721         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2722                 return;
2723
2724         ison = !strcmp(res->state, "on");
2725
2726         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2727                 port->rx_conf[res->qid].rx_deferred_start = ison;
2728                 needreconfig = 1;
2729         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2730                 port->tx_conf[res->qid].tx_deferred_start = ison;
2731                 needreconfig = 1;
2732         }
2733
2734         if (needreconfig)
2735                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2736 }
2737
2738 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2739         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2740                                                 port, "port");
2741 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2742         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2743                                                 port_id, UINT16);
2744 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2745         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2746                                                 rxtxq, "rxq#txq");
2747 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2748         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2749                                                 qid, UINT16);
2750 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2751         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2752                                                 opname, "deferred_start");
2753 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2754         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2755                                                 state, "on#off");
2756
2757 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2758         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2759         .data = NULL,
2760         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2761         .tokens = {
2762                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2763                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2764                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2765                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2766                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2767                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2768                 NULL,
2769         },
2770 };
2771
2772 /* *** configure port rxq/txq setup *** */
2773 struct cmd_setup_rxtx_queue {
2774         cmdline_fixed_string_t port;
2775         portid_t portid;
2776         cmdline_fixed_string_t rxtxq;
2777         uint16_t qid;
2778         cmdline_fixed_string_t setup;
2779 };
2780
2781 /* Common CLI fields for queue setup */
2782 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2783         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2784 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2785         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2786 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2787         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2788 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2789         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2790 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2791         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2792
2793 static void
2794 cmd_setup_rxtx_queue_parsed(
2795         void *parsed_result,
2796         __rte_unused struct cmdline *cl,
2797         __rte_unused void *data)
2798 {
2799         struct cmd_setup_rxtx_queue *res = parsed_result;
2800         struct rte_port *port;
2801         struct rte_mempool *mp;
2802         unsigned int socket_id;
2803         uint8_t isrx = 0;
2804         int ret;
2805
2806         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2807                 return;
2808
2809         if (res->portid == (portid_t)RTE_PORT_ALL) {
2810                 printf("Invalid port id\n");
2811                 return;
2812         }
2813
2814         if (!strcmp(res->rxtxq, "rxq"))
2815                 isrx = 1;
2816         else if (!strcmp(res->rxtxq, "txq"))
2817                 isrx = 0;
2818         else {
2819                 printf("Unknown parameter\n");
2820                 return;
2821         }
2822
2823         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2824                 printf("Invalid rx queue\n");
2825                 return;
2826         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2827                 printf("Invalid tx queue\n");
2828                 return;
2829         }
2830
2831         port = &ports[res->portid];
2832         if (isrx) {
2833                 socket_id = rxring_numa[res->portid];
2834                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2835                         socket_id = port->socket_id;
2836
2837                 mp = mbuf_pool_find(socket_id);
2838                 if (mp == NULL) {
2839                         printf("Failed to setup RX queue: "
2840                                 "No mempool allocation"
2841                                 " on the socket %d\n",
2842                                 rxring_numa[res->portid]);
2843                         return;
2844                 }
2845                 ret = rte_eth_rx_queue_setup(res->portid,
2846                                              res->qid,
2847                                              port->nb_rx_desc[res->qid],
2848                                              socket_id,
2849                                              &port->rx_conf[res->qid],
2850                                              mp);
2851                 if (ret)
2852                         printf("Failed to setup RX queue\n");
2853         } else {
2854                 socket_id = txring_numa[res->portid];
2855                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2856                         socket_id = port->socket_id;
2857
2858                 ret = rte_eth_tx_queue_setup(res->portid,
2859                                              res->qid,
2860                                              port->nb_tx_desc[res->qid],
2861                                              socket_id,
2862                                              &port->tx_conf[res->qid]);
2863                 if (ret)
2864                         printf("Failed to setup TX queue\n");
2865         }
2866 }
2867
2868 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2869         .f = cmd_setup_rxtx_queue_parsed,
2870         .data = NULL,
2871         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2872         .tokens = {
2873                 (void *)&cmd_setup_rxtx_queue_port,
2874                 (void *)&cmd_setup_rxtx_queue_portid,
2875                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2876                 (void *)&cmd_setup_rxtx_queue_qid,
2877                 (void *)&cmd_setup_rxtx_queue_setup,
2878                 NULL,
2879         },
2880 };
2881
2882
2883 /* *** Configure RSS RETA *** */
2884 struct cmd_config_rss_reta {
2885         cmdline_fixed_string_t port;
2886         cmdline_fixed_string_t keyword;
2887         portid_t port_id;
2888         cmdline_fixed_string_t name;
2889         cmdline_fixed_string_t list_name;
2890         cmdline_fixed_string_t list_of_items;
2891 };
2892
2893 static int
2894 parse_reta_config(const char *str,
2895                   struct rte_eth_rss_reta_entry64 *reta_conf,
2896                   uint16_t nb_entries)
2897 {
2898         int i;
2899         unsigned size;
2900         uint16_t hash_index, idx, shift;
2901         uint16_t nb_queue;
2902         char s[256];
2903         const char *p, *p0 = str;
2904         char *end;
2905         enum fieldnames {
2906                 FLD_HASH_INDEX = 0,
2907                 FLD_QUEUE,
2908                 _NUM_FLD
2909         };
2910         unsigned long int_fld[_NUM_FLD];
2911         char *str_fld[_NUM_FLD];
2912
2913         while ((p = strchr(p0,'(')) != NULL) {
2914                 ++p;
2915                 if((p0 = strchr(p,')')) == NULL)
2916                         return -1;
2917
2918                 size = p0 - p;
2919                 if(size >= sizeof(s))
2920                         return -1;
2921
2922                 snprintf(s, sizeof(s), "%.*s", size, p);
2923                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2924                         return -1;
2925                 for (i = 0; i < _NUM_FLD; i++) {
2926                         errno = 0;
2927                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2928                         if (errno != 0 || end == str_fld[i] ||
2929                                         int_fld[i] > 65535)
2930                                 return -1;
2931                 }
2932
2933                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2934                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2935
2936                 if (hash_index >= nb_entries) {
2937                         printf("Invalid RETA hash index=%d\n", hash_index);
2938                         return -1;
2939                 }
2940
2941                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2942                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2943                 reta_conf[idx].mask |= (1ULL << shift);
2944                 reta_conf[idx].reta[shift] = nb_queue;
2945         }
2946
2947         return 0;
2948 }
2949
2950 static void
2951 cmd_set_rss_reta_parsed(void *parsed_result,
2952                         __rte_unused struct cmdline *cl,
2953                         __rte_unused void *data)
2954 {
2955         int ret;
2956         struct rte_eth_dev_info dev_info;
2957         struct rte_eth_rss_reta_entry64 reta_conf[8];
2958         struct cmd_config_rss_reta *res = parsed_result;
2959
2960         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2961         if (ret != 0)
2962                 return;
2963
2964         if (dev_info.reta_size == 0) {
2965                 printf("Redirection table size is 0 which is "
2966                                         "invalid for RSS\n");
2967                 return;
2968         } else
2969                 printf("The reta size of port %d is %u\n",
2970                         res->port_id, dev_info.reta_size);
2971         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2972                 printf("Currently do not support more than %u entries of "
2973                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2974                 return;
2975         }
2976
2977         memset(reta_conf, 0, sizeof(reta_conf));
2978         if (!strcmp(res->list_name, "reta")) {
2979                 if (parse_reta_config(res->list_of_items, reta_conf,
2980                                                 dev_info.reta_size)) {
2981                         printf("Invalid RSS Redirection Table "
2982                                         "config entered\n");
2983                         return;
2984                 }
2985                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2986                                 reta_conf, dev_info.reta_size);
2987                 if (ret != 0)
2988                         printf("Bad redirection table parameter, "
2989                                         "return code = %d \n", ret);
2990         }
2991 }
2992
2993 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2994         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2995 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2996         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2997 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2998         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2999 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3000         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3001 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3002         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3003 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3004         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3005                                  NULL);
3006 cmdline_parse_inst_t cmd_config_rss_reta = {
3007         .f = cmd_set_rss_reta_parsed,
3008         .data = NULL,
3009         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3010         .tokens = {
3011                 (void *)&cmd_config_rss_reta_port,
3012                 (void *)&cmd_config_rss_reta_keyword,
3013                 (void *)&cmd_config_rss_reta_port_id,
3014                 (void *)&cmd_config_rss_reta_name,
3015                 (void *)&cmd_config_rss_reta_list_name,
3016                 (void *)&cmd_config_rss_reta_list_of_items,
3017                 NULL,
3018         },
3019 };
3020
3021 /* *** SHOW PORT RETA INFO *** */
3022 struct cmd_showport_reta {
3023         cmdline_fixed_string_t show;
3024         cmdline_fixed_string_t port;
3025         portid_t port_id;
3026         cmdline_fixed_string_t rss;
3027         cmdline_fixed_string_t reta;
3028         uint16_t size;
3029         cmdline_fixed_string_t list_of_items;
3030 };
3031
3032 static int
3033 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3034                            uint16_t nb_entries,
3035                            char *str)
3036 {
3037         uint32_t size;
3038         const char *p, *p0 = str;
3039         char s[256];
3040         char *end;
3041         char *str_fld[8];
3042         uint16_t i;
3043         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3044                         RTE_RETA_GROUP_SIZE;
3045         int ret;
3046
3047         p = strchr(p0, '(');
3048         if (p == NULL)
3049                 return -1;
3050         p++;
3051         p0 = strchr(p, ')');
3052         if (p0 == NULL)
3053                 return -1;
3054         size = p0 - p;
3055         if (size >= sizeof(s)) {
3056                 printf("The string size exceeds the internal buffer size\n");
3057                 return -1;
3058         }
3059         snprintf(s, sizeof(s), "%.*s", size, p);
3060         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3061         if (ret <= 0 || ret != num) {
3062                 printf("The bits of masks do not match the number of "
3063                                         "reta entries: %u\n", num);
3064                 return -1;
3065         }
3066         for (i = 0; i < ret; i++)
3067                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3068
3069         return 0;
3070 }
3071
3072 static void
3073 cmd_showport_reta_parsed(void *parsed_result,
3074                          __rte_unused struct cmdline *cl,
3075                          __rte_unused void *data)
3076 {
3077         struct cmd_showport_reta *res = parsed_result;
3078         struct rte_eth_rss_reta_entry64 reta_conf[8];
3079         struct rte_eth_dev_info dev_info;
3080         uint16_t max_reta_size;
3081         int ret;
3082
3083         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3084         if (ret != 0)
3085                 return;
3086
3087         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3088         if (res->size == 0 || res->size > max_reta_size) {
3089                 printf("Invalid redirection table size: %u (1-%u)\n",
3090                         res->size, max_reta_size);
3091                 return;
3092         }
3093
3094         memset(reta_conf, 0, sizeof(reta_conf));
3095         if (showport_parse_reta_config(reta_conf, res->size,
3096                                 res->list_of_items) < 0) {
3097                 printf("Invalid string: %s for reta masks\n",
3098                                         res->list_of_items);
3099                 return;
3100         }
3101         port_rss_reta_info(res->port_id, reta_conf, res->size);
3102 }
3103
3104 cmdline_parse_token_string_t cmd_showport_reta_show =
3105         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3106 cmdline_parse_token_string_t cmd_showport_reta_port =
3107         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3108 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3109         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3110 cmdline_parse_token_string_t cmd_showport_reta_rss =
3111         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3112 cmdline_parse_token_string_t cmd_showport_reta_reta =
3113         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3114 cmdline_parse_token_num_t cmd_showport_reta_size =
3115         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3116 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3117         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3118                                         list_of_items, NULL);
3119
3120 cmdline_parse_inst_t cmd_showport_reta = {
3121         .f = cmd_showport_reta_parsed,
3122         .data = NULL,
3123         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3124         .tokens = {
3125                 (void *)&cmd_showport_reta_show,
3126                 (void *)&cmd_showport_reta_port,
3127                 (void *)&cmd_showport_reta_port_id,
3128                 (void *)&cmd_showport_reta_rss,
3129                 (void *)&cmd_showport_reta_reta,
3130                 (void *)&cmd_showport_reta_size,
3131                 (void *)&cmd_showport_reta_list_of_items,
3132                 NULL,
3133         },
3134 };
3135
3136 /* *** Show RSS hash configuration *** */
3137 struct cmd_showport_rss_hash {
3138         cmdline_fixed_string_t show;
3139         cmdline_fixed_string_t port;
3140         portid_t port_id;
3141         cmdline_fixed_string_t rss_hash;
3142         cmdline_fixed_string_t rss_type;
3143         cmdline_fixed_string_t key; /* optional argument */
3144 };
3145
3146 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3147                                 __rte_unused struct cmdline *cl,
3148                                 void *show_rss_key)
3149 {
3150         struct cmd_showport_rss_hash *res = parsed_result;
3151
3152         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3153 }
3154
3155 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3156         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3157 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3158         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3159 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3160         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3161 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3162         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3163                                  "rss-hash");
3164 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3165         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3166
3167 cmdline_parse_inst_t cmd_showport_rss_hash = {
3168         .f = cmd_showport_rss_hash_parsed,
3169         .data = NULL,
3170         .help_str = "show port <port_id> rss-hash",
3171         .tokens = {
3172                 (void *)&cmd_showport_rss_hash_show,
3173                 (void *)&cmd_showport_rss_hash_port,
3174                 (void *)&cmd_showport_rss_hash_port_id,
3175                 (void *)&cmd_showport_rss_hash_rss_hash,
3176                 NULL,
3177         },
3178 };
3179
3180 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3181         .f = cmd_showport_rss_hash_parsed,
3182         .data = (void *)1,
3183         .help_str = "show port <port_id> rss-hash key",
3184         .tokens = {
3185                 (void *)&cmd_showport_rss_hash_show,
3186                 (void *)&cmd_showport_rss_hash_port,
3187                 (void *)&cmd_showport_rss_hash_port_id,
3188                 (void *)&cmd_showport_rss_hash_rss_hash,
3189                 (void *)&cmd_showport_rss_hash_rss_key,
3190                 NULL,
3191         },
3192 };
3193
3194 /* *** Configure DCB *** */
3195 struct cmd_config_dcb {
3196         cmdline_fixed_string_t port;
3197         cmdline_fixed_string_t config;
3198         portid_t port_id;
3199         cmdline_fixed_string_t dcb;
3200         cmdline_fixed_string_t vt;
3201         cmdline_fixed_string_t vt_en;
3202         uint8_t num_tcs;
3203         cmdline_fixed_string_t pfc;
3204         cmdline_fixed_string_t pfc_en;
3205 };
3206
3207 static void
3208 cmd_config_dcb_parsed(void *parsed_result,
3209                         __rte_unused struct cmdline *cl,
3210                         __rte_unused void *data)
3211 {
3212         struct cmd_config_dcb *res = parsed_result;
3213         portid_t port_id = res->port_id;
3214         struct rte_port *port;
3215         uint8_t pfc_en;
3216         int ret;
3217
3218         port = &ports[port_id];
3219         /** Check if the port is not started **/
3220         if (port->port_status != RTE_PORT_STOPPED) {
3221                 printf("Please stop port %d first\n", port_id);
3222                 return;
3223         }
3224
3225         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3226                 printf("The invalid number of traffic class,"
3227                         " only 4 or 8 allowed.\n");
3228                 return;
3229         }
3230
3231         if (nb_fwd_lcores < res->num_tcs) {
3232                 printf("nb_cores shouldn't be less than number of TCs.\n");
3233                 return;
3234         }
3235         if (!strncmp(res->pfc_en, "on", 2))
3236                 pfc_en = 1;
3237         else
3238                 pfc_en = 0;
3239
3240         /* DCB in VT mode */
3241         if (!strncmp(res->vt_en, "on", 2))
3242                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3243                                 (enum rte_eth_nb_tcs)res->num_tcs,
3244                                 pfc_en);
3245         else
3246                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3247                                 (enum rte_eth_nb_tcs)res->num_tcs,
3248                                 pfc_en);
3249
3250
3251         if (ret != 0) {
3252                 printf("Cannot initialize network ports.\n");
3253                 return;
3254         }
3255
3256         cmd_reconfig_device_queue(port_id, 1, 1);
3257 }
3258
3259 cmdline_parse_token_string_t cmd_config_dcb_port =
3260         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3261 cmdline_parse_token_string_t cmd_config_dcb_config =
3262         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3263 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3264         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3265 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3266         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3267 cmdline_parse_token_string_t cmd_config_dcb_vt =
3268         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3269 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3270         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3271 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3272         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3273 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3274         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3275 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3276         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3277
3278 cmdline_parse_inst_t cmd_config_dcb = {
3279         .f = cmd_config_dcb_parsed,
3280         .data = NULL,
3281         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3282         .tokens = {
3283                 (void *)&cmd_config_dcb_port,
3284                 (void *)&cmd_config_dcb_config,
3285                 (void *)&cmd_config_dcb_port_id,
3286                 (void *)&cmd_config_dcb_dcb,
3287                 (void *)&cmd_config_dcb_vt,
3288                 (void *)&cmd_config_dcb_vt_en,
3289                 (void *)&cmd_config_dcb_num_tcs,
3290                 (void *)&cmd_config_dcb_pfc,
3291                 (void *)&cmd_config_dcb_pfc_en,
3292                 NULL,
3293         },
3294 };
3295
3296 /* *** configure number of packets per burst *** */
3297 struct cmd_config_burst {
3298         cmdline_fixed_string_t port;
3299         cmdline_fixed_string_t keyword;
3300         cmdline_fixed_string_t all;
3301         cmdline_fixed_string_t name;
3302         uint16_t value;
3303 };
3304
3305 static void
3306 cmd_config_burst_parsed(void *parsed_result,
3307                         __rte_unused struct cmdline *cl,
3308                         __rte_unused void *data)
3309 {
3310         struct cmd_config_burst *res = parsed_result;
3311         struct rte_eth_dev_info dev_info;
3312         uint16_t rec_nb_pkts;
3313         int ret;
3314
3315         if (!all_ports_stopped()) {
3316                 printf("Please stop all ports first\n");
3317                 return;
3318         }
3319
3320         if (!strcmp(res->name, "burst")) {
3321                 if (res->value == 0) {
3322                         /* If user gives a value of zero, query the PMD for
3323                          * its recommended Rx burst size. Testpmd uses a single
3324                          * size for all ports, so assume all ports are the same
3325                          * NIC model and use the values from Port 0.
3326                          */
3327                         ret = eth_dev_info_get_print_err(0, &dev_info);
3328                         if (ret != 0)
3329                                 return;
3330
3331                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3332
3333                         if (rec_nb_pkts == 0) {
3334                                 printf("PMD does not recommend a burst size.\n"
3335                                         "User provided value must be between"
3336                                         " 1 and %d\n", MAX_PKT_BURST);
3337                                 return;
3338                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3339                                 printf("PMD recommended burst size of %d"
3340                                         " exceeds maximum value of %d\n",
3341                                         rec_nb_pkts, MAX_PKT_BURST);
3342                                 return;
3343                         }
3344                         printf("Using PMD-provided burst value of %d\n",
3345                                 rec_nb_pkts);
3346                         nb_pkt_per_burst = rec_nb_pkts;
3347                 } else if (res->value > MAX_PKT_BURST) {
3348                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3349                         return;
3350                 } else
3351                         nb_pkt_per_burst = res->value;
3352         } else {
3353                 printf("Unknown parameter\n");
3354                 return;
3355         }
3356
3357         init_port_config();
3358
3359         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3360 }
3361
3362 cmdline_parse_token_string_t cmd_config_burst_port =
3363         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3364 cmdline_parse_token_string_t cmd_config_burst_keyword =
3365         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3366 cmdline_parse_token_string_t cmd_config_burst_all =
3367         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3368 cmdline_parse_token_string_t cmd_config_burst_name =
3369         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3370 cmdline_parse_token_num_t cmd_config_burst_value =
3371         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3372
3373 cmdline_parse_inst_t cmd_config_burst = {
3374         .f = cmd_config_burst_parsed,
3375         .data = NULL,
3376         .help_str = "port config all burst <value>",
3377         .tokens = {
3378                 (void *)&cmd_config_burst_port,
3379                 (void *)&cmd_config_burst_keyword,
3380                 (void *)&cmd_config_burst_all,
3381                 (void *)&cmd_config_burst_name,
3382                 (void *)&cmd_config_burst_value,
3383                 NULL,
3384         },
3385 };
3386
3387 /* *** configure rx/tx queues *** */
3388 struct cmd_config_thresh {
3389         cmdline_fixed_string_t port;
3390         cmdline_fixed_string_t keyword;
3391         cmdline_fixed_string_t all;
3392         cmdline_fixed_string_t name;
3393         uint8_t value;
3394 };
3395
3396 static void
3397 cmd_config_thresh_parsed(void *parsed_result,
3398                         __rte_unused struct cmdline *cl,
3399                         __rte_unused void *data)
3400 {
3401         struct cmd_config_thresh *res = parsed_result;
3402
3403         if (!all_ports_stopped()) {
3404                 printf("Please stop all ports first\n");
3405                 return;
3406         }
3407
3408         if (!strcmp(res->name, "txpt"))
3409                 tx_pthresh = res->value;
3410         else if(!strcmp(res->name, "txht"))
3411                 tx_hthresh = res->value;
3412         else if(!strcmp(res->name, "txwt"))
3413                 tx_wthresh = res->value;
3414         else if(!strcmp(res->name, "rxpt"))
3415                 rx_pthresh = res->value;
3416         else if(!strcmp(res->name, "rxht"))
3417                 rx_hthresh = res->value;
3418         else if(!strcmp(res->name, "rxwt"))
3419                 rx_wthresh = res->value;
3420         else {
3421                 printf("Unknown parameter\n");
3422                 return;
3423         }
3424
3425         init_port_config();
3426
3427         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3428 }
3429
3430 cmdline_parse_token_string_t cmd_config_thresh_port =
3431         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3432 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3433         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3434 cmdline_parse_token_string_t cmd_config_thresh_all =
3435         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3436 cmdline_parse_token_string_t cmd_config_thresh_name =
3437         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3438                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3439 cmdline_parse_token_num_t cmd_config_thresh_value =
3440         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3441
3442 cmdline_parse_inst_t cmd_config_thresh = {
3443         .f = cmd_config_thresh_parsed,
3444         .data = NULL,
3445         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3446         .tokens = {
3447                 (void *)&cmd_config_thresh_port,
3448                 (void *)&cmd_config_thresh_keyword,
3449                 (void *)&cmd_config_thresh_all,
3450                 (void *)&cmd_config_thresh_name,
3451                 (void *)&cmd_config_thresh_value,
3452                 NULL,
3453         },
3454 };
3455
3456 /* *** configure free/rs threshold *** */
3457 struct cmd_config_threshold {
3458         cmdline_fixed_string_t port;
3459         cmdline_fixed_string_t keyword;
3460         cmdline_fixed_string_t all;
3461         cmdline_fixed_string_t name;
3462         uint16_t value;
3463 };
3464
3465 static void
3466 cmd_config_threshold_parsed(void *parsed_result,
3467                         __rte_unused struct cmdline *cl,
3468                         __rte_unused void *data)
3469 {
3470         struct cmd_config_threshold *res = parsed_result;
3471
3472         if (!all_ports_stopped()) {
3473                 printf("Please stop all ports first\n");
3474                 return;
3475         }
3476
3477         if (!strcmp(res->name, "txfreet"))
3478                 tx_free_thresh = res->value;
3479         else if (!strcmp(res->name, "txrst"))
3480                 tx_rs_thresh = res->value;
3481         else if (!strcmp(res->name, "rxfreet"))
3482                 rx_free_thresh = res->value;
3483         else {
3484                 printf("Unknown parameter\n");
3485                 return;
3486         }
3487
3488         init_port_config();
3489
3490         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3491 }
3492
3493 cmdline_parse_token_string_t cmd_config_threshold_port =
3494         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3495 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3496         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3497                                                                 "config");
3498 cmdline_parse_token_string_t cmd_config_threshold_all =
3499         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3500 cmdline_parse_token_string_t cmd_config_threshold_name =
3501         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3502                                                 "txfreet#txrst#rxfreet");
3503 cmdline_parse_token_num_t cmd_config_threshold_value =
3504         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3505
3506 cmdline_parse_inst_t cmd_config_threshold = {
3507         .f = cmd_config_threshold_parsed,
3508         .data = NULL,
3509         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3510         .tokens = {
3511                 (void *)&cmd_config_threshold_port,
3512                 (void *)&cmd_config_threshold_keyword,
3513                 (void *)&cmd_config_threshold_all,
3514                 (void *)&cmd_config_threshold_name,
3515                 (void *)&cmd_config_threshold_value,
3516                 NULL,
3517         },
3518 };
3519
3520 /* *** stop *** */
3521 struct cmd_stop_result {
3522         cmdline_fixed_string_t stop;
3523 };
3524
3525 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3526                             __rte_unused struct cmdline *cl,
3527                             __rte_unused void *data)
3528 {
3529         stop_packet_forwarding();
3530 }
3531
3532 cmdline_parse_token_string_t cmd_stop_stop =
3533         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3534
3535 cmdline_parse_inst_t cmd_stop = {
3536         .f = cmd_stop_parsed,
3537         .data = NULL,
3538         .help_str = "stop: Stop packet forwarding",
3539         .tokens = {
3540                 (void *)&cmd_stop_stop,
3541                 NULL,
3542         },
3543 };
3544
3545 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3546
3547 unsigned int
3548 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3549                 unsigned int *parsed_items, int check_unique_values)
3550 {
3551         unsigned int nb_item;
3552         unsigned int value;
3553         unsigned int i;
3554         unsigned int j;
3555         int value_ok;
3556         char c;
3557
3558         /*
3559          * First parse all items in the list and store their value.
3560          */
3561         value = 0;
3562         nb_item = 0;
3563         value_ok = 0;
3564         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3565                 c = str[i];
3566                 if ((c >= '0') && (c <= '9')) {
3567                         value = (unsigned int) (value * 10 + (c - '0'));
3568                         value_ok = 1;
3569                         continue;
3570                 }
3571                 if (c != ',') {
3572                         printf("character %c is not a decimal digit\n", c);
3573                         return 0;
3574                 }
3575                 if (! value_ok) {
3576                         printf("No valid value before comma\n");
3577                         return 0;
3578                 }
3579                 if (nb_item < max_items) {
3580                         parsed_items[nb_item] = value;
3581                         value_ok = 0;
3582                         value = 0;
3583                 }
3584                 nb_item++;
3585         }
3586         if (nb_item >= max_items) {
3587                 printf("Number of %s = %u > %u (maximum items)\n",
3588                        item_name, nb_item + 1, max_items);
3589                 return 0;
3590         }
3591         parsed_items[nb_item++] = value;
3592         if (! check_unique_values)
3593                 return nb_item;
3594
3595         /*
3596          * Then, check that all values in the list are differents.
3597          * No optimization here...
3598          */
3599         for (i = 0; i < nb_item; i++) {
3600                 for (j = i + 1; j < nb_item; j++) {
3601                         if (parsed_items[j] == parsed_items[i]) {
3602                                 printf("duplicated %s %u at index %u and %u\n",
3603                                        item_name, parsed_items[i], i, j);
3604                                 return 0;
3605                         }
3606                 }
3607         }
3608         return nb_item;
3609 }
3610
3611 struct cmd_set_list_result {
3612         cmdline_fixed_string_t cmd_keyword;
3613         cmdline_fixed_string_t list_name;
3614         cmdline_fixed_string_t list_of_items;
3615 };
3616
3617 static void cmd_set_list_parsed(void *parsed_result,
3618                                 __rte_unused struct cmdline *cl,
3619                                 __rte_unused void *data)
3620 {
3621         struct cmd_set_list_result *res;
3622         union {
3623                 unsigned int lcorelist[RTE_MAX_LCORE];
3624                 unsigned int portlist[RTE_MAX_ETHPORTS];
3625         } parsed_items;
3626         unsigned int nb_item;
3627
3628         if (test_done == 0) {
3629                 printf("Please stop forwarding first\n");
3630                 return;
3631         }
3632
3633         res = parsed_result;
3634         if (!strcmp(res->list_name, "corelist")) {
3635                 nb_item = parse_item_list(res->list_of_items, "core",
3636                                           RTE_MAX_LCORE,
3637                                           parsed_items.lcorelist, 1);
3638                 if (nb_item > 0) {
3639                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3640                         fwd_config_setup();
3641                 }
3642                 return;
3643         }
3644         if (!strcmp(res->list_name, "portlist")) {
3645                 nb_item = parse_item_list(res->list_of_items, "port",
3646                                           RTE_MAX_ETHPORTS,
3647                                           parsed_items.portlist, 1);
3648                 if (nb_item > 0) {
3649                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3650                         fwd_config_setup();
3651                 }
3652         }
3653 }
3654
3655 cmdline_parse_token_string_t cmd_set_list_keyword =
3656         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3657                                  "set");
3658 cmdline_parse_token_string_t cmd_set_list_name =
3659         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3660                                  "corelist#portlist");
3661 cmdline_parse_token_string_t cmd_set_list_of_items =
3662         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3663                                  NULL);
3664
3665 cmdline_parse_inst_t cmd_set_fwd_list = {
3666         .f = cmd_set_list_parsed,
3667         .data = NULL,
3668         .help_str = "set corelist|portlist <list0[,list1]*>",
3669         .tokens = {
3670                 (void *)&cmd_set_list_keyword,
3671                 (void *)&cmd_set_list_name,
3672                 (void *)&cmd_set_list_of_items,
3673                 NULL,
3674         },
3675 };
3676
3677 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3678
3679 struct cmd_setmask_result {
3680         cmdline_fixed_string_t set;
3681         cmdline_fixed_string_t mask;
3682         uint64_t hexavalue;
3683 };
3684
3685 static void cmd_set_mask_parsed(void *parsed_result,
3686                                 __rte_unused struct cmdline *cl,
3687                                 __rte_unused void *data)
3688 {
3689         struct cmd_setmask_result *res = parsed_result;
3690
3691         if (test_done == 0) {
3692                 printf("Please stop forwarding first\n");
3693                 return;
3694         }
3695         if (!strcmp(res->mask, "coremask")) {
3696                 set_fwd_lcores_mask(res->hexavalue);
3697                 fwd_config_setup();
3698         } else if (!strcmp(res->mask, "portmask")) {
3699                 set_fwd_ports_mask(res->hexavalue);
3700                 fwd_config_setup();
3701         }
3702 }
3703
3704 cmdline_parse_token_string_t cmd_setmask_set =
3705         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3706 cmdline_parse_token_string_t cmd_setmask_mask =
3707         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3708                                  "coremask#portmask");
3709 cmdline_parse_token_num_t cmd_setmask_value =
3710         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3711
3712 cmdline_parse_inst_t cmd_set_fwd_mask = {
3713         .f = cmd_set_mask_parsed,
3714         .data = NULL,
3715         .help_str = "set coremask|portmask <hexadecimal value>",
3716         .tokens = {
3717                 (void *)&cmd_setmask_set,
3718                 (void *)&cmd_setmask_mask,
3719                 (void *)&cmd_setmask_value,
3720                 NULL,
3721         },
3722 };
3723
3724 /*
3725  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3726  */
3727 struct cmd_set_result {
3728         cmdline_fixed_string_t set;
3729         cmdline_fixed_string_t what;
3730         uint16_t value;
3731 };
3732
3733 static void cmd_set_parsed(void *parsed_result,
3734                            __rte_unused struct cmdline *cl,
3735                            __rte_unused void *data)
3736 {
3737         struct cmd_set_result *res = parsed_result;
3738         if (!strcmp(res->what, "nbport")) {
3739                 set_fwd_ports_number(res->value);
3740                 fwd_config_setup();
3741         } else if (!strcmp(res->what, "nbcore")) {
3742                 set_fwd_lcores_number(res->value);
3743                 fwd_config_setup();
3744         } else if (!strcmp(res->what, "burst"))
3745                 set_nb_pkt_per_burst(res->value);
3746         else if (!strcmp(res->what, "verbose"))
3747                 set_verbose_level(res->value);
3748 }
3749
3750 cmdline_parse_token_string_t cmd_set_set =
3751         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3752 cmdline_parse_token_string_t cmd_set_what =
3753         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3754                                  "nbport#nbcore#burst#verbose");
3755 cmdline_parse_token_num_t cmd_set_value =
3756         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3757
3758 cmdline_parse_inst_t cmd_set_numbers = {
3759         .f = cmd_set_parsed,
3760         .data = NULL,
3761         .help_str = "set nbport|nbcore|burst|verbose <value>",
3762         .tokens = {
3763                 (void *)&cmd_set_set,
3764                 (void *)&cmd_set_what,
3765                 (void *)&cmd_set_value,
3766                 NULL,
3767         },
3768 };
3769
3770 /* *** SET LOG LEVEL CONFIGURATION *** */
3771
3772 struct cmd_set_log_result {
3773         cmdline_fixed_string_t set;
3774         cmdline_fixed_string_t log;
3775         cmdline_fixed_string_t type;
3776         uint32_t level;
3777 };
3778
3779 static void
3780 cmd_set_log_parsed(void *parsed_result,
3781                    __rte_unused struct cmdline *cl,
3782                    __rte_unused void *data)
3783 {
3784         struct cmd_set_log_result *res;
3785         int ret;
3786
3787         res = parsed_result;
3788         if (!strcmp(res->type, "global"))
3789                 rte_log_set_global_level(res->level);
3790         else {
3791                 ret = rte_log_set_level_regexp(res->type, res->level);
3792                 if (ret < 0)
3793                         printf("Unable to set log level\n");
3794         }
3795 }
3796
3797 cmdline_parse_token_string_t cmd_set_log_set =
3798         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3799 cmdline_parse_token_string_t cmd_set_log_log =
3800         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3801 cmdline_parse_token_string_t cmd_set_log_type =
3802         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3803 cmdline_parse_token_num_t cmd_set_log_level =
3804         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3805
3806 cmdline_parse_inst_t cmd_set_log = {
3807         .f = cmd_set_log_parsed,
3808         .data = NULL,
3809         .help_str = "set log global|<type> <level>",
3810         .tokens = {
3811                 (void *)&cmd_set_log_set,
3812                 (void *)&cmd_set_log_log,
3813                 (void *)&cmd_set_log_type,
3814                 (void *)&cmd_set_log_level,
3815                 NULL,
3816         },
3817 };
3818
3819 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3820
3821 struct cmd_set_txpkts_result {
3822         cmdline_fixed_string_t cmd_keyword;
3823         cmdline_fixed_string_t txpkts;
3824         cmdline_fixed_string_t seg_lengths;
3825 };
3826
3827 static void
3828 cmd_set_txpkts_parsed(void *parsed_result,
3829                       __rte_unused struct cmdline *cl,
3830                       __rte_unused void *data)
3831 {
3832         struct cmd_set_txpkts_result *res;
3833         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3834         unsigned int nb_segs;
3835
3836         res = parsed_result;
3837         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3838                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3839         if (nb_segs > 0)
3840                 set_tx_pkt_segments(seg_lengths, nb_segs);
3841 }
3842
3843 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3844         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3845                                  cmd_keyword, "set");
3846 cmdline_parse_token_string_t cmd_set_txpkts_name =
3847         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3848                                  txpkts, "txpkts");
3849 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3850         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3851                                  seg_lengths, NULL);
3852
3853 cmdline_parse_inst_t cmd_set_txpkts = {
3854         .f = cmd_set_txpkts_parsed,
3855         .data = NULL,
3856         .help_str = "set txpkts <len0[,len1]*>",
3857         .tokens = {
3858                 (void *)&cmd_set_txpkts_keyword,
3859                 (void *)&cmd_set_txpkts_name,
3860                 (void *)&cmd_set_txpkts_lengths,
3861                 NULL,
3862         },
3863 };
3864
3865 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3866
3867 struct cmd_set_txsplit_result {
3868         cmdline_fixed_string_t cmd_keyword;
3869         cmdline_fixed_string_t txsplit;
3870         cmdline_fixed_string_t mode;
3871 };
3872
3873 static void
3874 cmd_set_txsplit_parsed(void *parsed_result,
3875                       __rte_unused struct cmdline *cl,
3876                       __rte_unused void *data)
3877 {
3878         struct cmd_set_txsplit_result *res;
3879
3880         res = parsed_result;
3881         set_tx_pkt_split(res->mode);
3882 }
3883
3884 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3885         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3886                                  cmd_keyword, "set");
3887 cmdline_parse_token_string_t cmd_set_txsplit_name =
3888         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3889                                  txsplit, "txsplit");
3890 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3891         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3892                                  mode, NULL);
3893
3894 cmdline_parse_inst_t cmd_set_txsplit = {
3895         .f = cmd_set_txsplit_parsed,
3896         .data = NULL,
3897         .help_str = "set txsplit on|off|rand",
3898         .tokens = {
3899                 (void *)&cmd_set_txsplit_keyword,
3900                 (void *)&cmd_set_txsplit_name,
3901                 (void *)&cmd_set_txsplit_mode,
3902                 NULL,
3903         },
3904 };
3905
3906 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3907 struct cmd_rx_vlan_filter_all_result {
3908         cmdline_fixed_string_t rx_vlan;
3909         cmdline_fixed_string_t what;
3910         cmdline_fixed_string_t all;
3911         portid_t port_id;
3912 };
3913
3914 static void
3915 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3916                               __rte_unused struct cmdline *cl,
3917                               __rte_unused void *data)
3918 {
3919         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3920
3921         if (!strcmp(res->what, "add"))
3922                 rx_vlan_all_filter_set(res->port_id, 1);
3923         else
3924                 rx_vlan_all_filter_set(res->port_id, 0);
3925 }
3926
3927 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3928         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3929                                  rx_vlan, "rx_vlan");
3930 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3931         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3932                                  what, "add#rm");
3933 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3934         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3935                                  all, "all");
3936 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3937         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3938                               port_id, UINT16);
3939
3940 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3941         .f = cmd_rx_vlan_filter_all_parsed,
3942         .data = NULL,
3943         .help_str = "rx_vlan add|rm all <port_id>: "
3944                 "Add/Remove all identifiers to/from the set of VLAN "
3945                 "identifiers filtered by a port",
3946         .tokens = {
3947                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3948                 (void *)&cmd_rx_vlan_filter_all_what,
3949                 (void *)&cmd_rx_vlan_filter_all_all,
3950                 (void *)&cmd_rx_vlan_filter_all_portid,
3951                 NULL,
3952         },
3953 };
3954
3955 /* *** VLAN OFFLOAD SET ON A PORT *** */
3956 struct cmd_vlan_offload_result {
3957         cmdline_fixed_string_t vlan;
3958         cmdline_fixed_string_t set;
3959         cmdline_fixed_string_t vlan_type;
3960         cmdline_fixed_string_t what;
3961         cmdline_fixed_string_t on;
3962         cmdline_fixed_string_t port_id;
3963 };
3964
3965 static void
3966 cmd_vlan_offload_parsed(void *parsed_result,
3967                           __rte_unused struct cmdline *cl,
3968                           __rte_unused void *data)
3969 {
3970         int on;
3971         struct cmd_vlan_offload_result *res = parsed_result;
3972         char *str;
3973         int i, len = 0;
3974         portid_t port_id = 0;
3975         unsigned int tmp;
3976
3977         str = res->port_id;
3978         len = strnlen(str, STR_TOKEN_SIZE);
3979         i = 0;
3980         /* Get port_id first */
3981         while(i < len){
3982                 if(str[i] == ',')
3983                         break;
3984
3985                 i++;
3986         }
3987         str[i]='\0';
3988         tmp = strtoul(str, NULL, 0);
3989         /* If port_id greater that what portid_t can represent, return */
3990         if(tmp >= RTE_MAX_ETHPORTS)
3991                 return;
3992         port_id = (portid_t)tmp;
3993
3994         if (!strcmp(res->on, "on"))
3995                 on = 1;
3996         else
3997                 on = 0;
3998
3999         if (!strcmp(res->what, "strip"))
4000                 rx_vlan_strip_set(port_id,  on);
4001         else if(!strcmp(res->what, "stripq")){
4002                 uint16_t queue_id = 0;
4003
4004                 /* No queue_id, return */
4005                 if(i + 1 >= len) {
4006                         printf("must specify (port,queue_id)\n");
4007                         return;
4008                 }
4009                 tmp = strtoul(str + i + 1, NULL, 0);
4010                 /* If queue_id greater that what 16-bits can represent, return */
4011                 if(tmp > 0xffff)
4012                         return;
4013
4014                 queue_id = (uint16_t)tmp;
4015                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4016         }
4017         else if (!strcmp(res->what, "filter"))
4018                 rx_vlan_filter_set(port_id, on);
4019         else if (!strcmp(res->what, "qinq_strip"))
4020                 rx_vlan_qinq_strip_set(port_id, on);
4021         else
4022                 vlan_extend_set(port_id, on);
4023
4024         return;
4025 }
4026
4027 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4028         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4029                                  vlan, "vlan");
4030 cmdline_parse_token_string_t cmd_vlan_offload_set =
4031         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4032                                  set, "set");
4033 cmdline_parse_token_string_t cmd_vlan_offload_what =
4034         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4035                                 what, "strip#filter#qinq_strip#extend#stripq");
4036 cmdline_parse_token_string_t cmd_vlan_offload_on =
4037         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4038                               on, "on#off");
4039 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4040         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4041                               port_id, NULL);
4042
4043 cmdline_parse_inst_t cmd_vlan_offload = {
4044         .f = cmd_vlan_offload_parsed,
4045         .data = NULL,
4046         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4047                 "<port_id[,queue_id]>: "
4048                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4049         .tokens = {
4050                 (void *)&cmd_vlan_offload_vlan,
4051                 (void *)&cmd_vlan_offload_set,
4052                 (void *)&cmd_vlan_offload_what,
4053                 (void *)&cmd_vlan_offload_on,
4054                 (void *)&cmd_vlan_offload_portid,
4055                 NULL,
4056         },
4057 };
4058
4059 /* *** VLAN TPID SET ON A PORT *** */
4060 struct cmd_vlan_tpid_result {
4061         cmdline_fixed_string_t vlan;
4062         cmdline_fixed_string_t set;
4063         cmdline_fixed_string_t vlan_type;
4064         cmdline_fixed_string_t what;
4065         uint16_t tp_id;
4066         portid_t port_id;
4067 };
4068
4069 static void
4070 cmd_vlan_tpid_parsed(void *parsed_result,
4071                           __rte_unused struct cmdline *cl,
4072                           __rte_unused void *data)
4073 {
4074         struct cmd_vlan_tpid_result *res = parsed_result;
4075         enum rte_vlan_type vlan_type;
4076
4077         if (!strcmp(res->vlan_type, "inner"))
4078                 vlan_type = ETH_VLAN_TYPE_INNER;
4079         else if (!strcmp(res->vlan_type, "outer"))
4080                 vlan_type = ETH_VLAN_TYPE_OUTER;
4081         else {
4082                 printf("Unknown vlan type\n");
4083                 return;
4084         }
4085         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4086 }
4087
4088 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4089         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4090                                  vlan, "vlan");
4091 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4092         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4093                                  set, "set");
4094 cmdline_parse_token_string_t cmd_vlan_type =
4095         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4096                                  vlan_type, "inner#outer");
4097 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4098         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4099                                  what, "tpid");
4100 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4101         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4102                               tp_id, UINT16);
4103 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4104         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4105                               port_id, UINT16);
4106
4107 cmdline_parse_inst_t cmd_vlan_tpid = {
4108         .f = cmd_vlan_tpid_parsed,
4109         .data = NULL,
4110         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4111                 "Set the VLAN Ether type",
4112         .tokens = {
4113                 (void *)&cmd_vlan_tpid_vlan,
4114                 (void *)&cmd_vlan_tpid_set,
4115                 (void *)&cmd_vlan_type,
4116                 (void *)&cmd_vlan_tpid_what,
4117                 (void *)&cmd_vlan_tpid_tpid,
4118                 (void *)&cmd_vlan_tpid_portid,
4119                 NULL,
4120         },
4121 };
4122
4123 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4124 struct cmd_rx_vlan_filter_result {
4125         cmdline_fixed_string_t rx_vlan;
4126         cmdline_fixed_string_t what;
4127         uint16_t vlan_id;
4128         portid_t port_id;
4129 };
4130
4131 static void
4132 cmd_rx_vlan_filter_parsed(void *parsed_result,
4133                           __rte_unused struct cmdline *cl,
4134                           __rte_unused void *data)
4135 {
4136         struct cmd_rx_vlan_filter_result *res = parsed_result;
4137
4138         if (!strcmp(res->what, "add"))
4139                 rx_vft_set(res->port_id, res->vlan_id, 1);
4140         else
4141                 rx_vft_set(res->port_id, res->vlan_id, 0);
4142 }
4143
4144 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4145         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4146                                  rx_vlan, "rx_vlan");
4147 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4148         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4149                                  what, "add#rm");
4150 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4151         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4152                               vlan_id, UINT16);
4153 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4154         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4155                               port_id, UINT16);
4156
4157 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4158         .f = cmd_rx_vlan_filter_parsed,
4159         .data = NULL,
4160         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4161                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4162                 "identifiers filtered by a port",
4163         .tokens = {
4164                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4165                 (void *)&cmd_rx_vlan_filter_what,
4166                 (void *)&cmd_rx_vlan_filter_vlanid,
4167                 (void *)&cmd_rx_vlan_filter_portid,
4168                 NULL,
4169         },
4170 };
4171
4172 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4173 struct cmd_tx_vlan_set_result {
4174         cmdline_fixed_string_t tx_vlan;
4175         cmdline_fixed_string_t set;
4176         portid_t port_id;
4177         uint16_t vlan_id;
4178 };
4179
4180 static void
4181 cmd_tx_vlan_set_parsed(void *parsed_result,
4182                        __rte_unused struct cmdline *cl,
4183                        __rte_unused void *data)
4184 {
4185         struct cmd_tx_vlan_set_result *res = parsed_result;
4186
4187         if (!port_is_stopped(res->port_id)) {
4188                 printf("Please stop port %d first\n", res->port_id);
4189                 return;
4190         }
4191
4192         tx_vlan_set(res->port_id, res->vlan_id);
4193
4194         cmd_reconfig_device_queue(res->port_id, 1, 1);
4195 }
4196
4197 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4198         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4199                                  tx_vlan, "tx_vlan");
4200 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4201         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4202                                  set, "set");
4203 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4204         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4205                               port_id, UINT16);
4206 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4207         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4208                               vlan_id, UINT16);
4209
4210 cmdline_parse_inst_t cmd_tx_vlan_set = {
4211         .f = cmd_tx_vlan_set_parsed,
4212         .data = NULL,
4213         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4214                 "Enable hardware insertion of a single VLAN header "
4215                 "with a given TAG Identifier in packets sent on a port",
4216         .tokens = {
4217                 (void *)&cmd_tx_vlan_set_tx_vlan,
4218                 (void *)&cmd_tx_vlan_set_set,
4219                 (void *)&cmd_tx_vlan_set_portid,
4220                 (void *)&cmd_tx_vlan_set_vlanid,
4221                 NULL,
4222         },
4223 };
4224
4225 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4226 struct cmd_tx_vlan_set_qinq_result {
4227         cmdline_fixed_string_t tx_vlan;
4228         cmdline_fixed_string_t set;
4229         portid_t port_id;
4230         uint16_t vlan_id;
4231         uint16_t vlan_id_outer;
4232 };
4233
4234 static void
4235 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4236                             __rte_unused struct cmdline *cl,
4237                             __rte_unused void *data)
4238 {
4239         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4240
4241         if (!port_is_stopped(res->port_id)) {
4242                 printf("Please stop port %d first\n", res->port_id);
4243                 return;
4244         }
4245
4246         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4247
4248         cmd_reconfig_device_queue(res->port_id, 1, 1);
4249 }
4250
4251 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4252         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4253                 tx_vlan, "tx_vlan");
4254 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4255         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4256                 set, "set");
4257 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4258         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4259                 port_id, UINT16);
4260 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4261         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4262                 vlan_id, UINT16);
4263 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4264         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4265                 vlan_id_outer, UINT16);
4266
4267 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4268         .f = cmd_tx_vlan_set_qinq_parsed,
4269         .data = NULL,
4270         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4271                 "Enable hardware insertion of double VLAN header "
4272                 "with given TAG Identifiers in packets sent on a port",
4273         .tokens = {
4274                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4275                 (void *)&cmd_tx_vlan_set_qinq_set,
4276                 (void *)&cmd_tx_vlan_set_qinq_portid,
4277                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4278                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4279                 NULL,
4280         },
4281 };
4282
4283 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4284 struct cmd_tx_vlan_set_pvid_result {
4285         cmdline_fixed_string_t tx_vlan;
4286         cmdline_fixed_string_t set;
4287         cmdline_fixed_string_t pvid;
4288         portid_t port_id;
4289         uint16_t vlan_id;
4290         cmdline_fixed_string_t mode;
4291 };
4292
4293 static void
4294 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4295                             __rte_unused struct cmdline *cl,
4296                             __rte_unused void *data)
4297 {
4298         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4299
4300         if (strcmp(res->mode, "on") == 0)
4301                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4302         else
4303                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4304 }
4305
4306 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4307         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4308                                  tx_vlan, "tx_vlan");
4309 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4310         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4311                                  set, "set");
4312 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4313         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4314                                  pvid, "pvid");
4315 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4316         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4317                              port_id, UINT16);
4318 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4319         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4320                               vlan_id, UINT16);
4321 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4322         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4323                                  mode, "on#off");
4324
4325 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4326         .f = cmd_tx_vlan_set_pvid_parsed,
4327         .data = NULL,
4328         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4329         .tokens = {
4330                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4331                 (void *)&cmd_tx_vlan_set_pvid_set,
4332                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4333                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4334                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4335                 (void *)&cmd_tx_vlan_set_pvid_mode,
4336                 NULL,
4337         },
4338 };
4339
4340 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4341 struct cmd_tx_vlan_reset_result {
4342         cmdline_fixed_string_t tx_vlan;
4343         cmdline_fixed_string_t reset;
4344         portid_t port_id;
4345 };
4346
4347 static void
4348 cmd_tx_vlan_reset_parsed(void *parsed_result,
4349                          __rte_unused struct cmdline *cl,
4350                          __rte_unused void *data)
4351 {
4352         struct cmd_tx_vlan_reset_result *res = parsed_result;
4353
4354         if (!port_is_stopped(res->port_id)) {
4355                 printf("Please stop port %d first\n", res->port_id);
4356                 return;
4357         }
4358
4359         tx_vlan_reset(res->port_id);
4360
4361         cmd_reconfig_device_queue(res->port_id, 1, 1);
4362 }
4363
4364 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4365         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4366                                  tx_vlan, "tx_vlan");
4367 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4368         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4369                                  reset, "reset");
4370 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4371         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4372                               port_id, UINT16);
4373
4374 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4375         .f = cmd_tx_vlan_reset_parsed,
4376         .data = NULL,
4377         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4378                 "VLAN header in packets sent on a port",
4379         .tokens = {
4380                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4381                 (void *)&cmd_tx_vlan_reset_reset,
4382                 (void *)&cmd_tx_vlan_reset_portid,
4383                 NULL,
4384         },
4385 };
4386
4387
4388 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4389 struct cmd_csum_result {
4390         cmdline_fixed_string_t csum;
4391         cmdline_fixed_string_t mode;
4392         cmdline_fixed_string_t proto;
4393         cmdline_fixed_string_t hwsw;
4394         portid_t port_id;
4395 };
4396
4397 static void
4398 csum_show(int port_id)
4399 {
4400         struct rte_eth_dev_info dev_info;
4401         uint64_t tx_offloads;
4402         int ret;
4403
4404         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4405         printf("Parse tunnel is %s\n",
4406                 (ports[port_id].parse_tunnel) ? "on" : "off");
4407         printf("IP checksum offload is %s\n",
4408                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4409         printf("UDP checksum offload is %s\n",
4410                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4411         printf("TCP checksum offload is %s\n",
4412                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4413         printf("SCTP checksum offload is %s\n",
4414                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4415         printf("Outer-Ip checksum offload is %s\n",
4416                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4417         printf("Outer-Udp checksum offload is %s\n",
4418                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4419
4420         /* display warnings if configuration is not supported by the NIC */
4421         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4422         if (ret != 0)
4423                 return;
4424
4425         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4426                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4427                 printf("Warning: hardware IP checksum enabled but not "
4428                         "supported by port %d\n", port_id);
4429         }
4430         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4431                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4432                 printf("Warning: hardware UDP checksum enabled but not "
4433                         "supported by port %d\n", port_id);
4434         }
4435         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4436                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4437                 printf("Warning: hardware TCP checksum enabled but not "
4438                         "supported by port %d\n", port_id);
4439         }
4440         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4441                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4442                 printf("Warning: hardware SCTP checksum enabled but not "
4443                         "supported by port %d\n", port_id);
4444         }
4445         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4446                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4447                 printf("Warning: hardware outer IP checksum enabled but not "
4448                         "supported by port %d\n", port_id);
4449         }
4450         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4451                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4452                         == 0) {
4453                 printf("Warning: hardware outer UDP checksum enabled but not "
4454                         "supported by port %d\n", port_id);
4455         }
4456 }
4457
4458 static void
4459 cmd_config_queue_tx_offloads(struct rte_port *port)
4460 {
4461         int k;
4462
4463         /* Apply queue tx offloads configuration */
4464         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4465                 port->tx_conf[k].offloads =
4466                         port->dev_conf.txmode.offloads;
4467 }
4468
4469 static void
4470 cmd_csum_parsed(void *parsed_result,
4471                        __rte_unused struct cmdline *cl,
4472                        __rte_unused void *data)
4473 {
4474         struct cmd_csum_result *res = parsed_result;
4475         int hw = 0;
4476         uint64_t csum_offloads = 0;
4477         struct rte_eth_dev_info dev_info;
4478         int ret;
4479
4480         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4481                 printf("invalid port %d\n", res->port_id);
4482                 return;
4483         }
4484         if (!port_is_stopped(res->port_id)) {
4485                 printf("Please stop port %d first\n", res->port_id);
4486                 return;
4487         }
4488
4489         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4490         if (ret != 0)
4491                 return;
4492
4493         if (!strcmp(res->mode, "set")) {
4494
4495                 if (!strcmp(res->hwsw, "hw"))
4496                         hw = 1;
4497
4498                 if (!strcmp(res->proto, "ip")) {
4499                         if (hw == 0 || (dev_info.tx_offload_capa &
4500                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4501                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4502                         } else {
4503                                 printf("IP checksum offload is not supported "
4504                                        "by port %u\n", res->port_id);
4505                         }
4506                 } else if (!strcmp(res->proto, "udp")) {
4507                         if (hw == 0 || (dev_info.tx_offload_capa &
4508                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4509                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4510                         } else {
4511                                 printf("UDP checksum offload is not supported "
4512                                        "by port %u\n", res->port_id);
4513                         }
4514                 } else if (!strcmp(res->proto, "tcp")) {
4515                         if (hw == 0 || (dev_info.tx_offload_capa &
4516                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4517                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4518                         } else {
4519                                 printf("TCP checksum offload is not supported "
4520                                        "by port %u\n", res->port_id);
4521                         }
4522                 } else if (!strcmp(res->proto, "sctp")) {
4523                         if (hw == 0 || (dev_info.tx_offload_capa &
4524                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4525                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4526                         } else {
4527                                 printf("SCTP checksum offload is not supported "
4528                                        "by port %u\n", res->port_id);
4529                         }
4530                 } else if (!strcmp(res->proto, "outer-ip")) {
4531                         if (hw == 0 || (dev_info.tx_offload_capa &
4532                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4533                                 csum_offloads |=
4534                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4535                         } else {
4536                                 printf("Outer IP checksum offload is not "
4537                                        "supported by port %u\n", res->port_id);
4538                         }
4539                 } else if (!strcmp(res->proto, "outer-udp")) {
4540                         if (hw == 0 || (dev_info.tx_offload_capa &
4541                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4542                                 csum_offloads |=
4543                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4544                         } else {
4545                                 printf("Outer UDP checksum offload is not "
4546                                        "supported by port %u\n", res->port_id);
4547                         }
4548                 }
4549
4550                 if (hw) {
4551                         ports[res->port_id].dev_conf.txmode.offloads |=
4552                                                         csum_offloads;
4553                 } else {
4554                         ports[res->port_id].dev_conf.txmode.offloads &=
4555                                                         (~csum_offloads);
4556                 }
4557                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4558         }
4559         csum_show(res->port_id);
4560
4561         cmd_reconfig_device_queue(res->port_id, 1, 1);
4562 }
4563
4564 cmdline_parse_token_string_t cmd_csum_csum =
4565         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4566                                 csum, "csum");
4567 cmdline_parse_token_string_t cmd_csum_mode =
4568         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4569                                 mode, "set");
4570 cmdline_parse_token_string_t cmd_csum_proto =
4571         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4572                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4573 cmdline_parse_token_string_t cmd_csum_hwsw =
4574         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4575                                 hwsw, "hw#sw");
4576 cmdline_parse_token_num_t cmd_csum_portid =
4577         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4578                                 port_id, UINT16);
4579
4580 cmdline_parse_inst_t cmd_csum_set = {
4581         .f = cmd_csum_parsed,
4582         .data = NULL,
4583         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4584                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4585                 "using csum forward engine",
4586         .tokens = {
4587                 (void *)&cmd_csum_csum,
4588                 (void *)&cmd_csum_mode,
4589                 (void *)&cmd_csum_proto,
4590                 (void *)&cmd_csum_hwsw,
4591                 (void *)&cmd_csum_portid,
4592                 NULL,
4593         },
4594 };
4595
4596 cmdline_parse_token_string_t cmd_csum_mode_show =
4597         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4598                                 mode, "show");
4599
4600 cmdline_parse_inst_t cmd_csum_show = {
4601         .f = cmd_csum_parsed,
4602         .data = NULL,
4603         .help_str = "csum show <port_id>: Show checksum offload configuration",
4604         .tokens = {
4605                 (void *)&cmd_csum_csum,
4606                 (void *)&cmd_csum_mode_show,
4607                 (void *)&cmd_csum_portid,
4608                 NULL,
4609         },
4610 };
4611
4612 /* Enable/disable tunnel parsing */
4613 struct cmd_csum_tunnel_result {
4614         cmdline_fixed_string_t csum;
4615         cmdline_fixed_string_t parse;
4616         cmdline_fixed_string_t onoff;
4617         portid_t port_id;
4618 };
4619
4620 static void
4621 cmd_csum_tunnel_parsed(void *parsed_result,
4622                        __rte_unused struct cmdline *cl,
4623                        __rte_unused void *data)
4624 {
4625         struct cmd_csum_tunnel_result *res = parsed_result;
4626
4627         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4628                 return;
4629
4630         if (!strcmp(res->onoff, "on"))
4631                 ports[res->port_id].parse_tunnel = 1;
4632         else
4633                 ports[res->port_id].parse_tunnel = 0;
4634
4635         csum_show(res->port_id);
4636 }
4637
4638 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4639         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4640                                 csum, "csum");
4641 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4642         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4643                                 parse, "parse-tunnel");
4644 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4645         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4646                                 onoff, "on#off");
4647 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4648         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4649                                 port_id, UINT16);
4650
4651 cmdline_parse_inst_t cmd_csum_tunnel = {
4652         .f = cmd_csum_tunnel_parsed,
4653         .data = NULL,
4654         .help_str = "csum parse-tunnel on|off <port_id>: "
4655                 "Enable/Disable parsing of tunnels for csum engine",
4656         .tokens = {
4657                 (void *)&cmd_csum_tunnel_csum,
4658                 (void *)&cmd_csum_tunnel_parse,
4659                 (void *)&cmd_csum_tunnel_onoff,
4660                 (void *)&cmd_csum_tunnel_portid,
4661                 NULL,
4662         },
4663 };
4664
4665 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4666 struct cmd_tso_set_result {
4667         cmdline_fixed_string_t tso;
4668         cmdline_fixed_string_t mode;
4669         uint16_t tso_segsz;
4670         portid_t port_id;
4671 };
4672
4673 static void
4674 cmd_tso_set_parsed(void *parsed_result,
4675                        __rte_unused struct cmdline *cl,
4676                        __rte_unused void *data)
4677 {
4678         struct cmd_tso_set_result *res = parsed_result;
4679         struct rte_eth_dev_info dev_info;
4680         int ret;
4681
4682         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4683                 return;
4684         if (!port_is_stopped(res->port_id)) {
4685                 printf("Please stop port %d first\n", res->port_id);
4686                 return;
4687         }
4688
4689         if (!strcmp(res->mode, "set"))
4690                 ports[res->port_id].tso_segsz = res->tso_segsz;
4691
4692         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4693         if (ret != 0)
4694                 return;
4695
4696         if ((ports[res->port_id].tso_segsz != 0) &&
4697                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4698                 printf("Error: TSO is not supported by port %d\n",
4699                        res->port_id);
4700                 return;
4701         }
4702
4703         if (ports[res->port_id].tso_segsz == 0) {
4704                 ports[res->port_id].dev_conf.txmode.offloads &=
4705                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4706                 printf("TSO for non-tunneled packets is disabled\n");
4707         } else {
4708                 ports[res->port_id].dev_conf.txmode.offloads |=
4709                                                 DEV_TX_OFFLOAD_TCP_TSO;
4710                 printf("TSO segment size for non-tunneled packets is %d\n",
4711                         ports[res->port_id].tso_segsz);
4712         }
4713         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4714
4715         /* display warnings if configuration is not supported by the NIC */
4716         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4717         if (ret != 0)
4718                 return;
4719
4720         if ((ports[res->port_id].tso_segsz != 0) &&
4721                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4722                 printf("Warning: TSO enabled but not "
4723                         "supported by port %d\n", res->port_id);
4724         }
4725
4726         cmd_reconfig_device_queue(res->port_id, 1, 1);
4727 }
4728
4729 cmdline_parse_token_string_t cmd_tso_set_tso =
4730         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4731                                 tso, "tso");
4732 cmdline_parse_token_string_t cmd_tso_set_mode =
4733         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4734                                 mode, "set");
4735 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4736         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4737                                 tso_segsz, UINT16);
4738 cmdline_parse_token_num_t cmd_tso_set_portid =
4739         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4740                                 port_id, UINT16);
4741
4742 cmdline_parse_inst_t cmd_tso_set = {
4743         .f = cmd_tso_set_parsed,
4744         .data = NULL,
4745         .help_str = "tso set <tso_segsz> <port_id>: "
4746                 "Set TSO segment size of non-tunneled packets for csum engine "
4747                 "(0 to disable)",
4748         .tokens = {
4749                 (void *)&cmd_tso_set_tso,
4750                 (void *)&cmd_tso_set_mode,
4751                 (void *)&cmd_tso_set_tso_segsz,
4752                 (void *)&cmd_tso_set_portid,
4753                 NULL,
4754         },
4755 };
4756
4757 cmdline_parse_token_string_t cmd_tso_show_mode =
4758         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4759                                 mode, "show");
4760
4761
4762 cmdline_parse_inst_t cmd_tso_show = {
4763         .f = cmd_tso_set_parsed,
4764         .data = NULL,
4765         .help_str = "tso show <port_id>: "
4766                 "Show TSO segment size of non-tunneled packets for csum engine",
4767         .tokens = {
4768                 (void *)&cmd_tso_set_tso,
4769                 (void *)&cmd_tso_show_mode,
4770                 (void *)&cmd_tso_set_portid,
4771                 NULL,
4772         },
4773 };
4774
4775 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4776 struct cmd_tunnel_tso_set_result {
4777         cmdline_fixed_string_t tso;
4778         cmdline_fixed_string_t mode;
4779         uint16_t tso_segsz;
4780         portid_t port_id;
4781 };
4782
4783 static struct rte_eth_dev_info
4784 check_tunnel_tso_nic_support(portid_t port_id)
4785 {
4786         struct rte_eth_dev_info dev_info;
4787
4788         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4789                 return dev_info;
4790
4791         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4792                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4793                        "not enabled for port %d\n", port_id);
4794         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4795                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4796                        "not enabled for port %d\n", port_id);
4797         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4798                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4799                        "not enabled for port %d\n", port_id);
4800         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4801                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4802                        "not enabled for port %d\n", port_id);
4803         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4804                 printf("Warning: IP TUNNEL TSO not supported therefore "
4805                        "not enabled for port %d\n", port_id);
4806         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4807                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4808                        "not enabled for port %d\n", port_id);
4809         return dev_info;
4810 }
4811
4812 static void
4813 cmd_tunnel_tso_set_parsed(void *parsed_result,
4814                           __rte_unused struct cmdline *cl,
4815                           __rte_unused void *data)
4816 {
4817         struct cmd_tunnel_tso_set_result *res = parsed_result;
4818         struct rte_eth_dev_info dev_info;
4819
4820         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4821                 return;
4822         if (!port_is_stopped(res->port_id)) {
4823                 printf("Please stop port %d first\n", res->port_id);
4824                 return;
4825         }
4826
4827         if (!strcmp(res->mode, "set"))
4828                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4829
4830         dev_info = check_tunnel_tso_nic_support(res->port_id);
4831         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4832                 ports[res->port_id].dev_conf.txmode.offloads &=
4833                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4834                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4835                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4836                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4837                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4838                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4839                 printf("TSO for tunneled packets is disabled\n");
4840         } else {
4841                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4842                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4843                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4844                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4845                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4846                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4847
4848                 ports[res->port_id].dev_conf.txmode.offloads |=
4849                         (tso_offloads & dev_info.tx_offload_capa);
4850                 printf("TSO segment size for tunneled packets is %d\n",
4851                         ports[res->port_id].tunnel_tso_segsz);
4852
4853                 /* Below conditions are needed to make it work:
4854                  * (1) tunnel TSO is supported by the NIC;
4855                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4856                  * are recognized;
4857                  * (3) for tunneled pkts with outer L3 of IPv4,
4858                  * "csum set outer-ip" must be set to hw, because after tso,
4859                  * total_len of outer IP header is changed, and the checksum
4860                  * of outer IP header calculated by sw should be wrong; that
4861                  * is not necessary for IPv6 tunneled pkts because there's no
4862                  * checksum in IP header anymore.
4863                  */
4864
4865                 if (!ports[res->port_id].parse_tunnel)
4866                         printf("Warning: csum parse_tunnel must be set "
4867                                 "so that tunneled packets are recognized\n");
4868                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4869                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4870                         printf("Warning: csum set outer-ip must be set to hw "
4871                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4872         }
4873
4874         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4875         cmd_reconfig_device_queue(res->port_id, 1, 1);
4876 }
4877
4878 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4879         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4880                                 tso, "tunnel_tso");
4881 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4882         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4883                                 mode, "set");
4884 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4885         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4886                                 tso_segsz, UINT16);
4887 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4888         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4889                                 port_id, UINT16);
4890
4891 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4892         .f = cmd_tunnel_tso_set_parsed,
4893         .data = NULL,
4894         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4895                 "Set TSO segment size of tunneled packets for csum engine "
4896                 "(0 to disable)",
4897         .tokens = {
4898                 (void *)&cmd_tunnel_tso_set_tso,
4899                 (void *)&cmd_tunnel_tso_set_mode,
4900                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4901                 (void *)&cmd_tunnel_tso_set_portid,
4902                 NULL,
4903         },
4904 };
4905
4906 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4907         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4908                                 mode, "show");
4909
4910
4911 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4912         .f = cmd_tunnel_tso_set_parsed,
4913         .data = NULL,
4914         .help_str = "tunnel_tso show <port_id> "
4915                 "Show TSO segment size of tunneled packets for csum engine",
4916         .tokens = {
4917                 (void *)&cmd_tunnel_tso_set_tso,
4918                 (void *)&cmd_tunnel_tso_show_mode,
4919                 (void *)&cmd_tunnel_tso_set_portid,
4920                 NULL,
4921         },
4922 };
4923
4924 /* *** SET GRO FOR A PORT *** */
4925 struct cmd_gro_enable_result {
4926         cmdline_fixed_string_t cmd_set;
4927         cmdline_fixed_string_t cmd_port;
4928         cmdline_fixed_string_t cmd_keyword;
4929         cmdline_fixed_string_t cmd_onoff;
4930         portid_t cmd_pid;
4931 };
4932
4933 static void
4934 cmd_gro_enable_parsed(void *parsed_result,
4935                 __rte_unused struct cmdline *cl,
4936                 __rte_unused void *data)
4937 {
4938         struct cmd_gro_enable_result *res;
4939
4940         res = parsed_result;
4941         if (!strcmp(res->cmd_keyword, "gro"))
4942                 setup_gro(res->cmd_onoff, res->cmd_pid);
4943 }
4944
4945 cmdline_parse_token_string_t cmd_gro_enable_set =
4946         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4947                         cmd_set, "set");
4948 cmdline_parse_token_string_t cmd_gro_enable_port =
4949         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4950                         cmd_keyword, "port");
4951 cmdline_parse_token_num_t cmd_gro_enable_pid =
4952         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4953                         cmd_pid, UINT16);
4954 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4955         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4956                         cmd_keyword, "gro");
4957 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4958         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4959                         cmd_onoff, "on#off");
4960
4961 cmdline_parse_inst_t cmd_gro_enable = {
4962         .f = cmd_gro_enable_parsed,
4963         .data = NULL,
4964         .help_str = "set port <port_id> gro on|off",
4965         .tokens = {
4966                 (void *)&cmd_gro_enable_set,
4967                 (void *)&cmd_gro_enable_port,
4968                 (void *)&cmd_gro_enable_pid,
4969                 (void *)&cmd_gro_enable_keyword,
4970                 (void *)&cmd_gro_enable_onoff,
4971                 NULL,
4972         },
4973 };
4974
4975 /* *** DISPLAY GRO CONFIGURATION *** */
4976 struct cmd_gro_show_result {
4977         cmdline_fixed_string_t cmd_show;
4978         cmdline_fixed_string_t cmd_port;
4979         cmdline_fixed_string_t cmd_keyword;
4980         portid_t cmd_pid;
4981 };
4982
4983 static void
4984 cmd_gro_show_parsed(void *parsed_result,
4985                 __rte_unused struct cmdline *cl,
4986                 __rte_unused void *data)
4987 {
4988         struct cmd_gro_show_result *res;
4989
4990         res = parsed_result;
4991         if (!strcmp(res->cmd_keyword, "gro"))
4992                 show_gro(res->cmd_pid);
4993 }
4994
4995 cmdline_parse_token_string_t cmd_gro_show_show =
4996         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4997                         cmd_show, "show");
4998 cmdline_parse_token_string_t cmd_gro_show_port =
4999         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5000                         cmd_port, "port");
5001 cmdline_parse_token_num_t cmd_gro_show_pid =
5002         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5003                         cmd_pid, UINT16);
5004 cmdline_parse_token_string_t cmd_gro_show_keyword =
5005         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5006                         cmd_keyword, "gro");
5007
5008 cmdline_parse_inst_t cmd_gro_show = {
5009         .f = cmd_gro_show_parsed,
5010         .data = NULL,
5011         .help_str = "show port <port_id> gro",
5012         .tokens = {
5013                 (void *)&cmd_gro_show_show,
5014                 (void *)&cmd_gro_show_port,
5015                 (void *)&cmd_gro_show_pid,
5016                 (void *)&cmd_gro_show_keyword,
5017                 NULL,
5018         },
5019 };
5020
5021 /* *** SET FLUSH CYCLES FOR GRO *** */
5022 struct cmd_gro_flush_result {
5023         cmdline_fixed_string_t cmd_set;
5024         cmdline_fixed_string_t cmd_keyword;
5025         cmdline_fixed_string_t cmd_flush;
5026         uint8_t cmd_cycles;
5027 };
5028
5029 static void
5030 cmd_gro_flush_parsed(void *parsed_result,
5031                 __rte_unused struct cmdline *cl,
5032                 __rte_unused void *data)
5033 {
5034         struct cmd_gro_flush_result *res;
5035
5036         res = parsed_result;
5037         if ((!strcmp(res->cmd_keyword, "gro")) &&
5038                         (!strcmp(res->cmd_flush, "flush")))
5039                 setup_gro_flush_cycles(res->cmd_cycles);
5040 }
5041
5042 cmdline_parse_token_string_t cmd_gro_flush_set =
5043         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5044                         cmd_set, "set");
5045 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5046         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5047                         cmd_keyword, "gro");
5048 cmdline_parse_token_string_t cmd_gro_flush_flush =
5049         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5050                         cmd_flush, "flush");
5051 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5052         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5053                         cmd_cycles, UINT8);
5054
5055 cmdline_parse_inst_t cmd_gro_flush = {
5056         .f = cmd_gro_flush_parsed,
5057         .data = NULL,
5058         .help_str = "set gro flush <cycles>",
5059         .tokens = {
5060                 (void *)&cmd_gro_flush_set,
5061                 (void *)&cmd_gro_flush_keyword,
5062                 (void *)&cmd_gro_flush_flush,
5063                 (void *)&cmd_gro_flush_cycles,
5064                 NULL,
5065         },
5066 };
5067
5068 /* *** ENABLE/DISABLE GSO *** */
5069 struct cmd_gso_enable_result {
5070         cmdline_fixed_string_t cmd_set;
5071         cmdline_fixed_string_t cmd_port;
5072         cmdline_fixed_string_t cmd_keyword;
5073         cmdline_fixed_string_t cmd_mode;
5074         portid_t cmd_pid;
5075 };
5076
5077 static void
5078 cmd_gso_enable_parsed(void *parsed_result,
5079                 __rte_unused struct cmdline *cl,
5080                 __rte_unused void *data)
5081 {
5082         struct cmd_gso_enable_result *res;
5083
5084         res = parsed_result;
5085         if (!strcmp(res->cmd_keyword, "gso"))
5086                 setup_gso(res->cmd_mode, res->cmd_pid);
5087 }
5088
5089 cmdline_parse_token_string_t cmd_gso_enable_set =
5090         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5091                         cmd_set, "set");
5092 cmdline_parse_token_string_t cmd_gso_enable_port =
5093         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5094                         cmd_port, "port");
5095 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5096         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5097                         cmd_keyword, "gso");
5098 cmdline_parse_token_string_t cmd_gso_enable_mode =
5099         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5100                         cmd_mode, "on#off");
5101 cmdline_parse_token_num_t cmd_gso_enable_pid =
5102         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5103                         cmd_pid, UINT16);
5104
5105 cmdline_parse_inst_t cmd_gso_enable = {
5106         .f = cmd_gso_enable_parsed,
5107         .data = NULL,
5108         .help_str = "set port <port_id> gso on|off",
5109         .tokens = {
5110                 (void *)&cmd_gso_enable_set,
5111                 (void *)&cmd_gso_enable_port,
5112                 (void *)&cmd_gso_enable_pid,
5113                 (void *)&cmd_gso_enable_keyword,
5114                 (void *)&cmd_gso_enable_mode,
5115                 NULL,
5116         },
5117 };
5118
5119 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5120 struct cmd_gso_size_result {
5121         cmdline_fixed_string_t cmd_set;
5122         cmdline_fixed_string_t cmd_keyword;
5123         cmdline_fixed_string_t cmd_segsz;
5124         uint16_t cmd_size;
5125 };
5126
5127 static void
5128 cmd_gso_size_parsed(void *parsed_result,
5129                        __rte_unused struct cmdline *cl,
5130                        __rte_unused void *data)
5131 {
5132         struct cmd_gso_size_result *res = parsed_result;
5133
5134         if (test_done == 0) {
5135                 printf("Before setting GSO segsz, please first"
5136                                 " stop fowarding\n");
5137                 return;
5138         }
5139
5140         if (!strcmp(res->cmd_keyword, "gso") &&
5141                         !strcmp(res->cmd_segsz, "segsz")) {
5142                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5143                         printf("gso_size should be larger than %zu."
5144                                         " Please input a legal value\n",
5145                                         RTE_GSO_SEG_SIZE_MIN);
5146                 else
5147                         gso_max_segment_size = res->cmd_size;
5148         }
5149 }
5150
5151 cmdline_parse_token_string_t cmd_gso_size_set =
5152         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5153                                 cmd_set, "set");
5154 cmdline_parse_token_string_t cmd_gso_size_keyword =
5155         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5156                                 cmd_keyword, "gso");
5157 cmdline_parse_token_string_t cmd_gso_size_segsz =
5158         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5159                                 cmd_segsz, "segsz");
5160 cmdline_parse_token_num_t cmd_gso_size_size =
5161         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5162                                 cmd_size, UINT16);
5163
5164 cmdline_parse_inst_t cmd_gso_size = {
5165         .f = cmd_gso_size_parsed,
5166         .data = NULL,
5167         .help_str = "set gso segsz <length>",
5168         .tokens = {
5169                 (void *)&cmd_gso_size_set,
5170                 (void *)&cmd_gso_size_keyword,
5171                 (void *)&cmd_gso_size_segsz,
5172                 (void *)&cmd_gso_size_size,
5173                 NULL,
5174         },
5175 };
5176
5177 /* *** SHOW GSO CONFIGURATION *** */
5178 struct cmd_gso_show_result {
5179         cmdline_fixed_string_t cmd_show;
5180         cmdline_fixed_string_t cmd_port;
5181         cmdline_fixed_string_t cmd_keyword;
5182         portid_t cmd_pid;
5183 };
5184
5185 static void
5186 cmd_gso_show_parsed(void *parsed_result,
5187                        __rte_unused struct cmdline *cl,
5188                        __rte_unused void *data)
5189 {
5190         struct cmd_gso_show_result *res = parsed_result;
5191
5192         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5193                 printf("invalid port id %u\n", res->cmd_pid);
5194                 return;
5195         }
5196         if (!strcmp(res->cmd_keyword, "gso")) {
5197                 if (gso_ports[res->cmd_pid].enable) {
5198                         printf("Max GSO'd packet size: %uB\n"
5199                                         "Supported GSO types: TCP/IPv4, "
5200                                         "UDP/IPv4, VxLAN with inner "
5201                                         "TCP/IPv4 packet, GRE with inner "
5202                                         "TCP/IPv4 packet\n",
5203                                         gso_max_segment_size);
5204                 } else
5205                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5206         }
5207 }
5208
5209 cmdline_parse_token_string_t cmd_gso_show_show =
5210 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5211                 cmd_show, "show");
5212 cmdline_parse_token_string_t cmd_gso_show_port =
5213 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5214                 cmd_port, "port");
5215 cmdline_parse_token_string_t cmd_gso_show_keyword =
5216         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5217                                 cmd_keyword, "gso");
5218 cmdline_parse_token_num_t cmd_gso_show_pid =
5219         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5220                                 cmd_pid, UINT16);
5221
5222 cmdline_parse_inst_t cmd_gso_show = {
5223         .f = cmd_gso_show_parsed,
5224         .data = NULL,
5225         .help_str = "show port <port_id> gso",
5226         .tokens = {
5227                 (void *)&cmd_gso_show_show,
5228                 (void *)&cmd_gso_show_port,
5229                 (void *)&cmd_gso_show_pid,
5230                 (void *)&cmd_gso_show_keyword,
5231                 NULL,
5232         },
5233 };
5234
5235 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5236 struct cmd_set_flush_rx {
5237         cmdline_fixed_string_t set;
5238         cmdline_fixed_string_t flush_rx;
5239         cmdline_fixed_string_t mode;
5240 };
5241
5242 static void
5243 cmd_set_flush_rx_parsed(void *parsed_result,
5244                 __rte_unused struct cmdline *cl,
5245                 __rte_unused void *data)
5246 {
5247         struct cmd_set_flush_rx *res = parsed_result;
5248         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5249 }
5250
5251 cmdline_parse_token_string_t cmd_setflushrx_set =
5252         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5253                         set, "set");
5254 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5255         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5256                         flush_rx, "flush_rx");
5257 cmdline_parse_token_string_t cmd_setflushrx_mode =
5258         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5259                         mode, "on#off");
5260
5261
5262 cmdline_parse_inst_t cmd_set_flush_rx = {
5263         .f = cmd_set_flush_rx_parsed,
5264         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5265         .data = NULL,
5266         .tokens = {
5267                 (void *)&cmd_setflushrx_set,
5268                 (void *)&cmd_setflushrx_flush_rx,
5269                 (void *)&cmd_setflushrx_mode,
5270                 NULL,
5271         },
5272 };
5273
5274 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5275 struct cmd_set_link_check {
5276         cmdline_fixed_string_t set;
5277         cmdline_fixed_string_t link_check;
5278         cmdline_fixed_string_t mode;
5279 };
5280
5281 static void
5282 cmd_set_link_check_parsed(void *parsed_result,
5283                 __rte_unused struct cmdline *cl,
5284                 __rte_unused void *data)
5285 {
5286         struct cmd_set_link_check *res = parsed_result;
5287         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5288 }
5289
5290 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5291         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5292                         set, "set");
5293 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5294         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5295                         link_check, "link_check");
5296 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5297         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5298                         mode, "on#off");
5299
5300
5301 cmdline_parse_inst_t cmd_set_link_check = {
5302         .f = cmd_set_link_check_parsed,
5303         .help_str = "set link_check on|off: Enable/Disable link status check "
5304                     "when starting/stopping a port",
5305         .data = NULL,
5306         .tokens = {
5307                 (void *)&cmd_setlinkcheck_set,
5308                 (void *)&cmd_setlinkcheck_link_check,
5309                 (void *)&cmd_setlinkcheck_mode,
5310                 NULL,
5311         },
5312 };
5313
5314 /* *** SET NIC BYPASS MODE *** */
5315 struct cmd_set_bypass_mode_result {
5316         cmdline_fixed_string_t set;
5317         cmdline_fixed_string_t bypass;
5318         cmdline_fixed_string_t mode;
5319         cmdline_fixed_string_t value;
5320         portid_t port_id;
5321 };
5322
5323 static void
5324 cmd_set_bypass_mode_parsed(void *parsed_result,
5325                 __rte_unused struct cmdline *cl,
5326                 __rte_unused void *data)
5327 {
5328         struct cmd_set_bypass_mode_result *res = parsed_result;
5329         portid_t port_id = res->port_id;
5330         int32_t rc = -EINVAL;
5331
5332 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5333         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5334
5335         if (!strcmp(res->value, "bypass"))
5336                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5337         else if (!strcmp(res->value, "isolate"))
5338                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5339         else
5340                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5341
5342         /* Set the bypass mode for the relevant port. */
5343         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5344 #endif
5345         if (rc != 0)
5346                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5347 }
5348
5349 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5350         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5351                         set, "set");
5352 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5353         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5354                         bypass, "bypass");
5355 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5356         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5357                         mode, "mode");
5358 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5359         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5360                         value, "normal#bypass#isolate");
5361 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5362         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5363                                 port_id, UINT16);
5364
5365 cmdline_parse_inst_t cmd_set_bypass_mode = {
5366         .f = cmd_set_bypass_mode_parsed,
5367         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5368                     "Set the NIC bypass mode for port_id",
5369         .data = NULL,
5370         .tokens = {
5371                 (void *)&cmd_setbypass_mode_set,
5372                 (void *)&cmd_setbypass_mode_bypass,
5373                 (void *)&cmd_setbypass_mode_mode,
5374                 (void *)&cmd_setbypass_mode_value,
5375                 (void *)&cmd_setbypass_mode_port,
5376                 NULL,
5377         },
5378 };
5379
5380 /* *** SET NIC BYPASS EVENT *** */
5381 struct cmd_set_bypass_event_result {
5382         cmdline_fixed_string_t set;
5383         cmdline_fixed_string_t bypass;
5384         cmdline_fixed_string_t event;
5385         cmdline_fixed_string_t event_value;
5386         cmdline_fixed_string_t mode;
5387         cmdline_fixed_string_t mode_value;
5388         portid_t port_id;
5389 };
5390
5391 static void
5392 cmd_set_bypass_event_parsed(void *parsed_result,
5393                 __rte_unused struct cmdline *cl,
5394                 __rte_unused void *data)
5395 {
5396         int32_t rc = -EINVAL;
5397         struct cmd_set_bypass_event_result *res = parsed_result;
5398         portid_t port_id = res->port_id;
5399
5400 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5401         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5402         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5403
5404         if (!strcmp(res->event_value, "timeout"))
5405                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5406         else if (!strcmp(res->event_value, "os_on"))
5407                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5408         else if (!strcmp(res->event_value, "os_off"))
5409                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5410         else if (!strcmp(res->event_value, "power_on"))
5411                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5412         else if (!strcmp(res->event_value, "power_off"))
5413                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5414         else
5415                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5416
5417         if (!strcmp(res->mode_value, "bypass"))
5418                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5419         else if (!strcmp(res->mode_value, "isolate"))
5420                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5421         else
5422                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5423
5424         /* Set the watchdog timeout. */
5425         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5426
5427                 rc = -EINVAL;
5428                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5429                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5430                                                            bypass_timeout);
5431                 }
5432                 if (rc != 0) {
5433                         printf("Failed to set timeout value %u "
5434                         "for port %d, errto code: %d.\n",
5435                         bypass_timeout, port_id, rc);
5436                 }
5437         }
5438
5439         /* Set the bypass event to transition to bypass mode. */
5440         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5441                                               bypass_mode);
5442 #endif
5443
5444         if (rc != 0)
5445                 printf("\t Failed to set bypass event for port = %d.\n",
5446                        port_id);
5447 }
5448
5449 cmdline_parse_token_string_t cmd_setbypass_event_set =
5450         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5451                         set, "set");
5452 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5453         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5454                         bypass, "bypass");
5455 cmdline_parse_token_string_t cmd_setbypass_event_event =
5456         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5457                         event, "event");
5458 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5459         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5460                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5461 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5462         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5463                         mode, "mode");
5464 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5465         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5466                         mode_value, "normal#bypass#isolate");
5467 cmdline_parse_token_num_t cmd_setbypass_event_port =
5468         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5469                                 port_id, UINT16);
5470
5471 cmdline_parse_inst_t cmd_set_bypass_event = {
5472         .f = cmd_set_bypass_event_parsed,
5473         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5474                 "power_off mode normal|bypass|isolate <port_id>: "
5475                 "Set the NIC bypass event mode for port_id",
5476         .data = NULL,
5477         .tokens = {
5478                 (void *)&cmd_setbypass_event_set,
5479                 (void *)&cmd_setbypass_event_bypass,
5480                 (void *)&cmd_setbypass_event_event,
5481                 (void *)&cmd_setbypass_event_event_value,
5482                 (void *)&cmd_setbypass_event_mode,
5483                 (void *)&cmd_setbypass_event_mode_value,
5484                 (void *)&cmd_setbypass_event_port,
5485                 NULL,
5486         },
5487 };
5488
5489
5490 /* *** SET NIC BYPASS TIMEOUT *** */
5491 struct cmd_set_bypass_timeout_result {
5492         cmdline_fixed_string_t set;
5493         cmdline_fixed_string_t bypass;
5494         cmdline_fixed_string_t timeout;
5495         cmdline_fixed_string_t value;
5496 };
5497
5498 static void
5499 cmd_set_bypass_timeout_parsed(void *parsed_result,
5500                 __rte_unused struct cmdline *cl,
5501                 __rte_unused void *data)
5502 {
5503         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5504
5505 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5506         if (!strcmp(res->value, "1.5"))
5507                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5508         else if (!strcmp(res->value, "2"))
5509                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5510         else if (!strcmp(res->value, "3"))
5511                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5512         else if (!strcmp(res->value, "4"))
5513                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5514         else if (!strcmp(res->value, "8"))
5515                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5516         else if (!strcmp(res->value, "16"))
5517                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5518         else if (!strcmp(res->value, "32"))
5519                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5520         else
5521                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5522 #endif
5523 }
5524
5525 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5526         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5527                         set, "set");
5528 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5529         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5530                         bypass, "bypass");
5531 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5532         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5533                         timeout, "timeout");
5534 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5535         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5536                         value, "0#1.5#2#3#4#8#16#32");
5537
5538 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5539         .f = cmd_set_bypass_timeout_parsed,
5540         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5541                 "Set the NIC bypass watchdog timeout in seconds",
5542         .data = NULL,
5543         .tokens = {
5544                 (void *)&cmd_setbypass_timeout_set,
5545                 (void *)&cmd_setbypass_timeout_bypass,
5546                 (void *)&cmd_setbypass_timeout_timeout,
5547                 (void *)&cmd_setbypass_timeout_value,
5548                 NULL,
5549         },
5550 };
5551
5552 /* *** SHOW NIC BYPASS MODE *** */
5553 struct cmd_show_bypass_config_result {
5554         cmdline_fixed_string_t show;
5555         cmdline_fixed_string_t bypass;
5556         cmdline_fixed_string_t config;
5557         portid_t port_id;
5558 };
5559
5560 static void
5561 cmd_show_bypass_config_parsed(void *parsed_result,
5562                 __rte_unused struct cmdline *cl,
5563                 __rte_unused void *data)
5564 {
5565         struct cmd_show_bypass_config_result *res = parsed_result;
5566         portid_t port_id = res->port_id;
5567         int rc = -EINVAL;
5568 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5569         uint32_t event_mode;
5570         uint32_t bypass_mode;
5571         uint32_t timeout = bypass_timeout;
5572         unsigned int i;
5573
5574         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5575                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5576         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5577                 {"UNKNOWN", "normal", "bypass", "isolate"};
5578         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5579                 "NONE",
5580                 "OS/board on",
5581                 "power supply on",
5582                 "OS/board off",
5583                 "power supply off",
5584                 "timeout"};
5585
5586         /* Display the bypass mode.*/
5587         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5588                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5589                 return;
5590         }
5591         else {
5592                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5593                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5594
5595                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5596         }
5597
5598         /* Display the bypass timeout.*/
5599         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5600                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5601
5602         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5603
5604         /* Display the bypass events and associated modes. */
5605         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5606
5607                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5608                         printf("\tFailed to get bypass mode for event = %s\n",
5609                                 events[i]);
5610                 } else {
5611                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5612                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5613
5614                         printf("\tbypass event: %-16s = %s\n", events[i],
5615                                 modes[event_mode]);
5616                 }
5617         }
5618 #endif
5619         if (rc != 0)
5620                 printf("\tFailed to get bypass configuration for port = %d\n",
5621                        port_id);
5622 }
5623
5624 cmdline_parse_token_string_t cmd_showbypass_config_show =
5625         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5626                         show, "show");
5627 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5628         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5629                         bypass, "bypass");
5630 cmdline_parse_token_string_t cmd_showbypass_config_config =
5631         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5632                         config, "config");
5633 cmdline_parse_token_num_t cmd_showbypass_config_port =
5634         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5635                                 port_id, UINT16);
5636
5637 cmdline_parse_inst_t cmd_show_bypass_config = {
5638         .f = cmd_show_bypass_config_parsed,
5639         .help_str = "show bypass config <port_id>: "
5640                     "Show the NIC bypass config for port_id",
5641         .data = NULL,
5642         .tokens = {
5643                 (void *)&cmd_showbypass_config_show,
5644                 (void *)&cmd_showbypass_config_bypass,
5645                 (void *)&cmd_showbypass_config_config,
5646                 (void *)&cmd_showbypass_config_port,
5647                 NULL,
5648         },
5649 };
5650
5651 #ifdef RTE_LIBRTE_PMD_BOND
5652 /* *** SET BONDING MODE *** */
5653 struct cmd_set_bonding_mode_result {
5654         cmdline_fixed_string_t set;
5655         cmdline_fixed_string_t bonding;
5656         cmdline_fixed_string_t mode;
5657         uint8_t value;
5658         portid_t port_id;
5659 };
5660
5661 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5662                 __rte_unused  struct cmdline *cl,
5663                 __rte_unused void *data)
5664 {
5665         struct cmd_set_bonding_mode_result *res = parsed_result;
5666         portid_t port_id = res->port_id;
5667
5668         /* Set the bonding mode for the relevant port. */
5669         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5670                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5671 }
5672
5673 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5674 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5675                 set, "set");
5676 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5677 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5678                 bonding, "bonding");
5679 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5680 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5681                 mode, "mode");
5682 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5683 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5684                 value, UINT8);
5685 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5686 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5687                 port_id, UINT16);
5688
5689 cmdline_parse_inst_t cmd_set_bonding_mode = {
5690                 .f = cmd_set_bonding_mode_parsed,
5691                 .help_str = "set bonding mode <mode_value> <port_id>: "
5692                         "Set the bonding mode for port_id",
5693                 .data = NULL,
5694                 .tokens = {
5695                                 (void *) &cmd_setbonding_mode_set,
5696                                 (void *) &cmd_setbonding_mode_bonding,
5697                                 (void *) &cmd_setbonding_mode_mode,
5698                                 (void *) &cmd_setbonding_mode_value,
5699                                 (void *) &cmd_setbonding_mode_port,
5700                                 NULL
5701                 }
5702 };
5703
5704 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5705 struct cmd_set_bonding_lacp_dedicated_queues_result {
5706         cmdline_fixed_string_t set;
5707         cmdline_fixed_string_t bonding;
5708         cmdline_fixed_string_t lacp;
5709         cmdline_fixed_string_t dedicated_queues;
5710         portid_t port_id;
5711         cmdline_fixed_string_t mode;
5712 };
5713
5714 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5715                 __rte_unused  struct cmdline *cl,
5716                 __rte_unused void *data)
5717 {
5718         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5719         portid_t port_id = res->port_id;
5720         struct rte_port *port;
5721
5722         port = &ports[port_id];
5723
5724         /** Check if the port is not started **/
5725         if (port->port_status != RTE_PORT_STOPPED) {
5726                 printf("Please stop port %d first\n", port_id);
5727                 return;
5728         }
5729
5730         if (!strcmp(res->mode, "enable")) {
5731                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5732                         printf("Dedicate queues for LACP control packets"
5733                                         " enabled\n");
5734                 else
5735                         printf("Enabling dedicate queues for LACP control "
5736                                         "packets on port %d failed\n", port_id);
5737         } else if (!strcmp(res->mode, "disable")) {
5738                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5739                         printf("Dedicated queues for LACP control packets "
5740                                         "disabled\n");
5741                 else
5742                         printf("Disabling dedicated queues for LACP control "
5743                                         "traffic on port %d failed\n", port_id);
5744         }
5745 }
5746
5747 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5748 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5749                 set, "set");
5750 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5751 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5752                 bonding, "bonding");
5753 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5754 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5755                 lacp, "lacp");
5756 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5757 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5758                 dedicated_queues, "dedicated_queues");
5759 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5760 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5761                 port_id, UINT16);
5762 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5763 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5764                 mode, "enable#disable");
5765
5766 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5767                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5768                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5769                         "enable|disable: "
5770                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5771                 .data = NULL,
5772                 .tokens = {
5773                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5774                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5775                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5776                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5777                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5778                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5779                         NULL
5780                 }
5781 };
5782
5783 /* *** SET BALANCE XMIT POLICY *** */
5784 struct cmd_set_bonding_balance_xmit_policy_result {
5785         cmdline_fixed_string_t set;
5786         cmdline_fixed_string_t bonding;
5787         cmdline_fixed_string_t balance_xmit_policy;
5788         portid_t port_id;
5789         cmdline_fixed_string_t policy;
5790 };
5791
5792 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5793                 __rte_unused  struct cmdline *cl,
5794                 __rte_unused void *data)
5795 {
5796         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5797         portid_t port_id = res->port_id;
5798         uint8_t policy;
5799
5800         if (!strcmp(res->policy, "l2")) {
5801                 policy = BALANCE_XMIT_POLICY_LAYER2;
5802         } else if (!strcmp(res->policy, "l23")) {
5803                 policy = BALANCE_XMIT_POLICY_LAYER23;
5804         } else if (!strcmp(res->policy, "l34")) {
5805                 policy = BALANCE_XMIT_POLICY_LAYER34;
5806         } else {
5807                 printf("\t Invalid xmit policy selection");
5808                 return;
5809         }
5810
5811         /* Set the bonding mode for the relevant port. */
5812         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5813                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5814                                 port_id);
5815         }
5816 }
5817
5818 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5819 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5820                 set, "set");
5821 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5822 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5823                 bonding, "bonding");
5824 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5825 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5826                 balance_xmit_policy, "balance_xmit_policy");
5827 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5828 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5829                 port_id, UINT16);
5830 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5831 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5832                 policy, "l2#l23#l34");
5833
5834 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5835                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5836                 .help_str = "set bonding balance_xmit_policy <port_id> "
5837                         "l2|l23|l34: "
5838                         "Set the bonding balance_xmit_policy for port_id",
5839                 .data = NULL,
5840                 .tokens = {
5841                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5842                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5843                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5844                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5845                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5846                                 NULL
5847                 }
5848 };
5849
5850 /* *** SHOW NIC BONDING CONFIGURATION *** */
5851 struct cmd_show_bonding_config_result {
5852         cmdline_fixed_string_t show;
5853         cmdline_fixed_string_t bonding;
5854         cmdline_fixed_string_t config;
5855         portid_t port_id;
5856 };
5857
5858 static void cmd_show_bonding_config_parsed(void *parsed_result,
5859                 __rte_unused  struct cmdline *cl,
5860                 __rte_unused void *data)
5861 {
5862         struct cmd_show_bonding_config_result *res = parsed_result;
5863         int bonding_mode, agg_mode;
5864         portid_t slaves[RTE_MAX_ETHPORTS];
5865         int num_slaves, num_active_slaves;
5866         int primary_id;
5867         int i;
5868         portid_t port_id = res->port_id;
5869
5870         /* Display the bonding mode.*/
5871         bonding_mode = rte_eth_bond_mode_get(port_id);
5872         if (bonding_mode < 0) {
5873                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5874                 return;
5875         } else
5876                 printf("\tBonding mode: %d\n", bonding_mode);
5877
5878         if (bonding_mode == BONDING_MODE_BALANCE) {
5879                 int balance_xmit_policy;
5880
5881                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5882                 if (balance_xmit_policy < 0) {
5883                         printf("\tFailed to get balance xmit policy for port = %d\n",
5884                                         port_id);
5885                         return;
5886                 } else {
5887                         printf("\tBalance Xmit Policy: ");
5888
5889                         switch (balance_xmit_policy) {
5890                         case BALANCE_XMIT_POLICY_LAYER2:
5891                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5892                                 break;
5893                         case BALANCE_XMIT_POLICY_LAYER23:
5894                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5895                                 break;
5896                         case BALANCE_XMIT_POLICY_LAYER34:
5897                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5898                                 break;
5899                         }
5900                         printf("\n");
5901                 }
5902         }
5903
5904         if (bonding_mode == BONDING_MODE_8023AD) {
5905                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5906                 printf("\tIEEE802.3AD Aggregator Mode: ");
5907                 switch (agg_mode) {
5908                 case AGG_BANDWIDTH:
5909                         printf("bandwidth");
5910                         break;
5911                 case AGG_STABLE:
5912                         printf("stable");
5913                         break;
5914                 case AGG_COUNT:
5915                         printf("count");
5916                         break;
5917                 }
5918                 printf("\n");
5919         }
5920
5921         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5922
5923         if (num_slaves < 0) {
5924                 printf("\tFailed to get slave list for port = %d\n", port_id);
5925                 return;
5926         }
5927         if (num_slaves > 0) {
5928                 printf("\tSlaves (%d): [", num_slaves);
5929                 for (i = 0; i < num_slaves - 1; i++)
5930                         printf("%d ", slaves[i]);
5931
5932                 printf("%d]\n", slaves[num_slaves - 1]);
5933         } else {
5934                 printf("\tSlaves: []\n");
5935
5936         }
5937
5938         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5939                         RTE_MAX_ETHPORTS);
5940
5941         if (num_active_slaves < 0) {
5942                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5943                 return;
5944         }
5945         if (num_active_slaves > 0) {
5946                 printf("\tActive Slaves (%d): [", num_active_slaves);
5947                 for (i = 0; i < num_active_slaves - 1; i++)
5948                         printf("%d ", slaves[i]);
5949
5950                 printf("%d]\n", slaves[num_active_slaves - 1]);
5951
5952         } else {
5953                 printf("\tActive Slaves: []\n");
5954
5955         }
5956
5957         primary_id = rte_eth_bond_primary_get(port_id);
5958         if (primary_id < 0) {
5959                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5960                 return;
5961         } else
5962                 printf("\tPrimary: [%d]\n", primary_id);
5963
5964 }
5965
5966 cmdline_parse_token_string_t cmd_showbonding_config_show =
5967 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5968                 show, "show");
5969 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5970 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5971                 bonding, "bonding");
5972 cmdline_parse_token_string_t cmd_showbonding_config_config =
5973 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5974                 config, "config");
5975 cmdline_parse_token_num_t cmd_showbonding_config_port =
5976 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5977                 port_id, UINT16);
5978
5979 cmdline_parse_inst_t cmd_show_bonding_config = {
5980                 .f = cmd_show_bonding_config_parsed,
5981                 .help_str = "show bonding config <port_id>: "
5982                         "Show the bonding config for port_id",
5983                 .data = NULL,
5984                 .tokens = {
5985                                 (void *)&cmd_showbonding_config_show,
5986                                 (void *)&cmd_showbonding_config_bonding,
5987                                 (void *)&cmd_showbonding_config_config,
5988                                 (void *)&cmd_showbonding_config_port,
5989                                 NULL
5990                 }
5991 };
5992
5993 /* *** SET BONDING PRIMARY *** */
5994 struct cmd_set_bonding_primary_result {
5995         cmdline_fixed_string_t set;
5996         cmdline_fixed_string_t bonding;
5997         cmdline_fixed_string_t primary;
5998         portid_t slave_id;
5999         portid_t port_id;
6000 };
6001
6002 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6003                 __rte_unused  struct cmdline *cl,
6004                 __rte_unused void *data)
6005 {
6006         struct cmd_set_bonding_primary_result *res = parsed_result;
6007         portid_t master_port_id = res->port_id;
6008         portid_t slave_port_id = res->slave_id;
6009
6010         /* Set the primary slave for a bonded device. */
6011         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6012                 printf("\t Failed to set primary slave for port = %d.\n",
6013                                 master_port_id);
6014                 return;
6015         }
6016         init_port_config();
6017 }
6018
6019 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6020 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6021                 set, "set");
6022 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6023 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6024                 bonding, "bonding");
6025 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6026 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6027                 primary, "primary");
6028 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6029 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6030                 slave_id, UINT16);
6031 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6032 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6033                 port_id, UINT16);
6034
6035 cmdline_parse_inst_t cmd_set_bonding_primary = {
6036                 .f = cmd_set_bonding_primary_parsed,
6037                 .help_str = "set bonding primary <slave_id> <port_id>: "
6038                         "Set the primary slave for port_id",
6039                 .data = NULL,
6040                 .tokens = {
6041                                 (void *)&cmd_setbonding_primary_set,
6042                                 (void *)&cmd_setbonding_primary_bonding,
6043                                 (void *)&cmd_setbonding_primary_primary,
6044                                 (void *)&cmd_setbonding_primary_slave,
6045                                 (void *)&cmd_setbonding_primary_port,
6046                                 NULL
6047                 }
6048 };
6049
6050 /* *** ADD SLAVE *** */
6051 struct cmd_add_bonding_slave_result {
6052         cmdline_fixed_string_t add;
6053         cmdline_fixed_string_t bonding;
6054         cmdline_fixed_string_t slave;
6055         portid_t slave_id;
6056         portid_t port_id;
6057 };
6058
6059 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6060                 __rte_unused  struct cmdline *cl,
6061                 __rte_unused void *data)
6062 {
6063         struct cmd_add_bonding_slave_result *res = parsed_result;
6064         portid_t master_port_id = res->port_id;
6065         portid_t slave_port_id = res->slave_id;
6066
6067         /* add the slave for a bonded device. */
6068         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6069                 printf("\t Failed to add slave %d to master port = %d.\n",
6070                                 slave_port_id, master_port_id);
6071                 return;
6072         }
6073         init_port_config();
6074         set_port_slave_flag(slave_port_id);
6075 }
6076
6077 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6078 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6079                 add, "add");
6080 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6081 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6082                 bonding, "bonding");
6083 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6084 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6085                 slave, "slave");
6086 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6087 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6088                 slave_id, UINT16);
6089 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6090 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6091                 port_id, UINT16);
6092
6093 cmdline_parse_inst_t cmd_add_bonding_slave = {
6094                 .f = cmd_add_bonding_slave_parsed,
6095                 .help_str = "add bonding slave <slave_id> <port_id>: "
6096                         "Add a slave device to a bonded device",
6097                 .data = NULL,
6098                 .tokens = {
6099                                 (void *)&cmd_addbonding_slave_add,
6100                                 (void *)&cmd_addbonding_slave_bonding,
6101                                 (void *)&cmd_addbonding_slave_slave,
6102                                 (void *)&cmd_addbonding_slave_slaveid,
6103                                 (void *)&cmd_addbonding_slave_port,
6104                                 NULL
6105                 }
6106 };
6107
6108 /* *** REMOVE SLAVE *** */
6109 struct cmd_remove_bonding_slave_result {
6110         cmdline_fixed_string_t remove;
6111         cmdline_fixed_string_t bonding;
6112         cmdline_fixed_string_t slave;
6113         portid_t slave_id;
6114         portid_t port_id;
6115 };
6116
6117 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6118                 __rte_unused  struct cmdline *cl,
6119                 __rte_unused void *data)
6120 {
6121         struct cmd_remove_bonding_slave_result *res = parsed_result;
6122         portid_t master_port_id = res->port_id;
6123         portid_t slave_port_id = res->slave_id;
6124
6125         /* remove the slave from a bonded device. */
6126         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6127                 printf("\t Failed to remove slave %d from master port = %d.\n",
6128                                 slave_port_id, master_port_id);
6129                 return;
6130         }
6131         init_port_config();
6132         clear_port_slave_flag(slave_port_id);
6133 }
6134
6135 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6136                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6137                                 remove, "remove");
6138 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6139                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6140                                 bonding, "bonding");
6141 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6142                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6143                                 slave, "slave");
6144 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6145                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6146                                 slave_id, UINT16);
6147 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6148                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6149                                 port_id, UINT16);
6150
6151 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6152                 .f = cmd_remove_bonding_slave_parsed,
6153                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6154                         "Remove a slave device from a bonded device",
6155                 .data = NULL,
6156                 .tokens = {
6157                                 (void *)&cmd_removebonding_slave_remove,
6158                                 (void *)&cmd_removebonding_slave_bonding,
6159                                 (void *)&cmd_removebonding_slave_slave,
6160                                 (void *)&cmd_removebonding_slave_slaveid,
6161                                 (void *)&cmd_removebonding_slave_port,
6162                                 NULL
6163                 }
6164 };
6165
6166 /* *** CREATE BONDED DEVICE *** */
6167 struct cmd_create_bonded_device_result {
6168         cmdline_fixed_string_t create;
6169         cmdline_fixed_string_t bonded;
6170         cmdline_fixed_string_t device;
6171         uint8_t mode;
6172         uint8_t socket;
6173 };
6174
6175 static int bond_dev_num = 0;
6176
6177 static void cmd_create_bonded_device_parsed(void *parsed_result,
6178                 __rte_unused  struct cmdline *cl,
6179                 __rte_unused void *data)
6180 {
6181         struct cmd_create_bonded_device_result *res = parsed_result;
6182         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6183         int port_id;
6184         int ret;
6185
6186         if (test_done == 0) {
6187                 printf("Please stop forwarding first\n");
6188                 return;
6189         }
6190
6191         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6192                         bond_dev_num++);
6193
6194         /* Create a new bonded device. */
6195         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6196         if (port_id < 0) {
6197                 printf("\t Failed to create bonded device.\n");
6198                 return;
6199         } else {
6200                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6201                                 port_id);
6202
6203                 /* Update number of ports */
6204                 nb_ports = rte_eth_dev_count_avail();
6205                 reconfig(port_id, res->socket);
6206                 ret = rte_eth_promiscuous_enable(port_id);
6207                 if (ret != 0)
6208                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6209                                 port_id, rte_strerror(-ret));
6210
6211                 ports[port_id].need_setup = 0;
6212                 ports[port_id].port_status = RTE_PORT_STOPPED;
6213         }
6214
6215 }
6216
6217 cmdline_parse_token_string_t cmd_createbonded_device_create =
6218                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6219                                 create, "create");
6220 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6221                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6222                                 bonded, "bonded");
6223 cmdline_parse_token_string_t cmd_createbonded_device_device =
6224                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6225                                 device, "device");
6226 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6227                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6228                                 mode, UINT8);
6229 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6230                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6231                                 socket, UINT8);
6232
6233 cmdline_parse_inst_t cmd_create_bonded_device = {
6234                 .f = cmd_create_bonded_device_parsed,
6235                 .help_str = "create bonded device <mode> <socket>: "
6236                         "Create a new bonded device with specific bonding mode and socket",
6237                 .data = NULL,
6238                 .tokens = {
6239                                 (void *)&cmd_createbonded_device_create,
6240                                 (void *)&cmd_createbonded_device_bonded,
6241                                 (void *)&cmd_createbonded_device_device,
6242                                 (void *)&cmd_createbonded_device_mode,
6243                                 (void *)&cmd_createbonded_device_socket,
6244                                 NULL
6245                 }
6246 };
6247
6248 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6249 struct cmd_set_bond_mac_addr_result {
6250         cmdline_fixed_string_t set;
6251         cmdline_fixed_string_t bonding;
6252         cmdline_fixed_string_t mac_addr;
6253         uint16_t port_num;
6254         struct rte_ether_addr address;
6255 };
6256
6257 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6258                 __rte_unused  struct cmdline *cl,
6259                 __rte_unused void *data)
6260 {
6261         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6262         int ret;
6263
6264         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6265                 return;
6266
6267         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6268
6269         /* check the return value and print it if is < 0 */
6270         if (ret < 0)
6271                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6272 }
6273
6274 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6275                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6276 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6277                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6278                                 "bonding");
6279 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6280                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6281                                 "mac_addr");
6282 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6283                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6284                                 port_num, UINT16);
6285 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6286                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6287
6288 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6289                 .f = cmd_set_bond_mac_addr_parsed,
6290                 .data = (void *) 0,
6291                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6292                 .tokens = {
6293                                 (void *)&cmd_set_bond_mac_addr_set,
6294                                 (void *)&cmd_set_bond_mac_addr_bonding,
6295                                 (void *)&cmd_set_bond_mac_addr_mac,
6296                                 (void *)&cmd_set_bond_mac_addr_portnum,
6297                                 (void *)&cmd_set_bond_mac_addr_addr,
6298                                 NULL
6299                 }
6300 };
6301
6302
6303 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6304 struct cmd_set_bond_mon_period_result {
6305         cmdline_fixed_string_t set;
6306         cmdline_fixed_string_t bonding;
6307         cmdline_fixed_string_t mon_period;
6308         uint16_t port_num;
6309         uint32_t period_ms;
6310 };
6311
6312 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6313                 __rte_unused  struct cmdline *cl,
6314                 __rte_unused void *data)
6315 {
6316         struct cmd_set_bond_mon_period_result *res = parsed_result;
6317         int ret;
6318
6319         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6320
6321         /* check the return value and print it if is < 0 */
6322         if (ret < 0)
6323                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6324 }
6325
6326 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6327                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6328                                 set, "set");
6329 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6330                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6331                                 bonding, "bonding");
6332 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6333                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6334                                 mon_period,     "mon_period");
6335 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6336                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6337                                 port_num, UINT16);
6338 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6339                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6340                                 period_ms, UINT32);
6341
6342 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6343                 .f = cmd_set_bond_mon_period_parsed,
6344                 .data = (void *) 0,
6345                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6346                 .tokens = {
6347                                 (void *)&cmd_set_bond_mon_period_set,
6348                                 (void *)&cmd_set_bond_mon_period_bonding,
6349                                 (void *)&cmd_set_bond_mon_period_mon_period,
6350                                 (void *)&cmd_set_bond_mon_period_portnum,
6351                                 (void *)&cmd_set_bond_mon_period_period_ms,
6352                                 NULL
6353                 }
6354 };
6355
6356
6357
6358 struct cmd_set_bonding_agg_mode_policy_result {
6359         cmdline_fixed_string_t set;
6360         cmdline_fixed_string_t bonding;
6361         cmdline_fixed_string_t agg_mode;
6362         uint16_t port_num;
6363         cmdline_fixed_string_t policy;
6364 };
6365
6366
6367 static void
6368 cmd_set_bonding_agg_mode(void *parsed_result,
6369                 __rte_unused struct cmdline *cl,
6370                 __rte_unused void *data)
6371 {
6372         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6373         uint8_t policy = AGG_BANDWIDTH;
6374
6375         if (!strcmp(res->policy, "bandwidth"))
6376                 policy = AGG_BANDWIDTH;
6377         else if (!strcmp(res->policy, "stable"))
6378                 policy = AGG_STABLE;
6379         else if (!strcmp(res->policy, "count"))
6380                 policy = AGG_COUNT;
6381
6382         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6383 }
6384
6385
6386 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6387         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6388                                 set, "set");
6389 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6390         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6391                                 bonding, "bonding");
6392
6393 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6394         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6395                                 agg_mode, "agg_mode");
6396
6397 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6398         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6399                                 port_num, UINT16);
6400
6401 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6402         TOKEN_STRING_INITIALIZER(
6403                         struct cmd_set_bonding_balance_xmit_policy_result,
6404                 policy, "stable#bandwidth#count");
6405
6406 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6407         .f = cmd_set_bonding_agg_mode,
6408         .data = (void *) 0,
6409         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6410         .tokens = {
6411                         (void *)&cmd_set_bonding_agg_mode_set,
6412                         (void *)&cmd_set_bonding_agg_mode_bonding,
6413                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6414                         (void *)&cmd_set_bonding_agg_mode_portnum,
6415                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6416                         NULL
6417                 }
6418 };
6419
6420
6421 #endif /* RTE_LIBRTE_PMD_BOND */
6422
6423 /* *** SET FORWARDING MODE *** */
6424 struct cmd_set_fwd_mode_result {
6425         cmdline_fixed_string_t set;
6426         cmdline_fixed_string_t fwd;
6427         cmdline_fixed_string_t mode;
6428 };
6429
6430 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6431                                     __rte_unused struct cmdline *cl,
6432                                     __rte_unused void *data)
6433 {
6434         struct cmd_set_fwd_mode_result *res = parsed_result;
6435
6436         retry_enabled = 0;
6437         set_pkt_forwarding_mode(res->mode);
6438 }
6439
6440 cmdline_parse_token_string_t cmd_setfwd_set =
6441         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6442 cmdline_parse_token_string_t cmd_setfwd_fwd =
6443         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6444 cmdline_parse_token_string_t cmd_setfwd_mode =
6445         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6446                 "" /* defined at init */);
6447
6448 cmdline_parse_inst_t cmd_set_fwd_mode = {
6449         .f = cmd_set_fwd_mode_parsed,
6450         .data = NULL,
6451         .help_str = NULL, /* defined at init */
6452         .tokens = {
6453                 (void *)&cmd_setfwd_set,
6454                 (void *)&cmd_setfwd_fwd,
6455                 (void *)&cmd_setfwd_mode,
6456                 NULL,
6457         },
6458 };
6459
6460 static void cmd_set_fwd_mode_init(void)
6461 {
6462         char *modes, *c;
6463         static char token[128];
6464         static char help[256];
6465         cmdline_parse_token_string_t *token_struct;
6466
6467         modes = list_pkt_forwarding_modes();
6468         snprintf(help, sizeof(help), "set fwd %s: "
6469                 "Set packet forwarding mode", modes);
6470         cmd_set_fwd_mode.help_str = help;
6471
6472         /* string token separator is # */
6473         for (c = token; *modes != '\0'; modes++)
6474                 if (*modes == '|')
6475                         *c++ = '#';
6476                 else
6477                         *c++ = *modes;
6478         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6479         token_struct->string_data.str = token;
6480 }
6481
6482 /* *** SET RETRY FORWARDING MODE *** */
6483 struct cmd_set_fwd_retry_mode_result {
6484         cmdline_fixed_string_t set;
6485         cmdline_fixed_string_t fwd;
6486         cmdline_fixed_string_t mode;
6487         cmdline_fixed_string_t retry;
6488 };
6489
6490 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6491                             __rte_unused struct cmdline *cl,
6492                             __rte_unused void *data)
6493 {
6494         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6495
6496         retry_enabled = 1;
6497         set_pkt_forwarding_mode(res->mode);
6498 }
6499
6500 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6501         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6502                         set, "set");
6503 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6504         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6505                         fwd, "fwd");
6506 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6507         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6508                         mode,
6509                 "" /* defined at init */);
6510 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6511         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6512                         retry, "retry");
6513
6514 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6515         .f = cmd_set_fwd_retry_mode_parsed,
6516         .data = NULL,
6517         .help_str = NULL, /* defined at init */
6518         .tokens = {
6519                 (void *)&cmd_setfwd_retry_set,
6520                 (void *)&cmd_setfwd_retry_fwd,
6521                 (void *)&cmd_setfwd_retry_mode,
6522                 (void *)&cmd_setfwd_retry_retry,
6523                 NULL,
6524         },
6525 };
6526
6527 static void cmd_set_fwd_retry_mode_init(void)
6528 {
6529         char *modes, *c;
6530         static char token[128];
6531         static char help[256];
6532         cmdline_parse_token_string_t *token_struct;
6533
6534         modes = list_pkt_forwarding_retry_modes();
6535         snprintf(help, sizeof(help), "set fwd %s retry: "
6536                 "Set packet forwarding mode with retry", modes);
6537         cmd_set_fwd_retry_mode.help_str = help;
6538
6539         /* string token separator is # */
6540         for (c = token; *modes != '\0'; modes++)
6541                 if (*modes == '|')
6542                         *c++ = '#';
6543                 else
6544                         *c++ = *modes;
6545         token_struct = (cmdline_parse_token_string_t *)
6546                 cmd_set_fwd_retry_mode.tokens[2];
6547         token_struct->string_data.str = token;
6548 }
6549
6550 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6551 struct cmd_set_burst_tx_retry_result {
6552         cmdline_fixed_string_t set;
6553         cmdline_fixed_string_t burst;
6554         cmdline_fixed_string_t tx;
6555         cmdline_fixed_string_t delay;
6556         uint32_t time;
6557         cmdline_fixed_string_t retry;
6558         uint32_t retry_num;
6559 };
6560
6561 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6562                                         __rte_unused struct cmdline *cl,
6563                                         __rte_unused void *data)
6564 {
6565         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6566
6567         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6568                 && !strcmp(res->tx, "tx")) {
6569                 if (!strcmp(res->delay, "delay"))
6570                         burst_tx_delay_time = res->time;
6571                 if (!strcmp(res->retry, "retry"))
6572                         burst_tx_retry_num = res->retry_num;
6573         }
6574
6575 }
6576
6577 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6578         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6579 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6580         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6581                                  "burst");
6582 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6583         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6584 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6585         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6586 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6587         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6588 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6589         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6590 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6591         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6592
6593 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6594         .f = cmd_set_burst_tx_retry_parsed,
6595         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6596         .tokens = {
6597                 (void *)&cmd_set_burst_tx_retry_set,
6598                 (void *)&cmd_set_burst_tx_retry_burst,
6599                 (void *)&cmd_set_burst_tx_retry_tx,
6600                 (void *)&cmd_set_burst_tx_retry_delay,
6601                 (void *)&cmd_set_burst_tx_retry_time,
6602                 (void *)&cmd_set_burst_tx_retry_retry,
6603                 (void *)&cmd_set_burst_tx_retry_retry_num,
6604                 NULL,
6605         },
6606 };
6607
6608 /* *** SET PROMISC MODE *** */
6609 struct cmd_set_promisc_mode_result {
6610         cmdline_fixed_string_t set;
6611         cmdline_fixed_string_t promisc;
6612         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6613         uint16_t port_num;               /* valid if "allports" argument == 0 */
6614         cmdline_fixed_string_t mode;
6615 };
6616
6617 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6618                                         __rte_unused struct cmdline *cl,
6619                                         void *allports)
6620 {
6621         struct cmd_set_promisc_mode_result *res = parsed_result;
6622         int enable;
6623         portid_t i;
6624
6625         if (!strcmp(res->mode, "on"))
6626                 enable = 1;
6627         else
6628                 enable = 0;
6629
6630         /* all ports */
6631         if (allports) {
6632                 RTE_ETH_FOREACH_DEV(i)
6633                         eth_set_promisc_mode(i, enable);
6634         } else {
6635                 eth_set_promisc_mode(res->port_num, enable);
6636         }
6637 }
6638
6639 cmdline_parse_token_string_t cmd_setpromisc_set =
6640         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6641 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6642         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6643                                  "promisc");
6644 cmdline_parse_token_string_t cmd_setpromisc_portall =
6645         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6646                                  "all");
6647 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6648         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6649                               UINT16);
6650 cmdline_parse_token_string_t cmd_setpromisc_mode =
6651         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6652                                  "on#off");
6653
6654 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6655         .f = cmd_set_promisc_mode_parsed,
6656         .data = (void *)1,
6657         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6658         .tokens = {
6659                 (void *)&cmd_setpromisc_set,
6660                 (void *)&cmd_setpromisc_promisc,
6661                 (void *)&cmd_setpromisc_portall,
6662                 (void *)&cmd_setpromisc_mode,
6663                 NULL,
6664         },
6665 };
6666
6667 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6668         .f = cmd_set_promisc_mode_parsed,
6669         .data = (void *)0,
6670         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6671         .tokens = {
6672                 (void *)&cmd_setpromisc_set,
6673                 (void *)&cmd_setpromisc_promisc,
6674                 (void *)&cmd_setpromisc_portnum,
6675                 (void *)&cmd_setpromisc_mode,
6676                 NULL,
6677         },
6678 };
6679
6680 /* *** SET ALLMULTI MODE *** */
6681 struct cmd_set_allmulti_mode_result {
6682         cmdline_fixed_string_t set;
6683         cmdline_fixed_string_t allmulti;
6684         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6685         uint16_t port_num;               /* valid if "allports" argument == 0 */
6686         cmdline_fixed_string_t mode;
6687 };
6688
6689 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6690                                         __rte_unused struct cmdline *cl,
6691                                         void *allports)
6692 {
6693         struct cmd_set_allmulti_mode_result *res = parsed_result;
6694         int enable;
6695         portid_t i;
6696
6697         if (!strcmp(res->mode, "on"))
6698                 enable = 1;
6699         else
6700                 enable = 0;
6701
6702         /* all ports */
6703         if (allports) {
6704                 RTE_ETH_FOREACH_DEV(i) {
6705                         eth_set_allmulticast_mode(i, enable);
6706                 }
6707         }
6708         else {
6709                 eth_set_allmulticast_mode(res->port_num, enable);
6710         }
6711 }
6712
6713 cmdline_parse_token_string_t cmd_setallmulti_set =
6714         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6715 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6716         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6717                                  "allmulti");
6718 cmdline_parse_token_string_t cmd_setallmulti_portall =
6719         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6720                                  "all");
6721 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6722         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6723                               UINT16);
6724 cmdline_parse_token_string_t cmd_setallmulti_mode =
6725         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6726                                  "on#off");
6727
6728 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6729         .f = cmd_set_allmulti_mode_parsed,
6730         .data = (void *)1,
6731         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6732         .tokens = {
6733                 (void *)&cmd_setallmulti_set,
6734                 (void *)&cmd_setallmulti_allmulti,
6735                 (void *)&cmd_setallmulti_portall,
6736                 (void *)&cmd_setallmulti_mode,
6737                 NULL,
6738         },
6739 };
6740
6741 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6742         .f = cmd_set_allmulti_mode_parsed,
6743         .data = (void *)0,
6744         .help_str = "set allmulti <port_id> on|off: "
6745                 "Set allmulti mode on port_id",
6746         .tokens = {
6747                 (void *)&cmd_setallmulti_set,
6748                 (void *)&cmd_setallmulti_allmulti,
6749                 (void *)&cmd_setallmulti_portnum,
6750                 (void *)&cmd_setallmulti_mode,
6751                 NULL,
6752         },
6753 };
6754
6755 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6756 struct cmd_link_flow_ctrl_set_result {
6757         cmdline_fixed_string_t set;
6758         cmdline_fixed_string_t flow_ctrl;
6759         cmdline_fixed_string_t rx;
6760         cmdline_fixed_string_t rx_lfc_mode;
6761         cmdline_fixed_string_t tx;
6762         cmdline_fixed_string_t tx_lfc_mode;
6763         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6764         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6765         cmdline_fixed_string_t autoneg_str;
6766         cmdline_fixed_string_t autoneg;
6767         cmdline_fixed_string_t hw_str;
6768         uint32_t high_water;
6769         cmdline_fixed_string_t lw_str;
6770         uint32_t low_water;
6771         cmdline_fixed_string_t pt_str;
6772         uint16_t pause_time;
6773         cmdline_fixed_string_t xon_str;
6774         uint16_t send_xon;
6775         portid_t port_id;
6776 };
6777
6778 cmdline_parse_token_string_t cmd_lfc_set_set =
6779         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6780                                 set, "set");
6781 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6782         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6783                                 flow_ctrl, "flow_ctrl");
6784 cmdline_parse_token_string_t cmd_lfc_set_rx =
6785         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6786                                 rx, "rx");
6787 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6788         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6789                                 rx_lfc_mode, "on#off");
6790 cmdline_parse_token_string_t cmd_lfc_set_tx =
6791         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6792                                 tx, "tx");
6793 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6794         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6795                                 tx_lfc_mode, "on#off");
6796 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6797         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6798                                 hw_str, "high_water");
6799 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6800         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6801                                 high_water, UINT32);
6802 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6803         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6804                                 lw_str, "low_water");
6805 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6806         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6807                                 low_water, UINT32);
6808 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6809         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6810                                 pt_str, "pause_time");
6811 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6812         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6813                                 pause_time, UINT16);
6814 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6815         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6816                                 xon_str, "send_xon");
6817 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6818         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6819                                 send_xon, UINT16);
6820 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6821         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6822                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6823 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6824         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6825                                 mac_ctrl_frame_fwd_mode, "on#off");
6826 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6827         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6828                                 autoneg_str, "autoneg");
6829 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6830         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6831                                 autoneg, "on#off");
6832 cmdline_parse_token_num_t cmd_lfc_set_portid =
6833         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6834                                 port_id, UINT16);
6835
6836 /* forward declaration */
6837 static void
6838 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6839                               void *data);
6840
6841 cmdline_parse_inst_t cmd_link_flow_control_set = {
6842         .f = cmd_link_flow_ctrl_set_parsed,
6843         .data = NULL,
6844         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6845                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6846                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6847         .tokens = {
6848                 (void *)&cmd_lfc_set_set,
6849                 (void *)&cmd_lfc_set_flow_ctrl,
6850                 (void *)&cmd_lfc_set_rx,
6851                 (void *)&cmd_lfc_set_rx_mode,
6852                 (void *)&cmd_lfc_set_tx,
6853                 (void *)&cmd_lfc_set_tx_mode,
6854                 (void *)&cmd_lfc_set_high_water,
6855                 (void *)&cmd_lfc_set_low_water,
6856                 (void *)&cmd_lfc_set_pause_time,
6857                 (void *)&cmd_lfc_set_send_xon,
6858                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6859                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6860                 (void *)&cmd_lfc_set_autoneg_str,
6861                 (void *)&cmd_lfc_set_autoneg,
6862                 (void *)&cmd_lfc_set_portid,
6863                 NULL,
6864         },
6865 };
6866
6867 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6868         .f = cmd_link_flow_ctrl_set_parsed,
6869         .data = (void *)&cmd_link_flow_control_set_rx,
6870         .help_str = "set flow_ctrl rx on|off <port_id>: "
6871                 "Change rx flow control parameter",
6872         .tokens = {
6873                 (void *)&cmd_lfc_set_set,
6874                 (void *)&cmd_lfc_set_flow_ctrl,
6875                 (void *)&cmd_lfc_set_rx,
6876                 (void *)&cmd_lfc_set_rx_mode,
6877                 (void *)&cmd_lfc_set_portid,
6878                 NULL,
6879         },
6880 };
6881
6882 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6883         .f = cmd_link_flow_ctrl_set_parsed,
6884         .data = (void *)&cmd_link_flow_control_set_tx,
6885         .help_str = "set flow_ctrl tx on|off <port_id>: "
6886                 "Change tx flow control parameter",
6887         .tokens = {
6888                 (void *)&cmd_lfc_set_set,
6889                 (void *)&cmd_lfc_set_flow_ctrl,
6890                 (void *)&cmd_lfc_set_tx,
6891                 (void *)&cmd_lfc_set_tx_mode,
6892                 (void *)&cmd_lfc_set_portid,
6893                 NULL,
6894         },
6895 };
6896
6897 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6898         .f = cmd_link_flow_ctrl_set_parsed,
6899         .data = (void *)&cmd_link_flow_control_set_hw,
6900         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6901                 "Change high water flow control parameter",
6902         .tokens = {
6903                 (void *)&cmd_lfc_set_set,
6904                 (void *)&cmd_lfc_set_flow_ctrl,
6905                 (void *)&cmd_lfc_set_high_water_str,
6906                 (void *)&cmd_lfc_set_high_water,
6907                 (void *)&cmd_lfc_set_portid,
6908                 NULL,
6909         },
6910 };
6911
6912 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6913         .f = cmd_link_flow_ctrl_set_parsed,
6914         .data = (void *)&cmd_link_flow_control_set_lw,
6915         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6916                 "Change low water flow control parameter",
6917         .tokens = {
6918                 (void *)&cmd_lfc_set_set,
6919                 (void *)&cmd_lfc_set_flow_ctrl,
6920                 (void *)&cmd_lfc_set_low_water_str,
6921                 (void *)&cmd_lfc_set_low_water,
6922                 (void *)&cmd_lfc_set_portid,
6923                 NULL,
6924         },
6925 };
6926
6927 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6928         .f = cmd_link_flow_ctrl_set_parsed,
6929         .data = (void *)&cmd_link_flow_control_set_pt,
6930         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6931                 "Change pause time flow control parameter",
6932         .tokens = {
6933                 (void *)&cmd_lfc_set_set,
6934                 (void *)&cmd_lfc_set_flow_ctrl,
6935                 (void *)&cmd_lfc_set_pause_time_str,
6936                 (void *)&cmd_lfc_set_pause_time,
6937                 (void *)&cmd_lfc_set_portid,
6938                 NULL,
6939         },
6940 };
6941
6942 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6943         .f = cmd_link_flow_ctrl_set_parsed,
6944         .data = (void *)&cmd_link_flow_control_set_xon,
6945         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6946                 "Change send_xon flow control parameter",
6947         .tokens = {
6948                 (void *)&cmd_lfc_set_set,
6949                 (void *)&cmd_lfc_set_flow_ctrl,
6950                 (void *)&cmd_lfc_set_send_xon_str,
6951                 (void *)&cmd_lfc_set_send_xon,
6952                 (void *)&cmd_lfc_set_portid,
6953                 NULL,
6954         },
6955 };
6956
6957 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6958         .f = cmd_link_flow_ctrl_set_parsed,
6959         .data = (void *)&cmd_link_flow_control_set_macfwd,
6960         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6961                 "Change mac ctrl fwd flow control parameter",
6962         .tokens = {
6963                 (void *)&cmd_lfc_set_set,
6964                 (void *)&cmd_lfc_set_flow_ctrl,
6965                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6966                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6967                 (void *)&cmd_lfc_set_portid,
6968                 NULL,
6969         },
6970 };
6971
6972 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6973         .f = cmd_link_flow_ctrl_set_parsed,
6974         .data = (void *)&cmd_link_flow_control_set_autoneg,
6975         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6976                 "Change autoneg flow control parameter",
6977         .tokens = {
6978                 (void *)&cmd_lfc_set_set,
6979                 (void *)&cmd_lfc_set_flow_ctrl,
6980                 (void *)&cmd_lfc_set_autoneg_str,
6981                 (void *)&cmd_lfc_set_autoneg,
6982                 (void *)&cmd_lfc_set_portid,
6983                 NULL,
6984         },
6985 };
6986
6987 static void
6988 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6989                               __rte_unused struct cmdline *cl,
6990                               void *data)
6991 {
6992         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6993         cmdline_parse_inst_t *cmd = data;
6994         struct rte_eth_fc_conf fc_conf;
6995         int rx_fc_en = 0;
6996         int tx_fc_en = 0;
6997         int ret;
6998
6999         /*
7000          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7001          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7002          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7003          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7004          */
7005         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7006                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7007         };
7008
7009         /* Partial command line, retrieve current configuration */
7010         if (cmd) {
7011                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7012                 if (ret != 0) {
7013                         printf("cannot get current flow ctrl parameters, return"
7014                                "code = %d\n", ret);
7015                         return;
7016                 }
7017
7018                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7019                     (fc_conf.mode == RTE_FC_FULL))
7020                         rx_fc_en = 1;
7021                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7022                     (fc_conf.mode == RTE_FC_FULL))
7023                         tx_fc_en = 1;
7024         }
7025
7026         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7027                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7028
7029         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7030                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7031
7032         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7033
7034         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7035                 fc_conf.high_water = res->high_water;
7036
7037         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7038                 fc_conf.low_water = res->low_water;
7039
7040         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7041                 fc_conf.pause_time = res->pause_time;
7042
7043         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7044                 fc_conf.send_xon = res->send_xon;
7045
7046         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7047                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7048                         fc_conf.mac_ctrl_frame_fwd = 1;
7049                 else
7050                         fc_conf.mac_ctrl_frame_fwd = 0;
7051         }
7052
7053         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7054                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7055
7056         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7057         if (ret != 0)
7058                 printf("bad flow contrl parameter, return code = %d \n", ret);
7059 }
7060
7061 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7062 struct cmd_priority_flow_ctrl_set_result {
7063         cmdline_fixed_string_t set;
7064         cmdline_fixed_string_t pfc_ctrl;
7065         cmdline_fixed_string_t rx;
7066         cmdline_fixed_string_t rx_pfc_mode;
7067         cmdline_fixed_string_t tx;
7068         cmdline_fixed_string_t tx_pfc_mode;
7069         uint32_t high_water;
7070         uint32_t low_water;
7071         uint16_t pause_time;
7072         uint8_t  priority;
7073         portid_t port_id;
7074 };
7075
7076 static void
7077 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7078                        __rte_unused struct cmdline *cl,
7079                        __rte_unused void *data)
7080 {
7081         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7082         struct rte_eth_pfc_conf pfc_conf;
7083         int rx_fc_enable, tx_fc_enable;
7084         int ret;
7085
7086         /*
7087          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7088          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7089          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7090          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7091          */
7092         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7093                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7094         };
7095
7096         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7097         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7098         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7099         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7100         pfc_conf.fc.high_water = res->high_water;
7101         pfc_conf.fc.low_water  = res->low_water;
7102         pfc_conf.fc.pause_time = res->pause_time;
7103         pfc_conf.priority      = res->priority;
7104
7105         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7106         if (ret != 0)
7107                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7108 }
7109
7110 cmdline_parse_token_string_t cmd_pfc_set_set =
7111         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7112                                 set, "set");
7113 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7114         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7115                                 pfc_ctrl, "pfc_ctrl");
7116 cmdline_parse_token_string_t cmd_pfc_set_rx =
7117         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7118                                 rx, "rx");
7119 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7120         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7121                                 rx_pfc_mode, "on#off");
7122 cmdline_parse_token_string_t cmd_pfc_set_tx =
7123         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7124                                 tx, "tx");
7125 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7126         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7127                                 tx_pfc_mode, "on#off");
7128 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7129         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7130                                 high_water, UINT32);
7131 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7132         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7133                                 low_water, UINT32);
7134 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7135         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7136                                 pause_time, UINT16);
7137 cmdline_parse_token_num_t cmd_pfc_set_priority =
7138         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7139                                 priority, UINT8);
7140 cmdline_parse_token_num_t cmd_pfc_set_portid =
7141         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7142                                 port_id, UINT16);
7143
7144 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7145         .f = cmd_priority_flow_ctrl_set_parsed,
7146         .data = NULL,
7147         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7148                 "<pause_time> <priority> <port_id>: "
7149                 "Configure the Ethernet priority flow control",
7150         .tokens = {
7151                 (void *)&cmd_pfc_set_set,
7152                 (void *)&cmd_pfc_set_flow_ctrl,
7153                 (void *)&cmd_pfc_set_rx,
7154                 (void *)&cmd_pfc_set_rx_mode,
7155                 (void *)&cmd_pfc_set_tx,
7156                 (void *)&cmd_pfc_set_tx_mode,
7157                 (void *)&cmd_pfc_set_high_water,
7158                 (void *)&cmd_pfc_set_low_water,
7159                 (void *)&cmd_pfc_set_pause_time,
7160                 (void *)&cmd_pfc_set_priority,
7161                 (void *)&cmd_pfc_set_portid,
7162                 NULL,
7163         },
7164 };
7165
7166 /* *** RESET CONFIGURATION *** */
7167 struct cmd_reset_result {
7168         cmdline_fixed_string_t reset;
7169         cmdline_fixed_string_t def;
7170 };
7171
7172 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7173                              struct cmdline *cl,
7174                              __rte_unused void *data)
7175 {
7176         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7177         set_def_fwd_config();
7178 }
7179
7180 cmdline_parse_token_string_t cmd_reset_set =
7181         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7182 cmdline_parse_token_string_t cmd_reset_def =
7183         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7184                                  "default");
7185
7186 cmdline_parse_inst_t cmd_reset = {
7187         .f = cmd_reset_parsed,
7188         .data = NULL,
7189         .help_str = "set default: Reset default forwarding configuration",
7190         .tokens = {
7191                 (void *)&cmd_reset_set,
7192                 (void *)&cmd_reset_def,
7193                 NULL,
7194         },
7195 };
7196
7197 /* *** START FORWARDING *** */
7198 struct cmd_start_result {
7199         cmdline_fixed_string_t start;
7200 };
7201
7202 cmdline_parse_token_string_t cmd_start_start =
7203         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7204
7205 static void cmd_start_parsed(__rte_unused void *parsed_result,
7206                              __rte_unused struct cmdline *cl,
7207                              __rte_unused void *data)
7208 {
7209         start_packet_forwarding(0);
7210 }
7211
7212 cmdline_parse_inst_t cmd_start = {
7213         .f = cmd_start_parsed,
7214         .data = NULL,
7215         .help_str = "start: Start packet forwarding",
7216         .tokens = {
7217                 (void *)&cmd_start_start,
7218                 NULL,
7219         },
7220 };
7221
7222 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7223 struct cmd_start_tx_first_result {
7224         cmdline_fixed_string_t start;
7225         cmdline_fixed_string_t tx_first;
7226 };
7227
7228 static void
7229 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7230                           __rte_unused struct cmdline *cl,
7231                           __rte_unused void *data)
7232 {
7233         start_packet_forwarding(1);
7234 }
7235
7236 cmdline_parse_token_string_t cmd_start_tx_first_start =
7237         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7238                                  "start");
7239 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7240         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7241                                  tx_first, "tx_first");
7242
7243 cmdline_parse_inst_t cmd_start_tx_first = {
7244         .f = cmd_start_tx_first_parsed,
7245         .data = NULL,
7246         .help_str = "start tx_first: Start packet forwarding, "
7247                 "after sending 1 burst of packets",
7248         .tokens = {
7249                 (void *)&cmd_start_tx_first_start,
7250                 (void *)&cmd_start_tx_first_tx_first,
7251                 NULL,
7252         },
7253 };
7254
7255 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7256 struct cmd_start_tx_first_n_result {
7257         cmdline_fixed_string_t start;
7258         cmdline_fixed_string_t tx_first;
7259         uint32_t tx_num;
7260 };
7261
7262 static void
7263 cmd_start_tx_first_n_parsed(void *parsed_result,
7264                           __rte_unused struct cmdline *cl,
7265                           __rte_unused void *data)
7266 {
7267         struct cmd_start_tx_first_n_result *res = parsed_result;
7268
7269         start_packet_forwarding(res->tx_num);
7270 }
7271
7272 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7273         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7274                         start, "start");
7275 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7276         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7277                         tx_first, "tx_first");
7278 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7279         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7280                         tx_num, UINT32);
7281
7282 cmdline_parse_inst_t cmd_start_tx_first_n = {
7283         .f = cmd_start_tx_first_n_parsed,
7284         .data = NULL,
7285         .help_str = "start tx_first <num>: "
7286                 "packet forwarding, after sending <num> bursts of packets",
7287         .tokens = {
7288                 (void *)&cmd_start_tx_first_n_start,
7289                 (void *)&cmd_start_tx_first_n_tx_first,
7290                 (void *)&cmd_start_tx_first_n_tx_num,
7291                 NULL,
7292         },
7293 };
7294
7295 /* *** SET LINK UP *** */
7296 struct cmd_set_link_up_result {
7297         cmdline_fixed_string_t set;
7298         cmdline_fixed_string_t link_up;
7299         cmdline_fixed_string_t port;
7300         portid_t port_id;
7301 };
7302
7303 cmdline_parse_token_string_t cmd_set_link_up_set =
7304         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7305 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7306         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7307                                 "link-up");
7308 cmdline_parse_token_string_t cmd_set_link_up_port =
7309         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7310 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7311         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7312
7313 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7314                              __rte_unused struct cmdline *cl,
7315                              __rte_unused void *data)
7316 {
7317         struct cmd_set_link_up_result *res = parsed_result;
7318         dev_set_link_up(res->port_id);
7319 }
7320
7321 cmdline_parse_inst_t cmd_set_link_up = {
7322         .f = cmd_set_link_up_parsed,
7323         .data = NULL,
7324         .help_str = "set link-up port <port id>",
7325         .tokens = {
7326                 (void *)&cmd_set_link_up_set,
7327                 (void *)&cmd_set_link_up_link_up,
7328                 (void *)&cmd_set_link_up_port,
7329                 (void *)&cmd_set_link_up_port_id,
7330                 NULL,
7331         },
7332 };
7333
7334 /* *** SET LINK DOWN *** */
7335 struct cmd_set_link_down_result {
7336         cmdline_fixed_string_t set;
7337         cmdline_fixed_string_t link_down;
7338         cmdline_fixed_string_t port;
7339         portid_t port_id;
7340 };
7341
7342 cmdline_parse_token_string_t cmd_set_link_down_set =
7343         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7344 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7345         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7346                                 "link-down");
7347 cmdline_parse_token_string_t cmd_set_link_down_port =
7348         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7349 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7350         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7351
7352 static void cmd_set_link_down_parsed(
7353                                 __rte_unused void *parsed_result,
7354                                 __rte_unused struct cmdline *cl,
7355                                 __rte_unused void *data)
7356 {
7357         struct cmd_set_link_down_result *res = parsed_result;
7358         dev_set_link_down(res->port_id);
7359 }
7360
7361 cmdline_parse_inst_t cmd_set_link_down = {
7362         .f = cmd_set_link_down_parsed,
7363         .data = NULL,
7364         .help_str = "set link-down port <port id>",
7365         .tokens = {
7366                 (void *)&cmd_set_link_down_set,
7367                 (void *)&cmd_set_link_down_link_down,
7368                 (void *)&cmd_set_link_down_port,
7369                 (void *)&cmd_set_link_down_port_id,
7370                 NULL,
7371         },
7372 };
7373
7374 /* *** SHOW CFG *** */
7375 struct cmd_showcfg_result {
7376         cmdline_fixed_string_t show;
7377         cmdline_fixed_string_t cfg;
7378         cmdline_fixed_string_t what;
7379 };
7380
7381 static void cmd_showcfg_parsed(void *parsed_result,
7382                                __rte_unused struct cmdline *cl,
7383                                __rte_unused void *data)
7384 {
7385         struct cmd_showcfg_result *res = parsed_result;
7386         if (!strcmp(res->what, "rxtx"))
7387                 rxtx_config_display();
7388         else if (!strcmp(res->what, "cores"))
7389                 fwd_lcores_config_display();
7390         else if (!strcmp(res->what, "fwd"))
7391                 pkt_fwd_config_display(&cur_fwd_config);
7392         else if (!strcmp(res->what, "txpkts"))
7393                 show_tx_pkt_segments();
7394 }
7395
7396 cmdline_parse_token_string_t cmd_showcfg_show =
7397         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7398 cmdline_parse_token_string_t cmd_showcfg_port =
7399         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7400 cmdline_parse_token_string_t cmd_showcfg_what =
7401         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7402                                  "rxtx#cores#fwd#txpkts");
7403
7404 cmdline_parse_inst_t cmd_showcfg = {
7405         .f = cmd_showcfg_parsed,
7406         .data = NULL,
7407         .help_str = "show config rxtx|cores|fwd|txpkts",
7408         .tokens = {
7409                 (void *)&cmd_showcfg_show,
7410                 (void *)&cmd_showcfg_port,
7411                 (void *)&cmd_showcfg_what,
7412                 NULL,
7413         },
7414 };
7415
7416 /* *** SHOW ALL PORT INFO *** */
7417 struct cmd_showportall_result {
7418         cmdline_fixed_string_t show;
7419         cmdline_fixed_string_t port;
7420         cmdline_fixed_string_t what;
7421         cmdline_fixed_string_t all;
7422 };
7423
7424 static void cmd_showportall_parsed(void *parsed_result,
7425                                 __rte_unused struct cmdline *cl,
7426                                 __rte_unused void *data)
7427 {
7428         portid_t i;
7429
7430         struct cmd_showportall_result *res = parsed_result;
7431         if (!strcmp(res->show, "clear")) {
7432                 if (!strcmp(res->what, "stats"))
7433                         RTE_ETH_FOREACH_DEV(i)
7434                                 nic_stats_clear(i);
7435                 else if (!strcmp(res->what, "xstats"))
7436                         RTE_ETH_FOREACH_DEV(i)
7437                                 nic_xstats_clear(i);
7438         } else if (!strcmp(res->what, "info"))
7439                 RTE_ETH_FOREACH_DEV(i)
7440                         port_infos_display(i);
7441         else if (!strcmp(res->what, "summary")) {
7442                 port_summary_header_display();
7443                 RTE_ETH_FOREACH_DEV(i)
7444                         port_summary_display(i);
7445         }
7446         else if (!strcmp(res->what, "stats"))
7447                 RTE_ETH_FOREACH_DEV(i)
7448                         nic_stats_display(i);
7449         else if (!strcmp(res->what, "xstats"))
7450                 RTE_ETH_FOREACH_DEV(i)
7451                         nic_xstats_display(i);
7452         else if (!strcmp(res->what, "fdir"))
7453                 RTE_ETH_FOREACH_DEV(i)
7454                         fdir_get_infos(i);
7455         else if (!strcmp(res->what, "stat_qmap"))
7456                 RTE_ETH_FOREACH_DEV(i)
7457                         nic_stats_mapping_display(i);
7458         else if (!strcmp(res->what, "dcb_tc"))
7459                 RTE_ETH_FOREACH_DEV(i)
7460                         port_dcb_info_display(i);
7461         else if (!strcmp(res->what, "cap"))
7462                 RTE_ETH_FOREACH_DEV(i)
7463                         port_offload_cap_display(i);
7464 }
7465
7466 cmdline_parse_token_string_t cmd_showportall_show =
7467         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7468                                  "show#clear");
7469 cmdline_parse_token_string_t cmd_showportall_port =
7470         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7471 cmdline_parse_token_string_t cmd_showportall_what =
7472         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7473                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7474 cmdline_parse_token_string_t cmd_showportall_all =
7475         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7476 cmdline_parse_inst_t cmd_showportall = {
7477         .f = cmd_showportall_parsed,
7478         .data = NULL,
7479         .help_str = "show|clear port "
7480                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7481         .tokens = {
7482                 (void *)&cmd_showportall_show,
7483                 (void *)&cmd_showportall_port,
7484                 (void *)&cmd_showportall_what,
7485                 (void *)&cmd_showportall_all,
7486                 NULL,
7487         },
7488 };
7489
7490 /* *** SHOW PORT INFO *** */
7491 struct cmd_showport_result {
7492         cmdline_fixed_string_t show;
7493         cmdline_fixed_string_t port;
7494         cmdline_fixed_string_t what;
7495         uint16_t portnum;
7496 };
7497
7498 static void cmd_showport_parsed(void *parsed_result,
7499                                 __rte_unused struct cmdline *cl,
7500                                 __rte_unused void *data)
7501 {
7502         struct cmd_showport_result *res = parsed_result;
7503         if (!strcmp(res->show, "clear")) {
7504                 if (!strcmp(res->what, "stats"))
7505                         nic_stats_clear(res->portnum);
7506                 else if (!strcmp(res->what, "xstats"))
7507                         nic_xstats_clear(res->portnum);
7508         } else if (!strcmp(res->what, "info"))
7509                 port_infos_display(res->portnum);
7510         else if (!strcmp(res->what, "summary")) {
7511                 port_summary_header_display();
7512                 port_summary_display(res->portnum);
7513         }
7514         else if (!strcmp(res->what, "stats"))
7515                 nic_stats_display(res->portnum);
7516         else if (!strcmp(res->what, "xstats"))
7517                 nic_xstats_display(res->portnum);
7518         else if (!strcmp(res->what, "fdir"))
7519                  fdir_get_infos(res->portnum);
7520         else if (!strcmp(res->what, "stat_qmap"))
7521                 nic_stats_mapping_display(res->portnum);
7522         else if (!strcmp(res->what, "dcb_tc"))
7523                 port_dcb_info_display(res->portnum);
7524         else if (!strcmp(res->what, "cap"))
7525                 port_offload_cap_display(res->portnum);
7526 }
7527
7528 cmdline_parse_token_string_t cmd_showport_show =
7529         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7530                                  "show#clear");
7531 cmdline_parse_token_string_t cmd_showport_port =
7532         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7533 cmdline_parse_token_string_t cmd_showport_what =
7534         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7535                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7536 cmdline_parse_token_num_t cmd_showport_portnum =
7537         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7538
7539 cmdline_parse_inst_t cmd_showport = {
7540         .f = cmd_showport_parsed,
7541         .data = NULL,
7542         .help_str = "show|clear port "
7543                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7544                 "<port_id>",
7545         .tokens = {
7546                 (void *)&cmd_showport_show,
7547                 (void *)&cmd_showport_port,
7548                 (void *)&cmd_showport_what,
7549                 (void *)&cmd_showport_portnum,
7550                 NULL,
7551         },
7552 };
7553
7554 /* *** SHOW DEVICE INFO *** */
7555 struct cmd_showdevice_result {
7556         cmdline_fixed_string_t show;
7557         cmdline_fixed_string_t device;
7558         cmdline_fixed_string_t what;
7559         cmdline_fixed_string_t identifier;
7560 };
7561
7562 static void cmd_showdevice_parsed(void *parsed_result,
7563                                 __rte_unused struct cmdline *cl,
7564                                 __rte_unused void *data)
7565 {
7566         struct cmd_showdevice_result *res = parsed_result;
7567         if (!strcmp(res->what, "info")) {
7568                 if (!strcmp(res->identifier, "all"))
7569                         device_infos_display(NULL);
7570                 else
7571                         device_infos_display(res->identifier);
7572         }
7573 }
7574
7575 cmdline_parse_token_string_t cmd_showdevice_show =
7576         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7577                                  "show");
7578 cmdline_parse_token_string_t cmd_showdevice_device =
7579         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7580 cmdline_parse_token_string_t cmd_showdevice_what =
7581         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7582                                  "info");
7583 cmdline_parse_token_string_t cmd_showdevice_identifier =
7584         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7585                         identifier, NULL);
7586
7587 cmdline_parse_inst_t cmd_showdevice = {
7588         .f = cmd_showdevice_parsed,
7589         .data = NULL,
7590         .help_str = "show device info <identifier>|all",
7591         .tokens = {
7592                 (void *)&cmd_showdevice_show,
7593                 (void *)&cmd_showdevice_device,
7594                 (void *)&cmd_showdevice_what,
7595                 (void *)&cmd_showdevice_identifier,
7596                 NULL,
7597         },
7598 };
7599 /* *** SHOW QUEUE INFO *** */
7600 struct cmd_showqueue_result {
7601         cmdline_fixed_string_t show;
7602         cmdline_fixed_string_t type;
7603         cmdline_fixed_string_t what;
7604         uint16_t portnum;
7605         uint16_t queuenum;
7606 };
7607
7608 static void
7609 cmd_showqueue_parsed(void *parsed_result,
7610         __rte_unused struct cmdline *cl,
7611         __rte_unused void *data)
7612 {
7613         struct cmd_showqueue_result *res = parsed_result;
7614
7615         if (!strcmp(res->type, "rxq"))
7616                 rx_queue_infos_display(res->portnum, res->queuenum);
7617         else if (!strcmp(res->type, "txq"))
7618                 tx_queue_infos_display(res->portnum, res->queuenum);
7619 }
7620
7621 cmdline_parse_token_string_t cmd_showqueue_show =
7622         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7623 cmdline_parse_token_string_t cmd_showqueue_type =
7624         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7625 cmdline_parse_token_string_t cmd_showqueue_what =
7626         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7627 cmdline_parse_token_num_t cmd_showqueue_portnum =
7628         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7629 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7630         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7631
7632 cmdline_parse_inst_t cmd_showqueue = {
7633         .f = cmd_showqueue_parsed,
7634         .data = NULL,
7635         .help_str = "show rxq|txq info <port_id> <queue_id>",
7636         .tokens = {
7637                 (void *)&cmd_showqueue_show,
7638                 (void *)&cmd_showqueue_type,
7639                 (void *)&cmd_showqueue_what,
7640                 (void *)&cmd_showqueue_portnum,
7641                 (void *)&cmd_showqueue_queuenum,
7642                 NULL,
7643         },
7644 };
7645
7646 /* show/clear fwd engine statistics */
7647 struct fwd_result {
7648         cmdline_fixed_string_t action;
7649         cmdline_fixed_string_t fwd;
7650         cmdline_fixed_string_t stats;
7651         cmdline_fixed_string_t all;
7652 };
7653
7654 cmdline_parse_token_string_t cmd_fwd_action =
7655         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7656 cmdline_parse_token_string_t cmd_fwd_fwd =
7657         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7658 cmdline_parse_token_string_t cmd_fwd_stats =
7659         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7660 cmdline_parse_token_string_t cmd_fwd_all =
7661         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7662
7663 static void
7664 cmd_showfwdall_parsed(void *parsed_result,
7665                       __rte_unused struct cmdline *cl,
7666                       __rte_unused void *data)
7667 {
7668         struct fwd_result *res = parsed_result;
7669
7670         if (!strcmp(res->action, "show"))
7671                 fwd_stats_display();
7672         else
7673                 fwd_stats_reset();
7674 }
7675
7676 static cmdline_parse_inst_t cmd_showfwdall = {
7677         .f = cmd_showfwdall_parsed,
7678         .data = NULL,
7679         .help_str = "show|clear fwd stats all",
7680         .tokens = {
7681                 (void *)&cmd_fwd_action,
7682                 (void *)&cmd_fwd_fwd,
7683                 (void *)&cmd_fwd_stats,
7684                 (void *)&cmd_fwd_all,
7685                 NULL,
7686         },
7687 };
7688
7689 /* *** READ PORT REGISTER *** */
7690 struct cmd_read_reg_result {
7691         cmdline_fixed_string_t read;
7692         cmdline_fixed_string_t reg;
7693         portid_t port_id;
7694         uint32_t reg_off;
7695 };
7696
7697 static void
7698 cmd_read_reg_parsed(void *parsed_result,
7699                     __rte_unused struct cmdline *cl,
7700                     __rte_unused void *data)
7701 {
7702         struct cmd_read_reg_result *res = parsed_result;
7703         port_reg_display(res->port_id, res->reg_off);
7704 }
7705
7706 cmdline_parse_token_string_t cmd_read_reg_read =
7707         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7708 cmdline_parse_token_string_t cmd_read_reg_reg =
7709         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7710 cmdline_parse_token_num_t cmd_read_reg_port_id =
7711         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7712 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7713         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7714
7715 cmdline_parse_inst_t cmd_read_reg = {
7716         .f = cmd_read_reg_parsed,
7717         .data = NULL,
7718         .help_str = "read reg <port_id> <reg_off>",
7719         .tokens = {
7720                 (void *)&cmd_read_reg_read,
7721                 (void *)&cmd_read_reg_reg,
7722                 (void *)&cmd_read_reg_port_id,
7723                 (void *)&cmd_read_reg_reg_off,
7724                 NULL,
7725         },
7726 };
7727
7728 /* *** READ PORT REGISTER BIT FIELD *** */
7729 struct cmd_read_reg_bit_field_result {
7730         cmdline_fixed_string_t read;
7731         cmdline_fixed_string_t regfield;
7732         portid_t port_id;
7733         uint32_t reg_off;
7734         uint8_t bit1_pos;
7735         uint8_t bit2_pos;
7736 };
7737
7738 static void
7739 cmd_read_reg_bit_field_parsed(void *parsed_result,
7740                               __rte_unused struct cmdline *cl,
7741                               __rte_unused void *data)
7742 {
7743         struct cmd_read_reg_bit_field_result *res = parsed_result;
7744         port_reg_bit_field_display(res->port_id, res->reg_off,
7745                                    res->bit1_pos, res->bit2_pos);
7746 }
7747
7748 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7749         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7750                                  "read");
7751 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7752         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7753                                  regfield, "regfield");
7754 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7755         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7756                               UINT16);
7757 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7758         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7759                               UINT32);
7760 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7761         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7762                               UINT8);
7763 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7764         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7765                               UINT8);
7766
7767 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7768         .f = cmd_read_reg_bit_field_parsed,
7769         .data = NULL,
7770         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7771         "Read register bit field between bit_x and bit_y included",
7772         .tokens = {
7773                 (void *)&cmd_read_reg_bit_field_read,
7774                 (void *)&cmd_read_reg_bit_field_regfield,
7775                 (void *)&cmd_read_reg_bit_field_port_id,
7776                 (void *)&cmd_read_reg_bit_field_reg_off,
7777                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7778                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7779                 NULL,
7780         },
7781 };
7782
7783 /* *** READ PORT REGISTER BIT *** */
7784 struct cmd_read_reg_bit_result {
7785         cmdline_fixed_string_t read;
7786         cmdline_fixed_string_t regbit;
7787         portid_t port_id;
7788         uint32_t reg_off;
7789         uint8_t bit_pos;
7790 };
7791
7792 static void
7793 cmd_read_reg_bit_parsed(void *parsed_result,
7794                         __rte_unused struct cmdline *cl,
7795                         __rte_unused void *data)
7796 {
7797         struct cmd_read_reg_bit_result *res = parsed_result;
7798         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7799 }
7800
7801 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7802         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7803 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7804         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7805                                  regbit, "regbit");
7806 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7807         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7808 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7809         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7810 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7811         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7812
7813 cmdline_parse_inst_t cmd_read_reg_bit = {
7814         .f = cmd_read_reg_bit_parsed,
7815         .data = NULL,
7816         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7817         .tokens = {
7818                 (void *)&cmd_read_reg_bit_read,
7819                 (void *)&cmd_read_reg_bit_regbit,
7820                 (void *)&cmd_read_reg_bit_port_id,
7821                 (void *)&cmd_read_reg_bit_reg_off,
7822                 (void *)&cmd_read_reg_bit_bit_pos,
7823                 NULL,
7824         },
7825 };
7826
7827 /* *** WRITE PORT REGISTER *** */
7828 struct cmd_write_reg_result {
7829         cmdline_fixed_string_t write;
7830         cmdline_fixed_string_t reg;
7831         portid_t port_id;
7832         uint32_t reg_off;
7833         uint32_t value;
7834 };
7835
7836 static void
7837 cmd_write_reg_parsed(void *parsed_result,
7838                      __rte_unused struct cmdline *cl,
7839                      __rte_unused void *data)
7840 {
7841         struct cmd_write_reg_result *res = parsed_result;
7842         port_reg_set(res->port_id, res->reg_off, res->value);
7843 }
7844
7845 cmdline_parse_token_string_t cmd_write_reg_write =
7846         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7847 cmdline_parse_token_string_t cmd_write_reg_reg =
7848         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7849 cmdline_parse_token_num_t cmd_write_reg_port_id =
7850         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7851 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7852         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7853 cmdline_parse_token_num_t cmd_write_reg_value =
7854         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7855
7856 cmdline_parse_inst_t cmd_write_reg = {
7857         .f = cmd_write_reg_parsed,
7858         .data = NULL,
7859         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7860         .tokens = {
7861                 (void *)&cmd_write_reg_write,
7862                 (void *)&cmd_write_reg_reg,
7863                 (void *)&cmd_write_reg_port_id,
7864                 (void *)&cmd_write_reg_reg_off,
7865                 (void *)&cmd_write_reg_value,
7866                 NULL,
7867         },
7868 };
7869
7870 /* *** WRITE PORT REGISTER BIT FIELD *** */
7871 struct cmd_write_reg_bit_field_result {
7872         cmdline_fixed_string_t write;
7873         cmdline_fixed_string_t regfield;
7874         portid_t port_id;
7875         uint32_t reg_off;
7876         uint8_t bit1_pos;
7877         uint8_t bit2_pos;
7878         uint32_t value;
7879 };
7880
7881 static void
7882 cmd_write_reg_bit_field_parsed(void *parsed_result,
7883                                __rte_unused struct cmdline *cl,
7884                                __rte_unused void *data)
7885 {
7886         struct cmd_write_reg_bit_field_result *res = parsed_result;
7887         port_reg_bit_field_set(res->port_id, res->reg_off,
7888                           res->bit1_pos, res->bit2_pos, res->value);
7889 }
7890
7891 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7892         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7893                                  "write");
7894 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7895         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7896                                  regfield, "regfield");
7897 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7898         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7899                               UINT16);
7900 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7901         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7902                               UINT32);
7903 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7904         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7905                               UINT8);
7906 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7907         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7908                               UINT8);
7909 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7910         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7911                               UINT32);
7912
7913 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7914         .f = cmd_write_reg_bit_field_parsed,
7915         .data = NULL,
7916         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7917                 "<reg_value>: "
7918                 "Set register bit field between bit_x and bit_y included",
7919         .tokens = {
7920                 (void *)&cmd_write_reg_bit_field_write,
7921                 (void *)&cmd_write_reg_bit_field_regfield,
7922                 (void *)&cmd_write_reg_bit_field_port_id,
7923                 (void *)&cmd_write_reg_bit_field_reg_off,
7924                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7925                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7926                 (void *)&cmd_write_reg_bit_field_value,
7927                 NULL,
7928         },
7929 };
7930
7931 /* *** WRITE PORT REGISTER BIT *** */
7932 struct cmd_write_reg_bit_result {
7933         cmdline_fixed_string_t write;
7934         cmdline_fixed_string_t regbit;
7935         portid_t port_id;
7936         uint32_t reg_off;
7937         uint8_t bit_pos;
7938         uint8_t value;
7939 };
7940
7941 static void
7942 cmd_write_reg_bit_parsed(void *parsed_result,
7943                          __rte_unused struct cmdline *cl,
7944                          __rte_unused void *data)
7945 {
7946         struct cmd_write_reg_bit_result *res = parsed_result;
7947         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7948 }
7949
7950 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7951         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7952                                  "write");
7953 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7954         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7955                                  regbit, "regbit");
7956 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7957         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7958 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7959         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7960 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7961         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7962 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7963         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7964
7965 cmdline_parse_inst_t cmd_write_reg_bit = {
7966         .f = cmd_write_reg_bit_parsed,
7967         .data = NULL,
7968         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7969                 "0 <= bit_x <= 31",
7970         .tokens = {
7971                 (void *)&cmd_write_reg_bit_write,
7972                 (void *)&cmd_write_reg_bit_regbit,
7973                 (void *)&cmd_write_reg_bit_port_id,
7974                 (void *)&cmd_write_reg_bit_reg_off,
7975                 (void *)&cmd_write_reg_bit_bit_pos,
7976                 (void *)&cmd_write_reg_bit_value,
7977                 NULL,
7978         },
7979 };
7980
7981 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7982 struct cmd_read_rxd_txd_result {
7983         cmdline_fixed_string_t read;
7984         cmdline_fixed_string_t rxd_txd;
7985         portid_t port_id;
7986         uint16_t queue_id;
7987         uint16_t desc_id;
7988 };
7989
7990 static void
7991 cmd_read_rxd_txd_parsed(void *parsed_result,
7992                         __rte_unused struct cmdline *cl,
7993                         __rte_unused void *data)
7994 {
7995         struct cmd_read_rxd_txd_result *res = parsed_result;
7996
7997         if (!strcmp(res->rxd_txd, "rxd"))
7998                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7999         else if (!strcmp(res->rxd_txd, "txd"))
8000                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8001 }
8002
8003 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8004         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8005 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8006         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8007                                  "rxd#txd");
8008 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8009         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8010 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8011         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8012 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8013         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8014
8015 cmdline_parse_inst_t cmd_read_rxd_txd = {
8016         .f = cmd_read_rxd_txd_parsed,
8017         .data = NULL,
8018         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8019         .tokens = {
8020                 (void *)&cmd_read_rxd_txd_read,
8021                 (void *)&cmd_read_rxd_txd_rxd_txd,
8022                 (void *)&cmd_read_rxd_txd_port_id,
8023                 (void *)&cmd_read_rxd_txd_queue_id,
8024                 (void *)&cmd_read_rxd_txd_desc_id,
8025                 NULL,
8026         },
8027 };
8028
8029 /* *** QUIT *** */
8030 struct cmd_quit_result {
8031         cmdline_fixed_string_t quit;
8032 };
8033
8034 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8035                             struct cmdline *cl,
8036                             __rte_unused void *data)
8037 {
8038         cmdline_quit(cl);
8039 }
8040
8041 cmdline_parse_token_string_t cmd_quit_quit =
8042         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8043
8044 cmdline_parse_inst_t cmd_quit = {
8045         .f = cmd_quit_parsed,
8046         .data = NULL,
8047         .help_str = "quit: Exit application",
8048         .tokens = {
8049                 (void *)&cmd_quit_quit,
8050                 NULL,
8051         },
8052 };
8053
8054 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8055 struct cmd_mac_addr_result {
8056         cmdline_fixed_string_t mac_addr_cmd;
8057         cmdline_fixed_string_t what;
8058         uint16_t port_num;
8059         struct rte_ether_addr address;
8060 };
8061
8062 static void cmd_mac_addr_parsed(void *parsed_result,
8063                 __rte_unused struct cmdline *cl,
8064                 __rte_unused void *data)
8065 {
8066         struct cmd_mac_addr_result *res = parsed_result;
8067         int ret;
8068
8069         if (strcmp(res->what, "add") == 0)
8070                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8071         else if (strcmp(res->what, "set") == 0)
8072                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8073                                                        &res->address);
8074         else
8075                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8076
8077         /* check the return value and print it if is < 0 */
8078         if(ret < 0)
8079                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8080
8081 }
8082
8083 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8084         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8085                                 "mac_addr");
8086 cmdline_parse_token_string_t cmd_mac_addr_what =
8087         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8088                                 "add#remove#set");
8089 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8090                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8091                                         UINT16);
8092 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8093                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8094
8095 cmdline_parse_inst_t cmd_mac_addr = {
8096         .f = cmd_mac_addr_parsed,
8097         .data = (void *)0,
8098         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8099                         "Add/Remove/Set MAC address on port_id",
8100         .tokens = {
8101                 (void *)&cmd_mac_addr_cmd,
8102                 (void *)&cmd_mac_addr_what,
8103                 (void *)&cmd_mac_addr_portnum,
8104                 (void *)&cmd_mac_addr_addr,
8105                 NULL,
8106         },
8107 };
8108
8109 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8110 struct cmd_eth_peer_result {
8111         cmdline_fixed_string_t set;
8112         cmdline_fixed_string_t eth_peer;
8113         portid_t port_id;
8114         cmdline_fixed_string_t peer_addr;
8115 };
8116
8117 static void cmd_set_eth_peer_parsed(void *parsed_result,
8118                         __rte_unused struct cmdline *cl,
8119                         __rte_unused void *data)
8120 {
8121                 struct cmd_eth_peer_result *res = parsed_result;
8122
8123                 if (test_done == 0) {
8124                         printf("Please stop forwarding first\n");
8125                         return;
8126                 }
8127                 if (!strcmp(res->eth_peer, "eth-peer")) {
8128                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8129                         fwd_config_setup();
8130                 }
8131 }
8132 cmdline_parse_token_string_t cmd_eth_peer_set =
8133         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8134 cmdline_parse_token_string_t cmd_eth_peer =
8135         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8136 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8137         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8138 cmdline_parse_token_string_t cmd_eth_peer_addr =
8139         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8140
8141 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8142         .f = cmd_set_eth_peer_parsed,
8143         .data = NULL,
8144         .help_str = "set eth-peer <port_id> <peer_mac>",
8145         .tokens = {
8146                 (void *)&cmd_eth_peer_set,
8147                 (void *)&cmd_eth_peer,
8148                 (void *)&cmd_eth_peer_port_id,
8149                 (void *)&cmd_eth_peer_addr,
8150                 NULL,
8151         },
8152 };
8153
8154 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8155 struct cmd_set_qmap_result {
8156         cmdline_fixed_string_t set;
8157         cmdline_fixed_string_t qmap;
8158         cmdline_fixed_string_t what;
8159         portid_t port_id;
8160         uint16_t queue_id;
8161         uint8_t map_value;
8162 };
8163
8164 static void
8165 cmd_set_qmap_parsed(void *parsed_result,
8166                        __rte_unused struct cmdline *cl,
8167                        __rte_unused void *data)
8168 {
8169         struct cmd_set_qmap_result *res = parsed_result;
8170         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8171
8172         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8173 }
8174
8175 cmdline_parse_token_string_t cmd_setqmap_set =
8176         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8177                                  set, "set");
8178 cmdline_parse_token_string_t cmd_setqmap_qmap =
8179         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8180                                  qmap, "stat_qmap");
8181 cmdline_parse_token_string_t cmd_setqmap_what =
8182         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8183                                  what, "tx#rx");
8184 cmdline_parse_token_num_t cmd_setqmap_portid =
8185         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8186                               port_id, UINT16);
8187 cmdline_parse_token_num_t cmd_setqmap_queueid =
8188         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8189                               queue_id, UINT16);
8190 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8191         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8192                               map_value, UINT8);
8193
8194 cmdline_parse_inst_t cmd_set_qmap = {
8195         .f = cmd_set_qmap_parsed,
8196         .data = NULL,
8197         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8198                 "Set statistics mapping value on tx|rx queue_id of port_id",
8199         .tokens = {
8200                 (void *)&cmd_setqmap_set,
8201                 (void *)&cmd_setqmap_qmap,
8202                 (void *)&cmd_setqmap_what,
8203                 (void *)&cmd_setqmap_portid,
8204                 (void *)&cmd_setqmap_queueid,
8205                 (void *)&cmd_setqmap_mapvalue,
8206                 NULL,
8207         },
8208 };
8209
8210 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8211 struct cmd_set_xstats_hide_zero_result {
8212         cmdline_fixed_string_t keyword;
8213         cmdline_fixed_string_t name;
8214         cmdline_fixed_string_t on_off;
8215 };
8216
8217 static void
8218 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8219                         __rte_unused struct cmdline *cl,
8220                         __rte_unused void *data)
8221 {
8222         struct cmd_set_xstats_hide_zero_result *res;
8223         uint16_t on_off = 0;
8224
8225         res = parsed_result;
8226         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8227         set_xstats_hide_zero(on_off);
8228 }
8229
8230 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8231         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8232                                  keyword, "set");
8233 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8234         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8235                                  name, "xstats-hide-zero");
8236 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8237         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8238                                  on_off, "on#off");
8239
8240 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8241         .f = cmd_set_xstats_hide_zero_parsed,
8242         .data = NULL,
8243         .help_str = "set xstats-hide-zero on|off",
8244         .tokens = {
8245                 (void *)&cmd_set_xstats_hide_zero_keyword,
8246                 (void *)&cmd_set_xstats_hide_zero_name,
8247                 (void *)&cmd_set_xstats_hide_zero_on_off,
8248                 NULL,
8249         },
8250 };
8251
8252 /* *** CONFIGURE UNICAST HASH TABLE *** */
8253 struct cmd_set_uc_hash_table {
8254         cmdline_fixed_string_t set;
8255         cmdline_fixed_string_t port;
8256         portid_t port_id;
8257         cmdline_fixed_string_t what;
8258         struct rte_ether_addr address;
8259         cmdline_fixed_string_t mode;
8260 };
8261
8262 static void
8263 cmd_set_uc_hash_parsed(void *parsed_result,
8264                        __rte_unused struct cmdline *cl,
8265                        __rte_unused void *data)
8266 {
8267         int ret=0;
8268         struct cmd_set_uc_hash_table *res = parsed_result;
8269
8270         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8271
8272         if (strcmp(res->what, "uta") == 0)
8273                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8274                                                 &res->address,(uint8_t)is_on);
8275         if (ret < 0)
8276                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8277
8278 }
8279
8280 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8281         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8282                                  set, "set");
8283 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8284         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8285                                  port, "port");
8286 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8287         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8288                               port_id, UINT16);
8289 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8290         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8291                                  what, "uta");
8292 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8293         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8294                                 address);
8295 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8296         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8297                                  mode, "on#off");
8298
8299 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8300         .f = cmd_set_uc_hash_parsed,
8301         .data = NULL,
8302         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8303         .tokens = {
8304                 (void *)&cmd_set_uc_hash_set,
8305                 (void *)&cmd_set_uc_hash_port,
8306                 (void *)&cmd_set_uc_hash_portid,
8307                 (void *)&cmd_set_uc_hash_what,
8308                 (void *)&cmd_set_uc_hash_mac,
8309                 (void *)&cmd_set_uc_hash_mode,
8310                 NULL,
8311         },
8312 };
8313
8314 struct cmd_set_uc_all_hash_table {
8315         cmdline_fixed_string_t set;
8316         cmdline_fixed_string_t port;
8317         portid_t port_id;
8318         cmdline_fixed_string_t what;
8319         cmdline_fixed_string_t value;
8320         cmdline_fixed_string_t mode;
8321 };
8322
8323 static void
8324 cmd_set_uc_all_hash_parsed(void *parsed_result,
8325                        __rte_unused struct cmdline *cl,
8326                        __rte_unused void *data)
8327 {
8328         int ret=0;
8329         struct cmd_set_uc_all_hash_table *res = parsed_result;
8330
8331         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8332
8333         if ((strcmp(res->what, "uta") == 0) &&
8334                 (strcmp(res->value, "all") == 0))
8335                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8336         if (ret < 0)
8337                 printf("bad unicast hash table parameter,"
8338                         "return code = %d \n", ret);
8339 }
8340
8341 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8342         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8343                                  set, "set");
8344 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8345         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8346                                  port, "port");
8347 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8348         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8349                               port_id, UINT16);
8350 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8351         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8352                                  what, "uta");
8353 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8354         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8355                                 value,"all");
8356 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8357         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8358                                  mode, "on#off");
8359
8360 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8361         .f = cmd_set_uc_all_hash_parsed,
8362         .data = NULL,
8363         .help_str = "set port <port_id> uta all on|off",
8364         .tokens = {
8365                 (void *)&cmd_set_uc_all_hash_set,
8366                 (void *)&cmd_set_uc_all_hash_port,
8367                 (void *)&cmd_set_uc_all_hash_portid,
8368                 (void *)&cmd_set_uc_all_hash_what,
8369                 (void *)&cmd_set_uc_all_hash_value,
8370                 (void *)&cmd_set_uc_all_hash_mode,
8371                 NULL,
8372         },
8373 };
8374
8375 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8376 struct cmd_set_vf_macvlan_filter {
8377         cmdline_fixed_string_t set;
8378         cmdline_fixed_string_t port;
8379         portid_t port_id;
8380         cmdline_fixed_string_t vf;
8381         uint8_t vf_id;
8382         struct rte_ether_addr address;
8383         cmdline_fixed_string_t filter_type;
8384         cmdline_fixed_string_t mode;
8385 };
8386
8387 static void
8388 cmd_set_vf_macvlan_parsed(void *parsed_result,
8389                        __rte_unused struct cmdline *cl,
8390                        __rte_unused void *data)
8391 {
8392         int is_on, ret = 0;
8393         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8394         struct rte_eth_mac_filter filter;
8395
8396         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8397
8398         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8399
8400         /* set VF MAC filter */
8401         filter.is_vf = 1;
8402
8403         /* set VF ID */
8404         filter.dst_id = res->vf_id;
8405
8406         if (!strcmp(res->filter_type, "exact-mac"))
8407                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8408         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8409                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8410         else if (!strcmp(res->filter_type, "hashmac"))
8411                 filter.filter_type = RTE_MAC_HASH_MATCH;
8412         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8413                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8414
8415         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8416
8417         if (is_on)
8418                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8419                                         RTE_ETH_FILTER_MACVLAN,
8420                                         RTE_ETH_FILTER_ADD,
8421                                          &filter);
8422         else
8423                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8424                                         RTE_ETH_FILTER_MACVLAN,
8425                                         RTE_ETH_FILTER_DELETE,
8426                                         &filter);
8427
8428         if (ret < 0)
8429                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8430
8431 }
8432
8433 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8434         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8435                                  set, "set");
8436 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8437         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8438                                  port, "port");
8439 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8440         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8441                               port_id, UINT16);
8442 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8443         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8444                                  vf, "vf");
8445 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8446         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8447                                 vf_id, UINT8);
8448 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8449         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8450                                 address);
8451 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8452         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8453                                 filter_type, "exact-mac#exact-mac-vlan"
8454                                 "#hashmac#hashmac-vlan");
8455 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8456         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8457                                  mode, "on#off");
8458
8459 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8460         .f = cmd_set_vf_macvlan_parsed,
8461         .data = NULL,
8462         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8463                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8464                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8465                 "hash match rule: hash match of MAC and exact match of VLAN",
8466         .tokens = {
8467                 (void *)&cmd_set_vf_macvlan_set,
8468                 (void *)&cmd_set_vf_macvlan_port,
8469                 (void *)&cmd_set_vf_macvlan_portid,
8470                 (void *)&cmd_set_vf_macvlan_vf,
8471                 (void *)&cmd_set_vf_macvlan_vf_id,
8472                 (void *)&cmd_set_vf_macvlan_mac,
8473                 (void *)&cmd_set_vf_macvlan_filter_type,
8474                 (void *)&cmd_set_vf_macvlan_mode,
8475                 NULL,
8476         },
8477 };
8478
8479 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8480 struct cmd_set_vf_traffic {
8481         cmdline_fixed_string_t set;
8482         cmdline_fixed_string_t port;
8483         portid_t port_id;
8484         cmdline_fixed_string_t vf;
8485         uint8_t vf_id;
8486         cmdline_fixed_string_t what;
8487         cmdline_fixed_string_t mode;
8488 };
8489
8490 static void
8491 cmd_set_vf_traffic_parsed(void *parsed_result,
8492                        __rte_unused struct cmdline *cl,
8493                        __rte_unused void *data)
8494 {
8495         struct cmd_set_vf_traffic *res = parsed_result;
8496         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8497         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8498
8499         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8500 }
8501
8502 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8503         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8504                                  set, "set");
8505 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8506         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8507                                  port, "port");
8508 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8509         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8510                               port_id, UINT16);
8511 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8512         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8513                                  vf, "vf");
8514 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8515         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8516                               vf_id, UINT8);
8517 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8518         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8519                                  what, "tx#rx");
8520 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8521         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8522                                  mode, "on#off");
8523
8524 cmdline_parse_inst_t cmd_set_vf_traffic = {
8525         .f = cmd_set_vf_traffic_parsed,
8526         .data = NULL,
8527         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8528         .tokens = {
8529                 (void *)&cmd_setvf_traffic_set,
8530                 (void *)&cmd_setvf_traffic_port,
8531                 (void *)&cmd_setvf_traffic_portid,
8532                 (void *)&cmd_setvf_traffic_vf,
8533                 (void *)&cmd_setvf_traffic_vfid,
8534                 (void *)&cmd_setvf_traffic_what,
8535                 (void *)&cmd_setvf_traffic_mode,
8536                 NULL,
8537         },
8538 };
8539
8540 /* *** CONFIGURE VF RECEIVE MODE *** */
8541 struct cmd_set_vf_rxmode {
8542         cmdline_fixed_string_t set;
8543         cmdline_fixed_string_t port;
8544         portid_t port_id;
8545         cmdline_fixed_string_t vf;
8546         uint8_t vf_id;
8547         cmdline_fixed_string_t what;
8548         cmdline_fixed_string_t mode;
8549         cmdline_fixed_string_t on;
8550 };
8551
8552 static void
8553 cmd_set_vf_rxmode_parsed(void *parsed_result,
8554                        __rte_unused struct cmdline *cl,
8555                        __rte_unused void *data)
8556 {
8557         int ret = -ENOTSUP;
8558         uint16_t vf_rxmode = 0;
8559         struct cmd_set_vf_rxmode *res = parsed_result;
8560
8561         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8562         if (!strcmp(res->what,"rxmode")) {
8563                 if (!strcmp(res->mode, "AUPE"))
8564                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8565                 else if (!strcmp(res->mode, "ROPE"))
8566                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8567                 else if (!strcmp(res->mode, "BAM"))
8568                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8569                 else if (!strncmp(res->mode, "MPE",3))
8570                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8571         }
8572
8573         RTE_SET_USED(is_on);
8574
8575 #ifdef RTE_LIBRTE_IXGBE_PMD
8576         if (ret == -ENOTSUP)
8577                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8578                                                   vf_rxmode, (uint8_t)is_on);
8579 #endif
8580 #ifdef RTE_LIBRTE_BNXT_PMD
8581         if (ret == -ENOTSUP)
8582                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8583                                                  vf_rxmode, (uint8_t)is_on);
8584 #endif
8585         if (ret < 0)
8586                 printf("bad VF receive mode parameter, return code = %d \n",
8587                 ret);
8588 }
8589
8590 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8591         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8592                                  set, "set");
8593 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8594         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8595                                  port, "port");
8596 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8597         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8598                               port_id, UINT16);
8599 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8600         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8601                                  vf, "vf");
8602 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8603         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8604                               vf_id, UINT8);
8605 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8606         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8607                                  what, "rxmode");
8608 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8609         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8610                                  mode, "AUPE#ROPE#BAM#MPE");
8611 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8612         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8613                                  on, "on#off");
8614
8615 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8616         .f = cmd_set_vf_rxmode_parsed,
8617         .data = NULL,
8618         .help_str = "set port <port_id> vf <vf_id> rxmode "
8619                 "AUPE|ROPE|BAM|MPE on|off",
8620         .tokens = {
8621                 (void *)&cmd_set_vf_rxmode_set,
8622                 (void *)&cmd_set_vf_rxmode_port,
8623                 (void *)&cmd_set_vf_rxmode_portid,
8624                 (void *)&cmd_set_vf_rxmode_vf,
8625                 (void *)&cmd_set_vf_rxmode_vfid,
8626                 (void *)&cmd_set_vf_rxmode_what,
8627                 (void *)&cmd_set_vf_rxmode_mode,
8628                 (void *)&cmd_set_vf_rxmode_on,
8629                 NULL,
8630         },
8631 };
8632
8633 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8634 struct cmd_vf_mac_addr_result {
8635         cmdline_fixed_string_t mac_addr_cmd;
8636         cmdline_fixed_string_t what;
8637         cmdline_fixed_string_t port;
8638         uint16_t port_num;
8639         cmdline_fixed_string_t vf;
8640         uint8_t vf_num;
8641         struct rte_ether_addr address;
8642 };
8643
8644 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8645                 __rte_unused struct cmdline *cl,
8646                 __rte_unused void *data)
8647 {
8648         struct cmd_vf_mac_addr_result *res = parsed_result;
8649         int ret = -ENOTSUP;
8650
8651         if (strcmp(res->what, "add") != 0)
8652                 return;
8653
8654 #ifdef RTE_LIBRTE_I40E_PMD
8655         if (ret == -ENOTSUP)
8656                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8657                                                    &res->address);
8658 #endif
8659 #ifdef RTE_LIBRTE_BNXT_PMD
8660         if (ret == -ENOTSUP)
8661                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8662                                                 res->vf_num);
8663 #endif
8664
8665         if(ret < 0)
8666                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8667
8668 }
8669
8670 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8671         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8672                                 mac_addr_cmd,"mac_addr");
8673 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8674         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8675                                 what,"add");
8676 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8677         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8678                                 port,"port");
8679 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8680         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8681                                 port_num, UINT16);
8682 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8683         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8684                                 vf,"vf");
8685 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8686         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8687                                 vf_num, UINT8);
8688 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8689         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8690                                 address);
8691
8692 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8693         .f = cmd_vf_mac_addr_parsed,
8694         .data = (void *)0,
8695         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8696                 "Add MAC address filtering for a VF on port_id",
8697         .tokens = {
8698                 (void *)&cmd_vf_mac_addr_cmd,
8699                 (void *)&cmd_vf_mac_addr_what,
8700                 (void *)&cmd_vf_mac_addr_port,
8701                 (void *)&cmd_vf_mac_addr_portnum,
8702                 (void *)&cmd_vf_mac_addr_vf,
8703                 (void *)&cmd_vf_mac_addr_vfnum,
8704                 (void *)&cmd_vf_mac_addr_addr,
8705                 NULL,
8706         },
8707 };
8708
8709 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8710 struct cmd_vf_rx_vlan_filter {
8711         cmdline_fixed_string_t rx_vlan;
8712         cmdline_fixed_string_t what;
8713         uint16_t vlan_id;
8714         cmdline_fixed_string_t port;
8715         portid_t port_id;
8716         cmdline_fixed_string_t vf;
8717         uint64_t vf_mask;
8718 };
8719
8720 static void
8721 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8722                           __rte_unused struct cmdline *cl,
8723                           __rte_unused void *data)
8724 {
8725         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8726         int ret = -ENOTSUP;
8727
8728         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8729
8730 #ifdef RTE_LIBRTE_IXGBE_PMD
8731         if (ret == -ENOTSUP)
8732                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8733                                 res->vlan_id, res->vf_mask, is_add);
8734 #endif
8735 #ifdef RTE_LIBRTE_I40E_PMD
8736         if (ret == -ENOTSUP)
8737                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8738                                 res->vlan_id, res->vf_mask, is_add);
8739 #endif
8740 #ifdef RTE_LIBRTE_BNXT_PMD
8741         if (ret == -ENOTSUP)
8742                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8743                                 res->vlan_id, res->vf_mask, is_add);
8744 #endif
8745
8746         switch (ret) {
8747         case 0:
8748                 break;
8749         case -EINVAL:
8750                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8751                                 res->vlan_id, res->vf_mask);
8752                 break;
8753         case -ENODEV:
8754                 printf("invalid port_id %d\n", res->port_id);
8755                 break;
8756         case -ENOTSUP:
8757                 printf("function not implemented or supported\n");
8758                 break;
8759         default:
8760                 printf("programming error: (%s)\n", strerror(-ret));
8761         }
8762 }
8763
8764 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8765         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8766                                  rx_vlan, "rx_vlan");
8767 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8768         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8769                                  what, "add#rm");
8770 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8771         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8772                               vlan_id, UINT16);
8773 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8774         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8775                                  port, "port");
8776 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8777         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8778                               port_id, UINT16);
8779 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8780         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8781                                  vf, "vf");
8782 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8783         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8784                               vf_mask, UINT64);
8785
8786 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8787         .f = cmd_vf_rx_vlan_filter_parsed,
8788         .data = NULL,
8789         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8790                 "(vf_mask = hexadecimal VF mask)",
8791         .tokens = {
8792                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8793                 (void *)&cmd_vf_rx_vlan_filter_what,
8794                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8795                 (void *)&cmd_vf_rx_vlan_filter_port,
8796                 (void *)&cmd_vf_rx_vlan_filter_portid,
8797                 (void *)&cmd_vf_rx_vlan_filter_vf,
8798                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8799                 NULL,
8800         },
8801 };
8802
8803 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8804 struct cmd_queue_rate_limit_result {
8805         cmdline_fixed_string_t set;
8806         cmdline_fixed_string_t port;
8807         uint16_t port_num;
8808         cmdline_fixed_string_t queue;
8809         uint8_t queue_num;
8810         cmdline_fixed_string_t rate;
8811         uint16_t rate_num;
8812 };
8813
8814 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8815                 __rte_unused struct cmdline *cl,
8816                 __rte_unused void *data)
8817 {
8818         struct cmd_queue_rate_limit_result *res = parsed_result;
8819         int ret = 0;
8820
8821         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8822                 && (strcmp(res->queue, "queue") == 0)
8823                 && (strcmp(res->rate, "rate") == 0))
8824                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8825                                         res->rate_num);
8826         if (ret < 0)
8827                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8828
8829 }
8830
8831 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8832         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8833                                 set, "set");
8834 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8835         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8836                                 port, "port");
8837 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8838         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8839                                 port_num, UINT16);
8840 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8841         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8842                                 queue, "queue");
8843 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8844         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8845                                 queue_num, UINT8);
8846 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8847         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8848                                 rate, "rate");
8849 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8850         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8851                                 rate_num, UINT16);
8852
8853 cmdline_parse_inst_t cmd_queue_rate_limit = {
8854         .f = cmd_queue_rate_limit_parsed,
8855         .data = (void *)0,
8856         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8857                 "Set rate limit for a queue on port_id",
8858         .tokens = {
8859                 (void *)&cmd_queue_rate_limit_set,
8860                 (void *)&cmd_queue_rate_limit_port,
8861                 (void *)&cmd_queue_rate_limit_portnum,
8862                 (void *)&cmd_queue_rate_limit_queue,
8863                 (void *)&cmd_queue_rate_limit_queuenum,
8864                 (void *)&cmd_queue_rate_limit_rate,
8865                 (void *)&cmd_queue_rate_limit_ratenum,
8866                 NULL,
8867         },
8868 };
8869
8870 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8871 struct cmd_vf_rate_limit_result {
8872         cmdline_fixed_string_t set;
8873         cmdline_fixed_string_t port;
8874         uint16_t port_num;
8875         cmdline_fixed_string_t vf;
8876         uint8_t vf_num;
8877         cmdline_fixed_string_t rate;
8878         uint16_t rate_num;
8879         cmdline_fixed_string_t q_msk;
8880         uint64_t q_msk_val;
8881 };
8882
8883 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8884                 __rte_unused struct cmdline *cl,
8885                 __rte_unused void *data)
8886 {
8887         struct cmd_vf_rate_limit_result *res = parsed_result;
8888         int ret = 0;
8889
8890         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8891                 && (strcmp(res->vf, "vf") == 0)
8892                 && (strcmp(res->rate, "rate") == 0)
8893                 && (strcmp(res->q_msk, "queue_mask") == 0))
8894                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8895                                         res->rate_num, res->q_msk_val);
8896         if (ret < 0)
8897                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8898
8899 }
8900
8901 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8902         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8903                                 set, "set");
8904 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8905         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8906                                 port, "port");
8907 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8908         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8909                                 port_num, UINT16);
8910 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8911         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8912                                 vf, "vf");
8913 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8914         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8915                                 vf_num, UINT8);
8916 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8917         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8918                                 rate, "rate");
8919 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8920         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8921                                 rate_num, UINT16);
8922 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8923         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8924                                 q_msk, "queue_mask");
8925 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8926         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8927                                 q_msk_val, UINT64);
8928
8929 cmdline_parse_inst_t cmd_vf_rate_limit = {
8930         .f = cmd_vf_rate_limit_parsed,
8931         .data = (void *)0,
8932         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8933                 "queue_mask <queue_mask_value>: "
8934                 "Set rate limit for queues of VF on port_id",
8935         .tokens = {
8936                 (void *)&cmd_vf_rate_limit_set,
8937                 (void *)&cmd_vf_rate_limit_port,
8938                 (void *)&cmd_vf_rate_limit_portnum,
8939                 (void *)&cmd_vf_rate_limit_vf,
8940                 (void *)&cmd_vf_rate_limit_vfnum,
8941                 (void *)&cmd_vf_rate_limit_rate,
8942                 (void *)&cmd_vf_rate_limit_ratenum,
8943                 (void *)&cmd_vf_rate_limit_q_msk,
8944                 (void *)&cmd_vf_rate_limit_q_msk_val,
8945                 NULL,
8946         },
8947 };
8948
8949 /* *** ADD TUNNEL FILTER OF A PORT *** */
8950 struct cmd_tunnel_filter_result {
8951         cmdline_fixed_string_t cmd;
8952         cmdline_fixed_string_t what;
8953         portid_t port_id;
8954         struct rte_ether_addr outer_mac;
8955         struct rte_ether_addr inner_mac;
8956         cmdline_ipaddr_t ip_value;
8957         uint16_t inner_vlan;
8958         cmdline_fixed_string_t tunnel_type;
8959         cmdline_fixed_string_t filter_type;
8960         uint32_t tenant_id;
8961         uint16_t queue_num;
8962 };
8963
8964 static void
8965 cmd_tunnel_filter_parsed(void *parsed_result,
8966                           __rte_unused struct cmdline *cl,
8967                           __rte_unused void *data)
8968 {
8969         struct cmd_tunnel_filter_result *res = parsed_result;
8970         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8971         int ret = 0;
8972
8973         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8974
8975         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8976         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8977         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8978
8979         if (res->ip_value.family == AF_INET) {
8980                 tunnel_filter_conf.ip_addr.ipv4_addr =
8981                         res->ip_value.addr.ipv4.s_addr;
8982                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
8983         } else {
8984                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
8985                         &(res->ip_value.addr.ipv6),
8986                         sizeof(struct in6_addr));
8987                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
8988         }
8989
8990         if (!strcmp(res->filter_type, "imac-ivlan"))
8991                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
8992         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
8993                 tunnel_filter_conf.filter_type =
8994                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
8995         else if (!strcmp(res->filter_type, "imac-tenid"))
8996                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
8997         else if (!strcmp(res->filter_type, "imac"))
8998                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
8999         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9000                 tunnel_filter_conf.filter_type =
9001                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9002         else if (!strcmp(res->filter_type, "oip"))
9003                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9004         else if (!strcmp(res->filter_type, "iip"))
9005                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9006         else {
9007                 printf("The filter type is not supported");
9008                 return;
9009         }
9010
9011         if (!strcmp(res->tunnel_type, "vxlan"))
9012                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9013         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9014                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9015         else if (!strcmp(res->tunnel_type, "nvgre"))
9016                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9017         else if (!strcmp(res->tunnel_type, "ipingre"))
9018                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9019         else {
9020                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9021                 return;
9022         }
9023
9024         tunnel_filter_conf.tenant_id = res->tenant_id;
9025         tunnel_filter_conf.queue_id = res->queue_num;
9026         if (!strcmp(res->what, "add"))
9027                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9028                                         RTE_ETH_FILTER_TUNNEL,
9029                                         RTE_ETH_FILTER_ADD,
9030                                         &tunnel_filter_conf);
9031         else
9032                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9033                                         RTE_ETH_FILTER_TUNNEL,
9034                                         RTE_ETH_FILTER_DELETE,
9035                                         &tunnel_filter_conf);
9036         if (ret < 0)
9037                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9038                                 strerror(-ret));
9039
9040 }
9041 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9042         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9043         cmd, "tunnel_filter");
9044 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9045         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9046         what, "add#rm");
9047 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9048         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9049         port_id, UINT16);
9050 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9051         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9052         outer_mac);
9053 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9054         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9055         inner_mac);
9056 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9057         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9058         inner_vlan, UINT16);
9059 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9060         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9061         ip_value);
9062 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9063         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9064         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9065
9066 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9067         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9068         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9069                 "imac#omac-imac-tenid");
9070 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9071         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9072         tenant_id, UINT32);
9073 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9074         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9075         queue_num, UINT16);
9076
9077 cmdline_parse_inst_t cmd_tunnel_filter = {
9078         .f = cmd_tunnel_filter_parsed,
9079         .data = (void *)0,
9080         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9081                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9082                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9083                 "<queue_id>: Add/Rm tunnel filter of a port",
9084         .tokens = {
9085                 (void *)&cmd_tunnel_filter_cmd,
9086                 (void *)&cmd_tunnel_filter_what,
9087                 (void *)&cmd_tunnel_filter_port_id,
9088                 (void *)&cmd_tunnel_filter_outer_mac,
9089                 (void *)&cmd_tunnel_filter_inner_mac,
9090                 (void *)&cmd_tunnel_filter_ip_value,
9091                 (void *)&cmd_tunnel_filter_innner_vlan,
9092                 (void *)&cmd_tunnel_filter_tunnel_type,
9093                 (void *)&cmd_tunnel_filter_filter_type,
9094                 (void *)&cmd_tunnel_filter_tenant_id,
9095                 (void *)&cmd_tunnel_filter_queue_num,
9096                 NULL,
9097         },
9098 };
9099
9100 /* *** CONFIGURE TUNNEL UDP PORT *** */
9101 struct cmd_tunnel_udp_config {
9102         cmdline_fixed_string_t cmd;
9103         cmdline_fixed_string_t what;
9104         uint16_t udp_port;
9105         portid_t port_id;
9106 };
9107
9108 static void
9109 cmd_tunnel_udp_config_parsed(void *parsed_result,
9110                           __rte_unused struct cmdline *cl,
9111                           __rte_unused void *data)
9112 {
9113         struct cmd_tunnel_udp_config *res = parsed_result;
9114         struct rte_eth_udp_tunnel tunnel_udp;
9115         int ret;
9116
9117         tunnel_udp.udp_port = res->udp_port;
9118
9119         if (!strcmp(res->cmd, "rx_vxlan_port"))
9120                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9121
9122         if (!strcmp(res->what, "add"))
9123                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9124                                                       &tunnel_udp);
9125         else
9126                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9127                                                          &tunnel_udp);
9128
9129         if (ret < 0)
9130                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9131 }
9132
9133 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9134         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9135                                 cmd, "rx_vxlan_port");
9136 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9137         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9138                                 what, "add#rm");
9139 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9140         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9141                                 udp_port, UINT16);
9142 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9143         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9144                                 port_id, UINT16);
9145
9146 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9147         .f = cmd_tunnel_udp_config_parsed,
9148         .data = (void *)0,
9149         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9150                 "Add/Remove a tunneling UDP port filter",
9151         .tokens = {
9152                 (void *)&cmd_tunnel_udp_config_cmd,
9153                 (void *)&cmd_tunnel_udp_config_what,
9154                 (void *)&cmd_tunnel_udp_config_udp_port,
9155                 (void *)&cmd_tunnel_udp_config_port_id,
9156                 NULL,
9157         },
9158 };
9159
9160 struct cmd_config_tunnel_udp_port {
9161         cmdline_fixed_string_t port;
9162         cmdline_fixed_string_t config;
9163         portid_t port_id;
9164         cmdline_fixed_string_t udp_tunnel_port;
9165         cmdline_fixed_string_t action;
9166         cmdline_fixed_string_t tunnel_type;
9167         uint16_t udp_port;
9168 };
9169
9170 static void
9171 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9172                                __rte_unused struct cmdline *cl,
9173                                __rte_unused void *data)
9174 {
9175         struct cmd_config_tunnel_udp_port *res = parsed_result;
9176         struct rte_eth_udp_tunnel tunnel_udp;
9177         int ret = 0;
9178
9179         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9180                 return;
9181
9182         tunnel_udp.udp_port = res->udp_port;
9183
9184         if (!strcmp(res->tunnel_type, "vxlan")) {
9185                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9186         } else if (!strcmp(res->tunnel_type, "geneve")) {
9187                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9188         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9189                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9190         } else {
9191                 printf("Invalid tunnel type\n");
9192                 return;
9193         }
9194
9195         if (!strcmp(res->action, "add"))
9196                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9197                                                       &tunnel_udp);
9198         else
9199                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9200                                                          &tunnel_udp);
9201
9202         if (ret < 0)
9203                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9204 }
9205
9206 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9207         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9208                                  "port");
9209 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9210         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9211                                  "config");
9212 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9213         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9214                               UINT16);
9215 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9216         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9217                                  udp_tunnel_port,
9218                                  "udp_tunnel_port");
9219 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9220         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9221                                  "add#rm");
9222 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9223         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9224                                  "vxlan#geneve#vxlan-gpe");
9225 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9226         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9227                               UINT16);
9228
9229 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9230         .f = cmd_cfg_tunnel_udp_port_parsed,
9231         .data = NULL,
9232         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9233         .tokens = {
9234                 (void *)&cmd_config_tunnel_udp_port_port,
9235                 (void *)&cmd_config_tunnel_udp_port_config,
9236                 (void *)&cmd_config_tunnel_udp_port_port_id,
9237                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9238                 (void *)&cmd_config_tunnel_udp_port_action,
9239                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9240                 (void *)&cmd_config_tunnel_udp_port_value,
9241                 NULL,
9242         },
9243 };
9244
9245 /* *** GLOBAL CONFIG *** */
9246 struct cmd_global_config_result {
9247         cmdline_fixed_string_t cmd;
9248         portid_t port_id;
9249         cmdline_fixed_string_t cfg_type;
9250         uint8_t len;
9251 };
9252
9253 static void
9254 cmd_global_config_parsed(void *parsed_result,
9255                          __rte_unused struct cmdline *cl,
9256                          __rte_unused void *data)
9257 {
9258         struct cmd_global_config_result *res = parsed_result;
9259         struct rte_eth_global_cfg conf;
9260         int ret;
9261
9262         memset(&conf, 0, sizeof(conf));
9263         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9264         conf.cfg.gre_key_len = res->len;
9265         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9266                                       RTE_ETH_FILTER_SET, &conf);
9267         if (ret != 0)
9268                 printf("Global config error\n");
9269 }
9270
9271 cmdline_parse_token_string_t cmd_global_config_cmd =
9272         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9273                 "global_config");
9274 cmdline_parse_token_num_t cmd_global_config_port_id =
9275         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9276                                UINT16);
9277 cmdline_parse_token_string_t cmd_global_config_type =
9278         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9279                 cfg_type, "gre-key-len");
9280 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9281         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9282                 len, UINT8);
9283
9284 cmdline_parse_inst_t cmd_global_config = {
9285         .f = cmd_global_config_parsed,
9286         .data = (void *)NULL,
9287         .help_str = "global_config <port_id> gre-key-len <key_len>",
9288         .tokens = {
9289                 (void *)&cmd_global_config_cmd,
9290                 (void *)&cmd_global_config_port_id,
9291                 (void *)&cmd_global_config_type,
9292                 (void *)&cmd_global_config_gre_key_len,
9293                 NULL,
9294         },
9295 };
9296
9297 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9298 struct cmd_set_mirror_mask_result {
9299         cmdline_fixed_string_t set;
9300         cmdline_fixed_string_t port;
9301         portid_t port_id;
9302         cmdline_fixed_string_t mirror;
9303         uint8_t rule_id;
9304         cmdline_fixed_string_t what;
9305         cmdline_fixed_string_t value;
9306         cmdline_fixed_string_t dstpool;
9307         uint8_t dstpool_id;
9308         cmdline_fixed_string_t on;
9309 };
9310
9311 cmdline_parse_token_string_t cmd_mirror_mask_set =
9312         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9313                                 set, "set");
9314 cmdline_parse_token_string_t cmd_mirror_mask_port =
9315         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9316                                 port, "port");
9317 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9318         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9319                                 port_id, UINT16);
9320 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9321         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9322                                 mirror, "mirror-rule");
9323 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9324         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9325                                 rule_id, UINT8);
9326 cmdline_parse_token_string_t cmd_mirror_mask_what =
9327         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9328                                 what, "pool-mirror-up#pool-mirror-down"
9329                                       "#vlan-mirror");
9330 cmdline_parse_token_string_t cmd_mirror_mask_value =
9331         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9332                                 value, NULL);
9333 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9334         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9335                                 dstpool, "dst-pool");
9336 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9337         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9338                                 dstpool_id, UINT8);
9339 cmdline_parse_token_string_t cmd_mirror_mask_on =
9340         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9341                                 on, "on#off");
9342
9343 static void
9344 cmd_set_mirror_mask_parsed(void *parsed_result,
9345                        __rte_unused struct cmdline *cl,
9346                        __rte_unused void *data)
9347 {
9348         int ret,nb_item,i;
9349         struct cmd_set_mirror_mask_result *res = parsed_result;
9350         struct rte_eth_mirror_conf mr_conf;
9351
9352         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9353
9354         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9355
9356         mr_conf.dst_pool = res->dstpool_id;
9357
9358         if (!strcmp(res->what, "pool-mirror-up")) {
9359                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9360                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9361         } else if (!strcmp(res->what, "pool-mirror-down")) {
9362                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9363                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9364         } else if (!strcmp(res->what, "vlan-mirror")) {
9365                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9366                 nb_item = parse_item_list(res->value, "vlan",
9367                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9368                 if (nb_item <= 0)
9369                         return;
9370
9371                 for (i = 0; i < nb_item; i++) {
9372                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9373                                 printf("Invalid vlan_id: must be < 4096\n");
9374                                 return;
9375                         }
9376
9377                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9378                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9379                 }
9380         }
9381
9382         if (!strcmp(res->on, "on"))
9383                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9384                                                 res->rule_id, 1);
9385         else
9386                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9387                                                 res->rule_id, 0);
9388         if (ret < 0)
9389                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9390 }
9391
9392 cmdline_parse_inst_t cmd_set_mirror_mask = {
9393                 .f = cmd_set_mirror_mask_parsed,
9394                 .data = NULL,
9395                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9396                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9397                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9398                 .tokens = {
9399                         (void *)&cmd_mirror_mask_set,
9400                         (void *)&cmd_mirror_mask_port,
9401                         (void *)&cmd_mirror_mask_portid,
9402                         (void *)&cmd_mirror_mask_mirror,
9403                         (void *)&cmd_mirror_mask_ruleid,
9404                         (void *)&cmd_mirror_mask_what,
9405                         (void *)&cmd_mirror_mask_value,
9406                         (void *)&cmd_mirror_mask_dstpool,
9407                         (void *)&cmd_mirror_mask_poolid,
9408                         (void *)&cmd_mirror_mask_on,
9409                         NULL,
9410                 },
9411 };
9412
9413 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9414 struct cmd_set_mirror_link_result {
9415         cmdline_fixed_string_t set;
9416         cmdline_fixed_string_t port;
9417         portid_t port_id;
9418         cmdline_fixed_string_t mirror;
9419         uint8_t rule_id;
9420         cmdline_fixed_string_t what;
9421         cmdline_fixed_string_t dstpool;
9422         uint8_t dstpool_id;
9423         cmdline_fixed_string_t on;
9424 };
9425
9426 cmdline_parse_token_string_t cmd_mirror_link_set =
9427         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9428                                  set, "set");
9429 cmdline_parse_token_string_t cmd_mirror_link_port =
9430         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9431                                 port, "port");
9432 cmdline_parse_token_num_t cmd_mirror_link_portid =
9433         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9434                                 port_id, UINT16);
9435 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9436         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9437                                 mirror, "mirror-rule");
9438 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9439         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9440                             rule_id, UINT8);
9441 cmdline_parse_token_string_t cmd_mirror_link_what =
9442         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9443                                 what, "uplink-mirror#downlink-mirror");
9444 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9445         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9446                                 dstpool, "dst-pool");
9447 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9448         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9449                                 dstpool_id, UINT8);
9450 cmdline_parse_token_string_t cmd_mirror_link_on =
9451         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9452                                 on, "on#off");
9453
9454 static void
9455 cmd_set_mirror_link_parsed(void *parsed_result,
9456                        __rte_unused struct cmdline *cl,
9457                        __rte_unused void *data)
9458 {
9459         int ret;
9460         struct cmd_set_mirror_link_result *res = parsed_result;
9461         struct rte_eth_mirror_conf mr_conf;
9462
9463         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9464         if (!strcmp(res->what, "uplink-mirror"))
9465                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9466         else
9467                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9468
9469         mr_conf.dst_pool = res->dstpool_id;
9470
9471         if (!strcmp(res->on, "on"))
9472                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9473                                                 res->rule_id, 1);
9474         else
9475                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9476                                                 res->rule_id, 0);
9477
9478         /* check the return value and print it if is < 0 */
9479         if (ret < 0)
9480                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9481
9482 }
9483
9484 cmdline_parse_inst_t cmd_set_mirror_link = {
9485                 .f = cmd_set_mirror_link_parsed,
9486                 .data = NULL,
9487                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9488                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9489                 .tokens = {
9490                         (void *)&cmd_mirror_link_set,
9491                         (void *)&cmd_mirror_link_port,
9492                         (void *)&cmd_mirror_link_portid,
9493                         (void *)&cmd_mirror_link_mirror,
9494                         (void *)&cmd_mirror_link_ruleid,
9495                         (void *)&cmd_mirror_link_what,
9496                         (void *)&cmd_mirror_link_dstpool,
9497                         (void *)&cmd_mirror_link_poolid,
9498                         (void *)&cmd_mirror_link_on,
9499                         NULL,
9500                 },
9501 };
9502
9503 /* *** RESET VM MIRROR RULE *** */
9504 struct cmd_rm_mirror_rule_result {
9505         cmdline_fixed_string_t reset;
9506         cmdline_fixed_string_t port;
9507         portid_t port_id;
9508         cmdline_fixed_string_t mirror;
9509         uint8_t rule_id;
9510 };
9511
9512 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9513         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9514                                  reset, "reset");
9515 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9516         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9517                                 port, "port");
9518 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9519         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9520                                 port_id, UINT16);
9521 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9522         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9523                                 mirror, "mirror-rule");
9524 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9525         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9526                                 rule_id, UINT8);
9527
9528 static void
9529 cmd_reset_mirror_rule_parsed(void *parsed_result,
9530                        __rte_unused struct cmdline *cl,
9531                        __rte_unused void *data)
9532 {
9533         int ret;
9534         struct cmd_set_mirror_link_result *res = parsed_result;
9535         /* check rule_id */
9536         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9537         if(ret < 0)
9538                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9539 }
9540
9541 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9542                 .f = cmd_reset_mirror_rule_parsed,
9543                 .data = NULL,
9544                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9545                 .tokens = {
9546                         (void *)&cmd_rm_mirror_rule_reset,
9547                         (void *)&cmd_rm_mirror_rule_port,
9548                         (void *)&cmd_rm_mirror_rule_portid,
9549                         (void *)&cmd_rm_mirror_rule_mirror,
9550                         (void *)&cmd_rm_mirror_rule_ruleid,
9551                         NULL,
9552                 },
9553 };
9554
9555 /* ******************************************************************************** */
9556
9557 struct cmd_dump_result {
9558         cmdline_fixed_string_t dump;
9559 };
9560
9561 static void
9562 dump_struct_sizes(void)
9563 {
9564 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9565         DUMP_SIZE(struct rte_mbuf);
9566         DUMP_SIZE(struct rte_mempool);
9567         DUMP_SIZE(struct rte_ring);
9568 #undef DUMP_SIZE
9569 }
9570
9571
9572 /* Dump the socket memory statistics on console */
9573 static void
9574 dump_socket_mem(FILE *f)
9575 {
9576         struct rte_malloc_socket_stats socket_stats;
9577         unsigned int i;
9578         size_t total = 0;
9579         size_t alloc = 0;
9580         size_t free = 0;
9581         unsigned int n_alloc = 0;
9582         unsigned int n_free = 0;
9583         static size_t last_allocs;
9584         static size_t last_total;
9585
9586
9587         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9588                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9589                     !socket_stats.heap_totalsz_bytes)
9590                         continue;
9591                 total += socket_stats.heap_totalsz_bytes;
9592                 alloc += socket_stats.heap_allocsz_bytes;
9593                 free += socket_stats.heap_freesz_bytes;
9594                 n_alloc += socket_stats.alloc_count;
9595                 n_free += socket_stats.free_count;
9596                 fprintf(f,
9597                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9598                         i,
9599                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9600                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9601                         (double)socket_stats.heap_allocsz_bytes * 100 /
9602                         (double)socket_stats.heap_totalsz_bytes,
9603                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9604                         socket_stats.alloc_count,
9605                         socket_stats.free_count);
9606         }
9607         fprintf(f,
9608                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9609                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9610                 (double)alloc * 100 / (double)total,
9611                 (double)free / (1024 * 1024),
9612                 n_alloc, n_free);
9613         if (last_allocs)
9614                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9615                         ((double)total - (double)last_total) / (1024 * 1024),
9616                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9617         last_allocs = alloc;
9618         last_total = total;
9619 }
9620
9621 static void cmd_dump_parsed(void *parsed_result,
9622                             __rte_unused struct cmdline *cl,
9623                             __rte_unused void *data)
9624 {
9625         struct cmd_dump_result *res = parsed_result;
9626
9627         if (!strcmp(res->dump, "dump_physmem"))
9628                 rte_dump_physmem_layout(stdout);
9629         else if (!strcmp(res->dump, "dump_socket_mem"))
9630                 dump_socket_mem(stdout);
9631         else if (!strcmp(res->dump, "dump_memzone"))
9632                 rte_memzone_dump(stdout);
9633         else if (!strcmp(res->dump, "dump_struct_sizes"))
9634                 dump_struct_sizes();
9635         else if (!strcmp(res->dump, "dump_ring"))
9636                 rte_ring_list_dump(stdout);
9637         else if (!strcmp(res->dump, "dump_mempool"))
9638                 rte_mempool_list_dump(stdout);
9639         else if (!strcmp(res->dump, "dump_devargs"))
9640                 rte_devargs_dump(stdout);
9641         else if (!strcmp(res->dump, "dump_log_types"))
9642                 rte_log_dump(stdout);
9643 }
9644
9645 cmdline_parse_token_string_t cmd_dump_dump =
9646         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9647                 "dump_physmem#"
9648                 "dump_memzone#"
9649                 "dump_socket_mem#"
9650                 "dump_struct_sizes#"
9651                 "dump_ring#"
9652                 "dump_mempool#"
9653                 "dump_devargs#"
9654                 "dump_log_types");
9655
9656 cmdline_parse_inst_t cmd_dump = {
9657         .f = cmd_dump_parsed,  /* function to call */
9658         .data = NULL,      /* 2nd arg of func */
9659         .help_str = "Dump status",
9660         .tokens = {        /* token list, NULL terminated */
9661                 (void *)&cmd_dump_dump,
9662                 NULL,
9663         },
9664 };
9665
9666 /* ******************************************************************************** */
9667
9668 struct cmd_dump_one_result {
9669         cmdline_fixed_string_t dump;
9670         cmdline_fixed_string_t name;
9671 };
9672
9673 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9674                                 __rte_unused void *data)
9675 {
9676         struct cmd_dump_one_result *res = parsed_result;
9677
9678         if (!strcmp(res->dump, "dump_ring")) {
9679                 struct rte_ring *r;
9680                 r = rte_ring_lookup(res->name);
9681                 if (r == NULL) {
9682                         cmdline_printf(cl, "Cannot find ring\n");
9683                         return;
9684                 }
9685                 rte_ring_dump(stdout, r);
9686         } else if (!strcmp(res->dump, "dump_mempool")) {
9687                 struct rte_mempool *mp;
9688                 mp = rte_mempool_lookup(res->name);
9689                 if (mp == NULL) {
9690                         cmdline_printf(cl, "Cannot find mempool\n");
9691                         return;
9692                 }
9693                 rte_mempool_dump(stdout, mp);
9694         }
9695 }
9696
9697 cmdline_parse_token_string_t cmd_dump_one_dump =
9698         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9699                                  "dump_ring#dump_mempool");
9700
9701 cmdline_parse_token_string_t cmd_dump_one_name =
9702         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9703
9704 cmdline_parse_inst_t cmd_dump_one = {
9705         .f = cmd_dump_one_parsed,  /* function to call */
9706         .data = NULL,      /* 2nd arg of func */
9707         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9708         .tokens = {        /* token list, NULL terminated */
9709                 (void *)&cmd_dump_one_dump,
9710                 (void *)&cmd_dump_one_name,
9711                 NULL,
9712         },
9713 };
9714
9715 /* *** Add/Del syn filter *** */
9716 struct cmd_syn_filter_result {
9717         cmdline_fixed_string_t filter;
9718         portid_t port_id;
9719         cmdline_fixed_string_t ops;
9720         cmdline_fixed_string_t priority;
9721         cmdline_fixed_string_t high;
9722         cmdline_fixed_string_t queue;
9723         uint16_t queue_id;
9724 };
9725
9726 static void
9727 cmd_syn_filter_parsed(void *parsed_result,
9728                         __rte_unused struct cmdline *cl,
9729                         __rte_unused void *data)
9730 {
9731         struct cmd_syn_filter_result *res = parsed_result;
9732         struct rte_eth_syn_filter syn_filter;
9733         int ret = 0;
9734
9735         ret = rte_eth_dev_filter_supported(res->port_id,
9736                                         RTE_ETH_FILTER_SYN);
9737         if (ret < 0) {
9738                 printf("syn filter is not supported on port %u.\n",
9739                                 res->port_id);
9740                 return;
9741         }
9742
9743         memset(&syn_filter, 0, sizeof(syn_filter));
9744
9745         if (!strcmp(res->ops, "add")) {
9746                 if (!strcmp(res->high, "high"))
9747                         syn_filter.hig_pri = 1;
9748                 else
9749                         syn_filter.hig_pri = 0;
9750
9751                 syn_filter.queue = res->queue_id;
9752                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9753                                                 RTE_ETH_FILTER_SYN,
9754                                                 RTE_ETH_FILTER_ADD,
9755                                                 &syn_filter);
9756         } else
9757                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9758                                                 RTE_ETH_FILTER_SYN,
9759                                                 RTE_ETH_FILTER_DELETE,
9760                                                 &syn_filter);
9761
9762         if (ret < 0)
9763                 printf("syn filter programming error: (%s)\n",
9764                                 strerror(-ret));
9765 }
9766
9767 cmdline_parse_token_string_t cmd_syn_filter_filter =
9768         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9769         filter, "syn_filter");
9770 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9771         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9772         port_id, UINT16);
9773 cmdline_parse_token_string_t cmd_syn_filter_ops =
9774         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9775         ops, "add#del");
9776 cmdline_parse_token_string_t cmd_syn_filter_priority =
9777         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9778                                 priority, "priority");
9779 cmdline_parse_token_string_t cmd_syn_filter_high =
9780         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9781                                 high, "high#low");
9782 cmdline_parse_token_string_t cmd_syn_filter_queue =
9783         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9784                                 queue, "queue");
9785 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9786         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9787                                 queue_id, UINT16);
9788
9789 cmdline_parse_inst_t cmd_syn_filter = {
9790         .f = cmd_syn_filter_parsed,
9791         .data = NULL,
9792         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9793                 "<queue_id>: Add/Delete syn filter",
9794         .tokens = {
9795                 (void *)&cmd_syn_filter_filter,
9796                 (void *)&cmd_syn_filter_port_id,
9797                 (void *)&cmd_syn_filter_ops,
9798                 (void *)&cmd_syn_filter_priority,
9799                 (void *)&cmd_syn_filter_high,
9800                 (void *)&cmd_syn_filter_queue,
9801                 (void *)&cmd_syn_filter_queue_id,
9802                 NULL,
9803         },
9804 };
9805
9806 /* *** queue region set *** */
9807 struct cmd_queue_region_result {
9808         cmdline_fixed_string_t set;
9809         cmdline_fixed_string_t port;
9810         portid_t port_id;
9811         cmdline_fixed_string_t cmd;
9812         cmdline_fixed_string_t region;
9813         uint8_t  region_id;
9814         cmdline_fixed_string_t queue_start_index;
9815         uint8_t  queue_id;
9816         cmdline_fixed_string_t queue_num;
9817         uint8_t  queue_num_value;
9818 };
9819
9820 static void
9821 cmd_queue_region_parsed(void *parsed_result,
9822                         __rte_unused struct cmdline *cl,
9823                         __rte_unused void *data)
9824 {
9825         struct cmd_queue_region_result *res = parsed_result;
9826         int ret = -ENOTSUP;
9827 #ifdef RTE_LIBRTE_I40E_PMD
9828         struct rte_pmd_i40e_queue_region_conf region_conf;
9829         enum rte_pmd_i40e_queue_region_op op_type;
9830 #endif
9831
9832         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9833                 return;
9834
9835 #ifdef RTE_LIBRTE_I40E_PMD
9836         memset(&region_conf, 0, sizeof(region_conf));
9837         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9838         region_conf.region_id = res->region_id;
9839         region_conf.queue_num = res->queue_num_value;
9840         region_conf.queue_start_index = res->queue_id;
9841
9842         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9843                                 op_type, &region_conf);
9844 #endif
9845
9846         switch (ret) {
9847         case 0:
9848                 break;
9849         case -ENOTSUP:
9850                 printf("function not implemented or supported\n");
9851                 break;
9852         default:
9853                 printf("queue region config error: (%s)\n", strerror(-ret));
9854         }
9855 }
9856
9857 cmdline_parse_token_string_t cmd_queue_region_set =
9858 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9859                 set, "set");
9860 cmdline_parse_token_string_t cmd_queue_region_port =
9861         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9862 cmdline_parse_token_num_t cmd_queue_region_port_id =
9863         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9864                                 port_id, UINT16);
9865 cmdline_parse_token_string_t cmd_queue_region_cmd =
9866         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9867                                  cmd, "queue-region");
9868 cmdline_parse_token_string_t cmd_queue_region_id =
9869         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9870                                 region, "region_id");
9871 cmdline_parse_token_num_t cmd_queue_region_index =
9872         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9873                                 region_id, UINT8);
9874 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9875         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9876                                 queue_start_index, "queue_start_index");
9877 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9878         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9879                                 queue_id, UINT8);
9880 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9881         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9882                                 queue_num, "queue_num");
9883 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9884         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9885                                 queue_num_value, UINT8);
9886
9887 cmdline_parse_inst_t cmd_queue_region = {
9888         .f = cmd_queue_region_parsed,
9889         .data = NULL,
9890         .help_str = "set port <port_id> queue-region region_id <value> "
9891                 "queue_start_index <value> queue_num <value>: Set a queue region",
9892         .tokens = {
9893                 (void *)&cmd_queue_region_set,
9894                 (void *)&cmd_queue_region_port,
9895                 (void *)&cmd_queue_region_port_id,
9896                 (void *)&cmd_queue_region_cmd,
9897                 (void *)&cmd_queue_region_id,
9898                 (void *)&cmd_queue_region_index,
9899                 (void *)&cmd_queue_region_queue_start_index,
9900                 (void *)&cmd_queue_region_queue_id,
9901                 (void *)&cmd_queue_region_queue_num,
9902                 (void *)&cmd_queue_region_queue_num_value,
9903                 NULL,
9904         },
9905 };
9906
9907 /* *** queue region and flowtype set *** */
9908 struct cmd_region_flowtype_result {
9909         cmdline_fixed_string_t set;
9910         cmdline_fixed_string_t port;
9911         portid_t port_id;
9912         cmdline_fixed_string_t cmd;
9913         cmdline_fixed_string_t region;
9914         uint8_t  region_id;
9915         cmdline_fixed_string_t flowtype;
9916         uint8_t  flowtype_id;
9917 };
9918
9919 static void
9920 cmd_region_flowtype_parsed(void *parsed_result,
9921                         __rte_unused struct cmdline *cl,
9922                         __rte_unused void *data)
9923 {
9924         struct cmd_region_flowtype_result *res = parsed_result;
9925         int ret = -ENOTSUP;
9926 #ifdef RTE_LIBRTE_I40E_PMD
9927         struct rte_pmd_i40e_queue_region_conf region_conf;
9928         enum rte_pmd_i40e_queue_region_op op_type;
9929 #endif
9930
9931         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9932                 return;
9933
9934 #ifdef RTE_LIBRTE_I40E_PMD
9935         memset(&region_conf, 0, sizeof(region_conf));
9936
9937         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9938         region_conf.region_id = res->region_id;
9939         region_conf.hw_flowtype = res->flowtype_id;
9940
9941         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9942                         op_type, &region_conf);
9943 #endif
9944
9945         switch (ret) {
9946         case 0:
9947                 break;
9948         case -ENOTSUP:
9949                 printf("function not implemented or supported\n");
9950                 break;
9951         default:
9952                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9953         }
9954 }
9955
9956 cmdline_parse_token_string_t cmd_region_flowtype_set =
9957 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9958                                 set, "set");
9959 cmdline_parse_token_string_t cmd_region_flowtype_port =
9960         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9961                                 port, "port");
9962 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9963         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9964                                 port_id, UINT16);
9965 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9966         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9967                                 cmd, "queue-region");
9968 cmdline_parse_token_string_t cmd_region_flowtype_index =
9969         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9970                                 region, "region_id");
9971 cmdline_parse_token_num_t cmd_region_flowtype_id =
9972         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9973                                 region_id, UINT8);
9974 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9975         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9976                                 flowtype, "flowtype");
9977 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9978         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9979                                 flowtype_id, UINT8);
9980 cmdline_parse_inst_t cmd_region_flowtype = {
9981         .f = cmd_region_flowtype_parsed,
9982         .data = NULL,
9983         .help_str = "set port <port_id> queue-region region_id <value> "
9984                 "flowtype <value>: Set a flowtype region index",
9985         .tokens = {
9986                 (void *)&cmd_region_flowtype_set,
9987                 (void *)&cmd_region_flowtype_port,
9988                 (void *)&cmd_region_flowtype_port_index,
9989                 (void *)&cmd_region_flowtype_cmd,
9990                 (void *)&cmd_region_flowtype_index,
9991                 (void *)&cmd_region_flowtype_id,
9992                 (void *)&cmd_region_flowtype_flow_index,
9993                 (void *)&cmd_region_flowtype_flow_id,
9994                 NULL,
9995         },
9996 };
9997
9998 /* *** User Priority (UP) to queue region (region_id) set *** */
9999 struct cmd_user_priority_region_result {
10000         cmdline_fixed_string_t set;
10001         cmdline_fixed_string_t port;
10002         portid_t port_id;
10003         cmdline_fixed_string_t cmd;
10004         cmdline_fixed_string_t user_priority;
10005         uint8_t  user_priority_id;
10006         cmdline_fixed_string_t region;
10007         uint8_t  region_id;
10008 };
10009
10010 static void
10011 cmd_user_priority_region_parsed(void *parsed_result,
10012                         __rte_unused struct cmdline *cl,
10013                         __rte_unused void *data)
10014 {
10015         struct cmd_user_priority_region_result *res = parsed_result;
10016         int ret = -ENOTSUP;
10017 #ifdef RTE_LIBRTE_I40E_PMD
10018         struct rte_pmd_i40e_queue_region_conf region_conf;
10019         enum rte_pmd_i40e_queue_region_op op_type;
10020 #endif
10021
10022         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10023                 return;
10024
10025 #ifdef RTE_LIBRTE_I40E_PMD
10026         memset(&region_conf, 0, sizeof(region_conf));
10027         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10028         region_conf.user_priority = res->user_priority_id;
10029         region_conf.region_id = res->region_id;
10030
10031         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10032                                 op_type, &region_conf);
10033 #endif
10034
10035         switch (ret) {
10036         case 0:
10037                 break;
10038         case -ENOTSUP:
10039                 printf("function not implemented or supported\n");
10040                 break;
10041         default:
10042                 printf("user_priority region config error: (%s)\n",
10043                                 strerror(-ret));
10044         }
10045 }
10046
10047 cmdline_parse_token_string_t cmd_user_priority_region_set =
10048         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10049                                 set, "set");
10050 cmdline_parse_token_string_t cmd_user_priority_region_port =
10051         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10052                                 port, "port");
10053 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10054         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10055                                 port_id, UINT16);
10056 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10057         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10058                                 cmd, "queue-region");
10059 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10060         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10061                                 user_priority, "UP");
10062 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10063         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10064                                 user_priority_id, UINT8);
10065 cmdline_parse_token_string_t cmd_user_priority_region_region =
10066         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10067                                 region, "region_id");
10068 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10069         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10070                                 region_id, UINT8);
10071
10072 cmdline_parse_inst_t cmd_user_priority_region = {
10073         .f = cmd_user_priority_region_parsed,
10074         .data = NULL,
10075         .help_str = "set port <port_id> queue-region UP <value> "
10076                 "region_id <value>: Set the mapping of User Priority (UP) "
10077                 "to queue region (region_id) ",
10078         .tokens = {
10079                 (void *)&cmd_user_priority_region_set,
10080                 (void *)&cmd_user_priority_region_port,
10081                 (void *)&cmd_user_priority_region_port_index,
10082                 (void *)&cmd_user_priority_region_cmd,
10083                 (void *)&cmd_user_priority_region_UP,
10084                 (void *)&cmd_user_priority_region_UP_id,
10085                 (void *)&cmd_user_priority_region_region,
10086                 (void *)&cmd_user_priority_region_region_id,
10087                 NULL,
10088         },
10089 };
10090
10091 /* *** flush all queue region related configuration *** */
10092 struct cmd_flush_queue_region_result {
10093         cmdline_fixed_string_t set;
10094         cmdline_fixed_string_t port;
10095         portid_t port_id;
10096         cmdline_fixed_string_t cmd;
10097         cmdline_fixed_string_t flush;
10098         cmdline_fixed_string_t what;
10099 };
10100
10101 static void
10102 cmd_flush_queue_region_parsed(void *parsed_result,
10103                         __rte_unused struct cmdline *cl,
10104                         __rte_unused void *data)
10105 {
10106         struct cmd_flush_queue_region_result *res = parsed_result;
10107         int ret = -ENOTSUP;
10108 #ifdef RTE_LIBRTE_I40E_PMD
10109         struct rte_pmd_i40e_queue_region_conf region_conf;
10110         enum rte_pmd_i40e_queue_region_op op_type;
10111 #endif
10112
10113         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10114                 return;
10115
10116 #ifdef RTE_LIBRTE_I40E_PMD
10117         memset(&region_conf, 0, sizeof(region_conf));
10118
10119         if (strcmp(res->what, "on") == 0)
10120                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10121         else
10122                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10123
10124         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10125                                 op_type, &region_conf);
10126 #endif
10127
10128         switch (ret) {
10129         case 0:
10130                 break;
10131         case -ENOTSUP:
10132                 printf("function not implemented or supported\n");
10133                 break;
10134         default:
10135                 printf("queue region config flush error: (%s)\n",
10136                                 strerror(-ret));
10137         }
10138 }
10139
10140 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10141         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10142                                 set, "set");
10143 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10144         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10145                                 port, "port");
10146 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10147         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10148                                 port_id, UINT16);
10149 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10150         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10151                                 cmd, "queue-region");
10152 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10153         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10154                                 flush, "flush");
10155 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10156         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10157                                 what, "on#off");
10158
10159 cmdline_parse_inst_t cmd_flush_queue_region = {
10160         .f = cmd_flush_queue_region_parsed,
10161         .data = NULL,
10162         .help_str = "set port <port_id> queue-region flush on|off"
10163                 ": flush all queue region related configuration",
10164         .tokens = {
10165                 (void *)&cmd_flush_queue_region_set,
10166                 (void *)&cmd_flush_queue_region_port,
10167                 (void *)&cmd_flush_queue_region_port_index,
10168                 (void *)&cmd_flush_queue_region_cmd,
10169                 (void *)&cmd_flush_queue_region_flush,
10170                 (void *)&cmd_flush_queue_region_what,
10171                 NULL,
10172         },
10173 };
10174
10175 /* *** get all queue region related configuration info *** */
10176 struct cmd_show_queue_region_info {
10177         cmdline_fixed_string_t show;
10178         cmdline_fixed_string_t port;
10179         portid_t port_id;
10180         cmdline_fixed_string_t cmd;
10181 };
10182
10183 static void
10184 cmd_show_queue_region_info_parsed(void *parsed_result,
10185                         __rte_unused struct cmdline *cl,
10186                         __rte_unused void *data)
10187 {
10188         struct cmd_show_queue_region_info *res = parsed_result;
10189         int ret = -ENOTSUP;
10190 #ifdef RTE_LIBRTE_I40E_PMD
10191         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10192         enum rte_pmd_i40e_queue_region_op op_type;
10193 #endif
10194
10195         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10196                 return;
10197
10198 #ifdef RTE_LIBRTE_I40E_PMD
10199         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10200
10201         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10202
10203         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10204                                         op_type, &rte_pmd_regions);
10205
10206         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10207 #endif
10208
10209         switch (ret) {
10210         case 0:
10211                 break;
10212         case -ENOTSUP:
10213                 printf("function not implemented or supported\n");
10214                 break;
10215         default:
10216                 printf("queue region config info show error: (%s)\n",
10217                                 strerror(-ret));
10218         }
10219 }
10220
10221 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10222 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10223                                 show, "show");
10224 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10225         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10226                                 port, "port");
10227 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10228         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10229                                 port_id, UINT16);
10230 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10231         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10232                                 cmd, "queue-region");
10233
10234 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10235         .f = cmd_show_queue_region_info_parsed,
10236         .data = NULL,
10237         .help_str = "show port <port_id> queue-region"
10238                 ": show all queue region related configuration info",
10239         .tokens = {
10240                 (void *)&cmd_show_queue_region_info_get,
10241                 (void *)&cmd_show_queue_region_info_port,
10242                 (void *)&cmd_show_queue_region_info_port_index,
10243                 (void *)&cmd_show_queue_region_info_cmd,
10244                 NULL,
10245         },
10246 };
10247
10248 /* *** ADD/REMOVE A 2tuple FILTER *** */
10249 struct cmd_2tuple_filter_result {
10250         cmdline_fixed_string_t filter;
10251         portid_t port_id;
10252         cmdline_fixed_string_t ops;
10253         cmdline_fixed_string_t dst_port;
10254         uint16_t dst_port_value;
10255         cmdline_fixed_string_t protocol;
10256         uint8_t protocol_value;
10257         cmdline_fixed_string_t mask;
10258         uint8_t  mask_value;
10259         cmdline_fixed_string_t tcp_flags;
10260         uint8_t tcp_flags_value;
10261         cmdline_fixed_string_t priority;
10262         uint8_t  priority_value;
10263         cmdline_fixed_string_t queue;
10264         uint16_t  queue_id;
10265 };
10266
10267 static void
10268 cmd_2tuple_filter_parsed(void *parsed_result,
10269                         __rte_unused struct cmdline *cl,
10270                         __rte_unused void *data)
10271 {
10272         struct rte_eth_ntuple_filter filter;
10273         struct cmd_2tuple_filter_result *res = parsed_result;
10274         int ret = 0;
10275
10276         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10277         if (ret < 0) {
10278                 printf("ntuple filter is not supported on port %u.\n",
10279                         res->port_id);
10280                 return;
10281         }
10282
10283         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10284
10285         filter.flags = RTE_2TUPLE_FLAGS;
10286         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10287         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10288         filter.proto = res->protocol_value;
10289         filter.priority = res->priority_value;
10290         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10291                 printf("nonzero tcp_flags is only meaningful"
10292                         " when protocol is TCP.\n");
10293                 return;
10294         }
10295         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10296                 printf("invalid TCP flags.\n");
10297                 return;
10298         }
10299
10300         if (res->tcp_flags_value != 0) {
10301                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10302                 filter.tcp_flags = res->tcp_flags_value;
10303         }
10304
10305         /* need convert to big endian. */
10306         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10307         filter.queue = res->queue_id;
10308
10309         if (!strcmp(res->ops, "add"))
10310                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10311                                 RTE_ETH_FILTER_NTUPLE,
10312                                 RTE_ETH_FILTER_ADD,
10313                                 &filter);
10314         else
10315                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10316                                 RTE_ETH_FILTER_NTUPLE,
10317                                 RTE_ETH_FILTER_DELETE,
10318                                 &filter);
10319         if (ret < 0)
10320                 printf("2tuple filter programming error: (%s)\n",
10321                         strerror(-ret));
10322
10323 }
10324
10325 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10326         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10327                                  filter, "2tuple_filter");
10328 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10329         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10330                                 port_id, UINT16);
10331 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10332         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10333                                  ops, "add#del");
10334 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10335         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10336                                 dst_port, "dst_port");
10337 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10338         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10339                                 dst_port_value, UINT16);
10340 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10341         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10342                                 protocol, "protocol");
10343 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10344         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10345                                 protocol_value, UINT8);
10346 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10347         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10348                                 mask, "mask");
10349 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10350         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10351                                 mask_value, INT8);
10352 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10353         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10354                                 tcp_flags, "tcp_flags");
10355 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10356         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10357                                 tcp_flags_value, UINT8);
10358 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10359         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10360                                 priority, "priority");
10361 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10362         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10363                                 priority_value, UINT8);
10364 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10365         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10366                                 queue, "queue");
10367 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10368         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10369                                 queue_id, UINT16);
10370
10371 cmdline_parse_inst_t cmd_2tuple_filter = {
10372         .f = cmd_2tuple_filter_parsed,
10373         .data = NULL,
10374         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10375                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10376                 "<queue_id>: Add a 2tuple filter",
10377         .tokens = {
10378                 (void *)&cmd_2tuple_filter_filter,
10379                 (void *)&cmd_2tuple_filter_port_id,
10380                 (void *)&cmd_2tuple_filter_ops,
10381                 (void *)&cmd_2tuple_filter_dst_port,
10382                 (void *)&cmd_2tuple_filter_dst_port_value,
10383                 (void *)&cmd_2tuple_filter_protocol,
10384                 (void *)&cmd_2tuple_filter_protocol_value,
10385                 (void *)&cmd_2tuple_filter_mask,
10386                 (void *)&cmd_2tuple_filter_mask_value,
10387                 (void *)&cmd_2tuple_filter_tcp_flags,
10388                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10389                 (void *)&cmd_2tuple_filter_priority,
10390                 (void *)&cmd_2tuple_filter_priority_value,
10391                 (void *)&cmd_2tuple_filter_queue,
10392                 (void *)&cmd_2tuple_filter_queue_id,
10393                 NULL,
10394         },
10395 };
10396
10397 /* *** ADD/REMOVE A 5tuple FILTER *** */
10398 struct cmd_5tuple_filter_result {
10399         cmdline_fixed_string_t filter;
10400         portid_t port_id;
10401         cmdline_fixed_string_t ops;
10402         cmdline_fixed_string_t dst_ip;
10403         cmdline_ipaddr_t dst_ip_value;
10404         cmdline_fixed_string_t src_ip;
10405         cmdline_ipaddr_t src_ip_value;
10406         cmdline_fixed_string_t dst_port;
10407         uint16_t dst_port_value;
10408         cmdline_fixed_string_t src_port;
10409         uint16_t src_port_value;
10410         cmdline_fixed_string_t protocol;
10411         uint8_t protocol_value;
10412         cmdline_fixed_string_t mask;
10413         uint8_t  mask_value;
10414         cmdline_fixed_string_t tcp_flags;
10415         uint8_t tcp_flags_value;
10416         cmdline_fixed_string_t priority;
10417         uint8_t  priority_value;
10418         cmdline_fixed_string_t queue;
10419         uint16_t  queue_id;
10420 };
10421
10422 static void
10423 cmd_5tuple_filter_parsed(void *parsed_result,
10424                         __rte_unused struct cmdline *cl,
10425                         __rte_unused void *data)
10426 {
10427         struct rte_eth_ntuple_filter filter;
10428         struct cmd_5tuple_filter_result *res = parsed_result;
10429         int ret = 0;
10430
10431         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10432         if (ret < 0) {
10433                 printf("ntuple filter is not supported on port %u.\n",
10434                         res->port_id);
10435                 return;
10436         }
10437
10438         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10439
10440         filter.flags = RTE_5TUPLE_FLAGS;
10441         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10442         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10443         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10444         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10445         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10446         filter.proto = res->protocol_value;
10447         filter.priority = res->priority_value;
10448         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10449                 printf("nonzero tcp_flags is only meaningful"
10450                         " when protocol is TCP.\n");
10451                 return;
10452         }
10453         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10454                 printf("invalid TCP flags.\n");
10455                 return;
10456         }
10457
10458         if (res->tcp_flags_value != 0) {
10459                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10460                 filter.tcp_flags = res->tcp_flags_value;
10461         }
10462
10463         if (res->dst_ip_value.family == AF_INET)
10464                 /* no need to convert, already big endian. */
10465                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10466         else {
10467                 if (filter.dst_ip_mask == 0) {
10468                         printf("can not support ipv6 involved compare.\n");
10469                         return;
10470                 }
10471                 filter.dst_ip = 0;
10472         }
10473
10474         if (res->src_ip_value.family == AF_INET)
10475                 /* no need to convert, already big endian. */
10476                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10477         else {
10478                 if (filter.src_ip_mask == 0) {
10479                         printf("can not support ipv6 involved compare.\n");
10480                         return;
10481                 }
10482                 filter.src_ip = 0;
10483         }
10484         /* need convert to big endian. */
10485         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10486         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10487         filter.queue = res->queue_id;
10488
10489         if (!strcmp(res->ops, "add"))
10490                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10491                                 RTE_ETH_FILTER_NTUPLE,
10492                                 RTE_ETH_FILTER_ADD,
10493                                 &filter);
10494         else
10495                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10496                                 RTE_ETH_FILTER_NTUPLE,
10497                                 RTE_ETH_FILTER_DELETE,
10498                                 &filter);
10499         if (ret < 0)
10500                 printf("5tuple filter programming error: (%s)\n",
10501                         strerror(-ret));
10502 }
10503
10504 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10505         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10506                                  filter, "5tuple_filter");
10507 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10508         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10509                                 port_id, UINT16);
10510 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10511         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10512                                  ops, "add#del");
10513 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10514         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10515                                 dst_ip, "dst_ip");
10516 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10517         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10518                                 dst_ip_value);
10519 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10520         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10521                                 src_ip, "src_ip");
10522 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10523         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10524                                 src_ip_value);
10525 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10526         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10527                                 dst_port, "dst_port");
10528 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10529         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10530                                 dst_port_value, UINT16);
10531 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10532         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10533                                 src_port, "src_port");
10534 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10535         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10536                                 src_port_value, UINT16);
10537 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10538         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10539                                 protocol, "protocol");
10540 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10541         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10542                                 protocol_value, UINT8);
10543 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10544         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10545                                 mask, "mask");
10546 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10547         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10548                                 mask_value, INT8);
10549 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10550         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10551                                 tcp_flags, "tcp_flags");
10552 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10553         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10554                                 tcp_flags_value, UINT8);
10555 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10556         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10557                                 priority, "priority");
10558 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10559         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10560                                 priority_value, UINT8);
10561 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10562         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10563                                 queue, "queue");
10564 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10565         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10566                                 queue_id, UINT16);
10567
10568 cmdline_parse_inst_t cmd_5tuple_filter = {
10569         .f = cmd_5tuple_filter_parsed,
10570         .data = NULL,
10571         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10572                 "src_ip <value> dst_port <value> src_port <value> "
10573                 "protocol <value>  mask <value> tcp_flags <value> "
10574                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10575         .tokens = {
10576                 (void *)&cmd_5tuple_filter_filter,
10577                 (void *)&cmd_5tuple_filter_port_id,
10578                 (void *)&cmd_5tuple_filter_ops,
10579                 (void *)&cmd_5tuple_filter_dst_ip,
10580                 (void *)&cmd_5tuple_filter_dst_ip_value,
10581                 (void *)&cmd_5tuple_filter_src_ip,
10582                 (void *)&cmd_5tuple_filter_src_ip_value,
10583                 (void *)&cmd_5tuple_filter_dst_port,
10584                 (void *)&cmd_5tuple_filter_dst_port_value,
10585                 (void *)&cmd_5tuple_filter_src_port,
10586                 (void *)&cmd_5tuple_filter_src_port_value,
10587                 (void *)&cmd_5tuple_filter_protocol,
10588                 (void *)&cmd_5tuple_filter_protocol_value,
10589                 (void *)&cmd_5tuple_filter_mask,
10590                 (void *)&cmd_5tuple_filter_mask_value,
10591                 (void *)&cmd_5tuple_filter_tcp_flags,
10592                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10593                 (void *)&cmd_5tuple_filter_priority,
10594                 (void *)&cmd_5tuple_filter_priority_value,
10595                 (void *)&cmd_5tuple_filter_queue,
10596                 (void *)&cmd_5tuple_filter_queue_id,
10597                 NULL,
10598         },
10599 };
10600
10601 /* *** ADD/REMOVE A flex FILTER *** */
10602 struct cmd_flex_filter_result {
10603         cmdline_fixed_string_t filter;
10604         cmdline_fixed_string_t ops;
10605         portid_t port_id;
10606         cmdline_fixed_string_t len;
10607         uint8_t len_value;
10608         cmdline_fixed_string_t bytes;
10609         cmdline_fixed_string_t bytes_value;
10610         cmdline_fixed_string_t mask;
10611         cmdline_fixed_string_t mask_value;
10612         cmdline_fixed_string_t priority;
10613         uint8_t priority_value;
10614         cmdline_fixed_string_t queue;
10615         uint16_t queue_id;
10616 };
10617
10618 static int xdigit2val(unsigned char c)
10619 {
10620         int val;
10621         if (isdigit(c))
10622                 val = c - '0';
10623         else if (isupper(c))
10624                 val = c - 'A' + 10;
10625         else
10626                 val = c - 'a' + 10;
10627         return val;
10628 }
10629
10630 static void
10631 cmd_flex_filter_parsed(void *parsed_result,
10632                           __rte_unused struct cmdline *cl,
10633                           __rte_unused void *data)
10634 {
10635         int ret = 0;
10636         struct rte_eth_flex_filter filter;
10637         struct cmd_flex_filter_result *res = parsed_result;
10638         char *bytes_ptr, *mask_ptr;
10639         uint16_t len, i, j = 0;
10640         char c;
10641         int val;
10642         uint8_t byte = 0;
10643
10644         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10645                 printf("the len exceed the max length 128\n");
10646                 return;
10647         }
10648         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10649         filter.len = res->len_value;
10650         filter.priority = res->priority_value;
10651         filter.queue = res->queue_id;
10652         bytes_ptr = res->bytes_value;
10653         mask_ptr = res->mask_value;
10654
10655          /* translate bytes string to array. */
10656         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10657                 (bytes_ptr[1] == 'X')))
10658                 bytes_ptr += 2;
10659         len = strnlen(bytes_ptr, res->len_value * 2);
10660         if (len == 0 || (len % 8 != 0)) {
10661                 printf("please check len and bytes input\n");
10662                 return;
10663         }
10664         for (i = 0; i < len; i++) {
10665                 c = bytes_ptr[i];
10666                 if (isxdigit(c) == 0) {
10667                         /* invalid characters. */
10668                         printf("invalid input\n");
10669                         return;
10670                 }
10671                 val = xdigit2val(c);
10672                 if (i % 2) {
10673                         byte |= val;
10674                         filter.bytes[j] = byte;
10675                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10676                         j++;
10677                         byte = 0;
10678                 } else
10679                         byte |= val << 4;
10680         }
10681         printf("\n");
10682          /* translate mask string to uint8_t array. */
10683         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10684                 (mask_ptr[1] == 'X')))
10685                 mask_ptr += 2;
10686         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10687         if (len == 0) {
10688                 printf("invalid input\n");
10689                 return;
10690         }
10691         j = 0;
10692         byte = 0;
10693         for (i = 0; i < len; i++) {
10694                 c = mask_ptr[i];
10695                 if (isxdigit(c) == 0) {
10696                         /* invalid characters. */
10697                         printf("invalid input\n");
10698                         return;
10699                 }
10700                 val = xdigit2val(c);
10701                 if (i % 2) {
10702                         byte |= val;
10703                         filter.mask[j] = byte;
10704                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10705                         j++;
10706                         byte = 0;
10707                 } else
10708                         byte |= val << 4;
10709         }
10710         printf("\n");
10711
10712         if (!strcmp(res->ops, "add"))
10713                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10714                                 RTE_ETH_FILTER_FLEXIBLE,
10715                                 RTE_ETH_FILTER_ADD,
10716                                 &filter);
10717         else
10718                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10719                                 RTE_ETH_FILTER_FLEXIBLE,
10720                                 RTE_ETH_FILTER_DELETE,
10721                                 &filter);
10722
10723         if (ret < 0)
10724                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10725 }
10726
10727 cmdline_parse_token_string_t cmd_flex_filter_filter =
10728         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10729                                 filter, "flex_filter");
10730 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10731         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10732                                 port_id, UINT16);
10733 cmdline_parse_token_string_t cmd_flex_filter_ops =
10734         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10735                                 ops, "add#del");
10736 cmdline_parse_token_string_t cmd_flex_filter_len =
10737         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10738                                 len, "len");
10739 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10740         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10741                                 len_value, UINT8);
10742 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10743         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10744                                 bytes, "bytes");
10745 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10746         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10747                                 bytes_value, NULL);
10748 cmdline_parse_token_string_t cmd_flex_filter_mask =
10749         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10750                                 mask, "mask");
10751 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10752         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10753                                 mask_value, NULL);
10754 cmdline_parse_token_string_t cmd_flex_filter_priority =
10755         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10756                                 priority, "priority");
10757 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10758         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10759                                 priority_value, UINT8);
10760 cmdline_parse_token_string_t cmd_flex_filter_queue =
10761         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10762                                 queue, "queue");
10763 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10764         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10765                                 queue_id, UINT16);
10766 cmdline_parse_inst_t cmd_flex_filter = {
10767         .f = cmd_flex_filter_parsed,
10768         .data = NULL,
10769         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10770                 "<value> mask <value> priority <value> queue <queue_id>: "
10771                 "Add/Del a flex filter",
10772         .tokens = {
10773                 (void *)&cmd_flex_filter_filter,
10774                 (void *)&cmd_flex_filter_port_id,
10775                 (void *)&cmd_flex_filter_ops,
10776                 (void *)&cmd_flex_filter_len,
10777                 (void *)&cmd_flex_filter_len_value,
10778                 (void *)&cmd_flex_filter_bytes,
10779                 (void *)&cmd_flex_filter_bytes_value,
10780                 (void *)&cmd_flex_filter_mask,
10781                 (void *)&cmd_flex_filter_mask_value,
10782                 (void *)&cmd_flex_filter_priority,
10783                 (void *)&cmd_flex_filter_priority_value,
10784                 (void *)&cmd_flex_filter_queue,
10785                 (void *)&cmd_flex_filter_queue_id,
10786                 NULL,
10787         },
10788 };
10789
10790 /* *** Filters Control *** */
10791
10792 /* *** deal with ethertype filter *** */
10793 struct cmd_ethertype_filter_result {
10794         cmdline_fixed_string_t filter;
10795         portid_t port_id;
10796         cmdline_fixed_string_t ops;
10797         cmdline_fixed_string_t mac;
10798         struct rte_ether_addr mac_addr;
10799         cmdline_fixed_string_t ethertype;
10800         uint16_t ethertype_value;
10801         cmdline_fixed_string_t drop;
10802         cmdline_fixed_string_t queue;
10803         uint16_t  queue_id;
10804 };
10805
10806 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10807         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10808                                  filter, "ethertype_filter");
10809 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10810         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10811                               port_id, UINT16);
10812 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10813         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10814                                  ops, "add#del");
10815 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10816         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10817                                  mac, "mac_addr#mac_ignr");
10818 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10819         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10820                                      mac_addr);
10821 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10822         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10823                                  ethertype, "ethertype");
10824 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10825         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10826                               ethertype_value, UINT16);
10827 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10828         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10829                                  drop, "drop#fwd");
10830 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10831         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10832                                  queue, "queue");
10833 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10834         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10835                               queue_id, UINT16);
10836
10837 static void
10838 cmd_ethertype_filter_parsed(void *parsed_result,
10839                           __rte_unused struct cmdline *cl,
10840                           __rte_unused void *data)
10841 {
10842         struct cmd_ethertype_filter_result *res = parsed_result;
10843         struct rte_eth_ethertype_filter filter;
10844         int ret = 0;
10845
10846         ret = rte_eth_dev_filter_supported(res->port_id,
10847                         RTE_ETH_FILTER_ETHERTYPE);
10848         if (ret < 0) {
10849                 printf("ethertype filter is not supported on port %u.\n",
10850                         res->port_id);
10851                 return;
10852         }
10853
10854         memset(&filter, 0, sizeof(filter));
10855         if (!strcmp(res->mac, "mac_addr")) {
10856                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10857                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10858                         sizeof(struct rte_ether_addr));
10859         }
10860         if (!strcmp(res->drop, "drop"))
10861                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10862         filter.ether_type = res->ethertype_value;
10863         filter.queue = res->queue_id;
10864
10865         if (!strcmp(res->ops, "add"))
10866                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10867                                 RTE_ETH_FILTER_ETHERTYPE,
10868                                 RTE_ETH_FILTER_ADD,
10869                                 &filter);
10870         else
10871                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10872                                 RTE_ETH_FILTER_ETHERTYPE,
10873                                 RTE_ETH_FILTER_DELETE,
10874                                 &filter);
10875         if (ret < 0)
10876                 printf("ethertype filter programming error: (%s)\n",
10877                         strerror(-ret));
10878 }
10879
10880 cmdline_parse_inst_t cmd_ethertype_filter = {
10881         .f = cmd_ethertype_filter_parsed,
10882         .data = NULL,
10883         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10884                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10885                 "Add or delete an ethertype filter entry",
10886         .tokens = {
10887                 (void *)&cmd_ethertype_filter_filter,
10888                 (void *)&cmd_ethertype_filter_port_id,
10889                 (void *)&cmd_ethertype_filter_ops,
10890                 (void *)&cmd_ethertype_filter_mac,
10891                 (void *)&cmd_ethertype_filter_mac_addr,
10892                 (void *)&cmd_ethertype_filter_ethertype,
10893                 (void *)&cmd_ethertype_filter_ethertype_value,
10894                 (void *)&cmd_ethertype_filter_drop,
10895                 (void *)&cmd_ethertype_filter_queue,
10896                 (void *)&cmd_ethertype_filter_queue_id,
10897                 NULL,
10898         },
10899 };
10900
10901 /* *** deal with flow director filter *** */
10902 struct cmd_flow_director_result {
10903         cmdline_fixed_string_t flow_director_filter;
10904         portid_t port_id;
10905         cmdline_fixed_string_t mode;
10906         cmdline_fixed_string_t mode_value;
10907         cmdline_fixed_string_t ops;
10908         cmdline_fixed_string_t flow;
10909         cmdline_fixed_string_t flow_type;
10910         cmdline_fixed_string_t ether;
10911         uint16_t ether_type;
10912         cmdline_fixed_string_t src;
10913         cmdline_ipaddr_t ip_src;
10914         uint16_t port_src;
10915         cmdline_fixed_string_t dst;
10916         cmdline_ipaddr_t ip_dst;
10917         uint16_t port_dst;
10918         cmdline_fixed_string_t verify_tag;
10919         uint32_t verify_tag_value;
10920         cmdline_fixed_string_t tos;
10921         uint8_t tos_value;
10922         cmdline_fixed_string_t proto;
10923         uint8_t proto_value;
10924         cmdline_fixed_string_t ttl;
10925         uint8_t ttl_value;
10926         cmdline_fixed_string_t vlan;
10927         uint16_t vlan_value;
10928         cmdline_fixed_string_t flexbytes;
10929         cmdline_fixed_string_t flexbytes_value;
10930         cmdline_fixed_string_t pf_vf;
10931         cmdline_fixed_string_t drop;
10932         cmdline_fixed_string_t queue;
10933         uint16_t  queue_id;
10934         cmdline_fixed_string_t fd_id;
10935         uint32_t  fd_id_value;
10936         cmdline_fixed_string_t mac;
10937         struct rte_ether_addr mac_addr;
10938         cmdline_fixed_string_t tunnel;
10939         cmdline_fixed_string_t tunnel_type;
10940         cmdline_fixed_string_t tunnel_id;
10941         uint32_t tunnel_id_value;
10942         cmdline_fixed_string_t packet;
10943         char filepath[];
10944 };
10945
10946 static inline int
10947 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10948 {
10949         char s[256];
10950         const char *p, *p0 = q_arg;
10951         char *end;
10952         unsigned long int_fld;
10953         char *str_fld[max_num];
10954         int i;
10955         unsigned size;
10956         int ret = -1;
10957
10958         p = strchr(p0, '(');
10959         if (p == NULL)
10960                 return -1;
10961         ++p;
10962         p0 = strchr(p, ')');
10963         if (p0 == NULL)
10964                 return -1;
10965
10966         size = p0 - p;
10967         if (size >= sizeof(s))
10968                 return -1;
10969
10970         snprintf(s, sizeof(s), "%.*s", size, p);
10971         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10972         if (ret < 0 || ret > max_num)
10973                 return -1;
10974         for (i = 0; i < ret; i++) {
10975                 errno = 0;
10976                 int_fld = strtoul(str_fld[i], &end, 0);
10977                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10978                         return -1;
10979                 flexbytes[i] = (uint8_t)int_fld;
10980         }
10981         return ret;
10982 }
10983
10984 static uint16_t
10985 str2flowtype(char *string)
10986 {
10987         uint8_t i = 0;
10988         static const struct {
10989                 char str[32];
10990                 uint16_t type;
10991         } flowtype_str[] = {
10992                 {"raw", RTE_ETH_FLOW_RAW},
10993                 {"ipv4", RTE_ETH_FLOW_IPV4},
10994                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10995                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10996                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10997                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10998                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10999                 {"ipv6", RTE_ETH_FLOW_IPV6},
11000                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11001                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11002                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11003                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11004                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11005                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11006         };
11007
11008         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11009                 if (!strcmp(flowtype_str[i].str, string))
11010                         return flowtype_str[i].type;
11011         }
11012
11013         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11014                 return (uint16_t)atoi(string);
11015
11016         return RTE_ETH_FLOW_UNKNOWN;
11017 }
11018
11019 static enum rte_eth_fdir_tunnel_type
11020 str2fdir_tunneltype(char *string)
11021 {
11022         uint8_t i = 0;
11023
11024         static const struct {
11025                 char str[32];
11026                 enum rte_eth_fdir_tunnel_type type;
11027         } tunneltype_str[] = {
11028                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11029                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11030         };
11031
11032         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11033                 if (!strcmp(tunneltype_str[i].str, string))
11034                         return tunneltype_str[i].type;
11035         }
11036         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11037 }
11038
11039 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11040 do { \
11041         if ((ip_addr).family == AF_INET) \
11042                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11043         else { \
11044                 printf("invalid parameter.\n"); \
11045                 return; \
11046         } \
11047 } while (0)
11048
11049 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11050 do { \
11051         if ((ip_addr).family == AF_INET6) \
11052                 rte_memcpy(&(ip), \
11053                                  &((ip_addr).addr.ipv6), \
11054                                  sizeof(struct in6_addr)); \
11055         else { \
11056                 printf("invalid parameter.\n"); \
11057                 return; \
11058         } \
11059 } while (0)
11060
11061 static void
11062 cmd_flow_director_filter_parsed(void *parsed_result,
11063                           __rte_unused struct cmdline *cl,
11064                           __rte_unused void *data)
11065 {
11066         struct cmd_flow_director_result *res = parsed_result;
11067         struct rte_eth_fdir_filter entry;
11068         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11069         char *end;
11070         unsigned long vf_id;
11071         int ret = 0;
11072
11073         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11074         if (ret < 0) {
11075                 printf("flow director is not supported on port %u.\n",
11076                         res->port_id);
11077                 return;
11078         }
11079         memset(flexbytes, 0, sizeof(flexbytes));
11080         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11081
11082         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11083                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11084                         printf("Please set mode to MAC-VLAN.\n");
11085                         return;
11086                 }
11087         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11088                 if (strcmp(res->mode_value, "Tunnel")) {
11089                         printf("Please set mode to Tunnel.\n");
11090                         return;
11091                 }
11092         } else {
11093                 if (!strcmp(res->mode_value, "raw")) {
11094 #ifdef RTE_LIBRTE_I40E_PMD
11095                         struct rte_pmd_i40e_flow_type_mapping
11096                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11097                         struct rte_pmd_i40e_pkt_template_conf conf;
11098                         uint16_t flow_type = str2flowtype(res->flow_type);
11099                         uint16_t i, port = res->port_id;
11100                         uint8_t add;
11101
11102                         memset(&conf, 0, sizeof(conf));
11103
11104                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11105                                 printf("Invalid flow type specified.\n");
11106                                 return;
11107                         }
11108                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11109                                                                  mapping);
11110                         if (ret)
11111                                 return;
11112                         if (mapping[flow_type].pctype == 0ULL) {
11113                                 printf("Invalid flow type specified.\n");
11114                                 return;
11115                         }
11116                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11117                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11118                                         conf.input.pctype = i;
11119                                         break;
11120                                 }
11121                         }
11122
11123                         conf.input.packet = open_file(res->filepath,
11124                                                 &conf.input.length);
11125                         if (!conf.input.packet)
11126                                 return;
11127                         if (!strcmp(res->drop, "drop"))
11128                                 conf.action.behavior =
11129                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11130                         else
11131                                 conf.action.behavior =
11132                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11133                         conf.action.report_status =
11134                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11135                         conf.action.rx_queue = res->queue_id;
11136                         conf.soft_id = res->fd_id_value;
11137                         add  = strcmp(res->ops, "del") ? 1 : 0;
11138                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11139                                                                         &conf,
11140                                                                         add);
11141                         if (ret < 0)
11142                                 printf("flow director config error: (%s)\n",
11143                                        strerror(-ret));
11144                         close_file(conf.input.packet);
11145 #endif
11146                         return;
11147                 } else if (strcmp(res->mode_value, "IP")) {
11148                         printf("Please set mode to IP or raw.\n");
11149                         return;
11150                 }
11151                 entry.input.flow_type = str2flowtype(res->flow_type);
11152         }
11153
11154         ret = parse_flexbytes(res->flexbytes_value,
11155                                         flexbytes,
11156                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11157         if (ret < 0) {
11158                 printf("error: Cannot parse flexbytes input.\n");
11159                 return;
11160         }
11161
11162         switch (entry.input.flow_type) {
11163         case RTE_ETH_FLOW_FRAG_IPV4:
11164         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11165                 entry.input.flow.ip4_flow.proto = res->proto_value;
11166                 /* fall-through */
11167         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11168         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11169                 IPV4_ADDR_TO_UINT(res->ip_dst,
11170                         entry.input.flow.ip4_flow.dst_ip);
11171                 IPV4_ADDR_TO_UINT(res->ip_src,
11172                         entry.input.flow.ip4_flow.src_ip);
11173                 entry.input.flow.ip4_flow.tos = res->tos_value;
11174                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11175                 /* need convert to big endian. */
11176                 entry.input.flow.udp4_flow.dst_port =
11177                                 rte_cpu_to_be_16(res->port_dst);
11178                 entry.input.flow.udp4_flow.src_port =
11179                                 rte_cpu_to_be_16(res->port_src);
11180                 break;
11181         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11182                 IPV4_ADDR_TO_UINT(res->ip_dst,
11183                         entry.input.flow.sctp4_flow.ip.dst_ip);
11184                 IPV4_ADDR_TO_UINT(res->ip_src,
11185                         entry.input.flow.sctp4_flow.ip.src_ip);
11186                 entry.input.flow.ip4_flow.tos = res->tos_value;
11187                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11188                 /* need convert to big endian. */
11189                 entry.input.flow.sctp4_flow.dst_port =
11190                                 rte_cpu_to_be_16(res->port_dst);
11191                 entry.input.flow.sctp4_flow.src_port =
11192                                 rte_cpu_to_be_16(res->port_src);
11193                 entry.input.flow.sctp4_flow.verify_tag =
11194                                 rte_cpu_to_be_32(res->verify_tag_value);
11195                 break;
11196         case RTE_ETH_FLOW_FRAG_IPV6:
11197         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11198                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11199                 /* fall-through */
11200         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11201         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11202                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11203                         entry.input.flow.ipv6_flow.dst_ip);
11204                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11205                         entry.input.flow.ipv6_flow.src_ip);
11206                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11207                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11208                 /* need convert to big endian. */
11209                 entry.input.flow.udp6_flow.dst_port =
11210                                 rte_cpu_to_be_16(res->port_dst);
11211                 entry.input.flow.udp6_flow.src_port =
11212                                 rte_cpu_to_be_16(res->port_src);
11213                 break;
11214         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11215                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11216                         entry.input.flow.sctp6_flow.ip.dst_ip);
11217                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11218                         entry.input.flow.sctp6_flow.ip.src_ip);
11219                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11220                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11221                 /* need convert to big endian. */
11222                 entry.input.flow.sctp6_flow.dst_port =
11223                                 rte_cpu_to_be_16(res->port_dst);
11224                 entry.input.flow.sctp6_flow.src_port =
11225                                 rte_cpu_to_be_16(res->port_src);
11226                 entry.input.flow.sctp6_flow.verify_tag =
11227                                 rte_cpu_to_be_32(res->verify_tag_value);
11228                 break;
11229         case RTE_ETH_FLOW_L2_PAYLOAD:
11230                 entry.input.flow.l2_flow.ether_type =
11231                         rte_cpu_to_be_16(res->ether_type);
11232                 break;
11233         default:
11234                 break;
11235         }
11236
11237         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11238                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11239                                  &res->mac_addr,
11240                                  sizeof(struct rte_ether_addr));
11241
11242         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11243                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11244                                  &res->mac_addr,
11245                                  sizeof(struct rte_ether_addr));
11246                 entry.input.flow.tunnel_flow.tunnel_type =
11247                         str2fdir_tunneltype(res->tunnel_type);
11248                 entry.input.flow.tunnel_flow.tunnel_id =
11249                         rte_cpu_to_be_32(res->tunnel_id_value);
11250         }
11251
11252         rte_memcpy(entry.input.flow_ext.flexbytes,
11253                    flexbytes,
11254                    RTE_ETH_FDIR_MAX_FLEXLEN);
11255
11256         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11257
11258         entry.action.flex_off = 0;  /*use 0 by default */
11259         if (!strcmp(res->drop, "drop"))
11260                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11261         else
11262                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11263
11264         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11265             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11266                 if (!strcmp(res->pf_vf, "pf"))
11267                         entry.input.flow_ext.is_vf = 0;
11268                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11269                         struct rte_eth_dev_info dev_info;
11270
11271                         ret = eth_dev_info_get_print_err(res->port_id,
11272                                                 &dev_info);
11273                         if (ret != 0)
11274                                 return;
11275
11276                         errno = 0;
11277                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11278                         if (errno != 0 || *end != '\0' ||
11279                             vf_id >= dev_info.max_vfs) {
11280                                 printf("invalid parameter %s.\n", res->pf_vf);
11281                                 return;
11282                         }
11283                         entry.input.flow_ext.is_vf = 1;
11284                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11285                 } else {
11286                         printf("invalid parameter %s.\n", res->pf_vf);
11287                         return;
11288                 }
11289         }
11290
11291         /* set to report FD ID by default */
11292         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11293         entry.action.rx_queue = res->queue_id;
11294         entry.soft_id = res->fd_id_value;
11295         if (!strcmp(res->ops, "add"))
11296                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11297                                              RTE_ETH_FILTER_ADD, &entry);
11298         else if (!strcmp(res->ops, "del"))
11299                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11300                                              RTE_ETH_FILTER_DELETE, &entry);
11301         else
11302                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11303                                              RTE_ETH_FILTER_UPDATE, &entry);
11304         if (ret < 0)
11305                 printf("flow director programming error: (%s)\n",
11306                         strerror(-ret));
11307 }
11308
11309 cmdline_parse_token_string_t cmd_flow_director_filter =
11310         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11311                                  flow_director_filter, "flow_director_filter");
11312 cmdline_parse_token_num_t cmd_flow_director_port_id =
11313         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11314                               port_id, UINT16);
11315 cmdline_parse_token_string_t cmd_flow_director_ops =
11316         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11317                                  ops, "add#del#update");
11318 cmdline_parse_token_string_t cmd_flow_director_flow =
11319         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11320                                  flow, "flow");
11321 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11322         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11323                 flow_type, NULL);
11324 cmdline_parse_token_string_t cmd_flow_director_ether =
11325         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11326                                  ether, "ether");
11327 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11328         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11329                               ether_type, UINT16);
11330 cmdline_parse_token_string_t cmd_flow_director_src =
11331         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11332                                  src, "src");
11333 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11334         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11335                                  ip_src);
11336 cmdline_parse_token_num_t cmd_flow_director_port_src =
11337         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11338                               port_src, UINT16);
11339 cmdline_parse_token_string_t cmd_flow_director_dst =
11340         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11341                                  dst, "dst");
11342 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11343         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11344                                  ip_dst);
11345 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11346         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11347                               port_dst, UINT16);
11348 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11349         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11350                                   verify_tag, "verify_tag");
11351 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11352         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11353                               verify_tag_value, UINT32);
11354 cmdline_parse_token_string_t cmd_flow_director_tos =
11355         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11356                                  tos, "tos");
11357 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11358         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11359                               tos_value, UINT8);
11360 cmdline_parse_token_string_t cmd_flow_director_proto =
11361         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11362                                  proto, "proto");
11363 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11364         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11365                               proto_value, UINT8);
11366 cmdline_parse_token_string_t cmd_flow_director_ttl =
11367         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11368                                  ttl, "ttl");
11369 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11370         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11371                               ttl_value, UINT8);
11372 cmdline_parse_token_string_t cmd_flow_director_vlan =
11373         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11374                                  vlan, "vlan");
11375 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11376         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11377                               vlan_value, UINT16);
11378 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11379         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11380                                  flexbytes, "flexbytes");
11381 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11382         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11383                               flexbytes_value, NULL);
11384 cmdline_parse_token_string_t cmd_flow_director_drop =
11385         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11386                                  drop, "drop#fwd");
11387 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11388         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11389                               pf_vf, NULL);
11390 cmdline_parse_token_string_t cmd_flow_director_queue =
11391         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11392                                  queue, "queue");
11393 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11394         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11395                               queue_id, UINT16);
11396 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11397         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11398                                  fd_id, "fd_id");
11399 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11400         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11401                               fd_id_value, UINT32);
11402
11403 cmdline_parse_token_string_t cmd_flow_director_mode =
11404         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11405                                  mode, "mode");
11406 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11407         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11408                                  mode_value, "IP");
11409 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11410         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11411                                  mode_value, "MAC-VLAN");
11412 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11413         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11414                                  mode_value, "Tunnel");
11415 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11416         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11417                                  mode_value, "raw");
11418 cmdline_parse_token_string_t cmd_flow_director_mac =
11419         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11420                                  mac, "mac");
11421 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11422         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11423                                     mac_addr);
11424 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11425         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11426                                  tunnel, "tunnel");
11427 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11428         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11429                                  tunnel_type, "NVGRE#VxLAN");
11430 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11431         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11432                                  tunnel_id, "tunnel-id");
11433 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11434         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11435                               tunnel_id_value, UINT32);
11436 cmdline_parse_token_string_t cmd_flow_director_packet =
11437         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11438                                  packet, "packet");
11439 cmdline_parse_token_string_t cmd_flow_director_filepath =
11440         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11441                                  filepath, NULL);
11442
11443 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11444         .f = cmd_flow_director_filter_parsed,
11445         .data = NULL,
11446         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11447                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11448                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11449                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11450                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11451                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11452                 "fd_id <fd_id_value>: "
11453                 "Add or delete an ip flow director entry on NIC",
11454         .tokens = {
11455                 (void *)&cmd_flow_director_filter,
11456                 (void *)&cmd_flow_director_port_id,
11457                 (void *)&cmd_flow_director_mode,
11458                 (void *)&cmd_flow_director_mode_ip,
11459                 (void *)&cmd_flow_director_ops,
11460                 (void *)&cmd_flow_director_flow,
11461                 (void *)&cmd_flow_director_flow_type,
11462                 (void *)&cmd_flow_director_src,
11463                 (void *)&cmd_flow_director_ip_src,
11464                 (void *)&cmd_flow_director_dst,
11465                 (void *)&cmd_flow_director_ip_dst,
11466                 (void *)&cmd_flow_director_tos,
11467                 (void *)&cmd_flow_director_tos_value,
11468                 (void *)&cmd_flow_director_proto,
11469                 (void *)&cmd_flow_director_proto_value,
11470                 (void *)&cmd_flow_director_ttl,
11471                 (void *)&cmd_flow_director_ttl_value,
11472                 (void *)&cmd_flow_director_vlan,
11473                 (void *)&cmd_flow_director_vlan_value,
11474                 (void *)&cmd_flow_director_flexbytes,
11475                 (void *)&cmd_flow_director_flexbytes_value,
11476                 (void *)&cmd_flow_director_drop,
11477                 (void *)&cmd_flow_director_pf_vf,
11478                 (void *)&cmd_flow_director_queue,
11479                 (void *)&cmd_flow_director_queue_id,
11480                 (void *)&cmd_flow_director_fd_id,
11481                 (void *)&cmd_flow_director_fd_id_value,
11482                 NULL,
11483         },
11484 };
11485
11486 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11487         .f = cmd_flow_director_filter_parsed,
11488         .data = NULL,
11489         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11490                 "director entry on NIC",
11491         .tokens = {
11492                 (void *)&cmd_flow_director_filter,
11493                 (void *)&cmd_flow_director_port_id,
11494                 (void *)&cmd_flow_director_mode,
11495                 (void *)&cmd_flow_director_mode_ip,
11496                 (void *)&cmd_flow_director_ops,
11497                 (void *)&cmd_flow_director_flow,
11498                 (void *)&cmd_flow_director_flow_type,
11499                 (void *)&cmd_flow_director_src,
11500                 (void *)&cmd_flow_director_ip_src,
11501                 (void *)&cmd_flow_director_port_src,
11502                 (void *)&cmd_flow_director_dst,
11503                 (void *)&cmd_flow_director_ip_dst,
11504                 (void *)&cmd_flow_director_port_dst,
11505                 (void *)&cmd_flow_director_tos,
11506                 (void *)&cmd_flow_director_tos_value,
11507                 (void *)&cmd_flow_director_ttl,
11508                 (void *)&cmd_flow_director_ttl_value,
11509                 (void *)&cmd_flow_director_vlan,
11510                 (void *)&cmd_flow_director_vlan_value,
11511                 (void *)&cmd_flow_director_flexbytes,
11512                 (void *)&cmd_flow_director_flexbytes_value,
11513                 (void *)&cmd_flow_director_drop,
11514                 (void *)&cmd_flow_director_pf_vf,
11515                 (void *)&cmd_flow_director_queue,
11516                 (void *)&cmd_flow_director_queue_id,
11517                 (void *)&cmd_flow_director_fd_id,
11518                 (void *)&cmd_flow_director_fd_id_value,
11519                 NULL,
11520         },
11521 };
11522
11523 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11524         .f = cmd_flow_director_filter_parsed,
11525         .data = NULL,
11526         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11527                 "director entry on NIC",
11528         .tokens = {
11529                 (void *)&cmd_flow_director_filter,
11530                 (void *)&cmd_flow_director_port_id,
11531                 (void *)&cmd_flow_director_mode,
11532                 (void *)&cmd_flow_director_mode_ip,
11533                 (void *)&cmd_flow_director_ops,
11534                 (void *)&cmd_flow_director_flow,
11535                 (void *)&cmd_flow_director_flow_type,
11536                 (void *)&cmd_flow_director_src,
11537                 (void *)&cmd_flow_director_ip_src,
11538                 (void *)&cmd_flow_director_port_src,
11539                 (void *)&cmd_flow_director_dst,
11540                 (void *)&cmd_flow_director_ip_dst,
11541                 (void *)&cmd_flow_director_port_dst,
11542                 (void *)&cmd_flow_director_verify_tag,
11543                 (void *)&cmd_flow_director_verify_tag_value,
11544                 (void *)&cmd_flow_director_tos,
11545                 (void *)&cmd_flow_director_tos_value,
11546                 (void *)&cmd_flow_director_ttl,
11547                 (void *)&cmd_flow_director_ttl_value,
11548                 (void *)&cmd_flow_director_vlan,
11549                 (void *)&cmd_flow_director_vlan_value,
11550                 (void *)&cmd_flow_director_flexbytes,
11551                 (void *)&cmd_flow_director_flexbytes_value,
11552                 (void *)&cmd_flow_director_drop,
11553                 (void *)&cmd_flow_director_pf_vf,
11554                 (void *)&cmd_flow_director_queue,
11555                 (void *)&cmd_flow_director_queue_id,
11556                 (void *)&cmd_flow_director_fd_id,
11557                 (void *)&cmd_flow_director_fd_id_value,
11558                 NULL,
11559         },
11560 };
11561
11562 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11563         .f = cmd_flow_director_filter_parsed,
11564         .data = NULL,
11565         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11566                 "director entry on NIC",
11567         .tokens = {
11568                 (void *)&cmd_flow_director_filter,
11569                 (void *)&cmd_flow_director_port_id,
11570                 (void *)&cmd_flow_director_mode,
11571                 (void *)&cmd_flow_director_mode_ip,
11572                 (void *)&cmd_flow_director_ops,
11573                 (void *)&cmd_flow_director_flow,
11574                 (void *)&cmd_flow_director_flow_type,
11575                 (void *)&cmd_flow_director_ether,
11576                 (void *)&cmd_flow_director_ether_type,
11577                 (void *)&cmd_flow_director_flexbytes,
11578                 (void *)&cmd_flow_director_flexbytes_value,
11579                 (void *)&cmd_flow_director_drop,
11580                 (void *)&cmd_flow_director_pf_vf,
11581                 (void *)&cmd_flow_director_queue,
11582                 (void *)&cmd_flow_director_queue_id,
11583                 (void *)&cmd_flow_director_fd_id,
11584                 (void *)&cmd_flow_director_fd_id_value,
11585                 NULL,
11586         },
11587 };
11588
11589 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11590         .f = cmd_flow_director_filter_parsed,
11591         .data = NULL,
11592         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11593                 "director entry on NIC",
11594         .tokens = {
11595                 (void *)&cmd_flow_director_filter,
11596                 (void *)&cmd_flow_director_port_id,
11597                 (void *)&cmd_flow_director_mode,
11598                 (void *)&cmd_flow_director_mode_mac_vlan,
11599                 (void *)&cmd_flow_director_ops,
11600                 (void *)&cmd_flow_director_mac,
11601                 (void *)&cmd_flow_director_mac_addr,
11602                 (void *)&cmd_flow_director_vlan,
11603                 (void *)&cmd_flow_director_vlan_value,
11604                 (void *)&cmd_flow_director_flexbytes,
11605                 (void *)&cmd_flow_director_flexbytes_value,
11606                 (void *)&cmd_flow_director_drop,
11607                 (void *)&cmd_flow_director_queue,
11608                 (void *)&cmd_flow_director_queue_id,
11609                 (void *)&cmd_flow_director_fd_id,
11610                 (void *)&cmd_flow_director_fd_id_value,
11611                 NULL,
11612         },
11613 };
11614
11615 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11616         .f = cmd_flow_director_filter_parsed,
11617         .data = NULL,
11618         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11619                 "director entry on NIC",
11620         .tokens = {
11621                 (void *)&cmd_flow_director_filter,
11622                 (void *)&cmd_flow_director_port_id,
11623                 (void *)&cmd_flow_director_mode,
11624                 (void *)&cmd_flow_director_mode_tunnel,
11625                 (void *)&cmd_flow_director_ops,
11626                 (void *)&cmd_flow_director_mac,
11627                 (void *)&cmd_flow_director_mac_addr,
11628                 (void *)&cmd_flow_director_vlan,
11629                 (void *)&cmd_flow_director_vlan_value,
11630                 (void *)&cmd_flow_director_tunnel,
11631                 (void *)&cmd_flow_director_tunnel_type,
11632                 (void *)&cmd_flow_director_tunnel_id,
11633                 (void *)&cmd_flow_director_tunnel_id_value,
11634                 (void *)&cmd_flow_director_flexbytes,
11635                 (void *)&cmd_flow_director_flexbytes_value,
11636                 (void *)&cmd_flow_director_drop,
11637                 (void *)&cmd_flow_director_queue,
11638                 (void *)&cmd_flow_director_queue_id,
11639                 (void *)&cmd_flow_director_fd_id,
11640                 (void *)&cmd_flow_director_fd_id_value,
11641                 NULL,
11642         },
11643 };
11644
11645 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11646         .f = cmd_flow_director_filter_parsed,
11647         .data = NULL,
11648         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11649                 "director entry on NIC",
11650         .tokens = {
11651                 (void *)&cmd_flow_director_filter,
11652                 (void *)&cmd_flow_director_port_id,
11653                 (void *)&cmd_flow_director_mode,
11654                 (void *)&cmd_flow_director_mode_raw,
11655                 (void *)&cmd_flow_director_ops,
11656                 (void *)&cmd_flow_director_flow,
11657                 (void *)&cmd_flow_director_flow_type,
11658                 (void *)&cmd_flow_director_drop,
11659                 (void *)&cmd_flow_director_queue,
11660                 (void *)&cmd_flow_director_queue_id,
11661                 (void *)&cmd_flow_director_fd_id,
11662                 (void *)&cmd_flow_director_fd_id_value,
11663                 (void *)&cmd_flow_director_packet,
11664                 (void *)&cmd_flow_director_filepath,
11665                 NULL,
11666         },
11667 };
11668
11669 struct cmd_flush_flow_director_result {
11670         cmdline_fixed_string_t flush_flow_director;
11671         portid_t port_id;
11672 };
11673
11674 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11675         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11676                                  flush_flow_director, "flush_flow_director");
11677 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11678         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11679                               port_id, UINT16);
11680
11681 static void
11682 cmd_flush_flow_director_parsed(void *parsed_result,
11683                           __rte_unused struct cmdline *cl,
11684                           __rte_unused void *data)
11685 {
11686         struct cmd_flow_director_result *res = parsed_result;
11687         int ret = 0;
11688
11689         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11690         if (ret < 0) {
11691                 printf("flow director is not supported on port %u.\n",
11692                         res->port_id);
11693                 return;
11694         }
11695
11696         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11697                         RTE_ETH_FILTER_FLUSH, NULL);
11698         if (ret < 0)
11699                 printf("flow director table flushing error: (%s)\n",
11700                         strerror(-ret));
11701 }
11702
11703 cmdline_parse_inst_t cmd_flush_flow_director = {
11704         .f = cmd_flush_flow_director_parsed,
11705         .data = NULL,
11706         .help_str = "flush_flow_director <port_id>: "
11707                 "Flush all flow director entries of a device on NIC",
11708         .tokens = {
11709                 (void *)&cmd_flush_flow_director_flush,
11710                 (void *)&cmd_flush_flow_director_port_id,
11711                 NULL,
11712         },
11713 };
11714
11715 /* *** deal with flow director mask *** */
11716 struct cmd_flow_director_mask_result {
11717         cmdline_fixed_string_t flow_director_mask;
11718         portid_t port_id;
11719         cmdline_fixed_string_t mode;
11720         cmdline_fixed_string_t mode_value;
11721         cmdline_fixed_string_t vlan;
11722         uint16_t vlan_mask;
11723         cmdline_fixed_string_t src_mask;
11724         cmdline_ipaddr_t ipv4_src;
11725         cmdline_ipaddr_t ipv6_src;
11726         uint16_t port_src;
11727         cmdline_fixed_string_t dst_mask;
11728         cmdline_ipaddr_t ipv4_dst;
11729         cmdline_ipaddr_t ipv6_dst;
11730         uint16_t port_dst;
11731         cmdline_fixed_string_t mac;
11732         uint8_t mac_addr_byte_mask;
11733         cmdline_fixed_string_t tunnel_id;
11734         uint32_t tunnel_id_mask;
11735         cmdline_fixed_string_t tunnel_type;
11736         uint8_t tunnel_type_mask;
11737 };
11738
11739 static void
11740 cmd_flow_director_mask_parsed(void *parsed_result,
11741                           __rte_unused struct cmdline *cl,
11742                           __rte_unused void *data)
11743 {
11744         struct cmd_flow_director_mask_result *res = parsed_result;
11745         struct rte_eth_fdir_masks *mask;
11746         struct rte_port *port;
11747
11748         port = &ports[res->port_id];
11749         /** Check if the port is not started **/
11750         if (port->port_status != RTE_PORT_STOPPED) {
11751                 printf("Please stop port %d first\n", res->port_id);
11752                 return;
11753         }
11754
11755         mask = &port->dev_conf.fdir_conf.mask;
11756
11757         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11758                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11759                         printf("Please set mode to MAC-VLAN.\n");
11760                         return;
11761                 }
11762
11763                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11764         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11765                 if (strcmp(res->mode_value, "Tunnel")) {
11766                         printf("Please set mode to Tunnel.\n");
11767                         return;
11768                 }
11769
11770                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11771                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11772                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11773                 mask->tunnel_type_mask = res->tunnel_type_mask;
11774         } else {
11775                 if (strcmp(res->mode_value, "IP")) {
11776                         printf("Please set mode to IP.\n");
11777                         return;
11778                 }
11779
11780                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11781                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11782                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11783                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11784                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11785                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11786                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11787         }
11788
11789         cmd_reconfig_device_queue(res->port_id, 1, 1);
11790 }
11791
11792 cmdline_parse_token_string_t cmd_flow_director_mask =
11793         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11794                                  flow_director_mask, "flow_director_mask");
11795 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11796         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11797                               port_id, UINT16);
11798 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11799         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11800                                  vlan, "vlan");
11801 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11802         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11803                               vlan_mask, UINT16);
11804 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11805         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11806                                  src_mask, "src_mask");
11807 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11808         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11809                                  ipv4_src);
11810 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11811         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11812                                  ipv6_src);
11813 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11814         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11815                               port_src, UINT16);
11816 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11817         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11818                                  dst_mask, "dst_mask");
11819 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11820         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11821                                  ipv4_dst);
11822 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11823         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11824                                  ipv6_dst);
11825 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11826         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11827                               port_dst, UINT16);
11828
11829 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11830         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11831                                  mode, "mode");
11832 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11833         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11834                                  mode_value, "IP");
11835 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11836         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11837                                  mode_value, "MAC-VLAN");
11838 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11839         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11840                                  mode_value, "Tunnel");
11841 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11842         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11843                                  mac, "mac");
11844 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11845         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11846                               mac_addr_byte_mask, UINT8);
11847 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11848         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11849                                  tunnel_type, "tunnel-type");
11850 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11851         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11852                               tunnel_type_mask, UINT8);
11853 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11854         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11855                                  tunnel_id, "tunnel-id");
11856 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11857         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11858                               tunnel_id_mask, UINT32);
11859
11860 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11861         .f = cmd_flow_director_mask_parsed,
11862         .data = NULL,
11863         .help_str = "flow_director_mask ... : "
11864                 "Set IP mode flow director's mask on NIC",
11865         .tokens = {
11866                 (void *)&cmd_flow_director_mask,
11867                 (void *)&cmd_flow_director_mask_port_id,
11868                 (void *)&cmd_flow_director_mask_mode,
11869                 (void *)&cmd_flow_director_mask_mode_ip,
11870                 (void *)&cmd_flow_director_mask_vlan,
11871                 (void *)&cmd_flow_director_mask_vlan_value,
11872                 (void *)&cmd_flow_director_mask_src,
11873                 (void *)&cmd_flow_director_mask_ipv4_src,
11874                 (void *)&cmd_flow_director_mask_ipv6_src,
11875                 (void *)&cmd_flow_director_mask_port_src,
11876                 (void *)&cmd_flow_director_mask_dst,
11877                 (void *)&cmd_flow_director_mask_ipv4_dst,
11878                 (void *)&cmd_flow_director_mask_ipv6_dst,
11879                 (void *)&cmd_flow_director_mask_port_dst,
11880                 NULL,
11881         },
11882 };
11883
11884 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11885         .f = cmd_flow_director_mask_parsed,
11886         .data = NULL,
11887         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11888                 "flow director's mask on NIC",
11889         .tokens = {
11890                 (void *)&cmd_flow_director_mask,
11891                 (void *)&cmd_flow_director_mask_port_id,
11892                 (void *)&cmd_flow_director_mask_mode,
11893                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11894                 (void *)&cmd_flow_director_mask_vlan,
11895                 (void *)&cmd_flow_director_mask_vlan_value,
11896                 NULL,
11897         },
11898 };
11899
11900 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11901         .f = cmd_flow_director_mask_parsed,
11902         .data = NULL,
11903         .help_str = "flow_director_mask ... : Set tunnel mode "
11904                 "flow director's mask on NIC",
11905         .tokens = {
11906                 (void *)&cmd_flow_director_mask,
11907                 (void *)&cmd_flow_director_mask_port_id,
11908                 (void *)&cmd_flow_director_mask_mode,
11909                 (void *)&cmd_flow_director_mask_mode_tunnel,
11910                 (void *)&cmd_flow_director_mask_vlan,
11911                 (void *)&cmd_flow_director_mask_vlan_value,
11912                 (void *)&cmd_flow_director_mask_mac,
11913                 (void *)&cmd_flow_director_mask_mac_value,
11914                 (void *)&cmd_flow_director_mask_tunnel_type,
11915                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11916                 (void *)&cmd_flow_director_mask_tunnel_id,
11917                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11918                 NULL,
11919         },
11920 };
11921
11922 /* *** deal with flow director mask on flexible payload *** */
11923 struct cmd_flow_director_flex_mask_result {
11924         cmdline_fixed_string_t flow_director_flexmask;
11925         portid_t port_id;
11926         cmdline_fixed_string_t flow;
11927         cmdline_fixed_string_t flow_type;
11928         cmdline_fixed_string_t mask;
11929 };
11930
11931 static void
11932 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11933                           __rte_unused struct cmdline *cl,
11934                           __rte_unused void *data)
11935 {
11936         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11937         struct rte_eth_fdir_info fdir_info;
11938         struct rte_eth_fdir_flex_mask flex_mask;
11939         struct rte_port *port;
11940         uint64_t flow_type_mask;
11941         uint16_t i;
11942         int ret;
11943
11944         port = &ports[res->port_id];
11945         /** Check if the port is not started **/
11946         if (port->port_status != RTE_PORT_STOPPED) {
11947                 printf("Please stop port %d first\n", res->port_id);
11948                 return;
11949         }
11950
11951         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11952         ret = parse_flexbytes(res->mask,
11953                         flex_mask.mask,
11954                         RTE_ETH_FDIR_MAX_FLEXLEN);
11955         if (ret < 0) {
11956                 printf("error: Cannot parse mask input.\n");
11957                 return;
11958         }
11959
11960         memset(&fdir_info, 0, sizeof(fdir_info));
11961         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11962                                 RTE_ETH_FILTER_INFO, &fdir_info);
11963         if (ret < 0) {
11964                 printf("Cannot get FDir filter info\n");
11965                 return;
11966         }
11967
11968         if (!strcmp(res->flow_type, "none")) {
11969                 /* means don't specify the flow type */
11970                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11971                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11972                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11973                                0, sizeof(struct rte_eth_fdir_flex_mask));
11974                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11975                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11976                                  &flex_mask,
11977                                  sizeof(struct rte_eth_fdir_flex_mask));
11978                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11979                 return;
11980         }
11981         flow_type_mask = fdir_info.flow_types_mask[0];
11982         if (!strcmp(res->flow_type, "all")) {
11983                 if (!flow_type_mask) {
11984                         printf("No flow type supported\n");
11985                         return;
11986                 }
11987                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11988                         if (flow_type_mask & (1ULL << i)) {
11989                                 flex_mask.flow_type = i;
11990                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11991                         }
11992                 }
11993                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11994                 return;
11995         }
11996         flex_mask.flow_type = str2flowtype(res->flow_type);
11997         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11998                 printf("Flow type %s not supported on port %d\n",
11999                                 res->flow_type, res->port_id);
12000                 return;
12001         }
12002         fdir_set_flex_mask(res->port_id, &flex_mask);
12003         cmd_reconfig_device_queue(res->port_id, 1, 1);
12004 }
12005
12006 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12007         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12008                                  flow_director_flexmask,
12009                                  "flow_director_flex_mask");
12010 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12011         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12012                               port_id, UINT16);
12013 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12014         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12015                                  flow, "flow");
12016 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12017         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12018                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12019                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12020 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12021         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12022                                  mask, NULL);
12023
12024 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12025         .f = cmd_flow_director_flex_mask_parsed,
12026         .data = NULL,
12027         .help_str = "flow_director_flex_mask ... : "
12028                 "Set flow director's flex mask on NIC",
12029         .tokens = {
12030                 (void *)&cmd_flow_director_flexmask,
12031                 (void *)&cmd_flow_director_flexmask_port_id,
12032                 (void *)&cmd_flow_director_flexmask_flow,
12033                 (void *)&cmd_flow_director_flexmask_flow_type,
12034                 (void *)&cmd_flow_director_flexmask_mask,
12035                 NULL,
12036         },
12037 };
12038
12039 /* *** deal with flow director flexible payload configuration *** */
12040 struct cmd_flow_director_flexpayload_result {
12041         cmdline_fixed_string_t flow_director_flexpayload;
12042         portid_t port_id;
12043         cmdline_fixed_string_t payload_layer;
12044         cmdline_fixed_string_t payload_cfg;
12045 };
12046
12047 static inline int
12048 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12049 {
12050         char s[256];
12051         const char *p, *p0 = q_arg;
12052         char *end;
12053         unsigned long int_fld;
12054         char *str_fld[max_num];
12055         int i;
12056         unsigned size;
12057         int ret = -1;
12058
12059         p = strchr(p0, '(');
12060         if (p == NULL)
12061                 return -1;
12062         ++p;
12063         p0 = strchr(p, ')');
12064         if (p0 == NULL)
12065                 return -1;
12066
12067         size = p0 - p;
12068         if (size >= sizeof(s))
12069                 return -1;
12070
12071         snprintf(s, sizeof(s), "%.*s", size, p);
12072         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12073         if (ret < 0 || ret > max_num)
12074                 return -1;
12075         for (i = 0; i < ret; i++) {
12076                 errno = 0;
12077                 int_fld = strtoul(str_fld[i], &end, 0);
12078                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12079                         return -1;
12080                 offsets[i] = (uint16_t)int_fld;
12081         }
12082         return ret;
12083 }
12084
12085 static void
12086 cmd_flow_director_flxpld_parsed(void *parsed_result,
12087                           __rte_unused struct cmdline *cl,
12088                           __rte_unused void *data)
12089 {
12090         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12091         struct rte_eth_flex_payload_cfg flex_cfg;
12092         struct rte_port *port;
12093         int ret = 0;
12094
12095         port = &ports[res->port_id];
12096         /** Check if the port is not started **/
12097         if (port->port_status != RTE_PORT_STOPPED) {
12098                 printf("Please stop port %d first\n", res->port_id);
12099                 return;
12100         }
12101
12102         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12103
12104         if (!strcmp(res->payload_layer, "raw"))
12105                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12106         else if (!strcmp(res->payload_layer, "l2"))
12107                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12108         else if (!strcmp(res->payload_layer, "l3"))
12109                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12110         else if (!strcmp(res->payload_layer, "l4"))
12111                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12112
12113         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12114                             RTE_ETH_FDIR_MAX_FLEXLEN);
12115         if (ret < 0) {
12116                 printf("error: Cannot parse flex payload input.\n");
12117                 return;
12118         }
12119
12120         fdir_set_flex_payload(res->port_id, &flex_cfg);
12121         cmd_reconfig_device_queue(res->port_id, 1, 1);
12122 }
12123
12124 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12125         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12126                                  flow_director_flexpayload,
12127                                  "flow_director_flex_payload");
12128 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12129         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12130                               port_id, UINT16);
12131 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12132         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12133                                  payload_layer, "raw#l2#l3#l4");
12134 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12135         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12136                                  payload_cfg, NULL);
12137
12138 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12139         .f = cmd_flow_director_flxpld_parsed,
12140         .data = NULL,
12141         .help_str = "flow_director_flexpayload ... : "
12142                 "Set flow director's flex payload on NIC",
12143         .tokens = {
12144                 (void *)&cmd_flow_director_flexpayload,
12145                 (void *)&cmd_flow_director_flexpayload_port_id,
12146                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12147                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12148                 NULL,
12149         },
12150 };
12151
12152 /* Generic flow interface command. */
12153 extern cmdline_parse_inst_t cmd_flow;
12154
12155 /* *** Classification Filters Control *** */
12156 /* *** Get symmetric hash enable per port *** */
12157 struct cmd_get_sym_hash_ena_per_port_result {
12158         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12159         portid_t port_id;
12160 };
12161
12162 static void
12163 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12164                                  __rte_unused struct cmdline *cl,
12165                                  __rte_unused void *data)
12166 {
12167         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12168         struct rte_eth_hash_filter_info info;
12169         int ret;
12170
12171         if (rte_eth_dev_filter_supported(res->port_id,
12172                                 RTE_ETH_FILTER_HASH) < 0) {
12173                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12174                                                         res->port_id);
12175                 return;
12176         }
12177
12178         memset(&info, 0, sizeof(info));
12179         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12180         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12181                                                 RTE_ETH_FILTER_GET, &info);
12182
12183         if (ret < 0) {
12184                 printf("Cannot get symmetric hash enable per port "
12185                                         "on port %u\n", res->port_id);
12186                 return;
12187         }
12188
12189         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12190                                 "enabled" : "disabled", res->port_id);
12191 }
12192
12193 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12194         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12195                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12196 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12197         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12198                 port_id, UINT16);
12199
12200 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12201         .f = cmd_get_sym_hash_per_port_parsed,
12202         .data = NULL,
12203         .help_str = "get_sym_hash_ena_per_port <port_id>",
12204         .tokens = {
12205                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12206                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12207                 NULL,
12208         },
12209 };
12210
12211 /* *** Set symmetric hash enable per port *** */
12212 struct cmd_set_sym_hash_ena_per_port_result {
12213         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12214         cmdline_fixed_string_t enable;
12215         portid_t port_id;
12216 };
12217
12218 static void
12219 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12220                                  __rte_unused struct cmdline *cl,
12221                                  __rte_unused void *data)
12222 {
12223         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12224         struct rte_eth_hash_filter_info info;
12225         int ret;
12226
12227         if (rte_eth_dev_filter_supported(res->port_id,
12228                                 RTE_ETH_FILTER_HASH) < 0) {
12229                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12230                                                         res->port_id);
12231                 return;
12232         }
12233
12234         memset(&info, 0, sizeof(info));
12235         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12236         if (!strcmp(res->enable, "enable"))
12237                 info.info.enable = 1;
12238         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12239                                         RTE_ETH_FILTER_SET, &info);
12240         if (ret < 0) {
12241                 printf("Cannot set symmetric hash enable per port on "
12242                                         "port %u\n", res->port_id);
12243                 return;
12244         }
12245         printf("Symmetric hash has been set to %s on port %u\n",
12246                                         res->enable, res->port_id);
12247 }
12248
12249 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12250         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12251                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12252 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12253         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12254                 port_id, UINT16);
12255 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12256         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12257                 enable, "enable#disable");
12258
12259 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12260         .f = cmd_set_sym_hash_per_port_parsed,
12261         .data = NULL,
12262         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12263         .tokens = {
12264                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12265                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12266                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12267                 NULL,
12268         },
12269 };
12270
12271 /* Get global config of hash function */
12272 struct cmd_get_hash_global_config_result {
12273         cmdline_fixed_string_t get_hash_global_config;
12274         portid_t port_id;
12275 };
12276
12277 static char *
12278 flowtype_to_str(uint16_t ftype)
12279 {
12280         uint16_t i;
12281         static struct {
12282                 char str[16];
12283                 uint16_t ftype;
12284         } ftype_table[] = {
12285                 {"ipv4", RTE_ETH_FLOW_IPV4},
12286                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12287                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12288                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12289                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12290                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12291                 {"ipv6", RTE_ETH_FLOW_IPV6},
12292                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12293                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12294                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12295                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12296                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12297                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12298                 {"port", RTE_ETH_FLOW_PORT},
12299                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12300                 {"geneve", RTE_ETH_FLOW_GENEVE},
12301                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12302                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12303         };
12304
12305         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12306                 if (ftype_table[i].ftype == ftype)
12307                         return ftype_table[i].str;
12308         }
12309
12310         return NULL;
12311 }
12312
12313 static void
12314 cmd_get_hash_global_config_parsed(void *parsed_result,
12315                                   __rte_unused struct cmdline *cl,
12316                                   __rte_unused void *data)
12317 {
12318         struct cmd_get_hash_global_config_result *res = parsed_result;
12319         struct rte_eth_hash_filter_info info;
12320         uint32_t idx, offset;
12321         uint16_t i;
12322         char *str;
12323         int ret;
12324
12325         if (rte_eth_dev_filter_supported(res->port_id,
12326                         RTE_ETH_FILTER_HASH) < 0) {
12327                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12328                                                         res->port_id);
12329                 return;
12330         }
12331
12332         memset(&info, 0, sizeof(info));
12333         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12334         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12335                                         RTE_ETH_FILTER_GET, &info);
12336         if (ret < 0) {
12337                 printf("Cannot get hash global configurations by port %d\n",
12338                                                         res->port_id);
12339                 return;
12340         }
12341
12342         switch (info.info.global_conf.hash_func) {
12343         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12344                 printf("Hash function is Toeplitz\n");
12345                 break;
12346         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12347                 printf("Hash function is Simple XOR\n");
12348                 break;
12349         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12350                 printf("Hash function is Symmetric Toeplitz\n");
12351                 break;
12352         default:
12353                 printf("Unknown hash function\n");
12354                 break;
12355         }
12356
12357         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12358                 idx = i / UINT64_BIT;
12359                 offset = i % UINT64_BIT;
12360                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12361                                                 (1ULL << offset)))
12362                         continue;
12363                 str = flowtype_to_str(i);
12364                 if (!str)
12365                         continue;
12366                 printf("Symmetric hash is %s globally for flow type %s "
12367                                                         "by port %d\n",
12368                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12369                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12370                                                         res->port_id);
12371         }
12372 }
12373
12374 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12375         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12376                 get_hash_global_config, "get_hash_global_config");
12377 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12378         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12379                 port_id, UINT16);
12380
12381 cmdline_parse_inst_t cmd_get_hash_global_config = {
12382         .f = cmd_get_hash_global_config_parsed,
12383         .data = NULL,
12384         .help_str = "get_hash_global_config <port_id>",
12385         .tokens = {
12386                 (void *)&cmd_get_hash_global_config_all,
12387                 (void *)&cmd_get_hash_global_config_port_id,
12388                 NULL,
12389         },
12390 };
12391
12392 /* Set global config of hash function */
12393 struct cmd_set_hash_global_config_result {
12394         cmdline_fixed_string_t set_hash_global_config;
12395         portid_t port_id;
12396         cmdline_fixed_string_t hash_func;
12397         cmdline_fixed_string_t flow_type;
12398         cmdline_fixed_string_t enable;
12399 };
12400
12401 static void
12402 cmd_set_hash_global_config_parsed(void *parsed_result,
12403                                   __rte_unused struct cmdline *cl,
12404                                   __rte_unused void *data)
12405 {
12406         struct cmd_set_hash_global_config_result *res = parsed_result;
12407         struct rte_eth_hash_filter_info info;
12408         uint32_t ftype, idx, offset;
12409         int ret;
12410
12411         if (rte_eth_dev_filter_supported(res->port_id,
12412                                 RTE_ETH_FILTER_HASH) < 0) {
12413                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12414                                                         res->port_id);
12415                 return;
12416         }
12417         memset(&info, 0, sizeof(info));
12418         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12419         if (!strcmp(res->hash_func, "toeplitz"))
12420                 info.info.global_conf.hash_func =
12421                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12422         else if (!strcmp(res->hash_func, "simple_xor"))
12423                 info.info.global_conf.hash_func =
12424                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12425         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12426                 info.info.global_conf.hash_func =
12427                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12428         else if (!strcmp(res->hash_func, "default"))
12429                 info.info.global_conf.hash_func =
12430                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12431
12432         ftype = str2flowtype(res->flow_type);
12433         idx = ftype / UINT64_BIT;
12434         offset = ftype % UINT64_BIT;
12435         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12436         if (!strcmp(res->enable, "enable"))
12437                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12438                                                 (1ULL << offset);
12439         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12440                                         RTE_ETH_FILTER_SET, &info);
12441         if (ret < 0)
12442                 printf("Cannot set global hash configurations by port %d\n",
12443                                                         res->port_id);
12444         else
12445                 printf("Global hash configurations have been set "
12446                         "successfully by port %d\n", res->port_id);
12447 }
12448
12449 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12450         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12451                 set_hash_global_config, "set_hash_global_config");
12452 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12453         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12454                 port_id, UINT16);
12455 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12456         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12457                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12458 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12459         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12460                 flow_type,
12461                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12462                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12463 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12464         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12465                 enable, "enable#disable");
12466
12467 cmdline_parse_inst_t cmd_set_hash_global_config = {
12468         .f = cmd_set_hash_global_config_parsed,
12469         .data = NULL,
12470         .help_str = "set_hash_global_config <port_id> "
12471                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12472                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12473                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12474                 "l2_payload enable|disable",
12475         .tokens = {
12476                 (void *)&cmd_set_hash_global_config_all,
12477                 (void *)&cmd_set_hash_global_config_port_id,
12478                 (void *)&cmd_set_hash_global_config_hash_func,
12479                 (void *)&cmd_set_hash_global_config_flow_type,
12480                 (void *)&cmd_set_hash_global_config_enable,
12481                 NULL,
12482         },
12483 };
12484
12485 /* Set hash input set */
12486 struct cmd_set_hash_input_set_result {
12487         cmdline_fixed_string_t set_hash_input_set;
12488         portid_t port_id;
12489         cmdline_fixed_string_t flow_type;
12490         cmdline_fixed_string_t inset_field;
12491         cmdline_fixed_string_t select;
12492 };
12493
12494 static enum rte_eth_input_set_field
12495 str2inset(char *string)
12496 {
12497         uint16_t i;
12498
12499         static const struct {
12500                 char str[32];
12501                 enum rte_eth_input_set_field inset;
12502         } inset_table[] = {
12503                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12504                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12505                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12506                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12507                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12508                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12509                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12510                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12511                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12512                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12513                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12514                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12515                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12516                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12517                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12518                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12519                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12520                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12521                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12522                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12523                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12524                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12525                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12526                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12527                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12528                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12529                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12530                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12531                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12532                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12533                 {"none", RTE_ETH_INPUT_SET_NONE},
12534         };
12535
12536         for (i = 0; i < RTE_DIM(inset_table); i++) {
12537                 if (!strcmp(string, inset_table[i].str))
12538                         return inset_table[i].inset;
12539         }
12540
12541         return RTE_ETH_INPUT_SET_UNKNOWN;
12542 }
12543
12544 static void
12545 cmd_set_hash_input_set_parsed(void *parsed_result,
12546                               __rte_unused struct cmdline *cl,
12547                               __rte_unused void *data)
12548 {
12549         struct cmd_set_hash_input_set_result *res = parsed_result;
12550         struct rte_eth_hash_filter_info info;
12551
12552         memset(&info, 0, sizeof(info));
12553         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12554         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12555         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12556         info.info.input_set_conf.inset_size = 1;
12557         if (!strcmp(res->select, "select"))
12558                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12559         else if (!strcmp(res->select, "add"))
12560                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12561         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12562                                 RTE_ETH_FILTER_SET, &info);
12563 }
12564
12565 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12566         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12567                 set_hash_input_set, "set_hash_input_set");
12568 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12569         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12570                 port_id, UINT16);
12571 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12572         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12573                 flow_type, NULL);
12574 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12575         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12576                 inset_field,
12577                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12578                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12579                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12580                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12581                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12582                 "fld-8th#none");
12583 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12584         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12585                 select, "select#add");
12586
12587 cmdline_parse_inst_t cmd_set_hash_input_set = {
12588         .f = cmd_set_hash_input_set_parsed,
12589         .data = NULL,
12590         .help_str = "set_hash_input_set <port_id> "
12591         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12592         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12593         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12594         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12595         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12596         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12597         "fld-7th|fld-8th|none select|add",
12598         .tokens = {
12599                 (void *)&cmd_set_hash_input_set_cmd,
12600                 (void *)&cmd_set_hash_input_set_port_id,
12601                 (void *)&cmd_set_hash_input_set_flow_type,
12602                 (void *)&cmd_set_hash_input_set_field,
12603                 (void *)&cmd_set_hash_input_set_select,
12604                 NULL,
12605         },
12606 };
12607
12608 /* Set flow director input set */
12609 struct cmd_set_fdir_input_set_result {
12610         cmdline_fixed_string_t set_fdir_input_set;
12611         portid_t port_id;
12612         cmdline_fixed_string_t flow_type;
12613         cmdline_fixed_string_t inset_field;
12614         cmdline_fixed_string_t select;
12615 };
12616
12617 static void
12618 cmd_set_fdir_input_set_parsed(void *parsed_result,
12619         __rte_unused struct cmdline *cl,
12620         __rte_unused void *data)
12621 {
12622         struct cmd_set_fdir_input_set_result *res = parsed_result;
12623         struct rte_eth_fdir_filter_info info;
12624
12625         memset(&info, 0, sizeof(info));
12626         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12627         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12628         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12629         info.info.input_set_conf.inset_size = 1;
12630         if (!strcmp(res->select, "select"))
12631                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12632         else if (!strcmp(res->select, "add"))
12633                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12634         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12635                 RTE_ETH_FILTER_SET, &info);
12636 }
12637
12638 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12639         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12640         set_fdir_input_set, "set_fdir_input_set");
12641 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12642         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12643         port_id, UINT16);
12644 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12645         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12646         flow_type,
12647         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12648         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12649 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12650         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12651         inset_field,
12652         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12653         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12654         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12655         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12656         "sctp-veri-tag#none");
12657 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12658         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12659         select, "select#add");
12660
12661 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12662         .f = cmd_set_fdir_input_set_parsed,
12663         .data = NULL,
12664         .help_str = "set_fdir_input_set <port_id> "
12665         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12666         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12667         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12668         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12669         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12670         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12671         "sctp-veri-tag|none select|add",
12672         .tokens = {
12673                 (void *)&cmd_set_fdir_input_set_cmd,
12674                 (void *)&cmd_set_fdir_input_set_port_id,
12675                 (void *)&cmd_set_fdir_input_set_flow_type,
12676                 (void *)&cmd_set_fdir_input_set_field,
12677                 (void *)&cmd_set_fdir_input_set_select,
12678                 NULL,
12679         },
12680 };
12681
12682 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12683 struct cmd_mcast_addr_result {
12684         cmdline_fixed_string_t mcast_addr_cmd;
12685         cmdline_fixed_string_t what;
12686         uint16_t port_num;
12687         struct rte_ether_addr mc_addr;
12688 };
12689
12690 static void cmd_mcast_addr_parsed(void *parsed_result,
12691                 __rte_unused struct cmdline *cl,
12692                 __rte_unused void *data)
12693 {
12694         struct cmd_mcast_addr_result *res = parsed_result;
12695
12696         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12697                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12698                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12699                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12700                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12701                 return;
12702         }
12703         if (strcmp(res->what, "add") == 0)
12704                 mcast_addr_add(res->port_num, &res->mc_addr);
12705         else
12706                 mcast_addr_remove(res->port_num, &res->mc_addr);
12707 }
12708
12709 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12710         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12711                                  mcast_addr_cmd, "mcast_addr");
12712 cmdline_parse_token_string_t cmd_mcast_addr_what =
12713         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12714                                  "add#remove");
12715 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12716         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12717 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12718         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12719
12720 cmdline_parse_inst_t cmd_mcast_addr = {
12721         .f = cmd_mcast_addr_parsed,
12722         .data = (void *)0,
12723         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12724                 "Add/Remove multicast MAC address on port_id",
12725         .tokens = {
12726                 (void *)&cmd_mcast_addr_cmd,
12727                 (void *)&cmd_mcast_addr_what,
12728                 (void *)&cmd_mcast_addr_portnum,
12729                 (void *)&cmd_mcast_addr_addr,
12730                 NULL,
12731         },
12732 };
12733
12734 /* l2 tunnel config
12735  * only support E-tag now.
12736  */
12737
12738 /* Ether type config */
12739 struct cmd_config_l2_tunnel_eth_type_result {
12740         cmdline_fixed_string_t port;
12741         cmdline_fixed_string_t config;
12742         cmdline_fixed_string_t all;
12743         portid_t id;
12744         cmdline_fixed_string_t l2_tunnel;
12745         cmdline_fixed_string_t l2_tunnel_type;
12746         cmdline_fixed_string_t eth_type;
12747         uint16_t eth_type_val;
12748 };
12749
12750 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12751         TOKEN_STRING_INITIALIZER
12752                 (struct cmd_config_l2_tunnel_eth_type_result,
12753                  port, "port");
12754 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12755         TOKEN_STRING_INITIALIZER
12756                 (struct cmd_config_l2_tunnel_eth_type_result,
12757                  config, "config");
12758 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12759         TOKEN_STRING_INITIALIZER
12760                 (struct cmd_config_l2_tunnel_eth_type_result,
12761                  all, "all");
12762 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12763         TOKEN_NUM_INITIALIZER
12764                 (struct cmd_config_l2_tunnel_eth_type_result,
12765                  id, UINT16);
12766 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12767         TOKEN_STRING_INITIALIZER
12768                 (struct cmd_config_l2_tunnel_eth_type_result,
12769                  l2_tunnel, "l2-tunnel");
12770 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12771         TOKEN_STRING_INITIALIZER
12772                 (struct cmd_config_l2_tunnel_eth_type_result,
12773                  l2_tunnel_type, "E-tag");
12774 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12775         TOKEN_STRING_INITIALIZER
12776                 (struct cmd_config_l2_tunnel_eth_type_result,
12777                  eth_type, "ether-type");
12778 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12779         TOKEN_NUM_INITIALIZER
12780                 (struct cmd_config_l2_tunnel_eth_type_result,
12781                  eth_type_val, UINT16);
12782
12783 static enum rte_eth_tunnel_type
12784 str2fdir_l2_tunnel_type(char *string)
12785 {
12786         uint32_t i = 0;
12787
12788         static const struct {
12789                 char str[32];
12790                 enum rte_eth_tunnel_type type;
12791         } l2_tunnel_type_str[] = {
12792                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12793         };
12794
12795         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12796                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12797                         return l2_tunnel_type_str[i].type;
12798         }
12799         return RTE_TUNNEL_TYPE_NONE;
12800 }
12801
12802 /* ether type config for all ports */
12803 static void
12804 cmd_config_l2_tunnel_eth_type_all_parsed
12805         (void *parsed_result,
12806          __rte_unused struct cmdline *cl,
12807          __rte_unused void *data)
12808 {
12809         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12810         struct rte_eth_l2_tunnel_conf entry;
12811         portid_t pid;
12812
12813         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12814         entry.ether_type = res->eth_type_val;
12815
12816         RTE_ETH_FOREACH_DEV(pid) {
12817                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12818         }
12819 }
12820
12821 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12822         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12823         .data = NULL,
12824         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12825         .tokens = {
12826                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12827                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12828                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12829                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12830                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12831                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12832                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12833                 NULL,
12834         },
12835 };
12836
12837 /* ether type config for a specific port */
12838 static void
12839 cmd_config_l2_tunnel_eth_type_specific_parsed(
12840         void *parsed_result,
12841         __rte_unused struct cmdline *cl,
12842         __rte_unused void *data)
12843 {
12844         struct cmd_config_l2_tunnel_eth_type_result *res =
12845                  parsed_result;
12846         struct rte_eth_l2_tunnel_conf entry;
12847
12848         if (port_id_is_invalid(res->id, ENABLED_WARN))
12849                 return;
12850
12851         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12852         entry.ether_type = res->eth_type_val;
12853
12854         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12855 }
12856
12857 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12858         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12859         .data = NULL,
12860         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12861         .tokens = {
12862                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12863                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12864                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12865                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12866                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12867                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12868                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12869                 NULL,
12870         },
12871 };
12872
12873 /* Enable/disable l2 tunnel */
12874 struct cmd_config_l2_tunnel_en_dis_result {
12875         cmdline_fixed_string_t port;
12876         cmdline_fixed_string_t config;
12877         cmdline_fixed_string_t all;
12878         portid_t id;
12879         cmdline_fixed_string_t l2_tunnel;
12880         cmdline_fixed_string_t l2_tunnel_type;
12881         cmdline_fixed_string_t en_dis;
12882 };
12883
12884 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12885         TOKEN_STRING_INITIALIZER
12886                 (struct cmd_config_l2_tunnel_en_dis_result,
12887                  port, "port");
12888 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12889         TOKEN_STRING_INITIALIZER
12890                 (struct cmd_config_l2_tunnel_en_dis_result,
12891                  config, "config");
12892 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12893         TOKEN_STRING_INITIALIZER
12894                 (struct cmd_config_l2_tunnel_en_dis_result,
12895                  all, "all");
12896 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12897         TOKEN_NUM_INITIALIZER
12898                 (struct cmd_config_l2_tunnel_en_dis_result,
12899                  id, UINT16);
12900 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12901         TOKEN_STRING_INITIALIZER
12902                 (struct cmd_config_l2_tunnel_en_dis_result,
12903                  l2_tunnel, "l2-tunnel");
12904 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12905         TOKEN_STRING_INITIALIZER
12906                 (struct cmd_config_l2_tunnel_en_dis_result,
12907                  l2_tunnel_type, "E-tag");
12908 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12909         TOKEN_STRING_INITIALIZER
12910                 (struct cmd_config_l2_tunnel_en_dis_result,
12911                  en_dis, "enable#disable");
12912
12913 /* enable/disable l2 tunnel for all ports */
12914 static void
12915 cmd_config_l2_tunnel_en_dis_all_parsed(
12916         void *parsed_result,
12917         __rte_unused struct cmdline *cl,
12918         __rte_unused void *data)
12919 {
12920         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12921         struct rte_eth_l2_tunnel_conf entry;
12922         portid_t pid;
12923         uint8_t en;
12924
12925         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12926
12927         if (!strcmp("enable", res->en_dis))
12928                 en = 1;
12929         else
12930                 en = 0;
12931
12932         RTE_ETH_FOREACH_DEV(pid) {
12933                 rte_eth_dev_l2_tunnel_offload_set(pid,
12934                                                   &entry,
12935                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12936                                                   en);
12937         }
12938 }
12939
12940 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12941         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12942         .data = NULL,
12943         .help_str = "port config all l2-tunnel E-tag enable|disable",
12944         .tokens = {
12945                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12946                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12947                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12948                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12949                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12950                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12951                 NULL,
12952         },
12953 };
12954
12955 /* enable/disable l2 tunnel for a port */
12956 static void
12957 cmd_config_l2_tunnel_en_dis_specific_parsed(
12958         void *parsed_result,
12959         __rte_unused struct cmdline *cl,
12960         __rte_unused void *data)
12961 {
12962         struct cmd_config_l2_tunnel_en_dis_result *res =
12963                 parsed_result;
12964         struct rte_eth_l2_tunnel_conf entry;
12965
12966         if (port_id_is_invalid(res->id, ENABLED_WARN))
12967                 return;
12968
12969         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12970
12971         if (!strcmp("enable", res->en_dis))
12972                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12973                                                   &entry,
12974                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12975                                                   1);
12976         else
12977                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12978                                                   &entry,
12979                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12980                                                   0);
12981 }
12982
12983 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
12984         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
12985         .data = NULL,
12986         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
12987         .tokens = {
12988                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12989                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12990                 (void *)&cmd_config_l2_tunnel_en_dis_id,
12991                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12992                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12993                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12994                 NULL,
12995         },
12996 };
12997
12998 /* E-tag configuration */
12999
13000 /* Common result structure for all E-tag configuration */
13001 struct cmd_config_e_tag_result {
13002         cmdline_fixed_string_t e_tag;
13003         cmdline_fixed_string_t set;
13004         cmdline_fixed_string_t insertion;
13005         cmdline_fixed_string_t stripping;
13006         cmdline_fixed_string_t forwarding;
13007         cmdline_fixed_string_t filter;
13008         cmdline_fixed_string_t add;
13009         cmdline_fixed_string_t del;
13010         cmdline_fixed_string_t on;
13011         cmdline_fixed_string_t off;
13012         cmdline_fixed_string_t on_off;
13013         cmdline_fixed_string_t port_tag_id;
13014         uint32_t port_tag_id_val;
13015         cmdline_fixed_string_t e_tag_id;
13016         uint16_t e_tag_id_val;
13017         cmdline_fixed_string_t dst_pool;
13018         uint8_t dst_pool_val;
13019         cmdline_fixed_string_t port;
13020         portid_t port_id;
13021         cmdline_fixed_string_t vf;
13022         uint8_t vf_id;
13023 };
13024
13025 /* Common CLI fields for all E-tag configuration */
13026 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13027         TOKEN_STRING_INITIALIZER
13028                 (struct cmd_config_e_tag_result,
13029                  e_tag, "E-tag");
13030 cmdline_parse_token_string_t cmd_config_e_tag_set =
13031         TOKEN_STRING_INITIALIZER
13032                 (struct cmd_config_e_tag_result,
13033                  set, "set");
13034 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13035         TOKEN_STRING_INITIALIZER
13036                 (struct cmd_config_e_tag_result,
13037                  insertion, "insertion");
13038 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13039         TOKEN_STRING_INITIALIZER
13040                 (struct cmd_config_e_tag_result,
13041                  stripping, "stripping");
13042 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13043         TOKEN_STRING_INITIALIZER
13044                 (struct cmd_config_e_tag_result,
13045                  forwarding, "forwarding");
13046 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13047         TOKEN_STRING_INITIALIZER
13048                 (struct cmd_config_e_tag_result,
13049                  filter, "filter");
13050 cmdline_parse_token_string_t cmd_config_e_tag_add =
13051         TOKEN_STRING_INITIALIZER
13052                 (struct cmd_config_e_tag_result,
13053                  add, "add");
13054 cmdline_parse_token_string_t cmd_config_e_tag_del =
13055         TOKEN_STRING_INITIALIZER
13056                 (struct cmd_config_e_tag_result,
13057                  del, "del");
13058 cmdline_parse_token_string_t cmd_config_e_tag_on =
13059         TOKEN_STRING_INITIALIZER
13060                 (struct cmd_config_e_tag_result,
13061                  on, "on");
13062 cmdline_parse_token_string_t cmd_config_e_tag_off =
13063         TOKEN_STRING_INITIALIZER
13064                 (struct cmd_config_e_tag_result,
13065                  off, "off");
13066 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13067         TOKEN_STRING_INITIALIZER
13068                 (struct cmd_config_e_tag_result,
13069                  on_off, "on#off");
13070 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13071         TOKEN_STRING_INITIALIZER
13072                 (struct cmd_config_e_tag_result,
13073                  port_tag_id, "port-tag-id");
13074 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13075         TOKEN_NUM_INITIALIZER
13076                 (struct cmd_config_e_tag_result,
13077                  port_tag_id_val, UINT32);
13078 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13079         TOKEN_STRING_INITIALIZER
13080                 (struct cmd_config_e_tag_result,
13081                  e_tag_id, "e-tag-id");
13082 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13083         TOKEN_NUM_INITIALIZER
13084                 (struct cmd_config_e_tag_result,
13085                  e_tag_id_val, UINT16);
13086 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13087         TOKEN_STRING_INITIALIZER
13088                 (struct cmd_config_e_tag_result,
13089                  dst_pool, "dst-pool");
13090 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13091         TOKEN_NUM_INITIALIZER
13092                 (struct cmd_config_e_tag_result,
13093                  dst_pool_val, UINT8);
13094 cmdline_parse_token_string_t cmd_config_e_tag_port =
13095         TOKEN_STRING_INITIALIZER
13096                 (struct cmd_config_e_tag_result,
13097                  port, "port");
13098 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13099         TOKEN_NUM_INITIALIZER
13100                 (struct cmd_config_e_tag_result,
13101                  port_id, UINT16);
13102 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13103         TOKEN_STRING_INITIALIZER
13104                 (struct cmd_config_e_tag_result,
13105                  vf, "vf");
13106 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13107         TOKEN_NUM_INITIALIZER
13108                 (struct cmd_config_e_tag_result,
13109                  vf_id, UINT8);
13110
13111 /* E-tag insertion configuration */
13112 static void
13113 cmd_config_e_tag_insertion_en_parsed(
13114         void *parsed_result,
13115         __rte_unused struct cmdline *cl,
13116         __rte_unused void *data)
13117 {
13118         struct cmd_config_e_tag_result *res =
13119                 parsed_result;
13120         struct rte_eth_l2_tunnel_conf entry;
13121
13122         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13123                 return;
13124
13125         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13126         entry.tunnel_id = res->port_tag_id_val;
13127         entry.vf_id = res->vf_id;
13128         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13129                                           &entry,
13130                                           ETH_L2_TUNNEL_INSERTION_MASK,
13131                                           1);
13132 }
13133
13134 static void
13135 cmd_config_e_tag_insertion_dis_parsed(
13136         void *parsed_result,
13137         __rte_unused struct cmdline *cl,
13138         __rte_unused void *data)
13139 {
13140         struct cmd_config_e_tag_result *res =
13141                 parsed_result;
13142         struct rte_eth_l2_tunnel_conf entry;
13143
13144         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13145                 return;
13146
13147         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13148         entry.vf_id = res->vf_id;
13149
13150         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13151                                           &entry,
13152                                           ETH_L2_TUNNEL_INSERTION_MASK,
13153                                           0);
13154 }
13155
13156 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13157         .f = cmd_config_e_tag_insertion_en_parsed,
13158         .data = NULL,
13159         .help_str = "E-tag ... : E-tag insertion enable",
13160         .tokens = {
13161                 (void *)&cmd_config_e_tag_e_tag,
13162                 (void *)&cmd_config_e_tag_set,
13163                 (void *)&cmd_config_e_tag_insertion,
13164                 (void *)&cmd_config_e_tag_on,
13165                 (void *)&cmd_config_e_tag_port_tag_id,
13166                 (void *)&cmd_config_e_tag_port_tag_id_val,
13167                 (void *)&cmd_config_e_tag_port,
13168                 (void *)&cmd_config_e_tag_port_id,
13169                 (void *)&cmd_config_e_tag_vf,
13170                 (void *)&cmd_config_e_tag_vf_id,
13171                 NULL,
13172         },
13173 };
13174
13175 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13176         .f = cmd_config_e_tag_insertion_dis_parsed,
13177         .data = NULL,
13178         .help_str = "E-tag ... : E-tag insertion disable",
13179         .tokens = {
13180                 (void *)&cmd_config_e_tag_e_tag,
13181                 (void *)&cmd_config_e_tag_set,
13182                 (void *)&cmd_config_e_tag_insertion,
13183                 (void *)&cmd_config_e_tag_off,
13184                 (void *)&cmd_config_e_tag_port,
13185                 (void *)&cmd_config_e_tag_port_id,
13186                 (void *)&cmd_config_e_tag_vf,
13187                 (void *)&cmd_config_e_tag_vf_id,
13188                 NULL,
13189         },
13190 };
13191
13192 /* E-tag stripping configuration */
13193 static void
13194 cmd_config_e_tag_stripping_parsed(
13195         void *parsed_result,
13196         __rte_unused struct cmdline *cl,
13197         __rte_unused void *data)
13198 {
13199         struct cmd_config_e_tag_result *res =
13200                 parsed_result;
13201         struct rte_eth_l2_tunnel_conf entry;
13202
13203         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13204                 return;
13205
13206         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13207
13208         if (!strcmp(res->on_off, "on"))
13209                 rte_eth_dev_l2_tunnel_offload_set
13210                         (res->port_id,
13211                          &entry,
13212                          ETH_L2_TUNNEL_STRIPPING_MASK,
13213                          1);
13214         else
13215                 rte_eth_dev_l2_tunnel_offload_set
13216                         (res->port_id,
13217                          &entry,
13218                          ETH_L2_TUNNEL_STRIPPING_MASK,
13219                          0);
13220 }
13221
13222 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13223         .f = cmd_config_e_tag_stripping_parsed,
13224         .data = NULL,
13225         .help_str = "E-tag ... : E-tag stripping enable/disable",
13226         .tokens = {
13227                 (void *)&cmd_config_e_tag_e_tag,
13228                 (void *)&cmd_config_e_tag_set,
13229                 (void *)&cmd_config_e_tag_stripping,
13230                 (void *)&cmd_config_e_tag_on_off,
13231                 (void *)&cmd_config_e_tag_port,
13232                 (void *)&cmd_config_e_tag_port_id,
13233                 NULL,
13234         },
13235 };
13236
13237 /* E-tag forwarding configuration */
13238 static void
13239 cmd_config_e_tag_forwarding_parsed(
13240         void *parsed_result,
13241         __rte_unused struct cmdline *cl,
13242         __rte_unused void *data)
13243 {
13244         struct cmd_config_e_tag_result *res = parsed_result;
13245         struct rte_eth_l2_tunnel_conf entry;
13246
13247         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13248                 return;
13249
13250         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13251
13252         if (!strcmp(res->on_off, "on"))
13253                 rte_eth_dev_l2_tunnel_offload_set
13254                         (res->port_id,
13255                          &entry,
13256                          ETH_L2_TUNNEL_FORWARDING_MASK,
13257                          1);
13258         else
13259                 rte_eth_dev_l2_tunnel_offload_set
13260                         (res->port_id,
13261                          &entry,
13262                          ETH_L2_TUNNEL_FORWARDING_MASK,
13263                          0);
13264 }
13265
13266 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13267         .f = cmd_config_e_tag_forwarding_parsed,
13268         .data = NULL,
13269         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13270         .tokens = {
13271                 (void *)&cmd_config_e_tag_e_tag,
13272                 (void *)&cmd_config_e_tag_set,
13273                 (void *)&cmd_config_e_tag_forwarding,
13274                 (void *)&cmd_config_e_tag_on_off,
13275                 (void *)&cmd_config_e_tag_port,
13276                 (void *)&cmd_config_e_tag_port_id,
13277                 NULL,
13278         },
13279 };
13280
13281 /* E-tag filter configuration */
13282 static void
13283 cmd_config_e_tag_filter_add_parsed(
13284         void *parsed_result,
13285         __rte_unused struct cmdline *cl,
13286         __rte_unused void *data)
13287 {
13288         struct cmd_config_e_tag_result *res = parsed_result;
13289         struct rte_eth_l2_tunnel_conf entry;
13290         int ret = 0;
13291
13292         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13293                 return;
13294
13295         if (res->e_tag_id_val > 0x3fff) {
13296                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13297                 return;
13298         }
13299
13300         ret = rte_eth_dev_filter_supported(res->port_id,
13301                                            RTE_ETH_FILTER_L2_TUNNEL);
13302         if (ret < 0) {
13303                 printf("E-tag filter is not supported on port %u.\n",
13304                        res->port_id);
13305                 return;
13306         }
13307
13308         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13309         entry.tunnel_id = res->e_tag_id_val;
13310         entry.pool = res->dst_pool_val;
13311
13312         ret = rte_eth_dev_filter_ctrl(res->port_id,
13313                                       RTE_ETH_FILTER_L2_TUNNEL,
13314                                       RTE_ETH_FILTER_ADD,
13315                                       &entry);
13316         if (ret < 0)
13317                 printf("E-tag filter programming error: (%s)\n",
13318                        strerror(-ret));
13319 }
13320
13321 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13322         .f = cmd_config_e_tag_filter_add_parsed,
13323         .data = NULL,
13324         .help_str = "E-tag ... : E-tag filter add",
13325         .tokens = {
13326                 (void *)&cmd_config_e_tag_e_tag,
13327                 (void *)&cmd_config_e_tag_set,
13328                 (void *)&cmd_config_e_tag_filter,
13329                 (void *)&cmd_config_e_tag_add,
13330                 (void *)&cmd_config_e_tag_e_tag_id,
13331                 (void *)&cmd_config_e_tag_e_tag_id_val,
13332                 (void *)&cmd_config_e_tag_dst_pool,
13333                 (void *)&cmd_config_e_tag_dst_pool_val,
13334                 (void *)&cmd_config_e_tag_port,
13335                 (void *)&cmd_config_e_tag_port_id,
13336                 NULL,
13337         },
13338 };
13339
13340 static void
13341 cmd_config_e_tag_filter_del_parsed(
13342         void *parsed_result,
13343         __rte_unused struct cmdline *cl,
13344         __rte_unused void *data)
13345 {
13346         struct cmd_config_e_tag_result *res = parsed_result;
13347         struct rte_eth_l2_tunnel_conf entry;
13348         int ret = 0;
13349
13350         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13351                 return;
13352
13353         if (res->e_tag_id_val > 0x3fff) {
13354                 printf("e-tag-id must be less than 0x3fff.\n");
13355                 return;
13356         }
13357
13358         ret = rte_eth_dev_filter_supported(res->port_id,
13359                                            RTE_ETH_FILTER_L2_TUNNEL);
13360         if (ret < 0) {
13361                 printf("E-tag filter is not supported on port %u.\n",
13362                        res->port_id);
13363                 return;
13364         }
13365
13366         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13367         entry.tunnel_id = res->e_tag_id_val;
13368
13369         ret = rte_eth_dev_filter_ctrl(res->port_id,
13370                                       RTE_ETH_FILTER_L2_TUNNEL,
13371                                       RTE_ETH_FILTER_DELETE,
13372                                       &entry);
13373         if (ret < 0)
13374                 printf("E-tag filter programming error: (%s)\n",
13375                        strerror(-ret));
13376 }
13377
13378 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13379         .f = cmd_config_e_tag_filter_del_parsed,
13380         .data = NULL,
13381         .help_str = "E-tag ... : E-tag filter delete",
13382         .tokens = {
13383                 (void *)&cmd_config_e_tag_e_tag,
13384                 (void *)&cmd_config_e_tag_set,
13385                 (void *)&cmd_config_e_tag_filter,
13386                 (void *)&cmd_config_e_tag_del,
13387                 (void *)&cmd_config_e_tag_e_tag_id,
13388                 (void *)&cmd_config_e_tag_e_tag_id_val,
13389                 (void *)&cmd_config_e_tag_port,
13390                 (void *)&cmd_config_e_tag_port_id,
13391                 NULL,
13392         },
13393 };
13394
13395 /* vf vlan anti spoof configuration */
13396
13397 /* Common result structure for vf vlan anti spoof */
13398 struct cmd_vf_vlan_anti_spoof_result {
13399         cmdline_fixed_string_t set;
13400         cmdline_fixed_string_t vf;
13401         cmdline_fixed_string_t vlan;
13402         cmdline_fixed_string_t antispoof;
13403         portid_t port_id;
13404         uint32_t vf_id;
13405         cmdline_fixed_string_t on_off;
13406 };
13407
13408 /* Common CLI fields for vf vlan anti spoof enable disable */
13409 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13410         TOKEN_STRING_INITIALIZER
13411                 (struct cmd_vf_vlan_anti_spoof_result,
13412                  set, "set");
13413 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13414         TOKEN_STRING_INITIALIZER
13415                 (struct cmd_vf_vlan_anti_spoof_result,
13416                  vf, "vf");
13417 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13418         TOKEN_STRING_INITIALIZER
13419                 (struct cmd_vf_vlan_anti_spoof_result,
13420                  vlan, "vlan");
13421 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13422         TOKEN_STRING_INITIALIZER
13423                 (struct cmd_vf_vlan_anti_spoof_result,
13424                  antispoof, "antispoof");
13425 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13426         TOKEN_NUM_INITIALIZER
13427                 (struct cmd_vf_vlan_anti_spoof_result,
13428                  port_id, UINT16);
13429 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13430         TOKEN_NUM_INITIALIZER
13431                 (struct cmd_vf_vlan_anti_spoof_result,
13432                  vf_id, UINT32);
13433 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13434         TOKEN_STRING_INITIALIZER
13435                 (struct cmd_vf_vlan_anti_spoof_result,
13436                  on_off, "on#off");
13437
13438 static void
13439 cmd_set_vf_vlan_anti_spoof_parsed(
13440         void *parsed_result,
13441         __rte_unused struct cmdline *cl,
13442         __rte_unused void *data)
13443 {
13444         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13445         int ret = -ENOTSUP;
13446
13447         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13448
13449         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13450                 return;
13451
13452 #ifdef RTE_LIBRTE_IXGBE_PMD
13453         if (ret == -ENOTSUP)
13454                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13455                                 res->vf_id, is_on);
13456 #endif
13457 #ifdef RTE_LIBRTE_I40E_PMD
13458         if (ret == -ENOTSUP)
13459                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13460                                 res->vf_id, is_on);
13461 #endif
13462 #ifdef RTE_LIBRTE_BNXT_PMD
13463         if (ret == -ENOTSUP)
13464                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13465                                 res->vf_id, is_on);
13466 #endif
13467
13468         switch (ret) {
13469         case 0:
13470                 break;
13471         case -EINVAL:
13472                 printf("invalid vf_id %d\n", res->vf_id);
13473                 break;
13474         case -ENODEV:
13475                 printf("invalid port_id %d\n", res->port_id);
13476                 break;
13477         case -ENOTSUP:
13478                 printf("function not implemented\n");
13479                 break;
13480         default:
13481                 printf("programming error: (%s)\n", strerror(-ret));
13482         }
13483 }
13484
13485 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13486         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13487         .data = NULL,
13488         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13489         .tokens = {
13490                 (void *)&cmd_vf_vlan_anti_spoof_set,
13491                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13492                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13493                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13494                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13495                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13496                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13497                 NULL,
13498         },
13499 };
13500
13501 /* vf mac anti spoof configuration */
13502
13503 /* Common result structure for vf mac anti spoof */
13504 struct cmd_vf_mac_anti_spoof_result {
13505         cmdline_fixed_string_t set;
13506         cmdline_fixed_string_t vf;
13507         cmdline_fixed_string_t mac;
13508         cmdline_fixed_string_t antispoof;
13509         portid_t port_id;
13510         uint32_t vf_id;
13511         cmdline_fixed_string_t on_off;
13512 };
13513
13514 /* Common CLI fields for vf mac anti spoof enable disable */
13515 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13516         TOKEN_STRING_INITIALIZER
13517                 (struct cmd_vf_mac_anti_spoof_result,
13518                  set, "set");
13519 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13520         TOKEN_STRING_INITIALIZER
13521                 (struct cmd_vf_mac_anti_spoof_result,
13522                  vf, "vf");
13523 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13524         TOKEN_STRING_INITIALIZER
13525                 (struct cmd_vf_mac_anti_spoof_result,
13526                  mac, "mac");
13527 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13528         TOKEN_STRING_INITIALIZER
13529                 (struct cmd_vf_mac_anti_spoof_result,
13530                  antispoof, "antispoof");
13531 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13532         TOKEN_NUM_INITIALIZER
13533                 (struct cmd_vf_mac_anti_spoof_result,
13534                  port_id, UINT16);
13535 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13536         TOKEN_NUM_INITIALIZER
13537                 (struct cmd_vf_mac_anti_spoof_result,
13538                  vf_id, UINT32);
13539 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13540         TOKEN_STRING_INITIALIZER
13541                 (struct cmd_vf_mac_anti_spoof_result,
13542                  on_off, "on#off");
13543
13544 static void
13545 cmd_set_vf_mac_anti_spoof_parsed(
13546         void *parsed_result,
13547         __rte_unused struct cmdline *cl,
13548         __rte_unused void *data)
13549 {
13550         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13551         int ret = -ENOTSUP;
13552
13553         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13554
13555         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13556                 return;
13557
13558 #ifdef RTE_LIBRTE_IXGBE_PMD
13559         if (ret == -ENOTSUP)
13560                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13561                         res->vf_id, is_on);
13562 #endif
13563 #ifdef RTE_LIBRTE_I40E_PMD
13564         if (ret == -ENOTSUP)
13565                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13566                         res->vf_id, is_on);
13567 #endif
13568 #ifdef RTE_LIBRTE_BNXT_PMD
13569         if (ret == -ENOTSUP)
13570                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13571                         res->vf_id, is_on);
13572 #endif
13573
13574         switch (ret) {
13575         case 0:
13576                 break;
13577         case -EINVAL:
13578                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13579                 break;
13580         case -ENODEV:
13581                 printf("invalid port_id %d\n", res->port_id);
13582                 break;
13583         case -ENOTSUP:
13584                 printf("function not implemented\n");
13585                 break;
13586         default:
13587                 printf("programming error: (%s)\n", strerror(-ret));
13588         }
13589 }
13590
13591 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13592         .f = cmd_set_vf_mac_anti_spoof_parsed,
13593         .data = NULL,
13594         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13595         .tokens = {
13596                 (void *)&cmd_vf_mac_anti_spoof_set,
13597                 (void *)&cmd_vf_mac_anti_spoof_vf,
13598                 (void *)&cmd_vf_mac_anti_spoof_mac,
13599                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13600                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13601                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13602                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13603                 NULL,
13604         },
13605 };
13606
13607 /* vf vlan strip queue configuration */
13608
13609 /* Common result structure for vf mac anti spoof */
13610 struct cmd_vf_vlan_stripq_result {
13611         cmdline_fixed_string_t set;
13612         cmdline_fixed_string_t vf;
13613         cmdline_fixed_string_t vlan;
13614         cmdline_fixed_string_t stripq;
13615         portid_t port_id;
13616         uint16_t vf_id;
13617         cmdline_fixed_string_t on_off;
13618 };
13619
13620 /* Common CLI fields for vf vlan strip enable disable */
13621 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13622         TOKEN_STRING_INITIALIZER
13623                 (struct cmd_vf_vlan_stripq_result,
13624                  set, "set");
13625 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13626         TOKEN_STRING_INITIALIZER
13627                 (struct cmd_vf_vlan_stripq_result,
13628                  vf, "vf");
13629 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13630         TOKEN_STRING_INITIALIZER
13631                 (struct cmd_vf_vlan_stripq_result,
13632                  vlan, "vlan");
13633 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13634         TOKEN_STRING_INITIALIZER
13635                 (struct cmd_vf_vlan_stripq_result,
13636                  stripq, "stripq");
13637 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13638         TOKEN_NUM_INITIALIZER
13639                 (struct cmd_vf_vlan_stripq_result,
13640                  port_id, UINT16);
13641 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13642         TOKEN_NUM_INITIALIZER
13643                 (struct cmd_vf_vlan_stripq_result,
13644                  vf_id, UINT16);
13645 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13646         TOKEN_STRING_INITIALIZER
13647                 (struct cmd_vf_vlan_stripq_result,
13648                  on_off, "on#off");
13649
13650 static void
13651 cmd_set_vf_vlan_stripq_parsed(
13652         void *parsed_result,
13653         __rte_unused struct cmdline *cl,
13654         __rte_unused void *data)
13655 {
13656         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13657         int ret = -ENOTSUP;
13658
13659         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13660
13661         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13662                 return;
13663
13664 #ifdef RTE_LIBRTE_IXGBE_PMD
13665         if (ret == -ENOTSUP)
13666                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13667                         res->vf_id, is_on);
13668 #endif
13669 #ifdef RTE_LIBRTE_I40E_PMD
13670         if (ret == -ENOTSUP)
13671                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13672                         res->vf_id, is_on);
13673 #endif
13674 #ifdef RTE_LIBRTE_BNXT_PMD
13675         if (ret == -ENOTSUP)
13676                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13677                         res->vf_id, is_on);
13678 #endif
13679
13680         switch (ret) {
13681         case 0:
13682                 break;
13683         case -EINVAL:
13684                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13685                 break;
13686         case -ENODEV:
13687                 printf("invalid port_id %d\n", res->port_id);
13688                 break;
13689         case -ENOTSUP:
13690                 printf("function not implemented\n");
13691                 break;
13692         default:
13693                 printf("programming error: (%s)\n", strerror(-ret));
13694         }
13695 }
13696
13697 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13698         .f = cmd_set_vf_vlan_stripq_parsed,
13699         .data = NULL,
13700         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13701         .tokens = {
13702                 (void *)&cmd_vf_vlan_stripq_set,
13703                 (void *)&cmd_vf_vlan_stripq_vf,
13704                 (void *)&cmd_vf_vlan_stripq_vlan,
13705                 (void *)&cmd_vf_vlan_stripq_stripq,
13706                 (void *)&cmd_vf_vlan_stripq_port_id,
13707                 (void *)&cmd_vf_vlan_stripq_vf_id,
13708                 (void *)&cmd_vf_vlan_stripq_on_off,
13709                 NULL,
13710         },
13711 };
13712
13713 /* vf vlan insert configuration */
13714
13715 /* Common result structure for vf vlan insert */
13716 struct cmd_vf_vlan_insert_result {
13717         cmdline_fixed_string_t set;
13718         cmdline_fixed_string_t vf;
13719         cmdline_fixed_string_t vlan;
13720         cmdline_fixed_string_t insert;
13721         portid_t port_id;
13722         uint16_t vf_id;
13723         uint16_t vlan_id;
13724 };
13725
13726 /* Common CLI fields for vf vlan insert enable disable */
13727 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13728         TOKEN_STRING_INITIALIZER
13729                 (struct cmd_vf_vlan_insert_result,
13730                  set, "set");
13731 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13732         TOKEN_STRING_INITIALIZER
13733                 (struct cmd_vf_vlan_insert_result,
13734                  vf, "vf");
13735 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13736         TOKEN_STRING_INITIALIZER
13737                 (struct cmd_vf_vlan_insert_result,
13738                  vlan, "vlan");
13739 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13740         TOKEN_STRING_INITIALIZER
13741                 (struct cmd_vf_vlan_insert_result,
13742                  insert, "insert");
13743 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13744         TOKEN_NUM_INITIALIZER
13745                 (struct cmd_vf_vlan_insert_result,
13746                  port_id, UINT16);
13747 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13748         TOKEN_NUM_INITIALIZER
13749                 (struct cmd_vf_vlan_insert_result,
13750                  vf_id, UINT16);
13751 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13752         TOKEN_NUM_INITIALIZER
13753                 (struct cmd_vf_vlan_insert_result,
13754                  vlan_id, UINT16);
13755
13756 static void
13757 cmd_set_vf_vlan_insert_parsed(
13758         void *parsed_result,
13759         __rte_unused struct cmdline *cl,
13760         __rte_unused void *data)
13761 {
13762         struct cmd_vf_vlan_insert_result *res = parsed_result;
13763         int ret = -ENOTSUP;
13764
13765         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13766                 return;
13767
13768 #ifdef RTE_LIBRTE_IXGBE_PMD
13769         if (ret == -ENOTSUP)
13770                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13771                         res->vlan_id);
13772 #endif
13773 #ifdef RTE_LIBRTE_I40E_PMD
13774         if (ret == -ENOTSUP)
13775                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13776                         res->vlan_id);
13777 #endif
13778 #ifdef RTE_LIBRTE_BNXT_PMD
13779         if (ret == -ENOTSUP)
13780                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13781                         res->vlan_id);
13782 #endif
13783
13784         switch (ret) {
13785         case 0:
13786                 break;
13787         case -EINVAL:
13788                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13789                 break;
13790         case -ENODEV:
13791                 printf("invalid port_id %d\n", res->port_id);
13792                 break;
13793         case -ENOTSUP:
13794                 printf("function not implemented\n");
13795                 break;
13796         default:
13797                 printf("programming error: (%s)\n", strerror(-ret));
13798         }
13799 }
13800
13801 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13802         .f = cmd_set_vf_vlan_insert_parsed,
13803         .data = NULL,
13804         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13805         .tokens = {
13806                 (void *)&cmd_vf_vlan_insert_set,
13807                 (void *)&cmd_vf_vlan_insert_vf,
13808                 (void *)&cmd_vf_vlan_insert_vlan,
13809                 (void *)&cmd_vf_vlan_insert_insert,
13810                 (void *)&cmd_vf_vlan_insert_port_id,
13811                 (void *)&cmd_vf_vlan_insert_vf_id,
13812                 (void *)&cmd_vf_vlan_insert_vlan_id,
13813                 NULL,
13814         },
13815 };
13816
13817 /* tx loopback configuration */
13818
13819 /* Common result structure for tx loopback */
13820 struct cmd_tx_loopback_result {
13821         cmdline_fixed_string_t set;
13822         cmdline_fixed_string_t tx;
13823         cmdline_fixed_string_t loopback;
13824         portid_t port_id;
13825         cmdline_fixed_string_t on_off;
13826 };
13827
13828 /* Common CLI fields for tx loopback enable disable */
13829 cmdline_parse_token_string_t cmd_tx_loopback_set =
13830         TOKEN_STRING_INITIALIZER
13831                 (struct cmd_tx_loopback_result,
13832                  set, "set");
13833 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13834         TOKEN_STRING_INITIALIZER
13835                 (struct cmd_tx_loopback_result,
13836                  tx, "tx");
13837 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13838         TOKEN_STRING_INITIALIZER
13839                 (struct cmd_tx_loopback_result,
13840                  loopback, "loopback");
13841 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13842         TOKEN_NUM_INITIALIZER
13843                 (struct cmd_tx_loopback_result,
13844                  port_id, UINT16);
13845 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13846         TOKEN_STRING_INITIALIZER
13847                 (struct cmd_tx_loopback_result,
13848                  on_off, "on#off");
13849
13850 static void
13851 cmd_set_tx_loopback_parsed(
13852         void *parsed_result,
13853         __rte_unused struct cmdline *cl,
13854         __rte_unused void *data)
13855 {
13856         struct cmd_tx_loopback_result *res = parsed_result;
13857         int ret = -ENOTSUP;
13858
13859         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13860
13861         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13862                 return;
13863
13864 #ifdef RTE_LIBRTE_IXGBE_PMD
13865         if (ret == -ENOTSUP)
13866                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13867 #endif
13868 #ifdef RTE_LIBRTE_I40E_PMD
13869         if (ret == -ENOTSUP)
13870                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13871 #endif
13872 #ifdef RTE_LIBRTE_BNXT_PMD
13873         if (ret == -ENOTSUP)
13874                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13875 #endif
13876 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13877         if (ret == -ENOTSUP)
13878                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13879 #endif
13880
13881         switch (ret) {
13882         case 0:
13883                 break;
13884         case -EINVAL:
13885                 printf("invalid is_on %d\n", is_on);
13886                 break;
13887         case -ENODEV:
13888                 printf("invalid port_id %d\n", res->port_id);
13889                 break;
13890         case -ENOTSUP:
13891                 printf("function not implemented\n");
13892                 break;
13893         default:
13894                 printf("programming error: (%s)\n", strerror(-ret));
13895         }
13896 }
13897
13898 cmdline_parse_inst_t cmd_set_tx_loopback = {
13899         .f = cmd_set_tx_loopback_parsed,
13900         .data = NULL,
13901         .help_str = "set tx loopback <port_id> on|off",
13902         .tokens = {
13903                 (void *)&cmd_tx_loopback_set,
13904                 (void *)&cmd_tx_loopback_tx,
13905                 (void *)&cmd_tx_loopback_loopback,
13906                 (void *)&cmd_tx_loopback_port_id,
13907                 (void *)&cmd_tx_loopback_on_off,
13908                 NULL,
13909         },
13910 };
13911
13912 /* all queues drop enable configuration */
13913
13914 /* Common result structure for all queues drop enable */
13915 struct cmd_all_queues_drop_en_result {
13916         cmdline_fixed_string_t set;
13917         cmdline_fixed_string_t all;
13918         cmdline_fixed_string_t queues;
13919         cmdline_fixed_string_t drop;
13920         portid_t port_id;
13921         cmdline_fixed_string_t on_off;
13922 };
13923
13924 /* Common CLI fields for tx loopback enable disable */
13925 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13926         TOKEN_STRING_INITIALIZER
13927                 (struct cmd_all_queues_drop_en_result,
13928                  set, "set");
13929 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13930         TOKEN_STRING_INITIALIZER
13931                 (struct cmd_all_queues_drop_en_result,
13932                  all, "all");
13933 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13934         TOKEN_STRING_INITIALIZER
13935                 (struct cmd_all_queues_drop_en_result,
13936                  queues, "queues");
13937 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13938         TOKEN_STRING_INITIALIZER
13939                 (struct cmd_all_queues_drop_en_result,
13940                  drop, "drop");
13941 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13942         TOKEN_NUM_INITIALIZER
13943                 (struct cmd_all_queues_drop_en_result,
13944                  port_id, UINT16);
13945 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13946         TOKEN_STRING_INITIALIZER
13947                 (struct cmd_all_queues_drop_en_result,
13948                  on_off, "on#off");
13949
13950 static void
13951 cmd_set_all_queues_drop_en_parsed(
13952         void *parsed_result,
13953         __rte_unused struct cmdline *cl,
13954         __rte_unused void *data)
13955 {
13956         struct cmd_all_queues_drop_en_result *res = parsed_result;
13957         int ret = -ENOTSUP;
13958         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13959
13960         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13961                 return;
13962
13963 #ifdef RTE_LIBRTE_IXGBE_PMD
13964         if (ret == -ENOTSUP)
13965                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13966 #endif
13967 #ifdef RTE_LIBRTE_BNXT_PMD
13968         if (ret == -ENOTSUP)
13969                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13970 #endif
13971         switch (ret) {
13972         case 0:
13973                 break;
13974         case -EINVAL:
13975                 printf("invalid is_on %d\n", is_on);
13976                 break;
13977         case -ENODEV:
13978                 printf("invalid port_id %d\n", res->port_id);
13979                 break;
13980         case -ENOTSUP:
13981                 printf("function not implemented\n");
13982                 break;
13983         default:
13984                 printf("programming error: (%s)\n", strerror(-ret));
13985         }
13986 }
13987
13988 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
13989         .f = cmd_set_all_queues_drop_en_parsed,
13990         .data = NULL,
13991         .help_str = "set all queues drop <port_id> on|off",
13992         .tokens = {
13993                 (void *)&cmd_all_queues_drop_en_set,
13994                 (void *)&cmd_all_queues_drop_en_all,
13995                 (void *)&cmd_all_queues_drop_en_queues,
13996                 (void *)&cmd_all_queues_drop_en_drop,
13997                 (void *)&cmd_all_queues_drop_en_port_id,
13998                 (void *)&cmd_all_queues_drop_en_on_off,
13999                 NULL,
14000         },
14001 };
14002
14003 /* vf split drop enable configuration */
14004
14005 /* Common result structure for vf split drop enable */
14006 struct cmd_vf_split_drop_en_result {
14007         cmdline_fixed_string_t set;
14008         cmdline_fixed_string_t vf;
14009         cmdline_fixed_string_t split;
14010         cmdline_fixed_string_t drop;
14011         portid_t port_id;
14012         uint16_t vf_id;
14013         cmdline_fixed_string_t on_off;
14014 };
14015
14016 /* Common CLI fields for vf split drop enable disable */
14017 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14018         TOKEN_STRING_INITIALIZER
14019                 (struct cmd_vf_split_drop_en_result,
14020                  set, "set");
14021 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14022         TOKEN_STRING_INITIALIZER
14023                 (struct cmd_vf_split_drop_en_result,
14024                  vf, "vf");
14025 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14026         TOKEN_STRING_INITIALIZER
14027                 (struct cmd_vf_split_drop_en_result,
14028                  split, "split");
14029 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14030         TOKEN_STRING_INITIALIZER
14031                 (struct cmd_vf_split_drop_en_result,
14032                  drop, "drop");
14033 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14034         TOKEN_NUM_INITIALIZER
14035                 (struct cmd_vf_split_drop_en_result,
14036                  port_id, UINT16);
14037 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14038         TOKEN_NUM_INITIALIZER
14039                 (struct cmd_vf_split_drop_en_result,
14040                  vf_id, UINT16);
14041 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14042         TOKEN_STRING_INITIALIZER
14043                 (struct cmd_vf_split_drop_en_result,
14044                  on_off, "on#off");
14045
14046 static void
14047 cmd_set_vf_split_drop_en_parsed(
14048         void *parsed_result,
14049         __rte_unused struct cmdline *cl,
14050         __rte_unused void *data)
14051 {
14052         struct cmd_vf_split_drop_en_result *res = parsed_result;
14053         int ret = -ENOTSUP;
14054         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14055
14056         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14057                 return;
14058
14059 #ifdef RTE_LIBRTE_IXGBE_PMD
14060         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14061                         is_on);
14062 #endif
14063         switch (ret) {
14064         case 0:
14065                 break;
14066         case -EINVAL:
14067                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14068                 break;
14069         case -ENODEV:
14070                 printf("invalid port_id %d\n", res->port_id);
14071                 break;
14072         case -ENOTSUP:
14073                 printf("not supported on port %d\n", res->port_id);
14074                 break;
14075         default:
14076                 printf("programming error: (%s)\n", strerror(-ret));
14077         }
14078 }
14079
14080 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14081         .f = cmd_set_vf_split_drop_en_parsed,
14082         .data = NULL,
14083         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14084         .tokens = {
14085                 (void *)&cmd_vf_split_drop_en_set,
14086                 (void *)&cmd_vf_split_drop_en_vf,
14087                 (void *)&cmd_vf_split_drop_en_split,
14088                 (void *)&cmd_vf_split_drop_en_drop,
14089                 (void *)&cmd_vf_split_drop_en_port_id,
14090                 (void *)&cmd_vf_split_drop_en_vf_id,
14091                 (void *)&cmd_vf_split_drop_en_on_off,
14092                 NULL,
14093         },
14094 };
14095
14096 /* vf mac address configuration */
14097
14098 /* Common result structure for vf mac address */
14099 struct cmd_set_vf_mac_addr_result {
14100         cmdline_fixed_string_t set;
14101         cmdline_fixed_string_t vf;
14102         cmdline_fixed_string_t mac;
14103         cmdline_fixed_string_t addr;
14104         portid_t port_id;
14105         uint16_t vf_id;
14106         struct rte_ether_addr mac_addr;
14107
14108 };
14109
14110 /* Common CLI fields for vf split drop enable disable */
14111 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14112         TOKEN_STRING_INITIALIZER
14113                 (struct cmd_set_vf_mac_addr_result,
14114                  set, "set");
14115 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14116         TOKEN_STRING_INITIALIZER
14117                 (struct cmd_set_vf_mac_addr_result,
14118                  vf, "vf");
14119 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14120         TOKEN_STRING_INITIALIZER
14121                 (struct cmd_set_vf_mac_addr_result,
14122                  mac, "mac");
14123 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14124         TOKEN_STRING_INITIALIZER
14125                 (struct cmd_set_vf_mac_addr_result,
14126                  addr, "addr");
14127 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14128         TOKEN_NUM_INITIALIZER
14129                 (struct cmd_set_vf_mac_addr_result,
14130                  port_id, UINT16);
14131 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14132         TOKEN_NUM_INITIALIZER
14133                 (struct cmd_set_vf_mac_addr_result,
14134                  vf_id, UINT16);
14135 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14136         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14137                  mac_addr);
14138
14139 static void
14140 cmd_set_vf_mac_addr_parsed(
14141         void *parsed_result,
14142         __rte_unused struct cmdline *cl,
14143         __rte_unused void *data)
14144 {
14145         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14146         int ret = -ENOTSUP;
14147
14148         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14149                 return;
14150
14151 #ifdef RTE_LIBRTE_IXGBE_PMD
14152         if (ret == -ENOTSUP)
14153                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14154                                 &res->mac_addr);
14155 #endif
14156 #ifdef RTE_LIBRTE_I40E_PMD
14157         if (ret == -ENOTSUP)
14158                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14159                                 &res->mac_addr);
14160 #endif
14161 #ifdef RTE_LIBRTE_BNXT_PMD
14162         if (ret == -ENOTSUP)
14163                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14164                                 &res->mac_addr);
14165 #endif
14166
14167         switch (ret) {
14168         case 0:
14169                 break;
14170         case -EINVAL:
14171                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14172                 break;
14173         case -ENODEV:
14174                 printf("invalid port_id %d\n", res->port_id);
14175                 break;
14176         case -ENOTSUP:
14177                 printf("function not implemented\n");
14178                 break;
14179         default:
14180                 printf("programming error: (%s)\n", strerror(-ret));
14181         }
14182 }
14183
14184 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14185         .f = cmd_set_vf_mac_addr_parsed,
14186         .data = NULL,
14187         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14188         .tokens = {
14189                 (void *)&cmd_set_vf_mac_addr_set,
14190                 (void *)&cmd_set_vf_mac_addr_vf,
14191                 (void *)&cmd_set_vf_mac_addr_mac,
14192                 (void *)&cmd_set_vf_mac_addr_addr,
14193                 (void *)&cmd_set_vf_mac_addr_port_id,
14194                 (void *)&cmd_set_vf_mac_addr_vf_id,
14195                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14196                 NULL,
14197         },
14198 };
14199
14200 /* MACsec configuration */
14201
14202 /* Common result structure for MACsec offload enable */
14203 struct cmd_macsec_offload_on_result {
14204         cmdline_fixed_string_t set;
14205         cmdline_fixed_string_t macsec;
14206         cmdline_fixed_string_t offload;
14207         portid_t port_id;
14208         cmdline_fixed_string_t on;
14209         cmdline_fixed_string_t encrypt;
14210         cmdline_fixed_string_t en_on_off;
14211         cmdline_fixed_string_t replay_protect;
14212         cmdline_fixed_string_t rp_on_off;
14213 };
14214
14215 /* Common CLI fields for MACsec offload disable */
14216 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14217         TOKEN_STRING_INITIALIZER
14218                 (struct cmd_macsec_offload_on_result,
14219                  set, "set");
14220 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14221         TOKEN_STRING_INITIALIZER
14222                 (struct cmd_macsec_offload_on_result,
14223                  macsec, "macsec");
14224 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14225         TOKEN_STRING_INITIALIZER
14226                 (struct cmd_macsec_offload_on_result,
14227                  offload, "offload");
14228 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14229         TOKEN_NUM_INITIALIZER
14230                 (struct cmd_macsec_offload_on_result,
14231                  port_id, UINT16);
14232 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14233         TOKEN_STRING_INITIALIZER
14234                 (struct cmd_macsec_offload_on_result,
14235                  on, "on");
14236 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14237         TOKEN_STRING_INITIALIZER
14238                 (struct cmd_macsec_offload_on_result,
14239                  encrypt, "encrypt");
14240 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14241         TOKEN_STRING_INITIALIZER
14242                 (struct cmd_macsec_offload_on_result,
14243                  en_on_off, "on#off");
14244 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14245         TOKEN_STRING_INITIALIZER
14246                 (struct cmd_macsec_offload_on_result,
14247                  replay_protect, "replay-protect");
14248 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14249         TOKEN_STRING_INITIALIZER
14250                 (struct cmd_macsec_offload_on_result,
14251                  rp_on_off, "on#off");
14252
14253 static void
14254 cmd_set_macsec_offload_on_parsed(
14255         void *parsed_result,
14256         __rte_unused struct cmdline *cl,
14257         __rte_unused void *data)
14258 {
14259         struct cmd_macsec_offload_on_result *res = parsed_result;
14260         int ret = -ENOTSUP;
14261         portid_t port_id = res->port_id;
14262         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14263         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14264         struct rte_eth_dev_info dev_info;
14265
14266         if (port_id_is_invalid(port_id, ENABLED_WARN))
14267                 return;
14268         if (!port_is_stopped(port_id)) {
14269                 printf("Please stop port %d first\n", port_id);
14270                 return;
14271         }
14272
14273         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14274         if (ret != 0)
14275                 return;
14276
14277         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14278 #ifdef RTE_LIBRTE_IXGBE_PMD
14279                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14280 #endif
14281         }
14282         RTE_SET_USED(en);
14283         RTE_SET_USED(rp);
14284
14285         switch (ret) {
14286         case 0:
14287                 ports[port_id].dev_conf.txmode.offloads |=
14288                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14289                 cmd_reconfig_device_queue(port_id, 1, 1);
14290                 break;
14291         case -ENODEV:
14292                 printf("invalid port_id %d\n", port_id);
14293                 break;
14294         case -ENOTSUP:
14295                 printf("not supported on port %d\n", port_id);
14296                 break;
14297         default:
14298                 printf("programming error: (%s)\n", strerror(-ret));
14299         }
14300 }
14301
14302 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14303         .f = cmd_set_macsec_offload_on_parsed,
14304         .data = NULL,
14305         .help_str = "set macsec offload <port_id> on "
14306                 "encrypt on|off replay-protect on|off",
14307         .tokens = {
14308                 (void *)&cmd_macsec_offload_on_set,
14309                 (void *)&cmd_macsec_offload_on_macsec,
14310                 (void *)&cmd_macsec_offload_on_offload,
14311                 (void *)&cmd_macsec_offload_on_port_id,
14312                 (void *)&cmd_macsec_offload_on_on,
14313                 (void *)&cmd_macsec_offload_on_encrypt,
14314                 (void *)&cmd_macsec_offload_on_en_on_off,
14315                 (void *)&cmd_macsec_offload_on_replay_protect,
14316                 (void *)&cmd_macsec_offload_on_rp_on_off,
14317                 NULL,
14318         },
14319 };
14320
14321 /* Common result structure for MACsec offload disable */
14322 struct cmd_macsec_offload_off_result {
14323         cmdline_fixed_string_t set;
14324         cmdline_fixed_string_t macsec;
14325         cmdline_fixed_string_t offload;
14326         portid_t port_id;
14327         cmdline_fixed_string_t off;
14328 };
14329
14330 /* Common CLI fields for MACsec offload disable */
14331 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14332         TOKEN_STRING_INITIALIZER
14333                 (struct cmd_macsec_offload_off_result,
14334                  set, "set");
14335 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14336         TOKEN_STRING_INITIALIZER
14337                 (struct cmd_macsec_offload_off_result,
14338                  macsec, "macsec");
14339 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14340         TOKEN_STRING_INITIALIZER
14341                 (struct cmd_macsec_offload_off_result,
14342                  offload, "offload");
14343 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14344         TOKEN_NUM_INITIALIZER
14345                 (struct cmd_macsec_offload_off_result,
14346                  port_id, UINT16);
14347 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14348         TOKEN_STRING_INITIALIZER
14349                 (struct cmd_macsec_offload_off_result,
14350                  off, "off");
14351
14352 static void
14353 cmd_set_macsec_offload_off_parsed(
14354         void *parsed_result,
14355         __rte_unused struct cmdline *cl,
14356         __rte_unused void *data)
14357 {
14358         struct cmd_macsec_offload_off_result *res = parsed_result;
14359         int ret = -ENOTSUP;
14360         struct rte_eth_dev_info dev_info;
14361         portid_t port_id = res->port_id;
14362
14363         if (port_id_is_invalid(port_id, ENABLED_WARN))
14364                 return;
14365         if (!port_is_stopped(port_id)) {
14366                 printf("Please stop port %d first\n", port_id);
14367                 return;
14368         }
14369
14370         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14371         if (ret != 0)
14372                 return;
14373
14374         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14375 #ifdef RTE_LIBRTE_IXGBE_PMD
14376                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14377 #endif
14378         }
14379         switch (ret) {
14380         case 0:
14381                 ports[port_id].dev_conf.txmode.offloads &=
14382                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14383                 cmd_reconfig_device_queue(port_id, 1, 1);
14384                 break;
14385         case -ENODEV:
14386                 printf("invalid port_id %d\n", port_id);
14387                 break;
14388         case -ENOTSUP:
14389                 printf("not supported on port %d\n", port_id);
14390                 break;
14391         default:
14392                 printf("programming error: (%s)\n", strerror(-ret));
14393         }
14394 }
14395
14396 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14397         .f = cmd_set_macsec_offload_off_parsed,
14398         .data = NULL,
14399         .help_str = "set macsec offload <port_id> off",
14400         .tokens = {
14401                 (void *)&cmd_macsec_offload_off_set,
14402                 (void *)&cmd_macsec_offload_off_macsec,
14403                 (void *)&cmd_macsec_offload_off_offload,
14404                 (void *)&cmd_macsec_offload_off_port_id,
14405                 (void *)&cmd_macsec_offload_off_off,
14406                 NULL,
14407         },
14408 };
14409
14410 /* Common result structure for MACsec secure connection configure */
14411 struct cmd_macsec_sc_result {
14412         cmdline_fixed_string_t set;
14413         cmdline_fixed_string_t macsec;
14414         cmdline_fixed_string_t sc;
14415         cmdline_fixed_string_t tx_rx;
14416         portid_t port_id;
14417         struct rte_ether_addr mac;
14418         uint16_t pi;
14419 };
14420
14421 /* Common CLI fields for MACsec secure connection configure */
14422 cmdline_parse_token_string_t cmd_macsec_sc_set =
14423         TOKEN_STRING_INITIALIZER
14424                 (struct cmd_macsec_sc_result,
14425                  set, "set");
14426 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14427         TOKEN_STRING_INITIALIZER
14428                 (struct cmd_macsec_sc_result,
14429                  macsec, "macsec");
14430 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14431         TOKEN_STRING_INITIALIZER
14432                 (struct cmd_macsec_sc_result,
14433                  sc, "sc");
14434 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14435         TOKEN_STRING_INITIALIZER
14436                 (struct cmd_macsec_sc_result,
14437                  tx_rx, "tx#rx");
14438 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14439         TOKEN_NUM_INITIALIZER
14440                 (struct cmd_macsec_sc_result,
14441                  port_id, UINT16);
14442 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14443         TOKEN_ETHERADDR_INITIALIZER
14444                 (struct cmd_macsec_sc_result,
14445                  mac);
14446 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14447         TOKEN_NUM_INITIALIZER
14448                 (struct cmd_macsec_sc_result,
14449                  pi, UINT16);
14450
14451 static void
14452 cmd_set_macsec_sc_parsed(
14453         void *parsed_result,
14454         __rte_unused struct cmdline *cl,
14455         __rte_unused void *data)
14456 {
14457         struct cmd_macsec_sc_result *res = parsed_result;
14458         int ret = -ENOTSUP;
14459         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14460
14461 #ifdef RTE_LIBRTE_IXGBE_PMD
14462         ret = is_tx ?
14463                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14464                                 res->mac.addr_bytes) :
14465                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14466                                 res->mac.addr_bytes, res->pi);
14467 #endif
14468         RTE_SET_USED(is_tx);
14469
14470         switch (ret) {
14471         case 0:
14472                 break;
14473         case -ENODEV:
14474                 printf("invalid port_id %d\n", res->port_id);
14475                 break;
14476         case -ENOTSUP:
14477                 printf("not supported on port %d\n", res->port_id);
14478                 break;
14479         default:
14480                 printf("programming error: (%s)\n", strerror(-ret));
14481         }
14482 }
14483
14484 cmdline_parse_inst_t cmd_set_macsec_sc = {
14485         .f = cmd_set_macsec_sc_parsed,
14486         .data = NULL,
14487         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14488         .tokens = {
14489                 (void *)&cmd_macsec_sc_set,
14490                 (void *)&cmd_macsec_sc_macsec,
14491                 (void *)&cmd_macsec_sc_sc,
14492                 (void *)&cmd_macsec_sc_tx_rx,
14493                 (void *)&cmd_macsec_sc_port_id,
14494                 (void *)&cmd_macsec_sc_mac,
14495                 (void *)&cmd_macsec_sc_pi,
14496                 NULL,
14497         },
14498 };
14499
14500 /* Common result structure for MACsec secure connection configure */
14501 struct cmd_macsec_sa_result {
14502         cmdline_fixed_string_t set;
14503         cmdline_fixed_string_t macsec;
14504         cmdline_fixed_string_t sa;
14505         cmdline_fixed_string_t tx_rx;
14506         portid_t port_id;
14507         uint8_t idx;
14508         uint8_t an;
14509         uint32_t pn;
14510         cmdline_fixed_string_t key;
14511 };
14512
14513 /* Common CLI fields for MACsec secure connection configure */
14514 cmdline_parse_token_string_t cmd_macsec_sa_set =
14515         TOKEN_STRING_INITIALIZER
14516                 (struct cmd_macsec_sa_result,
14517                  set, "set");
14518 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14519         TOKEN_STRING_INITIALIZER
14520                 (struct cmd_macsec_sa_result,
14521                  macsec, "macsec");
14522 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14523         TOKEN_STRING_INITIALIZER
14524                 (struct cmd_macsec_sa_result,
14525                  sa, "sa");
14526 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14527         TOKEN_STRING_INITIALIZER
14528                 (struct cmd_macsec_sa_result,
14529                  tx_rx, "tx#rx");
14530 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14531         TOKEN_NUM_INITIALIZER
14532                 (struct cmd_macsec_sa_result,
14533                  port_id, UINT16);
14534 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14535         TOKEN_NUM_INITIALIZER
14536                 (struct cmd_macsec_sa_result,
14537                  idx, UINT8);
14538 cmdline_parse_token_num_t cmd_macsec_sa_an =
14539         TOKEN_NUM_INITIALIZER
14540                 (struct cmd_macsec_sa_result,
14541                  an, UINT8);
14542 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14543         TOKEN_NUM_INITIALIZER
14544                 (struct cmd_macsec_sa_result,
14545                  pn, UINT32);
14546 cmdline_parse_token_string_t cmd_macsec_sa_key =
14547         TOKEN_STRING_INITIALIZER
14548                 (struct cmd_macsec_sa_result,
14549                  key, NULL);
14550
14551 static void
14552 cmd_set_macsec_sa_parsed(
14553         void *parsed_result,
14554         __rte_unused struct cmdline *cl,
14555         __rte_unused void *data)
14556 {
14557         struct cmd_macsec_sa_result *res = parsed_result;
14558         int ret = -ENOTSUP;
14559         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14560         uint8_t key[16] = { 0 };
14561         uint8_t xdgt0;
14562         uint8_t xdgt1;
14563         int key_len;
14564         int i;
14565
14566         key_len = strlen(res->key) / 2;
14567         if (key_len > 16)
14568                 key_len = 16;
14569
14570         for (i = 0; i < key_len; i++) {
14571                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14572                 if (xdgt0 == 0xFF)
14573                         return;
14574                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14575                 if (xdgt1 == 0xFF)
14576                         return;
14577                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14578         }
14579
14580 #ifdef RTE_LIBRTE_IXGBE_PMD
14581         ret = is_tx ?
14582                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14583                         res->idx, res->an, res->pn, key) :
14584                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14585                         res->idx, res->an, res->pn, key);
14586 #endif
14587         RTE_SET_USED(is_tx);
14588         RTE_SET_USED(key);
14589
14590         switch (ret) {
14591         case 0:
14592                 break;
14593         case -EINVAL:
14594                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14595                 break;
14596         case -ENODEV:
14597                 printf("invalid port_id %d\n", res->port_id);
14598                 break;
14599         case -ENOTSUP:
14600                 printf("not supported on port %d\n", res->port_id);
14601                 break;
14602         default:
14603                 printf("programming error: (%s)\n", strerror(-ret));
14604         }
14605 }
14606
14607 cmdline_parse_inst_t cmd_set_macsec_sa = {
14608         .f = cmd_set_macsec_sa_parsed,
14609         .data = NULL,
14610         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14611         .tokens = {
14612                 (void *)&cmd_macsec_sa_set,
14613                 (void *)&cmd_macsec_sa_macsec,
14614                 (void *)&cmd_macsec_sa_sa,
14615                 (void *)&cmd_macsec_sa_tx_rx,
14616                 (void *)&cmd_macsec_sa_port_id,
14617                 (void *)&cmd_macsec_sa_idx,
14618                 (void *)&cmd_macsec_sa_an,
14619                 (void *)&cmd_macsec_sa_pn,
14620                 (void *)&cmd_macsec_sa_key,
14621                 NULL,
14622         },
14623 };
14624
14625 /* VF unicast promiscuous mode configuration */
14626
14627 /* Common result structure for VF unicast promiscuous mode */
14628 struct cmd_vf_promisc_result {
14629         cmdline_fixed_string_t set;
14630         cmdline_fixed_string_t vf;
14631         cmdline_fixed_string_t promisc;
14632         portid_t port_id;
14633         uint32_t vf_id;
14634         cmdline_fixed_string_t on_off;
14635 };
14636
14637 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14638 cmdline_parse_token_string_t cmd_vf_promisc_set =
14639         TOKEN_STRING_INITIALIZER
14640                 (struct cmd_vf_promisc_result,
14641                  set, "set");
14642 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14643         TOKEN_STRING_INITIALIZER
14644                 (struct cmd_vf_promisc_result,
14645                  vf, "vf");
14646 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14647         TOKEN_STRING_INITIALIZER
14648                 (struct cmd_vf_promisc_result,
14649                  promisc, "promisc");
14650 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14651         TOKEN_NUM_INITIALIZER
14652                 (struct cmd_vf_promisc_result,
14653                  port_id, UINT16);
14654 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14655         TOKEN_NUM_INITIALIZER
14656                 (struct cmd_vf_promisc_result,
14657                  vf_id, UINT32);
14658 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14659         TOKEN_STRING_INITIALIZER
14660                 (struct cmd_vf_promisc_result,
14661                  on_off, "on#off");
14662
14663 static void
14664 cmd_set_vf_promisc_parsed(
14665         void *parsed_result,
14666         __rte_unused struct cmdline *cl,
14667         __rte_unused void *data)
14668 {
14669         struct cmd_vf_promisc_result *res = parsed_result;
14670         int ret = -ENOTSUP;
14671
14672         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14673
14674         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14675                 return;
14676
14677 #ifdef RTE_LIBRTE_I40E_PMD
14678         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14679                                                   res->vf_id, is_on);
14680 #endif
14681
14682         switch (ret) {
14683         case 0:
14684                 break;
14685         case -EINVAL:
14686                 printf("invalid vf_id %d\n", res->vf_id);
14687                 break;
14688         case -ENODEV:
14689                 printf("invalid port_id %d\n", res->port_id);
14690                 break;
14691         case -ENOTSUP:
14692                 printf("function not implemented\n");
14693                 break;
14694         default:
14695                 printf("programming error: (%s)\n", strerror(-ret));
14696         }
14697 }
14698
14699 cmdline_parse_inst_t cmd_set_vf_promisc = {
14700         .f = cmd_set_vf_promisc_parsed,
14701         .data = NULL,
14702         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14703                 "Set unicast promiscuous mode for a VF from the PF",
14704         .tokens = {
14705                 (void *)&cmd_vf_promisc_set,
14706                 (void *)&cmd_vf_promisc_vf,
14707                 (void *)&cmd_vf_promisc_promisc,
14708                 (void *)&cmd_vf_promisc_port_id,
14709                 (void *)&cmd_vf_promisc_vf_id,
14710                 (void *)&cmd_vf_promisc_on_off,
14711                 NULL,
14712         },
14713 };
14714
14715 /* VF multicast promiscuous mode configuration */
14716
14717 /* Common result structure for VF multicast promiscuous mode */
14718 struct cmd_vf_allmulti_result {
14719         cmdline_fixed_string_t set;
14720         cmdline_fixed_string_t vf;
14721         cmdline_fixed_string_t allmulti;
14722         portid_t port_id;
14723         uint32_t vf_id;
14724         cmdline_fixed_string_t on_off;
14725 };
14726
14727 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14728 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14729         TOKEN_STRING_INITIALIZER
14730                 (struct cmd_vf_allmulti_result,
14731                  set, "set");
14732 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14733         TOKEN_STRING_INITIALIZER
14734                 (struct cmd_vf_allmulti_result,
14735                  vf, "vf");
14736 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14737         TOKEN_STRING_INITIALIZER
14738                 (struct cmd_vf_allmulti_result,
14739                  allmulti, "allmulti");
14740 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14741         TOKEN_NUM_INITIALIZER
14742                 (struct cmd_vf_allmulti_result,
14743                  port_id, UINT16);
14744 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14745         TOKEN_NUM_INITIALIZER
14746                 (struct cmd_vf_allmulti_result,
14747                  vf_id, UINT32);
14748 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14749         TOKEN_STRING_INITIALIZER
14750                 (struct cmd_vf_allmulti_result,
14751                  on_off, "on#off");
14752
14753 static void
14754 cmd_set_vf_allmulti_parsed(
14755         void *parsed_result,
14756         __rte_unused struct cmdline *cl,
14757         __rte_unused void *data)
14758 {
14759         struct cmd_vf_allmulti_result *res = parsed_result;
14760         int ret = -ENOTSUP;
14761
14762         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14763
14764         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14765                 return;
14766
14767 #ifdef RTE_LIBRTE_I40E_PMD
14768         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14769                                                     res->vf_id, is_on);
14770 #endif
14771
14772         switch (ret) {
14773         case 0:
14774                 break;
14775         case -EINVAL:
14776                 printf("invalid vf_id %d\n", res->vf_id);
14777                 break;
14778         case -ENODEV:
14779                 printf("invalid port_id %d\n", res->port_id);
14780                 break;
14781         case -ENOTSUP:
14782                 printf("function not implemented\n");
14783                 break;
14784         default:
14785                 printf("programming error: (%s)\n", strerror(-ret));
14786         }
14787 }
14788
14789 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14790         .f = cmd_set_vf_allmulti_parsed,
14791         .data = NULL,
14792         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14793                 "Set multicast promiscuous mode for a VF from the PF",
14794         .tokens = {
14795                 (void *)&cmd_vf_allmulti_set,
14796                 (void *)&cmd_vf_allmulti_vf,
14797                 (void *)&cmd_vf_allmulti_allmulti,
14798                 (void *)&cmd_vf_allmulti_port_id,
14799                 (void *)&cmd_vf_allmulti_vf_id,
14800                 (void *)&cmd_vf_allmulti_on_off,
14801                 NULL,
14802         },
14803 };
14804
14805 /* vf broadcast mode configuration */
14806
14807 /* Common result structure for vf broadcast */
14808 struct cmd_set_vf_broadcast_result {
14809         cmdline_fixed_string_t set;
14810         cmdline_fixed_string_t vf;
14811         cmdline_fixed_string_t broadcast;
14812         portid_t port_id;
14813         uint16_t vf_id;
14814         cmdline_fixed_string_t on_off;
14815 };
14816
14817 /* Common CLI fields for vf broadcast enable disable */
14818 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14819         TOKEN_STRING_INITIALIZER
14820                 (struct cmd_set_vf_broadcast_result,
14821                  set, "set");
14822 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14823         TOKEN_STRING_INITIALIZER
14824                 (struct cmd_set_vf_broadcast_result,
14825                  vf, "vf");
14826 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14827         TOKEN_STRING_INITIALIZER
14828                 (struct cmd_set_vf_broadcast_result,
14829                  broadcast, "broadcast");
14830 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14831         TOKEN_NUM_INITIALIZER
14832                 (struct cmd_set_vf_broadcast_result,
14833                  port_id, UINT16);
14834 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14835         TOKEN_NUM_INITIALIZER
14836                 (struct cmd_set_vf_broadcast_result,
14837                  vf_id, UINT16);
14838 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14839         TOKEN_STRING_INITIALIZER
14840                 (struct cmd_set_vf_broadcast_result,
14841                  on_off, "on#off");
14842
14843 static void
14844 cmd_set_vf_broadcast_parsed(
14845         void *parsed_result,
14846         __rte_unused struct cmdline *cl,
14847         __rte_unused void *data)
14848 {
14849         struct cmd_set_vf_broadcast_result *res = parsed_result;
14850         int ret = -ENOTSUP;
14851
14852         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14853
14854         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14855                 return;
14856
14857 #ifdef RTE_LIBRTE_I40E_PMD
14858         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14859                                             res->vf_id, is_on);
14860 #endif
14861
14862         switch (ret) {
14863         case 0:
14864                 break;
14865         case -EINVAL:
14866                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14867                 break;
14868         case -ENODEV:
14869                 printf("invalid port_id %d\n", res->port_id);
14870                 break;
14871         case -ENOTSUP:
14872                 printf("function not implemented\n");
14873                 break;
14874         default:
14875                 printf("programming error: (%s)\n", strerror(-ret));
14876         }
14877 }
14878
14879 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14880         .f = cmd_set_vf_broadcast_parsed,
14881         .data = NULL,
14882         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14883         .tokens = {
14884                 (void *)&cmd_set_vf_broadcast_set,
14885                 (void *)&cmd_set_vf_broadcast_vf,
14886                 (void *)&cmd_set_vf_broadcast_broadcast,
14887                 (void *)&cmd_set_vf_broadcast_port_id,
14888                 (void *)&cmd_set_vf_broadcast_vf_id,
14889                 (void *)&cmd_set_vf_broadcast_on_off,
14890                 NULL,
14891         },
14892 };
14893
14894 /* vf vlan tag configuration */
14895
14896 /* Common result structure for vf vlan tag */
14897 struct cmd_set_vf_vlan_tag_result {
14898         cmdline_fixed_string_t set;
14899         cmdline_fixed_string_t vf;
14900         cmdline_fixed_string_t vlan;
14901         cmdline_fixed_string_t tag;
14902         portid_t port_id;
14903         uint16_t vf_id;
14904         cmdline_fixed_string_t on_off;
14905 };
14906
14907 /* Common CLI fields for vf vlan tag enable disable */
14908 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14909         TOKEN_STRING_INITIALIZER
14910                 (struct cmd_set_vf_vlan_tag_result,
14911                  set, "set");
14912 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14913         TOKEN_STRING_INITIALIZER
14914                 (struct cmd_set_vf_vlan_tag_result,
14915                  vf, "vf");
14916 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14917         TOKEN_STRING_INITIALIZER
14918                 (struct cmd_set_vf_vlan_tag_result,
14919                  vlan, "vlan");
14920 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14921         TOKEN_STRING_INITIALIZER
14922                 (struct cmd_set_vf_vlan_tag_result,
14923                  tag, "tag");
14924 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14925         TOKEN_NUM_INITIALIZER
14926                 (struct cmd_set_vf_vlan_tag_result,
14927                  port_id, UINT16);
14928 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14929         TOKEN_NUM_INITIALIZER
14930                 (struct cmd_set_vf_vlan_tag_result,
14931                  vf_id, UINT16);
14932 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14933         TOKEN_STRING_INITIALIZER
14934                 (struct cmd_set_vf_vlan_tag_result,
14935                  on_off, "on#off");
14936
14937 static void
14938 cmd_set_vf_vlan_tag_parsed(
14939         void *parsed_result,
14940         __rte_unused struct cmdline *cl,
14941         __rte_unused void *data)
14942 {
14943         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14944         int ret = -ENOTSUP;
14945
14946         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14947
14948         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14949                 return;
14950
14951 #ifdef RTE_LIBRTE_I40E_PMD
14952         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14953                                            res->vf_id, is_on);
14954 #endif
14955
14956         switch (ret) {
14957         case 0:
14958                 break;
14959         case -EINVAL:
14960                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14961                 break;
14962         case -ENODEV:
14963                 printf("invalid port_id %d\n", res->port_id);
14964                 break;
14965         case -ENOTSUP:
14966                 printf("function not implemented\n");
14967                 break;
14968         default:
14969                 printf("programming error: (%s)\n", strerror(-ret));
14970         }
14971 }
14972
14973 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14974         .f = cmd_set_vf_vlan_tag_parsed,
14975         .data = NULL,
14976         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14977         .tokens = {
14978                 (void *)&cmd_set_vf_vlan_tag_set,
14979                 (void *)&cmd_set_vf_vlan_tag_vf,
14980                 (void *)&cmd_set_vf_vlan_tag_vlan,
14981                 (void *)&cmd_set_vf_vlan_tag_tag,
14982                 (void *)&cmd_set_vf_vlan_tag_port_id,
14983                 (void *)&cmd_set_vf_vlan_tag_vf_id,
14984                 (void *)&cmd_set_vf_vlan_tag_on_off,
14985                 NULL,
14986         },
14987 };
14988
14989 /* Common definition of VF and TC TX bandwidth configuration */
14990 struct cmd_vf_tc_bw_result {
14991         cmdline_fixed_string_t set;
14992         cmdline_fixed_string_t vf;
14993         cmdline_fixed_string_t tc;
14994         cmdline_fixed_string_t tx;
14995         cmdline_fixed_string_t min_bw;
14996         cmdline_fixed_string_t max_bw;
14997         cmdline_fixed_string_t strict_link_prio;
14998         portid_t port_id;
14999         uint16_t vf_id;
15000         uint8_t tc_no;
15001         uint32_t bw;
15002         cmdline_fixed_string_t bw_list;
15003         uint8_t tc_map;
15004 };
15005
15006 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15007         TOKEN_STRING_INITIALIZER
15008                 (struct cmd_vf_tc_bw_result,
15009                  set, "set");
15010 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15011         TOKEN_STRING_INITIALIZER
15012                 (struct cmd_vf_tc_bw_result,
15013                  vf, "vf");
15014 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15015         TOKEN_STRING_INITIALIZER
15016                 (struct cmd_vf_tc_bw_result,
15017                  tc, "tc");
15018 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15019         TOKEN_STRING_INITIALIZER
15020                 (struct cmd_vf_tc_bw_result,
15021                  tx, "tx");
15022 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15023         TOKEN_STRING_INITIALIZER
15024                 (struct cmd_vf_tc_bw_result,
15025                  strict_link_prio, "strict-link-priority");
15026 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15027         TOKEN_STRING_INITIALIZER
15028                 (struct cmd_vf_tc_bw_result,
15029                  min_bw, "min-bandwidth");
15030 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15031         TOKEN_STRING_INITIALIZER
15032                 (struct cmd_vf_tc_bw_result,
15033                  max_bw, "max-bandwidth");
15034 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15035         TOKEN_NUM_INITIALIZER
15036                 (struct cmd_vf_tc_bw_result,
15037                  port_id, UINT16);
15038 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15039         TOKEN_NUM_INITIALIZER
15040                 (struct cmd_vf_tc_bw_result,
15041                  vf_id, UINT16);
15042 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15043         TOKEN_NUM_INITIALIZER
15044                 (struct cmd_vf_tc_bw_result,
15045                  tc_no, UINT8);
15046 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15047         TOKEN_NUM_INITIALIZER
15048                 (struct cmd_vf_tc_bw_result,
15049                  bw, UINT32);
15050 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15051         TOKEN_STRING_INITIALIZER
15052                 (struct cmd_vf_tc_bw_result,
15053                  bw_list, NULL);
15054 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15055         TOKEN_NUM_INITIALIZER
15056                 (struct cmd_vf_tc_bw_result,
15057                  tc_map, UINT8);
15058
15059 /* VF max bandwidth setting */
15060 static void
15061 cmd_vf_max_bw_parsed(
15062         void *parsed_result,
15063         __rte_unused struct cmdline *cl,
15064         __rte_unused void *data)
15065 {
15066         struct cmd_vf_tc_bw_result *res = parsed_result;
15067         int ret = -ENOTSUP;
15068
15069         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15070                 return;
15071
15072 #ifdef RTE_LIBRTE_I40E_PMD
15073         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15074                                          res->vf_id, res->bw);
15075 #endif
15076
15077         switch (ret) {
15078         case 0:
15079                 break;
15080         case -EINVAL:
15081                 printf("invalid vf_id %d or bandwidth %d\n",
15082                        res->vf_id, res->bw);
15083                 break;
15084         case -ENODEV:
15085                 printf("invalid port_id %d\n", res->port_id);
15086                 break;
15087         case -ENOTSUP:
15088                 printf("function not implemented\n");
15089                 break;
15090         default:
15091                 printf("programming error: (%s)\n", strerror(-ret));
15092         }
15093 }
15094
15095 cmdline_parse_inst_t cmd_vf_max_bw = {
15096         .f = cmd_vf_max_bw_parsed,
15097         .data = NULL,
15098         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15099         .tokens = {
15100                 (void *)&cmd_vf_tc_bw_set,
15101                 (void *)&cmd_vf_tc_bw_vf,
15102                 (void *)&cmd_vf_tc_bw_tx,
15103                 (void *)&cmd_vf_tc_bw_max_bw,
15104                 (void *)&cmd_vf_tc_bw_port_id,
15105                 (void *)&cmd_vf_tc_bw_vf_id,
15106                 (void *)&cmd_vf_tc_bw_bw,
15107                 NULL,
15108         },
15109 };
15110
15111 static int
15112 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15113                            uint8_t *tc_num,
15114                            char *str)
15115 {
15116         uint32_t size;
15117         const char *p, *p0 = str;
15118         char s[256];
15119         char *end;
15120         char *str_fld[16];
15121         uint16_t i;
15122         int ret;
15123
15124         p = strchr(p0, '(');
15125         if (p == NULL) {
15126                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15127                 return -1;
15128         }
15129         p++;
15130         p0 = strchr(p, ')');
15131         if (p0 == NULL) {
15132                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15133                 return -1;
15134         }
15135         size = p0 - p;
15136         if (size >= sizeof(s)) {
15137                 printf("The string size exceeds the internal buffer size\n");
15138                 return -1;
15139         }
15140         snprintf(s, sizeof(s), "%.*s", size, p);
15141         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15142         if (ret <= 0) {
15143                 printf("Failed to get the bandwidth list. ");
15144                 return -1;
15145         }
15146         *tc_num = ret;
15147         for (i = 0; i < ret; i++)
15148                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15149
15150         return 0;
15151 }
15152
15153 /* TC min bandwidth setting */
15154 static void
15155 cmd_vf_tc_min_bw_parsed(
15156         void *parsed_result,
15157         __rte_unused struct cmdline *cl,
15158         __rte_unused void *data)
15159 {
15160         struct cmd_vf_tc_bw_result *res = parsed_result;
15161         uint8_t tc_num;
15162         uint8_t bw[16];
15163         int ret = -ENOTSUP;
15164
15165         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15166                 return;
15167
15168         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15169         if (ret)
15170                 return;
15171
15172 #ifdef RTE_LIBRTE_I40E_PMD
15173         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15174                                               tc_num, bw);
15175 #endif
15176
15177         switch (ret) {
15178         case 0:
15179                 break;
15180         case -EINVAL:
15181                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15182                 break;
15183         case -ENODEV:
15184                 printf("invalid port_id %d\n", res->port_id);
15185                 break;
15186         case -ENOTSUP:
15187                 printf("function not implemented\n");
15188                 break;
15189         default:
15190                 printf("programming error: (%s)\n", strerror(-ret));
15191         }
15192 }
15193
15194 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15195         .f = cmd_vf_tc_min_bw_parsed,
15196         .data = NULL,
15197         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15198                     " <bw1, bw2, ...>",
15199         .tokens = {
15200                 (void *)&cmd_vf_tc_bw_set,
15201                 (void *)&cmd_vf_tc_bw_vf,
15202                 (void *)&cmd_vf_tc_bw_tc,
15203                 (void *)&cmd_vf_tc_bw_tx,
15204                 (void *)&cmd_vf_tc_bw_min_bw,
15205                 (void *)&cmd_vf_tc_bw_port_id,
15206                 (void *)&cmd_vf_tc_bw_vf_id,
15207                 (void *)&cmd_vf_tc_bw_bw_list,
15208                 NULL,
15209         },
15210 };
15211
15212 static void
15213 cmd_tc_min_bw_parsed(
15214         void *parsed_result,
15215         __rte_unused struct cmdline *cl,
15216         __rte_unused void *data)
15217 {
15218         struct cmd_vf_tc_bw_result *res = parsed_result;
15219         struct rte_port *port;
15220         uint8_t tc_num;
15221         uint8_t bw[16];
15222         int ret = -ENOTSUP;
15223
15224         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15225                 return;
15226
15227         port = &ports[res->port_id];
15228         /** Check if the port is not started **/
15229         if (port->port_status != RTE_PORT_STOPPED) {
15230                 printf("Please stop port %d first\n", res->port_id);
15231                 return;
15232         }
15233
15234         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15235         if (ret)
15236                 return;
15237
15238 #ifdef RTE_LIBRTE_IXGBE_PMD
15239         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15240 #endif
15241
15242         switch (ret) {
15243         case 0:
15244                 break;
15245         case -EINVAL:
15246                 printf("invalid bandwidth\n");
15247                 break;
15248         case -ENODEV:
15249                 printf("invalid port_id %d\n", res->port_id);
15250                 break;
15251         case -ENOTSUP:
15252                 printf("function not implemented\n");
15253                 break;
15254         default:
15255                 printf("programming error: (%s)\n", strerror(-ret));
15256         }
15257 }
15258
15259 cmdline_parse_inst_t cmd_tc_min_bw = {
15260         .f = cmd_tc_min_bw_parsed,
15261         .data = NULL,
15262         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15263         .tokens = {
15264                 (void *)&cmd_vf_tc_bw_set,
15265                 (void *)&cmd_vf_tc_bw_tc,
15266                 (void *)&cmd_vf_tc_bw_tx,
15267                 (void *)&cmd_vf_tc_bw_min_bw,
15268                 (void *)&cmd_vf_tc_bw_port_id,
15269                 (void *)&cmd_vf_tc_bw_bw_list,
15270                 NULL,
15271         },
15272 };
15273
15274 /* TC max bandwidth setting */
15275 static void
15276 cmd_vf_tc_max_bw_parsed(
15277         void *parsed_result,
15278         __rte_unused struct cmdline *cl,
15279         __rte_unused void *data)
15280 {
15281         struct cmd_vf_tc_bw_result *res = parsed_result;
15282         int ret = -ENOTSUP;
15283
15284         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15285                 return;
15286
15287 #ifdef RTE_LIBRTE_I40E_PMD
15288         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15289                                             res->tc_no, res->bw);
15290 #endif
15291
15292         switch (ret) {
15293         case 0:
15294                 break;
15295         case -EINVAL:
15296                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15297                        res->vf_id, res->tc_no, res->bw);
15298                 break;
15299         case -ENODEV:
15300                 printf("invalid port_id %d\n", res->port_id);
15301                 break;
15302         case -ENOTSUP:
15303                 printf("function not implemented\n");
15304                 break;
15305         default:
15306                 printf("programming error: (%s)\n", strerror(-ret));
15307         }
15308 }
15309
15310 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15311         .f = cmd_vf_tc_max_bw_parsed,
15312         .data = NULL,
15313         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15314                     " <bandwidth>",
15315         .tokens = {
15316                 (void *)&cmd_vf_tc_bw_set,
15317                 (void *)&cmd_vf_tc_bw_vf,
15318                 (void *)&cmd_vf_tc_bw_tc,
15319                 (void *)&cmd_vf_tc_bw_tx,
15320                 (void *)&cmd_vf_tc_bw_max_bw,
15321                 (void *)&cmd_vf_tc_bw_port_id,
15322                 (void *)&cmd_vf_tc_bw_vf_id,
15323                 (void *)&cmd_vf_tc_bw_tc_no,
15324                 (void *)&cmd_vf_tc_bw_bw,
15325                 NULL,
15326         },
15327 };
15328
15329
15330 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15331
15332 /* *** Set Port default Traffic Management Hierarchy *** */
15333 struct cmd_set_port_tm_hierarchy_default_result {
15334         cmdline_fixed_string_t set;
15335         cmdline_fixed_string_t port;
15336         cmdline_fixed_string_t tm;
15337         cmdline_fixed_string_t hierarchy;
15338         cmdline_fixed_string_t def;
15339         portid_t port_id;
15340 };
15341
15342 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15343         TOKEN_STRING_INITIALIZER(
15344                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15345 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15346         TOKEN_STRING_INITIALIZER(
15347                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15348 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15349         TOKEN_STRING_INITIALIZER(
15350                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15351 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15352         TOKEN_STRING_INITIALIZER(
15353                 struct cmd_set_port_tm_hierarchy_default_result,
15354                         hierarchy, "hierarchy");
15355 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15356         TOKEN_STRING_INITIALIZER(
15357                 struct cmd_set_port_tm_hierarchy_default_result,
15358                         def, "default");
15359 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15360         TOKEN_NUM_INITIALIZER(
15361                 struct cmd_set_port_tm_hierarchy_default_result,
15362                         port_id, UINT16);
15363
15364 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15365         __rte_unused struct cmdline *cl,
15366         __rte_unused void *data)
15367 {
15368         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15369         struct rte_port *p;
15370         portid_t port_id = res->port_id;
15371
15372         if (port_id_is_invalid(port_id, ENABLED_WARN))
15373                 return;
15374
15375         p = &ports[port_id];
15376
15377         /* Forward mode: tm */
15378         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15379                 printf("  softnicfwd mode not enabled(error)\n");
15380                 return;
15381         }
15382
15383         /* Set the default tm hierarchy */
15384         p->softport.default_tm_hierarchy_enable = 1;
15385 }
15386
15387 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15388         .f = cmd_set_port_tm_hierarchy_default_parsed,
15389         .data = NULL,
15390         .help_str = "set port tm hierarchy default <port_id>",
15391         .tokens = {
15392                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15393                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15394                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15395                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15396                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15397                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15398                 NULL,
15399         },
15400 };
15401 #endif
15402
15403 /** Set VXLAN encapsulation details */
15404 struct cmd_set_vxlan_result {
15405         cmdline_fixed_string_t set;
15406         cmdline_fixed_string_t vxlan;
15407         cmdline_fixed_string_t pos_token;
15408         cmdline_fixed_string_t ip_version;
15409         uint32_t vlan_present:1;
15410         uint32_t vni;
15411         uint16_t udp_src;
15412         uint16_t udp_dst;
15413         cmdline_ipaddr_t ip_src;
15414         cmdline_ipaddr_t ip_dst;
15415         uint16_t tci;
15416         uint8_t tos;
15417         uint8_t ttl;
15418         struct rte_ether_addr eth_src;
15419         struct rte_ether_addr eth_dst;
15420 };
15421
15422 cmdline_parse_token_string_t cmd_set_vxlan_set =
15423         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15424 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15425         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15426 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15427         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15428                                  "vxlan-tos-ttl");
15429 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15430         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15431                                  "vxlan-with-vlan");
15432 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15433         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15434                                  "ip-version");
15435 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15436         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15437                                  "ipv4#ipv6");
15438 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15439         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15440                                  "vni");
15441 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15442         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15443 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15444         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15445                                  "udp-src");
15446 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15447         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15448 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15449         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15450                                  "udp-dst");
15451 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15452         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15453 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15454         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15455                                  "ip-tos");
15456 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15457         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15458 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15459         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15460                                  "ip-ttl");
15461 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15462         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15463 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15464         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15465                                  "ip-src");
15466 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15467         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15468 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15469         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15470                                  "ip-dst");
15471 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15472         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15473 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15474         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15475                                  "vlan-tci");
15476 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15477         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15478 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15479         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15480                                  "eth-src");
15481 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15482         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15483 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15484         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15485                                  "eth-dst");
15486 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15487         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15488
15489 static void cmd_set_vxlan_parsed(void *parsed_result,
15490         __rte_unused struct cmdline *cl,
15491         __rte_unused void *data)
15492 {
15493         struct cmd_set_vxlan_result *res = parsed_result;
15494         union {
15495                 uint32_t vxlan_id;
15496                 uint8_t vni[4];
15497         } id = {
15498                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15499         };
15500
15501         vxlan_encap_conf.select_tos_ttl = 0;
15502         if (strcmp(res->vxlan, "vxlan") == 0)
15503                 vxlan_encap_conf.select_vlan = 0;
15504         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15505                 vxlan_encap_conf.select_vlan = 1;
15506         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15507                 vxlan_encap_conf.select_vlan = 0;
15508                 vxlan_encap_conf.select_tos_ttl = 1;
15509         }
15510         if (strcmp(res->ip_version, "ipv4") == 0)
15511                 vxlan_encap_conf.select_ipv4 = 1;
15512         else if (strcmp(res->ip_version, "ipv6") == 0)
15513                 vxlan_encap_conf.select_ipv4 = 0;
15514         else
15515                 return;
15516         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15517         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15518         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15519         vxlan_encap_conf.ip_tos = res->tos;
15520         vxlan_encap_conf.ip_ttl = res->ttl;
15521         if (vxlan_encap_conf.select_ipv4) {
15522                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15523                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15524         } else {
15525                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15526                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15527         }
15528         if (vxlan_encap_conf.select_vlan)
15529                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15530         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15531                    RTE_ETHER_ADDR_LEN);
15532         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15533                    RTE_ETHER_ADDR_LEN);
15534 }
15535
15536 cmdline_parse_inst_t cmd_set_vxlan = {
15537         .f = cmd_set_vxlan_parsed,
15538         .data = NULL,
15539         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15540                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15541                 " eth-src <eth-src> eth-dst <eth-dst>",
15542         .tokens = {
15543                 (void *)&cmd_set_vxlan_set,
15544                 (void *)&cmd_set_vxlan_vxlan,
15545                 (void *)&cmd_set_vxlan_ip_version,
15546                 (void *)&cmd_set_vxlan_ip_version_value,
15547                 (void *)&cmd_set_vxlan_vni,
15548                 (void *)&cmd_set_vxlan_vni_value,
15549                 (void *)&cmd_set_vxlan_udp_src,
15550                 (void *)&cmd_set_vxlan_udp_src_value,
15551                 (void *)&cmd_set_vxlan_udp_dst,
15552                 (void *)&cmd_set_vxlan_udp_dst_value,
15553                 (void *)&cmd_set_vxlan_ip_src,
15554                 (void *)&cmd_set_vxlan_ip_src_value,
15555                 (void *)&cmd_set_vxlan_ip_dst,
15556                 (void *)&cmd_set_vxlan_ip_dst_value,
15557                 (void *)&cmd_set_vxlan_eth_src,
15558                 (void *)&cmd_set_vxlan_eth_src_value,
15559                 (void *)&cmd_set_vxlan_eth_dst,
15560                 (void *)&cmd_set_vxlan_eth_dst_value,
15561                 NULL,
15562         },
15563 };
15564
15565 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15566         .f = cmd_set_vxlan_parsed,
15567         .data = NULL,
15568         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15569                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15570                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15571                 " eth-dst <eth-dst>",
15572         .tokens = {
15573                 (void *)&cmd_set_vxlan_set,
15574                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15575                 (void *)&cmd_set_vxlan_ip_version,
15576                 (void *)&cmd_set_vxlan_ip_version_value,
15577                 (void *)&cmd_set_vxlan_vni,
15578                 (void *)&cmd_set_vxlan_vni_value,
15579                 (void *)&cmd_set_vxlan_udp_src,
15580                 (void *)&cmd_set_vxlan_udp_src_value,
15581                 (void *)&cmd_set_vxlan_udp_dst,
15582                 (void *)&cmd_set_vxlan_udp_dst_value,
15583                 (void *)&cmd_set_vxlan_ip_tos,
15584                 (void *)&cmd_set_vxlan_ip_tos_value,
15585                 (void *)&cmd_set_vxlan_ip_ttl,
15586                 (void *)&cmd_set_vxlan_ip_ttl_value,
15587                 (void *)&cmd_set_vxlan_ip_src,
15588                 (void *)&cmd_set_vxlan_ip_src_value,
15589                 (void *)&cmd_set_vxlan_ip_dst,
15590                 (void *)&cmd_set_vxlan_ip_dst_value,
15591                 (void *)&cmd_set_vxlan_eth_src,
15592                 (void *)&cmd_set_vxlan_eth_src_value,
15593                 (void *)&cmd_set_vxlan_eth_dst,
15594                 (void *)&cmd_set_vxlan_eth_dst_value,
15595                 NULL,
15596         },
15597 };
15598
15599 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15600         .f = cmd_set_vxlan_parsed,
15601         .data = NULL,
15602         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15603                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15604                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15605                 " <eth-dst>",
15606         .tokens = {
15607                 (void *)&cmd_set_vxlan_set,
15608                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15609                 (void *)&cmd_set_vxlan_ip_version,
15610                 (void *)&cmd_set_vxlan_ip_version_value,
15611                 (void *)&cmd_set_vxlan_vni,
15612                 (void *)&cmd_set_vxlan_vni_value,
15613                 (void *)&cmd_set_vxlan_udp_src,
15614                 (void *)&cmd_set_vxlan_udp_src_value,
15615                 (void *)&cmd_set_vxlan_udp_dst,
15616                 (void *)&cmd_set_vxlan_udp_dst_value,
15617                 (void *)&cmd_set_vxlan_ip_src,
15618                 (void *)&cmd_set_vxlan_ip_src_value,
15619                 (void *)&cmd_set_vxlan_ip_dst,
15620                 (void *)&cmd_set_vxlan_ip_dst_value,
15621                 (void *)&cmd_set_vxlan_vlan,
15622                 (void *)&cmd_set_vxlan_vlan_value,
15623                 (void *)&cmd_set_vxlan_eth_src,
15624                 (void *)&cmd_set_vxlan_eth_src_value,
15625                 (void *)&cmd_set_vxlan_eth_dst,
15626                 (void *)&cmd_set_vxlan_eth_dst_value,
15627                 NULL,
15628         },
15629 };
15630
15631 /** Set NVGRE encapsulation details */
15632 struct cmd_set_nvgre_result {
15633         cmdline_fixed_string_t set;
15634         cmdline_fixed_string_t nvgre;
15635         cmdline_fixed_string_t pos_token;
15636         cmdline_fixed_string_t ip_version;
15637         uint32_t tni;
15638         cmdline_ipaddr_t ip_src;
15639         cmdline_ipaddr_t ip_dst;
15640         uint16_t tci;
15641         struct rte_ether_addr eth_src;
15642         struct rte_ether_addr eth_dst;
15643 };
15644
15645 cmdline_parse_token_string_t cmd_set_nvgre_set =
15646         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15647 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15648         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15649 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15650         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15651                                  "nvgre-with-vlan");
15652 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15653         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15654                                  "ip-version");
15655 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15656         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15657                                  "ipv4#ipv6");
15658 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15659         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15660                                  "tni");
15661 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15662         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15663 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15664         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15665                                  "ip-src");
15666 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15667         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15668 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15669         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15670                                  "ip-dst");
15671 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15672         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15673 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15674         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15675                                  "vlan-tci");
15676 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15677         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15678 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15679         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15680                                  "eth-src");
15681 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15682         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15683 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15684         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15685                                  "eth-dst");
15686 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15687         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15688
15689 static void cmd_set_nvgre_parsed(void *parsed_result,
15690         __rte_unused struct cmdline *cl,
15691         __rte_unused void *data)
15692 {
15693         struct cmd_set_nvgre_result *res = parsed_result;
15694         union {
15695                 uint32_t nvgre_tni;
15696                 uint8_t tni[4];
15697         } id = {
15698                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15699         };
15700
15701         if (strcmp(res->nvgre, "nvgre") == 0)
15702                 nvgre_encap_conf.select_vlan = 0;
15703         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15704                 nvgre_encap_conf.select_vlan = 1;
15705         if (strcmp(res->ip_version, "ipv4") == 0)
15706                 nvgre_encap_conf.select_ipv4 = 1;
15707         else if (strcmp(res->ip_version, "ipv6") == 0)
15708                 nvgre_encap_conf.select_ipv4 = 0;
15709         else
15710                 return;
15711         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15712         if (nvgre_encap_conf.select_ipv4) {
15713                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15714                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15715         } else {
15716                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15717                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15718         }
15719         if (nvgre_encap_conf.select_vlan)
15720                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15721         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15722                    RTE_ETHER_ADDR_LEN);
15723         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15724                    RTE_ETHER_ADDR_LEN);
15725 }
15726
15727 cmdline_parse_inst_t cmd_set_nvgre = {
15728         .f = cmd_set_nvgre_parsed,
15729         .data = NULL,
15730         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15731                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15732                 " eth-dst <eth-dst>",
15733         .tokens = {
15734                 (void *)&cmd_set_nvgre_set,
15735                 (void *)&cmd_set_nvgre_nvgre,
15736                 (void *)&cmd_set_nvgre_ip_version,
15737                 (void *)&cmd_set_nvgre_ip_version_value,
15738                 (void *)&cmd_set_nvgre_tni,
15739                 (void *)&cmd_set_nvgre_tni_value,
15740                 (void *)&cmd_set_nvgre_ip_src,
15741                 (void *)&cmd_set_nvgre_ip_src_value,
15742                 (void *)&cmd_set_nvgre_ip_dst,
15743                 (void *)&cmd_set_nvgre_ip_dst_value,
15744                 (void *)&cmd_set_nvgre_eth_src,
15745                 (void *)&cmd_set_nvgre_eth_src_value,
15746                 (void *)&cmd_set_nvgre_eth_dst,
15747                 (void *)&cmd_set_nvgre_eth_dst_value,
15748                 NULL,
15749         },
15750 };
15751
15752 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15753         .f = cmd_set_nvgre_parsed,
15754         .data = NULL,
15755         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15756                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15757                 " eth-src <eth-src> eth-dst <eth-dst>",
15758         .tokens = {
15759                 (void *)&cmd_set_nvgre_set,
15760                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15761                 (void *)&cmd_set_nvgre_ip_version,
15762                 (void *)&cmd_set_nvgre_ip_version_value,
15763                 (void *)&cmd_set_nvgre_tni,
15764                 (void *)&cmd_set_nvgre_tni_value,
15765                 (void *)&cmd_set_nvgre_ip_src,
15766                 (void *)&cmd_set_nvgre_ip_src_value,
15767                 (void *)&cmd_set_nvgre_ip_dst,
15768                 (void *)&cmd_set_nvgre_ip_dst_value,
15769                 (void *)&cmd_set_nvgre_vlan,
15770                 (void *)&cmd_set_nvgre_vlan_value,
15771                 (void *)&cmd_set_nvgre_eth_src,
15772                 (void *)&cmd_set_nvgre_eth_src_value,
15773                 (void *)&cmd_set_nvgre_eth_dst,
15774                 (void *)&cmd_set_nvgre_eth_dst_value,
15775                 NULL,
15776         },
15777 };
15778
15779 /** Set L2 encapsulation details */
15780 struct cmd_set_l2_encap_result {
15781         cmdline_fixed_string_t set;
15782         cmdline_fixed_string_t l2_encap;
15783         cmdline_fixed_string_t pos_token;
15784         cmdline_fixed_string_t ip_version;
15785         uint32_t vlan_present:1;
15786         uint16_t tci;
15787         struct rte_ether_addr eth_src;
15788         struct rte_ether_addr eth_dst;
15789 };
15790
15791 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15792         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15793 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15794         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15795 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15796         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15797                                  "l2_encap-with-vlan");
15798 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15799         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15800                                  "ip-version");
15801 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15802         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15803                                  "ipv4#ipv6");
15804 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15805         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15806                                  "vlan-tci");
15807 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15808         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15809 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15810         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15811                                  "eth-src");
15812 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15813         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15814 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15815         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15816                                  "eth-dst");
15817 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15818         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15819
15820 static void cmd_set_l2_encap_parsed(void *parsed_result,
15821         __rte_unused struct cmdline *cl,
15822         __rte_unused void *data)
15823 {
15824         struct cmd_set_l2_encap_result *res = parsed_result;
15825
15826         if (strcmp(res->l2_encap, "l2_encap") == 0)
15827                 l2_encap_conf.select_vlan = 0;
15828         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15829                 l2_encap_conf.select_vlan = 1;
15830         if (strcmp(res->ip_version, "ipv4") == 0)
15831                 l2_encap_conf.select_ipv4 = 1;
15832         else if (strcmp(res->ip_version, "ipv6") == 0)
15833                 l2_encap_conf.select_ipv4 = 0;
15834         else
15835                 return;
15836         if (l2_encap_conf.select_vlan)
15837                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15838         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15839                    RTE_ETHER_ADDR_LEN);
15840         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15841                    RTE_ETHER_ADDR_LEN);
15842 }
15843
15844 cmdline_parse_inst_t cmd_set_l2_encap = {
15845         .f = cmd_set_l2_encap_parsed,
15846         .data = NULL,
15847         .help_str = "set l2_encap ip-version ipv4|ipv6"
15848                 " eth-src <eth-src> eth-dst <eth-dst>",
15849         .tokens = {
15850                 (void *)&cmd_set_l2_encap_set,
15851                 (void *)&cmd_set_l2_encap_l2_encap,
15852                 (void *)&cmd_set_l2_encap_ip_version,
15853                 (void *)&cmd_set_l2_encap_ip_version_value,
15854                 (void *)&cmd_set_l2_encap_eth_src,
15855                 (void *)&cmd_set_l2_encap_eth_src_value,
15856                 (void *)&cmd_set_l2_encap_eth_dst,
15857                 (void *)&cmd_set_l2_encap_eth_dst_value,
15858                 NULL,
15859         },
15860 };
15861
15862 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15863         .f = cmd_set_l2_encap_parsed,
15864         .data = NULL,
15865         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15866                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15867         .tokens = {
15868                 (void *)&cmd_set_l2_encap_set,
15869                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15870                 (void *)&cmd_set_l2_encap_ip_version,
15871                 (void *)&cmd_set_l2_encap_ip_version_value,
15872                 (void *)&cmd_set_l2_encap_vlan,
15873                 (void *)&cmd_set_l2_encap_vlan_value,
15874                 (void *)&cmd_set_l2_encap_eth_src,
15875                 (void *)&cmd_set_l2_encap_eth_src_value,
15876                 (void *)&cmd_set_l2_encap_eth_dst,
15877                 (void *)&cmd_set_l2_encap_eth_dst_value,
15878                 NULL,
15879         },
15880 };
15881
15882 /** Set L2 decapsulation details */
15883 struct cmd_set_l2_decap_result {
15884         cmdline_fixed_string_t set;
15885         cmdline_fixed_string_t l2_decap;
15886         cmdline_fixed_string_t pos_token;
15887         uint32_t vlan_present:1;
15888 };
15889
15890 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15891         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15892 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15893         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15894                                  "l2_decap");
15895 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15896         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15897                                  "l2_decap-with-vlan");
15898
15899 static void cmd_set_l2_decap_parsed(void *parsed_result,
15900         __rte_unused struct cmdline *cl,
15901         __rte_unused void *data)
15902 {
15903         struct cmd_set_l2_decap_result *res = parsed_result;
15904
15905         if (strcmp(res->l2_decap, "l2_decap") == 0)
15906                 l2_decap_conf.select_vlan = 0;
15907         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15908                 l2_decap_conf.select_vlan = 1;
15909 }
15910
15911 cmdline_parse_inst_t cmd_set_l2_decap = {
15912         .f = cmd_set_l2_decap_parsed,
15913         .data = NULL,
15914         .help_str = "set l2_decap",
15915         .tokens = {
15916                 (void *)&cmd_set_l2_decap_set,
15917                 (void *)&cmd_set_l2_decap_l2_decap,
15918                 NULL,
15919         },
15920 };
15921
15922 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15923         .f = cmd_set_l2_decap_parsed,
15924         .data = NULL,
15925         .help_str = "set l2_decap-with-vlan",
15926         .tokens = {
15927                 (void *)&cmd_set_l2_decap_set,
15928                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15929                 NULL,
15930         },
15931 };
15932
15933 /** Set MPLSoGRE encapsulation details */
15934 struct cmd_set_mplsogre_encap_result {
15935         cmdline_fixed_string_t set;
15936         cmdline_fixed_string_t mplsogre;
15937         cmdline_fixed_string_t pos_token;
15938         cmdline_fixed_string_t ip_version;
15939         uint32_t vlan_present:1;
15940         uint32_t label;
15941         cmdline_ipaddr_t ip_src;
15942         cmdline_ipaddr_t ip_dst;
15943         uint16_t tci;
15944         struct rte_ether_addr eth_src;
15945         struct rte_ether_addr eth_dst;
15946 };
15947
15948 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15949         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15950                                  "set");
15951 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15952         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15953                                  "mplsogre_encap");
15954 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15955         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15956                                  mplsogre, "mplsogre_encap-with-vlan");
15957 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15958         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15959                                  pos_token, "ip-version");
15960 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15961         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15962                                  ip_version, "ipv4#ipv6");
15963 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15964         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15965                                  pos_token, "label");
15966 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15967         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15968                               UINT32);
15969 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15970         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15971                                  pos_token, "ip-src");
15972 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15973         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15974 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15975         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15976                                  pos_token, "ip-dst");
15977 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15978         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15979 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15980         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15981                                  pos_token, "vlan-tci");
15982 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15983         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15984                               UINT16);
15985 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15986         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15987                                  pos_token, "eth-src");
15988 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15989         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15990                                     eth_src);
15991 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15992         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15993                                  pos_token, "eth-dst");
15994 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15995         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15996                                     eth_dst);
15997
15998 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15999         __rte_unused struct cmdline *cl,
16000         __rte_unused void *data)
16001 {
16002         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16003         union {
16004                 uint32_t mplsogre_label;
16005                 uint8_t label[4];
16006         } id = {
16007                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16008         };
16009
16010         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16011                 mplsogre_encap_conf.select_vlan = 0;
16012         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16013                 mplsogre_encap_conf.select_vlan = 1;
16014         if (strcmp(res->ip_version, "ipv4") == 0)
16015                 mplsogre_encap_conf.select_ipv4 = 1;
16016         else if (strcmp(res->ip_version, "ipv6") == 0)
16017                 mplsogre_encap_conf.select_ipv4 = 0;
16018         else
16019                 return;
16020         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16021         if (mplsogre_encap_conf.select_ipv4) {
16022                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16023                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16024         } else {
16025                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16026                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16027         }
16028         if (mplsogre_encap_conf.select_vlan)
16029                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16030         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16031                    RTE_ETHER_ADDR_LEN);
16032         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16033                    RTE_ETHER_ADDR_LEN);
16034 }
16035
16036 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16037         .f = cmd_set_mplsogre_encap_parsed,
16038         .data = NULL,
16039         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16040                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16041                 " eth-dst <eth-dst>",
16042         .tokens = {
16043                 (void *)&cmd_set_mplsogre_encap_set,
16044                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16045                 (void *)&cmd_set_mplsogre_encap_ip_version,
16046                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16047                 (void *)&cmd_set_mplsogre_encap_label,
16048                 (void *)&cmd_set_mplsogre_encap_label_value,
16049                 (void *)&cmd_set_mplsogre_encap_ip_src,
16050                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16051                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16052                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16053                 (void *)&cmd_set_mplsogre_encap_eth_src,
16054                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16055                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16056                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16057                 NULL,
16058         },
16059 };
16060
16061 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16062         .f = cmd_set_mplsogre_encap_parsed,
16063         .data = NULL,
16064         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16065                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16066                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16067         .tokens = {
16068                 (void *)&cmd_set_mplsogre_encap_set,
16069                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16070                 (void *)&cmd_set_mplsogre_encap_ip_version,
16071                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16072                 (void *)&cmd_set_mplsogre_encap_label,
16073                 (void *)&cmd_set_mplsogre_encap_label_value,
16074                 (void *)&cmd_set_mplsogre_encap_ip_src,
16075                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16076                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16077                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16078                 (void *)&cmd_set_mplsogre_encap_vlan,
16079                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16080                 (void *)&cmd_set_mplsogre_encap_eth_src,
16081                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16082                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16083                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16084                 NULL,
16085         },
16086 };
16087
16088 /** Set MPLSoGRE decapsulation details */
16089 struct cmd_set_mplsogre_decap_result {
16090         cmdline_fixed_string_t set;
16091         cmdline_fixed_string_t mplsogre;
16092         cmdline_fixed_string_t pos_token;
16093         cmdline_fixed_string_t ip_version;
16094         uint32_t vlan_present:1;
16095 };
16096
16097 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16098         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16099                                  "set");
16100 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16101         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16102                                  "mplsogre_decap");
16103 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16104         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16105                                  mplsogre, "mplsogre_decap-with-vlan");
16106 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16107         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16108                                  pos_token, "ip-version");
16109 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16110         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16111                                  ip_version, "ipv4#ipv6");
16112
16113 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16114         __rte_unused struct cmdline *cl,
16115         __rte_unused void *data)
16116 {
16117         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16118
16119         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16120                 mplsogre_decap_conf.select_vlan = 0;
16121         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16122                 mplsogre_decap_conf.select_vlan = 1;
16123         if (strcmp(res->ip_version, "ipv4") == 0)
16124                 mplsogre_decap_conf.select_ipv4 = 1;
16125         else if (strcmp(res->ip_version, "ipv6") == 0)
16126                 mplsogre_decap_conf.select_ipv4 = 0;
16127 }
16128
16129 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16130         .f = cmd_set_mplsogre_decap_parsed,
16131         .data = NULL,
16132         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16133         .tokens = {
16134                 (void *)&cmd_set_mplsogre_decap_set,
16135                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16136                 (void *)&cmd_set_mplsogre_decap_ip_version,
16137                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16138                 NULL,
16139         },
16140 };
16141
16142 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16143         .f = cmd_set_mplsogre_decap_parsed,
16144         .data = NULL,
16145         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16146         .tokens = {
16147                 (void *)&cmd_set_mplsogre_decap_set,
16148                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16149                 (void *)&cmd_set_mplsogre_decap_ip_version,
16150                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16151                 NULL,
16152         },
16153 };
16154
16155 /** Set MPLSoUDP encapsulation details */
16156 struct cmd_set_mplsoudp_encap_result {
16157         cmdline_fixed_string_t set;
16158         cmdline_fixed_string_t mplsoudp;
16159         cmdline_fixed_string_t pos_token;
16160         cmdline_fixed_string_t ip_version;
16161         uint32_t vlan_present:1;
16162         uint32_t label;
16163         uint16_t udp_src;
16164         uint16_t udp_dst;
16165         cmdline_ipaddr_t ip_src;
16166         cmdline_ipaddr_t ip_dst;
16167         uint16_t tci;
16168         struct rte_ether_addr eth_src;
16169         struct rte_ether_addr eth_dst;
16170 };
16171
16172 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16173         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16174                                  "set");
16175 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16176         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16177                                  "mplsoudp_encap");
16178 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16179         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16180                                  mplsoudp, "mplsoudp_encap-with-vlan");
16181 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16182         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16183                                  pos_token, "ip-version");
16184 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16185         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16186                                  ip_version, "ipv4#ipv6");
16187 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16188         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16189                                  pos_token, "label");
16190 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16191         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16192                               UINT32);
16193 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16194         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16195                                  pos_token, "udp-src");
16196 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16197         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16198                               UINT16);
16199 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16200         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16201                                  pos_token, "udp-dst");
16202 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16203         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16204                               UINT16);
16205 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16206         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16207                                  pos_token, "ip-src");
16208 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16209         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16210 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16211         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16212                                  pos_token, "ip-dst");
16213 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16214         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16215 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16216         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16217                                  pos_token, "vlan-tci");
16218 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16219         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16220                               UINT16);
16221 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16222         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16223                                  pos_token, "eth-src");
16224 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16225         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16226                                     eth_src);
16227 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16228         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16229                                  pos_token, "eth-dst");
16230 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16231         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16232                                     eth_dst);
16233
16234 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16235         __rte_unused struct cmdline *cl,
16236         __rte_unused void *data)
16237 {
16238         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16239         union {
16240                 uint32_t mplsoudp_label;
16241                 uint8_t label[4];
16242         } id = {
16243                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16244         };
16245
16246         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16247                 mplsoudp_encap_conf.select_vlan = 0;
16248         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16249                 mplsoudp_encap_conf.select_vlan = 1;
16250         if (strcmp(res->ip_version, "ipv4") == 0)
16251                 mplsoudp_encap_conf.select_ipv4 = 1;
16252         else if (strcmp(res->ip_version, "ipv6") == 0)
16253                 mplsoudp_encap_conf.select_ipv4 = 0;
16254         else
16255                 return;
16256         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16257         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16258         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16259         if (mplsoudp_encap_conf.select_ipv4) {
16260                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16261                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16262         } else {
16263                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16264                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16265         }
16266         if (mplsoudp_encap_conf.select_vlan)
16267                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16268         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16269                    RTE_ETHER_ADDR_LEN);
16270         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16271                    RTE_ETHER_ADDR_LEN);
16272 }
16273
16274 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16275         .f = cmd_set_mplsoudp_encap_parsed,
16276         .data = NULL,
16277         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16278                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16279                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16280         .tokens = {
16281                 (void *)&cmd_set_mplsoudp_encap_set,
16282                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16283                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16284                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16285                 (void *)&cmd_set_mplsoudp_encap_label,
16286                 (void *)&cmd_set_mplsoudp_encap_label_value,
16287                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16288                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16289                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16290                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16291                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16292                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16293                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16294                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16295                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16296                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16297                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16298                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16299                 NULL,
16300         },
16301 };
16302
16303 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16304         .f = cmd_set_mplsoudp_encap_parsed,
16305         .data = NULL,
16306         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16307                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16308                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16309                 " eth-src <eth-src> eth-dst <eth-dst>",
16310         .tokens = {
16311                 (void *)&cmd_set_mplsoudp_encap_set,
16312                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16313                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16314                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16315                 (void *)&cmd_set_mplsoudp_encap_label,
16316                 (void *)&cmd_set_mplsoudp_encap_label_value,
16317                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16318                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16319                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16320                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16321                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16322                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16323                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16324                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16325                 (void *)&cmd_set_mplsoudp_encap_vlan,
16326                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16327                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16328                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16329                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16330                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16331                 NULL,
16332         },
16333 };
16334
16335 /** Set MPLSoUDP decapsulation details */
16336 struct cmd_set_mplsoudp_decap_result {
16337         cmdline_fixed_string_t set;
16338         cmdline_fixed_string_t mplsoudp;
16339         cmdline_fixed_string_t pos_token;
16340         cmdline_fixed_string_t ip_version;
16341         uint32_t vlan_present:1;
16342 };
16343
16344 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16345         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16346                                  "set");
16347 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16348         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16349                                  "mplsoudp_decap");
16350 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16351         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16352                                  mplsoudp, "mplsoudp_decap-with-vlan");
16353 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16354         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16355                                  pos_token, "ip-version");
16356 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16357         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16358                                  ip_version, "ipv4#ipv6");
16359
16360 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16361         __rte_unused struct cmdline *cl,
16362         __rte_unused void *data)
16363 {
16364         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16365
16366         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16367                 mplsoudp_decap_conf.select_vlan = 0;
16368         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16369                 mplsoudp_decap_conf.select_vlan = 1;
16370         if (strcmp(res->ip_version, "ipv4") == 0)
16371                 mplsoudp_decap_conf.select_ipv4 = 1;
16372         else if (strcmp(res->ip_version, "ipv6") == 0)
16373                 mplsoudp_decap_conf.select_ipv4 = 0;
16374 }
16375
16376 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16377         .f = cmd_set_mplsoudp_decap_parsed,
16378         .data = NULL,
16379         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16380         .tokens = {
16381                 (void *)&cmd_set_mplsoudp_decap_set,
16382                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16383                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16384                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16385                 NULL,
16386         },
16387 };
16388
16389 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16390         .f = cmd_set_mplsoudp_decap_parsed,
16391         .data = NULL,
16392         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16393         .tokens = {
16394                 (void *)&cmd_set_mplsoudp_decap_set,
16395                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16396                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16397                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16398                 NULL,
16399         },
16400 };
16401
16402 /* Strict link priority scheduling mode setting */
16403 static void
16404 cmd_strict_link_prio_parsed(
16405         void *parsed_result,
16406         __rte_unused struct cmdline *cl,
16407         __rte_unused void *data)
16408 {
16409         struct cmd_vf_tc_bw_result *res = parsed_result;
16410         int ret = -ENOTSUP;
16411
16412         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16413                 return;
16414
16415 #ifdef RTE_LIBRTE_I40E_PMD
16416         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16417 #endif
16418
16419         switch (ret) {
16420         case 0:
16421                 break;
16422         case -EINVAL:
16423                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16424                 break;
16425         case -ENODEV:
16426                 printf("invalid port_id %d\n", res->port_id);
16427                 break;
16428         case -ENOTSUP:
16429                 printf("function not implemented\n");
16430                 break;
16431         default:
16432                 printf("programming error: (%s)\n", strerror(-ret));
16433         }
16434 }
16435
16436 cmdline_parse_inst_t cmd_strict_link_prio = {
16437         .f = cmd_strict_link_prio_parsed,
16438         .data = NULL,
16439         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16440         .tokens = {
16441                 (void *)&cmd_vf_tc_bw_set,
16442                 (void *)&cmd_vf_tc_bw_tx,
16443                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16444                 (void *)&cmd_vf_tc_bw_port_id,
16445                 (void *)&cmd_vf_tc_bw_tc_map,
16446                 NULL,
16447         },
16448 };
16449
16450 /* Load dynamic device personalization*/
16451 struct cmd_ddp_add_result {
16452         cmdline_fixed_string_t ddp;
16453         cmdline_fixed_string_t add;
16454         portid_t port_id;
16455         char filepath[];
16456 };
16457
16458 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16459         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16460 cmdline_parse_token_string_t cmd_ddp_add_add =
16461         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16462 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16463         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16464 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16465         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16466
16467 static void
16468 cmd_ddp_add_parsed(
16469         void *parsed_result,
16470         __rte_unused struct cmdline *cl,
16471         __rte_unused void *data)
16472 {
16473         struct cmd_ddp_add_result *res = parsed_result;
16474         uint8_t *buff;
16475         uint32_t size;
16476         char *filepath;
16477         char *file_fld[2];
16478         int file_num;
16479         int ret = -ENOTSUP;
16480
16481         if (!all_ports_stopped()) {
16482                 printf("Please stop all ports first\n");
16483                 return;
16484         }
16485
16486         filepath = strdup(res->filepath);
16487         if (filepath == NULL) {
16488                 printf("Failed to allocate memory\n");
16489                 return;
16490         }
16491         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16492
16493         buff = open_file(file_fld[0], &size);
16494         if (!buff) {
16495                 free((void *)filepath);
16496                 return;
16497         }
16498
16499 #ifdef RTE_LIBRTE_I40E_PMD
16500         if (ret == -ENOTSUP)
16501                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16502                                                buff, size,
16503                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16504 #endif
16505
16506         if (ret == -EEXIST)
16507                 printf("Profile has already existed.\n");
16508         else if (ret < 0)
16509                 printf("Failed to load profile.\n");
16510         else if (file_num == 2)
16511                 save_file(file_fld[1], buff, size);
16512
16513         close_file(buff);
16514         free((void *)filepath);
16515 }
16516
16517 cmdline_parse_inst_t cmd_ddp_add = {
16518         .f = cmd_ddp_add_parsed,
16519         .data = NULL,
16520         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16521         .tokens = {
16522                 (void *)&cmd_ddp_add_ddp,
16523                 (void *)&cmd_ddp_add_add,
16524                 (void *)&cmd_ddp_add_port_id,
16525                 (void *)&cmd_ddp_add_filepath,
16526                 NULL,
16527         },
16528 };
16529
16530 /* Delete dynamic device personalization*/
16531 struct cmd_ddp_del_result {
16532         cmdline_fixed_string_t ddp;
16533         cmdline_fixed_string_t del;
16534         portid_t port_id;
16535         char filepath[];
16536 };
16537
16538 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16539         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16540 cmdline_parse_token_string_t cmd_ddp_del_del =
16541         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16542 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16543         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16544 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16545         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16546
16547 static void
16548 cmd_ddp_del_parsed(
16549         void *parsed_result,
16550         __rte_unused struct cmdline *cl,
16551         __rte_unused void *data)
16552 {
16553         struct cmd_ddp_del_result *res = parsed_result;
16554         uint8_t *buff;
16555         uint32_t size;
16556         int ret = -ENOTSUP;
16557
16558         if (!all_ports_stopped()) {
16559                 printf("Please stop all ports first\n");
16560                 return;
16561         }
16562
16563         buff = open_file(res->filepath, &size);
16564         if (!buff)
16565                 return;
16566
16567 #ifdef RTE_LIBRTE_I40E_PMD
16568         if (ret == -ENOTSUP)
16569                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16570                                                buff, size,
16571                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16572 #endif
16573
16574         if (ret == -EACCES)
16575                 printf("Profile does not exist.\n");
16576         else if (ret < 0)
16577                 printf("Failed to delete profile.\n");
16578
16579         close_file(buff);
16580 }
16581
16582 cmdline_parse_inst_t cmd_ddp_del = {
16583         .f = cmd_ddp_del_parsed,
16584         .data = NULL,
16585         .help_str = "ddp del <port_id> <backup_profile_path>",
16586         .tokens = {
16587                 (void *)&cmd_ddp_del_ddp,
16588                 (void *)&cmd_ddp_del_del,
16589                 (void *)&cmd_ddp_del_port_id,
16590                 (void *)&cmd_ddp_del_filepath,
16591                 NULL,
16592         },
16593 };
16594
16595 /* Get dynamic device personalization profile info */
16596 struct cmd_ddp_info_result {
16597         cmdline_fixed_string_t ddp;
16598         cmdline_fixed_string_t get;
16599         cmdline_fixed_string_t info;
16600         char filepath[];
16601 };
16602
16603 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16604         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16605 cmdline_parse_token_string_t cmd_ddp_info_get =
16606         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16607 cmdline_parse_token_string_t cmd_ddp_info_info =
16608         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16609 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16610         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16611
16612 static void
16613 cmd_ddp_info_parsed(
16614         void *parsed_result,
16615         __rte_unused struct cmdline *cl,
16616         __rte_unused void *data)
16617 {
16618         struct cmd_ddp_info_result *res = parsed_result;
16619         uint8_t *pkg;
16620         uint32_t pkg_size;
16621         int ret = -ENOTSUP;
16622 #ifdef RTE_LIBRTE_I40E_PMD
16623         uint32_t i, j, n;
16624         uint8_t *buff;
16625         uint32_t buff_size = 0;
16626         struct rte_pmd_i40e_profile_info info;
16627         uint32_t dev_num = 0;
16628         struct rte_pmd_i40e_ddp_device_id *devs;
16629         uint32_t proto_num = 0;
16630         struct rte_pmd_i40e_proto_info *proto = NULL;
16631         uint32_t pctype_num = 0;
16632         struct rte_pmd_i40e_ptype_info *pctype;
16633         uint32_t ptype_num = 0;
16634         struct rte_pmd_i40e_ptype_info *ptype;
16635         uint8_t proto_id;
16636
16637 #endif
16638
16639         pkg = open_file(res->filepath, &pkg_size);
16640         if (!pkg)
16641                 return;
16642
16643 #ifdef RTE_LIBRTE_I40E_PMD
16644         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16645                                 (uint8_t *)&info, sizeof(info),
16646                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16647         if (!ret) {
16648                 printf("Global Track id:       0x%x\n", info.track_id);
16649                 printf("Global Version:        %d.%d.%d.%d\n",
16650                         info.version.major,
16651                         info.version.minor,
16652                         info.version.update,
16653                         info.version.draft);
16654                 printf("Global Package name:   %s\n\n", info.name);
16655         }
16656
16657         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16658                                 (uint8_t *)&info, sizeof(info),
16659                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16660         if (!ret) {
16661                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16662                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16663                         info.version.major,
16664                         info.version.minor,
16665                         info.version.update,
16666                         info.version.draft);
16667                 printf("i40e Profile name:     %s\n\n", info.name);
16668         }
16669
16670         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16671                                 (uint8_t *)&buff_size, sizeof(buff_size),
16672                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16673         if (!ret && buff_size) {
16674                 buff = (uint8_t *)malloc(buff_size);
16675                 if (buff) {
16676                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16677                                                 buff, buff_size,
16678                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16679                         if (!ret)
16680                                 printf("Package Notes:\n%s\n\n", buff);
16681                         free(buff);
16682                 }
16683         }
16684
16685         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16686                                 (uint8_t *)&dev_num, sizeof(dev_num),
16687                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16688         if (!ret && dev_num) {
16689                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16690                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16691                 if (devs) {
16692                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16693                                                 (uint8_t *)devs, buff_size,
16694                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16695                         if (!ret) {
16696                                 printf("List of supported devices:\n");
16697                                 for (i = 0; i < dev_num; i++) {
16698                                         printf("  %04X:%04X %04X:%04X\n",
16699                                                 devs[i].vendor_dev_id >> 16,
16700                                                 devs[i].vendor_dev_id & 0xFFFF,
16701                                                 devs[i].sub_vendor_dev_id >> 16,
16702                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16703                                 }
16704                                 printf("\n");
16705                         }
16706                         free(devs);
16707                 }
16708         }
16709
16710         /* get information about protocols and packet types */
16711         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16712                 (uint8_t *)&proto_num, sizeof(proto_num),
16713                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16714         if (ret || !proto_num)
16715                 goto no_print_return;
16716
16717         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16718         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16719         if (!proto)
16720                 goto no_print_return;
16721
16722         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16723                                         buff_size,
16724                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16725         if (!ret) {
16726                 printf("List of used protocols:\n");
16727                 for (i = 0; i < proto_num; i++)
16728                         printf("  %2u: %s\n", proto[i].proto_id,
16729                                proto[i].name);
16730                 printf("\n");
16731         }
16732         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16733                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16734                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16735         if (ret || !pctype_num)
16736                 goto no_print_pctypes;
16737
16738         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16739         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16740         if (!pctype)
16741                 goto no_print_pctypes;
16742
16743         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16744                                         buff_size,
16745                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16746         if (ret) {
16747                 free(pctype);
16748                 goto no_print_pctypes;
16749         }
16750
16751         printf("List of defined packet classification types:\n");
16752         for (i = 0; i < pctype_num; i++) {
16753                 printf("  %2u:", pctype[i].ptype_id);
16754                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16755                         proto_id = pctype[i].protocols[j];
16756                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16757                                 for (n = 0; n < proto_num; n++) {
16758                                         if (proto[n].proto_id == proto_id) {
16759                                                 printf(" %s", proto[n].name);
16760                                                 break;
16761                                         }
16762                                 }
16763                         }
16764                 }
16765                 printf("\n");
16766         }
16767         printf("\n");
16768         free(pctype);
16769
16770 no_print_pctypes:
16771
16772         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16773                                         sizeof(ptype_num),
16774                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16775         if (ret || !ptype_num)
16776                 goto no_print_return;
16777
16778         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16779         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16780         if (!ptype)
16781                 goto no_print_return;
16782
16783         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16784                                         buff_size,
16785                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16786         if (ret) {
16787                 free(ptype);
16788                 goto no_print_return;
16789         }
16790         printf("List of defined packet types:\n");
16791         for (i = 0; i < ptype_num; i++) {
16792                 printf("  %2u:", ptype[i].ptype_id);
16793                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16794                         proto_id = ptype[i].protocols[j];
16795                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16796                                 for (n = 0; n < proto_num; n++) {
16797                                         if (proto[n].proto_id == proto_id) {
16798                                                 printf(" %s", proto[n].name);
16799                                                 break;
16800                                         }
16801                                 }
16802                         }
16803                 }
16804                 printf("\n");
16805         }
16806         free(ptype);
16807         printf("\n");
16808
16809         ret = 0;
16810 no_print_return:
16811         if (proto)
16812                 free(proto);
16813 #endif
16814         if (ret == -ENOTSUP)
16815                 printf("Function not supported in PMD driver\n");
16816         close_file(pkg);
16817 }
16818
16819 cmdline_parse_inst_t cmd_ddp_get_info = {
16820         .f = cmd_ddp_info_parsed,
16821         .data = NULL,
16822         .help_str = "ddp get info <profile_path>",
16823         .tokens = {
16824                 (void *)&cmd_ddp_info_ddp,
16825                 (void *)&cmd_ddp_info_get,
16826                 (void *)&cmd_ddp_info_info,
16827                 (void *)&cmd_ddp_info_filepath,
16828                 NULL,
16829         },
16830 };
16831
16832 /* Get dynamic device personalization profile info list*/
16833 #define PROFILE_INFO_SIZE 48
16834 #define MAX_PROFILE_NUM 16
16835
16836 struct cmd_ddp_get_list_result {
16837         cmdline_fixed_string_t ddp;
16838         cmdline_fixed_string_t get;
16839         cmdline_fixed_string_t list;
16840         portid_t port_id;
16841 };
16842
16843 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16844         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16845 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16846         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16847 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16848         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16849 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16850         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16851
16852 static void
16853 cmd_ddp_get_list_parsed(
16854         __rte_unused void *parsed_result,
16855         __rte_unused struct cmdline *cl,
16856         __rte_unused void *data)
16857 {
16858 #ifdef RTE_LIBRTE_I40E_PMD
16859         struct cmd_ddp_get_list_result *res = parsed_result;
16860         struct rte_pmd_i40e_profile_list *p_list;
16861         struct rte_pmd_i40e_profile_info *p_info;
16862         uint32_t p_num;
16863         uint32_t size;
16864         uint32_t i;
16865 #endif
16866         int ret = -ENOTSUP;
16867
16868 #ifdef RTE_LIBRTE_I40E_PMD
16869         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16870         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16871         if (!p_list)
16872                 printf("%s: Failed to malloc buffer\n", __func__);
16873
16874         if (ret == -ENOTSUP)
16875                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16876                                                 (uint8_t *)p_list, size);
16877
16878         if (!ret) {
16879                 p_num = p_list->p_count;
16880                 printf("Profile number is: %d\n\n", p_num);
16881
16882                 for (i = 0; i < p_num; i++) {
16883                         p_info = &p_list->p_info[i];
16884                         printf("Profile %d:\n", i);
16885                         printf("Track id:     0x%x\n", p_info->track_id);
16886                         printf("Version:      %d.%d.%d.%d\n",
16887                                p_info->version.major,
16888                                p_info->version.minor,
16889                                p_info->version.update,
16890                                p_info->version.draft);
16891                         printf("Profile name: %s\n\n", p_info->name);
16892                 }
16893         }
16894
16895         free(p_list);
16896 #endif
16897
16898         if (ret < 0)
16899                 printf("Failed to get ddp list\n");
16900 }
16901
16902 cmdline_parse_inst_t cmd_ddp_get_list = {
16903         .f = cmd_ddp_get_list_parsed,
16904         .data = NULL,
16905         .help_str = "ddp get list <port_id>",
16906         .tokens = {
16907                 (void *)&cmd_ddp_get_list_ddp,
16908                 (void *)&cmd_ddp_get_list_get,
16909                 (void *)&cmd_ddp_get_list_list,
16910                 (void *)&cmd_ddp_get_list_port_id,
16911                 NULL,
16912         },
16913 };
16914
16915 /* Configure input set */
16916 struct cmd_cfg_input_set_result {
16917         cmdline_fixed_string_t port;
16918         cmdline_fixed_string_t cfg;
16919         portid_t port_id;
16920         cmdline_fixed_string_t pctype;
16921         uint8_t pctype_id;
16922         cmdline_fixed_string_t inset_type;
16923         cmdline_fixed_string_t opt;
16924         cmdline_fixed_string_t field;
16925         uint8_t field_idx;
16926 };
16927
16928 static void
16929 cmd_cfg_input_set_parsed(
16930         __rte_unused void *parsed_result,
16931         __rte_unused struct cmdline *cl,
16932         __rte_unused void *data)
16933 {
16934 #ifdef RTE_LIBRTE_I40E_PMD
16935         struct cmd_cfg_input_set_result *res = parsed_result;
16936         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16937         struct rte_pmd_i40e_inset inset;
16938 #endif
16939         int ret = -ENOTSUP;
16940
16941         if (!all_ports_stopped()) {
16942                 printf("Please stop all ports first\n");
16943                 return;
16944         }
16945
16946 #ifdef RTE_LIBRTE_I40E_PMD
16947         if (!strcmp(res->inset_type, "hash_inset"))
16948                 inset_type = INSET_HASH;
16949         else if (!strcmp(res->inset_type, "fdir_inset"))
16950                 inset_type = INSET_FDIR;
16951         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16952                 inset_type = INSET_FDIR_FLX;
16953         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16954                                      &inset, inset_type);
16955         if (ret) {
16956                 printf("Failed to get input set.\n");
16957                 return;
16958         }
16959
16960         if (!strcmp(res->opt, "get")) {
16961                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16962                                                    res->field_idx);
16963                 if (ret)
16964                         printf("Field index %d is enabled.\n", res->field_idx);
16965                 else
16966                         printf("Field index %d is disabled.\n", res->field_idx);
16967                 return;
16968         } else if (!strcmp(res->opt, "set"))
16969                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16970                                                    res->field_idx);
16971         else if (!strcmp(res->opt, "clear"))
16972                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16973                                                      res->field_idx);
16974         if (ret) {
16975                 printf("Failed to configure input set field.\n");
16976                 return;
16977         }
16978
16979         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16980                                      &inset, inset_type);
16981         if (ret) {
16982                 printf("Failed to set input set.\n");
16983                 return;
16984         }
16985 #endif
16986
16987         if (ret == -ENOTSUP)
16988                 printf("Function not supported\n");
16989 }
16990
16991 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16992         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16993                                  port, "port");
16994 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16995         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16996                                  cfg, "config");
16997 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16998         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16999                               port_id, UINT16);
17000 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17001         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17002                                  pctype, "pctype");
17003 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17004         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17005                               pctype_id, UINT8);
17006 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17007         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17008                                  inset_type,
17009                                  "hash_inset#fdir_inset#fdir_flx_inset");
17010 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17011         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17012                                  opt, "get#set#clear");
17013 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17014         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17015                                  field, "field");
17016 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17017         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17018                               field_idx, UINT8);
17019
17020 cmdline_parse_inst_t cmd_cfg_input_set = {
17021         .f = cmd_cfg_input_set_parsed,
17022         .data = NULL,
17023         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17024                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17025         .tokens = {
17026                 (void *)&cmd_cfg_input_set_port,
17027                 (void *)&cmd_cfg_input_set_cfg,
17028                 (void *)&cmd_cfg_input_set_port_id,
17029                 (void *)&cmd_cfg_input_set_pctype,
17030                 (void *)&cmd_cfg_input_set_pctype_id,
17031                 (void *)&cmd_cfg_input_set_inset_type,
17032                 (void *)&cmd_cfg_input_set_opt,
17033                 (void *)&cmd_cfg_input_set_field,
17034                 (void *)&cmd_cfg_input_set_field_idx,
17035                 NULL,
17036         },
17037 };
17038
17039 /* Clear input set */
17040 struct cmd_clear_input_set_result {
17041         cmdline_fixed_string_t port;
17042         cmdline_fixed_string_t cfg;
17043         portid_t port_id;
17044         cmdline_fixed_string_t pctype;
17045         uint8_t pctype_id;
17046         cmdline_fixed_string_t inset_type;
17047         cmdline_fixed_string_t clear;
17048         cmdline_fixed_string_t all;
17049 };
17050
17051 static void
17052 cmd_clear_input_set_parsed(
17053         __rte_unused void *parsed_result,
17054         __rte_unused struct cmdline *cl,
17055         __rte_unused void *data)
17056 {
17057 #ifdef RTE_LIBRTE_I40E_PMD
17058         struct cmd_clear_input_set_result *res = parsed_result;
17059         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17060         struct rte_pmd_i40e_inset inset;
17061 #endif
17062         int ret = -ENOTSUP;
17063
17064         if (!all_ports_stopped()) {
17065                 printf("Please stop all ports first\n");
17066                 return;
17067         }
17068
17069 #ifdef RTE_LIBRTE_I40E_PMD
17070         if (!strcmp(res->inset_type, "hash_inset"))
17071                 inset_type = INSET_HASH;
17072         else if (!strcmp(res->inset_type, "fdir_inset"))
17073                 inset_type = INSET_FDIR;
17074         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17075                 inset_type = INSET_FDIR_FLX;
17076
17077         memset(&inset, 0, sizeof(inset));
17078
17079         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17080                                      &inset, inset_type);
17081         if (ret) {
17082                 printf("Failed to clear input set.\n");
17083                 return;
17084         }
17085
17086 #endif
17087
17088         if (ret == -ENOTSUP)
17089                 printf("Function not supported\n");
17090 }
17091
17092 cmdline_parse_token_string_t cmd_clear_input_set_port =
17093         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17094                                  port, "port");
17095 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17096         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17097                                  cfg, "config");
17098 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17099         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17100                               port_id, UINT16);
17101 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17102         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17103                                  pctype, "pctype");
17104 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17105         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17106                               pctype_id, UINT8);
17107 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17108         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17109                                  inset_type,
17110                                  "hash_inset#fdir_inset#fdir_flx_inset");
17111 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17112         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17113                                  clear, "clear");
17114 cmdline_parse_token_string_t cmd_clear_input_set_all =
17115         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17116                                  all, "all");
17117
17118 cmdline_parse_inst_t cmd_clear_input_set = {
17119         .f = cmd_clear_input_set_parsed,
17120         .data = NULL,
17121         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17122                     "fdir_inset|fdir_flx_inset clear all",
17123         .tokens = {
17124                 (void *)&cmd_clear_input_set_port,
17125                 (void *)&cmd_clear_input_set_cfg,
17126                 (void *)&cmd_clear_input_set_port_id,
17127                 (void *)&cmd_clear_input_set_pctype,
17128                 (void *)&cmd_clear_input_set_pctype_id,
17129                 (void *)&cmd_clear_input_set_inset_type,
17130                 (void *)&cmd_clear_input_set_clear,
17131                 (void *)&cmd_clear_input_set_all,
17132                 NULL,
17133         },
17134 };
17135
17136 /* show vf stats */
17137
17138 /* Common result structure for show vf stats */
17139 struct cmd_show_vf_stats_result {
17140         cmdline_fixed_string_t show;
17141         cmdline_fixed_string_t vf;
17142         cmdline_fixed_string_t stats;
17143         portid_t port_id;
17144         uint16_t vf_id;
17145 };
17146
17147 /* Common CLI fields show vf stats*/
17148 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17149         TOKEN_STRING_INITIALIZER
17150                 (struct cmd_show_vf_stats_result,
17151                  show, "show");
17152 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17153         TOKEN_STRING_INITIALIZER
17154                 (struct cmd_show_vf_stats_result,
17155                  vf, "vf");
17156 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17157         TOKEN_STRING_INITIALIZER
17158                 (struct cmd_show_vf_stats_result,
17159                  stats, "stats");
17160 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17161         TOKEN_NUM_INITIALIZER
17162                 (struct cmd_show_vf_stats_result,
17163                  port_id, UINT16);
17164 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17165         TOKEN_NUM_INITIALIZER
17166                 (struct cmd_show_vf_stats_result,
17167                  vf_id, UINT16);
17168
17169 static void
17170 cmd_show_vf_stats_parsed(
17171         void *parsed_result,
17172         __rte_unused struct cmdline *cl,
17173         __rte_unused void *data)
17174 {
17175         struct cmd_show_vf_stats_result *res = parsed_result;
17176         struct rte_eth_stats stats;
17177         int ret = -ENOTSUP;
17178         static const char *nic_stats_border = "########################";
17179
17180         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17181                 return;
17182
17183         memset(&stats, 0, sizeof(stats));
17184
17185 #ifdef RTE_LIBRTE_I40E_PMD
17186         if (ret == -ENOTSUP)
17187                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17188                                                 res->vf_id,
17189                                                 &stats);
17190 #endif
17191 #ifdef RTE_LIBRTE_BNXT_PMD
17192         if (ret == -ENOTSUP)
17193                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17194                                                 res->vf_id,
17195                                                 &stats);
17196 #endif
17197
17198         switch (ret) {
17199         case 0:
17200                 break;
17201         case -EINVAL:
17202                 printf("invalid vf_id %d\n", res->vf_id);
17203                 break;
17204         case -ENODEV:
17205                 printf("invalid port_id %d\n", res->port_id);
17206                 break;
17207         case -ENOTSUP:
17208                 printf("function not implemented\n");
17209                 break;
17210         default:
17211                 printf("programming error: (%s)\n", strerror(-ret));
17212         }
17213
17214         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17215                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17216
17217         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17218                "%-"PRIu64"\n",
17219                stats.ipackets, stats.imissed, stats.ibytes);
17220         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17221         printf("  RX-nombuf:  %-10"PRIu64"\n",
17222                stats.rx_nombuf);
17223         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17224                "%-"PRIu64"\n",
17225                stats.opackets, stats.oerrors, stats.obytes);
17226
17227         printf("  %s############################%s\n",
17228                                nic_stats_border, nic_stats_border);
17229 }
17230
17231 cmdline_parse_inst_t cmd_show_vf_stats = {
17232         .f = cmd_show_vf_stats_parsed,
17233         .data = NULL,
17234         .help_str = "show vf stats <port_id> <vf_id>",
17235         .tokens = {
17236                 (void *)&cmd_show_vf_stats_show,
17237                 (void *)&cmd_show_vf_stats_vf,
17238                 (void *)&cmd_show_vf_stats_stats,
17239                 (void *)&cmd_show_vf_stats_port_id,
17240                 (void *)&cmd_show_vf_stats_vf_id,
17241                 NULL,
17242         },
17243 };
17244
17245 /* clear vf stats */
17246
17247 /* Common result structure for clear vf stats */
17248 struct cmd_clear_vf_stats_result {
17249         cmdline_fixed_string_t clear;
17250         cmdline_fixed_string_t vf;
17251         cmdline_fixed_string_t stats;
17252         portid_t port_id;
17253         uint16_t vf_id;
17254 };
17255
17256 /* Common CLI fields clear vf stats*/
17257 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17258         TOKEN_STRING_INITIALIZER
17259                 (struct cmd_clear_vf_stats_result,
17260                  clear, "clear");
17261 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17262         TOKEN_STRING_INITIALIZER
17263                 (struct cmd_clear_vf_stats_result,
17264                  vf, "vf");
17265 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17266         TOKEN_STRING_INITIALIZER
17267                 (struct cmd_clear_vf_stats_result,
17268                  stats, "stats");
17269 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17270         TOKEN_NUM_INITIALIZER
17271                 (struct cmd_clear_vf_stats_result,
17272                  port_id, UINT16);
17273 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17274         TOKEN_NUM_INITIALIZER
17275                 (struct cmd_clear_vf_stats_result,
17276                  vf_id, UINT16);
17277
17278 static void
17279 cmd_clear_vf_stats_parsed(
17280         void *parsed_result,
17281         __rte_unused struct cmdline *cl,
17282         __rte_unused void *data)
17283 {
17284         struct cmd_clear_vf_stats_result *res = parsed_result;
17285         int ret = -ENOTSUP;
17286
17287         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17288                 return;
17289
17290 #ifdef RTE_LIBRTE_I40E_PMD
17291         if (ret == -ENOTSUP)
17292                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17293                                                   res->vf_id);
17294 #endif
17295 #ifdef RTE_LIBRTE_BNXT_PMD
17296         if (ret == -ENOTSUP)
17297                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17298                                                   res->vf_id);
17299 #endif
17300
17301         switch (ret) {
17302         case 0:
17303                 break;
17304         case -EINVAL:
17305                 printf("invalid vf_id %d\n", res->vf_id);
17306                 break;
17307         case -ENODEV:
17308                 printf("invalid port_id %d\n", res->port_id);
17309                 break;
17310         case -ENOTSUP:
17311                 printf("function not implemented\n");
17312                 break;
17313         default:
17314                 printf("programming error: (%s)\n", strerror(-ret));
17315         }
17316 }
17317
17318 cmdline_parse_inst_t cmd_clear_vf_stats = {
17319         .f = cmd_clear_vf_stats_parsed,
17320         .data = NULL,
17321         .help_str = "clear vf stats <port_id> <vf_id>",
17322         .tokens = {
17323                 (void *)&cmd_clear_vf_stats_clear,
17324                 (void *)&cmd_clear_vf_stats_vf,
17325                 (void *)&cmd_clear_vf_stats_stats,
17326                 (void *)&cmd_clear_vf_stats_port_id,
17327                 (void *)&cmd_clear_vf_stats_vf_id,
17328                 NULL,
17329         },
17330 };
17331
17332 /* port config pctype mapping reset */
17333
17334 /* Common result structure for port config pctype mapping reset */
17335 struct cmd_pctype_mapping_reset_result {
17336         cmdline_fixed_string_t port;
17337         cmdline_fixed_string_t config;
17338         portid_t port_id;
17339         cmdline_fixed_string_t pctype;
17340         cmdline_fixed_string_t mapping;
17341         cmdline_fixed_string_t reset;
17342 };
17343
17344 /* Common CLI fields for port config pctype mapping reset*/
17345 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17346         TOKEN_STRING_INITIALIZER
17347                 (struct cmd_pctype_mapping_reset_result,
17348                  port, "port");
17349 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17350         TOKEN_STRING_INITIALIZER
17351                 (struct cmd_pctype_mapping_reset_result,
17352                  config, "config");
17353 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17354         TOKEN_NUM_INITIALIZER
17355                 (struct cmd_pctype_mapping_reset_result,
17356                  port_id, UINT16);
17357 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17358         TOKEN_STRING_INITIALIZER
17359                 (struct cmd_pctype_mapping_reset_result,
17360                  pctype, "pctype");
17361 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17362         TOKEN_STRING_INITIALIZER
17363                 (struct cmd_pctype_mapping_reset_result,
17364                  mapping, "mapping");
17365 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17366         TOKEN_STRING_INITIALIZER
17367                 (struct cmd_pctype_mapping_reset_result,
17368                  reset, "reset");
17369
17370 static void
17371 cmd_pctype_mapping_reset_parsed(
17372         void *parsed_result,
17373         __rte_unused struct cmdline *cl,
17374         __rte_unused void *data)
17375 {
17376         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17377         int ret = -ENOTSUP;
17378
17379         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17380                 return;
17381
17382 #ifdef RTE_LIBRTE_I40E_PMD
17383         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17384 #endif
17385
17386         switch (ret) {
17387         case 0:
17388                 break;
17389         case -ENODEV:
17390                 printf("invalid port_id %d\n", res->port_id);
17391                 break;
17392         case -ENOTSUP:
17393                 printf("function not implemented\n");
17394                 break;
17395         default:
17396                 printf("programming error: (%s)\n", strerror(-ret));
17397         }
17398 }
17399
17400 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17401         .f = cmd_pctype_mapping_reset_parsed,
17402         .data = NULL,
17403         .help_str = "port config <port_id> pctype mapping reset",
17404         .tokens = {
17405                 (void *)&cmd_pctype_mapping_reset_port,
17406                 (void *)&cmd_pctype_mapping_reset_config,
17407                 (void *)&cmd_pctype_mapping_reset_port_id,
17408                 (void *)&cmd_pctype_mapping_reset_pctype,
17409                 (void *)&cmd_pctype_mapping_reset_mapping,
17410                 (void *)&cmd_pctype_mapping_reset_reset,
17411                 NULL,
17412         },
17413 };
17414
17415 /* show port pctype mapping */
17416
17417 /* Common result structure for show port pctype mapping */
17418 struct cmd_pctype_mapping_get_result {
17419         cmdline_fixed_string_t show;
17420         cmdline_fixed_string_t port;
17421         portid_t port_id;
17422         cmdline_fixed_string_t pctype;
17423         cmdline_fixed_string_t mapping;
17424 };
17425
17426 /* Common CLI fields for pctype mapping get */
17427 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17428         TOKEN_STRING_INITIALIZER
17429                 (struct cmd_pctype_mapping_get_result,
17430                  show, "show");
17431 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17432         TOKEN_STRING_INITIALIZER
17433                 (struct cmd_pctype_mapping_get_result,
17434                  port, "port");
17435 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17436         TOKEN_NUM_INITIALIZER
17437                 (struct cmd_pctype_mapping_get_result,
17438                  port_id, UINT16);
17439 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17440         TOKEN_STRING_INITIALIZER
17441                 (struct cmd_pctype_mapping_get_result,
17442                  pctype, "pctype");
17443 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17444         TOKEN_STRING_INITIALIZER
17445                 (struct cmd_pctype_mapping_get_result,
17446                  mapping, "mapping");
17447
17448 static void
17449 cmd_pctype_mapping_get_parsed(
17450         void *parsed_result,
17451         __rte_unused struct cmdline *cl,
17452         __rte_unused void *data)
17453 {
17454         struct cmd_pctype_mapping_get_result *res = parsed_result;
17455         int ret = -ENOTSUP;
17456 #ifdef RTE_LIBRTE_I40E_PMD
17457         struct rte_pmd_i40e_flow_type_mapping
17458                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17459         int i, j, first_pctype;
17460 #endif
17461
17462         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17463                 return;
17464
17465 #ifdef RTE_LIBRTE_I40E_PMD
17466         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17467 #endif
17468
17469         switch (ret) {
17470         case 0:
17471                 break;
17472         case -ENODEV:
17473                 printf("invalid port_id %d\n", res->port_id);
17474                 return;
17475         case -ENOTSUP:
17476                 printf("function not implemented\n");
17477                 return;
17478         default:
17479                 printf("programming error: (%s)\n", strerror(-ret));
17480                 return;
17481         }
17482
17483 #ifdef RTE_LIBRTE_I40E_PMD
17484         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17485                 if (mapping[i].pctype != 0ULL) {
17486                         first_pctype = 1;
17487
17488                         printf("pctype: ");
17489                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17490                                 if (mapping[i].pctype & (1ULL << j)) {
17491                                         printf(first_pctype ?
17492                                                "%02d" : ",%02d", j);
17493                                         first_pctype = 0;
17494                                 }
17495                         }
17496                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17497                 }
17498         }
17499 #endif
17500 }
17501
17502 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17503         .f = cmd_pctype_mapping_get_parsed,
17504         .data = NULL,
17505         .help_str = "show port <port_id> pctype mapping",
17506         .tokens = {
17507                 (void *)&cmd_pctype_mapping_get_show,
17508                 (void *)&cmd_pctype_mapping_get_port,
17509                 (void *)&cmd_pctype_mapping_get_port_id,
17510                 (void *)&cmd_pctype_mapping_get_pctype,
17511                 (void *)&cmd_pctype_mapping_get_mapping,
17512                 NULL,
17513         },
17514 };
17515
17516 /* port config pctype mapping update */
17517
17518 /* Common result structure for port config pctype mapping update */
17519 struct cmd_pctype_mapping_update_result {
17520         cmdline_fixed_string_t port;
17521         cmdline_fixed_string_t config;
17522         portid_t port_id;
17523         cmdline_fixed_string_t pctype;
17524         cmdline_fixed_string_t mapping;
17525         cmdline_fixed_string_t update;
17526         cmdline_fixed_string_t pctype_list;
17527         uint16_t flow_type;
17528 };
17529
17530 /* Common CLI fields for pctype mapping update*/
17531 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17532         TOKEN_STRING_INITIALIZER
17533                 (struct cmd_pctype_mapping_update_result,
17534                  port, "port");
17535 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17536         TOKEN_STRING_INITIALIZER
17537                 (struct cmd_pctype_mapping_update_result,
17538                  config, "config");
17539 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17540         TOKEN_NUM_INITIALIZER
17541                 (struct cmd_pctype_mapping_update_result,
17542                  port_id, UINT16);
17543 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17544         TOKEN_STRING_INITIALIZER
17545                 (struct cmd_pctype_mapping_update_result,
17546                  pctype, "pctype");
17547 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17548         TOKEN_STRING_INITIALIZER
17549                 (struct cmd_pctype_mapping_update_result,
17550                  mapping, "mapping");
17551 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17552         TOKEN_STRING_INITIALIZER
17553                 (struct cmd_pctype_mapping_update_result,
17554                  update, "update");
17555 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17556         TOKEN_STRING_INITIALIZER
17557                 (struct cmd_pctype_mapping_update_result,
17558                  pctype_list, NULL);
17559 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17560         TOKEN_NUM_INITIALIZER
17561                 (struct cmd_pctype_mapping_update_result,
17562                  flow_type, UINT16);
17563
17564 static void
17565 cmd_pctype_mapping_update_parsed(
17566         void *parsed_result,
17567         __rte_unused struct cmdline *cl,
17568         __rte_unused void *data)
17569 {
17570         struct cmd_pctype_mapping_update_result *res = parsed_result;
17571         int ret = -ENOTSUP;
17572 #ifdef RTE_LIBRTE_I40E_PMD
17573         struct rte_pmd_i40e_flow_type_mapping mapping;
17574         unsigned int i;
17575         unsigned int nb_item;
17576         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17577 #endif
17578
17579         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17580                 return;
17581
17582 #ifdef RTE_LIBRTE_I40E_PMD
17583         nb_item = parse_item_list(res->pctype_list, "pctypes",
17584                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17585         mapping.flow_type = res->flow_type;
17586         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17587                 mapping.pctype |= (1ULL << pctype_list[i]);
17588         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17589                                                 &mapping,
17590                                                 1,
17591                                                 0);
17592 #endif
17593
17594         switch (ret) {
17595         case 0:
17596                 break;
17597         case -EINVAL:
17598                 printf("invalid pctype or flow type\n");
17599                 break;
17600         case -ENODEV:
17601                 printf("invalid port_id %d\n", res->port_id);
17602                 break;
17603         case -ENOTSUP:
17604                 printf("function not implemented\n");
17605                 break;
17606         default:
17607                 printf("programming error: (%s)\n", strerror(-ret));
17608         }
17609 }
17610
17611 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17612         .f = cmd_pctype_mapping_update_parsed,
17613         .data = NULL,
17614         .help_str = "port config <port_id> pctype mapping update"
17615         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17616         .tokens = {
17617                 (void *)&cmd_pctype_mapping_update_port,
17618                 (void *)&cmd_pctype_mapping_update_config,
17619                 (void *)&cmd_pctype_mapping_update_port_id,
17620                 (void *)&cmd_pctype_mapping_update_pctype,
17621                 (void *)&cmd_pctype_mapping_update_mapping,
17622                 (void *)&cmd_pctype_mapping_update_update,
17623                 (void *)&cmd_pctype_mapping_update_pc_type,
17624                 (void *)&cmd_pctype_mapping_update_flow_type,
17625                 NULL,
17626         },
17627 };
17628
17629 /* ptype mapping get */
17630
17631 /* Common result structure for ptype mapping get */
17632 struct cmd_ptype_mapping_get_result {
17633         cmdline_fixed_string_t ptype;
17634         cmdline_fixed_string_t mapping;
17635         cmdline_fixed_string_t get;
17636         portid_t port_id;
17637         uint8_t valid_only;
17638 };
17639
17640 /* Common CLI fields for ptype mapping get */
17641 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17642         TOKEN_STRING_INITIALIZER
17643                 (struct cmd_ptype_mapping_get_result,
17644                  ptype, "ptype");
17645 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17646         TOKEN_STRING_INITIALIZER
17647                 (struct cmd_ptype_mapping_get_result,
17648                  mapping, "mapping");
17649 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17650         TOKEN_STRING_INITIALIZER
17651                 (struct cmd_ptype_mapping_get_result,
17652                  get, "get");
17653 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17654         TOKEN_NUM_INITIALIZER
17655                 (struct cmd_ptype_mapping_get_result,
17656                  port_id, UINT16);
17657 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17658         TOKEN_NUM_INITIALIZER
17659                 (struct cmd_ptype_mapping_get_result,
17660                  valid_only, UINT8);
17661
17662 static void
17663 cmd_ptype_mapping_get_parsed(
17664         void *parsed_result,
17665         __rte_unused struct cmdline *cl,
17666         __rte_unused void *data)
17667 {
17668         struct cmd_ptype_mapping_get_result *res = parsed_result;
17669         int ret = -ENOTSUP;
17670 #ifdef RTE_LIBRTE_I40E_PMD
17671         int max_ptype_num = 256;
17672         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17673         uint16_t count;
17674         int i;
17675 #endif
17676
17677         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17678                 return;
17679
17680 #ifdef RTE_LIBRTE_I40E_PMD
17681         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17682                                         mapping,
17683                                         max_ptype_num,
17684                                         &count,
17685                                         res->valid_only);
17686 #endif
17687
17688         switch (ret) {
17689         case 0:
17690                 break;
17691         case -ENODEV:
17692                 printf("invalid port_id %d\n", res->port_id);
17693                 break;
17694         case -ENOTSUP:
17695                 printf("function not implemented\n");
17696                 break;
17697         default:
17698                 printf("programming error: (%s)\n", strerror(-ret));
17699         }
17700
17701 #ifdef RTE_LIBRTE_I40E_PMD
17702         if (!ret) {
17703                 for (i = 0; i < count; i++)
17704                         printf("%3d\t0x%08x\n",
17705                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17706         }
17707 #endif
17708 }
17709
17710 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17711         .f = cmd_ptype_mapping_get_parsed,
17712         .data = NULL,
17713         .help_str = "ptype mapping get <port_id> <valid_only>",
17714         .tokens = {
17715                 (void *)&cmd_ptype_mapping_get_ptype,
17716                 (void *)&cmd_ptype_mapping_get_mapping,
17717                 (void *)&cmd_ptype_mapping_get_get,
17718                 (void *)&cmd_ptype_mapping_get_port_id,
17719                 (void *)&cmd_ptype_mapping_get_valid_only,
17720                 NULL,
17721         },
17722 };
17723
17724 /* ptype mapping replace */
17725
17726 /* Common result structure for ptype mapping replace */
17727 struct cmd_ptype_mapping_replace_result {
17728         cmdline_fixed_string_t ptype;
17729         cmdline_fixed_string_t mapping;
17730         cmdline_fixed_string_t replace;
17731         portid_t port_id;
17732         uint32_t target;
17733         uint8_t mask;
17734         uint32_t pkt_type;
17735 };
17736
17737 /* Common CLI fields for ptype mapping replace */
17738 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17739         TOKEN_STRING_INITIALIZER
17740                 (struct cmd_ptype_mapping_replace_result,
17741                  ptype, "ptype");
17742 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17743         TOKEN_STRING_INITIALIZER
17744                 (struct cmd_ptype_mapping_replace_result,
17745                  mapping, "mapping");
17746 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17747         TOKEN_STRING_INITIALIZER
17748                 (struct cmd_ptype_mapping_replace_result,
17749                  replace, "replace");
17750 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17751         TOKEN_NUM_INITIALIZER
17752                 (struct cmd_ptype_mapping_replace_result,
17753                  port_id, UINT16);
17754 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17755         TOKEN_NUM_INITIALIZER
17756                 (struct cmd_ptype_mapping_replace_result,
17757                  target, UINT32);
17758 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17759         TOKEN_NUM_INITIALIZER
17760                 (struct cmd_ptype_mapping_replace_result,
17761                  mask, UINT8);
17762 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17763         TOKEN_NUM_INITIALIZER
17764                 (struct cmd_ptype_mapping_replace_result,
17765                  pkt_type, UINT32);
17766
17767 static void
17768 cmd_ptype_mapping_replace_parsed(
17769         void *parsed_result,
17770         __rte_unused struct cmdline *cl,
17771         __rte_unused void *data)
17772 {
17773         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17774         int ret = -ENOTSUP;
17775
17776         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17777                 return;
17778
17779 #ifdef RTE_LIBRTE_I40E_PMD
17780         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17781                                         res->target,
17782                                         res->mask,
17783                                         res->pkt_type);
17784 #endif
17785
17786         switch (ret) {
17787         case 0:
17788                 break;
17789         case -EINVAL:
17790                 printf("invalid ptype 0x%8x or 0x%8x\n",
17791                                 res->target, res->pkt_type);
17792                 break;
17793         case -ENODEV:
17794                 printf("invalid port_id %d\n", res->port_id);
17795                 break;
17796         case -ENOTSUP:
17797                 printf("function not implemented\n");
17798                 break;
17799         default:
17800                 printf("programming error: (%s)\n", strerror(-ret));
17801         }
17802 }
17803
17804 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17805         .f = cmd_ptype_mapping_replace_parsed,
17806         .data = NULL,
17807         .help_str =
17808                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17809         .tokens = {
17810                 (void *)&cmd_ptype_mapping_replace_ptype,
17811                 (void *)&cmd_ptype_mapping_replace_mapping,
17812                 (void *)&cmd_ptype_mapping_replace_replace,
17813                 (void *)&cmd_ptype_mapping_replace_port_id,
17814                 (void *)&cmd_ptype_mapping_replace_target,
17815                 (void *)&cmd_ptype_mapping_replace_mask,
17816                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17817                 NULL,
17818         },
17819 };
17820
17821 /* ptype mapping reset */
17822
17823 /* Common result structure for ptype mapping reset */
17824 struct cmd_ptype_mapping_reset_result {
17825         cmdline_fixed_string_t ptype;
17826         cmdline_fixed_string_t mapping;
17827         cmdline_fixed_string_t reset;
17828         portid_t port_id;
17829 };
17830
17831 /* Common CLI fields for ptype mapping reset*/
17832 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17833         TOKEN_STRING_INITIALIZER
17834                 (struct cmd_ptype_mapping_reset_result,
17835                  ptype, "ptype");
17836 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17837         TOKEN_STRING_INITIALIZER
17838                 (struct cmd_ptype_mapping_reset_result,
17839                  mapping, "mapping");
17840 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17841         TOKEN_STRING_INITIALIZER
17842                 (struct cmd_ptype_mapping_reset_result,
17843                  reset, "reset");
17844 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17845         TOKEN_NUM_INITIALIZER
17846                 (struct cmd_ptype_mapping_reset_result,
17847                  port_id, UINT16);
17848
17849 static void
17850 cmd_ptype_mapping_reset_parsed(
17851         void *parsed_result,
17852         __rte_unused struct cmdline *cl,
17853         __rte_unused void *data)
17854 {
17855         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17856         int ret = -ENOTSUP;
17857
17858         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17859                 return;
17860
17861 #ifdef RTE_LIBRTE_I40E_PMD
17862         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17863 #endif
17864
17865         switch (ret) {
17866         case 0:
17867                 break;
17868         case -ENODEV:
17869                 printf("invalid port_id %d\n", res->port_id);
17870                 break;
17871         case -ENOTSUP:
17872                 printf("function not implemented\n");
17873                 break;
17874         default:
17875                 printf("programming error: (%s)\n", strerror(-ret));
17876         }
17877 }
17878
17879 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17880         .f = cmd_ptype_mapping_reset_parsed,
17881         .data = NULL,
17882         .help_str = "ptype mapping reset <port_id>",
17883         .tokens = {
17884                 (void *)&cmd_ptype_mapping_reset_ptype,
17885                 (void *)&cmd_ptype_mapping_reset_mapping,
17886                 (void *)&cmd_ptype_mapping_reset_reset,
17887                 (void *)&cmd_ptype_mapping_reset_port_id,
17888                 NULL,
17889         },
17890 };
17891
17892 /* ptype mapping update */
17893
17894 /* Common result structure for ptype mapping update */
17895 struct cmd_ptype_mapping_update_result {
17896         cmdline_fixed_string_t ptype;
17897         cmdline_fixed_string_t mapping;
17898         cmdline_fixed_string_t reset;
17899         portid_t port_id;
17900         uint8_t hw_ptype;
17901         uint32_t sw_ptype;
17902 };
17903
17904 /* Common CLI fields for ptype mapping update*/
17905 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17906         TOKEN_STRING_INITIALIZER
17907                 (struct cmd_ptype_mapping_update_result,
17908                  ptype, "ptype");
17909 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17910         TOKEN_STRING_INITIALIZER
17911                 (struct cmd_ptype_mapping_update_result,
17912                  mapping, "mapping");
17913 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17914         TOKEN_STRING_INITIALIZER
17915                 (struct cmd_ptype_mapping_update_result,
17916                  reset, "update");
17917 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17918         TOKEN_NUM_INITIALIZER
17919                 (struct cmd_ptype_mapping_update_result,
17920                  port_id, UINT16);
17921 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17922         TOKEN_NUM_INITIALIZER
17923                 (struct cmd_ptype_mapping_update_result,
17924                  hw_ptype, UINT8);
17925 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17926         TOKEN_NUM_INITIALIZER
17927                 (struct cmd_ptype_mapping_update_result,
17928                  sw_ptype, UINT32);
17929
17930 static void
17931 cmd_ptype_mapping_update_parsed(
17932         void *parsed_result,
17933         __rte_unused struct cmdline *cl,
17934         __rte_unused void *data)
17935 {
17936         struct cmd_ptype_mapping_update_result *res = parsed_result;
17937         int ret = -ENOTSUP;
17938 #ifdef RTE_LIBRTE_I40E_PMD
17939         struct rte_pmd_i40e_ptype_mapping mapping;
17940 #endif
17941         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17942                 return;
17943
17944 #ifdef RTE_LIBRTE_I40E_PMD
17945         mapping.hw_ptype = res->hw_ptype;
17946         mapping.sw_ptype = res->sw_ptype;
17947         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17948                                                 &mapping,
17949                                                 1,
17950                                                 0);
17951 #endif
17952
17953         switch (ret) {
17954         case 0:
17955                 break;
17956         case -EINVAL:
17957                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17958                 break;
17959         case -ENODEV:
17960                 printf("invalid port_id %d\n", res->port_id);
17961                 break;
17962         case -ENOTSUP:
17963                 printf("function not implemented\n");
17964                 break;
17965         default:
17966                 printf("programming error: (%s)\n", strerror(-ret));
17967         }
17968 }
17969
17970 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17971         .f = cmd_ptype_mapping_update_parsed,
17972         .data = NULL,
17973         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17974         .tokens = {
17975                 (void *)&cmd_ptype_mapping_update_ptype,
17976                 (void *)&cmd_ptype_mapping_update_mapping,
17977                 (void *)&cmd_ptype_mapping_update_update,
17978                 (void *)&cmd_ptype_mapping_update_port_id,
17979                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17980                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17981                 NULL,
17982         },
17983 };
17984
17985 /* Common result structure for file commands */
17986 struct cmd_cmdfile_result {
17987         cmdline_fixed_string_t load;
17988         cmdline_fixed_string_t filename;
17989 };
17990
17991 /* Common CLI fields for file commands */
17992 cmdline_parse_token_string_t cmd_load_cmdfile =
17993         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17994 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17995         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17996
17997 static void
17998 cmd_load_from_file_parsed(
17999         void *parsed_result,
18000         __rte_unused struct cmdline *cl,
18001         __rte_unused void *data)
18002 {
18003         struct cmd_cmdfile_result *res = parsed_result;
18004
18005         cmdline_read_from_file(res->filename);
18006 }
18007
18008 cmdline_parse_inst_t cmd_load_from_file = {
18009         .f = cmd_load_from_file_parsed,
18010         .data = NULL,
18011         .help_str = "load <filename>",
18012         .tokens = {
18013                 (void *)&cmd_load_cmdfile,
18014                 (void *)&cmd_load_cmdfile_filename,
18015                 NULL,
18016         },
18017 };
18018
18019 /* Get Rx offloads capabilities */
18020 struct cmd_rx_offload_get_capa_result {
18021         cmdline_fixed_string_t show;
18022         cmdline_fixed_string_t port;
18023         portid_t port_id;
18024         cmdline_fixed_string_t rx_offload;
18025         cmdline_fixed_string_t capabilities;
18026 };
18027
18028 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18029         TOKEN_STRING_INITIALIZER
18030                 (struct cmd_rx_offload_get_capa_result,
18031                  show, "show");
18032 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18033         TOKEN_STRING_INITIALIZER
18034                 (struct cmd_rx_offload_get_capa_result,
18035                  port, "port");
18036 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18037         TOKEN_NUM_INITIALIZER
18038                 (struct cmd_rx_offload_get_capa_result,
18039                  port_id, UINT16);
18040 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18041         TOKEN_STRING_INITIALIZER
18042                 (struct cmd_rx_offload_get_capa_result,
18043                  rx_offload, "rx_offload");
18044 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18045         TOKEN_STRING_INITIALIZER
18046                 (struct cmd_rx_offload_get_capa_result,
18047                  capabilities, "capabilities");
18048
18049 static void
18050 print_rx_offloads(uint64_t offloads)
18051 {
18052         uint64_t single_offload;
18053         int begin;
18054         int end;
18055         int bit;
18056
18057         if (offloads == 0)
18058                 return;
18059
18060         begin = __builtin_ctzll(offloads);
18061         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18062
18063         single_offload = 1ULL << begin;
18064         for (bit = begin; bit < end; bit++) {
18065                 if (offloads & single_offload)
18066                         printf(" %s",
18067                                rte_eth_dev_rx_offload_name(single_offload));
18068                 single_offload <<= 1;
18069         }
18070 }
18071
18072 static void
18073 cmd_rx_offload_get_capa_parsed(
18074         void *parsed_result,
18075         __rte_unused struct cmdline *cl,
18076         __rte_unused void *data)
18077 {
18078         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18079         struct rte_eth_dev_info dev_info;
18080         portid_t port_id = res->port_id;
18081         uint64_t queue_offloads;
18082         uint64_t port_offloads;
18083         int ret;
18084
18085         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18086         if (ret != 0)
18087                 return;
18088
18089         queue_offloads = dev_info.rx_queue_offload_capa;
18090         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18091
18092         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18093         printf("  Per Queue :");
18094         print_rx_offloads(queue_offloads);
18095
18096         printf("\n");
18097         printf("  Per Port  :");
18098         print_rx_offloads(port_offloads);
18099         printf("\n\n");
18100 }
18101
18102 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18103         .f = cmd_rx_offload_get_capa_parsed,
18104         .data = NULL,
18105         .help_str = "show port <port_id> rx_offload capabilities",
18106         .tokens = {
18107                 (void *)&cmd_rx_offload_get_capa_show,
18108                 (void *)&cmd_rx_offload_get_capa_port,
18109                 (void *)&cmd_rx_offload_get_capa_port_id,
18110                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18111                 (void *)&cmd_rx_offload_get_capa_capabilities,
18112                 NULL,
18113         }
18114 };
18115
18116 /* Get Rx offloads configuration */
18117 struct cmd_rx_offload_get_configuration_result {
18118         cmdline_fixed_string_t show;
18119         cmdline_fixed_string_t port;
18120         portid_t port_id;
18121         cmdline_fixed_string_t rx_offload;
18122         cmdline_fixed_string_t configuration;
18123 };
18124
18125 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18126         TOKEN_STRING_INITIALIZER
18127                 (struct cmd_rx_offload_get_configuration_result,
18128                  show, "show");
18129 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18130         TOKEN_STRING_INITIALIZER
18131                 (struct cmd_rx_offload_get_configuration_result,
18132                  port, "port");
18133 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18134         TOKEN_NUM_INITIALIZER
18135                 (struct cmd_rx_offload_get_configuration_result,
18136                  port_id, UINT16);
18137 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18138         TOKEN_STRING_INITIALIZER
18139                 (struct cmd_rx_offload_get_configuration_result,
18140                  rx_offload, "rx_offload");
18141 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18142         TOKEN_STRING_INITIALIZER
18143                 (struct cmd_rx_offload_get_configuration_result,
18144                  configuration, "configuration");
18145
18146 static void
18147 cmd_rx_offload_get_configuration_parsed(
18148         void *parsed_result,
18149         __rte_unused struct cmdline *cl,
18150         __rte_unused void *data)
18151 {
18152         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18153         struct rte_eth_dev_info dev_info;
18154         portid_t port_id = res->port_id;
18155         struct rte_port *port = &ports[port_id];
18156         uint64_t port_offloads;
18157         uint64_t queue_offloads;
18158         uint16_t nb_rx_queues;
18159         int q;
18160         int ret;
18161
18162         printf("Rx Offloading Configuration of port %d :\n", port_id);
18163
18164         port_offloads = port->dev_conf.rxmode.offloads;
18165         printf("  Port :");
18166         print_rx_offloads(port_offloads);
18167         printf("\n");
18168
18169         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18170         if (ret != 0)
18171                 return;
18172
18173         nb_rx_queues = dev_info.nb_rx_queues;
18174         for (q = 0; q < nb_rx_queues; q++) {
18175                 queue_offloads = port->rx_conf[q].offloads;
18176                 printf("  Queue[%2d] :", q);
18177                 print_rx_offloads(queue_offloads);
18178                 printf("\n");
18179         }
18180         printf("\n");
18181 }
18182
18183 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18184         .f = cmd_rx_offload_get_configuration_parsed,
18185         .data = NULL,
18186         .help_str = "show port <port_id> rx_offload configuration",
18187         .tokens = {
18188                 (void *)&cmd_rx_offload_get_configuration_show,
18189                 (void *)&cmd_rx_offload_get_configuration_port,
18190                 (void *)&cmd_rx_offload_get_configuration_port_id,
18191                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18192                 (void *)&cmd_rx_offload_get_configuration_configuration,
18193                 NULL,
18194         }
18195 };
18196
18197 /* Enable/Disable a per port offloading */
18198 struct cmd_config_per_port_rx_offload_result {
18199         cmdline_fixed_string_t port;
18200         cmdline_fixed_string_t config;
18201         portid_t port_id;
18202         cmdline_fixed_string_t rx_offload;
18203         cmdline_fixed_string_t offload;
18204         cmdline_fixed_string_t on_off;
18205 };
18206
18207 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18208         TOKEN_STRING_INITIALIZER
18209                 (struct cmd_config_per_port_rx_offload_result,
18210                  port, "port");
18211 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18212         TOKEN_STRING_INITIALIZER
18213                 (struct cmd_config_per_port_rx_offload_result,
18214                  config, "config");
18215 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18216         TOKEN_NUM_INITIALIZER
18217                 (struct cmd_config_per_port_rx_offload_result,
18218                  port_id, UINT16);
18219 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18220         TOKEN_STRING_INITIALIZER
18221                 (struct cmd_config_per_port_rx_offload_result,
18222                  rx_offload, "rx_offload");
18223 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18224         TOKEN_STRING_INITIALIZER
18225                 (struct cmd_config_per_port_rx_offload_result,
18226                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18227                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18228                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18229                            "scatter#timestamp#security#keep_crc#rss_hash");
18230 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18231         TOKEN_STRING_INITIALIZER
18232                 (struct cmd_config_per_port_rx_offload_result,
18233                  on_off, "on#off");
18234
18235 static uint64_t
18236 search_rx_offload(const char *name)
18237 {
18238         uint64_t single_offload;
18239         const char *single_name;
18240         int found = 0;
18241         unsigned int bit;
18242
18243         single_offload = 1;
18244         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18245                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18246                 if (!strcasecmp(single_name, name)) {
18247                         found = 1;
18248                         break;
18249                 }
18250                 single_offload <<= 1;
18251         }
18252
18253         if (found)
18254                 return single_offload;
18255
18256         return 0;
18257 }
18258
18259 static void
18260 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18261                                 __rte_unused struct cmdline *cl,
18262                                 __rte_unused void *data)
18263 {
18264         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18265         portid_t port_id = res->port_id;
18266         struct rte_eth_dev_info dev_info;
18267         struct rte_port *port = &ports[port_id];
18268         uint64_t single_offload;
18269         uint16_t nb_rx_queues;
18270         int q;
18271         int ret;
18272
18273         if (port->port_status != RTE_PORT_STOPPED) {
18274                 printf("Error: Can't config offload when Port %d "
18275                        "is not stopped\n", port_id);
18276                 return;
18277         }
18278
18279         single_offload = search_rx_offload(res->offload);
18280         if (single_offload == 0) {
18281                 printf("Unknown offload name: %s\n", res->offload);
18282                 return;
18283         }
18284
18285         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18286         if (ret != 0)
18287                 return;
18288
18289         nb_rx_queues = dev_info.nb_rx_queues;
18290         if (!strcmp(res->on_off, "on")) {
18291                 port->dev_conf.rxmode.offloads |= single_offload;
18292                 for (q = 0; q < nb_rx_queues; q++)
18293                         port->rx_conf[q].offloads |= single_offload;
18294         } else {
18295                 port->dev_conf.rxmode.offloads &= ~single_offload;
18296                 for (q = 0; q < nb_rx_queues; q++)
18297                         port->rx_conf[q].offloads &= ~single_offload;
18298         }
18299
18300         cmd_reconfig_device_queue(port_id, 1, 1);
18301 }
18302
18303 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18304         .f = cmd_config_per_port_rx_offload_parsed,
18305         .data = NULL,
18306         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18307                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18308                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18309                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18310                     "on|off",
18311         .tokens = {
18312                 (void *)&cmd_config_per_port_rx_offload_result_port,
18313                 (void *)&cmd_config_per_port_rx_offload_result_config,
18314                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18315                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18316                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18317                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18318                 NULL,
18319         }
18320 };
18321
18322 /* Enable/Disable a per queue offloading */
18323 struct cmd_config_per_queue_rx_offload_result {
18324         cmdline_fixed_string_t port;
18325         portid_t port_id;
18326         cmdline_fixed_string_t rxq;
18327         uint16_t queue_id;
18328         cmdline_fixed_string_t rx_offload;
18329         cmdline_fixed_string_t offload;
18330         cmdline_fixed_string_t on_off;
18331 };
18332
18333 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18334         TOKEN_STRING_INITIALIZER
18335                 (struct cmd_config_per_queue_rx_offload_result,
18336                  port, "port");
18337 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18338         TOKEN_NUM_INITIALIZER
18339                 (struct cmd_config_per_queue_rx_offload_result,
18340                  port_id, UINT16);
18341 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18342         TOKEN_STRING_INITIALIZER
18343                 (struct cmd_config_per_queue_rx_offload_result,
18344                  rxq, "rxq");
18345 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18346         TOKEN_NUM_INITIALIZER
18347                 (struct cmd_config_per_queue_rx_offload_result,
18348                  queue_id, UINT16);
18349 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18350         TOKEN_STRING_INITIALIZER
18351                 (struct cmd_config_per_queue_rx_offload_result,
18352                  rx_offload, "rx_offload");
18353 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18354         TOKEN_STRING_INITIALIZER
18355                 (struct cmd_config_per_queue_rx_offload_result,
18356                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18357                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18358                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18359                            "scatter#timestamp#security#keep_crc");
18360 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18361         TOKEN_STRING_INITIALIZER
18362                 (struct cmd_config_per_queue_rx_offload_result,
18363                  on_off, "on#off");
18364
18365 static void
18366 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18367                                 __rte_unused struct cmdline *cl,
18368                                 __rte_unused void *data)
18369 {
18370         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18371         struct rte_eth_dev_info dev_info;
18372         portid_t port_id = res->port_id;
18373         uint16_t queue_id = res->queue_id;
18374         struct rte_port *port = &ports[port_id];
18375         uint64_t single_offload;
18376         int ret;
18377
18378         if (port->port_status != RTE_PORT_STOPPED) {
18379                 printf("Error: Can't config offload when Port %d "
18380                        "is not stopped\n", port_id);
18381                 return;
18382         }
18383
18384         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18385         if (ret != 0)
18386                 return;
18387
18388         if (queue_id >= dev_info.nb_rx_queues) {
18389                 printf("Error: input queue_id should be 0 ... "
18390                        "%d\n", dev_info.nb_rx_queues - 1);
18391                 return;
18392         }
18393
18394         single_offload = search_rx_offload(res->offload);
18395         if (single_offload == 0) {
18396                 printf("Unknown offload name: %s\n", res->offload);
18397                 return;
18398         }
18399
18400         if (!strcmp(res->on_off, "on"))
18401                 port->rx_conf[queue_id].offloads |= single_offload;
18402         else
18403                 port->rx_conf[queue_id].offloads &= ~single_offload;
18404
18405         cmd_reconfig_device_queue(port_id, 1, 1);
18406 }
18407
18408 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18409         .f = cmd_config_per_queue_rx_offload_parsed,
18410         .data = NULL,
18411         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18412                     "vlan_strip|ipv4_cksum|"
18413                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18414                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18415                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18416                     "on|off",
18417         .tokens = {
18418                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18419                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18420                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18421                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18422                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18423                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18424                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18425                 NULL,
18426         }
18427 };
18428
18429 /* Get Tx offloads capabilities */
18430 struct cmd_tx_offload_get_capa_result {
18431         cmdline_fixed_string_t show;
18432         cmdline_fixed_string_t port;
18433         portid_t port_id;
18434         cmdline_fixed_string_t tx_offload;
18435         cmdline_fixed_string_t capabilities;
18436 };
18437
18438 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18439         TOKEN_STRING_INITIALIZER
18440                 (struct cmd_tx_offload_get_capa_result,
18441                  show, "show");
18442 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18443         TOKEN_STRING_INITIALIZER
18444                 (struct cmd_tx_offload_get_capa_result,
18445                  port, "port");
18446 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18447         TOKEN_NUM_INITIALIZER
18448                 (struct cmd_tx_offload_get_capa_result,
18449                  port_id, UINT16);
18450 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18451         TOKEN_STRING_INITIALIZER
18452                 (struct cmd_tx_offload_get_capa_result,
18453                  tx_offload, "tx_offload");
18454 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18455         TOKEN_STRING_INITIALIZER
18456                 (struct cmd_tx_offload_get_capa_result,
18457                  capabilities, "capabilities");
18458
18459 static void
18460 print_tx_offloads(uint64_t offloads)
18461 {
18462         uint64_t single_offload;
18463         int begin;
18464         int end;
18465         int bit;
18466
18467         if (offloads == 0)
18468                 return;
18469
18470         begin = __builtin_ctzll(offloads);
18471         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18472
18473         single_offload = 1ULL << begin;
18474         for (bit = begin; bit < end; bit++) {
18475                 if (offloads & single_offload)
18476                         printf(" %s",
18477                                rte_eth_dev_tx_offload_name(single_offload));
18478                 single_offload <<= 1;
18479         }
18480 }
18481
18482 static void
18483 cmd_tx_offload_get_capa_parsed(
18484         void *parsed_result,
18485         __rte_unused struct cmdline *cl,
18486         __rte_unused void *data)
18487 {
18488         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18489         struct rte_eth_dev_info dev_info;
18490         portid_t port_id = res->port_id;
18491         uint64_t queue_offloads;
18492         uint64_t port_offloads;
18493         int ret;
18494
18495         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18496         if (ret != 0)
18497                 return;
18498
18499         queue_offloads = dev_info.tx_queue_offload_capa;
18500         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18501
18502         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18503         printf("  Per Queue :");
18504         print_tx_offloads(queue_offloads);
18505
18506         printf("\n");
18507         printf("  Per Port  :");
18508         print_tx_offloads(port_offloads);
18509         printf("\n\n");
18510 }
18511
18512 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18513         .f = cmd_tx_offload_get_capa_parsed,
18514         .data = NULL,
18515         .help_str = "show port <port_id> tx_offload capabilities",
18516         .tokens = {
18517                 (void *)&cmd_tx_offload_get_capa_show,
18518                 (void *)&cmd_tx_offload_get_capa_port,
18519                 (void *)&cmd_tx_offload_get_capa_port_id,
18520                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18521                 (void *)&cmd_tx_offload_get_capa_capabilities,
18522                 NULL,
18523         }
18524 };
18525
18526 /* Get Tx offloads configuration */
18527 struct cmd_tx_offload_get_configuration_result {
18528         cmdline_fixed_string_t show;
18529         cmdline_fixed_string_t port;
18530         portid_t port_id;
18531         cmdline_fixed_string_t tx_offload;
18532         cmdline_fixed_string_t configuration;
18533 };
18534
18535 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18536         TOKEN_STRING_INITIALIZER
18537                 (struct cmd_tx_offload_get_configuration_result,
18538                  show, "show");
18539 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18540         TOKEN_STRING_INITIALIZER
18541                 (struct cmd_tx_offload_get_configuration_result,
18542                  port, "port");
18543 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18544         TOKEN_NUM_INITIALIZER
18545                 (struct cmd_tx_offload_get_configuration_result,
18546                  port_id, UINT16);
18547 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18548         TOKEN_STRING_INITIALIZER
18549                 (struct cmd_tx_offload_get_configuration_result,
18550                  tx_offload, "tx_offload");
18551 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18552         TOKEN_STRING_INITIALIZER
18553                 (struct cmd_tx_offload_get_configuration_result,
18554                  configuration, "configuration");
18555
18556 static void
18557 cmd_tx_offload_get_configuration_parsed(
18558         void *parsed_result,
18559         __rte_unused struct cmdline *cl,
18560         __rte_unused void *data)
18561 {
18562         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18563         struct rte_eth_dev_info dev_info;
18564         portid_t port_id = res->port_id;
18565         struct rte_port *port = &ports[port_id];
18566         uint64_t port_offloads;
18567         uint64_t queue_offloads;
18568         uint16_t nb_tx_queues;
18569         int q;
18570         int ret;
18571
18572         printf("Tx Offloading Configuration of port %d :\n", port_id);
18573
18574         port_offloads = port->dev_conf.txmode.offloads;
18575         printf("  Port :");
18576         print_tx_offloads(port_offloads);
18577         printf("\n");
18578
18579         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18580         if (ret != 0)
18581                 return;
18582
18583         nb_tx_queues = dev_info.nb_tx_queues;
18584         for (q = 0; q < nb_tx_queues; q++) {
18585                 queue_offloads = port->tx_conf[q].offloads;
18586                 printf("  Queue[%2d] :", q);
18587                 print_tx_offloads(queue_offloads);
18588                 printf("\n");
18589         }
18590         printf("\n");
18591 }
18592
18593 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18594         .f = cmd_tx_offload_get_configuration_parsed,
18595         .data = NULL,
18596         .help_str = "show port <port_id> tx_offload configuration",
18597         .tokens = {
18598                 (void *)&cmd_tx_offload_get_configuration_show,
18599                 (void *)&cmd_tx_offload_get_configuration_port,
18600                 (void *)&cmd_tx_offload_get_configuration_port_id,
18601                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18602                 (void *)&cmd_tx_offload_get_configuration_configuration,
18603                 NULL,
18604         }
18605 };
18606
18607 /* Enable/Disable a per port offloading */
18608 struct cmd_config_per_port_tx_offload_result {
18609         cmdline_fixed_string_t port;
18610         cmdline_fixed_string_t config;
18611         portid_t port_id;
18612         cmdline_fixed_string_t tx_offload;
18613         cmdline_fixed_string_t offload;
18614         cmdline_fixed_string_t on_off;
18615 };
18616
18617 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18618         TOKEN_STRING_INITIALIZER
18619                 (struct cmd_config_per_port_tx_offload_result,
18620                  port, "port");
18621 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18622         TOKEN_STRING_INITIALIZER
18623                 (struct cmd_config_per_port_tx_offload_result,
18624                  config, "config");
18625 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18626         TOKEN_NUM_INITIALIZER
18627                 (struct cmd_config_per_port_tx_offload_result,
18628                  port_id, UINT16);
18629 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18630         TOKEN_STRING_INITIALIZER
18631                 (struct cmd_config_per_port_tx_offload_result,
18632                  tx_offload, "tx_offload");
18633 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18634         TOKEN_STRING_INITIALIZER
18635                 (struct cmd_config_per_port_tx_offload_result,
18636                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18637                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18638                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18639                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18640                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18641 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18642         TOKEN_STRING_INITIALIZER
18643                 (struct cmd_config_per_port_tx_offload_result,
18644                  on_off, "on#off");
18645
18646 static uint64_t
18647 search_tx_offload(const char *name)
18648 {
18649         uint64_t single_offload;
18650         const char *single_name;
18651         int found = 0;
18652         unsigned int bit;
18653
18654         single_offload = 1;
18655         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18656                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18657                 if (single_name == NULL)
18658                         break;
18659                 if (!strcasecmp(single_name, name)) {
18660                         found = 1;
18661                         break;
18662                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18663                         break;
18664                 single_offload <<= 1;
18665         }
18666
18667         if (found)
18668                 return single_offload;
18669
18670         return 0;
18671 }
18672
18673 static void
18674 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18675                                 __rte_unused struct cmdline *cl,
18676                                 __rte_unused void *data)
18677 {
18678         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18679         portid_t port_id = res->port_id;
18680         struct rte_eth_dev_info dev_info;
18681         struct rte_port *port = &ports[port_id];
18682         uint64_t single_offload;
18683         uint16_t nb_tx_queues;
18684         int q;
18685         int ret;
18686
18687         if (port->port_status != RTE_PORT_STOPPED) {
18688                 printf("Error: Can't config offload when Port %d "
18689                        "is not stopped\n", port_id);
18690                 return;
18691         }
18692
18693         single_offload = search_tx_offload(res->offload);
18694         if (single_offload == 0) {
18695                 printf("Unknown offload name: %s\n", res->offload);
18696                 return;
18697         }
18698
18699         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18700         if (ret != 0)
18701                 return;
18702
18703         nb_tx_queues = dev_info.nb_tx_queues;
18704         if (!strcmp(res->on_off, "on")) {
18705                 port->dev_conf.txmode.offloads |= single_offload;
18706                 for (q = 0; q < nb_tx_queues; q++)
18707                         port->tx_conf[q].offloads |= single_offload;
18708         } else {
18709                 port->dev_conf.txmode.offloads &= ~single_offload;
18710                 for (q = 0; q < nb_tx_queues; q++)
18711                         port->tx_conf[q].offloads &= ~single_offload;
18712         }
18713
18714         cmd_reconfig_device_queue(port_id, 1, 1);
18715 }
18716
18717 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18718         .f = cmd_config_per_port_tx_offload_parsed,
18719         .data = NULL,
18720         .help_str = "port config <port_id> tx_offload "
18721                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18722                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18723                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18724                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18725                     "mt_lockfree|multi_segs|mbuf_fast_free|security on|off",
18726         .tokens = {
18727                 (void *)&cmd_config_per_port_tx_offload_result_port,
18728                 (void *)&cmd_config_per_port_tx_offload_result_config,
18729                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18730                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18731                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18732                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18733                 NULL,
18734         }
18735 };
18736
18737 /* Enable/Disable a per queue offloading */
18738 struct cmd_config_per_queue_tx_offload_result {
18739         cmdline_fixed_string_t port;
18740         portid_t port_id;
18741         cmdline_fixed_string_t txq;
18742         uint16_t queue_id;
18743         cmdline_fixed_string_t tx_offload;
18744         cmdline_fixed_string_t offload;
18745         cmdline_fixed_string_t on_off;
18746 };
18747
18748 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18749         TOKEN_STRING_INITIALIZER
18750                 (struct cmd_config_per_queue_tx_offload_result,
18751                  port, "port");
18752 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18753         TOKEN_NUM_INITIALIZER
18754                 (struct cmd_config_per_queue_tx_offload_result,
18755                  port_id, UINT16);
18756 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18757         TOKEN_STRING_INITIALIZER
18758                 (struct cmd_config_per_queue_tx_offload_result,
18759                  txq, "txq");
18760 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18761         TOKEN_NUM_INITIALIZER
18762                 (struct cmd_config_per_queue_tx_offload_result,
18763                  queue_id, UINT16);
18764 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18765         TOKEN_STRING_INITIALIZER
18766                 (struct cmd_config_per_queue_tx_offload_result,
18767                  tx_offload, "tx_offload");
18768 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18769         TOKEN_STRING_INITIALIZER
18770                 (struct cmd_config_per_queue_tx_offload_result,
18771                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18772                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18773                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18774                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18775                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18776 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18777         TOKEN_STRING_INITIALIZER
18778                 (struct cmd_config_per_queue_tx_offload_result,
18779                  on_off, "on#off");
18780
18781 static void
18782 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18783                                 __rte_unused struct cmdline *cl,
18784                                 __rte_unused void *data)
18785 {
18786         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18787         struct rte_eth_dev_info dev_info;
18788         portid_t port_id = res->port_id;
18789         uint16_t queue_id = res->queue_id;
18790         struct rte_port *port = &ports[port_id];
18791         uint64_t single_offload;
18792         int ret;
18793
18794         if (port->port_status != RTE_PORT_STOPPED) {
18795                 printf("Error: Can't config offload when Port %d "
18796                        "is not stopped\n", port_id);
18797                 return;
18798         }
18799
18800         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18801         if (ret != 0)
18802                 return;
18803
18804         if (queue_id >= dev_info.nb_tx_queues) {
18805                 printf("Error: input queue_id should be 0 ... "
18806                        "%d\n", dev_info.nb_tx_queues - 1);
18807                 return;
18808         }
18809
18810         single_offload = search_tx_offload(res->offload);
18811         if (single_offload == 0) {
18812                 printf("Unknown offload name: %s\n", res->offload);
18813                 return;
18814         }
18815
18816         if (!strcmp(res->on_off, "on"))
18817                 port->tx_conf[queue_id].offloads |= single_offload;
18818         else
18819                 port->tx_conf[queue_id].offloads &= ~single_offload;
18820
18821         cmd_reconfig_device_queue(port_id, 1, 1);
18822 }
18823
18824 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18825         .f = cmd_config_per_queue_tx_offload_parsed,
18826         .data = NULL,
18827         .help_str = "port <port_id> txq <queue_id> tx_offload "
18828                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18829                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18830                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18831                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18832                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18833                     "on|off",
18834         .tokens = {
18835                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18836                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18837                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18838                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18839                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18840                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18841                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18842                 NULL,
18843         }
18844 };
18845
18846 /* *** configure tx_metadata for specific port *** */
18847 struct cmd_config_tx_metadata_specific_result {
18848         cmdline_fixed_string_t port;
18849         cmdline_fixed_string_t keyword;
18850         uint16_t port_id;
18851         cmdline_fixed_string_t item;
18852         uint32_t value;
18853 };
18854
18855 static void
18856 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18857                                 __rte_unused struct cmdline *cl,
18858                                 __rte_unused void *data)
18859 {
18860         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18861
18862         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18863                 return;
18864         ports[res->port_id].tx_metadata = res->value;
18865         /* Add/remove callback to insert valid metadata in every Tx packet. */
18866         if (ports[res->port_id].tx_metadata)
18867                 add_tx_md_callback(res->port_id);
18868         else
18869                 remove_tx_md_callback(res->port_id);
18870         rte_flow_dynf_metadata_register();
18871 }
18872
18873 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18874         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18875                         port, "port");
18876 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18877         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18878                         keyword, "config");
18879 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18880         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18881                         port_id, UINT16);
18882 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18883         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18884                         item, "tx_metadata");
18885 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18886         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18887                         value, UINT32);
18888
18889 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18890         .f = cmd_config_tx_metadata_specific_parsed,
18891         .data = NULL,
18892         .help_str = "port config <port_id> tx_metadata <value>",
18893         .tokens = {
18894                 (void *)&cmd_config_tx_metadata_specific_port,
18895                 (void *)&cmd_config_tx_metadata_specific_keyword,
18896                 (void *)&cmd_config_tx_metadata_specific_id,
18897                 (void *)&cmd_config_tx_metadata_specific_item,
18898                 (void *)&cmd_config_tx_metadata_specific_value,
18899                 NULL,
18900         },
18901 };
18902
18903 /* *** set dynf *** */
18904 struct cmd_config_tx_dynf_specific_result {
18905         cmdline_fixed_string_t port;
18906         cmdline_fixed_string_t keyword;
18907         uint16_t port_id;
18908         cmdline_fixed_string_t item;
18909         cmdline_fixed_string_t name;
18910         cmdline_fixed_string_t value;
18911 };
18912
18913 static void
18914 cmd_config_dynf_specific_parsed(void *parsed_result,
18915                                 __rte_unused struct cmdline *cl,
18916                                 __rte_unused void *data)
18917 {
18918         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18919         struct rte_mbuf_dynflag desc_flag;
18920         int flag;
18921         uint64_t old_port_flags;
18922
18923         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18924                 return;
18925         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18926         if (flag <= 0) {
18927                 if (strlcpy(desc_flag.name, res->name,
18928                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18929                         printf("Flag name too long\n");
18930                         return;
18931                 }
18932                 desc_flag.flags = 0;
18933                 flag = rte_mbuf_dynflag_register(&desc_flag);
18934                 if (flag < 0) {
18935                         printf("Can't register flag\n");
18936                         return;
18937                 }
18938                 strcpy(dynf_names[flag], desc_flag.name);
18939         }
18940         old_port_flags = ports[res->port_id].mbuf_dynf;
18941         if (!strcmp(res->value, "set")) {
18942                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
18943                 if (old_port_flags == 0)
18944                         add_tx_dynf_callback(res->port_id);
18945         } else {
18946                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18947                 if (ports[res->port_id].mbuf_dynf == 0)
18948                         remove_tx_dynf_callback(res->port_id);
18949         }
18950 }
18951
18952 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18953         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18954                         keyword, "port");
18955 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18956         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18957                         keyword, "config");
18958 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18959         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18960                         port_id, UINT16);
18961 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18962         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18963                         item, "dynf");
18964 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18965         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18966                         name, NULL);
18967 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
18968         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18969                         value, "set#clear");
18970
18971 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
18972         .f = cmd_config_dynf_specific_parsed,
18973         .data = NULL,
18974         .help_str = "port config <port id> dynf <name> set|clear",
18975         .tokens = {
18976                 (void *)&cmd_config_tx_dynf_specific_port,
18977                 (void *)&cmd_config_tx_dynf_specific_keyword,
18978                 (void *)&cmd_config_tx_dynf_specific_port_id,
18979                 (void *)&cmd_config_tx_dynf_specific_item,
18980                 (void *)&cmd_config_tx_dynf_specific_name,
18981                 (void *)&cmd_config_tx_dynf_specific_value,
18982                 NULL,
18983         },
18984 };
18985
18986 /* *** display tx_metadata per port configuration *** */
18987 struct cmd_show_tx_metadata_result {
18988         cmdline_fixed_string_t cmd_show;
18989         cmdline_fixed_string_t cmd_port;
18990         cmdline_fixed_string_t cmd_keyword;
18991         portid_t cmd_pid;
18992 };
18993
18994 static void
18995 cmd_show_tx_metadata_parsed(void *parsed_result,
18996                 __rte_unused struct cmdline *cl,
18997                 __rte_unused void *data)
18998 {
18999         struct cmd_show_tx_metadata_result *res = parsed_result;
19000
19001         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19002                 printf("invalid port id %u\n", res->cmd_pid);
19003                 return;
19004         }
19005         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19006                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19007                        ports[res->cmd_pid].tx_metadata);
19008         }
19009 }
19010
19011 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19012         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19013                         cmd_show, "show");
19014 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19015         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19016                         cmd_port, "port");
19017 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19018         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19019                         cmd_pid, UINT16);
19020 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19021         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19022                         cmd_keyword, "tx_metadata");
19023
19024 cmdline_parse_inst_t cmd_show_tx_metadata = {
19025         .f = cmd_show_tx_metadata_parsed,
19026         .data = NULL,
19027         .help_str = "show port <port_id> tx_metadata",
19028         .tokens = {
19029                 (void *)&cmd_show_tx_metadata_show,
19030                 (void *)&cmd_show_tx_metadata_port,
19031                 (void *)&cmd_show_tx_metadata_pid,
19032                 (void *)&cmd_show_tx_metadata_keyword,
19033                 NULL,
19034         },
19035 };
19036
19037 /* show port supported ptypes */
19038
19039 /* Common result structure for show port ptypes */
19040 struct cmd_show_port_supported_ptypes_result {
19041         cmdline_fixed_string_t show;
19042         cmdline_fixed_string_t port;
19043         portid_t port_id;
19044         cmdline_fixed_string_t ptypes;
19045 };
19046
19047 /* Common CLI fields for show port ptypes */
19048 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19049         TOKEN_STRING_INITIALIZER
19050                 (struct cmd_show_port_supported_ptypes_result,
19051                  show, "show");
19052 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19053         TOKEN_STRING_INITIALIZER
19054                 (struct cmd_show_port_supported_ptypes_result,
19055                  port, "port");
19056 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19057         TOKEN_NUM_INITIALIZER
19058                 (struct cmd_show_port_supported_ptypes_result,
19059                  port_id, UINT16);
19060 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19061         TOKEN_STRING_INITIALIZER
19062                 (struct cmd_show_port_supported_ptypes_result,
19063                  ptypes, "ptypes");
19064
19065 static void
19066 cmd_show_port_supported_ptypes_parsed(
19067         void *parsed_result,
19068         __rte_unused struct cmdline *cl,
19069         __rte_unused void *data)
19070 {
19071 #define RSVD_PTYPE_MASK       0xf0000000
19072 #define MAX_PTYPES_PER_LAYER  16
19073 #define LTYPE_NAMESIZE        32
19074 #define PTYPE_NAMESIZE        256
19075         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19076         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19077         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19078         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19079         uint16_t port_id = res->port_id;
19080         int ret, i;
19081
19082         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19083         if (ret < 0)
19084                 return;
19085
19086         while (ptype_mask != RSVD_PTYPE_MASK) {
19087
19088                 switch (ptype_mask) {
19089                 case RTE_PTYPE_L2_MASK:
19090                         strlcpy(ltype, "L2", sizeof(ltype));
19091                         break;
19092                 case RTE_PTYPE_L3_MASK:
19093                         strlcpy(ltype, "L3", sizeof(ltype));
19094                         break;
19095                 case RTE_PTYPE_L4_MASK:
19096                         strlcpy(ltype, "L4", sizeof(ltype));
19097                         break;
19098                 case RTE_PTYPE_TUNNEL_MASK:
19099                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19100                         break;
19101                 case RTE_PTYPE_INNER_L2_MASK:
19102                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19103                         break;
19104                 case RTE_PTYPE_INNER_L3_MASK:
19105                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19106                         break;
19107                 case RTE_PTYPE_INNER_L4_MASK:
19108                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19109                         break;
19110                 default:
19111                         return;
19112                 }
19113
19114                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19115                                                        ptype_mask, ptypes,
19116                                                        MAX_PTYPES_PER_LAYER);
19117
19118                 if (ret > 0)
19119                         printf("Supported %s ptypes:\n", ltype);
19120                 else
19121                         printf("%s ptypes unsupported\n", ltype);
19122
19123                 for (i = 0; i < ret; ++i) {
19124                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19125                         printf("%s\n", buf);
19126                 }
19127
19128                 ptype_mask <<= 4;
19129         }
19130 }
19131
19132 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19133         .f = cmd_show_port_supported_ptypes_parsed,
19134         .data = NULL,
19135         .help_str = "show port <port_id> ptypes",
19136         .tokens = {
19137                 (void *)&cmd_show_port_supported_ptypes_show,
19138                 (void *)&cmd_show_port_supported_ptypes_port,
19139                 (void *)&cmd_show_port_supported_ptypes_port_id,
19140                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19141                 NULL,
19142         },
19143 };
19144
19145 /* *** display rx/tx descriptor status *** */
19146 struct cmd_show_rx_tx_desc_status_result {
19147         cmdline_fixed_string_t cmd_show;
19148         cmdline_fixed_string_t cmd_port;
19149         cmdline_fixed_string_t cmd_keyword;
19150         cmdline_fixed_string_t cmd_desc;
19151         cmdline_fixed_string_t cmd_status;
19152         portid_t cmd_pid;
19153         portid_t cmd_qid;
19154         portid_t cmd_did;
19155 };
19156
19157 static void
19158 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19159                 __rte_unused struct cmdline *cl,
19160                 __rte_unused void *data)
19161 {
19162         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19163         int rc;
19164
19165         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19166                 printf("invalid port id %u\n", res->cmd_pid);
19167                 return;
19168         }
19169
19170         if (!strcmp(res->cmd_keyword, "rxq")) {
19171                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19172                                              res->cmd_did);
19173                 if (rc < 0) {
19174                         printf("Invalid queueid = %d\n", res->cmd_qid);
19175                         return;
19176                 }
19177                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19178                         printf("Desc status = AVAILABLE\n");
19179                 else if (rc == RTE_ETH_RX_DESC_DONE)
19180                         printf("Desc status = DONE\n");
19181                 else
19182                         printf("Desc status = UNAVAILABLE\n");
19183         } else if (!strcmp(res->cmd_keyword, "txq")) {
19184                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19185                                              res->cmd_did);
19186                 if (rc < 0) {
19187                         printf("Invalid queueid = %d\n", res->cmd_qid);
19188                         return;
19189                 }
19190                 if (rc == RTE_ETH_TX_DESC_FULL)
19191                         printf("Desc status = FULL\n");
19192                 else if (rc == RTE_ETH_TX_DESC_DONE)
19193                         printf("Desc status = DONE\n");
19194                 else
19195                         printf("Desc status = UNAVAILABLE\n");
19196         }
19197 }
19198
19199 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19200         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19201                         cmd_show, "show");
19202 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19203         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19204                         cmd_port, "port");
19205 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19206         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19207                         cmd_pid, UINT16);
19208 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19209         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19210                         cmd_keyword, "rxq#txq");
19211 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19212         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19213                         cmd_qid, UINT16);
19214 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19215         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19216                         cmd_desc, "desc");
19217 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19218         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19219                         cmd_did, UINT16);
19220 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19221         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19222                         cmd_status, "status");
19223 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19224         .f = cmd_show_rx_tx_desc_status_parsed,
19225         .data = NULL,
19226         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19227                 "status",
19228         .tokens = {
19229                 (void *)&cmd_show_rx_tx_desc_status_show,
19230                 (void *)&cmd_show_rx_tx_desc_status_port,
19231                 (void *)&cmd_show_rx_tx_desc_status_pid,
19232                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19233                 (void *)&cmd_show_rx_tx_desc_status_qid,
19234                 (void *)&cmd_show_rx_tx_desc_status_desc,
19235                 (void *)&cmd_show_rx_tx_desc_status_did,
19236                 (void *)&cmd_show_rx_tx_desc_status_status,
19237                 NULL,
19238         },
19239 };
19240
19241 /* Common result structure for set port ptypes */
19242 struct cmd_set_port_ptypes_result {
19243         cmdline_fixed_string_t set;
19244         cmdline_fixed_string_t port;
19245         portid_t port_id;
19246         cmdline_fixed_string_t ptype_mask;
19247         uint32_t mask;
19248 };
19249
19250 /* Common CLI fields for set port ptypes */
19251 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19252         TOKEN_STRING_INITIALIZER
19253                 (struct cmd_set_port_ptypes_result,
19254                  set, "set");
19255 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19256         TOKEN_STRING_INITIALIZER
19257                 (struct cmd_set_port_ptypes_result,
19258                  port, "port");
19259 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19260         TOKEN_NUM_INITIALIZER
19261                 (struct cmd_set_port_ptypes_result,
19262                  port_id, UINT16);
19263 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19264         TOKEN_STRING_INITIALIZER
19265                 (struct cmd_set_port_ptypes_result,
19266                  ptype_mask, "ptype_mask");
19267 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19268         TOKEN_NUM_INITIALIZER
19269                 (struct cmd_set_port_ptypes_result,
19270                  mask, UINT32);
19271
19272 static void
19273 cmd_set_port_ptypes_parsed(
19274         void *parsed_result,
19275         __rte_unused struct cmdline *cl,
19276         __rte_unused void *data)
19277 {
19278         struct cmd_set_port_ptypes_result *res = parsed_result;
19279 #define PTYPE_NAMESIZE        256
19280         char ptype_name[PTYPE_NAMESIZE];
19281         uint16_t port_id = res->port_id;
19282         uint32_t ptype_mask = res->mask;
19283         int ret, i;
19284
19285         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19286                                                NULL, 0);
19287         if (ret <= 0) {
19288                 printf("Port %d doesn't support any ptypes.\n", port_id);
19289                 return;
19290         }
19291
19292         uint32_t ptypes[ret];
19293
19294         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19295         if (ret < 0) {
19296                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19297                 return;
19298         }
19299
19300         printf("Successfully set following ptypes for Port %d\n", port_id);
19301         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19302                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19303                 printf("%s\n", ptype_name);
19304         }
19305
19306         clear_ptypes = false;
19307 }
19308
19309 cmdline_parse_inst_t cmd_set_port_ptypes = {
19310         .f = cmd_set_port_ptypes_parsed,
19311         .data = NULL,
19312         .help_str = "set port <port_id> ptype_mask <mask>",
19313         .tokens = {
19314                 (void *)&cmd_set_port_ptypes_set,
19315                 (void *)&cmd_set_port_ptypes_port,
19316                 (void *)&cmd_set_port_ptypes_port_id,
19317                 (void *)&cmd_set_port_ptypes_mask_str,
19318                 (void *)&cmd_set_port_ptypes_mask_u32,
19319                 NULL,
19320         },
19321 };
19322
19323 /* *** display mac addresses added to a port *** */
19324 struct cmd_showport_macs_result {
19325         cmdline_fixed_string_t cmd_show;
19326         cmdline_fixed_string_t cmd_port;
19327         cmdline_fixed_string_t cmd_keyword;
19328         portid_t cmd_pid;
19329 };
19330
19331 static void
19332 cmd_showport_macs_parsed(void *parsed_result,
19333                 __rte_unused struct cmdline *cl,
19334                 __rte_unused void *data)
19335 {
19336         struct cmd_showport_macs_result *res = parsed_result;
19337
19338         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19339                 return;
19340
19341         if (!strcmp(res->cmd_keyword, "macs"))
19342                 show_macs(res->cmd_pid);
19343         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19344                 show_mcast_macs(res->cmd_pid);
19345 }
19346
19347 cmdline_parse_token_string_t cmd_showport_macs_show =
19348         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19349                         cmd_show, "show");
19350 cmdline_parse_token_string_t cmd_showport_macs_port =
19351         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19352                         cmd_port, "port");
19353 cmdline_parse_token_num_t cmd_showport_macs_pid =
19354         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19355                         cmd_pid, UINT16);
19356 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19357         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19358                         cmd_keyword, "macs#mcast_macs");
19359
19360 cmdline_parse_inst_t cmd_showport_macs = {
19361         .f = cmd_showport_macs_parsed,
19362         .data = NULL,
19363         .help_str = "show port <port_id> macs|mcast_macs",
19364         .tokens = {
19365                 (void *)&cmd_showport_macs_show,
19366                 (void *)&cmd_showport_macs_port,
19367                 (void *)&cmd_showport_macs_pid,
19368                 (void *)&cmd_showport_macs_keyword,
19369                 NULL,
19370         },
19371 };
19372
19373 /* ******************************************************************************** */
19374
19375 /* list of instructions */
19376 cmdline_parse_ctx_t main_ctx[] = {
19377         (cmdline_parse_inst_t *)&cmd_help_brief,
19378         (cmdline_parse_inst_t *)&cmd_help_long,
19379         (cmdline_parse_inst_t *)&cmd_quit,
19380         (cmdline_parse_inst_t *)&cmd_load_from_file,
19381         (cmdline_parse_inst_t *)&cmd_showport,
19382         (cmdline_parse_inst_t *)&cmd_showqueue,
19383         (cmdline_parse_inst_t *)&cmd_showportall,
19384         (cmdline_parse_inst_t *)&cmd_showdevice,
19385         (cmdline_parse_inst_t *)&cmd_showcfg,
19386         (cmdline_parse_inst_t *)&cmd_showfwdall,
19387         (cmdline_parse_inst_t *)&cmd_start,
19388         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19389         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19390         (cmdline_parse_inst_t *)&cmd_set_link_up,
19391         (cmdline_parse_inst_t *)&cmd_set_link_down,
19392         (cmdline_parse_inst_t *)&cmd_reset,
19393         (cmdline_parse_inst_t *)&cmd_set_numbers,
19394         (cmdline_parse_inst_t *)&cmd_set_log,
19395         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19396         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19397         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19398         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19399         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19400         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19401         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19402         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19403         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19404         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19405         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19406         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19407         (cmdline_parse_inst_t *)&cmd_set_link_check,
19408         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19409         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19410         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19411         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19412 #ifdef RTE_LIBRTE_PMD_BOND
19413         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19414         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19415         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19416         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19417         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19418         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19419         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19420         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19421         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19422         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19423         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19424 #endif
19425         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19426         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19427         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19428         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19429         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19430         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19431         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19432         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19433         (cmdline_parse_inst_t *)&cmd_csum_set,
19434         (cmdline_parse_inst_t *)&cmd_csum_show,
19435         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19436         (cmdline_parse_inst_t *)&cmd_tso_set,
19437         (cmdline_parse_inst_t *)&cmd_tso_show,
19438         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19439         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19440         (cmdline_parse_inst_t *)&cmd_gro_enable,
19441         (cmdline_parse_inst_t *)&cmd_gro_flush,
19442         (cmdline_parse_inst_t *)&cmd_gro_show,
19443         (cmdline_parse_inst_t *)&cmd_gso_enable,
19444         (cmdline_parse_inst_t *)&cmd_gso_size,
19445         (cmdline_parse_inst_t *)&cmd_gso_show,
19446         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19447         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19448         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19449         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19450         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19451         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19452         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19453         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19454         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19455         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19456         (cmdline_parse_inst_t *)&cmd_config_dcb,
19457         (cmdline_parse_inst_t *)&cmd_read_reg,
19458         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19459         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19460         (cmdline_parse_inst_t *)&cmd_write_reg,
19461         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19462         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19463         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19464         (cmdline_parse_inst_t *)&cmd_stop,
19465         (cmdline_parse_inst_t *)&cmd_mac_addr,
19466         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19467         (cmdline_parse_inst_t *)&cmd_set_qmap,
19468         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19469         (cmdline_parse_inst_t *)&cmd_operate_port,
19470         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19471         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19472         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19473         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19474         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19475         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19476         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19477         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19478         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19479         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19480         (cmdline_parse_inst_t *)&cmd_config_mtu,
19481         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19482         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19483         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19484         (cmdline_parse_inst_t *)&cmd_config_rss,
19485         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19486         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19487         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19488         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19489         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19490         (cmdline_parse_inst_t *)&cmd_showport_reta,
19491         (cmdline_parse_inst_t *)&cmd_showport_macs,
19492         (cmdline_parse_inst_t *)&cmd_config_burst,
19493         (cmdline_parse_inst_t *)&cmd_config_thresh,
19494         (cmdline_parse_inst_t *)&cmd_config_threshold,
19495         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19496         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19497         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19498         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19499         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19500         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19501         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19502         (cmdline_parse_inst_t *)&cmd_global_config,
19503         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19504         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19505         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19506         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19507         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19508         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19509         (cmdline_parse_inst_t *)&cmd_dump,
19510         (cmdline_parse_inst_t *)&cmd_dump_one,
19511         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19512         (cmdline_parse_inst_t *)&cmd_syn_filter,
19513         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19514         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19515         (cmdline_parse_inst_t *)&cmd_flex_filter,
19516         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19517         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19518         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19519         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19520         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19521         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19522         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19523         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19524         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19525         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19526         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19527         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19528         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19529         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19530         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19531         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19532         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19533         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19534         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19535         (cmdline_parse_inst_t *)&cmd_flow,
19536         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19537         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19538         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19539         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19540         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19541         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19542         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19543         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19544         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19545         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19546         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19547         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19548         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19549         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19550         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19551         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19552         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19553         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19554         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19555         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19556         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19557         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19558         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19559         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19560         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19561         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19562         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19563         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19564         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19565         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19566         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19567         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19568         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19569         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19570         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19571         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19572         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19573         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19574         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19575         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19576         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19577         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19578         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19579         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19580         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19581         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19582         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19583         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19584         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19585 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19586         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19587 #endif
19588         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19589         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19590         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19591         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19592         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19593         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19594         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19595         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19596         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19597         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19598         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19599         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19600         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19601         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19602         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19603         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19604         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19605         (cmdline_parse_inst_t *)&cmd_ddp_add,
19606         (cmdline_parse_inst_t *)&cmd_ddp_del,
19607         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19608         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19609         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19610         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19611         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19612         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19613         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19614         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19615         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19616         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19617         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19618         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19619
19620         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19621         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19622         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19623         (cmdline_parse_inst_t *)&cmd_queue_region,
19624         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19625         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19626         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19627         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19628         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19629         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19630         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19631         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19632         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19633         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19634         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19635         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19636         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19637         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19638         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19639         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19640         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19641         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19642         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19643         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19644         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19645         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19646         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19647         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19648         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19649         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19650         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19651         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19652         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19653         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19654         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19655         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19656         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19657         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19658         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19659 #ifdef RTE_LIBRTE_BPF
19660         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19661         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19662 #endif
19663         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19664         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19665         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19666         (cmdline_parse_inst_t *)&cmd_set_raw,
19667         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19668         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19669         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19670         NULL,
19671 };
19672
19673 /* read cmdline commands from file */
19674 void
19675 cmdline_read_from_file(const char *filename)
19676 {
19677         struct cmdline *cl;
19678
19679         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19680         if (cl == NULL) {
19681                 printf("Failed to create file based cmdline context: %s\n",
19682                        filename);
19683                 return;
19684         }
19685
19686         cmdline_interact(cl);
19687         cmdline_quit(cl);
19688
19689         cmdline_free(cl);
19690
19691         printf("Read CLI commands from %s\n", filename);
19692 }
19693
19694 /* prompt function, called from main on MASTER lcore */
19695 void
19696 prompt(void)
19697 {
19698         /* initialize non-constant commands */
19699         cmd_set_fwd_mode_init();
19700         cmd_set_fwd_retry_mode_init();
19701
19702         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19703         if (testpmd_cl == NULL)
19704                 return;
19705         cmdline_interact(testpmd_cl);
19706         cmdline_stdin_exit(testpmd_cl);
19707 }
19708
19709 void
19710 prompt_exit(void)
19711 {
19712         if (testpmd_cl != NULL)
19713                 cmdline_quit(testpmd_cl);
19714 }
19715
19716 static void
19717 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19718 {
19719         if (id == (portid_t)RTE_PORT_ALL) {
19720                 portid_t pid;
19721
19722                 RTE_ETH_FOREACH_DEV(pid) {
19723                         /* check if need_reconfig has been set to 1 */
19724                         if (ports[pid].need_reconfig == 0)
19725                                 ports[pid].need_reconfig = dev;
19726                         /* check if need_reconfig_queues has been set to 1 */
19727                         if (ports[pid].need_reconfig_queues == 0)
19728                                 ports[pid].need_reconfig_queues = queue;
19729                 }
19730         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19731                 /* check if need_reconfig has been set to 1 */
19732                 if (ports[id].need_reconfig == 0)
19733                         ports[id].need_reconfig = dev;
19734                 /* check if need_reconfig_queues has been set to 1 */
19735                 if (ports[id].need_reconfig_queues == 0)
19736                         ports[id].need_reconfig_queues = queue;
19737         }
19738 }