22fb23a92dccf19781d8b537f6896c0ad1e169fc
[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 (check_nb_rxd(res->value) != 0)
1926                         return;
1927                 nb_rxd = res->value;
1928         } else if (!strcmp(res->name, "txd")) {
1929                 if (check_nb_txd(res->value) != 0)
1930                         return;
1931
1932                 nb_txd = res->value;
1933         } else {
1934                 printf("Unknown parameter\n");
1935                 return;
1936         }
1937
1938         fwd_config_setup();
1939
1940         init_port_config();
1941
1942         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1943 }
1944
1945 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1946         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1947 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1948         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1949 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1950         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1951 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1952         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1953                                                 "rxq#txq#rxd#txd");
1954 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1955         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1956
1957 cmdline_parse_inst_t cmd_config_rx_tx = {
1958         .f = cmd_config_rx_tx_parsed,
1959         .data = NULL,
1960         .help_str = "port config all rxq|txq|rxd|txd <value>",
1961         .tokens = {
1962                 (void *)&cmd_config_rx_tx_port,
1963                 (void *)&cmd_config_rx_tx_keyword,
1964                 (void *)&cmd_config_rx_tx_all,
1965                 (void *)&cmd_config_rx_tx_name,
1966                 (void *)&cmd_config_rx_tx_value,
1967                 NULL,
1968         },
1969 };
1970
1971 /* *** config max packet length *** */
1972 struct cmd_config_max_pkt_len_result {
1973         cmdline_fixed_string_t port;
1974         cmdline_fixed_string_t keyword;
1975         cmdline_fixed_string_t all;
1976         cmdline_fixed_string_t name;
1977         uint32_t value;
1978 };
1979
1980 static void
1981 cmd_config_max_pkt_len_parsed(void *parsed_result,
1982                                 __rte_unused struct cmdline *cl,
1983                                 __rte_unused void *data)
1984 {
1985         struct cmd_config_max_pkt_len_result *res = parsed_result;
1986         portid_t pid;
1987
1988         if (!all_ports_stopped()) {
1989                 printf("Please stop all ports first\n");
1990                 return;
1991         }
1992
1993         RTE_ETH_FOREACH_DEV(pid) {
1994                 struct rte_port *port = &ports[pid];
1995                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1996
1997                 if (!strcmp(res->name, "max-pkt-len")) {
1998                         if (res->value < RTE_ETHER_MIN_LEN) {
1999                                 printf("max-pkt-len can not be less than %d\n",
2000                                                 RTE_ETHER_MIN_LEN);
2001                                 return;
2002                         }
2003                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2004                                 return;
2005
2006                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2007                         if (res->value > RTE_ETHER_MAX_LEN)
2008                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2009                         else
2010                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2011                         port->dev_conf.rxmode.offloads = rx_offloads;
2012                 } else {
2013                         printf("Unknown parameter\n");
2014                         return;
2015                 }
2016         }
2017
2018         init_port_config();
2019
2020         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2021 }
2022
2023 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2024         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2025                                                                 "port");
2026 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2027         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2028                                                                 "config");
2029 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2030         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2031                                                                 "all");
2032 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2033         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2034                                                                 "max-pkt-len");
2035 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2036         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2037                                                                 UINT32);
2038
2039 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2040         .f = cmd_config_max_pkt_len_parsed,
2041         .data = NULL,
2042         .help_str = "port config all max-pkt-len <value>",
2043         .tokens = {
2044                 (void *)&cmd_config_max_pkt_len_port,
2045                 (void *)&cmd_config_max_pkt_len_keyword,
2046                 (void *)&cmd_config_max_pkt_len_all,
2047                 (void *)&cmd_config_max_pkt_len_name,
2048                 (void *)&cmd_config_max_pkt_len_value,
2049                 NULL,
2050         },
2051 };
2052
2053 /* *** config max LRO aggregated packet size *** */
2054 struct cmd_config_max_lro_pkt_size_result {
2055         cmdline_fixed_string_t port;
2056         cmdline_fixed_string_t keyword;
2057         cmdline_fixed_string_t all;
2058         cmdline_fixed_string_t name;
2059         uint32_t value;
2060 };
2061
2062 static void
2063 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2064                                 __rte_unused struct cmdline *cl,
2065                                 __rte_unused void *data)
2066 {
2067         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2068         portid_t pid;
2069
2070         if (!all_ports_stopped()) {
2071                 printf("Please stop all ports first\n");
2072                 return;
2073         }
2074
2075         RTE_ETH_FOREACH_DEV(pid) {
2076                 struct rte_port *port = &ports[pid];
2077
2078                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2079                         if (res->value ==
2080                                         port->dev_conf.rxmode.max_lro_pkt_size)
2081                                 return;
2082
2083                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2084                 } else {
2085                         printf("Unknown parameter\n");
2086                         return;
2087                 }
2088         }
2089
2090         init_port_config();
2091
2092         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2093 }
2094
2095 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2096         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2097                                  port, "port");
2098 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2099         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2100                                  keyword, "config");
2101 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2102         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2103                                  all, "all");
2104 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2105         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2106                                  name, "max-lro-pkt-size");
2107 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2108         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2109                               value, UINT32);
2110
2111 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2112         .f = cmd_config_max_lro_pkt_size_parsed,
2113         .data = NULL,
2114         .help_str = "port config all max-lro-pkt-size <value>",
2115         .tokens = {
2116                 (void *)&cmd_config_max_lro_pkt_size_port,
2117                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2118                 (void *)&cmd_config_max_lro_pkt_size_all,
2119                 (void *)&cmd_config_max_lro_pkt_size_name,
2120                 (void *)&cmd_config_max_lro_pkt_size_value,
2121                 NULL,
2122         },
2123 };
2124
2125 /* *** configure port MTU *** */
2126 struct cmd_config_mtu_result {
2127         cmdline_fixed_string_t port;
2128         cmdline_fixed_string_t keyword;
2129         cmdline_fixed_string_t mtu;
2130         portid_t port_id;
2131         uint16_t value;
2132 };
2133
2134 static void
2135 cmd_config_mtu_parsed(void *parsed_result,
2136                       __rte_unused struct cmdline *cl,
2137                       __rte_unused void *data)
2138 {
2139         struct cmd_config_mtu_result *res = parsed_result;
2140
2141         if (res->value < RTE_ETHER_MIN_LEN) {
2142                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2143                 return;
2144         }
2145         port_mtu_set(res->port_id, res->value);
2146 }
2147
2148 cmdline_parse_token_string_t cmd_config_mtu_port =
2149         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2150                                  "port");
2151 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2152         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2153                                  "config");
2154 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2155         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2156                                  "mtu");
2157 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2158         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2159 cmdline_parse_token_num_t cmd_config_mtu_value =
2160         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2161
2162 cmdline_parse_inst_t cmd_config_mtu = {
2163         .f = cmd_config_mtu_parsed,
2164         .data = NULL,
2165         .help_str = "port config mtu <port_id> <value>",
2166         .tokens = {
2167                 (void *)&cmd_config_mtu_port,
2168                 (void *)&cmd_config_mtu_keyword,
2169                 (void *)&cmd_config_mtu_mtu,
2170                 (void *)&cmd_config_mtu_port_id,
2171                 (void *)&cmd_config_mtu_value,
2172                 NULL,
2173         },
2174 };
2175
2176 /* *** configure rx mode *** */
2177 struct cmd_config_rx_mode_flag {
2178         cmdline_fixed_string_t port;
2179         cmdline_fixed_string_t keyword;
2180         cmdline_fixed_string_t all;
2181         cmdline_fixed_string_t name;
2182         cmdline_fixed_string_t value;
2183 };
2184
2185 static void
2186 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2187                                 __rte_unused struct cmdline *cl,
2188                                 __rte_unused void *data)
2189 {
2190         struct cmd_config_rx_mode_flag *res = parsed_result;
2191
2192         if (!all_ports_stopped()) {
2193                 printf("Please stop all ports first\n");
2194                 return;
2195         }
2196
2197         if (!strcmp(res->name, "drop-en")) {
2198                 if (!strcmp(res->value, "on"))
2199                         rx_drop_en = 1;
2200                 else if (!strcmp(res->value, "off"))
2201                         rx_drop_en = 0;
2202                 else {
2203                         printf("Unknown parameter\n");
2204                         return;
2205                 }
2206         } else {
2207                 printf("Unknown parameter\n");
2208                 return;
2209         }
2210
2211         init_port_config();
2212
2213         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2214 }
2215
2216 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2217         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2218 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2219         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2220                                                                 "config");
2221 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2222         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2223 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2224         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2225                                         "drop-en");
2226 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2227         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2228                                                         "on#off");
2229
2230 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2231         .f = cmd_config_rx_mode_flag_parsed,
2232         .data = NULL,
2233         .help_str = "port config all drop-en on|off",
2234         .tokens = {
2235                 (void *)&cmd_config_rx_mode_flag_port,
2236                 (void *)&cmd_config_rx_mode_flag_keyword,
2237                 (void *)&cmd_config_rx_mode_flag_all,
2238                 (void *)&cmd_config_rx_mode_flag_name,
2239                 (void *)&cmd_config_rx_mode_flag_value,
2240                 NULL,
2241         },
2242 };
2243
2244 /* *** configure rss *** */
2245 struct cmd_config_rss {
2246         cmdline_fixed_string_t port;
2247         cmdline_fixed_string_t keyword;
2248         cmdline_fixed_string_t all;
2249         cmdline_fixed_string_t name;
2250         cmdline_fixed_string_t value;
2251 };
2252
2253 static void
2254 cmd_config_rss_parsed(void *parsed_result,
2255                         __rte_unused struct cmdline *cl,
2256                         __rte_unused void *data)
2257 {
2258         struct cmd_config_rss *res = parsed_result;
2259         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2260         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2261         int use_default = 0;
2262         int all_updated = 1;
2263         int diag;
2264         uint16_t i;
2265         int ret;
2266
2267         if (!strcmp(res->value, "all"))
2268                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2269                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2270                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2271                         ETH_RSS_AH | ETH_RSS_PFCP;
2272         else if (!strcmp(res->value, "eth"))
2273                 rss_conf.rss_hf = ETH_RSS_ETH;
2274         else if (!strcmp(res->value, "vlan"))
2275                 rss_conf.rss_hf = ETH_RSS_VLAN;
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, "l2-src-only"))
2303                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2304         else if (!strcmp(res->value, "l2-dst-only"))
2305                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2306         else if (!strcmp(res->value, "l2tpv3"))
2307                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2308         else if (!strcmp(res->value, "esp"))
2309                 rss_conf.rss_hf = ETH_RSS_ESP;
2310         else if (!strcmp(res->value, "ah"))
2311                 rss_conf.rss_hf = ETH_RSS_AH;
2312         else if (!strcmp(res->value, "pfcp"))
2313                 rss_conf.rss_hf = ETH_RSS_PFCP;
2314         else if (!strcmp(res->value, "none"))
2315                 rss_conf.rss_hf = 0;
2316         else if (!strcmp(res->value, "default"))
2317                 use_default = 1;
2318         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2319                                                 atoi(res->value) < 64)
2320                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2321         else {
2322                 printf("Unknown parameter\n");
2323                 return;
2324         }
2325         rss_conf.rss_key = NULL;
2326         /* Update global configuration for RSS types. */
2327         RTE_ETH_FOREACH_DEV(i) {
2328                 struct rte_eth_rss_conf local_rss_conf;
2329
2330                 ret = eth_dev_info_get_print_err(i, &dev_info);
2331                 if (ret != 0)
2332                         return;
2333
2334                 if (use_default)
2335                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2336
2337                 local_rss_conf = rss_conf;
2338                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2339                         dev_info.flow_type_rss_offloads;
2340                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2341                         printf("Port %u modified RSS hash function based on hardware support,"
2342                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2343                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2344                 }
2345                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2346                 if (diag < 0) {
2347                         all_updated = 0;
2348                         printf("Configuration of RSS hash at ethernet port %d "
2349                                 "failed with error (%d): %s.\n",
2350                                 i, -diag, strerror(-diag));
2351                 }
2352         }
2353         if (all_updated && !use_default) {
2354                 rss_hf = rss_conf.rss_hf;
2355                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2356         }
2357 }
2358
2359 cmdline_parse_token_string_t cmd_config_rss_port =
2360         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2361 cmdline_parse_token_string_t cmd_config_rss_keyword =
2362         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2363 cmdline_parse_token_string_t cmd_config_rss_all =
2364         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2365 cmdline_parse_token_string_t cmd_config_rss_name =
2366         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2367 cmdline_parse_token_string_t cmd_config_rss_value =
2368         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2369
2370 cmdline_parse_inst_t cmd_config_rss = {
2371         .f = cmd_config_rss_parsed,
2372         .data = NULL,
2373         .help_str = "port config all rss "
2374                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2375                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|<flowtype_id>",
2376         .tokens = {
2377                 (void *)&cmd_config_rss_port,
2378                 (void *)&cmd_config_rss_keyword,
2379                 (void *)&cmd_config_rss_all,
2380                 (void *)&cmd_config_rss_name,
2381                 (void *)&cmd_config_rss_value,
2382                 NULL,
2383         },
2384 };
2385
2386 /* *** configure rss hash key *** */
2387 struct cmd_config_rss_hash_key {
2388         cmdline_fixed_string_t port;
2389         cmdline_fixed_string_t config;
2390         portid_t port_id;
2391         cmdline_fixed_string_t rss_hash_key;
2392         cmdline_fixed_string_t rss_type;
2393         cmdline_fixed_string_t key;
2394 };
2395
2396 static uint8_t
2397 hexa_digit_to_value(char hexa_digit)
2398 {
2399         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2400                 return (uint8_t) (hexa_digit - '0');
2401         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2402                 return (uint8_t) ((hexa_digit - 'a') + 10);
2403         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2404                 return (uint8_t) ((hexa_digit - 'A') + 10);
2405         /* Invalid hexa digit */
2406         return 0xFF;
2407 }
2408
2409 static uint8_t
2410 parse_and_check_key_hexa_digit(char *key, int idx)
2411 {
2412         uint8_t hexa_v;
2413
2414         hexa_v = hexa_digit_to_value(key[idx]);
2415         if (hexa_v == 0xFF)
2416                 printf("invalid key: character %c at position %d is not a "
2417                        "valid hexa digit\n", key[idx], idx);
2418         return hexa_v;
2419 }
2420
2421 static void
2422 cmd_config_rss_hash_key_parsed(void *parsed_result,
2423                                __rte_unused struct cmdline *cl,
2424                                __rte_unused void *data)
2425 {
2426         struct cmd_config_rss_hash_key *res = parsed_result;
2427         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2428         uint8_t xdgt0;
2429         uint8_t xdgt1;
2430         int i;
2431         struct rte_eth_dev_info dev_info;
2432         uint8_t hash_key_size;
2433         uint32_t key_len;
2434         int ret;
2435
2436         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2437         if (ret != 0)
2438                 return;
2439
2440         if (dev_info.hash_key_size > 0 &&
2441                         dev_info.hash_key_size <= sizeof(hash_key))
2442                 hash_key_size = dev_info.hash_key_size;
2443         else {
2444                 printf("dev_info did not provide a valid hash key size\n");
2445                 return;
2446         }
2447         /* Check the length of the RSS hash key */
2448         key_len = strlen(res->key);
2449         if (key_len != (hash_key_size * 2)) {
2450                 printf("key length: %d invalid - key must be a string of %d"
2451                            " hexa-decimal numbers\n",
2452                            (int) key_len, hash_key_size * 2);
2453                 return;
2454         }
2455         /* Translate RSS hash key into binary representation */
2456         for (i = 0; i < hash_key_size; i++) {
2457                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2458                 if (xdgt0 == 0xFF)
2459                         return;
2460                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2461                 if (xdgt1 == 0xFF)
2462                         return;
2463                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2464         }
2465         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2466                         hash_key_size);
2467 }
2468
2469 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2470         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2471 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2472         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2473                                  "config");
2474 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2475         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2476 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2477         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2478                                  rss_hash_key, "rss-hash-key");
2479 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2480         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2481                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2482                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2483                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2484                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2485                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2486                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2487                                  "l2tpv3#esp#ah#pfcp");
2488 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2489         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2490
2491 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2492         .f = cmd_config_rss_hash_key_parsed,
2493         .data = NULL,
2494         .help_str = "port config <port_id> rss-hash-key "
2495                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2496                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2497                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2498                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2499                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2500                 "l2tpv3|esp|ah|pfcp "
2501                 "<string of hex digits (variable length, NIC dependent)>",
2502         .tokens = {
2503                 (void *)&cmd_config_rss_hash_key_port,
2504                 (void *)&cmd_config_rss_hash_key_config,
2505                 (void *)&cmd_config_rss_hash_key_port_id,
2506                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2507                 (void *)&cmd_config_rss_hash_key_rss_type,
2508                 (void *)&cmd_config_rss_hash_key_value,
2509                 NULL,
2510         },
2511 };
2512
2513 /* *** configure port rxq/txq ring size *** */
2514 struct cmd_config_rxtx_ring_size {
2515         cmdline_fixed_string_t port;
2516         cmdline_fixed_string_t config;
2517         portid_t portid;
2518         cmdline_fixed_string_t rxtxq;
2519         uint16_t qid;
2520         cmdline_fixed_string_t rsize;
2521         uint16_t size;
2522 };
2523
2524 static void
2525 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2526                                  __rte_unused struct cmdline *cl,
2527                                  __rte_unused void *data)
2528 {
2529         struct cmd_config_rxtx_ring_size *res = parsed_result;
2530         struct rte_port *port;
2531         uint8_t isrx;
2532
2533         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2534                 return;
2535
2536         if (res->portid == (portid_t)RTE_PORT_ALL) {
2537                 printf("Invalid port id\n");
2538                 return;
2539         }
2540
2541         port = &ports[res->portid];
2542
2543         if (!strcmp(res->rxtxq, "rxq"))
2544                 isrx = 1;
2545         else if (!strcmp(res->rxtxq, "txq"))
2546                 isrx = 0;
2547         else {
2548                 printf("Unknown parameter\n");
2549                 return;
2550         }
2551
2552         if (isrx && rx_queue_id_is_invalid(res->qid))
2553                 return;
2554         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2555                 return;
2556
2557         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2558                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2559                        rx_free_thresh);
2560                 return;
2561         }
2562
2563         if (isrx)
2564                 port->nb_rx_desc[res->qid] = res->size;
2565         else
2566                 port->nb_tx_desc[res->qid] = res->size;
2567
2568         cmd_reconfig_device_queue(res->portid, 0, 1);
2569 }
2570
2571 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2572         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2573                                  port, "port");
2574 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2575         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2576                                  config, "config");
2577 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2578         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2579                                  portid, UINT16);
2580 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2581         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2582                                  rxtxq, "rxq#txq");
2583 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2584         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2585                               qid, UINT16);
2586 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2587         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2588                                  rsize, "ring_size");
2589 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2590         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2591                               size, UINT16);
2592
2593 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2594         .f = cmd_config_rxtx_ring_size_parsed,
2595         .data = NULL,
2596         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2597         .tokens = {
2598                 (void *)&cmd_config_rxtx_ring_size_port,
2599                 (void *)&cmd_config_rxtx_ring_size_config,
2600                 (void *)&cmd_config_rxtx_ring_size_portid,
2601                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2602                 (void *)&cmd_config_rxtx_ring_size_qid,
2603                 (void *)&cmd_config_rxtx_ring_size_rsize,
2604                 (void *)&cmd_config_rxtx_ring_size_size,
2605                 NULL,
2606         },
2607 };
2608
2609 /* *** configure port rxq/txq start/stop *** */
2610 struct cmd_config_rxtx_queue {
2611         cmdline_fixed_string_t port;
2612         portid_t portid;
2613         cmdline_fixed_string_t rxtxq;
2614         uint16_t qid;
2615         cmdline_fixed_string_t opname;
2616 };
2617
2618 static void
2619 cmd_config_rxtx_queue_parsed(void *parsed_result,
2620                         __rte_unused struct cmdline *cl,
2621                         __rte_unused void *data)
2622 {
2623         struct cmd_config_rxtx_queue *res = parsed_result;
2624         uint8_t isrx;
2625         uint8_t isstart;
2626         int ret = 0;
2627
2628         if (test_done == 0) {
2629                 printf("Please stop forwarding first\n");
2630                 return;
2631         }
2632
2633         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2634                 return;
2635
2636         if (port_is_started(res->portid) != 1) {
2637                 printf("Please start port %u first\n", res->portid);
2638                 return;
2639         }
2640
2641         if (!strcmp(res->rxtxq, "rxq"))
2642                 isrx = 1;
2643         else if (!strcmp(res->rxtxq, "txq"))
2644                 isrx = 0;
2645         else {
2646                 printf("Unknown parameter\n");
2647                 return;
2648         }
2649
2650         if (isrx && rx_queue_id_is_invalid(res->qid))
2651                 return;
2652         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2653                 return;
2654
2655         if (!strcmp(res->opname, "start"))
2656                 isstart = 1;
2657         else if (!strcmp(res->opname, "stop"))
2658                 isstart = 0;
2659         else {
2660                 printf("Unknown parameter\n");
2661                 return;
2662         }
2663
2664         if (isstart && isrx)
2665                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2666         else if (!isstart && isrx)
2667                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2668         else if (isstart && !isrx)
2669                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2670         else
2671                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2672
2673         if (ret == -ENOTSUP)
2674                 printf("Function not supported in PMD driver\n");
2675 }
2676
2677 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2678         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2679 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2680         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2681 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2682         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2683 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2684         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2685 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2686         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2687                                                 "start#stop");
2688
2689 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2690         .f = cmd_config_rxtx_queue_parsed,
2691         .data = NULL,
2692         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2693         .tokens = {
2694                 (void *)&cmd_config_rxtx_queue_port,
2695                 (void *)&cmd_config_rxtx_queue_portid,
2696                 (void *)&cmd_config_rxtx_queue_rxtxq,
2697                 (void *)&cmd_config_rxtx_queue_qid,
2698                 (void *)&cmd_config_rxtx_queue_opname,
2699                 NULL,
2700         },
2701 };
2702
2703 /* *** configure port rxq/txq deferred start on/off *** */
2704 struct cmd_config_deferred_start_rxtx_queue {
2705         cmdline_fixed_string_t port;
2706         portid_t port_id;
2707         cmdline_fixed_string_t rxtxq;
2708         uint16_t qid;
2709         cmdline_fixed_string_t opname;
2710         cmdline_fixed_string_t state;
2711 };
2712
2713 static void
2714 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2715                         __rte_unused struct cmdline *cl,
2716                         __rte_unused void *data)
2717 {
2718         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2719         struct rte_port *port;
2720         uint8_t isrx;
2721         uint8_t ison;
2722         uint8_t needreconfig = 0;
2723
2724         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2725                 return;
2726
2727         if (port_is_started(res->port_id) != 0) {
2728                 printf("Please stop port %u first\n", res->port_id);
2729                 return;
2730         }
2731
2732         port = &ports[res->port_id];
2733
2734         isrx = !strcmp(res->rxtxq, "rxq");
2735
2736         if (isrx && rx_queue_id_is_invalid(res->qid))
2737                 return;
2738         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2739                 return;
2740
2741         ison = !strcmp(res->state, "on");
2742
2743         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2744                 port->rx_conf[res->qid].rx_deferred_start = ison;
2745                 needreconfig = 1;
2746         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2747                 port->tx_conf[res->qid].tx_deferred_start = ison;
2748                 needreconfig = 1;
2749         }
2750
2751         if (needreconfig)
2752                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2753 }
2754
2755 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2756         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2757                                                 port, "port");
2758 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2759         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2760                                                 port_id, UINT16);
2761 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2762         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2763                                                 rxtxq, "rxq#txq");
2764 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2765         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2766                                                 qid, UINT16);
2767 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2768         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2769                                                 opname, "deferred_start");
2770 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2771         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2772                                                 state, "on#off");
2773
2774 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2775         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2776         .data = NULL,
2777         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2778         .tokens = {
2779                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2780                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2781                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2782                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2783                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2784                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2785                 NULL,
2786         },
2787 };
2788
2789 /* *** configure port rxq/txq setup *** */
2790 struct cmd_setup_rxtx_queue {
2791         cmdline_fixed_string_t port;
2792         portid_t portid;
2793         cmdline_fixed_string_t rxtxq;
2794         uint16_t qid;
2795         cmdline_fixed_string_t setup;
2796 };
2797
2798 /* Common CLI fields for queue setup */
2799 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2800         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2801 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2802         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2803 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2804         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2805 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2806         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2807 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2808         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2809
2810 static void
2811 cmd_setup_rxtx_queue_parsed(
2812         void *parsed_result,
2813         __rte_unused struct cmdline *cl,
2814         __rte_unused void *data)
2815 {
2816         struct cmd_setup_rxtx_queue *res = parsed_result;
2817         struct rte_port *port;
2818         struct rte_mempool *mp;
2819         unsigned int socket_id;
2820         uint8_t isrx = 0;
2821         int ret;
2822
2823         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2824                 return;
2825
2826         if (res->portid == (portid_t)RTE_PORT_ALL) {
2827                 printf("Invalid port id\n");
2828                 return;
2829         }
2830
2831         if (!strcmp(res->rxtxq, "rxq"))
2832                 isrx = 1;
2833         else if (!strcmp(res->rxtxq, "txq"))
2834                 isrx = 0;
2835         else {
2836                 printf("Unknown parameter\n");
2837                 return;
2838         }
2839
2840         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2841                 printf("Invalid rx queue\n");
2842                 return;
2843         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2844                 printf("Invalid tx queue\n");
2845                 return;
2846         }
2847
2848         port = &ports[res->portid];
2849         if (isrx) {
2850                 socket_id = rxring_numa[res->portid];
2851                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2852                         socket_id = port->socket_id;
2853
2854                 mp = mbuf_pool_find(socket_id);
2855                 if (mp == NULL) {
2856                         printf("Failed to setup RX queue: "
2857                                 "No mempool allocation"
2858                                 " on the socket %d\n",
2859                                 rxring_numa[res->portid]);
2860                         return;
2861                 }
2862                 ret = rte_eth_rx_queue_setup(res->portid,
2863                                              res->qid,
2864                                              port->nb_rx_desc[res->qid],
2865                                              socket_id,
2866                                              &port->rx_conf[res->qid],
2867                                              mp);
2868                 if (ret)
2869                         printf("Failed to setup RX queue\n");
2870         } else {
2871                 socket_id = txring_numa[res->portid];
2872                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2873                         socket_id = port->socket_id;
2874
2875                 ret = rte_eth_tx_queue_setup(res->portid,
2876                                              res->qid,
2877                                              port->nb_tx_desc[res->qid],
2878                                              socket_id,
2879                                              &port->tx_conf[res->qid]);
2880                 if (ret)
2881                         printf("Failed to setup TX queue\n");
2882         }
2883 }
2884
2885 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2886         .f = cmd_setup_rxtx_queue_parsed,
2887         .data = NULL,
2888         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2889         .tokens = {
2890                 (void *)&cmd_setup_rxtx_queue_port,
2891                 (void *)&cmd_setup_rxtx_queue_portid,
2892                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2893                 (void *)&cmd_setup_rxtx_queue_qid,
2894                 (void *)&cmd_setup_rxtx_queue_setup,
2895                 NULL,
2896         },
2897 };
2898
2899
2900 /* *** Configure RSS RETA *** */
2901 struct cmd_config_rss_reta {
2902         cmdline_fixed_string_t port;
2903         cmdline_fixed_string_t keyword;
2904         portid_t port_id;
2905         cmdline_fixed_string_t name;
2906         cmdline_fixed_string_t list_name;
2907         cmdline_fixed_string_t list_of_items;
2908 };
2909
2910 static int
2911 parse_reta_config(const char *str,
2912                   struct rte_eth_rss_reta_entry64 *reta_conf,
2913                   uint16_t nb_entries)
2914 {
2915         int i;
2916         unsigned size;
2917         uint16_t hash_index, idx, shift;
2918         uint16_t nb_queue;
2919         char s[256];
2920         const char *p, *p0 = str;
2921         char *end;
2922         enum fieldnames {
2923                 FLD_HASH_INDEX = 0,
2924                 FLD_QUEUE,
2925                 _NUM_FLD
2926         };
2927         unsigned long int_fld[_NUM_FLD];
2928         char *str_fld[_NUM_FLD];
2929
2930         while ((p = strchr(p0,'(')) != NULL) {
2931                 ++p;
2932                 if((p0 = strchr(p,')')) == NULL)
2933                         return -1;
2934
2935                 size = p0 - p;
2936                 if(size >= sizeof(s))
2937                         return -1;
2938
2939                 snprintf(s, sizeof(s), "%.*s", size, p);
2940                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2941                         return -1;
2942                 for (i = 0; i < _NUM_FLD; i++) {
2943                         errno = 0;
2944                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2945                         if (errno != 0 || end == str_fld[i] ||
2946                                         int_fld[i] > 65535)
2947                                 return -1;
2948                 }
2949
2950                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2951                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2952
2953                 if (hash_index >= nb_entries) {
2954                         printf("Invalid RETA hash index=%d\n", hash_index);
2955                         return -1;
2956                 }
2957
2958                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2959                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2960                 reta_conf[idx].mask |= (1ULL << shift);
2961                 reta_conf[idx].reta[shift] = nb_queue;
2962         }
2963
2964         return 0;
2965 }
2966
2967 static void
2968 cmd_set_rss_reta_parsed(void *parsed_result,
2969                         __rte_unused struct cmdline *cl,
2970                         __rte_unused void *data)
2971 {
2972         int ret;
2973         struct rte_eth_dev_info dev_info;
2974         struct rte_eth_rss_reta_entry64 reta_conf[8];
2975         struct cmd_config_rss_reta *res = parsed_result;
2976
2977         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2978         if (ret != 0)
2979                 return;
2980
2981         if (dev_info.reta_size == 0) {
2982                 printf("Redirection table size is 0 which is "
2983                                         "invalid for RSS\n");
2984                 return;
2985         } else
2986                 printf("The reta size of port %d is %u\n",
2987                         res->port_id, dev_info.reta_size);
2988         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2989                 printf("Currently do not support more than %u entries of "
2990                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2991                 return;
2992         }
2993
2994         memset(reta_conf, 0, sizeof(reta_conf));
2995         if (!strcmp(res->list_name, "reta")) {
2996                 if (parse_reta_config(res->list_of_items, reta_conf,
2997                                                 dev_info.reta_size)) {
2998                         printf("Invalid RSS Redirection Table "
2999                                         "config entered\n");
3000                         return;
3001                 }
3002                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3003                                 reta_conf, dev_info.reta_size);
3004                 if (ret != 0)
3005                         printf("Bad redirection table parameter, "
3006                                         "return code = %d \n", ret);
3007         }
3008 }
3009
3010 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3011         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3012 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3013         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3014 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3015         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3016 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3017         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3018 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3019         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3020 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3021         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3022                                  NULL);
3023 cmdline_parse_inst_t cmd_config_rss_reta = {
3024         .f = cmd_set_rss_reta_parsed,
3025         .data = NULL,
3026         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3027         .tokens = {
3028                 (void *)&cmd_config_rss_reta_port,
3029                 (void *)&cmd_config_rss_reta_keyword,
3030                 (void *)&cmd_config_rss_reta_port_id,
3031                 (void *)&cmd_config_rss_reta_name,
3032                 (void *)&cmd_config_rss_reta_list_name,
3033                 (void *)&cmd_config_rss_reta_list_of_items,
3034                 NULL,
3035         },
3036 };
3037
3038 /* *** SHOW PORT RETA INFO *** */
3039 struct cmd_showport_reta {
3040         cmdline_fixed_string_t show;
3041         cmdline_fixed_string_t port;
3042         portid_t port_id;
3043         cmdline_fixed_string_t rss;
3044         cmdline_fixed_string_t reta;
3045         uint16_t size;
3046         cmdline_fixed_string_t list_of_items;
3047 };
3048
3049 static int
3050 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3051                            uint16_t nb_entries,
3052                            char *str)
3053 {
3054         uint32_t size;
3055         const char *p, *p0 = str;
3056         char s[256];
3057         char *end;
3058         char *str_fld[8];
3059         uint16_t i;
3060         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3061                         RTE_RETA_GROUP_SIZE;
3062         int ret;
3063
3064         p = strchr(p0, '(');
3065         if (p == NULL)
3066                 return -1;
3067         p++;
3068         p0 = strchr(p, ')');
3069         if (p0 == NULL)
3070                 return -1;
3071         size = p0 - p;
3072         if (size >= sizeof(s)) {
3073                 printf("The string size exceeds the internal buffer size\n");
3074                 return -1;
3075         }
3076         snprintf(s, sizeof(s), "%.*s", size, p);
3077         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3078         if (ret <= 0 || ret != num) {
3079                 printf("The bits of masks do not match the number of "
3080                                         "reta entries: %u\n", num);
3081                 return -1;
3082         }
3083         for (i = 0; i < ret; i++)
3084                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3085
3086         return 0;
3087 }
3088
3089 static void
3090 cmd_showport_reta_parsed(void *parsed_result,
3091                          __rte_unused struct cmdline *cl,
3092                          __rte_unused void *data)
3093 {
3094         struct cmd_showport_reta *res = parsed_result;
3095         struct rte_eth_rss_reta_entry64 reta_conf[8];
3096         struct rte_eth_dev_info dev_info;
3097         uint16_t max_reta_size;
3098         int ret;
3099
3100         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3101         if (ret != 0)
3102                 return;
3103
3104         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3105         if (res->size == 0 || res->size > max_reta_size) {
3106                 printf("Invalid redirection table size: %u (1-%u)\n",
3107                         res->size, max_reta_size);
3108                 return;
3109         }
3110
3111         memset(reta_conf, 0, sizeof(reta_conf));
3112         if (showport_parse_reta_config(reta_conf, res->size,
3113                                 res->list_of_items) < 0) {
3114                 printf("Invalid string: %s for reta masks\n",
3115                                         res->list_of_items);
3116                 return;
3117         }
3118         port_rss_reta_info(res->port_id, reta_conf, res->size);
3119 }
3120
3121 cmdline_parse_token_string_t cmd_showport_reta_show =
3122         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3123 cmdline_parse_token_string_t cmd_showport_reta_port =
3124         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3125 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3126         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3127 cmdline_parse_token_string_t cmd_showport_reta_rss =
3128         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3129 cmdline_parse_token_string_t cmd_showport_reta_reta =
3130         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3131 cmdline_parse_token_num_t cmd_showport_reta_size =
3132         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3133 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3134         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3135                                         list_of_items, NULL);
3136
3137 cmdline_parse_inst_t cmd_showport_reta = {
3138         .f = cmd_showport_reta_parsed,
3139         .data = NULL,
3140         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3141         .tokens = {
3142                 (void *)&cmd_showport_reta_show,
3143                 (void *)&cmd_showport_reta_port,
3144                 (void *)&cmd_showport_reta_port_id,
3145                 (void *)&cmd_showport_reta_rss,
3146                 (void *)&cmd_showport_reta_reta,
3147                 (void *)&cmd_showport_reta_size,
3148                 (void *)&cmd_showport_reta_list_of_items,
3149                 NULL,
3150         },
3151 };
3152
3153 /* *** Show RSS hash configuration *** */
3154 struct cmd_showport_rss_hash {
3155         cmdline_fixed_string_t show;
3156         cmdline_fixed_string_t port;
3157         portid_t port_id;
3158         cmdline_fixed_string_t rss_hash;
3159         cmdline_fixed_string_t rss_type;
3160         cmdline_fixed_string_t key; /* optional argument */
3161 };
3162
3163 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3164                                 __rte_unused struct cmdline *cl,
3165                                 void *show_rss_key)
3166 {
3167         struct cmd_showport_rss_hash *res = parsed_result;
3168
3169         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3170 }
3171
3172 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3173         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3174 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3175         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3176 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3177         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3178 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3179         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3180                                  "rss-hash");
3181 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3182         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3183
3184 cmdline_parse_inst_t cmd_showport_rss_hash = {
3185         .f = cmd_showport_rss_hash_parsed,
3186         .data = NULL,
3187         .help_str = "show port <port_id> rss-hash",
3188         .tokens = {
3189                 (void *)&cmd_showport_rss_hash_show,
3190                 (void *)&cmd_showport_rss_hash_port,
3191                 (void *)&cmd_showport_rss_hash_port_id,
3192                 (void *)&cmd_showport_rss_hash_rss_hash,
3193                 NULL,
3194         },
3195 };
3196
3197 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3198         .f = cmd_showport_rss_hash_parsed,
3199         .data = (void *)1,
3200         .help_str = "show port <port_id> rss-hash key",
3201         .tokens = {
3202                 (void *)&cmd_showport_rss_hash_show,
3203                 (void *)&cmd_showport_rss_hash_port,
3204                 (void *)&cmd_showport_rss_hash_port_id,
3205                 (void *)&cmd_showport_rss_hash_rss_hash,
3206                 (void *)&cmd_showport_rss_hash_rss_key,
3207                 NULL,
3208         },
3209 };
3210
3211 /* *** Configure DCB *** */
3212 struct cmd_config_dcb {
3213         cmdline_fixed_string_t port;
3214         cmdline_fixed_string_t config;
3215         portid_t port_id;
3216         cmdline_fixed_string_t dcb;
3217         cmdline_fixed_string_t vt;
3218         cmdline_fixed_string_t vt_en;
3219         uint8_t num_tcs;
3220         cmdline_fixed_string_t pfc;
3221         cmdline_fixed_string_t pfc_en;
3222 };
3223
3224 static void
3225 cmd_config_dcb_parsed(void *parsed_result,
3226                         __rte_unused struct cmdline *cl,
3227                         __rte_unused void *data)
3228 {
3229         struct cmd_config_dcb *res = parsed_result;
3230         portid_t port_id = res->port_id;
3231         struct rte_port *port;
3232         uint8_t pfc_en;
3233         int ret;
3234
3235         port = &ports[port_id];
3236         /** Check if the port is not started **/
3237         if (port->port_status != RTE_PORT_STOPPED) {
3238                 printf("Please stop port %d first\n", port_id);
3239                 return;
3240         }
3241
3242         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3243                 printf("The invalid number of traffic class,"
3244                         " only 4 or 8 allowed.\n");
3245                 return;
3246         }
3247
3248         if (nb_fwd_lcores < res->num_tcs) {
3249                 printf("nb_cores shouldn't be less than number of TCs.\n");
3250                 return;
3251         }
3252         if (!strncmp(res->pfc_en, "on", 2))
3253                 pfc_en = 1;
3254         else
3255                 pfc_en = 0;
3256
3257         /* DCB in VT mode */
3258         if (!strncmp(res->vt_en, "on", 2))
3259                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3260                                 (enum rte_eth_nb_tcs)res->num_tcs,
3261                                 pfc_en);
3262         else
3263                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3264                                 (enum rte_eth_nb_tcs)res->num_tcs,
3265                                 pfc_en);
3266
3267
3268         if (ret != 0) {
3269                 printf("Cannot initialize network ports.\n");
3270                 return;
3271         }
3272
3273         cmd_reconfig_device_queue(port_id, 1, 1);
3274 }
3275
3276 cmdline_parse_token_string_t cmd_config_dcb_port =
3277         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3278 cmdline_parse_token_string_t cmd_config_dcb_config =
3279         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3280 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3281         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3282 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3283         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3284 cmdline_parse_token_string_t cmd_config_dcb_vt =
3285         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3286 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3287         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3288 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3289         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3290 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3291         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3292 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3293         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3294
3295 cmdline_parse_inst_t cmd_config_dcb = {
3296         .f = cmd_config_dcb_parsed,
3297         .data = NULL,
3298         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3299         .tokens = {
3300                 (void *)&cmd_config_dcb_port,
3301                 (void *)&cmd_config_dcb_config,
3302                 (void *)&cmd_config_dcb_port_id,
3303                 (void *)&cmd_config_dcb_dcb,
3304                 (void *)&cmd_config_dcb_vt,
3305                 (void *)&cmd_config_dcb_vt_en,
3306                 (void *)&cmd_config_dcb_num_tcs,
3307                 (void *)&cmd_config_dcb_pfc,
3308                 (void *)&cmd_config_dcb_pfc_en,
3309                 NULL,
3310         },
3311 };
3312
3313 /* *** configure number of packets per burst *** */
3314 struct cmd_config_burst {
3315         cmdline_fixed_string_t port;
3316         cmdline_fixed_string_t keyword;
3317         cmdline_fixed_string_t all;
3318         cmdline_fixed_string_t name;
3319         uint16_t value;
3320 };
3321
3322 static void
3323 cmd_config_burst_parsed(void *parsed_result,
3324                         __rte_unused struct cmdline *cl,
3325                         __rte_unused void *data)
3326 {
3327         struct cmd_config_burst *res = parsed_result;
3328         struct rte_eth_dev_info dev_info;
3329         uint16_t rec_nb_pkts;
3330         int ret;
3331
3332         if (!all_ports_stopped()) {
3333                 printf("Please stop all ports first\n");
3334                 return;
3335         }
3336
3337         if (!strcmp(res->name, "burst")) {
3338                 if (res->value == 0) {
3339                         /* If user gives a value of zero, query the PMD for
3340                          * its recommended Rx burst size. Testpmd uses a single
3341                          * size for all ports, so assume all ports are the same
3342                          * NIC model and use the values from Port 0.
3343                          */
3344                         ret = eth_dev_info_get_print_err(0, &dev_info);
3345                         if (ret != 0)
3346                                 return;
3347
3348                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3349
3350                         if (rec_nb_pkts == 0) {
3351                                 printf("PMD does not recommend a burst size.\n"
3352                                         "User provided value must be between"
3353                                         " 1 and %d\n", MAX_PKT_BURST);
3354                                 return;
3355                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3356                                 printf("PMD recommended burst size of %d"
3357                                         " exceeds maximum value of %d\n",
3358                                         rec_nb_pkts, MAX_PKT_BURST);
3359                                 return;
3360                         }
3361                         printf("Using PMD-provided burst value of %d\n",
3362                                 rec_nb_pkts);
3363                         nb_pkt_per_burst = rec_nb_pkts;
3364                 } else if (res->value > MAX_PKT_BURST) {
3365                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3366                         return;
3367                 } else
3368                         nb_pkt_per_burst = res->value;
3369         } else {
3370                 printf("Unknown parameter\n");
3371                 return;
3372         }
3373
3374         init_port_config();
3375
3376         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3377 }
3378
3379 cmdline_parse_token_string_t cmd_config_burst_port =
3380         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3381 cmdline_parse_token_string_t cmd_config_burst_keyword =
3382         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3383 cmdline_parse_token_string_t cmd_config_burst_all =
3384         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3385 cmdline_parse_token_string_t cmd_config_burst_name =
3386         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3387 cmdline_parse_token_num_t cmd_config_burst_value =
3388         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3389
3390 cmdline_parse_inst_t cmd_config_burst = {
3391         .f = cmd_config_burst_parsed,
3392         .data = NULL,
3393         .help_str = "port config all burst <value>",
3394         .tokens = {
3395                 (void *)&cmd_config_burst_port,
3396                 (void *)&cmd_config_burst_keyword,
3397                 (void *)&cmd_config_burst_all,
3398                 (void *)&cmd_config_burst_name,
3399                 (void *)&cmd_config_burst_value,
3400                 NULL,
3401         },
3402 };
3403
3404 /* *** configure rx/tx queues *** */
3405 struct cmd_config_thresh {
3406         cmdline_fixed_string_t port;
3407         cmdline_fixed_string_t keyword;
3408         cmdline_fixed_string_t all;
3409         cmdline_fixed_string_t name;
3410         uint8_t value;
3411 };
3412
3413 static void
3414 cmd_config_thresh_parsed(void *parsed_result,
3415                         __rte_unused struct cmdline *cl,
3416                         __rte_unused void *data)
3417 {
3418         struct cmd_config_thresh *res = parsed_result;
3419
3420         if (!all_ports_stopped()) {
3421                 printf("Please stop all ports first\n");
3422                 return;
3423         }
3424
3425         if (!strcmp(res->name, "txpt"))
3426                 tx_pthresh = res->value;
3427         else if(!strcmp(res->name, "txht"))
3428                 tx_hthresh = res->value;
3429         else if(!strcmp(res->name, "txwt"))
3430                 tx_wthresh = res->value;
3431         else if(!strcmp(res->name, "rxpt"))
3432                 rx_pthresh = res->value;
3433         else if(!strcmp(res->name, "rxht"))
3434                 rx_hthresh = res->value;
3435         else if(!strcmp(res->name, "rxwt"))
3436                 rx_wthresh = res->value;
3437         else {
3438                 printf("Unknown parameter\n");
3439                 return;
3440         }
3441
3442         init_port_config();
3443
3444         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3445 }
3446
3447 cmdline_parse_token_string_t cmd_config_thresh_port =
3448         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3449 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3450         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3451 cmdline_parse_token_string_t cmd_config_thresh_all =
3452         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3453 cmdline_parse_token_string_t cmd_config_thresh_name =
3454         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3455                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3456 cmdline_parse_token_num_t cmd_config_thresh_value =
3457         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3458
3459 cmdline_parse_inst_t cmd_config_thresh = {
3460         .f = cmd_config_thresh_parsed,
3461         .data = NULL,
3462         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3463         .tokens = {
3464                 (void *)&cmd_config_thresh_port,
3465                 (void *)&cmd_config_thresh_keyword,
3466                 (void *)&cmd_config_thresh_all,
3467                 (void *)&cmd_config_thresh_name,
3468                 (void *)&cmd_config_thresh_value,
3469                 NULL,
3470         },
3471 };
3472
3473 /* *** configure free/rs threshold *** */
3474 struct cmd_config_threshold {
3475         cmdline_fixed_string_t port;
3476         cmdline_fixed_string_t keyword;
3477         cmdline_fixed_string_t all;
3478         cmdline_fixed_string_t name;
3479         uint16_t value;
3480 };
3481
3482 static void
3483 cmd_config_threshold_parsed(void *parsed_result,
3484                         __rte_unused struct cmdline *cl,
3485                         __rte_unused void *data)
3486 {
3487         struct cmd_config_threshold *res = parsed_result;
3488
3489         if (!all_ports_stopped()) {
3490                 printf("Please stop all ports first\n");
3491                 return;
3492         }
3493
3494         if (!strcmp(res->name, "txfreet"))
3495                 tx_free_thresh = res->value;
3496         else if (!strcmp(res->name, "txrst"))
3497                 tx_rs_thresh = res->value;
3498         else if (!strcmp(res->name, "rxfreet"))
3499                 rx_free_thresh = res->value;
3500         else {
3501                 printf("Unknown parameter\n");
3502                 return;
3503         }
3504
3505         init_port_config();
3506
3507         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3508 }
3509
3510 cmdline_parse_token_string_t cmd_config_threshold_port =
3511         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3512 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3513         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3514                                                                 "config");
3515 cmdline_parse_token_string_t cmd_config_threshold_all =
3516         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3517 cmdline_parse_token_string_t cmd_config_threshold_name =
3518         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3519                                                 "txfreet#txrst#rxfreet");
3520 cmdline_parse_token_num_t cmd_config_threshold_value =
3521         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3522
3523 cmdline_parse_inst_t cmd_config_threshold = {
3524         .f = cmd_config_threshold_parsed,
3525         .data = NULL,
3526         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3527         .tokens = {
3528                 (void *)&cmd_config_threshold_port,
3529                 (void *)&cmd_config_threshold_keyword,
3530                 (void *)&cmd_config_threshold_all,
3531                 (void *)&cmd_config_threshold_name,
3532                 (void *)&cmd_config_threshold_value,
3533                 NULL,
3534         },
3535 };
3536
3537 /* *** stop *** */
3538 struct cmd_stop_result {
3539         cmdline_fixed_string_t stop;
3540 };
3541
3542 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3543                             __rte_unused struct cmdline *cl,
3544                             __rte_unused void *data)
3545 {
3546         stop_packet_forwarding();
3547 }
3548
3549 cmdline_parse_token_string_t cmd_stop_stop =
3550         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3551
3552 cmdline_parse_inst_t cmd_stop = {
3553         .f = cmd_stop_parsed,
3554         .data = NULL,
3555         .help_str = "stop: Stop packet forwarding",
3556         .tokens = {
3557                 (void *)&cmd_stop_stop,
3558                 NULL,
3559         },
3560 };
3561
3562 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3563
3564 unsigned int
3565 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3566                 unsigned int *parsed_items, int check_unique_values)
3567 {
3568         unsigned int nb_item;
3569         unsigned int value;
3570         unsigned int i;
3571         unsigned int j;
3572         int value_ok;
3573         char c;
3574
3575         /*
3576          * First parse all items in the list and store their value.
3577          */
3578         value = 0;
3579         nb_item = 0;
3580         value_ok = 0;
3581         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3582                 c = str[i];
3583                 if ((c >= '0') && (c <= '9')) {
3584                         value = (unsigned int) (value * 10 + (c - '0'));
3585                         value_ok = 1;
3586                         continue;
3587                 }
3588                 if (c != ',') {
3589                         printf("character %c is not a decimal digit\n", c);
3590                         return 0;
3591                 }
3592                 if (! value_ok) {
3593                         printf("No valid value before comma\n");
3594                         return 0;
3595                 }
3596                 if (nb_item < max_items) {
3597                         parsed_items[nb_item] = value;
3598                         value_ok = 0;
3599                         value = 0;
3600                 }
3601                 nb_item++;
3602         }
3603         if (nb_item >= max_items) {
3604                 printf("Number of %s = %u > %u (maximum items)\n",
3605                        item_name, nb_item + 1, max_items);
3606                 return 0;
3607         }
3608         parsed_items[nb_item++] = value;
3609         if (! check_unique_values)
3610                 return nb_item;
3611
3612         /*
3613          * Then, check that all values in the list are differents.
3614          * No optimization here...
3615          */
3616         for (i = 0; i < nb_item; i++) {
3617                 for (j = i + 1; j < nb_item; j++) {
3618                         if (parsed_items[j] == parsed_items[i]) {
3619                                 printf("duplicated %s %u at index %u and %u\n",
3620                                        item_name, parsed_items[i], i, j);
3621                                 return 0;
3622                         }
3623                 }
3624         }
3625         return nb_item;
3626 }
3627
3628 struct cmd_set_list_result {
3629         cmdline_fixed_string_t cmd_keyword;
3630         cmdline_fixed_string_t list_name;
3631         cmdline_fixed_string_t list_of_items;
3632 };
3633
3634 static void cmd_set_list_parsed(void *parsed_result,
3635                                 __rte_unused struct cmdline *cl,
3636                                 __rte_unused void *data)
3637 {
3638         struct cmd_set_list_result *res;
3639         union {
3640                 unsigned int lcorelist[RTE_MAX_LCORE];
3641                 unsigned int portlist[RTE_MAX_ETHPORTS];
3642         } parsed_items;
3643         unsigned int nb_item;
3644
3645         if (test_done == 0) {
3646                 printf("Please stop forwarding first\n");
3647                 return;
3648         }
3649
3650         res = parsed_result;
3651         if (!strcmp(res->list_name, "corelist")) {
3652                 nb_item = parse_item_list(res->list_of_items, "core",
3653                                           RTE_MAX_LCORE,
3654                                           parsed_items.lcorelist, 1);
3655                 if (nb_item > 0) {
3656                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3657                         fwd_config_setup();
3658                 }
3659                 return;
3660         }
3661         if (!strcmp(res->list_name, "portlist")) {
3662                 nb_item = parse_item_list(res->list_of_items, "port",
3663                                           RTE_MAX_ETHPORTS,
3664                                           parsed_items.portlist, 1);
3665                 if (nb_item > 0) {
3666                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3667                         fwd_config_setup();
3668                 }
3669         }
3670 }
3671
3672 cmdline_parse_token_string_t cmd_set_list_keyword =
3673         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3674                                  "set");
3675 cmdline_parse_token_string_t cmd_set_list_name =
3676         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3677                                  "corelist#portlist");
3678 cmdline_parse_token_string_t cmd_set_list_of_items =
3679         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3680                                  NULL);
3681
3682 cmdline_parse_inst_t cmd_set_fwd_list = {
3683         .f = cmd_set_list_parsed,
3684         .data = NULL,
3685         .help_str = "set corelist|portlist <list0[,list1]*>",
3686         .tokens = {
3687                 (void *)&cmd_set_list_keyword,
3688                 (void *)&cmd_set_list_name,
3689                 (void *)&cmd_set_list_of_items,
3690                 NULL,
3691         },
3692 };
3693
3694 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3695
3696 struct cmd_setmask_result {
3697         cmdline_fixed_string_t set;
3698         cmdline_fixed_string_t mask;
3699         uint64_t hexavalue;
3700 };
3701
3702 static void cmd_set_mask_parsed(void *parsed_result,
3703                                 __rte_unused struct cmdline *cl,
3704                                 __rte_unused void *data)
3705 {
3706         struct cmd_setmask_result *res = parsed_result;
3707
3708         if (test_done == 0) {
3709                 printf("Please stop forwarding first\n");
3710                 return;
3711         }
3712         if (!strcmp(res->mask, "coremask")) {
3713                 set_fwd_lcores_mask(res->hexavalue);
3714                 fwd_config_setup();
3715         } else if (!strcmp(res->mask, "portmask")) {
3716                 set_fwd_ports_mask(res->hexavalue);
3717                 fwd_config_setup();
3718         }
3719 }
3720
3721 cmdline_parse_token_string_t cmd_setmask_set =
3722         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3723 cmdline_parse_token_string_t cmd_setmask_mask =
3724         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3725                                  "coremask#portmask");
3726 cmdline_parse_token_num_t cmd_setmask_value =
3727         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3728
3729 cmdline_parse_inst_t cmd_set_fwd_mask = {
3730         .f = cmd_set_mask_parsed,
3731         .data = NULL,
3732         .help_str = "set coremask|portmask <hexadecimal value>",
3733         .tokens = {
3734                 (void *)&cmd_setmask_set,
3735                 (void *)&cmd_setmask_mask,
3736                 (void *)&cmd_setmask_value,
3737                 NULL,
3738         },
3739 };
3740
3741 /*
3742  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3743  */
3744 struct cmd_set_result {
3745         cmdline_fixed_string_t set;
3746         cmdline_fixed_string_t what;
3747         uint16_t value;
3748 };
3749
3750 static void cmd_set_parsed(void *parsed_result,
3751                            __rte_unused struct cmdline *cl,
3752                            __rte_unused void *data)
3753 {
3754         struct cmd_set_result *res = parsed_result;
3755         if (!strcmp(res->what, "nbport")) {
3756                 set_fwd_ports_number(res->value);
3757                 fwd_config_setup();
3758         } else if (!strcmp(res->what, "nbcore")) {
3759                 set_fwd_lcores_number(res->value);
3760                 fwd_config_setup();
3761         } else if (!strcmp(res->what, "burst"))
3762                 set_nb_pkt_per_burst(res->value);
3763         else if (!strcmp(res->what, "verbose"))
3764                 set_verbose_level(res->value);
3765 }
3766
3767 cmdline_parse_token_string_t cmd_set_set =
3768         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3769 cmdline_parse_token_string_t cmd_set_what =
3770         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3771                                  "nbport#nbcore#burst#verbose");
3772 cmdline_parse_token_num_t cmd_set_value =
3773         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3774
3775 cmdline_parse_inst_t cmd_set_numbers = {
3776         .f = cmd_set_parsed,
3777         .data = NULL,
3778         .help_str = "set nbport|nbcore|burst|verbose <value>",
3779         .tokens = {
3780                 (void *)&cmd_set_set,
3781                 (void *)&cmd_set_what,
3782                 (void *)&cmd_set_value,
3783                 NULL,
3784         },
3785 };
3786
3787 /* *** SET LOG LEVEL CONFIGURATION *** */
3788
3789 struct cmd_set_log_result {
3790         cmdline_fixed_string_t set;
3791         cmdline_fixed_string_t log;
3792         cmdline_fixed_string_t type;
3793         uint32_t level;
3794 };
3795
3796 static void
3797 cmd_set_log_parsed(void *parsed_result,
3798                    __rte_unused struct cmdline *cl,
3799                    __rte_unused void *data)
3800 {
3801         struct cmd_set_log_result *res;
3802         int ret;
3803
3804         res = parsed_result;
3805         if (!strcmp(res->type, "global"))
3806                 rte_log_set_global_level(res->level);
3807         else {
3808                 ret = rte_log_set_level_regexp(res->type, res->level);
3809                 if (ret < 0)
3810                         printf("Unable to set log level\n");
3811         }
3812 }
3813
3814 cmdline_parse_token_string_t cmd_set_log_set =
3815         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3816 cmdline_parse_token_string_t cmd_set_log_log =
3817         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3818 cmdline_parse_token_string_t cmd_set_log_type =
3819         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3820 cmdline_parse_token_num_t cmd_set_log_level =
3821         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3822
3823 cmdline_parse_inst_t cmd_set_log = {
3824         .f = cmd_set_log_parsed,
3825         .data = NULL,
3826         .help_str = "set log global|<type> <level>",
3827         .tokens = {
3828                 (void *)&cmd_set_log_set,
3829                 (void *)&cmd_set_log_log,
3830                 (void *)&cmd_set_log_type,
3831                 (void *)&cmd_set_log_level,
3832                 NULL,
3833         },
3834 };
3835
3836 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3837
3838 struct cmd_set_txpkts_result {
3839         cmdline_fixed_string_t cmd_keyword;
3840         cmdline_fixed_string_t txpkts;
3841         cmdline_fixed_string_t seg_lengths;
3842 };
3843
3844 static void
3845 cmd_set_txpkts_parsed(void *parsed_result,
3846                       __rte_unused struct cmdline *cl,
3847                       __rte_unused void *data)
3848 {
3849         struct cmd_set_txpkts_result *res;
3850         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3851         unsigned int nb_segs;
3852
3853         res = parsed_result;
3854         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3855                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3856         if (nb_segs > 0)
3857                 set_tx_pkt_segments(seg_lengths, nb_segs);
3858 }
3859
3860 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3861         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3862                                  cmd_keyword, "set");
3863 cmdline_parse_token_string_t cmd_set_txpkts_name =
3864         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3865                                  txpkts, "txpkts");
3866 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3867         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3868                                  seg_lengths, NULL);
3869
3870 cmdline_parse_inst_t cmd_set_txpkts = {
3871         .f = cmd_set_txpkts_parsed,
3872         .data = NULL,
3873         .help_str = "set txpkts <len0[,len1]*>",
3874         .tokens = {
3875                 (void *)&cmd_set_txpkts_keyword,
3876                 (void *)&cmd_set_txpkts_name,
3877                 (void *)&cmd_set_txpkts_lengths,
3878                 NULL,
3879         },
3880 };
3881
3882 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3883
3884 struct cmd_set_txsplit_result {
3885         cmdline_fixed_string_t cmd_keyword;
3886         cmdline_fixed_string_t txsplit;
3887         cmdline_fixed_string_t mode;
3888 };
3889
3890 static void
3891 cmd_set_txsplit_parsed(void *parsed_result,
3892                       __rte_unused struct cmdline *cl,
3893                       __rte_unused void *data)
3894 {
3895         struct cmd_set_txsplit_result *res;
3896
3897         res = parsed_result;
3898         set_tx_pkt_split(res->mode);
3899 }
3900
3901 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3902         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3903                                  cmd_keyword, "set");
3904 cmdline_parse_token_string_t cmd_set_txsplit_name =
3905         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3906                                  txsplit, "txsplit");
3907 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3908         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3909                                  mode, NULL);
3910
3911 cmdline_parse_inst_t cmd_set_txsplit = {
3912         .f = cmd_set_txsplit_parsed,
3913         .data = NULL,
3914         .help_str = "set txsplit on|off|rand",
3915         .tokens = {
3916                 (void *)&cmd_set_txsplit_keyword,
3917                 (void *)&cmd_set_txsplit_name,
3918                 (void *)&cmd_set_txsplit_mode,
3919                 NULL,
3920         },
3921 };
3922
3923 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3924 struct cmd_rx_vlan_filter_all_result {
3925         cmdline_fixed_string_t rx_vlan;
3926         cmdline_fixed_string_t what;
3927         cmdline_fixed_string_t all;
3928         portid_t port_id;
3929 };
3930
3931 static void
3932 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3933                               __rte_unused struct cmdline *cl,
3934                               __rte_unused void *data)
3935 {
3936         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3937
3938         if (!strcmp(res->what, "add"))
3939                 rx_vlan_all_filter_set(res->port_id, 1);
3940         else
3941                 rx_vlan_all_filter_set(res->port_id, 0);
3942 }
3943
3944 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3945         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3946                                  rx_vlan, "rx_vlan");
3947 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3948         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3949                                  what, "add#rm");
3950 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3951         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3952                                  all, "all");
3953 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3954         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3955                               port_id, UINT16);
3956
3957 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3958         .f = cmd_rx_vlan_filter_all_parsed,
3959         .data = NULL,
3960         .help_str = "rx_vlan add|rm all <port_id>: "
3961                 "Add/Remove all identifiers to/from the set of VLAN "
3962                 "identifiers filtered by a port",
3963         .tokens = {
3964                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3965                 (void *)&cmd_rx_vlan_filter_all_what,
3966                 (void *)&cmd_rx_vlan_filter_all_all,
3967                 (void *)&cmd_rx_vlan_filter_all_portid,
3968                 NULL,
3969         },
3970 };
3971
3972 /* *** VLAN OFFLOAD SET ON A PORT *** */
3973 struct cmd_vlan_offload_result {
3974         cmdline_fixed_string_t vlan;
3975         cmdline_fixed_string_t set;
3976         cmdline_fixed_string_t vlan_type;
3977         cmdline_fixed_string_t what;
3978         cmdline_fixed_string_t on;
3979         cmdline_fixed_string_t port_id;
3980 };
3981
3982 static void
3983 cmd_vlan_offload_parsed(void *parsed_result,
3984                           __rte_unused struct cmdline *cl,
3985                           __rte_unused void *data)
3986 {
3987         int on;
3988         struct cmd_vlan_offload_result *res = parsed_result;
3989         char *str;
3990         int i, len = 0;
3991         portid_t port_id = 0;
3992         unsigned int tmp;
3993
3994         str = res->port_id;
3995         len = strnlen(str, STR_TOKEN_SIZE);
3996         i = 0;
3997         /* Get port_id first */
3998         while(i < len){
3999                 if(str[i] == ',')
4000                         break;
4001
4002                 i++;
4003         }
4004         str[i]='\0';
4005         tmp = strtoul(str, NULL, 0);
4006         /* If port_id greater that what portid_t can represent, return */
4007         if(tmp >= RTE_MAX_ETHPORTS)
4008                 return;
4009         port_id = (portid_t)tmp;
4010
4011         if (!strcmp(res->on, "on"))
4012                 on = 1;
4013         else
4014                 on = 0;
4015
4016         if (!strcmp(res->what, "strip"))
4017                 rx_vlan_strip_set(port_id,  on);
4018         else if(!strcmp(res->what, "stripq")){
4019                 uint16_t queue_id = 0;
4020
4021                 /* No queue_id, return */
4022                 if(i + 1 >= len) {
4023                         printf("must specify (port,queue_id)\n");
4024                         return;
4025                 }
4026                 tmp = strtoul(str + i + 1, NULL, 0);
4027                 /* If queue_id greater that what 16-bits can represent, return */
4028                 if(tmp > 0xffff)
4029                         return;
4030
4031                 queue_id = (uint16_t)tmp;
4032                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4033         }
4034         else if (!strcmp(res->what, "filter"))
4035                 rx_vlan_filter_set(port_id, on);
4036         else if (!strcmp(res->what, "qinq_strip"))
4037                 rx_vlan_qinq_strip_set(port_id, on);
4038         else
4039                 vlan_extend_set(port_id, on);
4040
4041         return;
4042 }
4043
4044 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4045         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4046                                  vlan, "vlan");
4047 cmdline_parse_token_string_t cmd_vlan_offload_set =
4048         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4049                                  set, "set");
4050 cmdline_parse_token_string_t cmd_vlan_offload_what =
4051         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4052                                 what, "strip#filter#qinq_strip#extend#stripq");
4053 cmdline_parse_token_string_t cmd_vlan_offload_on =
4054         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4055                               on, "on#off");
4056 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4057         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4058                               port_id, NULL);
4059
4060 cmdline_parse_inst_t cmd_vlan_offload = {
4061         .f = cmd_vlan_offload_parsed,
4062         .data = NULL,
4063         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4064                 "<port_id[,queue_id]>: "
4065                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4066         .tokens = {
4067                 (void *)&cmd_vlan_offload_vlan,
4068                 (void *)&cmd_vlan_offload_set,
4069                 (void *)&cmd_vlan_offload_what,
4070                 (void *)&cmd_vlan_offload_on,
4071                 (void *)&cmd_vlan_offload_portid,
4072                 NULL,
4073         },
4074 };
4075
4076 /* *** VLAN TPID SET ON A PORT *** */
4077 struct cmd_vlan_tpid_result {
4078         cmdline_fixed_string_t vlan;
4079         cmdline_fixed_string_t set;
4080         cmdline_fixed_string_t vlan_type;
4081         cmdline_fixed_string_t what;
4082         uint16_t tp_id;
4083         portid_t port_id;
4084 };
4085
4086 static void
4087 cmd_vlan_tpid_parsed(void *parsed_result,
4088                           __rte_unused struct cmdline *cl,
4089                           __rte_unused void *data)
4090 {
4091         struct cmd_vlan_tpid_result *res = parsed_result;
4092         enum rte_vlan_type vlan_type;
4093
4094         if (!strcmp(res->vlan_type, "inner"))
4095                 vlan_type = ETH_VLAN_TYPE_INNER;
4096         else if (!strcmp(res->vlan_type, "outer"))
4097                 vlan_type = ETH_VLAN_TYPE_OUTER;
4098         else {
4099                 printf("Unknown vlan type\n");
4100                 return;
4101         }
4102         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4103 }
4104
4105 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4106         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4107                                  vlan, "vlan");
4108 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4109         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4110                                  set, "set");
4111 cmdline_parse_token_string_t cmd_vlan_type =
4112         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4113                                  vlan_type, "inner#outer");
4114 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4115         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4116                                  what, "tpid");
4117 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4118         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4119                               tp_id, UINT16);
4120 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4121         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4122                               port_id, UINT16);
4123
4124 cmdline_parse_inst_t cmd_vlan_tpid = {
4125         .f = cmd_vlan_tpid_parsed,
4126         .data = NULL,
4127         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4128                 "Set the VLAN Ether type",
4129         .tokens = {
4130                 (void *)&cmd_vlan_tpid_vlan,
4131                 (void *)&cmd_vlan_tpid_set,
4132                 (void *)&cmd_vlan_type,
4133                 (void *)&cmd_vlan_tpid_what,
4134                 (void *)&cmd_vlan_tpid_tpid,
4135                 (void *)&cmd_vlan_tpid_portid,
4136                 NULL,
4137         },
4138 };
4139
4140 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4141 struct cmd_rx_vlan_filter_result {
4142         cmdline_fixed_string_t rx_vlan;
4143         cmdline_fixed_string_t what;
4144         uint16_t vlan_id;
4145         portid_t port_id;
4146 };
4147
4148 static void
4149 cmd_rx_vlan_filter_parsed(void *parsed_result,
4150                           __rte_unused struct cmdline *cl,
4151                           __rte_unused void *data)
4152 {
4153         struct cmd_rx_vlan_filter_result *res = parsed_result;
4154
4155         if (!strcmp(res->what, "add"))
4156                 rx_vft_set(res->port_id, res->vlan_id, 1);
4157         else
4158                 rx_vft_set(res->port_id, res->vlan_id, 0);
4159 }
4160
4161 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4162         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4163                                  rx_vlan, "rx_vlan");
4164 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4165         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4166                                  what, "add#rm");
4167 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4168         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4169                               vlan_id, UINT16);
4170 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4171         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4172                               port_id, UINT16);
4173
4174 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4175         .f = cmd_rx_vlan_filter_parsed,
4176         .data = NULL,
4177         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4178                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4179                 "identifiers filtered by a port",
4180         .tokens = {
4181                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4182                 (void *)&cmd_rx_vlan_filter_what,
4183                 (void *)&cmd_rx_vlan_filter_vlanid,
4184                 (void *)&cmd_rx_vlan_filter_portid,
4185                 NULL,
4186         },
4187 };
4188
4189 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4190 struct cmd_tx_vlan_set_result {
4191         cmdline_fixed_string_t tx_vlan;
4192         cmdline_fixed_string_t set;
4193         portid_t port_id;
4194         uint16_t vlan_id;
4195 };
4196
4197 static void
4198 cmd_tx_vlan_set_parsed(void *parsed_result,
4199                        __rte_unused struct cmdline *cl,
4200                        __rte_unused void *data)
4201 {
4202         struct cmd_tx_vlan_set_result *res = parsed_result;
4203
4204         if (!port_is_stopped(res->port_id)) {
4205                 printf("Please stop port %d first\n", res->port_id);
4206                 return;
4207         }
4208
4209         tx_vlan_set(res->port_id, res->vlan_id);
4210
4211         cmd_reconfig_device_queue(res->port_id, 1, 1);
4212 }
4213
4214 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4215         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4216                                  tx_vlan, "tx_vlan");
4217 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4218         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4219                                  set, "set");
4220 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4221         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4222                               port_id, UINT16);
4223 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4224         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4225                               vlan_id, UINT16);
4226
4227 cmdline_parse_inst_t cmd_tx_vlan_set = {
4228         .f = cmd_tx_vlan_set_parsed,
4229         .data = NULL,
4230         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4231                 "Enable hardware insertion of a single VLAN header "
4232                 "with a given TAG Identifier in packets sent on a port",
4233         .tokens = {
4234                 (void *)&cmd_tx_vlan_set_tx_vlan,
4235                 (void *)&cmd_tx_vlan_set_set,
4236                 (void *)&cmd_tx_vlan_set_portid,
4237                 (void *)&cmd_tx_vlan_set_vlanid,
4238                 NULL,
4239         },
4240 };
4241
4242 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4243 struct cmd_tx_vlan_set_qinq_result {
4244         cmdline_fixed_string_t tx_vlan;
4245         cmdline_fixed_string_t set;
4246         portid_t port_id;
4247         uint16_t vlan_id;
4248         uint16_t vlan_id_outer;
4249 };
4250
4251 static void
4252 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4253                             __rte_unused struct cmdline *cl,
4254                             __rte_unused void *data)
4255 {
4256         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4257
4258         if (!port_is_stopped(res->port_id)) {
4259                 printf("Please stop port %d first\n", res->port_id);
4260                 return;
4261         }
4262
4263         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4264
4265         cmd_reconfig_device_queue(res->port_id, 1, 1);
4266 }
4267
4268 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4269         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4270                 tx_vlan, "tx_vlan");
4271 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4272         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4273                 set, "set");
4274 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4275         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4276                 port_id, UINT16);
4277 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4278         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4279                 vlan_id, UINT16);
4280 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4281         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4282                 vlan_id_outer, UINT16);
4283
4284 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4285         .f = cmd_tx_vlan_set_qinq_parsed,
4286         .data = NULL,
4287         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4288                 "Enable hardware insertion of double VLAN header "
4289                 "with given TAG Identifiers in packets sent on a port",
4290         .tokens = {
4291                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4292                 (void *)&cmd_tx_vlan_set_qinq_set,
4293                 (void *)&cmd_tx_vlan_set_qinq_portid,
4294                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4295                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4296                 NULL,
4297         },
4298 };
4299
4300 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4301 struct cmd_tx_vlan_set_pvid_result {
4302         cmdline_fixed_string_t tx_vlan;
4303         cmdline_fixed_string_t set;
4304         cmdline_fixed_string_t pvid;
4305         portid_t port_id;
4306         uint16_t vlan_id;
4307         cmdline_fixed_string_t mode;
4308 };
4309
4310 static void
4311 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4312                             __rte_unused struct cmdline *cl,
4313                             __rte_unused void *data)
4314 {
4315         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4316
4317         if (strcmp(res->mode, "on") == 0)
4318                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4319         else
4320                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4321 }
4322
4323 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4324         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4325                                  tx_vlan, "tx_vlan");
4326 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4327         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4328                                  set, "set");
4329 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4330         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4331                                  pvid, "pvid");
4332 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4333         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4334                              port_id, UINT16);
4335 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4336         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4337                               vlan_id, UINT16);
4338 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4339         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4340                                  mode, "on#off");
4341
4342 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4343         .f = cmd_tx_vlan_set_pvid_parsed,
4344         .data = NULL,
4345         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4346         .tokens = {
4347                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4348                 (void *)&cmd_tx_vlan_set_pvid_set,
4349                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4350                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4351                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4352                 (void *)&cmd_tx_vlan_set_pvid_mode,
4353                 NULL,
4354         },
4355 };
4356
4357 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4358 struct cmd_tx_vlan_reset_result {
4359         cmdline_fixed_string_t tx_vlan;
4360         cmdline_fixed_string_t reset;
4361         portid_t port_id;
4362 };
4363
4364 static void
4365 cmd_tx_vlan_reset_parsed(void *parsed_result,
4366                          __rte_unused struct cmdline *cl,
4367                          __rte_unused void *data)
4368 {
4369         struct cmd_tx_vlan_reset_result *res = parsed_result;
4370
4371         if (!port_is_stopped(res->port_id)) {
4372                 printf("Please stop port %d first\n", res->port_id);
4373                 return;
4374         }
4375
4376         tx_vlan_reset(res->port_id);
4377
4378         cmd_reconfig_device_queue(res->port_id, 1, 1);
4379 }
4380
4381 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4382         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4383                                  tx_vlan, "tx_vlan");
4384 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4385         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4386                                  reset, "reset");
4387 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4388         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4389                               port_id, UINT16);
4390
4391 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4392         .f = cmd_tx_vlan_reset_parsed,
4393         .data = NULL,
4394         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4395                 "VLAN header in packets sent on a port",
4396         .tokens = {
4397                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4398                 (void *)&cmd_tx_vlan_reset_reset,
4399                 (void *)&cmd_tx_vlan_reset_portid,
4400                 NULL,
4401         },
4402 };
4403
4404
4405 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4406 struct cmd_csum_result {
4407         cmdline_fixed_string_t csum;
4408         cmdline_fixed_string_t mode;
4409         cmdline_fixed_string_t proto;
4410         cmdline_fixed_string_t hwsw;
4411         portid_t port_id;
4412 };
4413
4414 static void
4415 csum_show(int port_id)
4416 {
4417         struct rte_eth_dev_info dev_info;
4418         uint64_t tx_offloads;
4419         int ret;
4420
4421         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4422         printf("Parse tunnel is %s\n",
4423                 (ports[port_id].parse_tunnel) ? "on" : "off");
4424         printf("IP checksum offload is %s\n",
4425                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4426         printf("UDP checksum offload is %s\n",
4427                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4428         printf("TCP checksum offload is %s\n",
4429                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4430         printf("SCTP checksum offload is %s\n",
4431                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4432         printf("Outer-Ip checksum offload is %s\n",
4433                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4434         printf("Outer-Udp checksum offload is %s\n",
4435                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4436
4437         /* display warnings if configuration is not supported by the NIC */
4438         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4439         if (ret != 0)
4440                 return;
4441
4442         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4443                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4444                 printf("Warning: hardware IP checksum enabled but not "
4445                         "supported by port %d\n", port_id);
4446         }
4447         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4448                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4449                 printf("Warning: hardware UDP checksum enabled but not "
4450                         "supported by port %d\n", port_id);
4451         }
4452         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4453                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4454                 printf("Warning: hardware TCP checksum enabled but not "
4455                         "supported by port %d\n", port_id);
4456         }
4457         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4458                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4459                 printf("Warning: hardware SCTP checksum enabled but not "
4460                         "supported by port %d\n", port_id);
4461         }
4462         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4463                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4464                 printf("Warning: hardware outer IP checksum enabled but not "
4465                         "supported by port %d\n", port_id);
4466         }
4467         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4468                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4469                         == 0) {
4470                 printf("Warning: hardware outer UDP checksum enabled but not "
4471                         "supported by port %d\n", port_id);
4472         }
4473 }
4474
4475 static void
4476 cmd_config_queue_tx_offloads(struct rte_port *port)
4477 {
4478         int k;
4479
4480         /* Apply queue tx offloads configuration */
4481         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4482                 port->tx_conf[k].offloads =
4483                         port->dev_conf.txmode.offloads;
4484 }
4485
4486 static void
4487 cmd_csum_parsed(void *parsed_result,
4488                        __rte_unused struct cmdline *cl,
4489                        __rte_unused void *data)
4490 {
4491         struct cmd_csum_result *res = parsed_result;
4492         int hw = 0;
4493         uint64_t csum_offloads = 0;
4494         struct rte_eth_dev_info dev_info;
4495         int ret;
4496
4497         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4498                 printf("invalid port %d\n", res->port_id);
4499                 return;
4500         }
4501         if (!port_is_stopped(res->port_id)) {
4502                 printf("Please stop port %d first\n", res->port_id);
4503                 return;
4504         }
4505
4506         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4507         if (ret != 0)
4508                 return;
4509
4510         if (!strcmp(res->mode, "set")) {
4511
4512                 if (!strcmp(res->hwsw, "hw"))
4513                         hw = 1;
4514
4515                 if (!strcmp(res->proto, "ip")) {
4516                         if (hw == 0 || (dev_info.tx_offload_capa &
4517                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4518                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4519                         } else {
4520                                 printf("IP checksum offload is not supported "
4521                                        "by port %u\n", res->port_id);
4522                         }
4523                 } else if (!strcmp(res->proto, "udp")) {
4524                         if (hw == 0 || (dev_info.tx_offload_capa &
4525                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4526                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4527                         } else {
4528                                 printf("UDP checksum offload is not supported "
4529                                        "by port %u\n", res->port_id);
4530                         }
4531                 } else if (!strcmp(res->proto, "tcp")) {
4532                         if (hw == 0 || (dev_info.tx_offload_capa &
4533                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4534                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4535                         } else {
4536                                 printf("TCP checksum offload is not supported "
4537                                        "by port %u\n", res->port_id);
4538                         }
4539                 } else if (!strcmp(res->proto, "sctp")) {
4540                         if (hw == 0 || (dev_info.tx_offload_capa &
4541                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4542                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4543                         } else {
4544                                 printf("SCTP checksum offload is not supported "
4545                                        "by port %u\n", res->port_id);
4546                         }
4547                 } else if (!strcmp(res->proto, "outer-ip")) {
4548                         if (hw == 0 || (dev_info.tx_offload_capa &
4549                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4550                                 csum_offloads |=
4551                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4552                         } else {
4553                                 printf("Outer IP checksum offload is not "
4554                                        "supported by port %u\n", res->port_id);
4555                         }
4556                 } else if (!strcmp(res->proto, "outer-udp")) {
4557                         if (hw == 0 || (dev_info.tx_offload_capa &
4558                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4559                                 csum_offloads |=
4560                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4561                         } else {
4562                                 printf("Outer UDP checksum offload is not "
4563                                        "supported by port %u\n", res->port_id);
4564                         }
4565                 }
4566
4567                 if (hw) {
4568                         ports[res->port_id].dev_conf.txmode.offloads |=
4569                                                         csum_offloads;
4570                 } else {
4571                         ports[res->port_id].dev_conf.txmode.offloads &=
4572                                                         (~csum_offloads);
4573                 }
4574                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4575         }
4576         csum_show(res->port_id);
4577
4578         cmd_reconfig_device_queue(res->port_id, 1, 1);
4579 }
4580
4581 cmdline_parse_token_string_t cmd_csum_csum =
4582         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4583                                 csum, "csum");
4584 cmdline_parse_token_string_t cmd_csum_mode =
4585         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4586                                 mode, "set");
4587 cmdline_parse_token_string_t cmd_csum_proto =
4588         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4589                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4590 cmdline_parse_token_string_t cmd_csum_hwsw =
4591         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4592                                 hwsw, "hw#sw");
4593 cmdline_parse_token_num_t cmd_csum_portid =
4594         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4595                                 port_id, UINT16);
4596
4597 cmdline_parse_inst_t cmd_csum_set = {
4598         .f = cmd_csum_parsed,
4599         .data = NULL,
4600         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4601                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4602                 "using csum forward engine",
4603         .tokens = {
4604                 (void *)&cmd_csum_csum,
4605                 (void *)&cmd_csum_mode,
4606                 (void *)&cmd_csum_proto,
4607                 (void *)&cmd_csum_hwsw,
4608                 (void *)&cmd_csum_portid,
4609                 NULL,
4610         },
4611 };
4612
4613 cmdline_parse_token_string_t cmd_csum_mode_show =
4614         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4615                                 mode, "show");
4616
4617 cmdline_parse_inst_t cmd_csum_show = {
4618         .f = cmd_csum_parsed,
4619         .data = NULL,
4620         .help_str = "csum show <port_id>: Show checksum offload configuration",
4621         .tokens = {
4622                 (void *)&cmd_csum_csum,
4623                 (void *)&cmd_csum_mode_show,
4624                 (void *)&cmd_csum_portid,
4625                 NULL,
4626         },
4627 };
4628
4629 /* Enable/disable tunnel parsing */
4630 struct cmd_csum_tunnel_result {
4631         cmdline_fixed_string_t csum;
4632         cmdline_fixed_string_t parse;
4633         cmdline_fixed_string_t onoff;
4634         portid_t port_id;
4635 };
4636
4637 static void
4638 cmd_csum_tunnel_parsed(void *parsed_result,
4639                        __rte_unused struct cmdline *cl,
4640                        __rte_unused void *data)
4641 {
4642         struct cmd_csum_tunnel_result *res = parsed_result;
4643
4644         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4645                 return;
4646
4647         if (!strcmp(res->onoff, "on"))
4648                 ports[res->port_id].parse_tunnel = 1;
4649         else
4650                 ports[res->port_id].parse_tunnel = 0;
4651
4652         csum_show(res->port_id);
4653 }
4654
4655 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4656         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4657                                 csum, "csum");
4658 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4659         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4660                                 parse, "parse-tunnel");
4661 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4662         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4663                                 onoff, "on#off");
4664 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4665         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4666                                 port_id, UINT16);
4667
4668 cmdline_parse_inst_t cmd_csum_tunnel = {
4669         .f = cmd_csum_tunnel_parsed,
4670         .data = NULL,
4671         .help_str = "csum parse-tunnel on|off <port_id>: "
4672                 "Enable/Disable parsing of tunnels for csum engine",
4673         .tokens = {
4674                 (void *)&cmd_csum_tunnel_csum,
4675                 (void *)&cmd_csum_tunnel_parse,
4676                 (void *)&cmd_csum_tunnel_onoff,
4677                 (void *)&cmd_csum_tunnel_portid,
4678                 NULL,
4679         },
4680 };
4681
4682 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4683 struct cmd_tso_set_result {
4684         cmdline_fixed_string_t tso;
4685         cmdline_fixed_string_t mode;
4686         uint16_t tso_segsz;
4687         portid_t port_id;
4688 };
4689
4690 static void
4691 cmd_tso_set_parsed(void *parsed_result,
4692                        __rte_unused struct cmdline *cl,
4693                        __rte_unused void *data)
4694 {
4695         struct cmd_tso_set_result *res = parsed_result;
4696         struct rte_eth_dev_info dev_info;
4697         int ret;
4698
4699         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4700                 return;
4701         if (!port_is_stopped(res->port_id)) {
4702                 printf("Please stop port %d first\n", res->port_id);
4703                 return;
4704         }
4705
4706         if (!strcmp(res->mode, "set"))
4707                 ports[res->port_id].tso_segsz = res->tso_segsz;
4708
4709         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4710         if (ret != 0)
4711                 return;
4712
4713         if ((ports[res->port_id].tso_segsz != 0) &&
4714                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4715                 printf("Error: TSO is not supported by port %d\n",
4716                        res->port_id);
4717                 return;
4718         }
4719
4720         if (ports[res->port_id].tso_segsz == 0) {
4721                 ports[res->port_id].dev_conf.txmode.offloads &=
4722                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4723                 printf("TSO for non-tunneled packets is disabled\n");
4724         } else {
4725                 ports[res->port_id].dev_conf.txmode.offloads |=
4726                                                 DEV_TX_OFFLOAD_TCP_TSO;
4727                 printf("TSO segment size for non-tunneled packets is %d\n",
4728                         ports[res->port_id].tso_segsz);
4729         }
4730         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4731
4732         /* display warnings if configuration is not supported by the NIC */
4733         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4734         if (ret != 0)
4735                 return;
4736
4737         if ((ports[res->port_id].tso_segsz != 0) &&
4738                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4739                 printf("Warning: TSO enabled but not "
4740                         "supported by port %d\n", res->port_id);
4741         }
4742
4743         cmd_reconfig_device_queue(res->port_id, 1, 1);
4744 }
4745
4746 cmdline_parse_token_string_t cmd_tso_set_tso =
4747         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4748                                 tso, "tso");
4749 cmdline_parse_token_string_t cmd_tso_set_mode =
4750         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4751                                 mode, "set");
4752 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4753         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4754                                 tso_segsz, UINT16);
4755 cmdline_parse_token_num_t cmd_tso_set_portid =
4756         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4757                                 port_id, UINT16);
4758
4759 cmdline_parse_inst_t cmd_tso_set = {
4760         .f = cmd_tso_set_parsed,
4761         .data = NULL,
4762         .help_str = "tso set <tso_segsz> <port_id>: "
4763                 "Set TSO segment size of non-tunneled packets for csum engine "
4764                 "(0 to disable)",
4765         .tokens = {
4766                 (void *)&cmd_tso_set_tso,
4767                 (void *)&cmd_tso_set_mode,
4768                 (void *)&cmd_tso_set_tso_segsz,
4769                 (void *)&cmd_tso_set_portid,
4770                 NULL,
4771         },
4772 };
4773
4774 cmdline_parse_token_string_t cmd_tso_show_mode =
4775         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4776                                 mode, "show");
4777
4778
4779 cmdline_parse_inst_t cmd_tso_show = {
4780         .f = cmd_tso_set_parsed,
4781         .data = NULL,
4782         .help_str = "tso show <port_id>: "
4783                 "Show TSO segment size of non-tunneled packets for csum engine",
4784         .tokens = {
4785                 (void *)&cmd_tso_set_tso,
4786                 (void *)&cmd_tso_show_mode,
4787                 (void *)&cmd_tso_set_portid,
4788                 NULL,
4789         },
4790 };
4791
4792 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4793 struct cmd_tunnel_tso_set_result {
4794         cmdline_fixed_string_t tso;
4795         cmdline_fixed_string_t mode;
4796         uint16_t tso_segsz;
4797         portid_t port_id;
4798 };
4799
4800 static struct rte_eth_dev_info
4801 check_tunnel_tso_nic_support(portid_t port_id)
4802 {
4803         struct rte_eth_dev_info dev_info;
4804
4805         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4806                 return dev_info;
4807
4808         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4809                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4810                        "not enabled for port %d\n", port_id);
4811         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4812                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4813                        "not enabled for port %d\n", port_id);
4814         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4815                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4816                        "not enabled for port %d\n", port_id);
4817         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4818                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4819                        "not enabled for port %d\n", port_id);
4820         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4821                 printf("Warning: IP TUNNEL TSO not supported therefore "
4822                        "not enabled for port %d\n", port_id);
4823         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4824                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4825                        "not enabled for port %d\n", port_id);
4826         return dev_info;
4827 }
4828
4829 static void
4830 cmd_tunnel_tso_set_parsed(void *parsed_result,
4831                           __rte_unused struct cmdline *cl,
4832                           __rte_unused void *data)
4833 {
4834         struct cmd_tunnel_tso_set_result *res = parsed_result;
4835         struct rte_eth_dev_info dev_info;
4836
4837         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4838                 return;
4839         if (!port_is_stopped(res->port_id)) {
4840                 printf("Please stop port %d first\n", res->port_id);
4841                 return;
4842         }
4843
4844         if (!strcmp(res->mode, "set"))
4845                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4846
4847         dev_info = check_tunnel_tso_nic_support(res->port_id);
4848         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4849                 ports[res->port_id].dev_conf.txmode.offloads &=
4850                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4851                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4852                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4853                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4854                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4855                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4856                 printf("TSO for tunneled packets is disabled\n");
4857         } else {
4858                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4859                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4860                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4861                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4862                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4863                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4864
4865                 ports[res->port_id].dev_conf.txmode.offloads |=
4866                         (tso_offloads & dev_info.tx_offload_capa);
4867                 printf("TSO segment size for tunneled packets is %d\n",
4868                         ports[res->port_id].tunnel_tso_segsz);
4869
4870                 /* Below conditions are needed to make it work:
4871                  * (1) tunnel TSO is supported by the NIC;
4872                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4873                  * are recognized;
4874                  * (3) for tunneled pkts with outer L3 of IPv4,
4875                  * "csum set outer-ip" must be set to hw, because after tso,
4876                  * total_len of outer IP header is changed, and the checksum
4877                  * of outer IP header calculated by sw should be wrong; that
4878                  * is not necessary for IPv6 tunneled pkts because there's no
4879                  * checksum in IP header anymore.
4880                  */
4881
4882                 if (!ports[res->port_id].parse_tunnel)
4883                         printf("Warning: csum parse_tunnel must be set "
4884                                 "so that tunneled packets are recognized\n");
4885                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4886                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4887                         printf("Warning: csum set outer-ip must be set to hw "
4888                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4889         }
4890
4891         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4892         cmd_reconfig_device_queue(res->port_id, 1, 1);
4893 }
4894
4895 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4896         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4897                                 tso, "tunnel_tso");
4898 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4899         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4900                                 mode, "set");
4901 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4902         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4903                                 tso_segsz, UINT16);
4904 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4905         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4906                                 port_id, UINT16);
4907
4908 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4909         .f = cmd_tunnel_tso_set_parsed,
4910         .data = NULL,
4911         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4912                 "Set TSO segment size of tunneled packets for csum engine "
4913                 "(0 to disable)",
4914         .tokens = {
4915                 (void *)&cmd_tunnel_tso_set_tso,
4916                 (void *)&cmd_tunnel_tso_set_mode,
4917                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4918                 (void *)&cmd_tunnel_tso_set_portid,
4919                 NULL,
4920         },
4921 };
4922
4923 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4924         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4925                                 mode, "show");
4926
4927
4928 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4929         .f = cmd_tunnel_tso_set_parsed,
4930         .data = NULL,
4931         .help_str = "tunnel_tso show <port_id> "
4932                 "Show TSO segment size of tunneled packets for csum engine",
4933         .tokens = {
4934                 (void *)&cmd_tunnel_tso_set_tso,
4935                 (void *)&cmd_tunnel_tso_show_mode,
4936                 (void *)&cmd_tunnel_tso_set_portid,
4937                 NULL,
4938         },
4939 };
4940
4941 /* *** SET GRO FOR A PORT *** */
4942 struct cmd_gro_enable_result {
4943         cmdline_fixed_string_t cmd_set;
4944         cmdline_fixed_string_t cmd_port;
4945         cmdline_fixed_string_t cmd_keyword;
4946         cmdline_fixed_string_t cmd_onoff;
4947         portid_t cmd_pid;
4948 };
4949
4950 static void
4951 cmd_gro_enable_parsed(void *parsed_result,
4952                 __rte_unused struct cmdline *cl,
4953                 __rte_unused void *data)
4954 {
4955         struct cmd_gro_enable_result *res;
4956
4957         res = parsed_result;
4958         if (!strcmp(res->cmd_keyword, "gro"))
4959                 setup_gro(res->cmd_onoff, res->cmd_pid);
4960 }
4961
4962 cmdline_parse_token_string_t cmd_gro_enable_set =
4963         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4964                         cmd_set, "set");
4965 cmdline_parse_token_string_t cmd_gro_enable_port =
4966         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4967                         cmd_keyword, "port");
4968 cmdline_parse_token_num_t cmd_gro_enable_pid =
4969         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4970                         cmd_pid, UINT16);
4971 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4972         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4973                         cmd_keyword, "gro");
4974 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4975         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4976                         cmd_onoff, "on#off");
4977
4978 cmdline_parse_inst_t cmd_gro_enable = {
4979         .f = cmd_gro_enable_parsed,
4980         .data = NULL,
4981         .help_str = "set port <port_id> gro on|off",
4982         .tokens = {
4983                 (void *)&cmd_gro_enable_set,
4984                 (void *)&cmd_gro_enable_port,
4985                 (void *)&cmd_gro_enable_pid,
4986                 (void *)&cmd_gro_enable_keyword,
4987                 (void *)&cmd_gro_enable_onoff,
4988                 NULL,
4989         },
4990 };
4991
4992 /* *** DISPLAY GRO CONFIGURATION *** */
4993 struct cmd_gro_show_result {
4994         cmdline_fixed_string_t cmd_show;
4995         cmdline_fixed_string_t cmd_port;
4996         cmdline_fixed_string_t cmd_keyword;
4997         portid_t cmd_pid;
4998 };
4999
5000 static void
5001 cmd_gro_show_parsed(void *parsed_result,
5002                 __rte_unused struct cmdline *cl,
5003                 __rte_unused void *data)
5004 {
5005         struct cmd_gro_show_result *res;
5006
5007         res = parsed_result;
5008         if (!strcmp(res->cmd_keyword, "gro"))
5009                 show_gro(res->cmd_pid);
5010 }
5011
5012 cmdline_parse_token_string_t cmd_gro_show_show =
5013         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5014                         cmd_show, "show");
5015 cmdline_parse_token_string_t cmd_gro_show_port =
5016         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5017                         cmd_port, "port");
5018 cmdline_parse_token_num_t cmd_gro_show_pid =
5019         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5020                         cmd_pid, UINT16);
5021 cmdline_parse_token_string_t cmd_gro_show_keyword =
5022         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5023                         cmd_keyword, "gro");
5024
5025 cmdline_parse_inst_t cmd_gro_show = {
5026         .f = cmd_gro_show_parsed,
5027         .data = NULL,
5028         .help_str = "show port <port_id> gro",
5029         .tokens = {
5030                 (void *)&cmd_gro_show_show,
5031                 (void *)&cmd_gro_show_port,
5032                 (void *)&cmd_gro_show_pid,
5033                 (void *)&cmd_gro_show_keyword,
5034                 NULL,
5035         },
5036 };
5037
5038 /* *** SET FLUSH CYCLES FOR GRO *** */
5039 struct cmd_gro_flush_result {
5040         cmdline_fixed_string_t cmd_set;
5041         cmdline_fixed_string_t cmd_keyword;
5042         cmdline_fixed_string_t cmd_flush;
5043         uint8_t cmd_cycles;
5044 };
5045
5046 static void
5047 cmd_gro_flush_parsed(void *parsed_result,
5048                 __rte_unused struct cmdline *cl,
5049                 __rte_unused void *data)
5050 {
5051         struct cmd_gro_flush_result *res;
5052
5053         res = parsed_result;
5054         if ((!strcmp(res->cmd_keyword, "gro")) &&
5055                         (!strcmp(res->cmd_flush, "flush")))
5056                 setup_gro_flush_cycles(res->cmd_cycles);
5057 }
5058
5059 cmdline_parse_token_string_t cmd_gro_flush_set =
5060         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5061                         cmd_set, "set");
5062 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5063         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5064                         cmd_keyword, "gro");
5065 cmdline_parse_token_string_t cmd_gro_flush_flush =
5066         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5067                         cmd_flush, "flush");
5068 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5069         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5070                         cmd_cycles, UINT8);
5071
5072 cmdline_parse_inst_t cmd_gro_flush = {
5073         .f = cmd_gro_flush_parsed,
5074         .data = NULL,
5075         .help_str = "set gro flush <cycles>",
5076         .tokens = {
5077                 (void *)&cmd_gro_flush_set,
5078                 (void *)&cmd_gro_flush_keyword,
5079                 (void *)&cmd_gro_flush_flush,
5080                 (void *)&cmd_gro_flush_cycles,
5081                 NULL,
5082         },
5083 };
5084
5085 /* *** ENABLE/DISABLE GSO *** */
5086 struct cmd_gso_enable_result {
5087         cmdline_fixed_string_t cmd_set;
5088         cmdline_fixed_string_t cmd_port;
5089         cmdline_fixed_string_t cmd_keyword;
5090         cmdline_fixed_string_t cmd_mode;
5091         portid_t cmd_pid;
5092 };
5093
5094 static void
5095 cmd_gso_enable_parsed(void *parsed_result,
5096                 __rte_unused struct cmdline *cl,
5097                 __rte_unused void *data)
5098 {
5099         struct cmd_gso_enable_result *res;
5100
5101         res = parsed_result;
5102         if (!strcmp(res->cmd_keyword, "gso"))
5103                 setup_gso(res->cmd_mode, res->cmd_pid);
5104 }
5105
5106 cmdline_parse_token_string_t cmd_gso_enable_set =
5107         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5108                         cmd_set, "set");
5109 cmdline_parse_token_string_t cmd_gso_enable_port =
5110         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5111                         cmd_port, "port");
5112 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5113         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5114                         cmd_keyword, "gso");
5115 cmdline_parse_token_string_t cmd_gso_enable_mode =
5116         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5117                         cmd_mode, "on#off");
5118 cmdline_parse_token_num_t cmd_gso_enable_pid =
5119         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5120                         cmd_pid, UINT16);
5121
5122 cmdline_parse_inst_t cmd_gso_enable = {
5123         .f = cmd_gso_enable_parsed,
5124         .data = NULL,
5125         .help_str = "set port <port_id> gso on|off",
5126         .tokens = {
5127                 (void *)&cmd_gso_enable_set,
5128                 (void *)&cmd_gso_enable_port,
5129                 (void *)&cmd_gso_enable_pid,
5130                 (void *)&cmd_gso_enable_keyword,
5131                 (void *)&cmd_gso_enable_mode,
5132                 NULL,
5133         },
5134 };
5135
5136 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5137 struct cmd_gso_size_result {
5138         cmdline_fixed_string_t cmd_set;
5139         cmdline_fixed_string_t cmd_keyword;
5140         cmdline_fixed_string_t cmd_segsz;
5141         uint16_t cmd_size;
5142 };
5143
5144 static void
5145 cmd_gso_size_parsed(void *parsed_result,
5146                        __rte_unused struct cmdline *cl,
5147                        __rte_unused void *data)
5148 {
5149         struct cmd_gso_size_result *res = parsed_result;
5150
5151         if (test_done == 0) {
5152                 printf("Before setting GSO segsz, please first"
5153                                 " stop fowarding\n");
5154                 return;
5155         }
5156
5157         if (!strcmp(res->cmd_keyword, "gso") &&
5158                         !strcmp(res->cmd_segsz, "segsz")) {
5159                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5160                         printf("gso_size should be larger than %zu."
5161                                         " Please input a legal value\n",
5162                                         RTE_GSO_SEG_SIZE_MIN);
5163                 else
5164                         gso_max_segment_size = res->cmd_size;
5165         }
5166 }
5167
5168 cmdline_parse_token_string_t cmd_gso_size_set =
5169         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5170                                 cmd_set, "set");
5171 cmdline_parse_token_string_t cmd_gso_size_keyword =
5172         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5173                                 cmd_keyword, "gso");
5174 cmdline_parse_token_string_t cmd_gso_size_segsz =
5175         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5176                                 cmd_segsz, "segsz");
5177 cmdline_parse_token_num_t cmd_gso_size_size =
5178         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5179                                 cmd_size, UINT16);
5180
5181 cmdline_parse_inst_t cmd_gso_size = {
5182         .f = cmd_gso_size_parsed,
5183         .data = NULL,
5184         .help_str = "set gso segsz <length>",
5185         .tokens = {
5186                 (void *)&cmd_gso_size_set,
5187                 (void *)&cmd_gso_size_keyword,
5188                 (void *)&cmd_gso_size_segsz,
5189                 (void *)&cmd_gso_size_size,
5190                 NULL,
5191         },
5192 };
5193
5194 /* *** SHOW GSO CONFIGURATION *** */
5195 struct cmd_gso_show_result {
5196         cmdline_fixed_string_t cmd_show;
5197         cmdline_fixed_string_t cmd_port;
5198         cmdline_fixed_string_t cmd_keyword;
5199         portid_t cmd_pid;
5200 };
5201
5202 static void
5203 cmd_gso_show_parsed(void *parsed_result,
5204                        __rte_unused struct cmdline *cl,
5205                        __rte_unused void *data)
5206 {
5207         struct cmd_gso_show_result *res = parsed_result;
5208
5209         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5210                 printf("invalid port id %u\n", res->cmd_pid);
5211                 return;
5212         }
5213         if (!strcmp(res->cmd_keyword, "gso")) {
5214                 if (gso_ports[res->cmd_pid].enable) {
5215                         printf("Max GSO'd packet size: %uB\n"
5216                                         "Supported GSO types: TCP/IPv4, "
5217                                         "UDP/IPv4, VxLAN with inner "
5218                                         "TCP/IPv4 packet, GRE with inner "
5219                                         "TCP/IPv4 packet\n",
5220                                         gso_max_segment_size);
5221                 } else
5222                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5223         }
5224 }
5225
5226 cmdline_parse_token_string_t cmd_gso_show_show =
5227 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5228                 cmd_show, "show");
5229 cmdline_parse_token_string_t cmd_gso_show_port =
5230 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5231                 cmd_port, "port");
5232 cmdline_parse_token_string_t cmd_gso_show_keyword =
5233         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5234                                 cmd_keyword, "gso");
5235 cmdline_parse_token_num_t cmd_gso_show_pid =
5236         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5237                                 cmd_pid, UINT16);
5238
5239 cmdline_parse_inst_t cmd_gso_show = {
5240         .f = cmd_gso_show_parsed,
5241         .data = NULL,
5242         .help_str = "show port <port_id> gso",
5243         .tokens = {
5244                 (void *)&cmd_gso_show_show,
5245                 (void *)&cmd_gso_show_port,
5246                 (void *)&cmd_gso_show_pid,
5247                 (void *)&cmd_gso_show_keyword,
5248                 NULL,
5249         },
5250 };
5251
5252 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5253 struct cmd_set_flush_rx {
5254         cmdline_fixed_string_t set;
5255         cmdline_fixed_string_t flush_rx;
5256         cmdline_fixed_string_t mode;
5257 };
5258
5259 static void
5260 cmd_set_flush_rx_parsed(void *parsed_result,
5261                 __rte_unused struct cmdline *cl,
5262                 __rte_unused void *data)
5263 {
5264         struct cmd_set_flush_rx *res = parsed_result;
5265         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5266 }
5267
5268 cmdline_parse_token_string_t cmd_setflushrx_set =
5269         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5270                         set, "set");
5271 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5272         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5273                         flush_rx, "flush_rx");
5274 cmdline_parse_token_string_t cmd_setflushrx_mode =
5275         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5276                         mode, "on#off");
5277
5278
5279 cmdline_parse_inst_t cmd_set_flush_rx = {
5280         .f = cmd_set_flush_rx_parsed,
5281         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5282         .data = NULL,
5283         .tokens = {
5284                 (void *)&cmd_setflushrx_set,
5285                 (void *)&cmd_setflushrx_flush_rx,
5286                 (void *)&cmd_setflushrx_mode,
5287                 NULL,
5288         },
5289 };
5290
5291 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5292 struct cmd_set_link_check {
5293         cmdline_fixed_string_t set;
5294         cmdline_fixed_string_t link_check;
5295         cmdline_fixed_string_t mode;
5296 };
5297
5298 static void
5299 cmd_set_link_check_parsed(void *parsed_result,
5300                 __rte_unused struct cmdline *cl,
5301                 __rte_unused void *data)
5302 {
5303         struct cmd_set_link_check *res = parsed_result;
5304         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5305 }
5306
5307 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5308         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5309                         set, "set");
5310 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5311         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5312                         link_check, "link_check");
5313 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5314         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5315                         mode, "on#off");
5316
5317
5318 cmdline_parse_inst_t cmd_set_link_check = {
5319         .f = cmd_set_link_check_parsed,
5320         .help_str = "set link_check on|off: Enable/Disable link status check "
5321                     "when starting/stopping a port",
5322         .data = NULL,
5323         .tokens = {
5324                 (void *)&cmd_setlinkcheck_set,
5325                 (void *)&cmd_setlinkcheck_link_check,
5326                 (void *)&cmd_setlinkcheck_mode,
5327                 NULL,
5328         },
5329 };
5330
5331 /* *** SET NIC BYPASS MODE *** */
5332 struct cmd_set_bypass_mode_result {
5333         cmdline_fixed_string_t set;
5334         cmdline_fixed_string_t bypass;
5335         cmdline_fixed_string_t mode;
5336         cmdline_fixed_string_t value;
5337         portid_t port_id;
5338 };
5339
5340 static void
5341 cmd_set_bypass_mode_parsed(void *parsed_result,
5342                 __rte_unused struct cmdline *cl,
5343                 __rte_unused void *data)
5344 {
5345         struct cmd_set_bypass_mode_result *res = parsed_result;
5346         portid_t port_id = res->port_id;
5347         int32_t rc = -EINVAL;
5348
5349 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5350         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5351
5352         if (!strcmp(res->value, "bypass"))
5353                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5354         else if (!strcmp(res->value, "isolate"))
5355                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5356         else
5357                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5358
5359         /* Set the bypass mode for the relevant port. */
5360         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5361 #endif
5362         if (rc != 0)
5363                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5364 }
5365
5366 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5367         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5368                         set, "set");
5369 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5370         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5371                         bypass, "bypass");
5372 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5373         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5374                         mode, "mode");
5375 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5376         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5377                         value, "normal#bypass#isolate");
5378 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5379         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5380                                 port_id, UINT16);
5381
5382 cmdline_parse_inst_t cmd_set_bypass_mode = {
5383         .f = cmd_set_bypass_mode_parsed,
5384         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5385                     "Set the NIC bypass mode for port_id",
5386         .data = NULL,
5387         .tokens = {
5388                 (void *)&cmd_setbypass_mode_set,
5389                 (void *)&cmd_setbypass_mode_bypass,
5390                 (void *)&cmd_setbypass_mode_mode,
5391                 (void *)&cmd_setbypass_mode_value,
5392                 (void *)&cmd_setbypass_mode_port,
5393                 NULL,
5394         },
5395 };
5396
5397 /* *** SET NIC BYPASS EVENT *** */
5398 struct cmd_set_bypass_event_result {
5399         cmdline_fixed_string_t set;
5400         cmdline_fixed_string_t bypass;
5401         cmdline_fixed_string_t event;
5402         cmdline_fixed_string_t event_value;
5403         cmdline_fixed_string_t mode;
5404         cmdline_fixed_string_t mode_value;
5405         portid_t port_id;
5406 };
5407
5408 static void
5409 cmd_set_bypass_event_parsed(void *parsed_result,
5410                 __rte_unused struct cmdline *cl,
5411                 __rte_unused void *data)
5412 {
5413         int32_t rc = -EINVAL;
5414         struct cmd_set_bypass_event_result *res = parsed_result;
5415         portid_t port_id = res->port_id;
5416
5417 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5418         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5419         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5420
5421         if (!strcmp(res->event_value, "timeout"))
5422                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5423         else if (!strcmp(res->event_value, "os_on"))
5424                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5425         else if (!strcmp(res->event_value, "os_off"))
5426                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5427         else if (!strcmp(res->event_value, "power_on"))
5428                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5429         else if (!strcmp(res->event_value, "power_off"))
5430                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5431         else
5432                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5433
5434         if (!strcmp(res->mode_value, "bypass"))
5435                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5436         else if (!strcmp(res->mode_value, "isolate"))
5437                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5438         else
5439                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5440
5441         /* Set the watchdog timeout. */
5442         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5443
5444                 rc = -EINVAL;
5445                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5446                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5447                                                            bypass_timeout);
5448                 }
5449                 if (rc != 0) {
5450                         printf("Failed to set timeout value %u "
5451                         "for port %d, errto code: %d.\n",
5452                         bypass_timeout, port_id, rc);
5453                 }
5454         }
5455
5456         /* Set the bypass event to transition to bypass mode. */
5457         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5458                                               bypass_mode);
5459 #endif
5460
5461         if (rc != 0)
5462                 printf("\t Failed to set bypass event for port = %d.\n",
5463                        port_id);
5464 }
5465
5466 cmdline_parse_token_string_t cmd_setbypass_event_set =
5467         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5468                         set, "set");
5469 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5470         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5471                         bypass, "bypass");
5472 cmdline_parse_token_string_t cmd_setbypass_event_event =
5473         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5474                         event, "event");
5475 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5476         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5477                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5478 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5479         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5480                         mode, "mode");
5481 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5482         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5483                         mode_value, "normal#bypass#isolate");
5484 cmdline_parse_token_num_t cmd_setbypass_event_port =
5485         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5486                                 port_id, UINT16);
5487
5488 cmdline_parse_inst_t cmd_set_bypass_event = {
5489         .f = cmd_set_bypass_event_parsed,
5490         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5491                 "power_off mode normal|bypass|isolate <port_id>: "
5492                 "Set the NIC bypass event mode for port_id",
5493         .data = NULL,
5494         .tokens = {
5495                 (void *)&cmd_setbypass_event_set,
5496                 (void *)&cmd_setbypass_event_bypass,
5497                 (void *)&cmd_setbypass_event_event,
5498                 (void *)&cmd_setbypass_event_event_value,
5499                 (void *)&cmd_setbypass_event_mode,
5500                 (void *)&cmd_setbypass_event_mode_value,
5501                 (void *)&cmd_setbypass_event_port,
5502                 NULL,
5503         },
5504 };
5505
5506
5507 /* *** SET NIC BYPASS TIMEOUT *** */
5508 struct cmd_set_bypass_timeout_result {
5509         cmdline_fixed_string_t set;
5510         cmdline_fixed_string_t bypass;
5511         cmdline_fixed_string_t timeout;
5512         cmdline_fixed_string_t value;
5513 };
5514
5515 static void
5516 cmd_set_bypass_timeout_parsed(void *parsed_result,
5517                 __rte_unused struct cmdline *cl,
5518                 __rte_unused void *data)
5519 {
5520         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5521
5522 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5523         if (!strcmp(res->value, "1.5"))
5524                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5525         else if (!strcmp(res->value, "2"))
5526                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5527         else if (!strcmp(res->value, "3"))
5528                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5529         else if (!strcmp(res->value, "4"))
5530                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5531         else if (!strcmp(res->value, "8"))
5532                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5533         else if (!strcmp(res->value, "16"))
5534                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5535         else if (!strcmp(res->value, "32"))
5536                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5537         else
5538                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5539 #endif
5540 }
5541
5542 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5543         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5544                         set, "set");
5545 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5546         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5547                         bypass, "bypass");
5548 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5549         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5550                         timeout, "timeout");
5551 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5552         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5553                         value, "0#1.5#2#3#4#8#16#32");
5554
5555 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5556         .f = cmd_set_bypass_timeout_parsed,
5557         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5558                 "Set the NIC bypass watchdog timeout in seconds",
5559         .data = NULL,
5560         .tokens = {
5561                 (void *)&cmd_setbypass_timeout_set,
5562                 (void *)&cmd_setbypass_timeout_bypass,
5563                 (void *)&cmd_setbypass_timeout_timeout,
5564                 (void *)&cmd_setbypass_timeout_value,
5565                 NULL,
5566         },
5567 };
5568
5569 /* *** SHOW NIC BYPASS MODE *** */
5570 struct cmd_show_bypass_config_result {
5571         cmdline_fixed_string_t show;
5572         cmdline_fixed_string_t bypass;
5573         cmdline_fixed_string_t config;
5574         portid_t port_id;
5575 };
5576
5577 static void
5578 cmd_show_bypass_config_parsed(void *parsed_result,
5579                 __rte_unused struct cmdline *cl,
5580                 __rte_unused void *data)
5581 {
5582         struct cmd_show_bypass_config_result *res = parsed_result;
5583         portid_t port_id = res->port_id;
5584         int rc = -EINVAL;
5585 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5586         uint32_t event_mode;
5587         uint32_t bypass_mode;
5588         uint32_t timeout = bypass_timeout;
5589         unsigned int i;
5590
5591         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5592                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5593         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5594                 {"UNKNOWN", "normal", "bypass", "isolate"};
5595         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5596                 "NONE",
5597                 "OS/board on",
5598                 "power supply on",
5599                 "OS/board off",
5600                 "power supply off",
5601                 "timeout"};
5602
5603         /* Display the bypass mode.*/
5604         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5605                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5606                 return;
5607         }
5608         else {
5609                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5610                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5611
5612                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5613         }
5614
5615         /* Display the bypass timeout.*/
5616         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5617                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5618
5619         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5620
5621         /* Display the bypass events and associated modes. */
5622         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5623
5624                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5625                         printf("\tFailed to get bypass mode for event = %s\n",
5626                                 events[i]);
5627                 } else {
5628                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5629                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5630
5631                         printf("\tbypass event: %-16s = %s\n", events[i],
5632                                 modes[event_mode]);
5633                 }
5634         }
5635 #endif
5636         if (rc != 0)
5637                 printf("\tFailed to get bypass configuration for port = %d\n",
5638                        port_id);
5639 }
5640
5641 cmdline_parse_token_string_t cmd_showbypass_config_show =
5642         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5643                         show, "show");
5644 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5645         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5646                         bypass, "bypass");
5647 cmdline_parse_token_string_t cmd_showbypass_config_config =
5648         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5649                         config, "config");
5650 cmdline_parse_token_num_t cmd_showbypass_config_port =
5651         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5652                                 port_id, UINT16);
5653
5654 cmdline_parse_inst_t cmd_show_bypass_config = {
5655         .f = cmd_show_bypass_config_parsed,
5656         .help_str = "show bypass config <port_id>: "
5657                     "Show the NIC bypass config for port_id",
5658         .data = NULL,
5659         .tokens = {
5660                 (void *)&cmd_showbypass_config_show,
5661                 (void *)&cmd_showbypass_config_bypass,
5662                 (void *)&cmd_showbypass_config_config,
5663                 (void *)&cmd_showbypass_config_port,
5664                 NULL,
5665         },
5666 };
5667
5668 #ifdef RTE_LIBRTE_PMD_BOND
5669 /* *** SET BONDING MODE *** */
5670 struct cmd_set_bonding_mode_result {
5671         cmdline_fixed_string_t set;
5672         cmdline_fixed_string_t bonding;
5673         cmdline_fixed_string_t mode;
5674         uint8_t value;
5675         portid_t port_id;
5676 };
5677
5678 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5679                 __rte_unused  struct cmdline *cl,
5680                 __rte_unused void *data)
5681 {
5682         struct cmd_set_bonding_mode_result *res = parsed_result;
5683         portid_t port_id = res->port_id;
5684
5685         /* Set the bonding mode for the relevant port. */
5686         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5687                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5688 }
5689
5690 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5691 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5692                 set, "set");
5693 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5694 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5695                 bonding, "bonding");
5696 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5697 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5698                 mode, "mode");
5699 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5700 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5701                 value, UINT8);
5702 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5703 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5704                 port_id, UINT16);
5705
5706 cmdline_parse_inst_t cmd_set_bonding_mode = {
5707                 .f = cmd_set_bonding_mode_parsed,
5708                 .help_str = "set bonding mode <mode_value> <port_id>: "
5709                         "Set the bonding mode for port_id",
5710                 .data = NULL,
5711                 .tokens = {
5712                                 (void *) &cmd_setbonding_mode_set,
5713                                 (void *) &cmd_setbonding_mode_bonding,
5714                                 (void *) &cmd_setbonding_mode_mode,
5715                                 (void *) &cmd_setbonding_mode_value,
5716                                 (void *) &cmd_setbonding_mode_port,
5717                                 NULL
5718                 }
5719 };
5720
5721 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5722 struct cmd_set_bonding_lacp_dedicated_queues_result {
5723         cmdline_fixed_string_t set;
5724         cmdline_fixed_string_t bonding;
5725         cmdline_fixed_string_t lacp;
5726         cmdline_fixed_string_t dedicated_queues;
5727         portid_t port_id;
5728         cmdline_fixed_string_t mode;
5729 };
5730
5731 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5732                 __rte_unused  struct cmdline *cl,
5733                 __rte_unused void *data)
5734 {
5735         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5736         portid_t port_id = res->port_id;
5737         struct rte_port *port;
5738
5739         port = &ports[port_id];
5740
5741         /** Check if the port is not started **/
5742         if (port->port_status != RTE_PORT_STOPPED) {
5743                 printf("Please stop port %d first\n", port_id);
5744                 return;
5745         }
5746
5747         if (!strcmp(res->mode, "enable")) {
5748                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5749                         printf("Dedicate queues for LACP control packets"
5750                                         " enabled\n");
5751                 else
5752                         printf("Enabling dedicate queues for LACP control "
5753                                         "packets on port %d failed\n", port_id);
5754         } else if (!strcmp(res->mode, "disable")) {
5755                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5756                         printf("Dedicated queues for LACP control packets "
5757                                         "disabled\n");
5758                 else
5759                         printf("Disabling dedicated queues for LACP control "
5760                                         "traffic on port %d failed\n", port_id);
5761         }
5762 }
5763
5764 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5765 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5766                 set, "set");
5767 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5768 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5769                 bonding, "bonding");
5770 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5771 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5772                 lacp, "lacp");
5773 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5774 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5775                 dedicated_queues, "dedicated_queues");
5776 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5777 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5778                 port_id, UINT16);
5779 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5780 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5781                 mode, "enable#disable");
5782
5783 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5784                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5785                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5786                         "enable|disable: "
5787                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5788                 .data = NULL,
5789                 .tokens = {
5790                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5791                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5792                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5793                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5794                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5795                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5796                         NULL
5797                 }
5798 };
5799
5800 /* *** SET BALANCE XMIT POLICY *** */
5801 struct cmd_set_bonding_balance_xmit_policy_result {
5802         cmdline_fixed_string_t set;
5803         cmdline_fixed_string_t bonding;
5804         cmdline_fixed_string_t balance_xmit_policy;
5805         portid_t port_id;
5806         cmdline_fixed_string_t policy;
5807 };
5808
5809 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5810                 __rte_unused  struct cmdline *cl,
5811                 __rte_unused void *data)
5812 {
5813         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5814         portid_t port_id = res->port_id;
5815         uint8_t policy;
5816
5817         if (!strcmp(res->policy, "l2")) {
5818                 policy = BALANCE_XMIT_POLICY_LAYER2;
5819         } else if (!strcmp(res->policy, "l23")) {
5820                 policy = BALANCE_XMIT_POLICY_LAYER23;
5821         } else if (!strcmp(res->policy, "l34")) {
5822                 policy = BALANCE_XMIT_POLICY_LAYER34;
5823         } else {
5824                 printf("\t Invalid xmit policy selection");
5825                 return;
5826         }
5827
5828         /* Set the bonding mode for the relevant port. */
5829         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5830                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5831                                 port_id);
5832         }
5833 }
5834
5835 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5836 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5837                 set, "set");
5838 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5839 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5840                 bonding, "bonding");
5841 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5842 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5843                 balance_xmit_policy, "balance_xmit_policy");
5844 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5845 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5846                 port_id, UINT16);
5847 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5848 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5849                 policy, "l2#l23#l34");
5850
5851 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5852                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5853                 .help_str = "set bonding balance_xmit_policy <port_id> "
5854                         "l2|l23|l34: "
5855                         "Set the bonding balance_xmit_policy for port_id",
5856                 .data = NULL,
5857                 .tokens = {
5858                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5859                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5860                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5861                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5862                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5863                                 NULL
5864                 }
5865 };
5866
5867 /* *** SHOW NIC BONDING CONFIGURATION *** */
5868 struct cmd_show_bonding_config_result {
5869         cmdline_fixed_string_t show;
5870         cmdline_fixed_string_t bonding;
5871         cmdline_fixed_string_t config;
5872         portid_t port_id;
5873 };
5874
5875 static void cmd_show_bonding_config_parsed(void *parsed_result,
5876                 __rte_unused  struct cmdline *cl,
5877                 __rte_unused void *data)
5878 {
5879         struct cmd_show_bonding_config_result *res = parsed_result;
5880         int bonding_mode, agg_mode;
5881         portid_t slaves[RTE_MAX_ETHPORTS];
5882         int num_slaves, num_active_slaves;
5883         int primary_id;
5884         int i;
5885         portid_t port_id = res->port_id;
5886
5887         /* Display the bonding mode.*/
5888         bonding_mode = rte_eth_bond_mode_get(port_id);
5889         if (bonding_mode < 0) {
5890                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5891                 return;
5892         } else
5893                 printf("\tBonding mode: %d\n", bonding_mode);
5894
5895         if (bonding_mode == BONDING_MODE_BALANCE) {
5896                 int balance_xmit_policy;
5897
5898                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5899                 if (balance_xmit_policy < 0) {
5900                         printf("\tFailed to get balance xmit policy for port = %d\n",
5901                                         port_id);
5902                         return;
5903                 } else {
5904                         printf("\tBalance Xmit Policy: ");
5905
5906                         switch (balance_xmit_policy) {
5907                         case BALANCE_XMIT_POLICY_LAYER2:
5908                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5909                                 break;
5910                         case BALANCE_XMIT_POLICY_LAYER23:
5911                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5912                                 break;
5913                         case BALANCE_XMIT_POLICY_LAYER34:
5914                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5915                                 break;
5916                         }
5917                         printf("\n");
5918                 }
5919         }
5920
5921         if (bonding_mode == BONDING_MODE_8023AD) {
5922                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5923                 printf("\tIEEE802.3AD Aggregator Mode: ");
5924                 switch (agg_mode) {
5925                 case AGG_BANDWIDTH:
5926                         printf("bandwidth");
5927                         break;
5928                 case AGG_STABLE:
5929                         printf("stable");
5930                         break;
5931                 case AGG_COUNT:
5932                         printf("count");
5933                         break;
5934                 }
5935                 printf("\n");
5936         }
5937
5938         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5939
5940         if (num_slaves < 0) {
5941                 printf("\tFailed to get slave list for port = %d\n", port_id);
5942                 return;
5943         }
5944         if (num_slaves > 0) {
5945                 printf("\tSlaves (%d): [", num_slaves);
5946                 for (i = 0; i < num_slaves - 1; i++)
5947                         printf("%d ", slaves[i]);
5948
5949                 printf("%d]\n", slaves[num_slaves - 1]);
5950         } else {
5951                 printf("\tSlaves: []\n");
5952
5953         }
5954
5955         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5956                         RTE_MAX_ETHPORTS);
5957
5958         if (num_active_slaves < 0) {
5959                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5960                 return;
5961         }
5962         if (num_active_slaves > 0) {
5963                 printf("\tActive Slaves (%d): [", num_active_slaves);
5964                 for (i = 0; i < num_active_slaves - 1; i++)
5965                         printf("%d ", slaves[i]);
5966
5967                 printf("%d]\n", slaves[num_active_slaves - 1]);
5968
5969         } else {
5970                 printf("\tActive Slaves: []\n");
5971
5972         }
5973
5974         primary_id = rte_eth_bond_primary_get(port_id);
5975         if (primary_id < 0) {
5976                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5977                 return;
5978         } else
5979                 printf("\tPrimary: [%d]\n", primary_id);
5980
5981 }
5982
5983 cmdline_parse_token_string_t cmd_showbonding_config_show =
5984 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5985                 show, "show");
5986 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5987 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5988                 bonding, "bonding");
5989 cmdline_parse_token_string_t cmd_showbonding_config_config =
5990 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5991                 config, "config");
5992 cmdline_parse_token_num_t cmd_showbonding_config_port =
5993 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5994                 port_id, UINT16);
5995
5996 cmdline_parse_inst_t cmd_show_bonding_config = {
5997                 .f = cmd_show_bonding_config_parsed,
5998                 .help_str = "show bonding config <port_id>: "
5999                         "Show the bonding config for port_id",
6000                 .data = NULL,
6001                 .tokens = {
6002                                 (void *)&cmd_showbonding_config_show,
6003                                 (void *)&cmd_showbonding_config_bonding,
6004                                 (void *)&cmd_showbonding_config_config,
6005                                 (void *)&cmd_showbonding_config_port,
6006                                 NULL
6007                 }
6008 };
6009
6010 /* *** SET BONDING PRIMARY *** */
6011 struct cmd_set_bonding_primary_result {
6012         cmdline_fixed_string_t set;
6013         cmdline_fixed_string_t bonding;
6014         cmdline_fixed_string_t primary;
6015         portid_t slave_id;
6016         portid_t port_id;
6017 };
6018
6019 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6020                 __rte_unused  struct cmdline *cl,
6021                 __rte_unused void *data)
6022 {
6023         struct cmd_set_bonding_primary_result *res = parsed_result;
6024         portid_t master_port_id = res->port_id;
6025         portid_t slave_port_id = res->slave_id;
6026
6027         /* Set the primary slave for a bonded device. */
6028         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6029                 printf("\t Failed to set primary slave for port = %d.\n",
6030                                 master_port_id);
6031                 return;
6032         }
6033         init_port_config();
6034 }
6035
6036 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6037 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6038                 set, "set");
6039 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6040 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6041                 bonding, "bonding");
6042 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6043 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6044                 primary, "primary");
6045 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6046 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6047                 slave_id, UINT16);
6048 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6049 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6050                 port_id, UINT16);
6051
6052 cmdline_parse_inst_t cmd_set_bonding_primary = {
6053                 .f = cmd_set_bonding_primary_parsed,
6054                 .help_str = "set bonding primary <slave_id> <port_id>: "
6055                         "Set the primary slave for port_id",
6056                 .data = NULL,
6057                 .tokens = {
6058                                 (void *)&cmd_setbonding_primary_set,
6059                                 (void *)&cmd_setbonding_primary_bonding,
6060                                 (void *)&cmd_setbonding_primary_primary,
6061                                 (void *)&cmd_setbonding_primary_slave,
6062                                 (void *)&cmd_setbonding_primary_port,
6063                                 NULL
6064                 }
6065 };
6066
6067 /* *** ADD SLAVE *** */
6068 struct cmd_add_bonding_slave_result {
6069         cmdline_fixed_string_t add;
6070         cmdline_fixed_string_t bonding;
6071         cmdline_fixed_string_t slave;
6072         portid_t slave_id;
6073         portid_t port_id;
6074 };
6075
6076 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6077                 __rte_unused  struct cmdline *cl,
6078                 __rte_unused void *data)
6079 {
6080         struct cmd_add_bonding_slave_result *res = parsed_result;
6081         portid_t master_port_id = res->port_id;
6082         portid_t slave_port_id = res->slave_id;
6083
6084         /* add the slave for a bonded device. */
6085         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6086                 printf("\t Failed to add slave %d to master port = %d.\n",
6087                                 slave_port_id, master_port_id);
6088                 return;
6089         }
6090         init_port_config();
6091         set_port_slave_flag(slave_port_id);
6092 }
6093
6094 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6095 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6096                 add, "add");
6097 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6098 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6099                 bonding, "bonding");
6100 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6101 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6102                 slave, "slave");
6103 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6104 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6105                 slave_id, UINT16);
6106 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6107 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6108                 port_id, UINT16);
6109
6110 cmdline_parse_inst_t cmd_add_bonding_slave = {
6111                 .f = cmd_add_bonding_slave_parsed,
6112                 .help_str = "add bonding slave <slave_id> <port_id>: "
6113                         "Add a slave device to a bonded device",
6114                 .data = NULL,
6115                 .tokens = {
6116                                 (void *)&cmd_addbonding_slave_add,
6117                                 (void *)&cmd_addbonding_slave_bonding,
6118                                 (void *)&cmd_addbonding_slave_slave,
6119                                 (void *)&cmd_addbonding_slave_slaveid,
6120                                 (void *)&cmd_addbonding_slave_port,
6121                                 NULL
6122                 }
6123 };
6124
6125 /* *** REMOVE SLAVE *** */
6126 struct cmd_remove_bonding_slave_result {
6127         cmdline_fixed_string_t remove;
6128         cmdline_fixed_string_t bonding;
6129         cmdline_fixed_string_t slave;
6130         portid_t slave_id;
6131         portid_t port_id;
6132 };
6133
6134 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6135                 __rte_unused  struct cmdline *cl,
6136                 __rte_unused void *data)
6137 {
6138         struct cmd_remove_bonding_slave_result *res = parsed_result;
6139         portid_t master_port_id = res->port_id;
6140         portid_t slave_port_id = res->slave_id;
6141
6142         /* remove the slave from a bonded device. */
6143         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6144                 printf("\t Failed to remove slave %d from master port = %d.\n",
6145                                 slave_port_id, master_port_id);
6146                 return;
6147         }
6148         init_port_config();
6149         clear_port_slave_flag(slave_port_id);
6150 }
6151
6152 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6153                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6154                                 remove, "remove");
6155 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6156                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6157                                 bonding, "bonding");
6158 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6159                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6160                                 slave, "slave");
6161 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6162                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6163                                 slave_id, UINT16);
6164 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6165                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6166                                 port_id, UINT16);
6167
6168 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6169                 .f = cmd_remove_bonding_slave_parsed,
6170                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6171                         "Remove a slave device from a bonded device",
6172                 .data = NULL,
6173                 .tokens = {
6174                                 (void *)&cmd_removebonding_slave_remove,
6175                                 (void *)&cmd_removebonding_slave_bonding,
6176                                 (void *)&cmd_removebonding_slave_slave,
6177                                 (void *)&cmd_removebonding_slave_slaveid,
6178                                 (void *)&cmd_removebonding_slave_port,
6179                                 NULL
6180                 }
6181 };
6182
6183 /* *** CREATE BONDED DEVICE *** */
6184 struct cmd_create_bonded_device_result {
6185         cmdline_fixed_string_t create;
6186         cmdline_fixed_string_t bonded;
6187         cmdline_fixed_string_t device;
6188         uint8_t mode;
6189         uint8_t socket;
6190 };
6191
6192 static int bond_dev_num = 0;
6193
6194 static void cmd_create_bonded_device_parsed(void *parsed_result,
6195                 __rte_unused  struct cmdline *cl,
6196                 __rte_unused void *data)
6197 {
6198         struct cmd_create_bonded_device_result *res = parsed_result;
6199         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6200         int port_id;
6201         int ret;
6202
6203         if (test_done == 0) {
6204                 printf("Please stop forwarding first\n");
6205                 return;
6206         }
6207
6208         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6209                         bond_dev_num++);
6210
6211         /* Create a new bonded device. */
6212         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6213         if (port_id < 0) {
6214                 printf("\t Failed to create bonded device.\n");
6215                 return;
6216         } else {
6217                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6218                                 port_id);
6219
6220                 /* Update number of ports */
6221                 nb_ports = rte_eth_dev_count_avail();
6222                 reconfig(port_id, res->socket);
6223                 ret = rte_eth_promiscuous_enable(port_id);
6224                 if (ret != 0)
6225                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6226                                 port_id, rte_strerror(-ret));
6227
6228                 ports[port_id].need_setup = 0;
6229                 ports[port_id].port_status = RTE_PORT_STOPPED;
6230         }
6231
6232 }
6233
6234 cmdline_parse_token_string_t cmd_createbonded_device_create =
6235                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6236                                 create, "create");
6237 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6238                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6239                                 bonded, "bonded");
6240 cmdline_parse_token_string_t cmd_createbonded_device_device =
6241                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6242                                 device, "device");
6243 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6244                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6245                                 mode, UINT8);
6246 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6247                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6248                                 socket, UINT8);
6249
6250 cmdline_parse_inst_t cmd_create_bonded_device = {
6251                 .f = cmd_create_bonded_device_parsed,
6252                 .help_str = "create bonded device <mode> <socket>: "
6253                         "Create a new bonded device with specific bonding mode and socket",
6254                 .data = NULL,
6255                 .tokens = {
6256                                 (void *)&cmd_createbonded_device_create,
6257                                 (void *)&cmd_createbonded_device_bonded,
6258                                 (void *)&cmd_createbonded_device_device,
6259                                 (void *)&cmd_createbonded_device_mode,
6260                                 (void *)&cmd_createbonded_device_socket,
6261                                 NULL
6262                 }
6263 };
6264
6265 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6266 struct cmd_set_bond_mac_addr_result {
6267         cmdline_fixed_string_t set;
6268         cmdline_fixed_string_t bonding;
6269         cmdline_fixed_string_t mac_addr;
6270         uint16_t port_num;
6271         struct rte_ether_addr address;
6272 };
6273
6274 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6275                 __rte_unused  struct cmdline *cl,
6276                 __rte_unused void *data)
6277 {
6278         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6279         int ret;
6280
6281         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6282                 return;
6283
6284         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6285
6286         /* check the return value and print it if is < 0 */
6287         if (ret < 0)
6288                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6289 }
6290
6291 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6292                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6293 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6294                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6295                                 "bonding");
6296 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6297                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6298                                 "mac_addr");
6299 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6300                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6301                                 port_num, UINT16);
6302 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6303                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6304
6305 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6306                 .f = cmd_set_bond_mac_addr_parsed,
6307                 .data = (void *) 0,
6308                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6309                 .tokens = {
6310                                 (void *)&cmd_set_bond_mac_addr_set,
6311                                 (void *)&cmd_set_bond_mac_addr_bonding,
6312                                 (void *)&cmd_set_bond_mac_addr_mac,
6313                                 (void *)&cmd_set_bond_mac_addr_portnum,
6314                                 (void *)&cmd_set_bond_mac_addr_addr,
6315                                 NULL
6316                 }
6317 };
6318
6319
6320 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6321 struct cmd_set_bond_mon_period_result {
6322         cmdline_fixed_string_t set;
6323         cmdline_fixed_string_t bonding;
6324         cmdline_fixed_string_t mon_period;
6325         uint16_t port_num;
6326         uint32_t period_ms;
6327 };
6328
6329 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6330                 __rte_unused  struct cmdline *cl,
6331                 __rte_unused void *data)
6332 {
6333         struct cmd_set_bond_mon_period_result *res = parsed_result;
6334         int ret;
6335
6336         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6337
6338         /* check the return value and print it if is < 0 */
6339         if (ret < 0)
6340                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6341 }
6342
6343 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6344                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6345                                 set, "set");
6346 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6347                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6348                                 bonding, "bonding");
6349 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6350                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6351                                 mon_period,     "mon_period");
6352 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6353                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6354                                 port_num, UINT16);
6355 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6356                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6357                                 period_ms, UINT32);
6358
6359 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6360                 .f = cmd_set_bond_mon_period_parsed,
6361                 .data = (void *) 0,
6362                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6363                 .tokens = {
6364                                 (void *)&cmd_set_bond_mon_period_set,
6365                                 (void *)&cmd_set_bond_mon_period_bonding,
6366                                 (void *)&cmd_set_bond_mon_period_mon_period,
6367                                 (void *)&cmd_set_bond_mon_period_portnum,
6368                                 (void *)&cmd_set_bond_mon_period_period_ms,
6369                                 NULL
6370                 }
6371 };
6372
6373
6374
6375 struct cmd_set_bonding_agg_mode_policy_result {
6376         cmdline_fixed_string_t set;
6377         cmdline_fixed_string_t bonding;
6378         cmdline_fixed_string_t agg_mode;
6379         uint16_t port_num;
6380         cmdline_fixed_string_t policy;
6381 };
6382
6383
6384 static void
6385 cmd_set_bonding_agg_mode(void *parsed_result,
6386                 __rte_unused struct cmdline *cl,
6387                 __rte_unused void *data)
6388 {
6389         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6390         uint8_t policy = AGG_BANDWIDTH;
6391
6392         if (!strcmp(res->policy, "bandwidth"))
6393                 policy = AGG_BANDWIDTH;
6394         else if (!strcmp(res->policy, "stable"))
6395                 policy = AGG_STABLE;
6396         else if (!strcmp(res->policy, "count"))
6397                 policy = AGG_COUNT;
6398
6399         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6400 }
6401
6402
6403 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6404         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6405                                 set, "set");
6406 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6407         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6408                                 bonding, "bonding");
6409
6410 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6411         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6412                                 agg_mode, "agg_mode");
6413
6414 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6415         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6416                                 port_num, UINT16);
6417
6418 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6419         TOKEN_STRING_INITIALIZER(
6420                         struct cmd_set_bonding_balance_xmit_policy_result,
6421                 policy, "stable#bandwidth#count");
6422
6423 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6424         .f = cmd_set_bonding_agg_mode,
6425         .data = (void *) 0,
6426         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6427         .tokens = {
6428                         (void *)&cmd_set_bonding_agg_mode_set,
6429                         (void *)&cmd_set_bonding_agg_mode_bonding,
6430                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6431                         (void *)&cmd_set_bonding_agg_mode_portnum,
6432                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6433                         NULL
6434                 }
6435 };
6436
6437
6438 #endif /* RTE_LIBRTE_PMD_BOND */
6439
6440 /* *** SET FORWARDING MODE *** */
6441 struct cmd_set_fwd_mode_result {
6442         cmdline_fixed_string_t set;
6443         cmdline_fixed_string_t fwd;
6444         cmdline_fixed_string_t mode;
6445 };
6446
6447 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6448                                     __rte_unused struct cmdline *cl,
6449                                     __rte_unused void *data)
6450 {
6451         struct cmd_set_fwd_mode_result *res = parsed_result;
6452
6453         retry_enabled = 0;
6454         set_pkt_forwarding_mode(res->mode);
6455 }
6456
6457 cmdline_parse_token_string_t cmd_setfwd_set =
6458         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6459 cmdline_parse_token_string_t cmd_setfwd_fwd =
6460         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6461 cmdline_parse_token_string_t cmd_setfwd_mode =
6462         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6463                 "" /* defined at init */);
6464
6465 cmdline_parse_inst_t cmd_set_fwd_mode = {
6466         .f = cmd_set_fwd_mode_parsed,
6467         .data = NULL,
6468         .help_str = NULL, /* defined at init */
6469         .tokens = {
6470                 (void *)&cmd_setfwd_set,
6471                 (void *)&cmd_setfwd_fwd,
6472                 (void *)&cmd_setfwd_mode,
6473                 NULL,
6474         },
6475 };
6476
6477 static void cmd_set_fwd_mode_init(void)
6478 {
6479         char *modes, *c;
6480         static char token[128];
6481         static char help[256];
6482         cmdline_parse_token_string_t *token_struct;
6483
6484         modes = list_pkt_forwarding_modes();
6485         snprintf(help, sizeof(help), "set fwd %s: "
6486                 "Set packet forwarding mode", modes);
6487         cmd_set_fwd_mode.help_str = help;
6488
6489         /* string token separator is # */
6490         for (c = token; *modes != '\0'; modes++)
6491                 if (*modes == '|')
6492                         *c++ = '#';
6493                 else
6494                         *c++ = *modes;
6495         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6496         token_struct->string_data.str = token;
6497 }
6498
6499 /* *** SET RETRY FORWARDING MODE *** */
6500 struct cmd_set_fwd_retry_mode_result {
6501         cmdline_fixed_string_t set;
6502         cmdline_fixed_string_t fwd;
6503         cmdline_fixed_string_t mode;
6504         cmdline_fixed_string_t retry;
6505 };
6506
6507 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6508                             __rte_unused struct cmdline *cl,
6509                             __rte_unused void *data)
6510 {
6511         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6512
6513         retry_enabled = 1;
6514         set_pkt_forwarding_mode(res->mode);
6515 }
6516
6517 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6518         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6519                         set, "set");
6520 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6521         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6522                         fwd, "fwd");
6523 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6524         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6525                         mode,
6526                 "" /* defined at init */);
6527 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6528         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6529                         retry, "retry");
6530
6531 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6532         .f = cmd_set_fwd_retry_mode_parsed,
6533         .data = NULL,
6534         .help_str = NULL, /* defined at init */
6535         .tokens = {
6536                 (void *)&cmd_setfwd_retry_set,
6537                 (void *)&cmd_setfwd_retry_fwd,
6538                 (void *)&cmd_setfwd_retry_mode,
6539                 (void *)&cmd_setfwd_retry_retry,
6540                 NULL,
6541         },
6542 };
6543
6544 static void cmd_set_fwd_retry_mode_init(void)
6545 {
6546         char *modes, *c;
6547         static char token[128];
6548         static char help[256];
6549         cmdline_parse_token_string_t *token_struct;
6550
6551         modes = list_pkt_forwarding_retry_modes();
6552         snprintf(help, sizeof(help), "set fwd %s retry: "
6553                 "Set packet forwarding mode with retry", modes);
6554         cmd_set_fwd_retry_mode.help_str = help;
6555
6556         /* string token separator is # */
6557         for (c = token; *modes != '\0'; modes++)
6558                 if (*modes == '|')
6559                         *c++ = '#';
6560                 else
6561                         *c++ = *modes;
6562         token_struct = (cmdline_parse_token_string_t *)
6563                 cmd_set_fwd_retry_mode.tokens[2];
6564         token_struct->string_data.str = token;
6565 }
6566
6567 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6568 struct cmd_set_burst_tx_retry_result {
6569         cmdline_fixed_string_t set;
6570         cmdline_fixed_string_t burst;
6571         cmdline_fixed_string_t tx;
6572         cmdline_fixed_string_t delay;
6573         uint32_t time;
6574         cmdline_fixed_string_t retry;
6575         uint32_t retry_num;
6576 };
6577
6578 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6579                                         __rte_unused struct cmdline *cl,
6580                                         __rte_unused void *data)
6581 {
6582         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6583
6584         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6585                 && !strcmp(res->tx, "tx")) {
6586                 if (!strcmp(res->delay, "delay"))
6587                         burst_tx_delay_time = res->time;
6588                 if (!strcmp(res->retry, "retry"))
6589                         burst_tx_retry_num = res->retry_num;
6590         }
6591
6592 }
6593
6594 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6595         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6596 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6597         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6598                                  "burst");
6599 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6600         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6601 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6602         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6603 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6604         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6605 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6606         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6607 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6608         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6609
6610 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6611         .f = cmd_set_burst_tx_retry_parsed,
6612         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6613         .tokens = {
6614                 (void *)&cmd_set_burst_tx_retry_set,
6615                 (void *)&cmd_set_burst_tx_retry_burst,
6616                 (void *)&cmd_set_burst_tx_retry_tx,
6617                 (void *)&cmd_set_burst_tx_retry_delay,
6618                 (void *)&cmd_set_burst_tx_retry_time,
6619                 (void *)&cmd_set_burst_tx_retry_retry,
6620                 (void *)&cmd_set_burst_tx_retry_retry_num,
6621                 NULL,
6622         },
6623 };
6624
6625 /* *** SET PROMISC MODE *** */
6626 struct cmd_set_promisc_mode_result {
6627         cmdline_fixed_string_t set;
6628         cmdline_fixed_string_t promisc;
6629         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6630         uint16_t port_num;               /* valid if "allports" argument == 0 */
6631         cmdline_fixed_string_t mode;
6632 };
6633
6634 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6635                                         __rte_unused struct cmdline *cl,
6636                                         void *allports)
6637 {
6638         struct cmd_set_promisc_mode_result *res = parsed_result;
6639         int enable;
6640         portid_t i;
6641
6642         if (!strcmp(res->mode, "on"))
6643                 enable = 1;
6644         else
6645                 enable = 0;
6646
6647         /* all ports */
6648         if (allports) {
6649                 RTE_ETH_FOREACH_DEV(i)
6650                         eth_set_promisc_mode(i, enable);
6651         } else {
6652                 eth_set_promisc_mode(res->port_num, enable);
6653         }
6654 }
6655
6656 cmdline_parse_token_string_t cmd_setpromisc_set =
6657         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6658 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6659         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6660                                  "promisc");
6661 cmdline_parse_token_string_t cmd_setpromisc_portall =
6662         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6663                                  "all");
6664 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6665         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6666                               UINT16);
6667 cmdline_parse_token_string_t cmd_setpromisc_mode =
6668         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6669                                  "on#off");
6670
6671 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6672         .f = cmd_set_promisc_mode_parsed,
6673         .data = (void *)1,
6674         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6675         .tokens = {
6676                 (void *)&cmd_setpromisc_set,
6677                 (void *)&cmd_setpromisc_promisc,
6678                 (void *)&cmd_setpromisc_portall,
6679                 (void *)&cmd_setpromisc_mode,
6680                 NULL,
6681         },
6682 };
6683
6684 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6685         .f = cmd_set_promisc_mode_parsed,
6686         .data = (void *)0,
6687         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6688         .tokens = {
6689                 (void *)&cmd_setpromisc_set,
6690                 (void *)&cmd_setpromisc_promisc,
6691                 (void *)&cmd_setpromisc_portnum,
6692                 (void *)&cmd_setpromisc_mode,
6693                 NULL,
6694         },
6695 };
6696
6697 /* *** SET ALLMULTI MODE *** */
6698 struct cmd_set_allmulti_mode_result {
6699         cmdline_fixed_string_t set;
6700         cmdline_fixed_string_t allmulti;
6701         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6702         uint16_t port_num;               /* valid if "allports" argument == 0 */
6703         cmdline_fixed_string_t mode;
6704 };
6705
6706 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6707                                         __rte_unused struct cmdline *cl,
6708                                         void *allports)
6709 {
6710         struct cmd_set_allmulti_mode_result *res = parsed_result;
6711         int enable;
6712         portid_t i;
6713
6714         if (!strcmp(res->mode, "on"))
6715                 enable = 1;
6716         else
6717                 enable = 0;
6718
6719         /* all ports */
6720         if (allports) {
6721                 RTE_ETH_FOREACH_DEV(i) {
6722                         eth_set_allmulticast_mode(i, enable);
6723                 }
6724         }
6725         else {
6726                 eth_set_allmulticast_mode(res->port_num, enable);
6727         }
6728 }
6729
6730 cmdline_parse_token_string_t cmd_setallmulti_set =
6731         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6732 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6733         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6734                                  "allmulti");
6735 cmdline_parse_token_string_t cmd_setallmulti_portall =
6736         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6737                                  "all");
6738 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6739         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6740                               UINT16);
6741 cmdline_parse_token_string_t cmd_setallmulti_mode =
6742         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6743                                  "on#off");
6744
6745 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6746         .f = cmd_set_allmulti_mode_parsed,
6747         .data = (void *)1,
6748         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6749         .tokens = {
6750                 (void *)&cmd_setallmulti_set,
6751                 (void *)&cmd_setallmulti_allmulti,
6752                 (void *)&cmd_setallmulti_portall,
6753                 (void *)&cmd_setallmulti_mode,
6754                 NULL,
6755         },
6756 };
6757
6758 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6759         .f = cmd_set_allmulti_mode_parsed,
6760         .data = (void *)0,
6761         .help_str = "set allmulti <port_id> on|off: "
6762                 "Set allmulti mode on port_id",
6763         .tokens = {
6764                 (void *)&cmd_setallmulti_set,
6765                 (void *)&cmd_setallmulti_allmulti,
6766                 (void *)&cmd_setallmulti_portnum,
6767                 (void *)&cmd_setallmulti_mode,
6768                 NULL,
6769         },
6770 };
6771
6772 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6773 struct cmd_link_flow_ctrl_set_result {
6774         cmdline_fixed_string_t set;
6775         cmdline_fixed_string_t flow_ctrl;
6776         cmdline_fixed_string_t rx;
6777         cmdline_fixed_string_t rx_lfc_mode;
6778         cmdline_fixed_string_t tx;
6779         cmdline_fixed_string_t tx_lfc_mode;
6780         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6781         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6782         cmdline_fixed_string_t autoneg_str;
6783         cmdline_fixed_string_t autoneg;
6784         cmdline_fixed_string_t hw_str;
6785         uint32_t high_water;
6786         cmdline_fixed_string_t lw_str;
6787         uint32_t low_water;
6788         cmdline_fixed_string_t pt_str;
6789         uint16_t pause_time;
6790         cmdline_fixed_string_t xon_str;
6791         uint16_t send_xon;
6792         portid_t port_id;
6793 };
6794
6795 cmdline_parse_token_string_t cmd_lfc_set_set =
6796         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6797                                 set, "set");
6798 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6799         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6800                                 flow_ctrl, "flow_ctrl");
6801 cmdline_parse_token_string_t cmd_lfc_set_rx =
6802         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6803                                 rx, "rx");
6804 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6805         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6806                                 rx_lfc_mode, "on#off");
6807 cmdline_parse_token_string_t cmd_lfc_set_tx =
6808         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6809                                 tx, "tx");
6810 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6811         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6812                                 tx_lfc_mode, "on#off");
6813 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6814         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6815                                 hw_str, "high_water");
6816 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6817         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6818                                 high_water, UINT32);
6819 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6820         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6821                                 lw_str, "low_water");
6822 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6823         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6824                                 low_water, UINT32);
6825 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6826         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6827                                 pt_str, "pause_time");
6828 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6829         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6830                                 pause_time, UINT16);
6831 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6832         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6833                                 xon_str, "send_xon");
6834 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6835         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6836                                 send_xon, UINT16);
6837 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6838         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6839                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6840 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6841         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6842                                 mac_ctrl_frame_fwd_mode, "on#off");
6843 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6844         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6845                                 autoneg_str, "autoneg");
6846 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6847         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6848                                 autoneg, "on#off");
6849 cmdline_parse_token_num_t cmd_lfc_set_portid =
6850         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6851                                 port_id, UINT16);
6852
6853 /* forward declaration */
6854 static void
6855 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6856                               void *data);
6857
6858 cmdline_parse_inst_t cmd_link_flow_control_set = {
6859         .f = cmd_link_flow_ctrl_set_parsed,
6860         .data = NULL,
6861         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6862                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6863                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6864         .tokens = {
6865                 (void *)&cmd_lfc_set_set,
6866                 (void *)&cmd_lfc_set_flow_ctrl,
6867                 (void *)&cmd_lfc_set_rx,
6868                 (void *)&cmd_lfc_set_rx_mode,
6869                 (void *)&cmd_lfc_set_tx,
6870                 (void *)&cmd_lfc_set_tx_mode,
6871                 (void *)&cmd_lfc_set_high_water,
6872                 (void *)&cmd_lfc_set_low_water,
6873                 (void *)&cmd_lfc_set_pause_time,
6874                 (void *)&cmd_lfc_set_send_xon,
6875                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6876                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6877                 (void *)&cmd_lfc_set_autoneg_str,
6878                 (void *)&cmd_lfc_set_autoneg,
6879                 (void *)&cmd_lfc_set_portid,
6880                 NULL,
6881         },
6882 };
6883
6884 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6885         .f = cmd_link_flow_ctrl_set_parsed,
6886         .data = (void *)&cmd_link_flow_control_set_rx,
6887         .help_str = "set flow_ctrl rx on|off <port_id>: "
6888                 "Change rx flow control parameter",
6889         .tokens = {
6890                 (void *)&cmd_lfc_set_set,
6891                 (void *)&cmd_lfc_set_flow_ctrl,
6892                 (void *)&cmd_lfc_set_rx,
6893                 (void *)&cmd_lfc_set_rx_mode,
6894                 (void *)&cmd_lfc_set_portid,
6895                 NULL,
6896         },
6897 };
6898
6899 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6900         .f = cmd_link_flow_ctrl_set_parsed,
6901         .data = (void *)&cmd_link_flow_control_set_tx,
6902         .help_str = "set flow_ctrl tx on|off <port_id>: "
6903                 "Change tx flow control parameter",
6904         .tokens = {
6905                 (void *)&cmd_lfc_set_set,
6906                 (void *)&cmd_lfc_set_flow_ctrl,
6907                 (void *)&cmd_lfc_set_tx,
6908                 (void *)&cmd_lfc_set_tx_mode,
6909                 (void *)&cmd_lfc_set_portid,
6910                 NULL,
6911         },
6912 };
6913
6914 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6915         .f = cmd_link_flow_ctrl_set_parsed,
6916         .data = (void *)&cmd_link_flow_control_set_hw,
6917         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6918                 "Change high water flow control parameter",
6919         .tokens = {
6920                 (void *)&cmd_lfc_set_set,
6921                 (void *)&cmd_lfc_set_flow_ctrl,
6922                 (void *)&cmd_lfc_set_high_water_str,
6923                 (void *)&cmd_lfc_set_high_water,
6924                 (void *)&cmd_lfc_set_portid,
6925                 NULL,
6926         },
6927 };
6928
6929 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6930         .f = cmd_link_flow_ctrl_set_parsed,
6931         .data = (void *)&cmd_link_flow_control_set_lw,
6932         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6933                 "Change low water flow control parameter",
6934         .tokens = {
6935                 (void *)&cmd_lfc_set_set,
6936                 (void *)&cmd_lfc_set_flow_ctrl,
6937                 (void *)&cmd_lfc_set_low_water_str,
6938                 (void *)&cmd_lfc_set_low_water,
6939                 (void *)&cmd_lfc_set_portid,
6940                 NULL,
6941         },
6942 };
6943
6944 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6945         .f = cmd_link_flow_ctrl_set_parsed,
6946         .data = (void *)&cmd_link_flow_control_set_pt,
6947         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6948                 "Change pause time flow control parameter",
6949         .tokens = {
6950                 (void *)&cmd_lfc_set_set,
6951                 (void *)&cmd_lfc_set_flow_ctrl,
6952                 (void *)&cmd_lfc_set_pause_time_str,
6953                 (void *)&cmd_lfc_set_pause_time,
6954                 (void *)&cmd_lfc_set_portid,
6955                 NULL,
6956         },
6957 };
6958
6959 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6960         .f = cmd_link_flow_ctrl_set_parsed,
6961         .data = (void *)&cmd_link_flow_control_set_xon,
6962         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6963                 "Change send_xon flow control parameter",
6964         .tokens = {
6965                 (void *)&cmd_lfc_set_set,
6966                 (void *)&cmd_lfc_set_flow_ctrl,
6967                 (void *)&cmd_lfc_set_send_xon_str,
6968                 (void *)&cmd_lfc_set_send_xon,
6969                 (void *)&cmd_lfc_set_portid,
6970                 NULL,
6971         },
6972 };
6973
6974 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6975         .f = cmd_link_flow_ctrl_set_parsed,
6976         .data = (void *)&cmd_link_flow_control_set_macfwd,
6977         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6978                 "Change mac ctrl fwd flow control parameter",
6979         .tokens = {
6980                 (void *)&cmd_lfc_set_set,
6981                 (void *)&cmd_lfc_set_flow_ctrl,
6982                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6983                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6984                 (void *)&cmd_lfc_set_portid,
6985                 NULL,
6986         },
6987 };
6988
6989 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6990         .f = cmd_link_flow_ctrl_set_parsed,
6991         .data = (void *)&cmd_link_flow_control_set_autoneg,
6992         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6993                 "Change autoneg flow control parameter",
6994         .tokens = {
6995                 (void *)&cmd_lfc_set_set,
6996                 (void *)&cmd_lfc_set_flow_ctrl,
6997                 (void *)&cmd_lfc_set_autoneg_str,
6998                 (void *)&cmd_lfc_set_autoneg,
6999                 (void *)&cmd_lfc_set_portid,
7000                 NULL,
7001         },
7002 };
7003
7004 static void
7005 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7006                               __rte_unused struct cmdline *cl,
7007                               void *data)
7008 {
7009         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7010         cmdline_parse_inst_t *cmd = data;
7011         struct rte_eth_fc_conf fc_conf;
7012         int rx_fc_en = 0;
7013         int tx_fc_en = 0;
7014         int ret;
7015
7016         /*
7017          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7018          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7019          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7020          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7021          */
7022         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7023                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7024         };
7025
7026         /* Partial command line, retrieve current configuration */
7027         if (cmd) {
7028                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7029                 if (ret != 0) {
7030                         printf("cannot get current flow ctrl parameters, return"
7031                                "code = %d\n", ret);
7032                         return;
7033                 }
7034
7035                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7036                     (fc_conf.mode == RTE_FC_FULL))
7037                         rx_fc_en = 1;
7038                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7039                     (fc_conf.mode == RTE_FC_FULL))
7040                         tx_fc_en = 1;
7041         }
7042
7043         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7044                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7045
7046         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7047                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7048
7049         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7050
7051         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7052                 fc_conf.high_water = res->high_water;
7053
7054         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7055                 fc_conf.low_water = res->low_water;
7056
7057         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7058                 fc_conf.pause_time = res->pause_time;
7059
7060         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7061                 fc_conf.send_xon = res->send_xon;
7062
7063         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7064                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7065                         fc_conf.mac_ctrl_frame_fwd = 1;
7066                 else
7067                         fc_conf.mac_ctrl_frame_fwd = 0;
7068         }
7069
7070         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7071                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7072
7073         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7074         if (ret != 0)
7075                 printf("bad flow contrl parameter, return code = %d \n", ret);
7076 }
7077
7078 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7079 struct cmd_priority_flow_ctrl_set_result {
7080         cmdline_fixed_string_t set;
7081         cmdline_fixed_string_t pfc_ctrl;
7082         cmdline_fixed_string_t rx;
7083         cmdline_fixed_string_t rx_pfc_mode;
7084         cmdline_fixed_string_t tx;
7085         cmdline_fixed_string_t tx_pfc_mode;
7086         uint32_t high_water;
7087         uint32_t low_water;
7088         uint16_t pause_time;
7089         uint8_t  priority;
7090         portid_t port_id;
7091 };
7092
7093 static void
7094 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7095                        __rte_unused struct cmdline *cl,
7096                        __rte_unused void *data)
7097 {
7098         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7099         struct rte_eth_pfc_conf pfc_conf;
7100         int rx_fc_enable, tx_fc_enable;
7101         int ret;
7102
7103         /*
7104          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7105          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7106          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7107          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7108          */
7109         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7110                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7111         };
7112
7113         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7114         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7115         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7116         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7117         pfc_conf.fc.high_water = res->high_water;
7118         pfc_conf.fc.low_water  = res->low_water;
7119         pfc_conf.fc.pause_time = res->pause_time;
7120         pfc_conf.priority      = res->priority;
7121
7122         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7123         if (ret != 0)
7124                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7125 }
7126
7127 cmdline_parse_token_string_t cmd_pfc_set_set =
7128         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7129                                 set, "set");
7130 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7131         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7132                                 pfc_ctrl, "pfc_ctrl");
7133 cmdline_parse_token_string_t cmd_pfc_set_rx =
7134         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7135                                 rx, "rx");
7136 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7137         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7138                                 rx_pfc_mode, "on#off");
7139 cmdline_parse_token_string_t cmd_pfc_set_tx =
7140         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7141                                 tx, "tx");
7142 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7143         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7144                                 tx_pfc_mode, "on#off");
7145 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7146         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7147                                 high_water, UINT32);
7148 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7149         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7150                                 low_water, UINT32);
7151 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7152         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7153                                 pause_time, UINT16);
7154 cmdline_parse_token_num_t cmd_pfc_set_priority =
7155         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7156                                 priority, UINT8);
7157 cmdline_parse_token_num_t cmd_pfc_set_portid =
7158         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7159                                 port_id, UINT16);
7160
7161 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7162         .f = cmd_priority_flow_ctrl_set_parsed,
7163         .data = NULL,
7164         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7165                 "<pause_time> <priority> <port_id>: "
7166                 "Configure the Ethernet priority flow control",
7167         .tokens = {
7168                 (void *)&cmd_pfc_set_set,
7169                 (void *)&cmd_pfc_set_flow_ctrl,
7170                 (void *)&cmd_pfc_set_rx,
7171                 (void *)&cmd_pfc_set_rx_mode,
7172                 (void *)&cmd_pfc_set_tx,
7173                 (void *)&cmd_pfc_set_tx_mode,
7174                 (void *)&cmd_pfc_set_high_water,
7175                 (void *)&cmd_pfc_set_low_water,
7176                 (void *)&cmd_pfc_set_pause_time,
7177                 (void *)&cmd_pfc_set_priority,
7178                 (void *)&cmd_pfc_set_portid,
7179                 NULL,
7180         },
7181 };
7182
7183 /* *** RESET CONFIGURATION *** */
7184 struct cmd_reset_result {
7185         cmdline_fixed_string_t reset;
7186         cmdline_fixed_string_t def;
7187 };
7188
7189 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7190                              struct cmdline *cl,
7191                              __rte_unused void *data)
7192 {
7193         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7194         set_def_fwd_config();
7195 }
7196
7197 cmdline_parse_token_string_t cmd_reset_set =
7198         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7199 cmdline_parse_token_string_t cmd_reset_def =
7200         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7201                                  "default");
7202
7203 cmdline_parse_inst_t cmd_reset = {
7204         .f = cmd_reset_parsed,
7205         .data = NULL,
7206         .help_str = "set default: Reset default forwarding configuration",
7207         .tokens = {
7208                 (void *)&cmd_reset_set,
7209                 (void *)&cmd_reset_def,
7210                 NULL,
7211         },
7212 };
7213
7214 /* *** START FORWARDING *** */
7215 struct cmd_start_result {
7216         cmdline_fixed_string_t start;
7217 };
7218
7219 cmdline_parse_token_string_t cmd_start_start =
7220         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7221
7222 static void cmd_start_parsed(__rte_unused void *parsed_result,
7223                              __rte_unused struct cmdline *cl,
7224                              __rte_unused void *data)
7225 {
7226         start_packet_forwarding(0);
7227 }
7228
7229 cmdline_parse_inst_t cmd_start = {
7230         .f = cmd_start_parsed,
7231         .data = NULL,
7232         .help_str = "start: Start packet forwarding",
7233         .tokens = {
7234                 (void *)&cmd_start_start,
7235                 NULL,
7236         },
7237 };
7238
7239 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7240 struct cmd_start_tx_first_result {
7241         cmdline_fixed_string_t start;
7242         cmdline_fixed_string_t tx_first;
7243 };
7244
7245 static void
7246 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7247                           __rte_unused struct cmdline *cl,
7248                           __rte_unused void *data)
7249 {
7250         start_packet_forwarding(1);
7251 }
7252
7253 cmdline_parse_token_string_t cmd_start_tx_first_start =
7254         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7255                                  "start");
7256 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7257         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7258                                  tx_first, "tx_first");
7259
7260 cmdline_parse_inst_t cmd_start_tx_first = {
7261         .f = cmd_start_tx_first_parsed,
7262         .data = NULL,
7263         .help_str = "start tx_first: Start packet forwarding, "
7264                 "after sending 1 burst of packets",
7265         .tokens = {
7266                 (void *)&cmd_start_tx_first_start,
7267                 (void *)&cmd_start_tx_first_tx_first,
7268                 NULL,
7269         },
7270 };
7271
7272 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7273 struct cmd_start_tx_first_n_result {
7274         cmdline_fixed_string_t start;
7275         cmdline_fixed_string_t tx_first;
7276         uint32_t tx_num;
7277 };
7278
7279 static void
7280 cmd_start_tx_first_n_parsed(void *parsed_result,
7281                           __rte_unused struct cmdline *cl,
7282                           __rte_unused void *data)
7283 {
7284         struct cmd_start_tx_first_n_result *res = parsed_result;
7285
7286         start_packet_forwarding(res->tx_num);
7287 }
7288
7289 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7290         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7291                         start, "start");
7292 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7293         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7294                         tx_first, "tx_first");
7295 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7296         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7297                         tx_num, UINT32);
7298
7299 cmdline_parse_inst_t cmd_start_tx_first_n = {
7300         .f = cmd_start_tx_first_n_parsed,
7301         .data = NULL,
7302         .help_str = "start tx_first <num>: "
7303                 "packet forwarding, after sending <num> bursts of packets",
7304         .tokens = {
7305                 (void *)&cmd_start_tx_first_n_start,
7306                 (void *)&cmd_start_tx_first_n_tx_first,
7307                 (void *)&cmd_start_tx_first_n_tx_num,
7308                 NULL,
7309         },
7310 };
7311
7312 /* *** SET LINK UP *** */
7313 struct cmd_set_link_up_result {
7314         cmdline_fixed_string_t set;
7315         cmdline_fixed_string_t link_up;
7316         cmdline_fixed_string_t port;
7317         portid_t port_id;
7318 };
7319
7320 cmdline_parse_token_string_t cmd_set_link_up_set =
7321         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7322 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7323         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7324                                 "link-up");
7325 cmdline_parse_token_string_t cmd_set_link_up_port =
7326         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7327 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7328         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7329
7330 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7331                              __rte_unused struct cmdline *cl,
7332                              __rte_unused void *data)
7333 {
7334         struct cmd_set_link_up_result *res = parsed_result;
7335         dev_set_link_up(res->port_id);
7336 }
7337
7338 cmdline_parse_inst_t cmd_set_link_up = {
7339         .f = cmd_set_link_up_parsed,
7340         .data = NULL,
7341         .help_str = "set link-up port <port id>",
7342         .tokens = {
7343                 (void *)&cmd_set_link_up_set,
7344                 (void *)&cmd_set_link_up_link_up,
7345                 (void *)&cmd_set_link_up_port,
7346                 (void *)&cmd_set_link_up_port_id,
7347                 NULL,
7348         },
7349 };
7350
7351 /* *** SET LINK DOWN *** */
7352 struct cmd_set_link_down_result {
7353         cmdline_fixed_string_t set;
7354         cmdline_fixed_string_t link_down;
7355         cmdline_fixed_string_t port;
7356         portid_t port_id;
7357 };
7358
7359 cmdline_parse_token_string_t cmd_set_link_down_set =
7360         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7361 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7362         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7363                                 "link-down");
7364 cmdline_parse_token_string_t cmd_set_link_down_port =
7365         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7366 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7367         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7368
7369 static void cmd_set_link_down_parsed(
7370                                 __rte_unused void *parsed_result,
7371                                 __rte_unused struct cmdline *cl,
7372                                 __rte_unused void *data)
7373 {
7374         struct cmd_set_link_down_result *res = parsed_result;
7375         dev_set_link_down(res->port_id);
7376 }
7377
7378 cmdline_parse_inst_t cmd_set_link_down = {
7379         .f = cmd_set_link_down_parsed,
7380         .data = NULL,
7381         .help_str = "set link-down port <port id>",
7382         .tokens = {
7383                 (void *)&cmd_set_link_down_set,
7384                 (void *)&cmd_set_link_down_link_down,
7385                 (void *)&cmd_set_link_down_port,
7386                 (void *)&cmd_set_link_down_port_id,
7387                 NULL,
7388         },
7389 };
7390
7391 /* *** SHOW CFG *** */
7392 struct cmd_showcfg_result {
7393         cmdline_fixed_string_t show;
7394         cmdline_fixed_string_t cfg;
7395         cmdline_fixed_string_t what;
7396 };
7397
7398 static void cmd_showcfg_parsed(void *parsed_result,
7399                                __rte_unused struct cmdline *cl,
7400                                __rte_unused void *data)
7401 {
7402         struct cmd_showcfg_result *res = parsed_result;
7403         if (!strcmp(res->what, "rxtx"))
7404                 rxtx_config_display();
7405         else if (!strcmp(res->what, "cores"))
7406                 fwd_lcores_config_display();
7407         else if (!strcmp(res->what, "fwd"))
7408                 pkt_fwd_config_display(&cur_fwd_config);
7409         else if (!strcmp(res->what, "txpkts"))
7410                 show_tx_pkt_segments();
7411 }
7412
7413 cmdline_parse_token_string_t cmd_showcfg_show =
7414         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7415 cmdline_parse_token_string_t cmd_showcfg_port =
7416         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7417 cmdline_parse_token_string_t cmd_showcfg_what =
7418         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7419                                  "rxtx#cores#fwd#txpkts");
7420
7421 cmdline_parse_inst_t cmd_showcfg = {
7422         .f = cmd_showcfg_parsed,
7423         .data = NULL,
7424         .help_str = "show config rxtx|cores|fwd|txpkts",
7425         .tokens = {
7426                 (void *)&cmd_showcfg_show,
7427                 (void *)&cmd_showcfg_port,
7428                 (void *)&cmd_showcfg_what,
7429                 NULL,
7430         },
7431 };
7432
7433 /* *** SHOW ALL PORT INFO *** */
7434 struct cmd_showportall_result {
7435         cmdline_fixed_string_t show;
7436         cmdline_fixed_string_t port;
7437         cmdline_fixed_string_t what;
7438         cmdline_fixed_string_t all;
7439 };
7440
7441 static void cmd_showportall_parsed(void *parsed_result,
7442                                 __rte_unused struct cmdline *cl,
7443                                 __rte_unused void *data)
7444 {
7445         portid_t i;
7446
7447         struct cmd_showportall_result *res = parsed_result;
7448         if (!strcmp(res->show, "clear")) {
7449                 if (!strcmp(res->what, "stats"))
7450                         RTE_ETH_FOREACH_DEV(i)
7451                                 nic_stats_clear(i);
7452                 else if (!strcmp(res->what, "xstats"))
7453                         RTE_ETH_FOREACH_DEV(i)
7454                                 nic_xstats_clear(i);
7455         } else if (!strcmp(res->what, "info"))
7456                 RTE_ETH_FOREACH_DEV(i)
7457                         port_infos_display(i);
7458         else if (!strcmp(res->what, "summary")) {
7459                 port_summary_header_display();
7460                 RTE_ETH_FOREACH_DEV(i)
7461                         port_summary_display(i);
7462         }
7463         else if (!strcmp(res->what, "stats"))
7464                 RTE_ETH_FOREACH_DEV(i)
7465                         nic_stats_display(i);
7466         else if (!strcmp(res->what, "xstats"))
7467                 RTE_ETH_FOREACH_DEV(i)
7468                         nic_xstats_display(i);
7469         else if (!strcmp(res->what, "fdir"))
7470                 RTE_ETH_FOREACH_DEV(i)
7471                         fdir_get_infos(i);
7472         else if (!strcmp(res->what, "stat_qmap"))
7473                 RTE_ETH_FOREACH_DEV(i)
7474                         nic_stats_mapping_display(i);
7475         else if (!strcmp(res->what, "dcb_tc"))
7476                 RTE_ETH_FOREACH_DEV(i)
7477                         port_dcb_info_display(i);
7478         else if (!strcmp(res->what, "cap"))
7479                 RTE_ETH_FOREACH_DEV(i)
7480                         port_offload_cap_display(i);
7481 }
7482
7483 cmdline_parse_token_string_t cmd_showportall_show =
7484         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7485                                  "show#clear");
7486 cmdline_parse_token_string_t cmd_showportall_port =
7487         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7488 cmdline_parse_token_string_t cmd_showportall_what =
7489         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7490                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7491 cmdline_parse_token_string_t cmd_showportall_all =
7492         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7493 cmdline_parse_inst_t cmd_showportall = {
7494         .f = cmd_showportall_parsed,
7495         .data = NULL,
7496         .help_str = "show|clear port "
7497                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7498         .tokens = {
7499                 (void *)&cmd_showportall_show,
7500                 (void *)&cmd_showportall_port,
7501                 (void *)&cmd_showportall_what,
7502                 (void *)&cmd_showportall_all,
7503                 NULL,
7504         },
7505 };
7506
7507 /* *** SHOW PORT INFO *** */
7508 struct cmd_showport_result {
7509         cmdline_fixed_string_t show;
7510         cmdline_fixed_string_t port;
7511         cmdline_fixed_string_t what;
7512         uint16_t portnum;
7513 };
7514
7515 static void cmd_showport_parsed(void *parsed_result,
7516                                 __rte_unused struct cmdline *cl,
7517                                 __rte_unused void *data)
7518 {
7519         struct cmd_showport_result *res = parsed_result;
7520         if (!strcmp(res->show, "clear")) {
7521                 if (!strcmp(res->what, "stats"))
7522                         nic_stats_clear(res->portnum);
7523                 else if (!strcmp(res->what, "xstats"))
7524                         nic_xstats_clear(res->portnum);
7525         } else if (!strcmp(res->what, "info"))
7526                 port_infos_display(res->portnum);
7527         else if (!strcmp(res->what, "summary")) {
7528                 port_summary_header_display();
7529                 port_summary_display(res->portnum);
7530         }
7531         else if (!strcmp(res->what, "stats"))
7532                 nic_stats_display(res->portnum);
7533         else if (!strcmp(res->what, "xstats"))
7534                 nic_xstats_display(res->portnum);
7535         else if (!strcmp(res->what, "fdir"))
7536                  fdir_get_infos(res->portnum);
7537         else if (!strcmp(res->what, "stat_qmap"))
7538                 nic_stats_mapping_display(res->portnum);
7539         else if (!strcmp(res->what, "dcb_tc"))
7540                 port_dcb_info_display(res->portnum);
7541         else if (!strcmp(res->what, "cap"))
7542                 port_offload_cap_display(res->portnum);
7543 }
7544
7545 cmdline_parse_token_string_t cmd_showport_show =
7546         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7547                                  "show#clear");
7548 cmdline_parse_token_string_t cmd_showport_port =
7549         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7550 cmdline_parse_token_string_t cmd_showport_what =
7551         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7552                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7553 cmdline_parse_token_num_t cmd_showport_portnum =
7554         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7555
7556 cmdline_parse_inst_t cmd_showport = {
7557         .f = cmd_showport_parsed,
7558         .data = NULL,
7559         .help_str = "show|clear port "
7560                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7561                 "<port_id>",
7562         .tokens = {
7563                 (void *)&cmd_showport_show,
7564                 (void *)&cmd_showport_port,
7565                 (void *)&cmd_showport_what,
7566                 (void *)&cmd_showport_portnum,
7567                 NULL,
7568         },
7569 };
7570
7571 /* *** SHOW DEVICE INFO *** */
7572 struct cmd_showdevice_result {
7573         cmdline_fixed_string_t show;
7574         cmdline_fixed_string_t device;
7575         cmdline_fixed_string_t what;
7576         cmdline_fixed_string_t identifier;
7577 };
7578
7579 static void cmd_showdevice_parsed(void *parsed_result,
7580                                 __rte_unused struct cmdline *cl,
7581                                 __rte_unused void *data)
7582 {
7583         struct cmd_showdevice_result *res = parsed_result;
7584         if (!strcmp(res->what, "info")) {
7585                 if (!strcmp(res->identifier, "all"))
7586                         device_infos_display(NULL);
7587                 else
7588                         device_infos_display(res->identifier);
7589         }
7590 }
7591
7592 cmdline_parse_token_string_t cmd_showdevice_show =
7593         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7594                                  "show");
7595 cmdline_parse_token_string_t cmd_showdevice_device =
7596         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7597 cmdline_parse_token_string_t cmd_showdevice_what =
7598         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7599                                  "info");
7600 cmdline_parse_token_string_t cmd_showdevice_identifier =
7601         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7602                         identifier, NULL);
7603
7604 cmdline_parse_inst_t cmd_showdevice = {
7605         .f = cmd_showdevice_parsed,
7606         .data = NULL,
7607         .help_str = "show device info <identifier>|all",
7608         .tokens = {
7609                 (void *)&cmd_showdevice_show,
7610                 (void *)&cmd_showdevice_device,
7611                 (void *)&cmd_showdevice_what,
7612                 (void *)&cmd_showdevice_identifier,
7613                 NULL,
7614         },
7615 };
7616 /* *** SHOW QUEUE INFO *** */
7617 struct cmd_showqueue_result {
7618         cmdline_fixed_string_t show;
7619         cmdline_fixed_string_t type;
7620         cmdline_fixed_string_t what;
7621         uint16_t portnum;
7622         uint16_t queuenum;
7623 };
7624
7625 static void
7626 cmd_showqueue_parsed(void *parsed_result,
7627         __rte_unused struct cmdline *cl,
7628         __rte_unused void *data)
7629 {
7630         struct cmd_showqueue_result *res = parsed_result;
7631
7632         if (!strcmp(res->type, "rxq"))
7633                 rx_queue_infos_display(res->portnum, res->queuenum);
7634         else if (!strcmp(res->type, "txq"))
7635                 tx_queue_infos_display(res->portnum, res->queuenum);
7636 }
7637
7638 cmdline_parse_token_string_t cmd_showqueue_show =
7639         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7640 cmdline_parse_token_string_t cmd_showqueue_type =
7641         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7642 cmdline_parse_token_string_t cmd_showqueue_what =
7643         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7644 cmdline_parse_token_num_t cmd_showqueue_portnum =
7645         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7646 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7647         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7648
7649 cmdline_parse_inst_t cmd_showqueue = {
7650         .f = cmd_showqueue_parsed,
7651         .data = NULL,
7652         .help_str = "show rxq|txq info <port_id> <queue_id>",
7653         .tokens = {
7654                 (void *)&cmd_showqueue_show,
7655                 (void *)&cmd_showqueue_type,
7656                 (void *)&cmd_showqueue_what,
7657                 (void *)&cmd_showqueue_portnum,
7658                 (void *)&cmd_showqueue_queuenum,
7659                 NULL,
7660         },
7661 };
7662
7663 /* show/clear fwd engine statistics */
7664 struct fwd_result {
7665         cmdline_fixed_string_t action;
7666         cmdline_fixed_string_t fwd;
7667         cmdline_fixed_string_t stats;
7668         cmdline_fixed_string_t all;
7669 };
7670
7671 cmdline_parse_token_string_t cmd_fwd_action =
7672         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7673 cmdline_parse_token_string_t cmd_fwd_fwd =
7674         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7675 cmdline_parse_token_string_t cmd_fwd_stats =
7676         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7677 cmdline_parse_token_string_t cmd_fwd_all =
7678         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7679
7680 static void
7681 cmd_showfwdall_parsed(void *parsed_result,
7682                       __rte_unused struct cmdline *cl,
7683                       __rte_unused void *data)
7684 {
7685         struct fwd_result *res = parsed_result;
7686
7687         if (!strcmp(res->action, "show"))
7688                 fwd_stats_display();
7689         else
7690                 fwd_stats_reset();
7691 }
7692
7693 static cmdline_parse_inst_t cmd_showfwdall = {
7694         .f = cmd_showfwdall_parsed,
7695         .data = NULL,
7696         .help_str = "show|clear fwd stats all",
7697         .tokens = {
7698                 (void *)&cmd_fwd_action,
7699                 (void *)&cmd_fwd_fwd,
7700                 (void *)&cmd_fwd_stats,
7701                 (void *)&cmd_fwd_all,
7702                 NULL,
7703         },
7704 };
7705
7706 /* *** READ PORT REGISTER *** */
7707 struct cmd_read_reg_result {
7708         cmdline_fixed_string_t read;
7709         cmdline_fixed_string_t reg;
7710         portid_t port_id;
7711         uint32_t reg_off;
7712 };
7713
7714 static void
7715 cmd_read_reg_parsed(void *parsed_result,
7716                     __rte_unused struct cmdline *cl,
7717                     __rte_unused void *data)
7718 {
7719         struct cmd_read_reg_result *res = parsed_result;
7720         port_reg_display(res->port_id, res->reg_off);
7721 }
7722
7723 cmdline_parse_token_string_t cmd_read_reg_read =
7724         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7725 cmdline_parse_token_string_t cmd_read_reg_reg =
7726         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7727 cmdline_parse_token_num_t cmd_read_reg_port_id =
7728         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7729 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7730         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7731
7732 cmdline_parse_inst_t cmd_read_reg = {
7733         .f = cmd_read_reg_parsed,
7734         .data = NULL,
7735         .help_str = "read reg <port_id> <reg_off>",
7736         .tokens = {
7737                 (void *)&cmd_read_reg_read,
7738                 (void *)&cmd_read_reg_reg,
7739                 (void *)&cmd_read_reg_port_id,
7740                 (void *)&cmd_read_reg_reg_off,
7741                 NULL,
7742         },
7743 };
7744
7745 /* *** READ PORT REGISTER BIT FIELD *** */
7746 struct cmd_read_reg_bit_field_result {
7747         cmdline_fixed_string_t read;
7748         cmdline_fixed_string_t regfield;
7749         portid_t port_id;
7750         uint32_t reg_off;
7751         uint8_t bit1_pos;
7752         uint8_t bit2_pos;
7753 };
7754
7755 static void
7756 cmd_read_reg_bit_field_parsed(void *parsed_result,
7757                               __rte_unused struct cmdline *cl,
7758                               __rte_unused void *data)
7759 {
7760         struct cmd_read_reg_bit_field_result *res = parsed_result;
7761         port_reg_bit_field_display(res->port_id, res->reg_off,
7762                                    res->bit1_pos, res->bit2_pos);
7763 }
7764
7765 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7766         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7767                                  "read");
7768 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7769         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7770                                  regfield, "regfield");
7771 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7772         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7773                               UINT16);
7774 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7775         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7776                               UINT32);
7777 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7778         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7779                               UINT8);
7780 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7781         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7782                               UINT8);
7783
7784 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7785         .f = cmd_read_reg_bit_field_parsed,
7786         .data = NULL,
7787         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7788         "Read register bit field between bit_x and bit_y included",
7789         .tokens = {
7790                 (void *)&cmd_read_reg_bit_field_read,
7791                 (void *)&cmd_read_reg_bit_field_regfield,
7792                 (void *)&cmd_read_reg_bit_field_port_id,
7793                 (void *)&cmd_read_reg_bit_field_reg_off,
7794                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7795                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7796                 NULL,
7797         },
7798 };
7799
7800 /* *** READ PORT REGISTER BIT *** */
7801 struct cmd_read_reg_bit_result {
7802         cmdline_fixed_string_t read;
7803         cmdline_fixed_string_t regbit;
7804         portid_t port_id;
7805         uint32_t reg_off;
7806         uint8_t bit_pos;
7807 };
7808
7809 static void
7810 cmd_read_reg_bit_parsed(void *parsed_result,
7811                         __rte_unused struct cmdline *cl,
7812                         __rte_unused void *data)
7813 {
7814         struct cmd_read_reg_bit_result *res = parsed_result;
7815         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7816 }
7817
7818 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7819         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7820 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7821         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7822                                  regbit, "regbit");
7823 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7824         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7825 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7826         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7827 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7828         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7829
7830 cmdline_parse_inst_t cmd_read_reg_bit = {
7831         .f = cmd_read_reg_bit_parsed,
7832         .data = NULL,
7833         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7834         .tokens = {
7835                 (void *)&cmd_read_reg_bit_read,
7836                 (void *)&cmd_read_reg_bit_regbit,
7837                 (void *)&cmd_read_reg_bit_port_id,
7838                 (void *)&cmd_read_reg_bit_reg_off,
7839                 (void *)&cmd_read_reg_bit_bit_pos,
7840                 NULL,
7841         },
7842 };
7843
7844 /* *** WRITE PORT REGISTER *** */
7845 struct cmd_write_reg_result {
7846         cmdline_fixed_string_t write;
7847         cmdline_fixed_string_t reg;
7848         portid_t port_id;
7849         uint32_t reg_off;
7850         uint32_t value;
7851 };
7852
7853 static void
7854 cmd_write_reg_parsed(void *parsed_result,
7855                      __rte_unused struct cmdline *cl,
7856                      __rte_unused void *data)
7857 {
7858         struct cmd_write_reg_result *res = parsed_result;
7859         port_reg_set(res->port_id, res->reg_off, res->value);
7860 }
7861
7862 cmdline_parse_token_string_t cmd_write_reg_write =
7863         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7864 cmdline_parse_token_string_t cmd_write_reg_reg =
7865         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7866 cmdline_parse_token_num_t cmd_write_reg_port_id =
7867         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7868 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7869         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7870 cmdline_parse_token_num_t cmd_write_reg_value =
7871         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7872
7873 cmdline_parse_inst_t cmd_write_reg = {
7874         .f = cmd_write_reg_parsed,
7875         .data = NULL,
7876         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7877         .tokens = {
7878                 (void *)&cmd_write_reg_write,
7879                 (void *)&cmd_write_reg_reg,
7880                 (void *)&cmd_write_reg_port_id,
7881                 (void *)&cmd_write_reg_reg_off,
7882                 (void *)&cmd_write_reg_value,
7883                 NULL,
7884         },
7885 };
7886
7887 /* *** WRITE PORT REGISTER BIT FIELD *** */
7888 struct cmd_write_reg_bit_field_result {
7889         cmdline_fixed_string_t write;
7890         cmdline_fixed_string_t regfield;
7891         portid_t port_id;
7892         uint32_t reg_off;
7893         uint8_t bit1_pos;
7894         uint8_t bit2_pos;
7895         uint32_t value;
7896 };
7897
7898 static void
7899 cmd_write_reg_bit_field_parsed(void *parsed_result,
7900                                __rte_unused struct cmdline *cl,
7901                                __rte_unused void *data)
7902 {
7903         struct cmd_write_reg_bit_field_result *res = parsed_result;
7904         port_reg_bit_field_set(res->port_id, res->reg_off,
7905                           res->bit1_pos, res->bit2_pos, res->value);
7906 }
7907
7908 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7909         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7910                                  "write");
7911 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7912         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7913                                  regfield, "regfield");
7914 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7915         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7916                               UINT16);
7917 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7918         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7919                               UINT32);
7920 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7921         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7922                               UINT8);
7923 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7924         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7925                               UINT8);
7926 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7927         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7928                               UINT32);
7929
7930 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7931         .f = cmd_write_reg_bit_field_parsed,
7932         .data = NULL,
7933         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7934                 "<reg_value>: "
7935                 "Set register bit field between bit_x and bit_y included",
7936         .tokens = {
7937                 (void *)&cmd_write_reg_bit_field_write,
7938                 (void *)&cmd_write_reg_bit_field_regfield,
7939                 (void *)&cmd_write_reg_bit_field_port_id,
7940                 (void *)&cmd_write_reg_bit_field_reg_off,
7941                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7942                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7943                 (void *)&cmd_write_reg_bit_field_value,
7944                 NULL,
7945         },
7946 };
7947
7948 /* *** WRITE PORT REGISTER BIT *** */
7949 struct cmd_write_reg_bit_result {
7950         cmdline_fixed_string_t write;
7951         cmdline_fixed_string_t regbit;
7952         portid_t port_id;
7953         uint32_t reg_off;
7954         uint8_t bit_pos;
7955         uint8_t value;
7956 };
7957
7958 static void
7959 cmd_write_reg_bit_parsed(void *parsed_result,
7960                          __rte_unused struct cmdline *cl,
7961                          __rte_unused void *data)
7962 {
7963         struct cmd_write_reg_bit_result *res = parsed_result;
7964         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7965 }
7966
7967 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7968         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7969                                  "write");
7970 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7971         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7972                                  regbit, "regbit");
7973 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7974         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7975 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7976         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7977 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7978         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7979 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7980         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7981
7982 cmdline_parse_inst_t cmd_write_reg_bit = {
7983         .f = cmd_write_reg_bit_parsed,
7984         .data = NULL,
7985         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7986                 "0 <= bit_x <= 31",
7987         .tokens = {
7988                 (void *)&cmd_write_reg_bit_write,
7989                 (void *)&cmd_write_reg_bit_regbit,
7990                 (void *)&cmd_write_reg_bit_port_id,
7991                 (void *)&cmd_write_reg_bit_reg_off,
7992                 (void *)&cmd_write_reg_bit_bit_pos,
7993                 (void *)&cmd_write_reg_bit_value,
7994                 NULL,
7995         },
7996 };
7997
7998 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7999 struct cmd_read_rxd_txd_result {
8000         cmdline_fixed_string_t read;
8001         cmdline_fixed_string_t rxd_txd;
8002         portid_t port_id;
8003         uint16_t queue_id;
8004         uint16_t desc_id;
8005 };
8006
8007 static void
8008 cmd_read_rxd_txd_parsed(void *parsed_result,
8009                         __rte_unused struct cmdline *cl,
8010                         __rte_unused void *data)
8011 {
8012         struct cmd_read_rxd_txd_result *res = parsed_result;
8013
8014         if (!strcmp(res->rxd_txd, "rxd"))
8015                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8016         else if (!strcmp(res->rxd_txd, "txd"))
8017                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8018 }
8019
8020 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8021         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8022 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8023         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8024                                  "rxd#txd");
8025 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8026         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8027 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8028         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8029 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8030         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8031
8032 cmdline_parse_inst_t cmd_read_rxd_txd = {
8033         .f = cmd_read_rxd_txd_parsed,
8034         .data = NULL,
8035         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8036         .tokens = {
8037                 (void *)&cmd_read_rxd_txd_read,
8038                 (void *)&cmd_read_rxd_txd_rxd_txd,
8039                 (void *)&cmd_read_rxd_txd_port_id,
8040                 (void *)&cmd_read_rxd_txd_queue_id,
8041                 (void *)&cmd_read_rxd_txd_desc_id,
8042                 NULL,
8043         },
8044 };
8045
8046 /* *** QUIT *** */
8047 struct cmd_quit_result {
8048         cmdline_fixed_string_t quit;
8049 };
8050
8051 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8052                             struct cmdline *cl,
8053                             __rte_unused void *data)
8054 {
8055         cmdline_quit(cl);
8056 }
8057
8058 cmdline_parse_token_string_t cmd_quit_quit =
8059         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8060
8061 cmdline_parse_inst_t cmd_quit = {
8062         .f = cmd_quit_parsed,
8063         .data = NULL,
8064         .help_str = "quit: Exit application",
8065         .tokens = {
8066                 (void *)&cmd_quit_quit,
8067                 NULL,
8068         },
8069 };
8070
8071 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8072 struct cmd_mac_addr_result {
8073         cmdline_fixed_string_t mac_addr_cmd;
8074         cmdline_fixed_string_t what;
8075         uint16_t port_num;
8076         struct rte_ether_addr address;
8077 };
8078
8079 static void cmd_mac_addr_parsed(void *parsed_result,
8080                 __rte_unused struct cmdline *cl,
8081                 __rte_unused void *data)
8082 {
8083         struct cmd_mac_addr_result *res = parsed_result;
8084         int ret;
8085
8086         if (strcmp(res->what, "add") == 0)
8087                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8088         else if (strcmp(res->what, "set") == 0)
8089                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8090                                                        &res->address);
8091         else
8092                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8093
8094         /* check the return value and print it if is < 0 */
8095         if(ret < 0)
8096                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8097
8098 }
8099
8100 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8101         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8102                                 "mac_addr");
8103 cmdline_parse_token_string_t cmd_mac_addr_what =
8104         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8105                                 "add#remove#set");
8106 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8107                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8108                                         UINT16);
8109 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8110                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8111
8112 cmdline_parse_inst_t cmd_mac_addr = {
8113         .f = cmd_mac_addr_parsed,
8114         .data = (void *)0,
8115         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8116                         "Add/Remove/Set MAC address on port_id",
8117         .tokens = {
8118                 (void *)&cmd_mac_addr_cmd,
8119                 (void *)&cmd_mac_addr_what,
8120                 (void *)&cmd_mac_addr_portnum,
8121                 (void *)&cmd_mac_addr_addr,
8122                 NULL,
8123         },
8124 };
8125
8126 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8127 struct cmd_eth_peer_result {
8128         cmdline_fixed_string_t set;
8129         cmdline_fixed_string_t eth_peer;
8130         portid_t port_id;
8131         cmdline_fixed_string_t peer_addr;
8132 };
8133
8134 static void cmd_set_eth_peer_parsed(void *parsed_result,
8135                         __rte_unused struct cmdline *cl,
8136                         __rte_unused void *data)
8137 {
8138                 struct cmd_eth_peer_result *res = parsed_result;
8139
8140                 if (test_done == 0) {
8141                         printf("Please stop forwarding first\n");
8142                         return;
8143                 }
8144                 if (!strcmp(res->eth_peer, "eth-peer")) {
8145                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8146                         fwd_config_setup();
8147                 }
8148 }
8149 cmdline_parse_token_string_t cmd_eth_peer_set =
8150         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8151 cmdline_parse_token_string_t cmd_eth_peer =
8152         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8153 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8154         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8155 cmdline_parse_token_string_t cmd_eth_peer_addr =
8156         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8157
8158 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8159         .f = cmd_set_eth_peer_parsed,
8160         .data = NULL,
8161         .help_str = "set eth-peer <port_id> <peer_mac>",
8162         .tokens = {
8163                 (void *)&cmd_eth_peer_set,
8164                 (void *)&cmd_eth_peer,
8165                 (void *)&cmd_eth_peer_port_id,
8166                 (void *)&cmd_eth_peer_addr,
8167                 NULL,
8168         },
8169 };
8170
8171 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8172 struct cmd_set_qmap_result {
8173         cmdline_fixed_string_t set;
8174         cmdline_fixed_string_t qmap;
8175         cmdline_fixed_string_t what;
8176         portid_t port_id;
8177         uint16_t queue_id;
8178         uint8_t map_value;
8179 };
8180
8181 static void
8182 cmd_set_qmap_parsed(void *parsed_result,
8183                        __rte_unused struct cmdline *cl,
8184                        __rte_unused void *data)
8185 {
8186         struct cmd_set_qmap_result *res = parsed_result;
8187         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8188
8189         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8190 }
8191
8192 cmdline_parse_token_string_t cmd_setqmap_set =
8193         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8194                                  set, "set");
8195 cmdline_parse_token_string_t cmd_setqmap_qmap =
8196         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8197                                  qmap, "stat_qmap");
8198 cmdline_parse_token_string_t cmd_setqmap_what =
8199         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8200                                  what, "tx#rx");
8201 cmdline_parse_token_num_t cmd_setqmap_portid =
8202         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8203                               port_id, UINT16);
8204 cmdline_parse_token_num_t cmd_setqmap_queueid =
8205         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8206                               queue_id, UINT16);
8207 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8208         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8209                               map_value, UINT8);
8210
8211 cmdline_parse_inst_t cmd_set_qmap = {
8212         .f = cmd_set_qmap_parsed,
8213         .data = NULL,
8214         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8215                 "Set statistics mapping value on tx|rx queue_id of port_id",
8216         .tokens = {
8217                 (void *)&cmd_setqmap_set,
8218                 (void *)&cmd_setqmap_qmap,
8219                 (void *)&cmd_setqmap_what,
8220                 (void *)&cmd_setqmap_portid,
8221                 (void *)&cmd_setqmap_queueid,
8222                 (void *)&cmd_setqmap_mapvalue,
8223                 NULL,
8224         },
8225 };
8226
8227 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8228 struct cmd_set_xstats_hide_zero_result {
8229         cmdline_fixed_string_t keyword;
8230         cmdline_fixed_string_t name;
8231         cmdline_fixed_string_t on_off;
8232 };
8233
8234 static void
8235 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8236                         __rte_unused struct cmdline *cl,
8237                         __rte_unused void *data)
8238 {
8239         struct cmd_set_xstats_hide_zero_result *res;
8240         uint16_t on_off = 0;
8241
8242         res = parsed_result;
8243         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8244         set_xstats_hide_zero(on_off);
8245 }
8246
8247 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8248         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8249                                  keyword, "set");
8250 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8251         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8252                                  name, "xstats-hide-zero");
8253 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8254         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8255                                  on_off, "on#off");
8256
8257 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8258         .f = cmd_set_xstats_hide_zero_parsed,
8259         .data = NULL,
8260         .help_str = "set xstats-hide-zero on|off",
8261         .tokens = {
8262                 (void *)&cmd_set_xstats_hide_zero_keyword,
8263                 (void *)&cmd_set_xstats_hide_zero_name,
8264                 (void *)&cmd_set_xstats_hide_zero_on_off,
8265                 NULL,
8266         },
8267 };
8268
8269 /* *** CONFIGURE UNICAST HASH TABLE *** */
8270 struct cmd_set_uc_hash_table {
8271         cmdline_fixed_string_t set;
8272         cmdline_fixed_string_t port;
8273         portid_t port_id;
8274         cmdline_fixed_string_t what;
8275         struct rte_ether_addr address;
8276         cmdline_fixed_string_t mode;
8277 };
8278
8279 static void
8280 cmd_set_uc_hash_parsed(void *parsed_result,
8281                        __rte_unused struct cmdline *cl,
8282                        __rte_unused void *data)
8283 {
8284         int ret=0;
8285         struct cmd_set_uc_hash_table *res = parsed_result;
8286
8287         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8288
8289         if (strcmp(res->what, "uta") == 0)
8290                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8291                                                 &res->address,(uint8_t)is_on);
8292         if (ret < 0)
8293                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8294
8295 }
8296
8297 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8298         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8299                                  set, "set");
8300 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8301         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8302                                  port, "port");
8303 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8304         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8305                               port_id, UINT16);
8306 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8307         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8308                                  what, "uta");
8309 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8310         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8311                                 address);
8312 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8313         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8314                                  mode, "on#off");
8315
8316 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8317         .f = cmd_set_uc_hash_parsed,
8318         .data = NULL,
8319         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8320         .tokens = {
8321                 (void *)&cmd_set_uc_hash_set,
8322                 (void *)&cmd_set_uc_hash_port,
8323                 (void *)&cmd_set_uc_hash_portid,
8324                 (void *)&cmd_set_uc_hash_what,
8325                 (void *)&cmd_set_uc_hash_mac,
8326                 (void *)&cmd_set_uc_hash_mode,
8327                 NULL,
8328         },
8329 };
8330
8331 struct cmd_set_uc_all_hash_table {
8332         cmdline_fixed_string_t set;
8333         cmdline_fixed_string_t port;
8334         portid_t port_id;
8335         cmdline_fixed_string_t what;
8336         cmdline_fixed_string_t value;
8337         cmdline_fixed_string_t mode;
8338 };
8339
8340 static void
8341 cmd_set_uc_all_hash_parsed(void *parsed_result,
8342                        __rte_unused struct cmdline *cl,
8343                        __rte_unused void *data)
8344 {
8345         int ret=0;
8346         struct cmd_set_uc_all_hash_table *res = parsed_result;
8347
8348         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8349
8350         if ((strcmp(res->what, "uta") == 0) &&
8351                 (strcmp(res->value, "all") == 0))
8352                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8353         if (ret < 0)
8354                 printf("bad unicast hash table parameter,"
8355                         "return code = %d \n", ret);
8356 }
8357
8358 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8359         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8360                                  set, "set");
8361 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8362         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8363                                  port, "port");
8364 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8365         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8366                               port_id, UINT16);
8367 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8368         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8369                                  what, "uta");
8370 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8371         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8372                                 value,"all");
8373 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8374         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8375                                  mode, "on#off");
8376
8377 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8378         .f = cmd_set_uc_all_hash_parsed,
8379         .data = NULL,
8380         .help_str = "set port <port_id> uta all on|off",
8381         .tokens = {
8382                 (void *)&cmd_set_uc_all_hash_set,
8383                 (void *)&cmd_set_uc_all_hash_port,
8384                 (void *)&cmd_set_uc_all_hash_portid,
8385                 (void *)&cmd_set_uc_all_hash_what,
8386                 (void *)&cmd_set_uc_all_hash_value,
8387                 (void *)&cmd_set_uc_all_hash_mode,
8388                 NULL,
8389         },
8390 };
8391
8392 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8393 struct cmd_set_vf_macvlan_filter {
8394         cmdline_fixed_string_t set;
8395         cmdline_fixed_string_t port;
8396         portid_t port_id;
8397         cmdline_fixed_string_t vf;
8398         uint8_t vf_id;
8399         struct rte_ether_addr address;
8400         cmdline_fixed_string_t filter_type;
8401         cmdline_fixed_string_t mode;
8402 };
8403
8404 static void
8405 cmd_set_vf_macvlan_parsed(void *parsed_result,
8406                        __rte_unused struct cmdline *cl,
8407                        __rte_unused void *data)
8408 {
8409         int is_on, ret = 0;
8410         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8411         struct rte_eth_mac_filter filter;
8412
8413         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8414
8415         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8416
8417         /* set VF MAC filter */
8418         filter.is_vf = 1;
8419
8420         /* set VF ID */
8421         filter.dst_id = res->vf_id;
8422
8423         if (!strcmp(res->filter_type, "exact-mac"))
8424                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8425         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8426                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8427         else if (!strcmp(res->filter_type, "hashmac"))
8428                 filter.filter_type = RTE_MAC_HASH_MATCH;
8429         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8430                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8431
8432         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8433
8434         if (is_on)
8435                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8436                                         RTE_ETH_FILTER_MACVLAN,
8437                                         RTE_ETH_FILTER_ADD,
8438                                          &filter);
8439         else
8440                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8441                                         RTE_ETH_FILTER_MACVLAN,
8442                                         RTE_ETH_FILTER_DELETE,
8443                                         &filter);
8444
8445         if (ret < 0)
8446                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8447
8448 }
8449
8450 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8451         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8452                                  set, "set");
8453 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8454         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8455                                  port, "port");
8456 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8457         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8458                               port_id, UINT16);
8459 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8460         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8461                                  vf, "vf");
8462 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8463         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8464                                 vf_id, UINT8);
8465 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8466         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8467                                 address);
8468 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8469         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8470                                 filter_type, "exact-mac#exact-mac-vlan"
8471                                 "#hashmac#hashmac-vlan");
8472 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8473         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8474                                  mode, "on#off");
8475
8476 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8477         .f = cmd_set_vf_macvlan_parsed,
8478         .data = NULL,
8479         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8480                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8481                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8482                 "hash match rule: hash match of MAC and exact match of VLAN",
8483         .tokens = {
8484                 (void *)&cmd_set_vf_macvlan_set,
8485                 (void *)&cmd_set_vf_macvlan_port,
8486                 (void *)&cmd_set_vf_macvlan_portid,
8487                 (void *)&cmd_set_vf_macvlan_vf,
8488                 (void *)&cmd_set_vf_macvlan_vf_id,
8489                 (void *)&cmd_set_vf_macvlan_mac,
8490                 (void *)&cmd_set_vf_macvlan_filter_type,
8491                 (void *)&cmd_set_vf_macvlan_mode,
8492                 NULL,
8493         },
8494 };
8495
8496 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8497 struct cmd_set_vf_traffic {
8498         cmdline_fixed_string_t set;
8499         cmdline_fixed_string_t port;
8500         portid_t port_id;
8501         cmdline_fixed_string_t vf;
8502         uint8_t vf_id;
8503         cmdline_fixed_string_t what;
8504         cmdline_fixed_string_t mode;
8505 };
8506
8507 static void
8508 cmd_set_vf_traffic_parsed(void *parsed_result,
8509                        __rte_unused struct cmdline *cl,
8510                        __rte_unused void *data)
8511 {
8512         struct cmd_set_vf_traffic *res = parsed_result;
8513         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8514         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8515
8516         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8517 }
8518
8519 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8520         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8521                                  set, "set");
8522 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8523         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8524                                  port, "port");
8525 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8526         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8527                               port_id, UINT16);
8528 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8529         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8530                                  vf, "vf");
8531 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8532         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8533                               vf_id, UINT8);
8534 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8535         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8536                                  what, "tx#rx");
8537 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8538         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8539                                  mode, "on#off");
8540
8541 cmdline_parse_inst_t cmd_set_vf_traffic = {
8542         .f = cmd_set_vf_traffic_parsed,
8543         .data = NULL,
8544         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8545         .tokens = {
8546                 (void *)&cmd_setvf_traffic_set,
8547                 (void *)&cmd_setvf_traffic_port,
8548                 (void *)&cmd_setvf_traffic_portid,
8549                 (void *)&cmd_setvf_traffic_vf,
8550                 (void *)&cmd_setvf_traffic_vfid,
8551                 (void *)&cmd_setvf_traffic_what,
8552                 (void *)&cmd_setvf_traffic_mode,
8553                 NULL,
8554         },
8555 };
8556
8557 /* *** CONFIGURE VF RECEIVE MODE *** */
8558 struct cmd_set_vf_rxmode {
8559         cmdline_fixed_string_t set;
8560         cmdline_fixed_string_t port;
8561         portid_t port_id;
8562         cmdline_fixed_string_t vf;
8563         uint8_t vf_id;
8564         cmdline_fixed_string_t what;
8565         cmdline_fixed_string_t mode;
8566         cmdline_fixed_string_t on;
8567 };
8568
8569 static void
8570 cmd_set_vf_rxmode_parsed(void *parsed_result,
8571                        __rte_unused struct cmdline *cl,
8572                        __rte_unused void *data)
8573 {
8574         int ret = -ENOTSUP;
8575         uint16_t vf_rxmode = 0;
8576         struct cmd_set_vf_rxmode *res = parsed_result;
8577
8578         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8579         if (!strcmp(res->what,"rxmode")) {
8580                 if (!strcmp(res->mode, "AUPE"))
8581                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8582                 else if (!strcmp(res->mode, "ROPE"))
8583                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8584                 else if (!strcmp(res->mode, "BAM"))
8585                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8586                 else if (!strncmp(res->mode, "MPE",3))
8587                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8588         }
8589
8590         RTE_SET_USED(is_on);
8591
8592 #ifdef RTE_LIBRTE_IXGBE_PMD
8593         if (ret == -ENOTSUP)
8594                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8595                                                   vf_rxmode, (uint8_t)is_on);
8596 #endif
8597 #ifdef RTE_LIBRTE_BNXT_PMD
8598         if (ret == -ENOTSUP)
8599                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8600                                                  vf_rxmode, (uint8_t)is_on);
8601 #endif
8602         if (ret < 0)
8603                 printf("bad VF receive mode parameter, return code = %d \n",
8604                 ret);
8605 }
8606
8607 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8608         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8609                                  set, "set");
8610 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8611         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8612                                  port, "port");
8613 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8614         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8615                               port_id, UINT16);
8616 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8617         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8618                                  vf, "vf");
8619 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8620         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8621                               vf_id, UINT8);
8622 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8623         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8624                                  what, "rxmode");
8625 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8626         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8627                                  mode, "AUPE#ROPE#BAM#MPE");
8628 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8629         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8630                                  on, "on#off");
8631
8632 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8633         .f = cmd_set_vf_rxmode_parsed,
8634         .data = NULL,
8635         .help_str = "set port <port_id> vf <vf_id> rxmode "
8636                 "AUPE|ROPE|BAM|MPE on|off",
8637         .tokens = {
8638                 (void *)&cmd_set_vf_rxmode_set,
8639                 (void *)&cmd_set_vf_rxmode_port,
8640                 (void *)&cmd_set_vf_rxmode_portid,
8641                 (void *)&cmd_set_vf_rxmode_vf,
8642                 (void *)&cmd_set_vf_rxmode_vfid,
8643                 (void *)&cmd_set_vf_rxmode_what,
8644                 (void *)&cmd_set_vf_rxmode_mode,
8645                 (void *)&cmd_set_vf_rxmode_on,
8646                 NULL,
8647         },
8648 };
8649
8650 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8651 struct cmd_vf_mac_addr_result {
8652         cmdline_fixed_string_t mac_addr_cmd;
8653         cmdline_fixed_string_t what;
8654         cmdline_fixed_string_t port;
8655         uint16_t port_num;
8656         cmdline_fixed_string_t vf;
8657         uint8_t vf_num;
8658         struct rte_ether_addr address;
8659 };
8660
8661 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8662                 __rte_unused struct cmdline *cl,
8663                 __rte_unused void *data)
8664 {
8665         struct cmd_vf_mac_addr_result *res = parsed_result;
8666         int ret = -ENOTSUP;
8667
8668         if (strcmp(res->what, "add") != 0)
8669                 return;
8670
8671 #ifdef RTE_LIBRTE_I40E_PMD
8672         if (ret == -ENOTSUP)
8673                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8674                                                    &res->address);
8675 #endif
8676 #ifdef RTE_LIBRTE_BNXT_PMD
8677         if (ret == -ENOTSUP)
8678                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8679                                                 res->vf_num);
8680 #endif
8681
8682         if(ret < 0)
8683                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8684
8685 }
8686
8687 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8688         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8689                                 mac_addr_cmd,"mac_addr");
8690 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8691         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8692                                 what,"add");
8693 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8694         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8695                                 port,"port");
8696 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8697         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8698                                 port_num, UINT16);
8699 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8700         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8701                                 vf,"vf");
8702 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8703         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8704                                 vf_num, UINT8);
8705 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8706         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8707                                 address);
8708
8709 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8710         .f = cmd_vf_mac_addr_parsed,
8711         .data = (void *)0,
8712         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8713                 "Add MAC address filtering for a VF on port_id",
8714         .tokens = {
8715                 (void *)&cmd_vf_mac_addr_cmd,
8716                 (void *)&cmd_vf_mac_addr_what,
8717                 (void *)&cmd_vf_mac_addr_port,
8718                 (void *)&cmd_vf_mac_addr_portnum,
8719                 (void *)&cmd_vf_mac_addr_vf,
8720                 (void *)&cmd_vf_mac_addr_vfnum,
8721                 (void *)&cmd_vf_mac_addr_addr,
8722                 NULL,
8723         },
8724 };
8725
8726 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8727 struct cmd_vf_rx_vlan_filter {
8728         cmdline_fixed_string_t rx_vlan;
8729         cmdline_fixed_string_t what;
8730         uint16_t vlan_id;
8731         cmdline_fixed_string_t port;
8732         portid_t port_id;
8733         cmdline_fixed_string_t vf;
8734         uint64_t vf_mask;
8735 };
8736
8737 static void
8738 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8739                           __rte_unused struct cmdline *cl,
8740                           __rte_unused void *data)
8741 {
8742         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8743         int ret = -ENOTSUP;
8744
8745         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8746
8747 #ifdef RTE_LIBRTE_IXGBE_PMD
8748         if (ret == -ENOTSUP)
8749                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8750                                 res->vlan_id, res->vf_mask, is_add);
8751 #endif
8752 #ifdef RTE_LIBRTE_I40E_PMD
8753         if (ret == -ENOTSUP)
8754                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8755                                 res->vlan_id, res->vf_mask, is_add);
8756 #endif
8757 #ifdef RTE_LIBRTE_BNXT_PMD
8758         if (ret == -ENOTSUP)
8759                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8760                                 res->vlan_id, res->vf_mask, is_add);
8761 #endif
8762
8763         switch (ret) {
8764         case 0:
8765                 break;
8766         case -EINVAL:
8767                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8768                                 res->vlan_id, res->vf_mask);
8769                 break;
8770         case -ENODEV:
8771                 printf("invalid port_id %d\n", res->port_id);
8772                 break;
8773         case -ENOTSUP:
8774                 printf("function not implemented or supported\n");
8775                 break;
8776         default:
8777                 printf("programming error: (%s)\n", strerror(-ret));
8778         }
8779 }
8780
8781 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8782         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8783                                  rx_vlan, "rx_vlan");
8784 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8785         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8786                                  what, "add#rm");
8787 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8788         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8789                               vlan_id, UINT16);
8790 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8791         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8792                                  port, "port");
8793 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8794         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8795                               port_id, UINT16);
8796 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8797         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8798                                  vf, "vf");
8799 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8800         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8801                               vf_mask, UINT64);
8802
8803 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8804         .f = cmd_vf_rx_vlan_filter_parsed,
8805         .data = NULL,
8806         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8807                 "(vf_mask = hexadecimal VF mask)",
8808         .tokens = {
8809                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8810                 (void *)&cmd_vf_rx_vlan_filter_what,
8811                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8812                 (void *)&cmd_vf_rx_vlan_filter_port,
8813                 (void *)&cmd_vf_rx_vlan_filter_portid,
8814                 (void *)&cmd_vf_rx_vlan_filter_vf,
8815                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8816                 NULL,
8817         },
8818 };
8819
8820 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8821 struct cmd_queue_rate_limit_result {
8822         cmdline_fixed_string_t set;
8823         cmdline_fixed_string_t port;
8824         uint16_t port_num;
8825         cmdline_fixed_string_t queue;
8826         uint8_t queue_num;
8827         cmdline_fixed_string_t rate;
8828         uint16_t rate_num;
8829 };
8830
8831 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8832                 __rte_unused struct cmdline *cl,
8833                 __rte_unused void *data)
8834 {
8835         struct cmd_queue_rate_limit_result *res = parsed_result;
8836         int ret = 0;
8837
8838         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8839                 && (strcmp(res->queue, "queue") == 0)
8840                 && (strcmp(res->rate, "rate") == 0))
8841                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8842                                         res->rate_num);
8843         if (ret < 0)
8844                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8845
8846 }
8847
8848 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8849         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8850                                 set, "set");
8851 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8852         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8853                                 port, "port");
8854 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8855         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8856                                 port_num, UINT16);
8857 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8858         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8859                                 queue, "queue");
8860 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8861         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8862                                 queue_num, UINT8);
8863 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8864         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8865                                 rate, "rate");
8866 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8867         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8868                                 rate_num, UINT16);
8869
8870 cmdline_parse_inst_t cmd_queue_rate_limit = {
8871         .f = cmd_queue_rate_limit_parsed,
8872         .data = (void *)0,
8873         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8874                 "Set rate limit for a queue on port_id",
8875         .tokens = {
8876                 (void *)&cmd_queue_rate_limit_set,
8877                 (void *)&cmd_queue_rate_limit_port,
8878                 (void *)&cmd_queue_rate_limit_portnum,
8879                 (void *)&cmd_queue_rate_limit_queue,
8880                 (void *)&cmd_queue_rate_limit_queuenum,
8881                 (void *)&cmd_queue_rate_limit_rate,
8882                 (void *)&cmd_queue_rate_limit_ratenum,
8883                 NULL,
8884         },
8885 };
8886
8887 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8888 struct cmd_vf_rate_limit_result {
8889         cmdline_fixed_string_t set;
8890         cmdline_fixed_string_t port;
8891         uint16_t port_num;
8892         cmdline_fixed_string_t vf;
8893         uint8_t vf_num;
8894         cmdline_fixed_string_t rate;
8895         uint16_t rate_num;
8896         cmdline_fixed_string_t q_msk;
8897         uint64_t q_msk_val;
8898 };
8899
8900 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8901                 __rte_unused struct cmdline *cl,
8902                 __rte_unused void *data)
8903 {
8904         struct cmd_vf_rate_limit_result *res = parsed_result;
8905         int ret = 0;
8906
8907         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8908                 && (strcmp(res->vf, "vf") == 0)
8909                 && (strcmp(res->rate, "rate") == 0)
8910                 && (strcmp(res->q_msk, "queue_mask") == 0))
8911                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8912                                         res->rate_num, res->q_msk_val);
8913         if (ret < 0)
8914                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8915
8916 }
8917
8918 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8919         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8920                                 set, "set");
8921 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8922         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8923                                 port, "port");
8924 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8925         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8926                                 port_num, UINT16);
8927 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8928         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8929                                 vf, "vf");
8930 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8931         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8932                                 vf_num, UINT8);
8933 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8934         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8935                                 rate, "rate");
8936 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8937         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8938                                 rate_num, UINT16);
8939 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8940         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8941                                 q_msk, "queue_mask");
8942 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8943         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8944                                 q_msk_val, UINT64);
8945
8946 cmdline_parse_inst_t cmd_vf_rate_limit = {
8947         .f = cmd_vf_rate_limit_parsed,
8948         .data = (void *)0,
8949         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8950                 "queue_mask <queue_mask_value>: "
8951                 "Set rate limit for queues of VF on port_id",
8952         .tokens = {
8953                 (void *)&cmd_vf_rate_limit_set,
8954                 (void *)&cmd_vf_rate_limit_port,
8955                 (void *)&cmd_vf_rate_limit_portnum,
8956                 (void *)&cmd_vf_rate_limit_vf,
8957                 (void *)&cmd_vf_rate_limit_vfnum,
8958                 (void *)&cmd_vf_rate_limit_rate,
8959                 (void *)&cmd_vf_rate_limit_ratenum,
8960                 (void *)&cmd_vf_rate_limit_q_msk,
8961                 (void *)&cmd_vf_rate_limit_q_msk_val,
8962                 NULL,
8963         },
8964 };
8965
8966 /* *** ADD TUNNEL FILTER OF A PORT *** */
8967 struct cmd_tunnel_filter_result {
8968         cmdline_fixed_string_t cmd;
8969         cmdline_fixed_string_t what;
8970         portid_t port_id;
8971         struct rte_ether_addr outer_mac;
8972         struct rte_ether_addr inner_mac;
8973         cmdline_ipaddr_t ip_value;
8974         uint16_t inner_vlan;
8975         cmdline_fixed_string_t tunnel_type;
8976         cmdline_fixed_string_t filter_type;
8977         uint32_t tenant_id;
8978         uint16_t queue_num;
8979 };
8980
8981 static void
8982 cmd_tunnel_filter_parsed(void *parsed_result,
8983                           __rte_unused struct cmdline *cl,
8984                           __rte_unused void *data)
8985 {
8986         struct cmd_tunnel_filter_result *res = parsed_result;
8987         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8988         int ret = 0;
8989
8990         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8991
8992         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8993         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8994         tunnel_filter_conf.inner_vlan = res->inner_vlan;
8995
8996         if (res->ip_value.family == AF_INET) {
8997                 tunnel_filter_conf.ip_addr.ipv4_addr =
8998                         res->ip_value.addr.ipv4.s_addr;
8999                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9000         } else {
9001                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9002                         &(res->ip_value.addr.ipv6),
9003                         sizeof(struct in6_addr));
9004                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9005         }
9006
9007         if (!strcmp(res->filter_type, "imac-ivlan"))
9008                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9009         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9010                 tunnel_filter_conf.filter_type =
9011                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9012         else if (!strcmp(res->filter_type, "imac-tenid"))
9013                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9014         else if (!strcmp(res->filter_type, "imac"))
9015                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9016         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9017                 tunnel_filter_conf.filter_type =
9018                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9019         else if (!strcmp(res->filter_type, "oip"))
9020                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9021         else if (!strcmp(res->filter_type, "iip"))
9022                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9023         else {
9024                 printf("The filter type is not supported");
9025                 return;
9026         }
9027
9028         if (!strcmp(res->tunnel_type, "vxlan"))
9029                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9030         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9031                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9032         else if (!strcmp(res->tunnel_type, "nvgre"))
9033                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9034         else if (!strcmp(res->tunnel_type, "ipingre"))
9035                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9036         else {
9037                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9038                 return;
9039         }
9040
9041         tunnel_filter_conf.tenant_id = res->tenant_id;
9042         tunnel_filter_conf.queue_id = res->queue_num;
9043         if (!strcmp(res->what, "add"))
9044                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9045                                         RTE_ETH_FILTER_TUNNEL,
9046                                         RTE_ETH_FILTER_ADD,
9047                                         &tunnel_filter_conf);
9048         else
9049                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9050                                         RTE_ETH_FILTER_TUNNEL,
9051                                         RTE_ETH_FILTER_DELETE,
9052                                         &tunnel_filter_conf);
9053         if (ret < 0)
9054                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9055                                 strerror(-ret));
9056
9057 }
9058 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9059         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9060         cmd, "tunnel_filter");
9061 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9062         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9063         what, "add#rm");
9064 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9065         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9066         port_id, UINT16);
9067 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9068         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9069         outer_mac);
9070 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9071         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9072         inner_mac);
9073 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9074         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9075         inner_vlan, UINT16);
9076 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9077         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9078         ip_value);
9079 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9080         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9081         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9082
9083 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9084         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9085         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9086                 "imac#omac-imac-tenid");
9087 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9088         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9089         tenant_id, UINT32);
9090 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9091         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9092         queue_num, UINT16);
9093
9094 cmdline_parse_inst_t cmd_tunnel_filter = {
9095         .f = cmd_tunnel_filter_parsed,
9096         .data = (void *)0,
9097         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9098                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9099                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9100                 "<queue_id>: Add/Rm tunnel filter of a port",
9101         .tokens = {
9102                 (void *)&cmd_tunnel_filter_cmd,
9103                 (void *)&cmd_tunnel_filter_what,
9104                 (void *)&cmd_tunnel_filter_port_id,
9105                 (void *)&cmd_tunnel_filter_outer_mac,
9106                 (void *)&cmd_tunnel_filter_inner_mac,
9107                 (void *)&cmd_tunnel_filter_ip_value,
9108                 (void *)&cmd_tunnel_filter_innner_vlan,
9109                 (void *)&cmd_tunnel_filter_tunnel_type,
9110                 (void *)&cmd_tunnel_filter_filter_type,
9111                 (void *)&cmd_tunnel_filter_tenant_id,
9112                 (void *)&cmd_tunnel_filter_queue_num,
9113                 NULL,
9114         },
9115 };
9116
9117 /* *** CONFIGURE TUNNEL UDP PORT *** */
9118 struct cmd_tunnel_udp_config {
9119         cmdline_fixed_string_t cmd;
9120         cmdline_fixed_string_t what;
9121         uint16_t udp_port;
9122         portid_t port_id;
9123 };
9124
9125 static void
9126 cmd_tunnel_udp_config_parsed(void *parsed_result,
9127                           __rte_unused struct cmdline *cl,
9128                           __rte_unused void *data)
9129 {
9130         struct cmd_tunnel_udp_config *res = parsed_result;
9131         struct rte_eth_udp_tunnel tunnel_udp;
9132         int ret;
9133
9134         tunnel_udp.udp_port = res->udp_port;
9135
9136         if (!strcmp(res->cmd, "rx_vxlan_port"))
9137                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9138
9139         if (!strcmp(res->what, "add"))
9140                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9141                                                       &tunnel_udp);
9142         else
9143                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9144                                                          &tunnel_udp);
9145
9146         if (ret < 0)
9147                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9148 }
9149
9150 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9151         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9152                                 cmd, "rx_vxlan_port");
9153 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9154         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9155                                 what, "add#rm");
9156 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9157         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9158                                 udp_port, UINT16);
9159 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9160         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9161                                 port_id, UINT16);
9162
9163 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9164         .f = cmd_tunnel_udp_config_parsed,
9165         .data = (void *)0,
9166         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9167                 "Add/Remove a tunneling UDP port filter",
9168         .tokens = {
9169                 (void *)&cmd_tunnel_udp_config_cmd,
9170                 (void *)&cmd_tunnel_udp_config_what,
9171                 (void *)&cmd_tunnel_udp_config_udp_port,
9172                 (void *)&cmd_tunnel_udp_config_port_id,
9173                 NULL,
9174         },
9175 };
9176
9177 struct cmd_config_tunnel_udp_port {
9178         cmdline_fixed_string_t port;
9179         cmdline_fixed_string_t config;
9180         portid_t port_id;
9181         cmdline_fixed_string_t udp_tunnel_port;
9182         cmdline_fixed_string_t action;
9183         cmdline_fixed_string_t tunnel_type;
9184         uint16_t udp_port;
9185 };
9186
9187 static void
9188 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9189                                __rte_unused struct cmdline *cl,
9190                                __rte_unused void *data)
9191 {
9192         struct cmd_config_tunnel_udp_port *res = parsed_result;
9193         struct rte_eth_udp_tunnel tunnel_udp;
9194         int ret = 0;
9195
9196         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9197                 return;
9198
9199         tunnel_udp.udp_port = res->udp_port;
9200
9201         if (!strcmp(res->tunnel_type, "vxlan")) {
9202                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9203         } else if (!strcmp(res->tunnel_type, "geneve")) {
9204                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9205         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9206                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9207         } else {
9208                 printf("Invalid tunnel type\n");
9209                 return;
9210         }
9211
9212         if (!strcmp(res->action, "add"))
9213                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9214                                                       &tunnel_udp);
9215         else
9216                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9217                                                          &tunnel_udp);
9218
9219         if (ret < 0)
9220                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9221 }
9222
9223 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9224         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9225                                  "port");
9226 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9227         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9228                                  "config");
9229 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9230         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9231                               UINT16);
9232 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9233         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9234                                  udp_tunnel_port,
9235                                  "udp_tunnel_port");
9236 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9237         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9238                                  "add#rm");
9239 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9240         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9241                                  "vxlan#geneve#vxlan-gpe");
9242 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9243         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9244                               UINT16);
9245
9246 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9247         .f = cmd_cfg_tunnel_udp_port_parsed,
9248         .data = NULL,
9249         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9250         .tokens = {
9251                 (void *)&cmd_config_tunnel_udp_port_port,
9252                 (void *)&cmd_config_tunnel_udp_port_config,
9253                 (void *)&cmd_config_tunnel_udp_port_port_id,
9254                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9255                 (void *)&cmd_config_tunnel_udp_port_action,
9256                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9257                 (void *)&cmd_config_tunnel_udp_port_value,
9258                 NULL,
9259         },
9260 };
9261
9262 /* *** GLOBAL CONFIG *** */
9263 struct cmd_global_config_result {
9264         cmdline_fixed_string_t cmd;
9265         portid_t port_id;
9266         cmdline_fixed_string_t cfg_type;
9267         uint8_t len;
9268 };
9269
9270 static void
9271 cmd_global_config_parsed(void *parsed_result,
9272                          __rte_unused struct cmdline *cl,
9273                          __rte_unused void *data)
9274 {
9275         struct cmd_global_config_result *res = parsed_result;
9276         struct rte_eth_global_cfg conf;
9277         int ret;
9278
9279         memset(&conf, 0, sizeof(conf));
9280         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9281         conf.cfg.gre_key_len = res->len;
9282         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9283                                       RTE_ETH_FILTER_SET, &conf);
9284         if (ret != 0)
9285                 printf("Global config error\n");
9286 }
9287
9288 cmdline_parse_token_string_t cmd_global_config_cmd =
9289         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9290                 "global_config");
9291 cmdline_parse_token_num_t cmd_global_config_port_id =
9292         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9293                                UINT16);
9294 cmdline_parse_token_string_t cmd_global_config_type =
9295         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9296                 cfg_type, "gre-key-len");
9297 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9298         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9299                 len, UINT8);
9300
9301 cmdline_parse_inst_t cmd_global_config = {
9302         .f = cmd_global_config_parsed,
9303         .data = (void *)NULL,
9304         .help_str = "global_config <port_id> gre-key-len <key_len>",
9305         .tokens = {
9306                 (void *)&cmd_global_config_cmd,
9307                 (void *)&cmd_global_config_port_id,
9308                 (void *)&cmd_global_config_type,
9309                 (void *)&cmd_global_config_gre_key_len,
9310                 NULL,
9311         },
9312 };
9313
9314 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9315 struct cmd_set_mirror_mask_result {
9316         cmdline_fixed_string_t set;
9317         cmdline_fixed_string_t port;
9318         portid_t port_id;
9319         cmdline_fixed_string_t mirror;
9320         uint8_t rule_id;
9321         cmdline_fixed_string_t what;
9322         cmdline_fixed_string_t value;
9323         cmdline_fixed_string_t dstpool;
9324         uint8_t dstpool_id;
9325         cmdline_fixed_string_t on;
9326 };
9327
9328 cmdline_parse_token_string_t cmd_mirror_mask_set =
9329         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9330                                 set, "set");
9331 cmdline_parse_token_string_t cmd_mirror_mask_port =
9332         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9333                                 port, "port");
9334 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9335         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9336                                 port_id, UINT16);
9337 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9338         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9339                                 mirror, "mirror-rule");
9340 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9341         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9342                                 rule_id, UINT8);
9343 cmdline_parse_token_string_t cmd_mirror_mask_what =
9344         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9345                                 what, "pool-mirror-up#pool-mirror-down"
9346                                       "#vlan-mirror");
9347 cmdline_parse_token_string_t cmd_mirror_mask_value =
9348         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9349                                 value, NULL);
9350 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9351         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9352                                 dstpool, "dst-pool");
9353 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9354         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9355                                 dstpool_id, UINT8);
9356 cmdline_parse_token_string_t cmd_mirror_mask_on =
9357         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9358                                 on, "on#off");
9359
9360 static void
9361 cmd_set_mirror_mask_parsed(void *parsed_result,
9362                        __rte_unused struct cmdline *cl,
9363                        __rte_unused void *data)
9364 {
9365         int ret,nb_item,i;
9366         struct cmd_set_mirror_mask_result *res = parsed_result;
9367         struct rte_eth_mirror_conf mr_conf;
9368
9369         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9370
9371         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9372
9373         mr_conf.dst_pool = res->dstpool_id;
9374
9375         if (!strcmp(res->what, "pool-mirror-up")) {
9376                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9377                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9378         } else if (!strcmp(res->what, "pool-mirror-down")) {
9379                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9380                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9381         } else if (!strcmp(res->what, "vlan-mirror")) {
9382                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9383                 nb_item = parse_item_list(res->value, "vlan",
9384                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9385                 if (nb_item <= 0)
9386                         return;
9387
9388                 for (i = 0; i < nb_item; i++) {
9389                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9390                                 printf("Invalid vlan_id: must be < 4096\n");
9391                                 return;
9392                         }
9393
9394                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9395                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9396                 }
9397         }
9398
9399         if (!strcmp(res->on, "on"))
9400                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9401                                                 res->rule_id, 1);
9402         else
9403                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9404                                                 res->rule_id, 0);
9405         if (ret < 0)
9406                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9407 }
9408
9409 cmdline_parse_inst_t cmd_set_mirror_mask = {
9410                 .f = cmd_set_mirror_mask_parsed,
9411                 .data = NULL,
9412                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9413                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9414                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9415                 .tokens = {
9416                         (void *)&cmd_mirror_mask_set,
9417                         (void *)&cmd_mirror_mask_port,
9418                         (void *)&cmd_mirror_mask_portid,
9419                         (void *)&cmd_mirror_mask_mirror,
9420                         (void *)&cmd_mirror_mask_ruleid,
9421                         (void *)&cmd_mirror_mask_what,
9422                         (void *)&cmd_mirror_mask_value,
9423                         (void *)&cmd_mirror_mask_dstpool,
9424                         (void *)&cmd_mirror_mask_poolid,
9425                         (void *)&cmd_mirror_mask_on,
9426                         NULL,
9427                 },
9428 };
9429
9430 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9431 struct cmd_set_mirror_link_result {
9432         cmdline_fixed_string_t set;
9433         cmdline_fixed_string_t port;
9434         portid_t port_id;
9435         cmdline_fixed_string_t mirror;
9436         uint8_t rule_id;
9437         cmdline_fixed_string_t what;
9438         cmdline_fixed_string_t dstpool;
9439         uint8_t dstpool_id;
9440         cmdline_fixed_string_t on;
9441 };
9442
9443 cmdline_parse_token_string_t cmd_mirror_link_set =
9444         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9445                                  set, "set");
9446 cmdline_parse_token_string_t cmd_mirror_link_port =
9447         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9448                                 port, "port");
9449 cmdline_parse_token_num_t cmd_mirror_link_portid =
9450         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9451                                 port_id, UINT16);
9452 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9453         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9454                                 mirror, "mirror-rule");
9455 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9456         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9457                             rule_id, UINT8);
9458 cmdline_parse_token_string_t cmd_mirror_link_what =
9459         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9460                                 what, "uplink-mirror#downlink-mirror");
9461 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9462         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9463                                 dstpool, "dst-pool");
9464 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9465         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9466                                 dstpool_id, UINT8);
9467 cmdline_parse_token_string_t cmd_mirror_link_on =
9468         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9469                                 on, "on#off");
9470
9471 static void
9472 cmd_set_mirror_link_parsed(void *parsed_result,
9473                        __rte_unused struct cmdline *cl,
9474                        __rte_unused void *data)
9475 {
9476         int ret;
9477         struct cmd_set_mirror_link_result *res = parsed_result;
9478         struct rte_eth_mirror_conf mr_conf;
9479
9480         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9481         if (!strcmp(res->what, "uplink-mirror"))
9482                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9483         else
9484                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9485
9486         mr_conf.dst_pool = res->dstpool_id;
9487
9488         if (!strcmp(res->on, "on"))
9489                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9490                                                 res->rule_id, 1);
9491         else
9492                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9493                                                 res->rule_id, 0);
9494
9495         /* check the return value and print it if is < 0 */
9496         if (ret < 0)
9497                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9498
9499 }
9500
9501 cmdline_parse_inst_t cmd_set_mirror_link = {
9502                 .f = cmd_set_mirror_link_parsed,
9503                 .data = NULL,
9504                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9505                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9506                 .tokens = {
9507                         (void *)&cmd_mirror_link_set,
9508                         (void *)&cmd_mirror_link_port,
9509                         (void *)&cmd_mirror_link_portid,
9510                         (void *)&cmd_mirror_link_mirror,
9511                         (void *)&cmd_mirror_link_ruleid,
9512                         (void *)&cmd_mirror_link_what,
9513                         (void *)&cmd_mirror_link_dstpool,
9514                         (void *)&cmd_mirror_link_poolid,
9515                         (void *)&cmd_mirror_link_on,
9516                         NULL,
9517                 },
9518 };
9519
9520 /* *** RESET VM MIRROR RULE *** */
9521 struct cmd_rm_mirror_rule_result {
9522         cmdline_fixed_string_t reset;
9523         cmdline_fixed_string_t port;
9524         portid_t port_id;
9525         cmdline_fixed_string_t mirror;
9526         uint8_t rule_id;
9527 };
9528
9529 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9530         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9531                                  reset, "reset");
9532 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9533         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9534                                 port, "port");
9535 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9536         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9537                                 port_id, UINT16);
9538 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9539         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9540                                 mirror, "mirror-rule");
9541 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9542         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9543                                 rule_id, UINT8);
9544
9545 static void
9546 cmd_reset_mirror_rule_parsed(void *parsed_result,
9547                        __rte_unused struct cmdline *cl,
9548                        __rte_unused void *data)
9549 {
9550         int ret;
9551         struct cmd_set_mirror_link_result *res = parsed_result;
9552         /* check rule_id */
9553         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9554         if(ret < 0)
9555                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9556 }
9557
9558 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9559                 .f = cmd_reset_mirror_rule_parsed,
9560                 .data = NULL,
9561                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9562                 .tokens = {
9563                         (void *)&cmd_rm_mirror_rule_reset,
9564                         (void *)&cmd_rm_mirror_rule_port,
9565                         (void *)&cmd_rm_mirror_rule_portid,
9566                         (void *)&cmd_rm_mirror_rule_mirror,
9567                         (void *)&cmd_rm_mirror_rule_ruleid,
9568                         NULL,
9569                 },
9570 };
9571
9572 /* ******************************************************************************** */
9573
9574 struct cmd_dump_result {
9575         cmdline_fixed_string_t dump;
9576 };
9577
9578 static void
9579 dump_struct_sizes(void)
9580 {
9581 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9582         DUMP_SIZE(struct rte_mbuf);
9583         DUMP_SIZE(struct rte_mempool);
9584         DUMP_SIZE(struct rte_ring);
9585 #undef DUMP_SIZE
9586 }
9587
9588
9589 /* Dump the socket memory statistics on console */
9590 static void
9591 dump_socket_mem(FILE *f)
9592 {
9593         struct rte_malloc_socket_stats socket_stats;
9594         unsigned int i;
9595         size_t total = 0;
9596         size_t alloc = 0;
9597         size_t free = 0;
9598         unsigned int n_alloc = 0;
9599         unsigned int n_free = 0;
9600         static size_t last_allocs;
9601         static size_t last_total;
9602
9603
9604         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9605                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9606                     !socket_stats.heap_totalsz_bytes)
9607                         continue;
9608                 total += socket_stats.heap_totalsz_bytes;
9609                 alloc += socket_stats.heap_allocsz_bytes;
9610                 free += socket_stats.heap_freesz_bytes;
9611                 n_alloc += socket_stats.alloc_count;
9612                 n_free += socket_stats.free_count;
9613                 fprintf(f,
9614                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9615                         i,
9616                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9617                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9618                         (double)socket_stats.heap_allocsz_bytes * 100 /
9619                         (double)socket_stats.heap_totalsz_bytes,
9620                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9621                         socket_stats.alloc_count,
9622                         socket_stats.free_count);
9623         }
9624         fprintf(f,
9625                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9626                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9627                 (double)alloc * 100 / (double)total,
9628                 (double)free / (1024 * 1024),
9629                 n_alloc, n_free);
9630         if (last_allocs)
9631                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9632                         ((double)total - (double)last_total) / (1024 * 1024),
9633                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9634         last_allocs = alloc;
9635         last_total = total;
9636 }
9637
9638 static void cmd_dump_parsed(void *parsed_result,
9639                             __rte_unused struct cmdline *cl,
9640                             __rte_unused void *data)
9641 {
9642         struct cmd_dump_result *res = parsed_result;
9643
9644         if (!strcmp(res->dump, "dump_physmem"))
9645                 rte_dump_physmem_layout(stdout);
9646         else if (!strcmp(res->dump, "dump_socket_mem"))
9647                 dump_socket_mem(stdout);
9648         else if (!strcmp(res->dump, "dump_memzone"))
9649                 rte_memzone_dump(stdout);
9650         else if (!strcmp(res->dump, "dump_struct_sizes"))
9651                 dump_struct_sizes();
9652         else if (!strcmp(res->dump, "dump_ring"))
9653                 rte_ring_list_dump(stdout);
9654         else if (!strcmp(res->dump, "dump_mempool"))
9655                 rte_mempool_list_dump(stdout);
9656         else if (!strcmp(res->dump, "dump_devargs"))
9657                 rte_devargs_dump(stdout);
9658         else if (!strcmp(res->dump, "dump_log_types"))
9659                 rte_log_dump(stdout);
9660 }
9661
9662 cmdline_parse_token_string_t cmd_dump_dump =
9663         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9664                 "dump_physmem#"
9665                 "dump_memzone#"
9666                 "dump_socket_mem#"
9667                 "dump_struct_sizes#"
9668                 "dump_ring#"
9669                 "dump_mempool#"
9670                 "dump_devargs#"
9671                 "dump_log_types");
9672
9673 cmdline_parse_inst_t cmd_dump = {
9674         .f = cmd_dump_parsed,  /* function to call */
9675         .data = NULL,      /* 2nd arg of func */
9676         .help_str = "Dump status",
9677         .tokens = {        /* token list, NULL terminated */
9678                 (void *)&cmd_dump_dump,
9679                 NULL,
9680         },
9681 };
9682
9683 /* ******************************************************************************** */
9684
9685 struct cmd_dump_one_result {
9686         cmdline_fixed_string_t dump;
9687         cmdline_fixed_string_t name;
9688 };
9689
9690 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9691                                 __rte_unused void *data)
9692 {
9693         struct cmd_dump_one_result *res = parsed_result;
9694
9695         if (!strcmp(res->dump, "dump_ring")) {
9696                 struct rte_ring *r;
9697                 r = rte_ring_lookup(res->name);
9698                 if (r == NULL) {
9699                         cmdline_printf(cl, "Cannot find ring\n");
9700                         return;
9701                 }
9702                 rte_ring_dump(stdout, r);
9703         } else if (!strcmp(res->dump, "dump_mempool")) {
9704                 struct rte_mempool *mp;
9705                 mp = rte_mempool_lookup(res->name);
9706                 if (mp == NULL) {
9707                         cmdline_printf(cl, "Cannot find mempool\n");
9708                         return;
9709                 }
9710                 rte_mempool_dump(stdout, mp);
9711         }
9712 }
9713
9714 cmdline_parse_token_string_t cmd_dump_one_dump =
9715         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9716                                  "dump_ring#dump_mempool");
9717
9718 cmdline_parse_token_string_t cmd_dump_one_name =
9719         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9720
9721 cmdline_parse_inst_t cmd_dump_one = {
9722         .f = cmd_dump_one_parsed,  /* function to call */
9723         .data = NULL,      /* 2nd arg of func */
9724         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9725         .tokens = {        /* token list, NULL terminated */
9726                 (void *)&cmd_dump_one_dump,
9727                 (void *)&cmd_dump_one_name,
9728                 NULL,
9729         },
9730 };
9731
9732 /* *** Add/Del syn filter *** */
9733 struct cmd_syn_filter_result {
9734         cmdline_fixed_string_t filter;
9735         portid_t port_id;
9736         cmdline_fixed_string_t ops;
9737         cmdline_fixed_string_t priority;
9738         cmdline_fixed_string_t high;
9739         cmdline_fixed_string_t queue;
9740         uint16_t queue_id;
9741 };
9742
9743 static void
9744 cmd_syn_filter_parsed(void *parsed_result,
9745                         __rte_unused struct cmdline *cl,
9746                         __rte_unused void *data)
9747 {
9748         struct cmd_syn_filter_result *res = parsed_result;
9749         struct rte_eth_syn_filter syn_filter;
9750         int ret = 0;
9751
9752         ret = rte_eth_dev_filter_supported(res->port_id,
9753                                         RTE_ETH_FILTER_SYN);
9754         if (ret < 0) {
9755                 printf("syn filter is not supported on port %u.\n",
9756                                 res->port_id);
9757                 return;
9758         }
9759
9760         memset(&syn_filter, 0, sizeof(syn_filter));
9761
9762         if (!strcmp(res->ops, "add")) {
9763                 if (!strcmp(res->high, "high"))
9764                         syn_filter.hig_pri = 1;
9765                 else
9766                         syn_filter.hig_pri = 0;
9767
9768                 syn_filter.queue = res->queue_id;
9769                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9770                                                 RTE_ETH_FILTER_SYN,
9771                                                 RTE_ETH_FILTER_ADD,
9772                                                 &syn_filter);
9773         } else
9774                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9775                                                 RTE_ETH_FILTER_SYN,
9776                                                 RTE_ETH_FILTER_DELETE,
9777                                                 &syn_filter);
9778
9779         if (ret < 0)
9780                 printf("syn filter programming error: (%s)\n",
9781                                 strerror(-ret));
9782 }
9783
9784 cmdline_parse_token_string_t cmd_syn_filter_filter =
9785         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9786         filter, "syn_filter");
9787 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9788         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9789         port_id, UINT16);
9790 cmdline_parse_token_string_t cmd_syn_filter_ops =
9791         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9792         ops, "add#del");
9793 cmdline_parse_token_string_t cmd_syn_filter_priority =
9794         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9795                                 priority, "priority");
9796 cmdline_parse_token_string_t cmd_syn_filter_high =
9797         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9798                                 high, "high#low");
9799 cmdline_parse_token_string_t cmd_syn_filter_queue =
9800         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9801                                 queue, "queue");
9802 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9803         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9804                                 queue_id, UINT16);
9805
9806 cmdline_parse_inst_t cmd_syn_filter = {
9807         .f = cmd_syn_filter_parsed,
9808         .data = NULL,
9809         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9810                 "<queue_id>: Add/Delete syn filter",
9811         .tokens = {
9812                 (void *)&cmd_syn_filter_filter,
9813                 (void *)&cmd_syn_filter_port_id,
9814                 (void *)&cmd_syn_filter_ops,
9815                 (void *)&cmd_syn_filter_priority,
9816                 (void *)&cmd_syn_filter_high,
9817                 (void *)&cmd_syn_filter_queue,
9818                 (void *)&cmd_syn_filter_queue_id,
9819                 NULL,
9820         },
9821 };
9822
9823 /* *** queue region set *** */
9824 struct cmd_queue_region_result {
9825         cmdline_fixed_string_t set;
9826         cmdline_fixed_string_t port;
9827         portid_t port_id;
9828         cmdline_fixed_string_t cmd;
9829         cmdline_fixed_string_t region;
9830         uint8_t  region_id;
9831         cmdline_fixed_string_t queue_start_index;
9832         uint8_t  queue_id;
9833         cmdline_fixed_string_t queue_num;
9834         uint8_t  queue_num_value;
9835 };
9836
9837 static void
9838 cmd_queue_region_parsed(void *parsed_result,
9839                         __rte_unused struct cmdline *cl,
9840                         __rte_unused void *data)
9841 {
9842         struct cmd_queue_region_result *res = parsed_result;
9843         int ret = -ENOTSUP;
9844 #ifdef RTE_LIBRTE_I40E_PMD
9845         struct rte_pmd_i40e_queue_region_conf region_conf;
9846         enum rte_pmd_i40e_queue_region_op op_type;
9847 #endif
9848
9849         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9850                 return;
9851
9852 #ifdef RTE_LIBRTE_I40E_PMD
9853         memset(&region_conf, 0, sizeof(region_conf));
9854         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9855         region_conf.region_id = res->region_id;
9856         region_conf.queue_num = res->queue_num_value;
9857         region_conf.queue_start_index = res->queue_id;
9858
9859         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9860                                 op_type, &region_conf);
9861 #endif
9862
9863         switch (ret) {
9864         case 0:
9865                 break;
9866         case -ENOTSUP:
9867                 printf("function not implemented or supported\n");
9868                 break;
9869         default:
9870                 printf("queue region config error: (%s)\n", strerror(-ret));
9871         }
9872 }
9873
9874 cmdline_parse_token_string_t cmd_queue_region_set =
9875 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9876                 set, "set");
9877 cmdline_parse_token_string_t cmd_queue_region_port =
9878         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9879 cmdline_parse_token_num_t cmd_queue_region_port_id =
9880         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9881                                 port_id, UINT16);
9882 cmdline_parse_token_string_t cmd_queue_region_cmd =
9883         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9884                                  cmd, "queue-region");
9885 cmdline_parse_token_string_t cmd_queue_region_id =
9886         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9887                                 region, "region_id");
9888 cmdline_parse_token_num_t cmd_queue_region_index =
9889         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9890                                 region_id, UINT8);
9891 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9892         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9893                                 queue_start_index, "queue_start_index");
9894 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9895         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9896                                 queue_id, UINT8);
9897 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9898         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9899                                 queue_num, "queue_num");
9900 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9901         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9902                                 queue_num_value, UINT8);
9903
9904 cmdline_parse_inst_t cmd_queue_region = {
9905         .f = cmd_queue_region_parsed,
9906         .data = NULL,
9907         .help_str = "set port <port_id> queue-region region_id <value> "
9908                 "queue_start_index <value> queue_num <value>: Set a queue region",
9909         .tokens = {
9910                 (void *)&cmd_queue_region_set,
9911                 (void *)&cmd_queue_region_port,
9912                 (void *)&cmd_queue_region_port_id,
9913                 (void *)&cmd_queue_region_cmd,
9914                 (void *)&cmd_queue_region_id,
9915                 (void *)&cmd_queue_region_index,
9916                 (void *)&cmd_queue_region_queue_start_index,
9917                 (void *)&cmd_queue_region_queue_id,
9918                 (void *)&cmd_queue_region_queue_num,
9919                 (void *)&cmd_queue_region_queue_num_value,
9920                 NULL,
9921         },
9922 };
9923
9924 /* *** queue region and flowtype set *** */
9925 struct cmd_region_flowtype_result {
9926         cmdline_fixed_string_t set;
9927         cmdline_fixed_string_t port;
9928         portid_t port_id;
9929         cmdline_fixed_string_t cmd;
9930         cmdline_fixed_string_t region;
9931         uint8_t  region_id;
9932         cmdline_fixed_string_t flowtype;
9933         uint8_t  flowtype_id;
9934 };
9935
9936 static void
9937 cmd_region_flowtype_parsed(void *parsed_result,
9938                         __rte_unused struct cmdline *cl,
9939                         __rte_unused void *data)
9940 {
9941         struct cmd_region_flowtype_result *res = parsed_result;
9942         int ret = -ENOTSUP;
9943 #ifdef RTE_LIBRTE_I40E_PMD
9944         struct rte_pmd_i40e_queue_region_conf region_conf;
9945         enum rte_pmd_i40e_queue_region_op op_type;
9946 #endif
9947
9948         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9949                 return;
9950
9951 #ifdef RTE_LIBRTE_I40E_PMD
9952         memset(&region_conf, 0, sizeof(region_conf));
9953
9954         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9955         region_conf.region_id = res->region_id;
9956         region_conf.hw_flowtype = res->flowtype_id;
9957
9958         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9959                         op_type, &region_conf);
9960 #endif
9961
9962         switch (ret) {
9963         case 0:
9964                 break;
9965         case -ENOTSUP:
9966                 printf("function not implemented or supported\n");
9967                 break;
9968         default:
9969                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9970         }
9971 }
9972
9973 cmdline_parse_token_string_t cmd_region_flowtype_set =
9974 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9975                                 set, "set");
9976 cmdline_parse_token_string_t cmd_region_flowtype_port =
9977         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9978                                 port, "port");
9979 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9980         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9981                                 port_id, UINT16);
9982 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9983         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9984                                 cmd, "queue-region");
9985 cmdline_parse_token_string_t cmd_region_flowtype_index =
9986         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9987                                 region, "region_id");
9988 cmdline_parse_token_num_t cmd_region_flowtype_id =
9989         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9990                                 region_id, UINT8);
9991 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9992         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9993                                 flowtype, "flowtype");
9994 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9995         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9996                                 flowtype_id, UINT8);
9997 cmdline_parse_inst_t cmd_region_flowtype = {
9998         .f = cmd_region_flowtype_parsed,
9999         .data = NULL,
10000         .help_str = "set port <port_id> queue-region region_id <value> "
10001                 "flowtype <value>: Set a flowtype region index",
10002         .tokens = {
10003                 (void *)&cmd_region_flowtype_set,
10004                 (void *)&cmd_region_flowtype_port,
10005                 (void *)&cmd_region_flowtype_port_index,
10006                 (void *)&cmd_region_flowtype_cmd,
10007                 (void *)&cmd_region_flowtype_index,
10008                 (void *)&cmd_region_flowtype_id,
10009                 (void *)&cmd_region_flowtype_flow_index,
10010                 (void *)&cmd_region_flowtype_flow_id,
10011                 NULL,
10012         },
10013 };
10014
10015 /* *** User Priority (UP) to queue region (region_id) set *** */
10016 struct cmd_user_priority_region_result {
10017         cmdline_fixed_string_t set;
10018         cmdline_fixed_string_t port;
10019         portid_t port_id;
10020         cmdline_fixed_string_t cmd;
10021         cmdline_fixed_string_t user_priority;
10022         uint8_t  user_priority_id;
10023         cmdline_fixed_string_t region;
10024         uint8_t  region_id;
10025 };
10026
10027 static void
10028 cmd_user_priority_region_parsed(void *parsed_result,
10029                         __rte_unused struct cmdline *cl,
10030                         __rte_unused void *data)
10031 {
10032         struct cmd_user_priority_region_result *res = parsed_result;
10033         int ret = -ENOTSUP;
10034 #ifdef RTE_LIBRTE_I40E_PMD
10035         struct rte_pmd_i40e_queue_region_conf region_conf;
10036         enum rte_pmd_i40e_queue_region_op op_type;
10037 #endif
10038
10039         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10040                 return;
10041
10042 #ifdef RTE_LIBRTE_I40E_PMD
10043         memset(&region_conf, 0, sizeof(region_conf));
10044         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10045         region_conf.user_priority = res->user_priority_id;
10046         region_conf.region_id = res->region_id;
10047
10048         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10049                                 op_type, &region_conf);
10050 #endif
10051
10052         switch (ret) {
10053         case 0:
10054                 break;
10055         case -ENOTSUP:
10056                 printf("function not implemented or supported\n");
10057                 break;
10058         default:
10059                 printf("user_priority region config error: (%s)\n",
10060                                 strerror(-ret));
10061         }
10062 }
10063
10064 cmdline_parse_token_string_t cmd_user_priority_region_set =
10065         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10066                                 set, "set");
10067 cmdline_parse_token_string_t cmd_user_priority_region_port =
10068         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10069                                 port, "port");
10070 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10071         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10072                                 port_id, UINT16);
10073 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10074         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10075                                 cmd, "queue-region");
10076 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10077         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10078                                 user_priority, "UP");
10079 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10080         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10081                                 user_priority_id, UINT8);
10082 cmdline_parse_token_string_t cmd_user_priority_region_region =
10083         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10084                                 region, "region_id");
10085 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10086         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10087                                 region_id, UINT8);
10088
10089 cmdline_parse_inst_t cmd_user_priority_region = {
10090         .f = cmd_user_priority_region_parsed,
10091         .data = NULL,
10092         .help_str = "set port <port_id> queue-region UP <value> "
10093                 "region_id <value>: Set the mapping of User Priority (UP) "
10094                 "to queue region (region_id) ",
10095         .tokens = {
10096                 (void *)&cmd_user_priority_region_set,
10097                 (void *)&cmd_user_priority_region_port,
10098                 (void *)&cmd_user_priority_region_port_index,
10099                 (void *)&cmd_user_priority_region_cmd,
10100                 (void *)&cmd_user_priority_region_UP,
10101                 (void *)&cmd_user_priority_region_UP_id,
10102                 (void *)&cmd_user_priority_region_region,
10103                 (void *)&cmd_user_priority_region_region_id,
10104                 NULL,
10105         },
10106 };
10107
10108 /* *** flush all queue region related configuration *** */
10109 struct cmd_flush_queue_region_result {
10110         cmdline_fixed_string_t set;
10111         cmdline_fixed_string_t port;
10112         portid_t port_id;
10113         cmdline_fixed_string_t cmd;
10114         cmdline_fixed_string_t flush;
10115         cmdline_fixed_string_t what;
10116 };
10117
10118 static void
10119 cmd_flush_queue_region_parsed(void *parsed_result,
10120                         __rte_unused struct cmdline *cl,
10121                         __rte_unused void *data)
10122 {
10123         struct cmd_flush_queue_region_result *res = parsed_result;
10124         int ret = -ENOTSUP;
10125 #ifdef RTE_LIBRTE_I40E_PMD
10126         struct rte_pmd_i40e_queue_region_conf region_conf;
10127         enum rte_pmd_i40e_queue_region_op op_type;
10128 #endif
10129
10130         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10131                 return;
10132
10133 #ifdef RTE_LIBRTE_I40E_PMD
10134         memset(&region_conf, 0, sizeof(region_conf));
10135
10136         if (strcmp(res->what, "on") == 0)
10137                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10138         else
10139                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10140
10141         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10142                                 op_type, &region_conf);
10143 #endif
10144
10145         switch (ret) {
10146         case 0:
10147                 break;
10148         case -ENOTSUP:
10149                 printf("function not implemented or supported\n");
10150                 break;
10151         default:
10152                 printf("queue region config flush error: (%s)\n",
10153                                 strerror(-ret));
10154         }
10155 }
10156
10157 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10158         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10159                                 set, "set");
10160 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10161         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10162                                 port, "port");
10163 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10164         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10165                                 port_id, UINT16);
10166 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10167         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10168                                 cmd, "queue-region");
10169 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10170         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10171                                 flush, "flush");
10172 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10173         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10174                                 what, "on#off");
10175
10176 cmdline_parse_inst_t cmd_flush_queue_region = {
10177         .f = cmd_flush_queue_region_parsed,
10178         .data = NULL,
10179         .help_str = "set port <port_id> queue-region flush on|off"
10180                 ": flush all queue region related configuration",
10181         .tokens = {
10182                 (void *)&cmd_flush_queue_region_set,
10183                 (void *)&cmd_flush_queue_region_port,
10184                 (void *)&cmd_flush_queue_region_port_index,
10185                 (void *)&cmd_flush_queue_region_cmd,
10186                 (void *)&cmd_flush_queue_region_flush,
10187                 (void *)&cmd_flush_queue_region_what,
10188                 NULL,
10189         },
10190 };
10191
10192 /* *** get all queue region related configuration info *** */
10193 struct cmd_show_queue_region_info {
10194         cmdline_fixed_string_t show;
10195         cmdline_fixed_string_t port;
10196         portid_t port_id;
10197         cmdline_fixed_string_t cmd;
10198 };
10199
10200 static void
10201 cmd_show_queue_region_info_parsed(void *parsed_result,
10202                         __rte_unused struct cmdline *cl,
10203                         __rte_unused void *data)
10204 {
10205         struct cmd_show_queue_region_info *res = parsed_result;
10206         int ret = -ENOTSUP;
10207 #ifdef RTE_LIBRTE_I40E_PMD
10208         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10209         enum rte_pmd_i40e_queue_region_op op_type;
10210 #endif
10211
10212         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10213                 return;
10214
10215 #ifdef RTE_LIBRTE_I40E_PMD
10216         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10217
10218         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10219
10220         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10221                                         op_type, &rte_pmd_regions);
10222
10223         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10224 #endif
10225
10226         switch (ret) {
10227         case 0:
10228                 break;
10229         case -ENOTSUP:
10230                 printf("function not implemented or supported\n");
10231                 break;
10232         default:
10233                 printf("queue region config info show error: (%s)\n",
10234                                 strerror(-ret));
10235         }
10236 }
10237
10238 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10239 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10240                                 show, "show");
10241 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10242         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10243                                 port, "port");
10244 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10245         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10246                                 port_id, UINT16);
10247 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10248         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10249                                 cmd, "queue-region");
10250
10251 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10252         .f = cmd_show_queue_region_info_parsed,
10253         .data = NULL,
10254         .help_str = "show port <port_id> queue-region"
10255                 ": show all queue region related configuration info",
10256         .tokens = {
10257                 (void *)&cmd_show_queue_region_info_get,
10258                 (void *)&cmd_show_queue_region_info_port,
10259                 (void *)&cmd_show_queue_region_info_port_index,
10260                 (void *)&cmd_show_queue_region_info_cmd,
10261                 NULL,
10262         },
10263 };
10264
10265 /* *** ADD/REMOVE A 2tuple FILTER *** */
10266 struct cmd_2tuple_filter_result {
10267         cmdline_fixed_string_t filter;
10268         portid_t port_id;
10269         cmdline_fixed_string_t ops;
10270         cmdline_fixed_string_t dst_port;
10271         uint16_t dst_port_value;
10272         cmdline_fixed_string_t protocol;
10273         uint8_t protocol_value;
10274         cmdline_fixed_string_t mask;
10275         uint8_t  mask_value;
10276         cmdline_fixed_string_t tcp_flags;
10277         uint8_t tcp_flags_value;
10278         cmdline_fixed_string_t priority;
10279         uint8_t  priority_value;
10280         cmdline_fixed_string_t queue;
10281         uint16_t  queue_id;
10282 };
10283
10284 static void
10285 cmd_2tuple_filter_parsed(void *parsed_result,
10286                         __rte_unused struct cmdline *cl,
10287                         __rte_unused void *data)
10288 {
10289         struct rte_eth_ntuple_filter filter;
10290         struct cmd_2tuple_filter_result *res = parsed_result;
10291         int ret = 0;
10292
10293         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10294         if (ret < 0) {
10295                 printf("ntuple filter is not supported on port %u.\n",
10296                         res->port_id);
10297                 return;
10298         }
10299
10300         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10301
10302         filter.flags = RTE_2TUPLE_FLAGS;
10303         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10304         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10305         filter.proto = res->protocol_value;
10306         filter.priority = res->priority_value;
10307         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10308                 printf("nonzero tcp_flags is only meaningful"
10309                         " when protocol is TCP.\n");
10310                 return;
10311         }
10312         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10313                 printf("invalid TCP flags.\n");
10314                 return;
10315         }
10316
10317         if (res->tcp_flags_value != 0) {
10318                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10319                 filter.tcp_flags = res->tcp_flags_value;
10320         }
10321
10322         /* need convert to big endian. */
10323         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10324         filter.queue = res->queue_id;
10325
10326         if (!strcmp(res->ops, "add"))
10327                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10328                                 RTE_ETH_FILTER_NTUPLE,
10329                                 RTE_ETH_FILTER_ADD,
10330                                 &filter);
10331         else
10332                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10333                                 RTE_ETH_FILTER_NTUPLE,
10334                                 RTE_ETH_FILTER_DELETE,
10335                                 &filter);
10336         if (ret < 0)
10337                 printf("2tuple filter programming error: (%s)\n",
10338                         strerror(-ret));
10339
10340 }
10341
10342 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10343         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10344                                  filter, "2tuple_filter");
10345 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10346         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10347                                 port_id, UINT16);
10348 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10349         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10350                                  ops, "add#del");
10351 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10352         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10353                                 dst_port, "dst_port");
10354 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10355         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10356                                 dst_port_value, UINT16);
10357 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10358         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10359                                 protocol, "protocol");
10360 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10361         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10362                                 protocol_value, UINT8);
10363 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10364         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10365                                 mask, "mask");
10366 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10367         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10368                                 mask_value, INT8);
10369 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10370         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10371                                 tcp_flags, "tcp_flags");
10372 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10373         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10374                                 tcp_flags_value, UINT8);
10375 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10376         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10377                                 priority, "priority");
10378 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10379         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10380                                 priority_value, UINT8);
10381 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10382         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10383                                 queue, "queue");
10384 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10385         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10386                                 queue_id, UINT16);
10387
10388 cmdline_parse_inst_t cmd_2tuple_filter = {
10389         .f = cmd_2tuple_filter_parsed,
10390         .data = NULL,
10391         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10392                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10393                 "<queue_id>: Add a 2tuple filter",
10394         .tokens = {
10395                 (void *)&cmd_2tuple_filter_filter,
10396                 (void *)&cmd_2tuple_filter_port_id,
10397                 (void *)&cmd_2tuple_filter_ops,
10398                 (void *)&cmd_2tuple_filter_dst_port,
10399                 (void *)&cmd_2tuple_filter_dst_port_value,
10400                 (void *)&cmd_2tuple_filter_protocol,
10401                 (void *)&cmd_2tuple_filter_protocol_value,
10402                 (void *)&cmd_2tuple_filter_mask,
10403                 (void *)&cmd_2tuple_filter_mask_value,
10404                 (void *)&cmd_2tuple_filter_tcp_flags,
10405                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10406                 (void *)&cmd_2tuple_filter_priority,
10407                 (void *)&cmd_2tuple_filter_priority_value,
10408                 (void *)&cmd_2tuple_filter_queue,
10409                 (void *)&cmd_2tuple_filter_queue_id,
10410                 NULL,
10411         },
10412 };
10413
10414 /* *** ADD/REMOVE A 5tuple FILTER *** */
10415 struct cmd_5tuple_filter_result {
10416         cmdline_fixed_string_t filter;
10417         portid_t port_id;
10418         cmdline_fixed_string_t ops;
10419         cmdline_fixed_string_t dst_ip;
10420         cmdline_ipaddr_t dst_ip_value;
10421         cmdline_fixed_string_t src_ip;
10422         cmdline_ipaddr_t src_ip_value;
10423         cmdline_fixed_string_t dst_port;
10424         uint16_t dst_port_value;
10425         cmdline_fixed_string_t src_port;
10426         uint16_t src_port_value;
10427         cmdline_fixed_string_t protocol;
10428         uint8_t protocol_value;
10429         cmdline_fixed_string_t mask;
10430         uint8_t  mask_value;
10431         cmdline_fixed_string_t tcp_flags;
10432         uint8_t tcp_flags_value;
10433         cmdline_fixed_string_t priority;
10434         uint8_t  priority_value;
10435         cmdline_fixed_string_t queue;
10436         uint16_t  queue_id;
10437 };
10438
10439 static void
10440 cmd_5tuple_filter_parsed(void *parsed_result,
10441                         __rte_unused struct cmdline *cl,
10442                         __rte_unused void *data)
10443 {
10444         struct rte_eth_ntuple_filter filter;
10445         struct cmd_5tuple_filter_result *res = parsed_result;
10446         int ret = 0;
10447
10448         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10449         if (ret < 0) {
10450                 printf("ntuple filter is not supported on port %u.\n",
10451                         res->port_id);
10452                 return;
10453         }
10454
10455         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10456
10457         filter.flags = RTE_5TUPLE_FLAGS;
10458         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10459         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10460         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10461         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10462         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10463         filter.proto = res->protocol_value;
10464         filter.priority = res->priority_value;
10465         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10466                 printf("nonzero tcp_flags is only meaningful"
10467                         " when protocol is TCP.\n");
10468                 return;
10469         }
10470         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10471                 printf("invalid TCP flags.\n");
10472                 return;
10473         }
10474
10475         if (res->tcp_flags_value != 0) {
10476                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10477                 filter.tcp_flags = res->tcp_flags_value;
10478         }
10479
10480         if (res->dst_ip_value.family == AF_INET)
10481                 /* no need to convert, already big endian. */
10482                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10483         else {
10484                 if (filter.dst_ip_mask == 0) {
10485                         printf("can not support ipv6 involved compare.\n");
10486                         return;
10487                 }
10488                 filter.dst_ip = 0;
10489         }
10490
10491         if (res->src_ip_value.family == AF_INET)
10492                 /* no need to convert, already big endian. */
10493                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10494         else {
10495                 if (filter.src_ip_mask == 0) {
10496                         printf("can not support ipv6 involved compare.\n");
10497                         return;
10498                 }
10499                 filter.src_ip = 0;
10500         }
10501         /* need convert to big endian. */
10502         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10503         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10504         filter.queue = res->queue_id;
10505
10506         if (!strcmp(res->ops, "add"))
10507                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10508                                 RTE_ETH_FILTER_NTUPLE,
10509                                 RTE_ETH_FILTER_ADD,
10510                                 &filter);
10511         else
10512                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10513                                 RTE_ETH_FILTER_NTUPLE,
10514                                 RTE_ETH_FILTER_DELETE,
10515                                 &filter);
10516         if (ret < 0)
10517                 printf("5tuple filter programming error: (%s)\n",
10518                         strerror(-ret));
10519 }
10520
10521 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10522         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10523                                  filter, "5tuple_filter");
10524 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10525         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10526                                 port_id, UINT16);
10527 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10528         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10529                                  ops, "add#del");
10530 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10531         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10532                                 dst_ip, "dst_ip");
10533 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10534         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10535                                 dst_ip_value);
10536 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10537         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10538                                 src_ip, "src_ip");
10539 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10540         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10541                                 src_ip_value);
10542 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10543         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10544                                 dst_port, "dst_port");
10545 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10546         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10547                                 dst_port_value, UINT16);
10548 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10549         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10550                                 src_port, "src_port");
10551 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10552         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10553                                 src_port_value, UINT16);
10554 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10555         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10556                                 protocol, "protocol");
10557 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10558         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10559                                 protocol_value, UINT8);
10560 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10561         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10562                                 mask, "mask");
10563 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10564         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10565                                 mask_value, INT8);
10566 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10567         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10568                                 tcp_flags, "tcp_flags");
10569 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10570         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10571                                 tcp_flags_value, UINT8);
10572 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10573         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10574                                 priority, "priority");
10575 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10576         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10577                                 priority_value, UINT8);
10578 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10579         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10580                                 queue, "queue");
10581 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10582         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10583                                 queue_id, UINT16);
10584
10585 cmdline_parse_inst_t cmd_5tuple_filter = {
10586         .f = cmd_5tuple_filter_parsed,
10587         .data = NULL,
10588         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10589                 "src_ip <value> dst_port <value> src_port <value> "
10590                 "protocol <value>  mask <value> tcp_flags <value> "
10591                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10592         .tokens = {
10593                 (void *)&cmd_5tuple_filter_filter,
10594                 (void *)&cmd_5tuple_filter_port_id,
10595                 (void *)&cmd_5tuple_filter_ops,
10596                 (void *)&cmd_5tuple_filter_dst_ip,
10597                 (void *)&cmd_5tuple_filter_dst_ip_value,
10598                 (void *)&cmd_5tuple_filter_src_ip,
10599                 (void *)&cmd_5tuple_filter_src_ip_value,
10600                 (void *)&cmd_5tuple_filter_dst_port,
10601                 (void *)&cmd_5tuple_filter_dst_port_value,
10602                 (void *)&cmd_5tuple_filter_src_port,
10603                 (void *)&cmd_5tuple_filter_src_port_value,
10604                 (void *)&cmd_5tuple_filter_protocol,
10605                 (void *)&cmd_5tuple_filter_protocol_value,
10606                 (void *)&cmd_5tuple_filter_mask,
10607                 (void *)&cmd_5tuple_filter_mask_value,
10608                 (void *)&cmd_5tuple_filter_tcp_flags,
10609                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10610                 (void *)&cmd_5tuple_filter_priority,
10611                 (void *)&cmd_5tuple_filter_priority_value,
10612                 (void *)&cmd_5tuple_filter_queue,
10613                 (void *)&cmd_5tuple_filter_queue_id,
10614                 NULL,
10615         },
10616 };
10617
10618 /* *** ADD/REMOVE A flex FILTER *** */
10619 struct cmd_flex_filter_result {
10620         cmdline_fixed_string_t filter;
10621         cmdline_fixed_string_t ops;
10622         portid_t port_id;
10623         cmdline_fixed_string_t len;
10624         uint8_t len_value;
10625         cmdline_fixed_string_t bytes;
10626         cmdline_fixed_string_t bytes_value;
10627         cmdline_fixed_string_t mask;
10628         cmdline_fixed_string_t mask_value;
10629         cmdline_fixed_string_t priority;
10630         uint8_t priority_value;
10631         cmdline_fixed_string_t queue;
10632         uint16_t queue_id;
10633 };
10634
10635 static int xdigit2val(unsigned char c)
10636 {
10637         int val;
10638         if (isdigit(c))
10639                 val = c - '0';
10640         else if (isupper(c))
10641                 val = c - 'A' + 10;
10642         else
10643                 val = c - 'a' + 10;
10644         return val;
10645 }
10646
10647 static void
10648 cmd_flex_filter_parsed(void *parsed_result,
10649                           __rte_unused struct cmdline *cl,
10650                           __rte_unused void *data)
10651 {
10652         int ret = 0;
10653         struct rte_eth_flex_filter filter;
10654         struct cmd_flex_filter_result *res = parsed_result;
10655         char *bytes_ptr, *mask_ptr;
10656         uint16_t len, i, j = 0;
10657         char c;
10658         int val;
10659         uint8_t byte = 0;
10660
10661         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10662                 printf("the len exceed the max length 128\n");
10663                 return;
10664         }
10665         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10666         filter.len = res->len_value;
10667         filter.priority = res->priority_value;
10668         filter.queue = res->queue_id;
10669         bytes_ptr = res->bytes_value;
10670         mask_ptr = res->mask_value;
10671
10672          /* translate bytes string to array. */
10673         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10674                 (bytes_ptr[1] == 'X')))
10675                 bytes_ptr += 2;
10676         len = strnlen(bytes_ptr, res->len_value * 2);
10677         if (len == 0 || (len % 8 != 0)) {
10678                 printf("please check len and bytes input\n");
10679                 return;
10680         }
10681         for (i = 0; i < len; i++) {
10682                 c = bytes_ptr[i];
10683                 if (isxdigit(c) == 0) {
10684                         /* invalid characters. */
10685                         printf("invalid input\n");
10686                         return;
10687                 }
10688                 val = xdigit2val(c);
10689                 if (i % 2) {
10690                         byte |= val;
10691                         filter.bytes[j] = byte;
10692                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10693                         j++;
10694                         byte = 0;
10695                 } else
10696                         byte |= val << 4;
10697         }
10698         printf("\n");
10699          /* translate mask string to uint8_t array. */
10700         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10701                 (mask_ptr[1] == 'X')))
10702                 mask_ptr += 2;
10703         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10704         if (len == 0) {
10705                 printf("invalid input\n");
10706                 return;
10707         }
10708         j = 0;
10709         byte = 0;
10710         for (i = 0; i < len; i++) {
10711                 c = mask_ptr[i];
10712                 if (isxdigit(c) == 0) {
10713                         /* invalid characters. */
10714                         printf("invalid input\n");
10715                         return;
10716                 }
10717                 val = xdigit2val(c);
10718                 if (i % 2) {
10719                         byte |= val;
10720                         filter.mask[j] = byte;
10721                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10722                         j++;
10723                         byte = 0;
10724                 } else
10725                         byte |= val << 4;
10726         }
10727         printf("\n");
10728
10729         if (!strcmp(res->ops, "add"))
10730                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10731                                 RTE_ETH_FILTER_FLEXIBLE,
10732                                 RTE_ETH_FILTER_ADD,
10733                                 &filter);
10734         else
10735                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10736                                 RTE_ETH_FILTER_FLEXIBLE,
10737                                 RTE_ETH_FILTER_DELETE,
10738                                 &filter);
10739
10740         if (ret < 0)
10741                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10742 }
10743
10744 cmdline_parse_token_string_t cmd_flex_filter_filter =
10745         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10746                                 filter, "flex_filter");
10747 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10748         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10749                                 port_id, UINT16);
10750 cmdline_parse_token_string_t cmd_flex_filter_ops =
10751         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10752                                 ops, "add#del");
10753 cmdline_parse_token_string_t cmd_flex_filter_len =
10754         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10755                                 len, "len");
10756 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10757         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10758                                 len_value, UINT8);
10759 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10760         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10761                                 bytes, "bytes");
10762 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10763         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10764                                 bytes_value, NULL);
10765 cmdline_parse_token_string_t cmd_flex_filter_mask =
10766         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10767                                 mask, "mask");
10768 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10769         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10770                                 mask_value, NULL);
10771 cmdline_parse_token_string_t cmd_flex_filter_priority =
10772         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10773                                 priority, "priority");
10774 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10775         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10776                                 priority_value, UINT8);
10777 cmdline_parse_token_string_t cmd_flex_filter_queue =
10778         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10779                                 queue, "queue");
10780 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10781         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10782                                 queue_id, UINT16);
10783 cmdline_parse_inst_t cmd_flex_filter = {
10784         .f = cmd_flex_filter_parsed,
10785         .data = NULL,
10786         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10787                 "<value> mask <value> priority <value> queue <queue_id>: "
10788                 "Add/Del a flex filter",
10789         .tokens = {
10790                 (void *)&cmd_flex_filter_filter,
10791                 (void *)&cmd_flex_filter_port_id,
10792                 (void *)&cmd_flex_filter_ops,
10793                 (void *)&cmd_flex_filter_len,
10794                 (void *)&cmd_flex_filter_len_value,
10795                 (void *)&cmd_flex_filter_bytes,
10796                 (void *)&cmd_flex_filter_bytes_value,
10797                 (void *)&cmd_flex_filter_mask,
10798                 (void *)&cmd_flex_filter_mask_value,
10799                 (void *)&cmd_flex_filter_priority,
10800                 (void *)&cmd_flex_filter_priority_value,
10801                 (void *)&cmd_flex_filter_queue,
10802                 (void *)&cmd_flex_filter_queue_id,
10803                 NULL,
10804         },
10805 };
10806
10807 /* *** Filters Control *** */
10808
10809 /* *** deal with ethertype filter *** */
10810 struct cmd_ethertype_filter_result {
10811         cmdline_fixed_string_t filter;
10812         portid_t port_id;
10813         cmdline_fixed_string_t ops;
10814         cmdline_fixed_string_t mac;
10815         struct rte_ether_addr mac_addr;
10816         cmdline_fixed_string_t ethertype;
10817         uint16_t ethertype_value;
10818         cmdline_fixed_string_t drop;
10819         cmdline_fixed_string_t queue;
10820         uint16_t  queue_id;
10821 };
10822
10823 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10824         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10825                                  filter, "ethertype_filter");
10826 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10827         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10828                               port_id, UINT16);
10829 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10830         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10831                                  ops, "add#del");
10832 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10833         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10834                                  mac, "mac_addr#mac_ignr");
10835 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10836         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10837                                      mac_addr);
10838 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10839         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10840                                  ethertype, "ethertype");
10841 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10842         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10843                               ethertype_value, UINT16);
10844 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10845         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10846                                  drop, "drop#fwd");
10847 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10848         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10849                                  queue, "queue");
10850 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10851         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10852                               queue_id, UINT16);
10853
10854 static void
10855 cmd_ethertype_filter_parsed(void *parsed_result,
10856                           __rte_unused struct cmdline *cl,
10857                           __rte_unused void *data)
10858 {
10859         struct cmd_ethertype_filter_result *res = parsed_result;
10860         struct rte_eth_ethertype_filter filter;
10861         int ret = 0;
10862
10863         ret = rte_eth_dev_filter_supported(res->port_id,
10864                         RTE_ETH_FILTER_ETHERTYPE);
10865         if (ret < 0) {
10866                 printf("ethertype filter is not supported on port %u.\n",
10867                         res->port_id);
10868                 return;
10869         }
10870
10871         memset(&filter, 0, sizeof(filter));
10872         if (!strcmp(res->mac, "mac_addr")) {
10873                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10874                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10875                         sizeof(struct rte_ether_addr));
10876         }
10877         if (!strcmp(res->drop, "drop"))
10878                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10879         filter.ether_type = res->ethertype_value;
10880         filter.queue = res->queue_id;
10881
10882         if (!strcmp(res->ops, "add"))
10883                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10884                                 RTE_ETH_FILTER_ETHERTYPE,
10885                                 RTE_ETH_FILTER_ADD,
10886                                 &filter);
10887         else
10888                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10889                                 RTE_ETH_FILTER_ETHERTYPE,
10890                                 RTE_ETH_FILTER_DELETE,
10891                                 &filter);
10892         if (ret < 0)
10893                 printf("ethertype filter programming error: (%s)\n",
10894                         strerror(-ret));
10895 }
10896
10897 cmdline_parse_inst_t cmd_ethertype_filter = {
10898         .f = cmd_ethertype_filter_parsed,
10899         .data = NULL,
10900         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10901                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10902                 "Add or delete an ethertype filter entry",
10903         .tokens = {
10904                 (void *)&cmd_ethertype_filter_filter,
10905                 (void *)&cmd_ethertype_filter_port_id,
10906                 (void *)&cmd_ethertype_filter_ops,
10907                 (void *)&cmd_ethertype_filter_mac,
10908                 (void *)&cmd_ethertype_filter_mac_addr,
10909                 (void *)&cmd_ethertype_filter_ethertype,
10910                 (void *)&cmd_ethertype_filter_ethertype_value,
10911                 (void *)&cmd_ethertype_filter_drop,
10912                 (void *)&cmd_ethertype_filter_queue,
10913                 (void *)&cmd_ethertype_filter_queue_id,
10914                 NULL,
10915         },
10916 };
10917
10918 /* *** deal with flow director filter *** */
10919 struct cmd_flow_director_result {
10920         cmdline_fixed_string_t flow_director_filter;
10921         portid_t port_id;
10922         cmdline_fixed_string_t mode;
10923         cmdline_fixed_string_t mode_value;
10924         cmdline_fixed_string_t ops;
10925         cmdline_fixed_string_t flow;
10926         cmdline_fixed_string_t flow_type;
10927         cmdline_fixed_string_t ether;
10928         uint16_t ether_type;
10929         cmdline_fixed_string_t src;
10930         cmdline_ipaddr_t ip_src;
10931         uint16_t port_src;
10932         cmdline_fixed_string_t dst;
10933         cmdline_ipaddr_t ip_dst;
10934         uint16_t port_dst;
10935         cmdline_fixed_string_t verify_tag;
10936         uint32_t verify_tag_value;
10937         cmdline_fixed_string_t tos;
10938         uint8_t tos_value;
10939         cmdline_fixed_string_t proto;
10940         uint8_t proto_value;
10941         cmdline_fixed_string_t ttl;
10942         uint8_t ttl_value;
10943         cmdline_fixed_string_t vlan;
10944         uint16_t vlan_value;
10945         cmdline_fixed_string_t flexbytes;
10946         cmdline_fixed_string_t flexbytes_value;
10947         cmdline_fixed_string_t pf_vf;
10948         cmdline_fixed_string_t drop;
10949         cmdline_fixed_string_t queue;
10950         uint16_t  queue_id;
10951         cmdline_fixed_string_t fd_id;
10952         uint32_t  fd_id_value;
10953         cmdline_fixed_string_t mac;
10954         struct rte_ether_addr mac_addr;
10955         cmdline_fixed_string_t tunnel;
10956         cmdline_fixed_string_t tunnel_type;
10957         cmdline_fixed_string_t tunnel_id;
10958         uint32_t tunnel_id_value;
10959         cmdline_fixed_string_t packet;
10960         char filepath[];
10961 };
10962
10963 static inline int
10964 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10965 {
10966         char s[256];
10967         const char *p, *p0 = q_arg;
10968         char *end;
10969         unsigned long int_fld;
10970         char *str_fld[max_num];
10971         int i;
10972         unsigned size;
10973         int ret = -1;
10974
10975         p = strchr(p0, '(');
10976         if (p == NULL)
10977                 return -1;
10978         ++p;
10979         p0 = strchr(p, ')');
10980         if (p0 == NULL)
10981                 return -1;
10982
10983         size = p0 - p;
10984         if (size >= sizeof(s))
10985                 return -1;
10986
10987         snprintf(s, sizeof(s), "%.*s", size, p);
10988         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10989         if (ret < 0 || ret > max_num)
10990                 return -1;
10991         for (i = 0; i < ret; i++) {
10992                 errno = 0;
10993                 int_fld = strtoul(str_fld[i], &end, 0);
10994                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10995                         return -1;
10996                 flexbytes[i] = (uint8_t)int_fld;
10997         }
10998         return ret;
10999 }
11000
11001 static uint16_t
11002 str2flowtype(char *string)
11003 {
11004         uint8_t i = 0;
11005         static const struct {
11006                 char str[32];
11007                 uint16_t type;
11008         } flowtype_str[] = {
11009                 {"raw", RTE_ETH_FLOW_RAW},
11010                 {"ipv4", RTE_ETH_FLOW_IPV4},
11011                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11012                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11013                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11014                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11015                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11016                 {"ipv6", RTE_ETH_FLOW_IPV6},
11017                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11018                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11019                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11020                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11021                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11022                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11023         };
11024
11025         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11026                 if (!strcmp(flowtype_str[i].str, string))
11027                         return flowtype_str[i].type;
11028         }
11029
11030         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11031                 return (uint16_t)atoi(string);
11032
11033         return RTE_ETH_FLOW_UNKNOWN;
11034 }
11035
11036 static enum rte_eth_fdir_tunnel_type
11037 str2fdir_tunneltype(char *string)
11038 {
11039         uint8_t i = 0;
11040
11041         static const struct {
11042                 char str[32];
11043                 enum rte_eth_fdir_tunnel_type type;
11044         } tunneltype_str[] = {
11045                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11046                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11047         };
11048
11049         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11050                 if (!strcmp(tunneltype_str[i].str, string))
11051                         return tunneltype_str[i].type;
11052         }
11053         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11054 }
11055
11056 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11057 do { \
11058         if ((ip_addr).family == AF_INET) \
11059                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11060         else { \
11061                 printf("invalid parameter.\n"); \
11062                 return; \
11063         } \
11064 } while (0)
11065
11066 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11067 do { \
11068         if ((ip_addr).family == AF_INET6) \
11069                 rte_memcpy(&(ip), \
11070                                  &((ip_addr).addr.ipv6), \
11071                                  sizeof(struct in6_addr)); \
11072         else { \
11073                 printf("invalid parameter.\n"); \
11074                 return; \
11075         } \
11076 } while (0)
11077
11078 static void
11079 cmd_flow_director_filter_parsed(void *parsed_result,
11080                           __rte_unused struct cmdline *cl,
11081                           __rte_unused void *data)
11082 {
11083         struct cmd_flow_director_result *res = parsed_result;
11084         struct rte_eth_fdir_filter entry;
11085         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11086         char *end;
11087         unsigned long vf_id;
11088         int ret = 0;
11089
11090         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11091         if (ret < 0) {
11092                 printf("flow director is not supported on port %u.\n",
11093                         res->port_id);
11094                 return;
11095         }
11096         memset(flexbytes, 0, sizeof(flexbytes));
11097         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11098
11099         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11100                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11101                         printf("Please set mode to MAC-VLAN.\n");
11102                         return;
11103                 }
11104         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11105                 if (strcmp(res->mode_value, "Tunnel")) {
11106                         printf("Please set mode to Tunnel.\n");
11107                         return;
11108                 }
11109         } else {
11110                 if (!strcmp(res->mode_value, "raw")) {
11111 #ifdef RTE_LIBRTE_I40E_PMD
11112                         struct rte_pmd_i40e_flow_type_mapping
11113                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11114                         struct rte_pmd_i40e_pkt_template_conf conf;
11115                         uint16_t flow_type = str2flowtype(res->flow_type);
11116                         uint16_t i, port = res->port_id;
11117                         uint8_t add;
11118
11119                         memset(&conf, 0, sizeof(conf));
11120
11121                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11122                                 printf("Invalid flow type specified.\n");
11123                                 return;
11124                         }
11125                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11126                                                                  mapping);
11127                         if (ret)
11128                                 return;
11129                         if (mapping[flow_type].pctype == 0ULL) {
11130                                 printf("Invalid flow type specified.\n");
11131                                 return;
11132                         }
11133                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11134                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11135                                         conf.input.pctype = i;
11136                                         break;
11137                                 }
11138                         }
11139
11140                         conf.input.packet = open_file(res->filepath,
11141                                                 &conf.input.length);
11142                         if (!conf.input.packet)
11143                                 return;
11144                         if (!strcmp(res->drop, "drop"))
11145                                 conf.action.behavior =
11146                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11147                         else
11148                                 conf.action.behavior =
11149                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11150                         conf.action.report_status =
11151                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11152                         conf.action.rx_queue = res->queue_id;
11153                         conf.soft_id = res->fd_id_value;
11154                         add  = strcmp(res->ops, "del") ? 1 : 0;
11155                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11156                                                                         &conf,
11157                                                                         add);
11158                         if (ret < 0)
11159                                 printf("flow director config error: (%s)\n",
11160                                        strerror(-ret));
11161                         close_file(conf.input.packet);
11162 #endif
11163                         return;
11164                 } else if (strcmp(res->mode_value, "IP")) {
11165                         printf("Please set mode to IP or raw.\n");
11166                         return;
11167                 }
11168                 entry.input.flow_type = str2flowtype(res->flow_type);
11169         }
11170
11171         ret = parse_flexbytes(res->flexbytes_value,
11172                                         flexbytes,
11173                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11174         if (ret < 0) {
11175                 printf("error: Cannot parse flexbytes input.\n");
11176                 return;
11177         }
11178
11179         switch (entry.input.flow_type) {
11180         case RTE_ETH_FLOW_FRAG_IPV4:
11181         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11182                 entry.input.flow.ip4_flow.proto = res->proto_value;
11183                 /* fall-through */
11184         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11185         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11186                 IPV4_ADDR_TO_UINT(res->ip_dst,
11187                         entry.input.flow.ip4_flow.dst_ip);
11188                 IPV4_ADDR_TO_UINT(res->ip_src,
11189                         entry.input.flow.ip4_flow.src_ip);
11190                 entry.input.flow.ip4_flow.tos = res->tos_value;
11191                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11192                 /* need convert to big endian. */
11193                 entry.input.flow.udp4_flow.dst_port =
11194                                 rte_cpu_to_be_16(res->port_dst);
11195                 entry.input.flow.udp4_flow.src_port =
11196                                 rte_cpu_to_be_16(res->port_src);
11197                 break;
11198         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11199                 IPV4_ADDR_TO_UINT(res->ip_dst,
11200                         entry.input.flow.sctp4_flow.ip.dst_ip);
11201                 IPV4_ADDR_TO_UINT(res->ip_src,
11202                         entry.input.flow.sctp4_flow.ip.src_ip);
11203                 entry.input.flow.ip4_flow.tos = res->tos_value;
11204                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11205                 /* need convert to big endian. */
11206                 entry.input.flow.sctp4_flow.dst_port =
11207                                 rte_cpu_to_be_16(res->port_dst);
11208                 entry.input.flow.sctp4_flow.src_port =
11209                                 rte_cpu_to_be_16(res->port_src);
11210                 entry.input.flow.sctp4_flow.verify_tag =
11211                                 rte_cpu_to_be_32(res->verify_tag_value);
11212                 break;
11213         case RTE_ETH_FLOW_FRAG_IPV6:
11214         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11215                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11216                 /* fall-through */
11217         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11218         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11219                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11220                         entry.input.flow.ipv6_flow.dst_ip);
11221                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11222                         entry.input.flow.ipv6_flow.src_ip);
11223                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11224                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11225                 /* need convert to big endian. */
11226                 entry.input.flow.udp6_flow.dst_port =
11227                                 rte_cpu_to_be_16(res->port_dst);
11228                 entry.input.flow.udp6_flow.src_port =
11229                                 rte_cpu_to_be_16(res->port_src);
11230                 break;
11231         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11232                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11233                         entry.input.flow.sctp6_flow.ip.dst_ip);
11234                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11235                         entry.input.flow.sctp6_flow.ip.src_ip);
11236                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11237                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11238                 /* need convert to big endian. */
11239                 entry.input.flow.sctp6_flow.dst_port =
11240                                 rte_cpu_to_be_16(res->port_dst);
11241                 entry.input.flow.sctp6_flow.src_port =
11242                                 rte_cpu_to_be_16(res->port_src);
11243                 entry.input.flow.sctp6_flow.verify_tag =
11244                                 rte_cpu_to_be_32(res->verify_tag_value);
11245                 break;
11246         case RTE_ETH_FLOW_L2_PAYLOAD:
11247                 entry.input.flow.l2_flow.ether_type =
11248                         rte_cpu_to_be_16(res->ether_type);
11249                 break;
11250         default:
11251                 break;
11252         }
11253
11254         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11255                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11256                                  &res->mac_addr,
11257                                  sizeof(struct rte_ether_addr));
11258
11259         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11260                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11261                                  &res->mac_addr,
11262                                  sizeof(struct rte_ether_addr));
11263                 entry.input.flow.tunnel_flow.tunnel_type =
11264                         str2fdir_tunneltype(res->tunnel_type);
11265                 entry.input.flow.tunnel_flow.tunnel_id =
11266                         rte_cpu_to_be_32(res->tunnel_id_value);
11267         }
11268
11269         rte_memcpy(entry.input.flow_ext.flexbytes,
11270                    flexbytes,
11271                    RTE_ETH_FDIR_MAX_FLEXLEN);
11272
11273         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11274
11275         entry.action.flex_off = 0;  /*use 0 by default */
11276         if (!strcmp(res->drop, "drop"))
11277                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11278         else
11279                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11280
11281         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11282             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11283                 if (!strcmp(res->pf_vf, "pf"))
11284                         entry.input.flow_ext.is_vf = 0;
11285                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11286                         struct rte_eth_dev_info dev_info;
11287
11288                         ret = eth_dev_info_get_print_err(res->port_id,
11289                                                 &dev_info);
11290                         if (ret != 0)
11291                                 return;
11292
11293                         errno = 0;
11294                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11295                         if (errno != 0 || *end != '\0' ||
11296                             vf_id >= dev_info.max_vfs) {
11297                                 printf("invalid parameter %s.\n", res->pf_vf);
11298                                 return;
11299                         }
11300                         entry.input.flow_ext.is_vf = 1;
11301                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11302                 } else {
11303                         printf("invalid parameter %s.\n", res->pf_vf);
11304                         return;
11305                 }
11306         }
11307
11308         /* set to report FD ID by default */
11309         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11310         entry.action.rx_queue = res->queue_id;
11311         entry.soft_id = res->fd_id_value;
11312         if (!strcmp(res->ops, "add"))
11313                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11314                                              RTE_ETH_FILTER_ADD, &entry);
11315         else if (!strcmp(res->ops, "del"))
11316                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11317                                              RTE_ETH_FILTER_DELETE, &entry);
11318         else
11319                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11320                                              RTE_ETH_FILTER_UPDATE, &entry);
11321         if (ret < 0)
11322                 printf("flow director programming error: (%s)\n",
11323                         strerror(-ret));
11324 }
11325
11326 cmdline_parse_token_string_t cmd_flow_director_filter =
11327         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11328                                  flow_director_filter, "flow_director_filter");
11329 cmdline_parse_token_num_t cmd_flow_director_port_id =
11330         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11331                               port_id, UINT16);
11332 cmdline_parse_token_string_t cmd_flow_director_ops =
11333         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11334                                  ops, "add#del#update");
11335 cmdline_parse_token_string_t cmd_flow_director_flow =
11336         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11337                                  flow, "flow");
11338 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11339         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11340                 flow_type, NULL);
11341 cmdline_parse_token_string_t cmd_flow_director_ether =
11342         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11343                                  ether, "ether");
11344 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11345         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11346                               ether_type, UINT16);
11347 cmdline_parse_token_string_t cmd_flow_director_src =
11348         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11349                                  src, "src");
11350 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11351         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11352                                  ip_src);
11353 cmdline_parse_token_num_t cmd_flow_director_port_src =
11354         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11355                               port_src, UINT16);
11356 cmdline_parse_token_string_t cmd_flow_director_dst =
11357         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11358                                  dst, "dst");
11359 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11360         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11361                                  ip_dst);
11362 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11363         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11364                               port_dst, UINT16);
11365 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11366         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11367                                   verify_tag, "verify_tag");
11368 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11369         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11370                               verify_tag_value, UINT32);
11371 cmdline_parse_token_string_t cmd_flow_director_tos =
11372         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11373                                  tos, "tos");
11374 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11375         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11376                               tos_value, UINT8);
11377 cmdline_parse_token_string_t cmd_flow_director_proto =
11378         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11379                                  proto, "proto");
11380 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11381         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11382                               proto_value, UINT8);
11383 cmdline_parse_token_string_t cmd_flow_director_ttl =
11384         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11385                                  ttl, "ttl");
11386 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11387         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11388                               ttl_value, UINT8);
11389 cmdline_parse_token_string_t cmd_flow_director_vlan =
11390         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11391                                  vlan, "vlan");
11392 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11393         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11394                               vlan_value, UINT16);
11395 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11396         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11397                                  flexbytes, "flexbytes");
11398 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11399         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11400                               flexbytes_value, NULL);
11401 cmdline_parse_token_string_t cmd_flow_director_drop =
11402         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11403                                  drop, "drop#fwd");
11404 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11405         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11406                               pf_vf, NULL);
11407 cmdline_parse_token_string_t cmd_flow_director_queue =
11408         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11409                                  queue, "queue");
11410 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11411         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11412                               queue_id, UINT16);
11413 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11414         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11415                                  fd_id, "fd_id");
11416 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11417         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11418                               fd_id_value, UINT32);
11419
11420 cmdline_parse_token_string_t cmd_flow_director_mode =
11421         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11422                                  mode, "mode");
11423 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11424         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11425                                  mode_value, "IP");
11426 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11427         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11428                                  mode_value, "MAC-VLAN");
11429 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11430         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11431                                  mode_value, "Tunnel");
11432 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11433         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11434                                  mode_value, "raw");
11435 cmdline_parse_token_string_t cmd_flow_director_mac =
11436         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11437                                  mac, "mac");
11438 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11439         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11440                                     mac_addr);
11441 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11442         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11443                                  tunnel, "tunnel");
11444 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11445         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11446                                  tunnel_type, "NVGRE#VxLAN");
11447 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11448         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11449                                  tunnel_id, "tunnel-id");
11450 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11451         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11452                               tunnel_id_value, UINT32);
11453 cmdline_parse_token_string_t cmd_flow_director_packet =
11454         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11455                                  packet, "packet");
11456 cmdline_parse_token_string_t cmd_flow_director_filepath =
11457         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11458                                  filepath, NULL);
11459
11460 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11461         .f = cmd_flow_director_filter_parsed,
11462         .data = NULL,
11463         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11464                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11465                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11466                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11467                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11468                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11469                 "fd_id <fd_id_value>: "
11470                 "Add or delete an ip flow director entry on NIC",
11471         .tokens = {
11472                 (void *)&cmd_flow_director_filter,
11473                 (void *)&cmd_flow_director_port_id,
11474                 (void *)&cmd_flow_director_mode,
11475                 (void *)&cmd_flow_director_mode_ip,
11476                 (void *)&cmd_flow_director_ops,
11477                 (void *)&cmd_flow_director_flow,
11478                 (void *)&cmd_flow_director_flow_type,
11479                 (void *)&cmd_flow_director_src,
11480                 (void *)&cmd_flow_director_ip_src,
11481                 (void *)&cmd_flow_director_dst,
11482                 (void *)&cmd_flow_director_ip_dst,
11483                 (void *)&cmd_flow_director_tos,
11484                 (void *)&cmd_flow_director_tos_value,
11485                 (void *)&cmd_flow_director_proto,
11486                 (void *)&cmd_flow_director_proto_value,
11487                 (void *)&cmd_flow_director_ttl,
11488                 (void *)&cmd_flow_director_ttl_value,
11489                 (void *)&cmd_flow_director_vlan,
11490                 (void *)&cmd_flow_director_vlan_value,
11491                 (void *)&cmd_flow_director_flexbytes,
11492                 (void *)&cmd_flow_director_flexbytes_value,
11493                 (void *)&cmd_flow_director_drop,
11494                 (void *)&cmd_flow_director_pf_vf,
11495                 (void *)&cmd_flow_director_queue,
11496                 (void *)&cmd_flow_director_queue_id,
11497                 (void *)&cmd_flow_director_fd_id,
11498                 (void *)&cmd_flow_director_fd_id_value,
11499                 NULL,
11500         },
11501 };
11502
11503 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11504         .f = cmd_flow_director_filter_parsed,
11505         .data = NULL,
11506         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11507                 "director entry on NIC",
11508         .tokens = {
11509                 (void *)&cmd_flow_director_filter,
11510                 (void *)&cmd_flow_director_port_id,
11511                 (void *)&cmd_flow_director_mode,
11512                 (void *)&cmd_flow_director_mode_ip,
11513                 (void *)&cmd_flow_director_ops,
11514                 (void *)&cmd_flow_director_flow,
11515                 (void *)&cmd_flow_director_flow_type,
11516                 (void *)&cmd_flow_director_src,
11517                 (void *)&cmd_flow_director_ip_src,
11518                 (void *)&cmd_flow_director_port_src,
11519                 (void *)&cmd_flow_director_dst,
11520                 (void *)&cmd_flow_director_ip_dst,
11521                 (void *)&cmd_flow_director_port_dst,
11522                 (void *)&cmd_flow_director_tos,
11523                 (void *)&cmd_flow_director_tos_value,
11524                 (void *)&cmd_flow_director_ttl,
11525                 (void *)&cmd_flow_director_ttl_value,
11526                 (void *)&cmd_flow_director_vlan,
11527                 (void *)&cmd_flow_director_vlan_value,
11528                 (void *)&cmd_flow_director_flexbytes,
11529                 (void *)&cmd_flow_director_flexbytes_value,
11530                 (void *)&cmd_flow_director_drop,
11531                 (void *)&cmd_flow_director_pf_vf,
11532                 (void *)&cmd_flow_director_queue,
11533                 (void *)&cmd_flow_director_queue_id,
11534                 (void *)&cmd_flow_director_fd_id,
11535                 (void *)&cmd_flow_director_fd_id_value,
11536                 NULL,
11537         },
11538 };
11539
11540 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11541         .f = cmd_flow_director_filter_parsed,
11542         .data = NULL,
11543         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11544                 "director entry on NIC",
11545         .tokens = {
11546                 (void *)&cmd_flow_director_filter,
11547                 (void *)&cmd_flow_director_port_id,
11548                 (void *)&cmd_flow_director_mode,
11549                 (void *)&cmd_flow_director_mode_ip,
11550                 (void *)&cmd_flow_director_ops,
11551                 (void *)&cmd_flow_director_flow,
11552                 (void *)&cmd_flow_director_flow_type,
11553                 (void *)&cmd_flow_director_src,
11554                 (void *)&cmd_flow_director_ip_src,
11555                 (void *)&cmd_flow_director_port_src,
11556                 (void *)&cmd_flow_director_dst,
11557                 (void *)&cmd_flow_director_ip_dst,
11558                 (void *)&cmd_flow_director_port_dst,
11559                 (void *)&cmd_flow_director_verify_tag,
11560                 (void *)&cmd_flow_director_verify_tag_value,
11561                 (void *)&cmd_flow_director_tos,
11562                 (void *)&cmd_flow_director_tos_value,
11563                 (void *)&cmd_flow_director_ttl,
11564                 (void *)&cmd_flow_director_ttl_value,
11565                 (void *)&cmd_flow_director_vlan,
11566                 (void *)&cmd_flow_director_vlan_value,
11567                 (void *)&cmd_flow_director_flexbytes,
11568                 (void *)&cmd_flow_director_flexbytes_value,
11569                 (void *)&cmd_flow_director_drop,
11570                 (void *)&cmd_flow_director_pf_vf,
11571                 (void *)&cmd_flow_director_queue,
11572                 (void *)&cmd_flow_director_queue_id,
11573                 (void *)&cmd_flow_director_fd_id,
11574                 (void *)&cmd_flow_director_fd_id_value,
11575                 NULL,
11576         },
11577 };
11578
11579 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11580         .f = cmd_flow_director_filter_parsed,
11581         .data = NULL,
11582         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11583                 "director entry on NIC",
11584         .tokens = {
11585                 (void *)&cmd_flow_director_filter,
11586                 (void *)&cmd_flow_director_port_id,
11587                 (void *)&cmd_flow_director_mode,
11588                 (void *)&cmd_flow_director_mode_ip,
11589                 (void *)&cmd_flow_director_ops,
11590                 (void *)&cmd_flow_director_flow,
11591                 (void *)&cmd_flow_director_flow_type,
11592                 (void *)&cmd_flow_director_ether,
11593                 (void *)&cmd_flow_director_ether_type,
11594                 (void *)&cmd_flow_director_flexbytes,
11595                 (void *)&cmd_flow_director_flexbytes_value,
11596                 (void *)&cmd_flow_director_drop,
11597                 (void *)&cmd_flow_director_pf_vf,
11598                 (void *)&cmd_flow_director_queue,
11599                 (void *)&cmd_flow_director_queue_id,
11600                 (void *)&cmd_flow_director_fd_id,
11601                 (void *)&cmd_flow_director_fd_id_value,
11602                 NULL,
11603         },
11604 };
11605
11606 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11607         .f = cmd_flow_director_filter_parsed,
11608         .data = NULL,
11609         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11610                 "director entry on NIC",
11611         .tokens = {
11612                 (void *)&cmd_flow_director_filter,
11613                 (void *)&cmd_flow_director_port_id,
11614                 (void *)&cmd_flow_director_mode,
11615                 (void *)&cmd_flow_director_mode_mac_vlan,
11616                 (void *)&cmd_flow_director_ops,
11617                 (void *)&cmd_flow_director_mac,
11618                 (void *)&cmd_flow_director_mac_addr,
11619                 (void *)&cmd_flow_director_vlan,
11620                 (void *)&cmd_flow_director_vlan_value,
11621                 (void *)&cmd_flow_director_flexbytes,
11622                 (void *)&cmd_flow_director_flexbytes_value,
11623                 (void *)&cmd_flow_director_drop,
11624                 (void *)&cmd_flow_director_queue,
11625                 (void *)&cmd_flow_director_queue_id,
11626                 (void *)&cmd_flow_director_fd_id,
11627                 (void *)&cmd_flow_director_fd_id_value,
11628                 NULL,
11629         },
11630 };
11631
11632 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11633         .f = cmd_flow_director_filter_parsed,
11634         .data = NULL,
11635         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11636                 "director entry on NIC",
11637         .tokens = {
11638                 (void *)&cmd_flow_director_filter,
11639                 (void *)&cmd_flow_director_port_id,
11640                 (void *)&cmd_flow_director_mode,
11641                 (void *)&cmd_flow_director_mode_tunnel,
11642                 (void *)&cmd_flow_director_ops,
11643                 (void *)&cmd_flow_director_mac,
11644                 (void *)&cmd_flow_director_mac_addr,
11645                 (void *)&cmd_flow_director_vlan,
11646                 (void *)&cmd_flow_director_vlan_value,
11647                 (void *)&cmd_flow_director_tunnel,
11648                 (void *)&cmd_flow_director_tunnel_type,
11649                 (void *)&cmd_flow_director_tunnel_id,
11650                 (void *)&cmd_flow_director_tunnel_id_value,
11651                 (void *)&cmd_flow_director_flexbytes,
11652                 (void *)&cmd_flow_director_flexbytes_value,
11653                 (void *)&cmd_flow_director_drop,
11654                 (void *)&cmd_flow_director_queue,
11655                 (void *)&cmd_flow_director_queue_id,
11656                 (void *)&cmd_flow_director_fd_id,
11657                 (void *)&cmd_flow_director_fd_id_value,
11658                 NULL,
11659         },
11660 };
11661
11662 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11663         .f = cmd_flow_director_filter_parsed,
11664         .data = NULL,
11665         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11666                 "director entry on NIC",
11667         .tokens = {
11668                 (void *)&cmd_flow_director_filter,
11669                 (void *)&cmd_flow_director_port_id,
11670                 (void *)&cmd_flow_director_mode,
11671                 (void *)&cmd_flow_director_mode_raw,
11672                 (void *)&cmd_flow_director_ops,
11673                 (void *)&cmd_flow_director_flow,
11674                 (void *)&cmd_flow_director_flow_type,
11675                 (void *)&cmd_flow_director_drop,
11676                 (void *)&cmd_flow_director_queue,
11677                 (void *)&cmd_flow_director_queue_id,
11678                 (void *)&cmd_flow_director_fd_id,
11679                 (void *)&cmd_flow_director_fd_id_value,
11680                 (void *)&cmd_flow_director_packet,
11681                 (void *)&cmd_flow_director_filepath,
11682                 NULL,
11683         },
11684 };
11685
11686 struct cmd_flush_flow_director_result {
11687         cmdline_fixed_string_t flush_flow_director;
11688         portid_t port_id;
11689 };
11690
11691 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11692         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11693                                  flush_flow_director, "flush_flow_director");
11694 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11695         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11696                               port_id, UINT16);
11697
11698 static void
11699 cmd_flush_flow_director_parsed(void *parsed_result,
11700                           __rte_unused struct cmdline *cl,
11701                           __rte_unused void *data)
11702 {
11703         struct cmd_flow_director_result *res = parsed_result;
11704         int ret = 0;
11705
11706         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11707         if (ret < 0) {
11708                 printf("flow director is not supported on port %u.\n",
11709                         res->port_id);
11710                 return;
11711         }
11712
11713         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11714                         RTE_ETH_FILTER_FLUSH, NULL);
11715         if (ret < 0)
11716                 printf("flow director table flushing error: (%s)\n",
11717                         strerror(-ret));
11718 }
11719
11720 cmdline_parse_inst_t cmd_flush_flow_director = {
11721         .f = cmd_flush_flow_director_parsed,
11722         .data = NULL,
11723         .help_str = "flush_flow_director <port_id>: "
11724                 "Flush all flow director entries of a device on NIC",
11725         .tokens = {
11726                 (void *)&cmd_flush_flow_director_flush,
11727                 (void *)&cmd_flush_flow_director_port_id,
11728                 NULL,
11729         },
11730 };
11731
11732 /* *** deal with flow director mask *** */
11733 struct cmd_flow_director_mask_result {
11734         cmdline_fixed_string_t flow_director_mask;
11735         portid_t port_id;
11736         cmdline_fixed_string_t mode;
11737         cmdline_fixed_string_t mode_value;
11738         cmdline_fixed_string_t vlan;
11739         uint16_t vlan_mask;
11740         cmdline_fixed_string_t src_mask;
11741         cmdline_ipaddr_t ipv4_src;
11742         cmdline_ipaddr_t ipv6_src;
11743         uint16_t port_src;
11744         cmdline_fixed_string_t dst_mask;
11745         cmdline_ipaddr_t ipv4_dst;
11746         cmdline_ipaddr_t ipv6_dst;
11747         uint16_t port_dst;
11748         cmdline_fixed_string_t mac;
11749         uint8_t mac_addr_byte_mask;
11750         cmdline_fixed_string_t tunnel_id;
11751         uint32_t tunnel_id_mask;
11752         cmdline_fixed_string_t tunnel_type;
11753         uint8_t tunnel_type_mask;
11754 };
11755
11756 static void
11757 cmd_flow_director_mask_parsed(void *parsed_result,
11758                           __rte_unused struct cmdline *cl,
11759                           __rte_unused void *data)
11760 {
11761         struct cmd_flow_director_mask_result *res = parsed_result;
11762         struct rte_eth_fdir_masks *mask;
11763         struct rte_port *port;
11764
11765         port = &ports[res->port_id];
11766         /** Check if the port is not started **/
11767         if (port->port_status != RTE_PORT_STOPPED) {
11768                 printf("Please stop port %d first\n", res->port_id);
11769                 return;
11770         }
11771
11772         mask = &port->dev_conf.fdir_conf.mask;
11773
11774         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11775                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11776                         printf("Please set mode to MAC-VLAN.\n");
11777                         return;
11778                 }
11779
11780                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11781         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11782                 if (strcmp(res->mode_value, "Tunnel")) {
11783                         printf("Please set mode to Tunnel.\n");
11784                         return;
11785                 }
11786
11787                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11788                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11789                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11790                 mask->tunnel_type_mask = res->tunnel_type_mask;
11791         } else {
11792                 if (strcmp(res->mode_value, "IP")) {
11793                         printf("Please set mode to IP.\n");
11794                         return;
11795                 }
11796
11797                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11798                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11799                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11800                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11801                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11802                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11803                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11804         }
11805
11806         cmd_reconfig_device_queue(res->port_id, 1, 1);
11807 }
11808
11809 cmdline_parse_token_string_t cmd_flow_director_mask =
11810         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11811                                  flow_director_mask, "flow_director_mask");
11812 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11813         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11814                               port_id, UINT16);
11815 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11816         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11817                                  vlan, "vlan");
11818 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11819         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11820                               vlan_mask, UINT16);
11821 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11822         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11823                                  src_mask, "src_mask");
11824 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11825         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11826                                  ipv4_src);
11827 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11828         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11829                                  ipv6_src);
11830 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11831         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11832                               port_src, UINT16);
11833 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11834         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11835                                  dst_mask, "dst_mask");
11836 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11837         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11838                                  ipv4_dst);
11839 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11840         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11841                                  ipv6_dst);
11842 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11843         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11844                               port_dst, UINT16);
11845
11846 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11847         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11848                                  mode, "mode");
11849 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11850         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11851                                  mode_value, "IP");
11852 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11853         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11854                                  mode_value, "MAC-VLAN");
11855 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11856         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11857                                  mode_value, "Tunnel");
11858 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11859         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11860                                  mac, "mac");
11861 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11862         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11863                               mac_addr_byte_mask, UINT8);
11864 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11865         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11866                                  tunnel_type, "tunnel-type");
11867 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11868         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11869                               tunnel_type_mask, UINT8);
11870 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11871         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11872                                  tunnel_id, "tunnel-id");
11873 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11874         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11875                               tunnel_id_mask, UINT32);
11876
11877 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11878         .f = cmd_flow_director_mask_parsed,
11879         .data = NULL,
11880         .help_str = "flow_director_mask ... : "
11881                 "Set IP mode flow director's mask on NIC",
11882         .tokens = {
11883                 (void *)&cmd_flow_director_mask,
11884                 (void *)&cmd_flow_director_mask_port_id,
11885                 (void *)&cmd_flow_director_mask_mode,
11886                 (void *)&cmd_flow_director_mask_mode_ip,
11887                 (void *)&cmd_flow_director_mask_vlan,
11888                 (void *)&cmd_flow_director_mask_vlan_value,
11889                 (void *)&cmd_flow_director_mask_src,
11890                 (void *)&cmd_flow_director_mask_ipv4_src,
11891                 (void *)&cmd_flow_director_mask_ipv6_src,
11892                 (void *)&cmd_flow_director_mask_port_src,
11893                 (void *)&cmd_flow_director_mask_dst,
11894                 (void *)&cmd_flow_director_mask_ipv4_dst,
11895                 (void *)&cmd_flow_director_mask_ipv6_dst,
11896                 (void *)&cmd_flow_director_mask_port_dst,
11897                 NULL,
11898         },
11899 };
11900
11901 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11902         .f = cmd_flow_director_mask_parsed,
11903         .data = NULL,
11904         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11905                 "flow director's mask on NIC",
11906         .tokens = {
11907                 (void *)&cmd_flow_director_mask,
11908                 (void *)&cmd_flow_director_mask_port_id,
11909                 (void *)&cmd_flow_director_mask_mode,
11910                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11911                 (void *)&cmd_flow_director_mask_vlan,
11912                 (void *)&cmd_flow_director_mask_vlan_value,
11913                 NULL,
11914         },
11915 };
11916
11917 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11918         .f = cmd_flow_director_mask_parsed,
11919         .data = NULL,
11920         .help_str = "flow_director_mask ... : Set tunnel mode "
11921                 "flow director's mask on NIC",
11922         .tokens = {
11923                 (void *)&cmd_flow_director_mask,
11924                 (void *)&cmd_flow_director_mask_port_id,
11925                 (void *)&cmd_flow_director_mask_mode,
11926                 (void *)&cmd_flow_director_mask_mode_tunnel,
11927                 (void *)&cmd_flow_director_mask_vlan,
11928                 (void *)&cmd_flow_director_mask_vlan_value,
11929                 (void *)&cmd_flow_director_mask_mac,
11930                 (void *)&cmd_flow_director_mask_mac_value,
11931                 (void *)&cmd_flow_director_mask_tunnel_type,
11932                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11933                 (void *)&cmd_flow_director_mask_tunnel_id,
11934                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11935                 NULL,
11936         },
11937 };
11938
11939 /* *** deal with flow director mask on flexible payload *** */
11940 struct cmd_flow_director_flex_mask_result {
11941         cmdline_fixed_string_t flow_director_flexmask;
11942         portid_t port_id;
11943         cmdline_fixed_string_t flow;
11944         cmdline_fixed_string_t flow_type;
11945         cmdline_fixed_string_t mask;
11946 };
11947
11948 static void
11949 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11950                           __rte_unused struct cmdline *cl,
11951                           __rte_unused void *data)
11952 {
11953         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11954         struct rte_eth_fdir_info fdir_info;
11955         struct rte_eth_fdir_flex_mask flex_mask;
11956         struct rte_port *port;
11957         uint64_t flow_type_mask;
11958         uint16_t i;
11959         int ret;
11960
11961         port = &ports[res->port_id];
11962         /** Check if the port is not started **/
11963         if (port->port_status != RTE_PORT_STOPPED) {
11964                 printf("Please stop port %d first\n", res->port_id);
11965                 return;
11966         }
11967
11968         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11969         ret = parse_flexbytes(res->mask,
11970                         flex_mask.mask,
11971                         RTE_ETH_FDIR_MAX_FLEXLEN);
11972         if (ret < 0) {
11973                 printf("error: Cannot parse mask input.\n");
11974                 return;
11975         }
11976
11977         memset(&fdir_info, 0, sizeof(fdir_info));
11978         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11979                                 RTE_ETH_FILTER_INFO, &fdir_info);
11980         if (ret < 0) {
11981                 printf("Cannot get FDir filter info\n");
11982                 return;
11983         }
11984
11985         if (!strcmp(res->flow_type, "none")) {
11986                 /* means don't specify the flow type */
11987                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11988                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11989                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11990                                0, sizeof(struct rte_eth_fdir_flex_mask));
11991                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11992                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11993                                  &flex_mask,
11994                                  sizeof(struct rte_eth_fdir_flex_mask));
11995                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11996                 return;
11997         }
11998         flow_type_mask = fdir_info.flow_types_mask[0];
11999         if (!strcmp(res->flow_type, "all")) {
12000                 if (!flow_type_mask) {
12001                         printf("No flow type supported\n");
12002                         return;
12003                 }
12004                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12005                         if (flow_type_mask & (1ULL << i)) {
12006                                 flex_mask.flow_type = i;
12007                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12008                         }
12009                 }
12010                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12011                 return;
12012         }
12013         flex_mask.flow_type = str2flowtype(res->flow_type);
12014         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12015                 printf("Flow type %s not supported on port %d\n",
12016                                 res->flow_type, res->port_id);
12017                 return;
12018         }
12019         fdir_set_flex_mask(res->port_id, &flex_mask);
12020         cmd_reconfig_device_queue(res->port_id, 1, 1);
12021 }
12022
12023 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12024         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12025                                  flow_director_flexmask,
12026                                  "flow_director_flex_mask");
12027 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12028         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12029                               port_id, UINT16);
12030 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12031         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12032                                  flow, "flow");
12033 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12034         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12035                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12036                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12037 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12038         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12039                                  mask, NULL);
12040
12041 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12042         .f = cmd_flow_director_flex_mask_parsed,
12043         .data = NULL,
12044         .help_str = "flow_director_flex_mask ... : "
12045                 "Set flow director's flex mask on NIC",
12046         .tokens = {
12047                 (void *)&cmd_flow_director_flexmask,
12048                 (void *)&cmd_flow_director_flexmask_port_id,
12049                 (void *)&cmd_flow_director_flexmask_flow,
12050                 (void *)&cmd_flow_director_flexmask_flow_type,
12051                 (void *)&cmd_flow_director_flexmask_mask,
12052                 NULL,
12053         },
12054 };
12055
12056 /* *** deal with flow director flexible payload configuration *** */
12057 struct cmd_flow_director_flexpayload_result {
12058         cmdline_fixed_string_t flow_director_flexpayload;
12059         portid_t port_id;
12060         cmdline_fixed_string_t payload_layer;
12061         cmdline_fixed_string_t payload_cfg;
12062 };
12063
12064 static inline int
12065 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12066 {
12067         char s[256];
12068         const char *p, *p0 = q_arg;
12069         char *end;
12070         unsigned long int_fld;
12071         char *str_fld[max_num];
12072         int i;
12073         unsigned size;
12074         int ret = -1;
12075
12076         p = strchr(p0, '(');
12077         if (p == NULL)
12078                 return -1;
12079         ++p;
12080         p0 = strchr(p, ')');
12081         if (p0 == NULL)
12082                 return -1;
12083
12084         size = p0 - p;
12085         if (size >= sizeof(s))
12086                 return -1;
12087
12088         snprintf(s, sizeof(s), "%.*s", size, p);
12089         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12090         if (ret < 0 || ret > max_num)
12091                 return -1;
12092         for (i = 0; i < ret; i++) {
12093                 errno = 0;
12094                 int_fld = strtoul(str_fld[i], &end, 0);
12095                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12096                         return -1;
12097                 offsets[i] = (uint16_t)int_fld;
12098         }
12099         return ret;
12100 }
12101
12102 static void
12103 cmd_flow_director_flxpld_parsed(void *parsed_result,
12104                           __rte_unused struct cmdline *cl,
12105                           __rte_unused void *data)
12106 {
12107         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12108         struct rte_eth_flex_payload_cfg flex_cfg;
12109         struct rte_port *port;
12110         int ret = 0;
12111
12112         port = &ports[res->port_id];
12113         /** Check if the port is not started **/
12114         if (port->port_status != RTE_PORT_STOPPED) {
12115                 printf("Please stop port %d first\n", res->port_id);
12116                 return;
12117         }
12118
12119         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12120
12121         if (!strcmp(res->payload_layer, "raw"))
12122                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12123         else if (!strcmp(res->payload_layer, "l2"))
12124                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12125         else if (!strcmp(res->payload_layer, "l3"))
12126                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12127         else if (!strcmp(res->payload_layer, "l4"))
12128                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12129
12130         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12131                             RTE_ETH_FDIR_MAX_FLEXLEN);
12132         if (ret < 0) {
12133                 printf("error: Cannot parse flex payload input.\n");
12134                 return;
12135         }
12136
12137         fdir_set_flex_payload(res->port_id, &flex_cfg);
12138         cmd_reconfig_device_queue(res->port_id, 1, 1);
12139 }
12140
12141 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12142         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12143                                  flow_director_flexpayload,
12144                                  "flow_director_flex_payload");
12145 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12146         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12147                               port_id, UINT16);
12148 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12149         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12150                                  payload_layer, "raw#l2#l3#l4");
12151 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12152         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12153                                  payload_cfg, NULL);
12154
12155 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12156         .f = cmd_flow_director_flxpld_parsed,
12157         .data = NULL,
12158         .help_str = "flow_director_flexpayload ... : "
12159                 "Set flow director's flex payload on NIC",
12160         .tokens = {
12161                 (void *)&cmd_flow_director_flexpayload,
12162                 (void *)&cmd_flow_director_flexpayload_port_id,
12163                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12164                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12165                 NULL,
12166         },
12167 };
12168
12169 /* Generic flow interface command. */
12170 extern cmdline_parse_inst_t cmd_flow;
12171
12172 /* *** Classification Filters Control *** */
12173 /* *** Get symmetric hash enable per port *** */
12174 struct cmd_get_sym_hash_ena_per_port_result {
12175         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12176         portid_t port_id;
12177 };
12178
12179 static void
12180 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12181                                  __rte_unused struct cmdline *cl,
12182                                  __rte_unused void *data)
12183 {
12184         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12185         struct rte_eth_hash_filter_info info;
12186         int ret;
12187
12188         if (rte_eth_dev_filter_supported(res->port_id,
12189                                 RTE_ETH_FILTER_HASH) < 0) {
12190                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12191                                                         res->port_id);
12192                 return;
12193         }
12194
12195         memset(&info, 0, sizeof(info));
12196         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12197         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12198                                                 RTE_ETH_FILTER_GET, &info);
12199
12200         if (ret < 0) {
12201                 printf("Cannot get symmetric hash enable per port "
12202                                         "on port %u\n", res->port_id);
12203                 return;
12204         }
12205
12206         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12207                                 "enabled" : "disabled", res->port_id);
12208 }
12209
12210 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12211         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12212                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12213 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12214         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12215                 port_id, UINT16);
12216
12217 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12218         .f = cmd_get_sym_hash_per_port_parsed,
12219         .data = NULL,
12220         .help_str = "get_sym_hash_ena_per_port <port_id>",
12221         .tokens = {
12222                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12223                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12224                 NULL,
12225         },
12226 };
12227
12228 /* *** Set symmetric hash enable per port *** */
12229 struct cmd_set_sym_hash_ena_per_port_result {
12230         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12231         cmdline_fixed_string_t enable;
12232         portid_t port_id;
12233 };
12234
12235 static void
12236 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12237                                  __rte_unused struct cmdline *cl,
12238                                  __rte_unused void *data)
12239 {
12240         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12241         struct rte_eth_hash_filter_info info;
12242         int ret;
12243
12244         if (rte_eth_dev_filter_supported(res->port_id,
12245                                 RTE_ETH_FILTER_HASH) < 0) {
12246                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12247                                                         res->port_id);
12248                 return;
12249         }
12250
12251         memset(&info, 0, sizeof(info));
12252         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12253         if (!strcmp(res->enable, "enable"))
12254                 info.info.enable = 1;
12255         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12256                                         RTE_ETH_FILTER_SET, &info);
12257         if (ret < 0) {
12258                 printf("Cannot set symmetric hash enable per port on "
12259                                         "port %u\n", res->port_id);
12260                 return;
12261         }
12262         printf("Symmetric hash has been set to %s on port %u\n",
12263                                         res->enable, res->port_id);
12264 }
12265
12266 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12267         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12268                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12269 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12270         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12271                 port_id, UINT16);
12272 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12273         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12274                 enable, "enable#disable");
12275
12276 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12277         .f = cmd_set_sym_hash_per_port_parsed,
12278         .data = NULL,
12279         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12280         .tokens = {
12281                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12282                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12283                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12284                 NULL,
12285         },
12286 };
12287
12288 /* Get global config of hash function */
12289 struct cmd_get_hash_global_config_result {
12290         cmdline_fixed_string_t get_hash_global_config;
12291         portid_t port_id;
12292 };
12293
12294 static char *
12295 flowtype_to_str(uint16_t ftype)
12296 {
12297         uint16_t i;
12298         static struct {
12299                 char str[16];
12300                 uint16_t ftype;
12301         } ftype_table[] = {
12302                 {"ipv4", RTE_ETH_FLOW_IPV4},
12303                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12304                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12305                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12306                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12307                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12308                 {"ipv6", RTE_ETH_FLOW_IPV6},
12309                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12310                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12311                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12312                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12313                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12314                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12315                 {"port", RTE_ETH_FLOW_PORT},
12316                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12317                 {"geneve", RTE_ETH_FLOW_GENEVE},
12318                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12319                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12320         };
12321
12322         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12323                 if (ftype_table[i].ftype == ftype)
12324                         return ftype_table[i].str;
12325         }
12326
12327         return NULL;
12328 }
12329
12330 static void
12331 cmd_get_hash_global_config_parsed(void *parsed_result,
12332                                   __rte_unused struct cmdline *cl,
12333                                   __rte_unused void *data)
12334 {
12335         struct cmd_get_hash_global_config_result *res = parsed_result;
12336         struct rte_eth_hash_filter_info info;
12337         uint32_t idx, offset;
12338         uint16_t i;
12339         char *str;
12340         int ret;
12341
12342         if (rte_eth_dev_filter_supported(res->port_id,
12343                         RTE_ETH_FILTER_HASH) < 0) {
12344                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12345                                                         res->port_id);
12346                 return;
12347         }
12348
12349         memset(&info, 0, sizeof(info));
12350         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12351         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12352                                         RTE_ETH_FILTER_GET, &info);
12353         if (ret < 0) {
12354                 printf("Cannot get hash global configurations by port %d\n",
12355                                                         res->port_id);
12356                 return;
12357         }
12358
12359         switch (info.info.global_conf.hash_func) {
12360         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12361                 printf("Hash function is Toeplitz\n");
12362                 break;
12363         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12364                 printf("Hash function is Simple XOR\n");
12365                 break;
12366         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12367                 printf("Hash function is Symmetric Toeplitz\n");
12368                 break;
12369         default:
12370                 printf("Unknown hash function\n");
12371                 break;
12372         }
12373
12374         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12375                 idx = i / UINT64_BIT;
12376                 offset = i % UINT64_BIT;
12377                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12378                                                 (1ULL << offset)))
12379                         continue;
12380                 str = flowtype_to_str(i);
12381                 if (!str)
12382                         continue;
12383                 printf("Symmetric hash is %s globally for flow type %s "
12384                                                         "by port %d\n",
12385                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12386                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12387                                                         res->port_id);
12388         }
12389 }
12390
12391 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12392         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12393                 get_hash_global_config, "get_hash_global_config");
12394 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12395         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12396                 port_id, UINT16);
12397
12398 cmdline_parse_inst_t cmd_get_hash_global_config = {
12399         .f = cmd_get_hash_global_config_parsed,
12400         .data = NULL,
12401         .help_str = "get_hash_global_config <port_id>",
12402         .tokens = {
12403                 (void *)&cmd_get_hash_global_config_all,
12404                 (void *)&cmd_get_hash_global_config_port_id,
12405                 NULL,
12406         },
12407 };
12408
12409 /* Set global config of hash function */
12410 struct cmd_set_hash_global_config_result {
12411         cmdline_fixed_string_t set_hash_global_config;
12412         portid_t port_id;
12413         cmdline_fixed_string_t hash_func;
12414         cmdline_fixed_string_t flow_type;
12415         cmdline_fixed_string_t enable;
12416 };
12417
12418 static void
12419 cmd_set_hash_global_config_parsed(void *parsed_result,
12420                                   __rte_unused struct cmdline *cl,
12421                                   __rte_unused void *data)
12422 {
12423         struct cmd_set_hash_global_config_result *res = parsed_result;
12424         struct rte_eth_hash_filter_info info;
12425         uint32_t ftype, idx, offset;
12426         int ret;
12427
12428         if (rte_eth_dev_filter_supported(res->port_id,
12429                                 RTE_ETH_FILTER_HASH) < 0) {
12430                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12431                                                         res->port_id);
12432                 return;
12433         }
12434         memset(&info, 0, sizeof(info));
12435         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12436         if (!strcmp(res->hash_func, "toeplitz"))
12437                 info.info.global_conf.hash_func =
12438                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12439         else if (!strcmp(res->hash_func, "simple_xor"))
12440                 info.info.global_conf.hash_func =
12441                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12442         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12443                 info.info.global_conf.hash_func =
12444                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12445         else if (!strcmp(res->hash_func, "default"))
12446                 info.info.global_conf.hash_func =
12447                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12448
12449         ftype = str2flowtype(res->flow_type);
12450         idx = ftype / UINT64_BIT;
12451         offset = ftype % UINT64_BIT;
12452         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12453         if (!strcmp(res->enable, "enable"))
12454                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12455                                                 (1ULL << offset);
12456         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12457                                         RTE_ETH_FILTER_SET, &info);
12458         if (ret < 0)
12459                 printf("Cannot set global hash configurations by port %d\n",
12460                                                         res->port_id);
12461         else
12462                 printf("Global hash configurations have been set "
12463                         "successfully by port %d\n", res->port_id);
12464 }
12465
12466 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12467         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12468                 set_hash_global_config, "set_hash_global_config");
12469 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12470         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12471                 port_id, UINT16);
12472 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12473         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12474                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12475 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12476         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12477                 flow_type,
12478                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12479                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12480 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12481         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12482                 enable, "enable#disable");
12483
12484 cmdline_parse_inst_t cmd_set_hash_global_config = {
12485         .f = cmd_set_hash_global_config_parsed,
12486         .data = NULL,
12487         .help_str = "set_hash_global_config <port_id> "
12488                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12489                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12490                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12491                 "l2_payload enable|disable",
12492         .tokens = {
12493                 (void *)&cmd_set_hash_global_config_all,
12494                 (void *)&cmd_set_hash_global_config_port_id,
12495                 (void *)&cmd_set_hash_global_config_hash_func,
12496                 (void *)&cmd_set_hash_global_config_flow_type,
12497                 (void *)&cmd_set_hash_global_config_enable,
12498                 NULL,
12499         },
12500 };
12501
12502 /* Set hash input set */
12503 struct cmd_set_hash_input_set_result {
12504         cmdline_fixed_string_t set_hash_input_set;
12505         portid_t port_id;
12506         cmdline_fixed_string_t flow_type;
12507         cmdline_fixed_string_t inset_field;
12508         cmdline_fixed_string_t select;
12509 };
12510
12511 static enum rte_eth_input_set_field
12512 str2inset(char *string)
12513 {
12514         uint16_t i;
12515
12516         static const struct {
12517                 char str[32];
12518                 enum rte_eth_input_set_field inset;
12519         } inset_table[] = {
12520                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12521                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12522                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12523                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12524                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12525                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12526                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12527                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12528                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12529                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12530                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12531                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12532                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12533                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12534                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12535                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12536                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12537                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12538                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12539                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12540                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12541                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12542                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12543                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12544                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12545                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12546                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12547                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12548                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12549                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12550                 {"none", RTE_ETH_INPUT_SET_NONE},
12551         };
12552
12553         for (i = 0; i < RTE_DIM(inset_table); i++) {
12554                 if (!strcmp(string, inset_table[i].str))
12555                         return inset_table[i].inset;
12556         }
12557
12558         return RTE_ETH_INPUT_SET_UNKNOWN;
12559 }
12560
12561 static void
12562 cmd_set_hash_input_set_parsed(void *parsed_result,
12563                               __rte_unused struct cmdline *cl,
12564                               __rte_unused void *data)
12565 {
12566         struct cmd_set_hash_input_set_result *res = parsed_result;
12567         struct rte_eth_hash_filter_info info;
12568
12569         memset(&info, 0, sizeof(info));
12570         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12571         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12572         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12573         info.info.input_set_conf.inset_size = 1;
12574         if (!strcmp(res->select, "select"))
12575                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12576         else if (!strcmp(res->select, "add"))
12577                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12578         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12579                                 RTE_ETH_FILTER_SET, &info);
12580 }
12581
12582 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12583         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12584                 set_hash_input_set, "set_hash_input_set");
12585 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12586         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12587                 port_id, UINT16);
12588 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12589         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12590                 flow_type, NULL);
12591 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12592         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12593                 inset_field,
12594                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12595                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12596                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12597                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12598                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12599                 "fld-8th#none");
12600 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12601         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12602                 select, "select#add");
12603
12604 cmdline_parse_inst_t cmd_set_hash_input_set = {
12605         .f = cmd_set_hash_input_set_parsed,
12606         .data = NULL,
12607         .help_str = "set_hash_input_set <port_id> "
12608         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12609         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12610         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12611         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12612         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12613         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12614         "fld-7th|fld-8th|none select|add",
12615         .tokens = {
12616                 (void *)&cmd_set_hash_input_set_cmd,
12617                 (void *)&cmd_set_hash_input_set_port_id,
12618                 (void *)&cmd_set_hash_input_set_flow_type,
12619                 (void *)&cmd_set_hash_input_set_field,
12620                 (void *)&cmd_set_hash_input_set_select,
12621                 NULL,
12622         },
12623 };
12624
12625 /* Set flow director input set */
12626 struct cmd_set_fdir_input_set_result {
12627         cmdline_fixed_string_t set_fdir_input_set;
12628         portid_t port_id;
12629         cmdline_fixed_string_t flow_type;
12630         cmdline_fixed_string_t inset_field;
12631         cmdline_fixed_string_t select;
12632 };
12633
12634 static void
12635 cmd_set_fdir_input_set_parsed(void *parsed_result,
12636         __rte_unused struct cmdline *cl,
12637         __rte_unused void *data)
12638 {
12639         struct cmd_set_fdir_input_set_result *res = parsed_result;
12640         struct rte_eth_fdir_filter_info info;
12641
12642         memset(&info, 0, sizeof(info));
12643         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12644         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12645         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12646         info.info.input_set_conf.inset_size = 1;
12647         if (!strcmp(res->select, "select"))
12648                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12649         else if (!strcmp(res->select, "add"))
12650                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12651         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12652                 RTE_ETH_FILTER_SET, &info);
12653 }
12654
12655 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12656         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12657         set_fdir_input_set, "set_fdir_input_set");
12658 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12659         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12660         port_id, UINT16);
12661 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12662         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12663         flow_type,
12664         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12665         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12666 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12667         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12668         inset_field,
12669         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12670         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12671         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12672         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12673         "sctp-veri-tag#none");
12674 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12675         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12676         select, "select#add");
12677
12678 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12679         .f = cmd_set_fdir_input_set_parsed,
12680         .data = NULL,
12681         .help_str = "set_fdir_input_set <port_id> "
12682         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12683         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12684         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12685         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12686         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12687         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12688         "sctp-veri-tag|none select|add",
12689         .tokens = {
12690                 (void *)&cmd_set_fdir_input_set_cmd,
12691                 (void *)&cmd_set_fdir_input_set_port_id,
12692                 (void *)&cmd_set_fdir_input_set_flow_type,
12693                 (void *)&cmd_set_fdir_input_set_field,
12694                 (void *)&cmd_set_fdir_input_set_select,
12695                 NULL,
12696         },
12697 };
12698
12699 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12700 struct cmd_mcast_addr_result {
12701         cmdline_fixed_string_t mcast_addr_cmd;
12702         cmdline_fixed_string_t what;
12703         uint16_t port_num;
12704         struct rte_ether_addr mc_addr;
12705 };
12706
12707 static void cmd_mcast_addr_parsed(void *parsed_result,
12708                 __rte_unused struct cmdline *cl,
12709                 __rte_unused void *data)
12710 {
12711         struct cmd_mcast_addr_result *res = parsed_result;
12712
12713         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12714                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12715                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12716                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12717                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12718                 return;
12719         }
12720         if (strcmp(res->what, "add") == 0)
12721                 mcast_addr_add(res->port_num, &res->mc_addr);
12722         else
12723                 mcast_addr_remove(res->port_num, &res->mc_addr);
12724 }
12725
12726 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12727         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12728                                  mcast_addr_cmd, "mcast_addr");
12729 cmdline_parse_token_string_t cmd_mcast_addr_what =
12730         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12731                                  "add#remove");
12732 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12733         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12734 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12735         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12736
12737 cmdline_parse_inst_t cmd_mcast_addr = {
12738         .f = cmd_mcast_addr_parsed,
12739         .data = (void *)0,
12740         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12741                 "Add/Remove multicast MAC address on port_id",
12742         .tokens = {
12743                 (void *)&cmd_mcast_addr_cmd,
12744                 (void *)&cmd_mcast_addr_what,
12745                 (void *)&cmd_mcast_addr_portnum,
12746                 (void *)&cmd_mcast_addr_addr,
12747                 NULL,
12748         },
12749 };
12750
12751 /* l2 tunnel config
12752  * only support E-tag now.
12753  */
12754
12755 /* Ether type config */
12756 struct cmd_config_l2_tunnel_eth_type_result {
12757         cmdline_fixed_string_t port;
12758         cmdline_fixed_string_t config;
12759         cmdline_fixed_string_t all;
12760         portid_t id;
12761         cmdline_fixed_string_t l2_tunnel;
12762         cmdline_fixed_string_t l2_tunnel_type;
12763         cmdline_fixed_string_t eth_type;
12764         uint16_t eth_type_val;
12765 };
12766
12767 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12768         TOKEN_STRING_INITIALIZER
12769                 (struct cmd_config_l2_tunnel_eth_type_result,
12770                  port, "port");
12771 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12772         TOKEN_STRING_INITIALIZER
12773                 (struct cmd_config_l2_tunnel_eth_type_result,
12774                  config, "config");
12775 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12776         TOKEN_STRING_INITIALIZER
12777                 (struct cmd_config_l2_tunnel_eth_type_result,
12778                  all, "all");
12779 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12780         TOKEN_NUM_INITIALIZER
12781                 (struct cmd_config_l2_tunnel_eth_type_result,
12782                  id, UINT16);
12783 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12784         TOKEN_STRING_INITIALIZER
12785                 (struct cmd_config_l2_tunnel_eth_type_result,
12786                  l2_tunnel, "l2-tunnel");
12787 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12788         TOKEN_STRING_INITIALIZER
12789                 (struct cmd_config_l2_tunnel_eth_type_result,
12790                  l2_tunnel_type, "E-tag");
12791 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12792         TOKEN_STRING_INITIALIZER
12793                 (struct cmd_config_l2_tunnel_eth_type_result,
12794                  eth_type, "ether-type");
12795 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12796         TOKEN_NUM_INITIALIZER
12797                 (struct cmd_config_l2_tunnel_eth_type_result,
12798                  eth_type_val, UINT16);
12799
12800 static enum rte_eth_tunnel_type
12801 str2fdir_l2_tunnel_type(char *string)
12802 {
12803         uint32_t i = 0;
12804
12805         static const struct {
12806                 char str[32];
12807                 enum rte_eth_tunnel_type type;
12808         } l2_tunnel_type_str[] = {
12809                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12810         };
12811
12812         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12813                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12814                         return l2_tunnel_type_str[i].type;
12815         }
12816         return RTE_TUNNEL_TYPE_NONE;
12817 }
12818
12819 /* ether type config for all ports */
12820 static void
12821 cmd_config_l2_tunnel_eth_type_all_parsed
12822         (void *parsed_result,
12823          __rte_unused struct cmdline *cl,
12824          __rte_unused void *data)
12825 {
12826         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12827         struct rte_eth_l2_tunnel_conf entry;
12828         portid_t pid;
12829
12830         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12831         entry.ether_type = res->eth_type_val;
12832
12833         RTE_ETH_FOREACH_DEV(pid) {
12834                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12835         }
12836 }
12837
12838 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12839         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12840         .data = NULL,
12841         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12842         .tokens = {
12843                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12844                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12845                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12846                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12847                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12848                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12849                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12850                 NULL,
12851         },
12852 };
12853
12854 /* ether type config for a specific port */
12855 static void
12856 cmd_config_l2_tunnel_eth_type_specific_parsed(
12857         void *parsed_result,
12858         __rte_unused struct cmdline *cl,
12859         __rte_unused void *data)
12860 {
12861         struct cmd_config_l2_tunnel_eth_type_result *res =
12862                  parsed_result;
12863         struct rte_eth_l2_tunnel_conf entry;
12864
12865         if (port_id_is_invalid(res->id, ENABLED_WARN))
12866                 return;
12867
12868         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12869         entry.ether_type = res->eth_type_val;
12870
12871         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12872 }
12873
12874 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12875         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12876         .data = NULL,
12877         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12878         .tokens = {
12879                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12880                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12881                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12882                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12883                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12884                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12885                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12886                 NULL,
12887         },
12888 };
12889
12890 /* Enable/disable l2 tunnel */
12891 struct cmd_config_l2_tunnel_en_dis_result {
12892         cmdline_fixed_string_t port;
12893         cmdline_fixed_string_t config;
12894         cmdline_fixed_string_t all;
12895         portid_t id;
12896         cmdline_fixed_string_t l2_tunnel;
12897         cmdline_fixed_string_t l2_tunnel_type;
12898         cmdline_fixed_string_t en_dis;
12899 };
12900
12901 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12902         TOKEN_STRING_INITIALIZER
12903                 (struct cmd_config_l2_tunnel_en_dis_result,
12904                  port, "port");
12905 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12906         TOKEN_STRING_INITIALIZER
12907                 (struct cmd_config_l2_tunnel_en_dis_result,
12908                  config, "config");
12909 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12910         TOKEN_STRING_INITIALIZER
12911                 (struct cmd_config_l2_tunnel_en_dis_result,
12912                  all, "all");
12913 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12914         TOKEN_NUM_INITIALIZER
12915                 (struct cmd_config_l2_tunnel_en_dis_result,
12916                  id, UINT16);
12917 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12918         TOKEN_STRING_INITIALIZER
12919                 (struct cmd_config_l2_tunnel_en_dis_result,
12920                  l2_tunnel, "l2-tunnel");
12921 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12922         TOKEN_STRING_INITIALIZER
12923                 (struct cmd_config_l2_tunnel_en_dis_result,
12924                  l2_tunnel_type, "E-tag");
12925 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12926         TOKEN_STRING_INITIALIZER
12927                 (struct cmd_config_l2_tunnel_en_dis_result,
12928                  en_dis, "enable#disable");
12929
12930 /* enable/disable l2 tunnel for all ports */
12931 static void
12932 cmd_config_l2_tunnel_en_dis_all_parsed(
12933         void *parsed_result,
12934         __rte_unused struct cmdline *cl,
12935         __rte_unused void *data)
12936 {
12937         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12938         struct rte_eth_l2_tunnel_conf entry;
12939         portid_t pid;
12940         uint8_t en;
12941
12942         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12943
12944         if (!strcmp("enable", res->en_dis))
12945                 en = 1;
12946         else
12947                 en = 0;
12948
12949         RTE_ETH_FOREACH_DEV(pid) {
12950                 rte_eth_dev_l2_tunnel_offload_set(pid,
12951                                                   &entry,
12952                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12953                                                   en);
12954         }
12955 }
12956
12957 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12958         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12959         .data = NULL,
12960         .help_str = "port config all l2-tunnel E-tag enable|disable",
12961         .tokens = {
12962                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12963                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12964                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12965                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12966                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12967                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12968                 NULL,
12969         },
12970 };
12971
12972 /* enable/disable l2 tunnel for a port */
12973 static void
12974 cmd_config_l2_tunnel_en_dis_specific_parsed(
12975         void *parsed_result,
12976         __rte_unused struct cmdline *cl,
12977         __rte_unused void *data)
12978 {
12979         struct cmd_config_l2_tunnel_en_dis_result *res =
12980                 parsed_result;
12981         struct rte_eth_l2_tunnel_conf entry;
12982
12983         if (port_id_is_invalid(res->id, ENABLED_WARN))
12984                 return;
12985
12986         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12987
12988         if (!strcmp("enable", res->en_dis))
12989                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12990                                                   &entry,
12991                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12992                                                   1);
12993         else
12994                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12995                                                   &entry,
12996                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12997                                                   0);
12998 }
12999
13000 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13001         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13002         .data = NULL,
13003         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13004         .tokens = {
13005                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13006                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13007                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13008                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13009                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13010                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13011                 NULL,
13012         },
13013 };
13014
13015 /* E-tag configuration */
13016
13017 /* Common result structure for all E-tag configuration */
13018 struct cmd_config_e_tag_result {
13019         cmdline_fixed_string_t e_tag;
13020         cmdline_fixed_string_t set;
13021         cmdline_fixed_string_t insertion;
13022         cmdline_fixed_string_t stripping;
13023         cmdline_fixed_string_t forwarding;
13024         cmdline_fixed_string_t filter;
13025         cmdline_fixed_string_t add;
13026         cmdline_fixed_string_t del;
13027         cmdline_fixed_string_t on;
13028         cmdline_fixed_string_t off;
13029         cmdline_fixed_string_t on_off;
13030         cmdline_fixed_string_t port_tag_id;
13031         uint32_t port_tag_id_val;
13032         cmdline_fixed_string_t e_tag_id;
13033         uint16_t e_tag_id_val;
13034         cmdline_fixed_string_t dst_pool;
13035         uint8_t dst_pool_val;
13036         cmdline_fixed_string_t port;
13037         portid_t port_id;
13038         cmdline_fixed_string_t vf;
13039         uint8_t vf_id;
13040 };
13041
13042 /* Common CLI fields for all E-tag configuration */
13043 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13044         TOKEN_STRING_INITIALIZER
13045                 (struct cmd_config_e_tag_result,
13046                  e_tag, "E-tag");
13047 cmdline_parse_token_string_t cmd_config_e_tag_set =
13048         TOKEN_STRING_INITIALIZER
13049                 (struct cmd_config_e_tag_result,
13050                  set, "set");
13051 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13052         TOKEN_STRING_INITIALIZER
13053                 (struct cmd_config_e_tag_result,
13054                  insertion, "insertion");
13055 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13056         TOKEN_STRING_INITIALIZER
13057                 (struct cmd_config_e_tag_result,
13058                  stripping, "stripping");
13059 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13060         TOKEN_STRING_INITIALIZER
13061                 (struct cmd_config_e_tag_result,
13062                  forwarding, "forwarding");
13063 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13064         TOKEN_STRING_INITIALIZER
13065                 (struct cmd_config_e_tag_result,
13066                  filter, "filter");
13067 cmdline_parse_token_string_t cmd_config_e_tag_add =
13068         TOKEN_STRING_INITIALIZER
13069                 (struct cmd_config_e_tag_result,
13070                  add, "add");
13071 cmdline_parse_token_string_t cmd_config_e_tag_del =
13072         TOKEN_STRING_INITIALIZER
13073                 (struct cmd_config_e_tag_result,
13074                  del, "del");
13075 cmdline_parse_token_string_t cmd_config_e_tag_on =
13076         TOKEN_STRING_INITIALIZER
13077                 (struct cmd_config_e_tag_result,
13078                  on, "on");
13079 cmdline_parse_token_string_t cmd_config_e_tag_off =
13080         TOKEN_STRING_INITIALIZER
13081                 (struct cmd_config_e_tag_result,
13082                  off, "off");
13083 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13084         TOKEN_STRING_INITIALIZER
13085                 (struct cmd_config_e_tag_result,
13086                  on_off, "on#off");
13087 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13088         TOKEN_STRING_INITIALIZER
13089                 (struct cmd_config_e_tag_result,
13090                  port_tag_id, "port-tag-id");
13091 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13092         TOKEN_NUM_INITIALIZER
13093                 (struct cmd_config_e_tag_result,
13094                  port_tag_id_val, UINT32);
13095 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13096         TOKEN_STRING_INITIALIZER
13097                 (struct cmd_config_e_tag_result,
13098                  e_tag_id, "e-tag-id");
13099 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13100         TOKEN_NUM_INITIALIZER
13101                 (struct cmd_config_e_tag_result,
13102                  e_tag_id_val, UINT16);
13103 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13104         TOKEN_STRING_INITIALIZER
13105                 (struct cmd_config_e_tag_result,
13106                  dst_pool, "dst-pool");
13107 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13108         TOKEN_NUM_INITIALIZER
13109                 (struct cmd_config_e_tag_result,
13110                  dst_pool_val, UINT8);
13111 cmdline_parse_token_string_t cmd_config_e_tag_port =
13112         TOKEN_STRING_INITIALIZER
13113                 (struct cmd_config_e_tag_result,
13114                  port, "port");
13115 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13116         TOKEN_NUM_INITIALIZER
13117                 (struct cmd_config_e_tag_result,
13118                  port_id, UINT16);
13119 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13120         TOKEN_STRING_INITIALIZER
13121                 (struct cmd_config_e_tag_result,
13122                  vf, "vf");
13123 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13124         TOKEN_NUM_INITIALIZER
13125                 (struct cmd_config_e_tag_result,
13126                  vf_id, UINT8);
13127
13128 /* E-tag insertion configuration */
13129 static void
13130 cmd_config_e_tag_insertion_en_parsed(
13131         void *parsed_result,
13132         __rte_unused struct cmdline *cl,
13133         __rte_unused void *data)
13134 {
13135         struct cmd_config_e_tag_result *res =
13136                 parsed_result;
13137         struct rte_eth_l2_tunnel_conf entry;
13138
13139         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13140                 return;
13141
13142         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13143         entry.tunnel_id = res->port_tag_id_val;
13144         entry.vf_id = res->vf_id;
13145         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13146                                           &entry,
13147                                           ETH_L2_TUNNEL_INSERTION_MASK,
13148                                           1);
13149 }
13150
13151 static void
13152 cmd_config_e_tag_insertion_dis_parsed(
13153         void *parsed_result,
13154         __rte_unused struct cmdline *cl,
13155         __rte_unused void *data)
13156 {
13157         struct cmd_config_e_tag_result *res =
13158                 parsed_result;
13159         struct rte_eth_l2_tunnel_conf entry;
13160
13161         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13162                 return;
13163
13164         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13165         entry.vf_id = res->vf_id;
13166
13167         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13168                                           &entry,
13169                                           ETH_L2_TUNNEL_INSERTION_MASK,
13170                                           0);
13171 }
13172
13173 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13174         .f = cmd_config_e_tag_insertion_en_parsed,
13175         .data = NULL,
13176         .help_str = "E-tag ... : E-tag insertion enable",
13177         .tokens = {
13178                 (void *)&cmd_config_e_tag_e_tag,
13179                 (void *)&cmd_config_e_tag_set,
13180                 (void *)&cmd_config_e_tag_insertion,
13181                 (void *)&cmd_config_e_tag_on,
13182                 (void *)&cmd_config_e_tag_port_tag_id,
13183                 (void *)&cmd_config_e_tag_port_tag_id_val,
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 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13193         .f = cmd_config_e_tag_insertion_dis_parsed,
13194         .data = NULL,
13195         .help_str = "E-tag ... : E-tag insertion disable",
13196         .tokens = {
13197                 (void *)&cmd_config_e_tag_e_tag,
13198                 (void *)&cmd_config_e_tag_set,
13199                 (void *)&cmd_config_e_tag_insertion,
13200                 (void *)&cmd_config_e_tag_off,
13201                 (void *)&cmd_config_e_tag_port,
13202                 (void *)&cmd_config_e_tag_port_id,
13203                 (void *)&cmd_config_e_tag_vf,
13204                 (void *)&cmd_config_e_tag_vf_id,
13205                 NULL,
13206         },
13207 };
13208
13209 /* E-tag stripping configuration */
13210 static void
13211 cmd_config_e_tag_stripping_parsed(
13212         void *parsed_result,
13213         __rte_unused struct cmdline *cl,
13214         __rte_unused void *data)
13215 {
13216         struct cmd_config_e_tag_result *res =
13217                 parsed_result;
13218         struct rte_eth_l2_tunnel_conf entry;
13219
13220         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13221                 return;
13222
13223         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13224
13225         if (!strcmp(res->on_off, "on"))
13226                 rte_eth_dev_l2_tunnel_offload_set
13227                         (res->port_id,
13228                          &entry,
13229                          ETH_L2_TUNNEL_STRIPPING_MASK,
13230                          1);
13231         else
13232                 rte_eth_dev_l2_tunnel_offload_set
13233                         (res->port_id,
13234                          &entry,
13235                          ETH_L2_TUNNEL_STRIPPING_MASK,
13236                          0);
13237 }
13238
13239 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13240         .f = cmd_config_e_tag_stripping_parsed,
13241         .data = NULL,
13242         .help_str = "E-tag ... : E-tag stripping enable/disable",
13243         .tokens = {
13244                 (void *)&cmd_config_e_tag_e_tag,
13245                 (void *)&cmd_config_e_tag_set,
13246                 (void *)&cmd_config_e_tag_stripping,
13247                 (void *)&cmd_config_e_tag_on_off,
13248                 (void *)&cmd_config_e_tag_port,
13249                 (void *)&cmd_config_e_tag_port_id,
13250                 NULL,
13251         },
13252 };
13253
13254 /* E-tag forwarding configuration */
13255 static void
13256 cmd_config_e_tag_forwarding_parsed(
13257         void *parsed_result,
13258         __rte_unused struct cmdline *cl,
13259         __rte_unused void *data)
13260 {
13261         struct cmd_config_e_tag_result *res = parsed_result;
13262         struct rte_eth_l2_tunnel_conf entry;
13263
13264         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13265                 return;
13266
13267         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13268
13269         if (!strcmp(res->on_off, "on"))
13270                 rte_eth_dev_l2_tunnel_offload_set
13271                         (res->port_id,
13272                          &entry,
13273                          ETH_L2_TUNNEL_FORWARDING_MASK,
13274                          1);
13275         else
13276                 rte_eth_dev_l2_tunnel_offload_set
13277                         (res->port_id,
13278                          &entry,
13279                          ETH_L2_TUNNEL_FORWARDING_MASK,
13280                          0);
13281 }
13282
13283 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13284         .f = cmd_config_e_tag_forwarding_parsed,
13285         .data = NULL,
13286         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13287         .tokens = {
13288                 (void *)&cmd_config_e_tag_e_tag,
13289                 (void *)&cmd_config_e_tag_set,
13290                 (void *)&cmd_config_e_tag_forwarding,
13291                 (void *)&cmd_config_e_tag_on_off,
13292                 (void *)&cmd_config_e_tag_port,
13293                 (void *)&cmd_config_e_tag_port_id,
13294                 NULL,
13295         },
13296 };
13297
13298 /* E-tag filter configuration */
13299 static void
13300 cmd_config_e_tag_filter_add_parsed(
13301         void *parsed_result,
13302         __rte_unused struct cmdline *cl,
13303         __rte_unused void *data)
13304 {
13305         struct cmd_config_e_tag_result *res = parsed_result;
13306         struct rte_eth_l2_tunnel_conf entry;
13307         int ret = 0;
13308
13309         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13310                 return;
13311
13312         if (res->e_tag_id_val > 0x3fff) {
13313                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13314                 return;
13315         }
13316
13317         ret = rte_eth_dev_filter_supported(res->port_id,
13318                                            RTE_ETH_FILTER_L2_TUNNEL);
13319         if (ret < 0) {
13320                 printf("E-tag filter is not supported on port %u.\n",
13321                        res->port_id);
13322                 return;
13323         }
13324
13325         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13326         entry.tunnel_id = res->e_tag_id_val;
13327         entry.pool = res->dst_pool_val;
13328
13329         ret = rte_eth_dev_filter_ctrl(res->port_id,
13330                                       RTE_ETH_FILTER_L2_TUNNEL,
13331                                       RTE_ETH_FILTER_ADD,
13332                                       &entry);
13333         if (ret < 0)
13334                 printf("E-tag filter programming error: (%s)\n",
13335                        strerror(-ret));
13336 }
13337
13338 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13339         .f = cmd_config_e_tag_filter_add_parsed,
13340         .data = NULL,
13341         .help_str = "E-tag ... : E-tag filter add",
13342         .tokens = {
13343                 (void *)&cmd_config_e_tag_e_tag,
13344                 (void *)&cmd_config_e_tag_set,
13345                 (void *)&cmd_config_e_tag_filter,
13346                 (void *)&cmd_config_e_tag_add,
13347                 (void *)&cmd_config_e_tag_e_tag_id,
13348                 (void *)&cmd_config_e_tag_e_tag_id_val,
13349                 (void *)&cmd_config_e_tag_dst_pool,
13350                 (void *)&cmd_config_e_tag_dst_pool_val,
13351                 (void *)&cmd_config_e_tag_port,
13352                 (void *)&cmd_config_e_tag_port_id,
13353                 NULL,
13354         },
13355 };
13356
13357 static void
13358 cmd_config_e_tag_filter_del_parsed(
13359         void *parsed_result,
13360         __rte_unused struct cmdline *cl,
13361         __rte_unused void *data)
13362 {
13363         struct cmd_config_e_tag_result *res = parsed_result;
13364         struct rte_eth_l2_tunnel_conf entry;
13365         int ret = 0;
13366
13367         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13368                 return;
13369
13370         if (res->e_tag_id_val > 0x3fff) {
13371                 printf("e-tag-id must be less than 0x3fff.\n");
13372                 return;
13373         }
13374
13375         ret = rte_eth_dev_filter_supported(res->port_id,
13376                                            RTE_ETH_FILTER_L2_TUNNEL);
13377         if (ret < 0) {
13378                 printf("E-tag filter is not supported on port %u.\n",
13379                        res->port_id);
13380                 return;
13381         }
13382
13383         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13384         entry.tunnel_id = res->e_tag_id_val;
13385
13386         ret = rte_eth_dev_filter_ctrl(res->port_id,
13387                                       RTE_ETH_FILTER_L2_TUNNEL,
13388                                       RTE_ETH_FILTER_DELETE,
13389                                       &entry);
13390         if (ret < 0)
13391                 printf("E-tag filter programming error: (%s)\n",
13392                        strerror(-ret));
13393 }
13394
13395 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13396         .f = cmd_config_e_tag_filter_del_parsed,
13397         .data = NULL,
13398         .help_str = "E-tag ... : E-tag filter delete",
13399         .tokens = {
13400                 (void *)&cmd_config_e_tag_e_tag,
13401                 (void *)&cmd_config_e_tag_set,
13402                 (void *)&cmd_config_e_tag_filter,
13403                 (void *)&cmd_config_e_tag_del,
13404                 (void *)&cmd_config_e_tag_e_tag_id,
13405                 (void *)&cmd_config_e_tag_e_tag_id_val,
13406                 (void *)&cmd_config_e_tag_port,
13407                 (void *)&cmd_config_e_tag_port_id,
13408                 NULL,
13409         },
13410 };
13411
13412 /* vf vlan anti spoof configuration */
13413
13414 /* Common result structure for vf vlan anti spoof */
13415 struct cmd_vf_vlan_anti_spoof_result {
13416         cmdline_fixed_string_t set;
13417         cmdline_fixed_string_t vf;
13418         cmdline_fixed_string_t vlan;
13419         cmdline_fixed_string_t antispoof;
13420         portid_t port_id;
13421         uint32_t vf_id;
13422         cmdline_fixed_string_t on_off;
13423 };
13424
13425 /* Common CLI fields for vf vlan anti spoof enable disable */
13426 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13427         TOKEN_STRING_INITIALIZER
13428                 (struct cmd_vf_vlan_anti_spoof_result,
13429                  set, "set");
13430 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13431         TOKEN_STRING_INITIALIZER
13432                 (struct cmd_vf_vlan_anti_spoof_result,
13433                  vf, "vf");
13434 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13435         TOKEN_STRING_INITIALIZER
13436                 (struct cmd_vf_vlan_anti_spoof_result,
13437                  vlan, "vlan");
13438 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13439         TOKEN_STRING_INITIALIZER
13440                 (struct cmd_vf_vlan_anti_spoof_result,
13441                  antispoof, "antispoof");
13442 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13443         TOKEN_NUM_INITIALIZER
13444                 (struct cmd_vf_vlan_anti_spoof_result,
13445                  port_id, UINT16);
13446 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13447         TOKEN_NUM_INITIALIZER
13448                 (struct cmd_vf_vlan_anti_spoof_result,
13449                  vf_id, UINT32);
13450 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13451         TOKEN_STRING_INITIALIZER
13452                 (struct cmd_vf_vlan_anti_spoof_result,
13453                  on_off, "on#off");
13454
13455 static void
13456 cmd_set_vf_vlan_anti_spoof_parsed(
13457         void *parsed_result,
13458         __rte_unused struct cmdline *cl,
13459         __rte_unused void *data)
13460 {
13461         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13462         int ret = -ENOTSUP;
13463
13464         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13465
13466         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13467                 return;
13468
13469 #ifdef RTE_LIBRTE_IXGBE_PMD
13470         if (ret == -ENOTSUP)
13471                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13472                                 res->vf_id, is_on);
13473 #endif
13474 #ifdef RTE_LIBRTE_I40E_PMD
13475         if (ret == -ENOTSUP)
13476                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13477                                 res->vf_id, is_on);
13478 #endif
13479 #ifdef RTE_LIBRTE_BNXT_PMD
13480         if (ret == -ENOTSUP)
13481                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13482                                 res->vf_id, is_on);
13483 #endif
13484
13485         switch (ret) {
13486         case 0:
13487                 break;
13488         case -EINVAL:
13489                 printf("invalid vf_id %d\n", res->vf_id);
13490                 break;
13491         case -ENODEV:
13492                 printf("invalid port_id %d\n", res->port_id);
13493                 break;
13494         case -ENOTSUP:
13495                 printf("function not implemented\n");
13496                 break;
13497         default:
13498                 printf("programming error: (%s)\n", strerror(-ret));
13499         }
13500 }
13501
13502 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13503         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13504         .data = NULL,
13505         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13506         .tokens = {
13507                 (void *)&cmd_vf_vlan_anti_spoof_set,
13508                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13509                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13510                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13511                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13512                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13513                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13514                 NULL,
13515         },
13516 };
13517
13518 /* vf mac anti spoof configuration */
13519
13520 /* Common result structure for vf mac anti spoof */
13521 struct cmd_vf_mac_anti_spoof_result {
13522         cmdline_fixed_string_t set;
13523         cmdline_fixed_string_t vf;
13524         cmdline_fixed_string_t mac;
13525         cmdline_fixed_string_t antispoof;
13526         portid_t port_id;
13527         uint32_t vf_id;
13528         cmdline_fixed_string_t on_off;
13529 };
13530
13531 /* Common CLI fields for vf mac anti spoof enable disable */
13532 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13533         TOKEN_STRING_INITIALIZER
13534                 (struct cmd_vf_mac_anti_spoof_result,
13535                  set, "set");
13536 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13537         TOKEN_STRING_INITIALIZER
13538                 (struct cmd_vf_mac_anti_spoof_result,
13539                  vf, "vf");
13540 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13541         TOKEN_STRING_INITIALIZER
13542                 (struct cmd_vf_mac_anti_spoof_result,
13543                  mac, "mac");
13544 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13545         TOKEN_STRING_INITIALIZER
13546                 (struct cmd_vf_mac_anti_spoof_result,
13547                  antispoof, "antispoof");
13548 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13549         TOKEN_NUM_INITIALIZER
13550                 (struct cmd_vf_mac_anti_spoof_result,
13551                  port_id, UINT16);
13552 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13553         TOKEN_NUM_INITIALIZER
13554                 (struct cmd_vf_mac_anti_spoof_result,
13555                  vf_id, UINT32);
13556 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13557         TOKEN_STRING_INITIALIZER
13558                 (struct cmd_vf_mac_anti_spoof_result,
13559                  on_off, "on#off");
13560
13561 static void
13562 cmd_set_vf_mac_anti_spoof_parsed(
13563         void *parsed_result,
13564         __rte_unused struct cmdline *cl,
13565         __rte_unused void *data)
13566 {
13567         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13568         int ret = -ENOTSUP;
13569
13570         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13571
13572         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13573                 return;
13574
13575 #ifdef RTE_LIBRTE_IXGBE_PMD
13576         if (ret == -ENOTSUP)
13577                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13578                         res->vf_id, is_on);
13579 #endif
13580 #ifdef RTE_LIBRTE_I40E_PMD
13581         if (ret == -ENOTSUP)
13582                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13583                         res->vf_id, is_on);
13584 #endif
13585 #ifdef RTE_LIBRTE_BNXT_PMD
13586         if (ret == -ENOTSUP)
13587                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13588                         res->vf_id, is_on);
13589 #endif
13590
13591         switch (ret) {
13592         case 0:
13593                 break;
13594         case -EINVAL:
13595                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13596                 break;
13597         case -ENODEV:
13598                 printf("invalid port_id %d\n", res->port_id);
13599                 break;
13600         case -ENOTSUP:
13601                 printf("function not implemented\n");
13602                 break;
13603         default:
13604                 printf("programming error: (%s)\n", strerror(-ret));
13605         }
13606 }
13607
13608 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13609         .f = cmd_set_vf_mac_anti_spoof_parsed,
13610         .data = NULL,
13611         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13612         .tokens = {
13613                 (void *)&cmd_vf_mac_anti_spoof_set,
13614                 (void *)&cmd_vf_mac_anti_spoof_vf,
13615                 (void *)&cmd_vf_mac_anti_spoof_mac,
13616                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13617                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13618                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13619                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13620                 NULL,
13621         },
13622 };
13623
13624 /* vf vlan strip queue configuration */
13625
13626 /* Common result structure for vf mac anti spoof */
13627 struct cmd_vf_vlan_stripq_result {
13628         cmdline_fixed_string_t set;
13629         cmdline_fixed_string_t vf;
13630         cmdline_fixed_string_t vlan;
13631         cmdline_fixed_string_t stripq;
13632         portid_t port_id;
13633         uint16_t vf_id;
13634         cmdline_fixed_string_t on_off;
13635 };
13636
13637 /* Common CLI fields for vf vlan strip enable disable */
13638 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13639         TOKEN_STRING_INITIALIZER
13640                 (struct cmd_vf_vlan_stripq_result,
13641                  set, "set");
13642 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13643         TOKEN_STRING_INITIALIZER
13644                 (struct cmd_vf_vlan_stripq_result,
13645                  vf, "vf");
13646 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13647         TOKEN_STRING_INITIALIZER
13648                 (struct cmd_vf_vlan_stripq_result,
13649                  vlan, "vlan");
13650 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13651         TOKEN_STRING_INITIALIZER
13652                 (struct cmd_vf_vlan_stripq_result,
13653                  stripq, "stripq");
13654 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13655         TOKEN_NUM_INITIALIZER
13656                 (struct cmd_vf_vlan_stripq_result,
13657                  port_id, UINT16);
13658 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13659         TOKEN_NUM_INITIALIZER
13660                 (struct cmd_vf_vlan_stripq_result,
13661                  vf_id, UINT16);
13662 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13663         TOKEN_STRING_INITIALIZER
13664                 (struct cmd_vf_vlan_stripq_result,
13665                  on_off, "on#off");
13666
13667 static void
13668 cmd_set_vf_vlan_stripq_parsed(
13669         void *parsed_result,
13670         __rte_unused struct cmdline *cl,
13671         __rte_unused void *data)
13672 {
13673         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13674         int ret = -ENOTSUP;
13675
13676         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13677
13678         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13679                 return;
13680
13681 #ifdef RTE_LIBRTE_IXGBE_PMD
13682         if (ret == -ENOTSUP)
13683                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13684                         res->vf_id, is_on);
13685 #endif
13686 #ifdef RTE_LIBRTE_I40E_PMD
13687         if (ret == -ENOTSUP)
13688                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13689                         res->vf_id, is_on);
13690 #endif
13691 #ifdef RTE_LIBRTE_BNXT_PMD
13692         if (ret == -ENOTSUP)
13693                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13694                         res->vf_id, is_on);
13695 #endif
13696
13697         switch (ret) {
13698         case 0:
13699                 break;
13700         case -EINVAL:
13701                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13702                 break;
13703         case -ENODEV:
13704                 printf("invalid port_id %d\n", res->port_id);
13705                 break;
13706         case -ENOTSUP:
13707                 printf("function not implemented\n");
13708                 break;
13709         default:
13710                 printf("programming error: (%s)\n", strerror(-ret));
13711         }
13712 }
13713
13714 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13715         .f = cmd_set_vf_vlan_stripq_parsed,
13716         .data = NULL,
13717         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13718         .tokens = {
13719                 (void *)&cmd_vf_vlan_stripq_set,
13720                 (void *)&cmd_vf_vlan_stripq_vf,
13721                 (void *)&cmd_vf_vlan_stripq_vlan,
13722                 (void *)&cmd_vf_vlan_stripq_stripq,
13723                 (void *)&cmd_vf_vlan_stripq_port_id,
13724                 (void *)&cmd_vf_vlan_stripq_vf_id,
13725                 (void *)&cmd_vf_vlan_stripq_on_off,
13726                 NULL,
13727         },
13728 };
13729
13730 /* vf vlan insert configuration */
13731
13732 /* Common result structure for vf vlan insert */
13733 struct cmd_vf_vlan_insert_result {
13734         cmdline_fixed_string_t set;
13735         cmdline_fixed_string_t vf;
13736         cmdline_fixed_string_t vlan;
13737         cmdline_fixed_string_t insert;
13738         portid_t port_id;
13739         uint16_t vf_id;
13740         uint16_t vlan_id;
13741 };
13742
13743 /* Common CLI fields for vf vlan insert enable disable */
13744 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13745         TOKEN_STRING_INITIALIZER
13746                 (struct cmd_vf_vlan_insert_result,
13747                  set, "set");
13748 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13749         TOKEN_STRING_INITIALIZER
13750                 (struct cmd_vf_vlan_insert_result,
13751                  vf, "vf");
13752 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13753         TOKEN_STRING_INITIALIZER
13754                 (struct cmd_vf_vlan_insert_result,
13755                  vlan, "vlan");
13756 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13757         TOKEN_STRING_INITIALIZER
13758                 (struct cmd_vf_vlan_insert_result,
13759                  insert, "insert");
13760 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13761         TOKEN_NUM_INITIALIZER
13762                 (struct cmd_vf_vlan_insert_result,
13763                  port_id, UINT16);
13764 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13765         TOKEN_NUM_INITIALIZER
13766                 (struct cmd_vf_vlan_insert_result,
13767                  vf_id, UINT16);
13768 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13769         TOKEN_NUM_INITIALIZER
13770                 (struct cmd_vf_vlan_insert_result,
13771                  vlan_id, UINT16);
13772
13773 static void
13774 cmd_set_vf_vlan_insert_parsed(
13775         void *parsed_result,
13776         __rte_unused struct cmdline *cl,
13777         __rte_unused void *data)
13778 {
13779         struct cmd_vf_vlan_insert_result *res = parsed_result;
13780         int ret = -ENOTSUP;
13781
13782         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13783                 return;
13784
13785 #ifdef RTE_LIBRTE_IXGBE_PMD
13786         if (ret == -ENOTSUP)
13787                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13788                         res->vlan_id);
13789 #endif
13790 #ifdef RTE_LIBRTE_I40E_PMD
13791         if (ret == -ENOTSUP)
13792                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13793                         res->vlan_id);
13794 #endif
13795 #ifdef RTE_LIBRTE_BNXT_PMD
13796         if (ret == -ENOTSUP)
13797                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13798                         res->vlan_id);
13799 #endif
13800
13801         switch (ret) {
13802         case 0:
13803                 break;
13804         case -EINVAL:
13805                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13806                 break;
13807         case -ENODEV:
13808                 printf("invalid port_id %d\n", res->port_id);
13809                 break;
13810         case -ENOTSUP:
13811                 printf("function not implemented\n");
13812                 break;
13813         default:
13814                 printf("programming error: (%s)\n", strerror(-ret));
13815         }
13816 }
13817
13818 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13819         .f = cmd_set_vf_vlan_insert_parsed,
13820         .data = NULL,
13821         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13822         .tokens = {
13823                 (void *)&cmd_vf_vlan_insert_set,
13824                 (void *)&cmd_vf_vlan_insert_vf,
13825                 (void *)&cmd_vf_vlan_insert_vlan,
13826                 (void *)&cmd_vf_vlan_insert_insert,
13827                 (void *)&cmd_vf_vlan_insert_port_id,
13828                 (void *)&cmd_vf_vlan_insert_vf_id,
13829                 (void *)&cmd_vf_vlan_insert_vlan_id,
13830                 NULL,
13831         },
13832 };
13833
13834 /* tx loopback configuration */
13835
13836 /* Common result structure for tx loopback */
13837 struct cmd_tx_loopback_result {
13838         cmdline_fixed_string_t set;
13839         cmdline_fixed_string_t tx;
13840         cmdline_fixed_string_t loopback;
13841         portid_t port_id;
13842         cmdline_fixed_string_t on_off;
13843 };
13844
13845 /* Common CLI fields for tx loopback enable disable */
13846 cmdline_parse_token_string_t cmd_tx_loopback_set =
13847         TOKEN_STRING_INITIALIZER
13848                 (struct cmd_tx_loopback_result,
13849                  set, "set");
13850 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13851         TOKEN_STRING_INITIALIZER
13852                 (struct cmd_tx_loopback_result,
13853                  tx, "tx");
13854 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13855         TOKEN_STRING_INITIALIZER
13856                 (struct cmd_tx_loopback_result,
13857                  loopback, "loopback");
13858 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13859         TOKEN_NUM_INITIALIZER
13860                 (struct cmd_tx_loopback_result,
13861                  port_id, UINT16);
13862 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13863         TOKEN_STRING_INITIALIZER
13864                 (struct cmd_tx_loopback_result,
13865                  on_off, "on#off");
13866
13867 static void
13868 cmd_set_tx_loopback_parsed(
13869         void *parsed_result,
13870         __rte_unused struct cmdline *cl,
13871         __rte_unused void *data)
13872 {
13873         struct cmd_tx_loopback_result *res = parsed_result;
13874         int ret = -ENOTSUP;
13875
13876         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13877
13878         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13879                 return;
13880
13881 #ifdef RTE_LIBRTE_IXGBE_PMD
13882         if (ret == -ENOTSUP)
13883                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13884 #endif
13885 #ifdef RTE_LIBRTE_I40E_PMD
13886         if (ret == -ENOTSUP)
13887                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13888 #endif
13889 #ifdef RTE_LIBRTE_BNXT_PMD
13890         if (ret == -ENOTSUP)
13891                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13892 #endif
13893 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13894         if (ret == -ENOTSUP)
13895                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13896 #endif
13897
13898         switch (ret) {
13899         case 0:
13900                 break;
13901         case -EINVAL:
13902                 printf("invalid is_on %d\n", is_on);
13903                 break;
13904         case -ENODEV:
13905                 printf("invalid port_id %d\n", res->port_id);
13906                 break;
13907         case -ENOTSUP:
13908                 printf("function not implemented\n");
13909                 break;
13910         default:
13911                 printf("programming error: (%s)\n", strerror(-ret));
13912         }
13913 }
13914
13915 cmdline_parse_inst_t cmd_set_tx_loopback = {
13916         .f = cmd_set_tx_loopback_parsed,
13917         .data = NULL,
13918         .help_str = "set tx loopback <port_id> on|off",
13919         .tokens = {
13920                 (void *)&cmd_tx_loopback_set,
13921                 (void *)&cmd_tx_loopback_tx,
13922                 (void *)&cmd_tx_loopback_loopback,
13923                 (void *)&cmd_tx_loopback_port_id,
13924                 (void *)&cmd_tx_loopback_on_off,
13925                 NULL,
13926         },
13927 };
13928
13929 /* all queues drop enable configuration */
13930
13931 /* Common result structure for all queues drop enable */
13932 struct cmd_all_queues_drop_en_result {
13933         cmdline_fixed_string_t set;
13934         cmdline_fixed_string_t all;
13935         cmdline_fixed_string_t queues;
13936         cmdline_fixed_string_t drop;
13937         portid_t port_id;
13938         cmdline_fixed_string_t on_off;
13939 };
13940
13941 /* Common CLI fields for tx loopback enable disable */
13942 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13943         TOKEN_STRING_INITIALIZER
13944                 (struct cmd_all_queues_drop_en_result,
13945                  set, "set");
13946 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13947         TOKEN_STRING_INITIALIZER
13948                 (struct cmd_all_queues_drop_en_result,
13949                  all, "all");
13950 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13951         TOKEN_STRING_INITIALIZER
13952                 (struct cmd_all_queues_drop_en_result,
13953                  queues, "queues");
13954 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13955         TOKEN_STRING_INITIALIZER
13956                 (struct cmd_all_queues_drop_en_result,
13957                  drop, "drop");
13958 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13959         TOKEN_NUM_INITIALIZER
13960                 (struct cmd_all_queues_drop_en_result,
13961                  port_id, UINT16);
13962 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13963         TOKEN_STRING_INITIALIZER
13964                 (struct cmd_all_queues_drop_en_result,
13965                  on_off, "on#off");
13966
13967 static void
13968 cmd_set_all_queues_drop_en_parsed(
13969         void *parsed_result,
13970         __rte_unused struct cmdline *cl,
13971         __rte_unused void *data)
13972 {
13973         struct cmd_all_queues_drop_en_result *res = parsed_result;
13974         int ret = -ENOTSUP;
13975         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13976
13977         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13978                 return;
13979
13980 #ifdef RTE_LIBRTE_IXGBE_PMD
13981         if (ret == -ENOTSUP)
13982                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13983 #endif
13984 #ifdef RTE_LIBRTE_BNXT_PMD
13985         if (ret == -ENOTSUP)
13986                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13987 #endif
13988         switch (ret) {
13989         case 0:
13990                 break;
13991         case -EINVAL:
13992                 printf("invalid is_on %d\n", is_on);
13993                 break;
13994         case -ENODEV:
13995                 printf("invalid port_id %d\n", res->port_id);
13996                 break;
13997         case -ENOTSUP:
13998                 printf("function not implemented\n");
13999                 break;
14000         default:
14001                 printf("programming error: (%s)\n", strerror(-ret));
14002         }
14003 }
14004
14005 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14006         .f = cmd_set_all_queues_drop_en_parsed,
14007         .data = NULL,
14008         .help_str = "set all queues drop <port_id> on|off",
14009         .tokens = {
14010                 (void *)&cmd_all_queues_drop_en_set,
14011                 (void *)&cmd_all_queues_drop_en_all,
14012                 (void *)&cmd_all_queues_drop_en_queues,
14013                 (void *)&cmd_all_queues_drop_en_drop,
14014                 (void *)&cmd_all_queues_drop_en_port_id,
14015                 (void *)&cmd_all_queues_drop_en_on_off,
14016                 NULL,
14017         },
14018 };
14019
14020 /* vf split drop enable configuration */
14021
14022 /* Common result structure for vf split drop enable */
14023 struct cmd_vf_split_drop_en_result {
14024         cmdline_fixed_string_t set;
14025         cmdline_fixed_string_t vf;
14026         cmdline_fixed_string_t split;
14027         cmdline_fixed_string_t drop;
14028         portid_t port_id;
14029         uint16_t vf_id;
14030         cmdline_fixed_string_t on_off;
14031 };
14032
14033 /* Common CLI fields for vf split drop enable disable */
14034 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14035         TOKEN_STRING_INITIALIZER
14036                 (struct cmd_vf_split_drop_en_result,
14037                  set, "set");
14038 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14039         TOKEN_STRING_INITIALIZER
14040                 (struct cmd_vf_split_drop_en_result,
14041                  vf, "vf");
14042 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14043         TOKEN_STRING_INITIALIZER
14044                 (struct cmd_vf_split_drop_en_result,
14045                  split, "split");
14046 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14047         TOKEN_STRING_INITIALIZER
14048                 (struct cmd_vf_split_drop_en_result,
14049                  drop, "drop");
14050 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14051         TOKEN_NUM_INITIALIZER
14052                 (struct cmd_vf_split_drop_en_result,
14053                  port_id, UINT16);
14054 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14055         TOKEN_NUM_INITIALIZER
14056                 (struct cmd_vf_split_drop_en_result,
14057                  vf_id, UINT16);
14058 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14059         TOKEN_STRING_INITIALIZER
14060                 (struct cmd_vf_split_drop_en_result,
14061                  on_off, "on#off");
14062
14063 static void
14064 cmd_set_vf_split_drop_en_parsed(
14065         void *parsed_result,
14066         __rte_unused struct cmdline *cl,
14067         __rte_unused void *data)
14068 {
14069         struct cmd_vf_split_drop_en_result *res = parsed_result;
14070         int ret = -ENOTSUP;
14071         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14072
14073         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14074                 return;
14075
14076 #ifdef RTE_LIBRTE_IXGBE_PMD
14077         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14078                         is_on);
14079 #endif
14080         switch (ret) {
14081         case 0:
14082                 break;
14083         case -EINVAL:
14084                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14085                 break;
14086         case -ENODEV:
14087                 printf("invalid port_id %d\n", res->port_id);
14088                 break;
14089         case -ENOTSUP:
14090                 printf("not supported on port %d\n", res->port_id);
14091                 break;
14092         default:
14093                 printf("programming error: (%s)\n", strerror(-ret));
14094         }
14095 }
14096
14097 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14098         .f = cmd_set_vf_split_drop_en_parsed,
14099         .data = NULL,
14100         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14101         .tokens = {
14102                 (void *)&cmd_vf_split_drop_en_set,
14103                 (void *)&cmd_vf_split_drop_en_vf,
14104                 (void *)&cmd_vf_split_drop_en_split,
14105                 (void *)&cmd_vf_split_drop_en_drop,
14106                 (void *)&cmd_vf_split_drop_en_port_id,
14107                 (void *)&cmd_vf_split_drop_en_vf_id,
14108                 (void *)&cmd_vf_split_drop_en_on_off,
14109                 NULL,
14110         },
14111 };
14112
14113 /* vf mac address configuration */
14114
14115 /* Common result structure for vf mac address */
14116 struct cmd_set_vf_mac_addr_result {
14117         cmdline_fixed_string_t set;
14118         cmdline_fixed_string_t vf;
14119         cmdline_fixed_string_t mac;
14120         cmdline_fixed_string_t addr;
14121         portid_t port_id;
14122         uint16_t vf_id;
14123         struct rte_ether_addr mac_addr;
14124
14125 };
14126
14127 /* Common CLI fields for vf split drop enable disable */
14128 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14129         TOKEN_STRING_INITIALIZER
14130                 (struct cmd_set_vf_mac_addr_result,
14131                  set, "set");
14132 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14133         TOKEN_STRING_INITIALIZER
14134                 (struct cmd_set_vf_mac_addr_result,
14135                  vf, "vf");
14136 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14137         TOKEN_STRING_INITIALIZER
14138                 (struct cmd_set_vf_mac_addr_result,
14139                  mac, "mac");
14140 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14141         TOKEN_STRING_INITIALIZER
14142                 (struct cmd_set_vf_mac_addr_result,
14143                  addr, "addr");
14144 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14145         TOKEN_NUM_INITIALIZER
14146                 (struct cmd_set_vf_mac_addr_result,
14147                  port_id, UINT16);
14148 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14149         TOKEN_NUM_INITIALIZER
14150                 (struct cmd_set_vf_mac_addr_result,
14151                  vf_id, UINT16);
14152 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14153         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14154                  mac_addr);
14155
14156 static void
14157 cmd_set_vf_mac_addr_parsed(
14158         void *parsed_result,
14159         __rte_unused struct cmdline *cl,
14160         __rte_unused void *data)
14161 {
14162         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14163         int ret = -ENOTSUP;
14164
14165         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14166                 return;
14167
14168 #ifdef RTE_LIBRTE_IXGBE_PMD
14169         if (ret == -ENOTSUP)
14170                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14171                                 &res->mac_addr);
14172 #endif
14173 #ifdef RTE_LIBRTE_I40E_PMD
14174         if (ret == -ENOTSUP)
14175                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14176                                 &res->mac_addr);
14177 #endif
14178 #ifdef RTE_LIBRTE_BNXT_PMD
14179         if (ret == -ENOTSUP)
14180                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14181                                 &res->mac_addr);
14182 #endif
14183
14184         switch (ret) {
14185         case 0:
14186                 break;
14187         case -EINVAL:
14188                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14189                 break;
14190         case -ENODEV:
14191                 printf("invalid port_id %d\n", res->port_id);
14192                 break;
14193         case -ENOTSUP:
14194                 printf("function not implemented\n");
14195                 break;
14196         default:
14197                 printf("programming error: (%s)\n", strerror(-ret));
14198         }
14199 }
14200
14201 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14202         .f = cmd_set_vf_mac_addr_parsed,
14203         .data = NULL,
14204         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14205         .tokens = {
14206                 (void *)&cmd_set_vf_mac_addr_set,
14207                 (void *)&cmd_set_vf_mac_addr_vf,
14208                 (void *)&cmd_set_vf_mac_addr_mac,
14209                 (void *)&cmd_set_vf_mac_addr_addr,
14210                 (void *)&cmd_set_vf_mac_addr_port_id,
14211                 (void *)&cmd_set_vf_mac_addr_vf_id,
14212                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14213                 NULL,
14214         },
14215 };
14216
14217 /* MACsec configuration */
14218
14219 /* Common result structure for MACsec offload enable */
14220 struct cmd_macsec_offload_on_result {
14221         cmdline_fixed_string_t set;
14222         cmdline_fixed_string_t macsec;
14223         cmdline_fixed_string_t offload;
14224         portid_t port_id;
14225         cmdline_fixed_string_t on;
14226         cmdline_fixed_string_t encrypt;
14227         cmdline_fixed_string_t en_on_off;
14228         cmdline_fixed_string_t replay_protect;
14229         cmdline_fixed_string_t rp_on_off;
14230 };
14231
14232 /* Common CLI fields for MACsec offload disable */
14233 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14234         TOKEN_STRING_INITIALIZER
14235                 (struct cmd_macsec_offload_on_result,
14236                  set, "set");
14237 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14238         TOKEN_STRING_INITIALIZER
14239                 (struct cmd_macsec_offload_on_result,
14240                  macsec, "macsec");
14241 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14242         TOKEN_STRING_INITIALIZER
14243                 (struct cmd_macsec_offload_on_result,
14244                  offload, "offload");
14245 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14246         TOKEN_NUM_INITIALIZER
14247                 (struct cmd_macsec_offload_on_result,
14248                  port_id, UINT16);
14249 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14250         TOKEN_STRING_INITIALIZER
14251                 (struct cmd_macsec_offload_on_result,
14252                  on, "on");
14253 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14254         TOKEN_STRING_INITIALIZER
14255                 (struct cmd_macsec_offload_on_result,
14256                  encrypt, "encrypt");
14257 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14258         TOKEN_STRING_INITIALIZER
14259                 (struct cmd_macsec_offload_on_result,
14260                  en_on_off, "on#off");
14261 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14262         TOKEN_STRING_INITIALIZER
14263                 (struct cmd_macsec_offload_on_result,
14264                  replay_protect, "replay-protect");
14265 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14266         TOKEN_STRING_INITIALIZER
14267                 (struct cmd_macsec_offload_on_result,
14268                  rp_on_off, "on#off");
14269
14270 static void
14271 cmd_set_macsec_offload_on_parsed(
14272         void *parsed_result,
14273         __rte_unused struct cmdline *cl,
14274         __rte_unused void *data)
14275 {
14276         struct cmd_macsec_offload_on_result *res = parsed_result;
14277         int ret = -ENOTSUP;
14278         portid_t port_id = res->port_id;
14279         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14280         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14281         struct rte_eth_dev_info dev_info;
14282
14283         if (port_id_is_invalid(port_id, ENABLED_WARN))
14284                 return;
14285         if (!port_is_stopped(port_id)) {
14286                 printf("Please stop port %d first\n", port_id);
14287                 return;
14288         }
14289
14290         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14291         if (ret != 0)
14292                 return;
14293
14294         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14295 #ifdef RTE_LIBRTE_IXGBE_PMD
14296                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14297 #endif
14298         }
14299         RTE_SET_USED(en);
14300         RTE_SET_USED(rp);
14301
14302         switch (ret) {
14303         case 0:
14304                 ports[port_id].dev_conf.txmode.offloads |=
14305                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14306                 cmd_reconfig_device_queue(port_id, 1, 1);
14307                 break;
14308         case -ENODEV:
14309                 printf("invalid port_id %d\n", port_id);
14310                 break;
14311         case -ENOTSUP:
14312                 printf("not supported on port %d\n", port_id);
14313                 break;
14314         default:
14315                 printf("programming error: (%s)\n", strerror(-ret));
14316         }
14317 }
14318
14319 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14320         .f = cmd_set_macsec_offload_on_parsed,
14321         .data = NULL,
14322         .help_str = "set macsec offload <port_id> on "
14323                 "encrypt on|off replay-protect on|off",
14324         .tokens = {
14325                 (void *)&cmd_macsec_offload_on_set,
14326                 (void *)&cmd_macsec_offload_on_macsec,
14327                 (void *)&cmd_macsec_offload_on_offload,
14328                 (void *)&cmd_macsec_offload_on_port_id,
14329                 (void *)&cmd_macsec_offload_on_on,
14330                 (void *)&cmd_macsec_offload_on_encrypt,
14331                 (void *)&cmd_macsec_offload_on_en_on_off,
14332                 (void *)&cmd_macsec_offload_on_replay_protect,
14333                 (void *)&cmd_macsec_offload_on_rp_on_off,
14334                 NULL,
14335         },
14336 };
14337
14338 /* Common result structure for MACsec offload disable */
14339 struct cmd_macsec_offload_off_result {
14340         cmdline_fixed_string_t set;
14341         cmdline_fixed_string_t macsec;
14342         cmdline_fixed_string_t offload;
14343         portid_t port_id;
14344         cmdline_fixed_string_t off;
14345 };
14346
14347 /* Common CLI fields for MACsec offload disable */
14348 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14349         TOKEN_STRING_INITIALIZER
14350                 (struct cmd_macsec_offload_off_result,
14351                  set, "set");
14352 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14353         TOKEN_STRING_INITIALIZER
14354                 (struct cmd_macsec_offload_off_result,
14355                  macsec, "macsec");
14356 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14357         TOKEN_STRING_INITIALIZER
14358                 (struct cmd_macsec_offload_off_result,
14359                  offload, "offload");
14360 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14361         TOKEN_NUM_INITIALIZER
14362                 (struct cmd_macsec_offload_off_result,
14363                  port_id, UINT16);
14364 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14365         TOKEN_STRING_INITIALIZER
14366                 (struct cmd_macsec_offload_off_result,
14367                  off, "off");
14368
14369 static void
14370 cmd_set_macsec_offload_off_parsed(
14371         void *parsed_result,
14372         __rte_unused struct cmdline *cl,
14373         __rte_unused void *data)
14374 {
14375         struct cmd_macsec_offload_off_result *res = parsed_result;
14376         int ret = -ENOTSUP;
14377         struct rte_eth_dev_info dev_info;
14378         portid_t port_id = res->port_id;
14379
14380         if (port_id_is_invalid(port_id, ENABLED_WARN))
14381                 return;
14382         if (!port_is_stopped(port_id)) {
14383                 printf("Please stop port %d first\n", port_id);
14384                 return;
14385         }
14386
14387         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14388         if (ret != 0)
14389                 return;
14390
14391         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14392 #ifdef RTE_LIBRTE_IXGBE_PMD
14393                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14394 #endif
14395         }
14396         switch (ret) {
14397         case 0:
14398                 ports[port_id].dev_conf.txmode.offloads &=
14399                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14400                 cmd_reconfig_device_queue(port_id, 1, 1);
14401                 break;
14402         case -ENODEV:
14403                 printf("invalid port_id %d\n", port_id);
14404                 break;
14405         case -ENOTSUP:
14406                 printf("not supported on port %d\n", port_id);
14407                 break;
14408         default:
14409                 printf("programming error: (%s)\n", strerror(-ret));
14410         }
14411 }
14412
14413 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14414         .f = cmd_set_macsec_offload_off_parsed,
14415         .data = NULL,
14416         .help_str = "set macsec offload <port_id> off",
14417         .tokens = {
14418                 (void *)&cmd_macsec_offload_off_set,
14419                 (void *)&cmd_macsec_offload_off_macsec,
14420                 (void *)&cmd_macsec_offload_off_offload,
14421                 (void *)&cmd_macsec_offload_off_port_id,
14422                 (void *)&cmd_macsec_offload_off_off,
14423                 NULL,
14424         },
14425 };
14426
14427 /* Common result structure for MACsec secure connection configure */
14428 struct cmd_macsec_sc_result {
14429         cmdline_fixed_string_t set;
14430         cmdline_fixed_string_t macsec;
14431         cmdline_fixed_string_t sc;
14432         cmdline_fixed_string_t tx_rx;
14433         portid_t port_id;
14434         struct rte_ether_addr mac;
14435         uint16_t pi;
14436 };
14437
14438 /* Common CLI fields for MACsec secure connection configure */
14439 cmdline_parse_token_string_t cmd_macsec_sc_set =
14440         TOKEN_STRING_INITIALIZER
14441                 (struct cmd_macsec_sc_result,
14442                  set, "set");
14443 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14444         TOKEN_STRING_INITIALIZER
14445                 (struct cmd_macsec_sc_result,
14446                  macsec, "macsec");
14447 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14448         TOKEN_STRING_INITIALIZER
14449                 (struct cmd_macsec_sc_result,
14450                  sc, "sc");
14451 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14452         TOKEN_STRING_INITIALIZER
14453                 (struct cmd_macsec_sc_result,
14454                  tx_rx, "tx#rx");
14455 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14456         TOKEN_NUM_INITIALIZER
14457                 (struct cmd_macsec_sc_result,
14458                  port_id, UINT16);
14459 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14460         TOKEN_ETHERADDR_INITIALIZER
14461                 (struct cmd_macsec_sc_result,
14462                  mac);
14463 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14464         TOKEN_NUM_INITIALIZER
14465                 (struct cmd_macsec_sc_result,
14466                  pi, UINT16);
14467
14468 static void
14469 cmd_set_macsec_sc_parsed(
14470         void *parsed_result,
14471         __rte_unused struct cmdline *cl,
14472         __rte_unused void *data)
14473 {
14474         struct cmd_macsec_sc_result *res = parsed_result;
14475         int ret = -ENOTSUP;
14476         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14477
14478 #ifdef RTE_LIBRTE_IXGBE_PMD
14479         ret = is_tx ?
14480                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14481                                 res->mac.addr_bytes) :
14482                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14483                                 res->mac.addr_bytes, res->pi);
14484 #endif
14485         RTE_SET_USED(is_tx);
14486
14487         switch (ret) {
14488         case 0:
14489                 break;
14490         case -ENODEV:
14491                 printf("invalid port_id %d\n", res->port_id);
14492                 break;
14493         case -ENOTSUP:
14494                 printf("not supported on port %d\n", res->port_id);
14495                 break;
14496         default:
14497                 printf("programming error: (%s)\n", strerror(-ret));
14498         }
14499 }
14500
14501 cmdline_parse_inst_t cmd_set_macsec_sc = {
14502         .f = cmd_set_macsec_sc_parsed,
14503         .data = NULL,
14504         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14505         .tokens = {
14506                 (void *)&cmd_macsec_sc_set,
14507                 (void *)&cmd_macsec_sc_macsec,
14508                 (void *)&cmd_macsec_sc_sc,
14509                 (void *)&cmd_macsec_sc_tx_rx,
14510                 (void *)&cmd_macsec_sc_port_id,
14511                 (void *)&cmd_macsec_sc_mac,
14512                 (void *)&cmd_macsec_sc_pi,
14513                 NULL,
14514         },
14515 };
14516
14517 /* Common result structure for MACsec secure connection configure */
14518 struct cmd_macsec_sa_result {
14519         cmdline_fixed_string_t set;
14520         cmdline_fixed_string_t macsec;
14521         cmdline_fixed_string_t sa;
14522         cmdline_fixed_string_t tx_rx;
14523         portid_t port_id;
14524         uint8_t idx;
14525         uint8_t an;
14526         uint32_t pn;
14527         cmdline_fixed_string_t key;
14528 };
14529
14530 /* Common CLI fields for MACsec secure connection configure */
14531 cmdline_parse_token_string_t cmd_macsec_sa_set =
14532         TOKEN_STRING_INITIALIZER
14533                 (struct cmd_macsec_sa_result,
14534                  set, "set");
14535 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14536         TOKEN_STRING_INITIALIZER
14537                 (struct cmd_macsec_sa_result,
14538                  macsec, "macsec");
14539 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14540         TOKEN_STRING_INITIALIZER
14541                 (struct cmd_macsec_sa_result,
14542                  sa, "sa");
14543 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14544         TOKEN_STRING_INITIALIZER
14545                 (struct cmd_macsec_sa_result,
14546                  tx_rx, "tx#rx");
14547 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14548         TOKEN_NUM_INITIALIZER
14549                 (struct cmd_macsec_sa_result,
14550                  port_id, UINT16);
14551 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14552         TOKEN_NUM_INITIALIZER
14553                 (struct cmd_macsec_sa_result,
14554                  idx, UINT8);
14555 cmdline_parse_token_num_t cmd_macsec_sa_an =
14556         TOKEN_NUM_INITIALIZER
14557                 (struct cmd_macsec_sa_result,
14558                  an, UINT8);
14559 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14560         TOKEN_NUM_INITIALIZER
14561                 (struct cmd_macsec_sa_result,
14562                  pn, UINT32);
14563 cmdline_parse_token_string_t cmd_macsec_sa_key =
14564         TOKEN_STRING_INITIALIZER
14565                 (struct cmd_macsec_sa_result,
14566                  key, NULL);
14567
14568 static void
14569 cmd_set_macsec_sa_parsed(
14570         void *parsed_result,
14571         __rte_unused struct cmdline *cl,
14572         __rte_unused void *data)
14573 {
14574         struct cmd_macsec_sa_result *res = parsed_result;
14575         int ret = -ENOTSUP;
14576         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14577         uint8_t key[16] = { 0 };
14578         uint8_t xdgt0;
14579         uint8_t xdgt1;
14580         int key_len;
14581         int i;
14582
14583         key_len = strlen(res->key) / 2;
14584         if (key_len > 16)
14585                 key_len = 16;
14586
14587         for (i = 0; i < key_len; i++) {
14588                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14589                 if (xdgt0 == 0xFF)
14590                         return;
14591                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14592                 if (xdgt1 == 0xFF)
14593                         return;
14594                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14595         }
14596
14597 #ifdef RTE_LIBRTE_IXGBE_PMD
14598         ret = is_tx ?
14599                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14600                         res->idx, res->an, res->pn, key) :
14601                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14602                         res->idx, res->an, res->pn, key);
14603 #endif
14604         RTE_SET_USED(is_tx);
14605         RTE_SET_USED(key);
14606
14607         switch (ret) {
14608         case 0:
14609                 break;
14610         case -EINVAL:
14611                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14612                 break;
14613         case -ENODEV:
14614                 printf("invalid port_id %d\n", res->port_id);
14615                 break;
14616         case -ENOTSUP:
14617                 printf("not supported on port %d\n", res->port_id);
14618                 break;
14619         default:
14620                 printf("programming error: (%s)\n", strerror(-ret));
14621         }
14622 }
14623
14624 cmdline_parse_inst_t cmd_set_macsec_sa = {
14625         .f = cmd_set_macsec_sa_parsed,
14626         .data = NULL,
14627         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14628         .tokens = {
14629                 (void *)&cmd_macsec_sa_set,
14630                 (void *)&cmd_macsec_sa_macsec,
14631                 (void *)&cmd_macsec_sa_sa,
14632                 (void *)&cmd_macsec_sa_tx_rx,
14633                 (void *)&cmd_macsec_sa_port_id,
14634                 (void *)&cmd_macsec_sa_idx,
14635                 (void *)&cmd_macsec_sa_an,
14636                 (void *)&cmd_macsec_sa_pn,
14637                 (void *)&cmd_macsec_sa_key,
14638                 NULL,
14639         },
14640 };
14641
14642 /* VF unicast promiscuous mode configuration */
14643
14644 /* Common result structure for VF unicast promiscuous mode */
14645 struct cmd_vf_promisc_result {
14646         cmdline_fixed_string_t set;
14647         cmdline_fixed_string_t vf;
14648         cmdline_fixed_string_t promisc;
14649         portid_t port_id;
14650         uint32_t vf_id;
14651         cmdline_fixed_string_t on_off;
14652 };
14653
14654 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14655 cmdline_parse_token_string_t cmd_vf_promisc_set =
14656         TOKEN_STRING_INITIALIZER
14657                 (struct cmd_vf_promisc_result,
14658                  set, "set");
14659 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14660         TOKEN_STRING_INITIALIZER
14661                 (struct cmd_vf_promisc_result,
14662                  vf, "vf");
14663 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14664         TOKEN_STRING_INITIALIZER
14665                 (struct cmd_vf_promisc_result,
14666                  promisc, "promisc");
14667 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14668         TOKEN_NUM_INITIALIZER
14669                 (struct cmd_vf_promisc_result,
14670                  port_id, UINT16);
14671 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14672         TOKEN_NUM_INITIALIZER
14673                 (struct cmd_vf_promisc_result,
14674                  vf_id, UINT32);
14675 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14676         TOKEN_STRING_INITIALIZER
14677                 (struct cmd_vf_promisc_result,
14678                  on_off, "on#off");
14679
14680 static void
14681 cmd_set_vf_promisc_parsed(
14682         void *parsed_result,
14683         __rte_unused struct cmdline *cl,
14684         __rte_unused void *data)
14685 {
14686         struct cmd_vf_promisc_result *res = parsed_result;
14687         int ret = -ENOTSUP;
14688
14689         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14690
14691         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14692                 return;
14693
14694 #ifdef RTE_LIBRTE_I40E_PMD
14695         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14696                                                   res->vf_id, is_on);
14697 #endif
14698
14699         switch (ret) {
14700         case 0:
14701                 break;
14702         case -EINVAL:
14703                 printf("invalid vf_id %d\n", res->vf_id);
14704                 break;
14705         case -ENODEV:
14706                 printf("invalid port_id %d\n", res->port_id);
14707                 break;
14708         case -ENOTSUP:
14709                 printf("function not implemented\n");
14710                 break;
14711         default:
14712                 printf("programming error: (%s)\n", strerror(-ret));
14713         }
14714 }
14715
14716 cmdline_parse_inst_t cmd_set_vf_promisc = {
14717         .f = cmd_set_vf_promisc_parsed,
14718         .data = NULL,
14719         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14720                 "Set unicast promiscuous mode for a VF from the PF",
14721         .tokens = {
14722                 (void *)&cmd_vf_promisc_set,
14723                 (void *)&cmd_vf_promisc_vf,
14724                 (void *)&cmd_vf_promisc_promisc,
14725                 (void *)&cmd_vf_promisc_port_id,
14726                 (void *)&cmd_vf_promisc_vf_id,
14727                 (void *)&cmd_vf_promisc_on_off,
14728                 NULL,
14729         },
14730 };
14731
14732 /* VF multicast promiscuous mode configuration */
14733
14734 /* Common result structure for VF multicast promiscuous mode */
14735 struct cmd_vf_allmulti_result {
14736         cmdline_fixed_string_t set;
14737         cmdline_fixed_string_t vf;
14738         cmdline_fixed_string_t allmulti;
14739         portid_t port_id;
14740         uint32_t vf_id;
14741         cmdline_fixed_string_t on_off;
14742 };
14743
14744 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14745 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14746         TOKEN_STRING_INITIALIZER
14747                 (struct cmd_vf_allmulti_result,
14748                  set, "set");
14749 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14750         TOKEN_STRING_INITIALIZER
14751                 (struct cmd_vf_allmulti_result,
14752                  vf, "vf");
14753 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14754         TOKEN_STRING_INITIALIZER
14755                 (struct cmd_vf_allmulti_result,
14756                  allmulti, "allmulti");
14757 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14758         TOKEN_NUM_INITIALIZER
14759                 (struct cmd_vf_allmulti_result,
14760                  port_id, UINT16);
14761 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14762         TOKEN_NUM_INITIALIZER
14763                 (struct cmd_vf_allmulti_result,
14764                  vf_id, UINT32);
14765 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14766         TOKEN_STRING_INITIALIZER
14767                 (struct cmd_vf_allmulti_result,
14768                  on_off, "on#off");
14769
14770 static void
14771 cmd_set_vf_allmulti_parsed(
14772         void *parsed_result,
14773         __rte_unused struct cmdline *cl,
14774         __rte_unused void *data)
14775 {
14776         struct cmd_vf_allmulti_result *res = parsed_result;
14777         int ret = -ENOTSUP;
14778
14779         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14780
14781         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14782                 return;
14783
14784 #ifdef RTE_LIBRTE_I40E_PMD
14785         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14786                                                     res->vf_id, is_on);
14787 #endif
14788
14789         switch (ret) {
14790         case 0:
14791                 break;
14792         case -EINVAL:
14793                 printf("invalid vf_id %d\n", res->vf_id);
14794                 break;
14795         case -ENODEV:
14796                 printf("invalid port_id %d\n", res->port_id);
14797                 break;
14798         case -ENOTSUP:
14799                 printf("function not implemented\n");
14800                 break;
14801         default:
14802                 printf("programming error: (%s)\n", strerror(-ret));
14803         }
14804 }
14805
14806 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14807         .f = cmd_set_vf_allmulti_parsed,
14808         .data = NULL,
14809         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14810                 "Set multicast promiscuous mode for a VF from the PF",
14811         .tokens = {
14812                 (void *)&cmd_vf_allmulti_set,
14813                 (void *)&cmd_vf_allmulti_vf,
14814                 (void *)&cmd_vf_allmulti_allmulti,
14815                 (void *)&cmd_vf_allmulti_port_id,
14816                 (void *)&cmd_vf_allmulti_vf_id,
14817                 (void *)&cmd_vf_allmulti_on_off,
14818                 NULL,
14819         },
14820 };
14821
14822 /* vf broadcast mode configuration */
14823
14824 /* Common result structure for vf broadcast */
14825 struct cmd_set_vf_broadcast_result {
14826         cmdline_fixed_string_t set;
14827         cmdline_fixed_string_t vf;
14828         cmdline_fixed_string_t broadcast;
14829         portid_t port_id;
14830         uint16_t vf_id;
14831         cmdline_fixed_string_t on_off;
14832 };
14833
14834 /* Common CLI fields for vf broadcast enable disable */
14835 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14836         TOKEN_STRING_INITIALIZER
14837                 (struct cmd_set_vf_broadcast_result,
14838                  set, "set");
14839 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14840         TOKEN_STRING_INITIALIZER
14841                 (struct cmd_set_vf_broadcast_result,
14842                  vf, "vf");
14843 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14844         TOKEN_STRING_INITIALIZER
14845                 (struct cmd_set_vf_broadcast_result,
14846                  broadcast, "broadcast");
14847 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14848         TOKEN_NUM_INITIALIZER
14849                 (struct cmd_set_vf_broadcast_result,
14850                  port_id, UINT16);
14851 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14852         TOKEN_NUM_INITIALIZER
14853                 (struct cmd_set_vf_broadcast_result,
14854                  vf_id, UINT16);
14855 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14856         TOKEN_STRING_INITIALIZER
14857                 (struct cmd_set_vf_broadcast_result,
14858                  on_off, "on#off");
14859
14860 static void
14861 cmd_set_vf_broadcast_parsed(
14862         void *parsed_result,
14863         __rte_unused struct cmdline *cl,
14864         __rte_unused void *data)
14865 {
14866         struct cmd_set_vf_broadcast_result *res = parsed_result;
14867         int ret = -ENOTSUP;
14868
14869         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14870
14871         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14872                 return;
14873
14874 #ifdef RTE_LIBRTE_I40E_PMD
14875         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14876                                             res->vf_id, is_on);
14877 #endif
14878
14879         switch (ret) {
14880         case 0:
14881                 break;
14882         case -EINVAL:
14883                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14884                 break;
14885         case -ENODEV:
14886                 printf("invalid port_id %d\n", res->port_id);
14887                 break;
14888         case -ENOTSUP:
14889                 printf("function not implemented\n");
14890                 break;
14891         default:
14892                 printf("programming error: (%s)\n", strerror(-ret));
14893         }
14894 }
14895
14896 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14897         .f = cmd_set_vf_broadcast_parsed,
14898         .data = NULL,
14899         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14900         .tokens = {
14901                 (void *)&cmd_set_vf_broadcast_set,
14902                 (void *)&cmd_set_vf_broadcast_vf,
14903                 (void *)&cmd_set_vf_broadcast_broadcast,
14904                 (void *)&cmd_set_vf_broadcast_port_id,
14905                 (void *)&cmd_set_vf_broadcast_vf_id,
14906                 (void *)&cmd_set_vf_broadcast_on_off,
14907                 NULL,
14908         },
14909 };
14910
14911 /* vf vlan tag configuration */
14912
14913 /* Common result structure for vf vlan tag */
14914 struct cmd_set_vf_vlan_tag_result {
14915         cmdline_fixed_string_t set;
14916         cmdline_fixed_string_t vf;
14917         cmdline_fixed_string_t vlan;
14918         cmdline_fixed_string_t tag;
14919         portid_t port_id;
14920         uint16_t vf_id;
14921         cmdline_fixed_string_t on_off;
14922 };
14923
14924 /* Common CLI fields for vf vlan tag enable disable */
14925 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14926         TOKEN_STRING_INITIALIZER
14927                 (struct cmd_set_vf_vlan_tag_result,
14928                  set, "set");
14929 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14930         TOKEN_STRING_INITIALIZER
14931                 (struct cmd_set_vf_vlan_tag_result,
14932                  vf, "vf");
14933 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14934         TOKEN_STRING_INITIALIZER
14935                 (struct cmd_set_vf_vlan_tag_result,
14936                  vlan, "vlan");
14937 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14938         TOKEN_STRING_INITIALIZER
14939                 (struct cmd_set_vf_vlan_tag_result,
14940                  tag, "tag");
14941 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14942         TOKEN_NUM_INITIALIZER
14943                 (struct cmd_set_vf_vlan_tag_result,
14944                  port_id, UINT16);
14945 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14946         TOKEN_NUM_INITIALIZER
14947                 (struct cmd_set_vf_vlan_tag_result,
14948                  vf_id, UINT16);
14949 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14950         TOKEN_STRING_INITIALIZER
14951                 (struct cmd_set_vf_vlan_tag_result,
14952                  on_off, "on#off");
14953
14954 static void
14955 cmd_set_vf_vlan_tag_parsed(
14956         void *parsed_result,
14957         __rte_unused struct cmdline *cl,
14958         __rte_unused void *data)
14959 {
14960         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14961         int ret = -ENOTSUP;
14962
14963         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14964
14965         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14966                 return;
14967
14968 #ifdef RTE_LIBRTE_I40E_PMD
14969         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14970                                            res->vf_id, is_on);
14971 #endif
14972
14973         switch (ret) {
14974         case 0:
14975                 break;
14976         case -EINVAL:
14977                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14978                 break;
14979         case -ENODEV:
14980                 printf("invalid port_id %d\n", res->port_id);
14981                 break;
14982         case -ENOTSUP:
14983                 printf("function not implemented\n");
14984                 break;
14985         default:
14986                 printf("programming error: (%s)\n", strerror(-ret));
14987         }
14988 }
14989
14990 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14991         .f = cmd_set_vf_vlan_tag_parsed,
14992         .data = NULL,
14993         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14994         .tokens = {
14995                 (void *)&cmd_set_vf_vlan_tag_set,
14996                 (void *)&cmd_set_vf_vlan_tag_vf,
14997                 (void *)&cmd_set_vf_vlan_tag_vlan,
14998                 (void *)&cmd_set_vf_vlan_tag_tag,
14999                 (void *)&cmd_set_vf_vlan_tag_port_id,
15000                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15001                 (void *)&cmd_set_vf_vlan_tag_on_off,
15002                 NULL,
15003         },
15004 };
15005
15006 /* Common definition of VF and TC TX bandwidth configuration */
15007 struct cmd_vf_tc_bw_result {
15008         cmdline_fixed_string_t set;
15009         cmdline_fixed_string_t vf;
15010         cmdline_fixed_string_t tc;
15011         cmdline_fixed_string_t tx;
15012         cmdline_fixed_string_t min_bw;
15013         cmdline_fixed_string_t max_bw;
15014         cmdline_fixed_string_t strict_link_prio;
15015         portid_t port_id;
15016         uint16_t vf_id;
15017         uint8_t tc_no;
15018         uint32_t bw;
15019         cmdline_fixed_string_t bw_list;
15020         uint8_t tc_map;
15021 };
15022
15023 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15024         TOKEN_STRING_INITIALIZER
15025                 (struct cmd_vf_tc_bw_result,
15026                  set, "set");
15027 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15028         TOKEN_STRING_INITIALIZER
15029                 (struct cmd_vf_tc_bw_result,
15030                  vf, "vf");
15031 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15032         TOKEN_STRING_INITIALIZER
15033                 (struct cmd_vf_tc_bw_result,
15034                  tc, "tc");
15035 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15036         TOKEN_STRING_INITIALIZER
15037                 (struct cmd_vf_tc_bw_result,
15038                  tx, "tx");
15039 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15040         TOKEN_STRING_INITIALIZER
15041                 (struct cmd_vf_tc_bw_result,
15042                  strict_link_prio, "strict-link-priority");
15043 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15044         TOKEN_STRING_INITIALIZER
15045                 (struct cmd_vf_tc_bw_result,
15046                  min_bw, "min-bandwidth");
15047 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15048         TOKEN_STRING_INITIALIZER
15049                 (struct cmd_vf_tc_bw_result,
15050                  max_bw, "max-bandwidth");
15051 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15052         TOKEN_NUM_INITIALIZER
15053                 (struct cmd_vf_tc_bw_result,
15054                  port_id, UINT16);
15055 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15056         TOKEN_NUM_INITIALIZER
15057                 (struct cmd_vf_tc_bw_result,
15058                  vf_id, UINT16);
15059 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15060         TOKEN_NUM_INITIALIZER
15061                 (struct cmd_vf_tc_bw_result,
15062                  tc_no, UINT8);
15063 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15064         TOKEN_NUM_INITIALIZER
15065                 (struct cmd_vf_tc_bw_result,
15066                  bw, UINT32);
15067 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15068         TOKEN_STRING_INITIALIZER
15069                 (struct cmd_vf_tc_bw_result,
15070                  bw_list, NULL);
15071 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15072         TOKEN_NUM_INITIALIZER
15073                 (struct cmd_vf_tc_bw_result,
15074                  tc_map, UINT8);
15075
15076 /* VF max bandwidth setting */
15077 static void
15078 cmd_vf_max_bw_parsed(
15079         void *parsed_result,
15080         __rte_unused struct cmdline *cl,
15081         __rte_unused void *data)
15082 {
15083         struct cmd_vf_tc_bw_result *res = parsed_result;
15084         int ret = -ENOTSUP;
15085
15086         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15087                 return;
15088
15089 #ifdef RTE_LIBRTE_I40E_PMD
15090         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15091                                          res->vf_id, res->bw);
15092 #endif
15093
15094         switch (ret) {
15095         case 0:
15096                 break;
15097         case -EINVAL:
15098                 printf("invalid vf_id %d or bandwidth %d\n",
15099                        res->vf_id, res->bw);
15100                 break;
15101         case -ENODEV:
15102                 printf("invalid port_id %d\n", res->port_id);
15103                 break;
15104         case -ENOTSUP:
15105                 printf("function not implemented\n");
15106                 break;
15107         default:
15108                 printf("programming error: (%s)\n", strerror(-ret));
15109         }
15110 }
15111
15112 cmdline_parse_inst_t cmd_vf_max_bw = {
15113         .f = cmd_vf_max_bw_parsed,
15114         .data = NULL,
15115         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15116         .tokens = {
15117                 (void *)&cmd_vf_tc_bw_set,
15118                 (void *)&cmd_vf_tc_bw_vf,
15119                 (void *)&cmd_vf_tc_bw_tx,
15120                 (void *)&cmd_vf_tc_bw_max_bw,
15121                 (void *)&cmd_vf_tc_bw_port_id,
15122                 (void *)&cmd_vf_tc_bw_vf_id,
15123                 (void *)&cmd_vf_tc_bw_bw,
15124                 NULL,
15125         },
15126 };
15127
15128 static int
15129 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15130                            uint8_t *tc_num,
15131                            char *str)
15132 {
15133         uint32_t size;
15134         const char *p, *p0 = str;
15135         char s[256];
15136         char *end;
15137         char *str_fld[16];
15138         uint16_t i;
15139         int ret;
15140
15141         p = strchr(p0, '(');
15142         if (p == NULL) {
15143                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15144                 return -1;
15145         }
15146         p++;
15147         p0 = strchr(p, ')');
15148         if (p0 == NULL) {
15149                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15150                 return -1;
15151         }
15152         size = p0 - p;
15153         if (size >= sizeof(s)) {
15154                 printf("The string size exceeds the internal buffer size\n");
15155                 return -1;
15156         }
15157         snprintf(s, sizeof(s), "%.*s", size, p);
15158         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15159         if (ret <= 0) {
15160                 printf("Failed to get the bandwidth list. ");
15161                 return -1;
15162         }
15163         *tc_num = ret;
15164         for (i = 0; i < ret; i++)
15165                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15166
15167         return 0;
15168 }
15169
15170 /* TC min bandwidth setting */
15171 static void
15172 cmd_vf_tc_min_bw_parsed(
15173         void *parsed_result,
15174         __rte_unused struct cmdline *cl,
15175         __rte_unused void *data)
15176 {
15177         struct cmd_vf_tc_bw_result *res = parsed_result;
15178         uint8_t tc_num;
15179         uint8_t bw[16];
15180         int ret = -ENOTSUP;
15181
15182         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15183                 return;
15184
15185         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15186         if (ret)
15187                 return;
15188
15189 #ifdef RTE_LIBRTE_I40E_PMD
15190         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15191                                               tc_num, bw);
15192 #endif
15193
15194         switch (ret) {
15195         case 0:
15196                 break;
15197         case -EINVAL:
15198                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15199                 break;
15200         case -ENODEV:
15201                 printf("invalid port_id %d\n", res->port_id);
15202                 break;
15203         case -ENOTSUP:
15204                 printf("function not implemented\n");
15205                 break;
15206         default:
15207                 printf("programming error: (%s)\n", strerror(-ret));
15208         }
15209 }
15210
15211 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15212         .f = cmd_vf_tc_min_bw_parsed,
15213         .data = NULL,
15214         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15215                     " <bw1, bw2, ...>",
15216         .tokens = {
15217                 (void *)&cmd_vf_tc_bw_set,
15218                 (void *)&cmd_vf_tc_bw_vf,
15219                 (void *)&cmd_vf_tc_bw_tc,
15220                 (void *)&cmd_vf_tc_bw_tx,
15221                 (void *)&cmd_vf_tc_bw_min_bw,
15222                 (void *)&cmd_vf_tc_bw_port_id,
15223                 (void *)&cmd_vf_tc_bw_vf_id,
15224                 (void *)&cmd_vf_tc_bw_bw_list,
15225                 NULL,
15226         },
15227 };
15228
15229 static void
15230 cmd_tc_min_bw_parsed(
15231         void *parsed_result,
15232         __rte_unused struct cmdline *cl,
15233         __rte_unused void *data)
15234 {
15235         struct cmd_vf_tc_bw_result *res = parsed_result;
15236         struct rte_port *port;
15237         uint8_t tc_num;
15238         uint8_t bw[16];
15239         int ret = -ENOTSUP;
15240
15241         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15242                 return;
15243
15244         port = &ports[res->port_id];
15245         /** Check if the port is not started **/
15246         if (port->port_status != RTE_PORT_STOPPED) {
15247                 printf("Please stop port %d first\n", res->port_id);
15248                 return;
15249         }
15250
15251         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15252         if (ret)
15253                 return;
15254
15255 #ifdef RTE_LIBRTE_IXGBE_PMD
15256         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15257 #endif
15258
15259         switch (ret) {
15260         case 0:
15261                 break;
15262         case -EINVAL:
15263                 printf("invalid bandwidth\n");
15264                 break;
15265         case -ENODEV:
15266                 printf("invalid port_id %d\n", res->port_id);
15267                 break;
15268         case -ENOTSUP:
15269                 printf("function not implemented\n");
15270                 break;
15271         default:
15272                 printf("programming error: (%s)\n", strerror(-ret));
15273         }
15274 }
15275
15276 cmdline_parse_inst_t cmd_tc_min_bw = {
15277         .f = cmd_tc_min_bw_parsed,
15278         .data = NULL,
15279         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15280         .tokens = {
15281                 (void *)&cmd_vf_tc_bw_set,
15282                 (void *)&cmd_vf_tc_bw_tc,
15283                 (void *)&cmd_vf_tc_bw_tx,
15284                 (void *)&cmd_vf_tc_bw_min_bw,
15285                 (void *)&cmd_vf_tc_bw_port_id,
15286                 (void *)&cmd_vf_tc_bw_bw_list,
15287                 NULL,
15288         },
15289 };
15290
15291 /* TC max bandwidth setting */
15292 static void
15293 cmd_vf_tc_max_bw_parsed(
15294         void *parsed_result,
15295         __rte_unused struct cmdline *cl,
15296         __rte_unused void *data)
15297 {
15298         struct cmd_vf_tc_bw_result *res = parsed_result;
15299         int ret = -ENOTSUP;
15300
15301         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15302                 return;
15303
15304 #ifdef RTE_LIBRTE_I40E_PMD
15305         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15306                                             res->tc_no, res->bw);
15307 #endif
15308
15309         switch (ret) {
15310         case 0:
15311                 break;
15312         case -EINVAL:
15313                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15314                        res->vf_id, res->tc_no, res->bw);
15315                 break;
15316         case -ENODEV:
15317                 printf("invalid port_id %d\n", res->port_id);
15318                 break;
15319         case -ENOTSUP:
15320                 printf("function not implemented\n");
15321                 break;
15322         default:
15323                 printf("programming error: (%s)\n", strerror(-ret));
15324         }
15325 }
15326
15327 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15328         .f = cmd_vf_tc_max_bw_parsed,
15329         .data = NULL,
15330         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15331                     " <bandwidth>",
15332         .tokens = {
15333                 (void *)&cmd_vf_tc_bw_set,
15334                 (void *)&cmd_vf_tc_bw_vf,
15335                 (void *)&cmd_vf_tc_bw_tc,
15336                 (void *)&cmd_vf_tc_bw_tx,
15337                 (void *)&cmd_vf_tc_bw_max_bw,
15338                 (void *)&cmd_vf_tc_bw_port_id,
15339                 (void *)&cmd_vf_tc_bw_vf_id,
15340                 (void *)&cmd_vf_tc_bw_tc_no,
15341                 (void *)&cmd_vf_tc_bw_bw,
15342                 NULL,
15343         },
15344 };
15345
15346
15347 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15348
15349 /* *** Set Port default Traffic Management Hierarchy *** */
15350 struct cmd_set_port_tm_hierarchy_default_result {
15351         cmdline_fixed_string_t set;
15352         cmdline_fixed_string_t port;
15353         cmdline_fixed_string_t tm;
15354         cmdline_fixed_string_t hierarchy;
15355         cmdline_fixed_string_t def;
15356         portid_t port_id;
15357 };
15358
15359 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15360         TOKEN_STRING_INITIALIZER(
15361                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15362 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15363         TOKEN_STRING_INITIALIZER(
15364                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15365 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15366         TOKEN_STRING_INITIALIZER(
15367                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15368 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15369         TOKEN_STRING_INITIALIZER(
15370                 struct cmd_set_port_tm_hierarchy_default_result,
15371                         hierarchy, "hierarchy");
15372 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15373         TOKEN_STRING_INITIALIZER(
15374                 struct cmd_set_port_tm_hierarchy_default_result,
15375                         def, "default");
15376 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15377         TOKEN_NUM_INITIALIZER(
15378                 struct cmd_set_port_tm_hierarchy_default_result,
15379                         port_id, UINT16);
15380
15381 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15382         __rte_unused struct cmdline *cl,
15383         __rte_unused void *data)
15384 {
15385         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15386         struct rte_port *p;
15387         portid_t port_id = res->port_id;
15388
15389         if (port_id_is_invalid(port_id, ENABLED_WARN))
15390                 return;
15391
15392         p = &ports[port_id];
15393
15394         /* Forward mode: tm */
15395         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15396                 printf("  softnicfwd mode not enabled(error)\n");
15397                 return;
15398         }
15399
15400         /* Set the default tm hierarchy */
15401         p->softport.default_tm_hierarchy_enable = 1;
15402 }
15403
15404 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15405         .f = cmd_set_port_tm_hierarchy_default_parsed,
15406         .data = NULL,
15407         .help_str = "set port tm hierarchy default <port_id>",
15408         .tokens = {
15409                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15410                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15411                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15412                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15413                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15414                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15415                 NULL,
15416         },
15417 };
15418 #endif
15419
15420 /** Set VXLAN encapsulation details */
15421 struct cmd_set_vxlan_result {
15422         cmdline_fixed_string_t set;
15423         cmdline_fixed_string_t vxlan;
15424         cmdline_fixed_string_t pos_token;
15425         cmdline_fixed_string_t ip_version;
15426         uint32_t vlan_present:1;
15427         uint32_t vni;
15428         uint16_t udp_src;
15429         uint16_t udp_dst;
15430         cmdline_ipaddr_t ip_src;
15431         cmdline_ipaddr_t ip_dst;
15432         uint16_t tci;
15433         uint8_t tos;
15434         uint8_t ttl;
15435         struct rte_ether_addr eth_src;
15436         struct rte_ether_addr eth_dst;
15437 };
15438
15439 cmdline_parse_token_string_t cmd_set_vxlan_set =
15440         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15441 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15442         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15443 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15444         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15445                                  "vxlan-tos-ttl");
15446 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15447         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15448                                  "vxlan-with-vlan");
15449 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15450         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15451                                  "ip-version");
15452 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15453         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15454                                  "ipv4#ipv6");
15455 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15456         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15457                                  "vni");
15458 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15459         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15460 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15461         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15462                                  "udp-src");
15463 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15464         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15465 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15466         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15467                                  "udp-dst");
15468 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15469         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15470 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15471         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15472                                  "ip-tos");
15473 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15474         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15475 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15476         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15477                                  "ip-ttl");
15478 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15479         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15480 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15481         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15482                                  "ip-src");
15483 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15484         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15485 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15486         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15487                                  "ip-dst");
15488 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15489         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15490 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15491         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15492                                  "vlan-tci");
15493 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15494         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15495 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15496         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15497                                  "eth-src");
15498 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15499         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15500 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15501         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15502                                  "eth-dst");
15503 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15504         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15505
15506 static void cmd_set_vxlan_parsed(void *parsed_result,
15507         __rte_unused struct cmdline *cl,
15508         __rte_unused void *data)
15509 {
15510         struct cmd_set_vxlan_result *res = parsed_result;
15511         union {
15512                 uint32_t vxlan_id;
15513                 uint8_t vni[4];
15514         } id = {
15515                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15516         };
15517
15518         vxlan_encap_conf.select_tos_ttl = 0;
15519         if (strcmp(res->vxlan, "vxlan") == 0)
15520                 vxlan_encap_conf.select_vlan = 0;
15521         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15522                 vxlan_encap_conf.select_vlan = 1;
15523         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15524                 vxlan_encap_conf.select_vlan = 0;
15525                 vxlan_encap_conf.select_tos_ttl = 1;
15526         }
15527         if (strcmp(res->ip_version, "ipv4") == 0)
15528                 vxlan_encap_conf.select_ipv4 = 1;
15529         else if (strcmp(res->ip_version, "ipv6") == 0)
15530                 vxlan_encap_conf.select_ipv4 = 0;
15531         else
15532                 return;
15533         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15534         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15535         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15536         vxlan_encap_conf.ip_tos = res->tos;
15537         vxlan_encap_conf.ip_ttl = res->ttl;
15538         if (vxlan_encap_conf.select_ipv4) {
15539                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15540                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15541         } else {
15542                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15543                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15544         }
15545         if (vxlan_encap_conf.select_vlan)
15546                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15547         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15548                    RTE_ETHER_ADDR_LEN);
15549         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15550                    RTE_ETHER_ADDR_LEN);
15551 }
15552
15553 cmdline_parse_inst_t cmd_set_vxlan = {
15554         .f = cmd_set_vxlan_parsed,
15555         .data = NULL,
15556         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15557                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15558                 " eth-src <eth-src> eth-dst <eth-dst>",
15559         .tokens = {
15560                 (void *)&cmd_set_vxlan_set,
15561                 (void *)&cmd_set_vxlan_vxlan,
15562                 (void *)&cmd_set_vxlan_ip_version,
15563                 (void *)&cmd_set_vxlan_ip_version_value,
15564                 (void *)&cmd_set_vxlan_vni,
15565                 (void *)&cmd_set_vxlan_vni_value,
15566                 (void *)&cmd_set_vxlan_udp_src,
15567                 (void *)&cmd_set_vxlan_udp_src_value,
15568                 (void *)&cmd_set_vxlan_udp_dst,
15569                 (void *)&cmd_set_vxlan_udp_dst_value,
15570                 (void *)&cmd_set_vxlan_ip_src,
15571                 (void *)&cmd_set_vxlan_ip_src_value,
15572                 (void *)&cmd_set_vxlan_ip_dst,
15573                 (void *)&cmd_set_vxlan_ip_dst_value,
15574                 (void *)&cmd_set_vxlan_eth_src,
15575                 (void *)&cmd_set_vxlan_eth_src_value,
15576                 (void *)&cmd_set_vxlan_eth_dst,
15577                 (void *)&cmd_set_vxlan_eth_dst_value,
15578                 NULL,
15579         },
15580 };
15581
15582 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15583         .f = cmd_set_vxlan_parsed,
15584         .data = NULL,
15585         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15586                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15587                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15588                 " eth-dst <eth-dst>",
15589         .tokens = {
15590                 (void *)&cmd_set_vxlan_set,
15591                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15592                 (void *)&cmd_set_vxlan_ip_version,
15593                 (void *)&cmd_set_vxlan_ip_version_value,
15594                 (void *)&cmd_set_vxlan_vni,
15595                 (void *)&cmd_set_vxlan_vni_value,
15596                 (void *)&cmd_set_vxlan_udp_src,
15597                 (void *)&cmd_set_vxlan_udp_src_value,
15598                 (void *)&cmd_set_vxlan_udp_dst,
15599                 (void *)&cmd_set_vxlan_udp_dst_value,
15600                 (void *)&cmd_set_vxlan_ip_tos,
15601                 (void *)&cmd_set_vxlan_ip_tos_value,
15602                 (void *)&cmd_set_vxlan_ip_ttl,
15603                 (void *)&cmd_set_vxlan_ip_ttl_value,
15604                 (void *)&cmd_set_vxlan_ip_src,
15605                 (void *)&cmd_set_vxlan_ip_src_value,
15606                 (void *)&cmd_set_vxlan_ip_dst,
15607                 (void *)&cmd_set_vxlan_ip_dst_value,
15608                 (void *)&cmd_set_vxlan_eth_src,
15609                 (void *)&cmd_set_vxlan_eth_src_value,
15610                 (void *)&cmd_set_vxlan_eth_dst,
15611                 (void *)&cmd_set_vxlan_eth_dst_value,
15612                 NULL,
15613         },
15614 };
15615
15616 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15617         .f = cmd_set_vxlan_parsed,
15618         .data = NULL,
15619         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15620                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15621                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15622                 " <eth-dst>",
15623         .tokens = {
15624                 (void *)&cmd_set_vxlan_set,
15625                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15626                 (void *)&cmd_set_vxlan_ip_version,
15627                 (void *)&cmd_set_vxlan_ip_version_value,
15628                 (void *)&cmd_set_vxlan_vni,
15629                 (void *)&cmd_set_vxlan_vni_value,
15630                 (void *)&cmd_set_vxlan_udp_src,
15631                 (void *)&cmd_set_vxlan_udp_src_value,
15632                 (void *)&cmd_set_vxlan_udp_dst,
15633                 (void *)&cmd_set_vxlan_udp_dst_value,
15634                 (void *)&cmd_set_vxlan_ip_src,
15635                 (void *)&cmd_set_vxlan_ip_src_value,
15636                 (void *)&cmd_set_vxlan_ip_dst,
15637                 (void *)&cmd_set_vxlan_ip_dst_value,
15638                 (void *)&cmd_set_vxlan_vlan,
15639                 (void *)&cmd_set_vxlan_vlan_value,
15640                 (void *)&cmd_set_vxlan_eth_src,
15641                 (void *)&cmd_set_vxlan_eth_src_value,
15642                 (void *)&cmd_set_vxlan_eth_dst,
15643                 (void *)&cmd_set_vxlan_eth_dst_value,
15644                 NULL,
15645         },
15646 };
15647
15648 /** Set NVGRE encapsulation details */
15649 struct cmd_set_nvgre_result {
15650         cmdline_fixed_string_t set;
15651         cmdline_fixed_string_t nvgre;
15652         cmdline_fixed_string_t pos_token;
15653         cmdline_fixed_string_t ip_version;
15654         uint32_t tni;
15655         cmdline_ipaddr_t ip_src;
15656         cmdline_ipaddr_t ip_dst;
15657         uint16_t tci;
15658         struct rte_ether_addr eth_src;
15659         struct rte_ether_addr eth_dst;
15660 };
15661
15662 cmdline_parse_token_string_t cmd_set_nvgre_set =
15663         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15664 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15665         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15666 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15667         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15668                                  "nvgre-with-vlan");
15669 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15670         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15671                                  "ip-version");
15672 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15673         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15674                                  "ipv4#ipv6");
15675 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15676         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15677                                  "tni");
15678 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15679         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15680 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15681         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15682                                  "ip-src");
15683 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15684         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15685 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15686         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15687                                  "ip-dst");
15688 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15689         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15690 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15691         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15692                                  "vlan-tci");
15693 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15694         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15695 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15696         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15697                                  "eth-src");
15698 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15699         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15700 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15701         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15702                                  "eth-dst");
15703 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15704         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15705
15706 static void cmd_set_nvgre_parsed(void *parsed_result,
15707         __rte_unused struct cmdline *cl,
15708         __rte_unused void *data)
15709 {
15710         struct cmd_set_nvgre_result *res = parsed_result;
15711         union {
15712                 uint32_t nvgre_tni;
15713                 uint8_t tni[4];
15714         } id = {
15715                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15716         };
15717
15718         if (strcmp(res->nvgre, "nvgre") == 0)
15719                 nvgre_encap_conf.select_vlan = 0;
15720         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15721                 nvgre_encap_conf.select_vlan = 1;
15722         if (strcmp(res->ip_version, "ipv4") == 0)
15723                 nvgre_encap_conf.select_ipv4 = 1;
15724         else if (strcmp(res->ip_version, "ipv6") == 0)
15725                 nvgre_encap_conf.select_ipv4 = 0;
15726         else
15727                 return;
15728         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15729         if (nvgre_encap_conf.select_ipv4) {
15730                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15731                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15732         } else {
15733                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15734                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15735         }
15736         if (nvgre_encap_conf.select_vlan)
15737                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15738         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15739                    RTE_ETHER_ADDR_LEN);
15740         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15741                    RTE_ETHER_ADDR_LEN);
15742 }
15743
15744 cmdline_parse_inst_t cmd_set_nvgre = {
15745         .f = cmd_set_nvgre_parsed,
15746         .data = NULL,
15747         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15748                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15749                 " eth-dst <eth-dst>",
15750         .tokens = {
15751                 (void *)&cmd_set_nvgre_set,
15752                 (void *)&cmd_set_nvgre_nvgre,
15753                 (void *)&cmd_set_nvgre_ip_version,
15754                 (void *)&cmd_set_nvgre_ip_version_value,
15755                 (void *)&cmd_set_nvgre_tni,
15756                 (void *)&cmd_set_nvgre_tni_value,
15757                 (void *)&cmd_set_nvgre_ip_src,
15758                 (void *)&cmd_set_nvgre_ip_src_value,
15759                 (void *)&cmd_set_nvgre_ip_dst,
15760                 (void *)&cmd_set_nvgre_ip_dst_value,
15761                 (void *)&cmd_set_nvgre_eth_src,
15762                 (void *)&cmd_set_nvgre_eth_src_value,
15763                 (void *)&cmd_set_nvgre_eth_dst,
15764                 (void *)&cmd_set_nvgre_eth_dst_value,
15765                 NULL,
15766         },
15767 };
15768
15769 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15770         .f = cmd_set_nvgre_parsed,
15771         .data = NULL,
15772         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15773                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15774                 " eth-src <eth-src> eth-dst <eth-dst>",
15775         .tokens = {
15776                 (void *)&cmd_set_nvgre_set,
15777                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15778                 (void *)&cmd_set_nvgre_ip_version,
15779                 (void *)&cmd_set_nvgre_ip_version_value,
15780                 (void *)&cmd_set_nvgre_tni,
15781                 (void *)&cmd_set_nvgre_tni_value,
15782                 (void *)&cmd_set_nvgre_ip_src,
15783                 (void *)&cmd_set_nvgre_ip_src_value,
15784                 (void *)&cmd_set_nvgre_ip_dst,
15785                 (void *)&cmd_set_nvgre_ip_dst_value,
15786                 (void *)&cmd_set_nvgre_vlan,
15787                 (void *)&cmd_set_nvgre_vlan_value,
15788                 (void *)&cmd_set_nvgre_eth_src,
15789                 (void *)&cmd_set_nvgre_eth_src_value,
15790                 (void *)&cmd_set_nvgre_eth_dst,
15791                 (void *)&cmd_set_nvgre_eth_dst_value,
15792                 NULL,
15793         },
15794 };
15795
15796 /** Set L2 encapsulation details */
15797 struct cmd_set_l2_encap_result {
15798         cmdline_fixed_string_t set;
15799         cmdline_fixed_string_t l2_encap;
15800         cmdline_fixed_string_t pos_token;
15801         cmdline_fixed_string_t ip_version;
15802         uint32_t vlan_present:1;
15803         uint16_t tci;
15804         struct rte_ether_addr eth_src;
15805         struct rte_ether_addr eth_dst;
15806 };
15807
15808 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15809         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15810 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15811         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15812 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15813         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15814                                  "l2_encap-with-vlan");
15815 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15816         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15817                                  "ip-version");
15818 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15819         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15820                                  "ipv4#ipv6");
15821 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15822         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15823                                  "vlan-tci");
15824 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15825         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15826 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15827         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15828                                  "eth-src");
15829 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15830         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15831 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15832         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15833                                  "eth-dst");
15834 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15835         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15836
15837 static void cmd_set_l2_encap_parsed(void *parsed_result,
15838         __rte_unused struct cmdline *cl,
15839         __rte_unused void *data)
15840 {
15841         struct cmd_set_l2_encap_result *res = parsed_result;
15842
15843         if (strcmp(res->l2_encap, "l2_encap") == 0)
15844                 l2_encap_conf.select_vlan = 0;
15845         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15846                 l2_encap_conf.select_vlan = 1;
15847         if (strcmp(res->ip_version, "ipv4") == 0)
15848                 l2_encap_conf.select_ipv4 = 1;
15849         else if (strcmp(res->ip_version, "ipv6") == 0)
15850                 l2_encap_conf.select_ipv4 = 0;
15851         else
15852                 return;
15853         if (l2_encap_conf.select_vlan)
15854                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15855         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15856                    RTE_ETHER_ADDR_LEN);
15857         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15858                    RTE_ETHER_ADDR_LEN);
15859 }
15860
15861 cmdline_parse_inst_t cmd_set_l2_encap = {
15862         .f = cmd_set_l2_encap_parsed,
15863         .data = NULL,
15864         .help_str = "set l2_encap ip-version ipv4|ipv6"
15865                 " eth-src <eth-src> eth-dst <eth-dst>",
15866         .tokens = {
15867                 (void *)&cmd_set_l2_encap_set,
15868                 (void *)&cmd_set_l2_encap_l2_encap,
15869                 (void *)&cmd_set_l2_encap_ip_version,
15870                 (void *)&cmd_set_l2_encap_ip_version_value,
15871                 (void *)&cmd_set_l2_encap_eth_src,
15872                 (void *)&cmd_set_l2_encap_eth_src_value,
15873                 (void *)&cmd_set_l2_encap_eth_dst,
15874                 (void *)&cmd_set_l2_encap_eth_dst_value,
15875                 NULL,
15876         },
15877 };
15878
15879 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15880         .f = cmd_set_l2_encap_parsed,
15881         .data = NULL,
15882         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15883                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15884         .tokens = {
15885                 (void *)&cmd_set_l2_encap_set,
15886                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15887                 (void *)&cmd_set_l2_encap_ip_version,
15888                 (void *)&cmd_set_l2_encap_ip_version_value,
15889                 (void *)&cmd_set_l2_encap_vlan,
15890                 (void *)&cmd_set_l2_encap_vlan_value,
15891                 (void *)&cmd_set_l2_encap_eth_src,
15892                 (void *)&cmd_set_l2_encap_eth_src_value,
15893                 (void *)&cmd_set_l2_encap_eth_dst,
15894                 (void *)&cmd_set_l2_encap_eth_dst_value,
15895                 NULL,
15896         },
15897 };
15898
15899 /** Set L2 decapsulation details */
15900 struct cmd_set_l2_decap_result {
15901         cmdline_fixed_string_t set;
15902         cmdline_fixed_string_t l2_decap;
15903         cmdline_fixed_string_t pos_token;
15904         uint32_t vlan_present:1;
15905 };
15906
15907 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15908         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15909 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15910         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15911                                  "l2_decap");
15912 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15913         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15914                                  "l2_decap-with-vlan");
15915
15916 static void cmd_set_l2_decap_parsed(void *parsed_result,
15917         __rte_unused struct cmdline *cl,
15918         __rte_unused void *data)
15919 {
15920         struct cmd_set_l2_decap_result *res = parsed_result;
15921
15922         if (strcmp(res->l2_decap, "l2_decap") == 0)
15923                 l2_decap_conf.select_vlan = 0;
15924         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15925                 l2_decap_conf.select_vlan = 1;
15926 }
15927
15928 cmdline_parse_inst_t cmd_set_l2_decap = {
15929         .f = cmd_set_l2_decap_parsed,
15930         .data = NULL,
15931         .help_str = "set l2_decap",
15932         .tokens = {
15933                 (void *)&cmd_set_l2_decap_set,
15934                 (void *)&cmd_set_l2_decap_l2_decap,
15935                 NULL,
15936         },
15937 };
15938
15939 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15940         .f = cmd_set_l2_decap_parsed,
15941         .data = NULL,
15942         .help_str = "set l2_decap-with-vlan",
15943         .tokens = {
15944                 (void *)&cmd_set_l2_decap_set,
15945                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15946                 NULL,
15947         },
15948 };
15949
15950 /** Set MPLSoGRE encapsulation details */
15951 struct cmd_set_mplsogre_encap_result {
15952         cmdline_fixed_string_t set;
15953         cmdline_fixed_string_t mplsogre;
15954         cmdline_fixed_string_t pos_token;
15955         cmdline_fixed_string_t ip_version;
15956         uint32_t vlan_present:1;
15957         uint32_t label;
15958         cmdline_ipaddr_t ip_src;
15959         cmdline_ipaddr_t ip_dst;
15960         uint16_t tci;
15961         struct rte_ether_addr eth_src;
15962         struct rte_ether_addr eth_dst;
15963 };
15964
15965 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15966         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15967                                  "set");
15968 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15969         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15970                                  "mplsogre_encap");
15971 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15972         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15973                                  mplsogre, "mplsogre_encap-with-vlan");
15974 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15975         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15976                                  pos_token, "ip-version");
15977 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15978         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15979                                  ip_version, "ipv4#ipv6");
15980 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15981         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15982                                  pos_token, "label");
15983 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15984         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15985                               UINT32);
15986 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15987         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15988                                  pos_token, "ip-src");
15989 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15990         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15991 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15992         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15993                                  pos_token, "ip-dst");
15994 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15995         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15996 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15997         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15998                                  pos_token, "vlan-tci");
15999 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16000         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16001                               UINT16);
16002 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16003         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16004                                  pos_token, "eth-src");
16005 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16006         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16007                                     eth_src);
16008 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16009         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16010                                  pos_token, "eth-dst");
16011 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16012         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16013                                     eth_dst);
16014
16015 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16016         __rte_unused struct cmdline *cl,
16017         __rte_unused void *data)
16018 {
16019         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16020         union {
16021                 uint32_t mplsogre_label;
16022                 uint8_t label[4];
16023         } id = {
16024                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16025         };
16026
16027         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16028                 mplsogre_encap_conf.select_vlan = 0;
16029         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16030                 mplsogre_encap_conf.select_vlan = 1;
16031         if (strcmp(res->ip_version, "ipv4") == 0)
16032                 mplsogre_encap_conf.select_ipv4 = 1;
16033         else if (strcmp(res->ip_version, "ipv6") == 0)
16034                 mplsogre_encap_conf.select_ipv4 = 0;
16035         else
16036                 return;
16037         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16038         if (mplsogre_encap_conf.select_ipv4) {
16039                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16040                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16041         } else {
16042                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16043                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16044         }
16045         if (mplsogre_encap_conf.select_vlan)
16046                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16047         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16048                    RTE_ETHER_ADDR_LEN);
16049         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16050                    RTE_ETHER_ADDR_LEN);
16051 }
16052
16053 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16054         .f = cmd_set_mplsogre_encap_parsed,
16055         .data = NULL,
16056         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16057                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16058                 " eth-dst <eth-dst>",
16059         .tokens = {
16060                 (void *)&cmd_set_mplsogre_encap_set,
16061                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16062                 (void *)&cmd_set_mplsogre_encap_ip_version,
16063                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16064                 (void *)&cmd_set_mplsogre_encap_label,
16065                 (void *)&cmd_set_mplsogre_encap_label_value,
16066                 (void *)&cmd_set_mplsogre_encap_ip_src,
16067                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16068                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16069                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16070                 (void *)&cmd_set_mplsogre_encap_eth_src,
16071                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16072                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16073                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16074                 NULL,
16075         },
16076 };
16077
16078 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16079         .f = cmd_set_mplsogre_encap_parsed,
16080         .data = NULL,
16081         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16082                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16083                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16084         .tokens = {
16085                 (void *)&cmd_set_mplsogre_encap_set,
16086                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16087                 (void *)&cmd_set_mplsogre_encap_ip_version,
16088                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16089                 (void *)&cmd_set_mplsogre_encap_label,
16090                 (void *)&cmd_set_mplsogre_encap_label_value,
16091                 (void *)&cmd_set_mplsogre_encap_ip_src,
16092                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16093                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16094                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16095                 (void *)&cmd_set_mplsogre_encap_vlan,
16096                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16097                 (void *)&cmd_set_mplsogre_encap_eth_src,
16098                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16099                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16100                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16101                 NULL,
16102         },
16103 };
16104
16105 /** Set MPLSoGRE decapsulation details */
16106 struct cmd_set_mplsogre_decap_result {
16107         cmdline_fixed_string_t set;
16108         cmdline_fixed_string_t mplsogre;
16109         cmdline_fixed_string_t pos_token;
16110         cmdline_fixed_string_t ip_version;
16111         uint32_t vlan_present:1;
16112 };
16113
16114 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16115         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16116                                  "set");
16117 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16118         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16119                                  "mplsogre_decap");
16120 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16121         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16122                                  mplsogre, "mplsogre_decap-with-vlan");
16123 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16124         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16125                                  pos_token, "ip-version");
16126 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16127         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16128                                  ip_version, "ipv4#ipv6");
16129
16130 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16131         __rte_unused struct cmdline *cl,
16132         __rte_unused void *data)
16133 {
16134         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16135
16136         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16137                 mplsogre_decap_conf.select_vlan = 0;
16138         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16139                 mplsogre_decap_conf.select_vlan = 1;
16140         if (strcmp(res->ip_version, "ipv4") == 0)
16141                 mplsogre_decap_conf.select_ipv4 = 1;
16142         else if (strcmp(res->ip_version, "ipv6") == 0)
16143                 mplsogre_decap_conf.select_ipv4 = 0;
16144 }
16145
16146 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16147         .f = cmd_set_mplsogre_decap_parsed,
16148         .data = NULL,
16149         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16150         .tokens = {
16151                 (void *)&cmd_set_mplsogre_decap_set,
16152                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16153                 (void *)&cmd_set_mplsogre_decap_ip_version,
16154                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16155                 NULL,
16156         },
16157 };
16158
16159 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16160         .f = cmd_set_mplsogre_decap_parsed,
16161         .data = NULL,
16162         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16163         .tokens = {
16164                 (void *)&cmd_set_mplsogre_decap_set,
16165                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16166                 (void *)&cmd_set_mplsogre_decap_ip_version,
16167                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16168                 NULL,
16169         },
16170 };
16171
16172 /** Set MPLSoUDP encapsulation details */
16173 struct cmd_set_mplsoudp_encap_result {
16174         cmdline_fixed_string_t set;
16175         cmdline_fixed_string_t mplsoudp;
16176         cmdline_fixed_string_t pos_token;
16177         cmdline_fixed_string_t ip_version;
16178         uint32_t vlan_present:1;
16179         uint32_t label;
16180         uint16_t udp_src;
16181         uint16_t udp_dst;
16182         cmdline_ipaddr_t ip_src;
16183         cmdline_ipaddr_t ip_dst;
16184         uint16_t tci;
16185         struct rte_ether_addr eth_src;
16186         struct rte_ether_addr eth_dst;
16187 };
16188
16189 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16190         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16191                                  "set");
16192 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16193         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16194                                  "mplsoudp_encap");
16195 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16196         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16197                                  mplsoudp, "mplsoudp_encap-with-vlan");
16198 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16199         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16200                                  pos_token, "ip-version");
16201 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16202         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16203                                  ip_version, "ipv4#ipv6");
16204 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16205         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16206                                  pos_token, "label");
16207 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16208         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16209                               UINT32);
16210 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16211         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16212                                  pos_token, "udp-src");
16213 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16214         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16215                               UINT16);
16216 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16217         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16218                                  pos_token, "udp-dst");
16219 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16220         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16221                               UINT16);
16222 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16223         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16224                                  pos_token, "ip-src");
16225 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16226         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16227 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16228         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16229                                  pos_token, "ip-dst");
16230 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16231         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16232 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16233         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16234                                  pos_token, "vlan-tci");
16235 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16236         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16237                               UINT16);
16238 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16239         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16240                                  pos_token, "eth-src");
16241 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16242         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16243                                     eth_src);
16244 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16245         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16246                                  pos_token, "eth-dst");
16247 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16248         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16249                                     eth_dst);
16250
16251 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16252         __rte_unused struct cmdline *cl,
16253         __rte_unused void *data)
16254 {
16255         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16256         union {
16257                 uint32_t mplsoudp_label;
16258                 uint8_t label[4];
16259         } id = {
16260                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16261         };
16262
16263         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16264                 mplsoudp_encap_conf.select_vlan = 0;
16265         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16266                 mplsoudp_encap_conf.select_vlan = 1;
16267         if (strcmp(res->ip_version, "ipv4") == 0)
16268                 mplsoudp_encap_conf.select_ipv4 = 1;
16269         else if (strcmp(res->ip_version, "ipv6") == 0)
16270                 mplsoudp_encap_conf.select_ipv4 = 0;
16271         else
16272                 return;
16273         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16274         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16275         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16276         if (mplsoudp_encap_conf.select_ipv4) {
16277                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16278                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16279         } else {
16280                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16281                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16282         }
16283         if (mplsoudp_encap_conf.select_vlan)
16284                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16285         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16286                    RTE_ETHER_ADDR_LEN);
16287         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16288                    RTE_ETHER_ADDR_LEN);
16289 }
16290
16291 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16292         .f = cmd_set_mplsoudp_encap_parsed,
16293         .data = NULL,
16294         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16295                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16296                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16297         .tokens = {
16298                 (void *)&cmd_set_mplsoudp_encap_set,
16299                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16300                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16301                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16302                 (void *)&cmd_set_mplsoudp_encap_label,
16303                 (void *)&cmd_set_mplsoudp_encap_label_value,
16304                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16305                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16306                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16307                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16308                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16309                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16310                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16311                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16312                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16313                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16314                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16315                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16316                 NULL,
16317         },
16318 };
16319
16320 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16321         .f = cmd_set_mplsoudp_encap_parsed,
16322         .data = NULL,
16323         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16324                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16325                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16326                 " eth-src <eth-src> eth-dst <eth-dst>",
16327         .tokens = {
16328                 (void *)&cmd_set_mplsoudp_encap_set,
16329                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16330                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16331                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16332                 (void *)&cmd_set_mplsoudp_encap_label,
16333                 (void *)&cmd_set_mplsoudp_encap_label_value,
16334                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16335                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16336                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16337                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16338                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16339                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16340                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16341                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16342                 (void *)&cmd_set_mplsoudp_encap_vlan,
16343                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16344                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16345                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16346                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16347                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16348                 NULL,
16349         },
16350 };
16351
16352 /** Set MPLSoUDP decapsulation details */
16353 struct cmd_set_mplsoudp_decap_result {
16354         cmdline_fixed_string_t set;
16355         cmdline_fixed_string_t mplsoudp;
16356         cmdline_fixed_string_t pos_token;
16357         cmdline_fixed_string_t ip_version;
16358         uint32_t vlan_present:1;
16359 };
16360
16361 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16362         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16363                                  "set");
16364 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16365         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16366                                  "mplsoudp_decap");
16367 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16368         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16369                                  mplsoudp, "mplsoudp_decap-with-vlan");
16370 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16371         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16372                                  pos_token, "ip-version");
16373 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16374         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16375                                  ip_version, "ipv4#ipv6");
16376
16377 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16378         __rte_unused struct cmdline *cl,
16379         __rte_unused void *data)
16380 {
16381         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16382
16383         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16384                 mplsoudp_decap_conf.select_vlan = 0;
16385         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16386                 mplsoudp_decap_conf.select_vlan = 1;
16387         if (strcmp(res->ip_version, "ipv4") == 0)
16388                 mplsoudp_decap_conf.select_ipv4 = 1;
16389         else if (strcmp(res->ip_version, "ipv6") == 0)
16390                 mplsoudp_decap_conf.select_ipv4 = 0;
16391 }
16392
16393 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16394         .f = cmd_set_mplsoudp_decap_parsed,
16395         .data = NULL,
16396         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16397         .tokens = {
16398                 (void *)&cmd_set_mplsoudp_decap_set,
16399                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16400                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16401                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16402                 NULL,
16403         },
16404 };
16405
16406 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16407         .f = cmd_set_mplsoudp_decap_parsed,
16408         .data = NULL,
16409         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16410         .tokens = {
16411                 (void *)&cmd_set_mplsoudp_decap_set,
16412                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16413                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16414                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16415                 NULL,
16416         },
16417 };
16418
16419 /* Strict link priority scheduling mode setting */
16420 static void
16421 cmd_strict_link_prio_parsed(
16422         void *parsed_result,
16423         __rte_unused struct cmdline *cl,
16424         __rte_unused void *data)
16425 {
16426         struct cmd_vf_tc_bw_result *res = parsed_result;
16427         int ret = -ENOTSUP;
16428
16429         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16430                 return;
16431
16432 #ifdef RTE_LIBRTE_I40E_PMD
16433         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16434 #endif
16435
16436         switch (ret) {
16437         case 0:
16438                 break;
16439         case -EINVAL:
16440                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16441                 break;
16442         case -ENODEV:
16443                 printf("invalid port_id %d\n", res->port_id);
16444                 break;
16445         case -ENOTSUP:
16446                 printf("function not implemented\n");
16447                 break;
16448         default:
16449                 printf("programming error: (%s)\n", strerror(-ret));
16450         }
16451 }
16452
16453 cmdline_parse_inst_t cmd_strict_link_prio = {
16454         .f = cmd_strict_link_prio_parsed,
16455         .data = NULL,
16456         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16457         .tokens = {
16458                 (void *)&cmd_vf_tc_bw_set,
16459                 (void *)&cmd_vf_tc_bw_tx,
16460                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16461                 (void *)&cmd_vf_tc_bw_port_id,
16462                 (void *)&cmd_vf_tc_bw_tc_map,
16463                 NULL,
16464         },
16465 };
16466
16467 /* Load dynamic device personalization*/
16468 struct cmd_ddp_add_result {
16469         cmdline_fixed_string_t ddp;
16470         cmdline_fixed_string_t add;
16471         portid_t port_id;
16472         char filepath[];
16473 };
16474
16475 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16476         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16477 cmdline_parse_token_string_t cmd_ddp_add_add =
16478         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16479 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16480         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16481 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16482         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16483
16484 static void
16485 cmd_ddp_add_parsed(
16486         void *parsed_result,
16487         __rte_unused struct cmdline *cl,
16488         __rte_unused void *data)
16489 {
16490         struct cmd_ddp_add_result *res = parsed_result;
16491         uint8_t *buff;
16492         uint32_t size;
16493         char *filepath;
16494         char *file_fld[2];
16495         int file_num;
16496         int ret = -ENOTSUP;
16497
16498         if (!all_ports_stopped()) {
16499                 printf("Please stop all ports first\n");
16500                 return;
16501         }
16502
16503         filepath = strdup(res->filepath);
16504         if (filepath == NULL) {
16505                 printf("Failed to allocate memory\n");
16506                 return;
16507         }
16508         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16509
16510         buff = open_file(file_fld[0], &size);
16511         if (!buff) {
16512                 free((void *)filepath);
16513                 return;
16514         }
16515
16516 #ifdef RTE_LIBRTE_I40E_PMD
16517         if (ret == -ENOTSUP)
16518                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16519                                                buff, size,
16520                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16521 #endif
16522
16523         if (ret == -EEXIST)
16524                 printf("Profile has already existed.\n");
16525         else if (ret < 0)
16526                 printf("Failed to load profile.\n");
16527         else if (file_num == 2)
16528                 save_file(file_fld[1], buff, size);
16529
16530         close_file(buff);
16531         free((void *)filepath);
16532 }
16533
16534 cmdline_parse_inst_t cmd_ddp_add = {
16535         .f = cmd_ddp_add_parsed,
16536         .data = NULL,
16537         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16538         .tokens = {
16539                 (void *)&cmd_ddp_add_ddp,
16540                 (void *)&cmd_ddp_add_add,
16541                 (void *)&cmd_ddp_add_port_id,
16542                 (void *)&cmd_ddp_add_filepath,
16543                 NULL,
16544         },
16545 };
16546
16547 /* Delete dynamic device personalization*/
16548 struct cmd_ddp_del_result {
16549         cmdline_fixed_string_t ddp;
16550         cmdline_fixed_string_t del;
16551         portid_t port_id;
16552         char filepath[];
16553 };
16554
16555 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16556         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16557 cmdline_parse_token_string_t cmd_ddp_del_del =
16558         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16559 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16560         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16561 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16562         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16563
16564 static void
16565 cmd_ddp_del_parsed(
16566         void *parsed_result,
16567         __rte_unused struct cmdline *cl,
16568         __rte_unused void *data)
16569 {
16570         struct cmd_ddp_del_result *res = parsed_result;
16571         uint8_t *buff;
16572         uint32_t size;
16573         int ret = -ENOTSUP;
16574
16575         if (!all_ports_stopped()) {
16576                 printf("Please stop all ports first\n");
16577                 return;
16578         }
16579
16580         buff = open_file(res->filepath, &size);
16581         if (!buff)
16582                 return;
16583
16584 #ifdef RTE_LIBRTE_I40E_PMD
16585         if (ret == -ENOTSUP)
16586                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16587                                                buff, size,
16588                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16589 #endif
16590
16591         if (ret == -EACCES)
16592                 printf("Profile does not exist.\n");
16593         else if (ret < 0)
16594                 printf("Failed to delete profile.\n");
16595
16596         close_file(buff);
16597 }
16598
16599 cmdline_parse_inst_t cmd_ddp_del = {
16600         .f = cmd_ddp_del_parsed,
16601         .data = NULL,
16602         .help_str = "ddp del <port_id> <backup_profile_path>",
16603         .tokens = {
16604                 (void *)&cmd_ddp_del_ddp,
16605                 (void *)&cmd_ddp_del_del,
16606                 (void *)&cmd_ddp_del_port_id,
16607                 (void *)&cmd_ddp_del_filepath,
16608                 NULL,
16609         },
16610 };
16611
16612 /* Get dynamic device personalization profile info */
16613 struct cmd_ddp_info_result {
16614         cmdline_fixed_string_t ddp;
16615         cmdline_fixed_string_t get;
16616         cmdline_fixed_string_t info;
16617         char filepath[];
16618 };
16619
16620 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16621         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16622 cmdline_parse_token_string_t cmd_ddp_info_get =
16623         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16624 cmdline_parse_token_string_t cmd_ddp_info_info =
16625         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16626 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16627         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16628
16629 static void
16630 cmd_ddp_info_parsed(
16631         void *parsed_result,
16632         __rte_unused struct cmdline *cl,
16633         __rte_unused void *data)
16634 {
16635         struct cmd_ddp_info_result *res = parsed_result;
16636         uint8_t *pkg;
16637         uint32_t pkg_size;
16638         int ret = -ENOTSUP;
16639 #ifdef RTE_LIBRTE_I40E_PMD
16640         uint32_t i, j, n;
16641         uint8_t *buff;
16642         uint32_t buff_size = 0;
16643         struct rte_pmd_i40e_profile_info info;
16644         uint32_t dev_num = 0;
16645         struct rte_pmd_i40e_ddp_device_id *devs;
16646         uint32_t proto_num = 0;
16647         struct rte_pmd_i40e_proto_info *proto = NULL;
16648         uint32_t pctype_num = 0;
16649         struct rte_pmd_i40e_ptype_info *pctype;
16650         uint32_t ptype_num = 0;
16651         struct rte_pmd_i40e_ptype_info *ptype;
16652         uint8_t proto_id;
16653
16654 #endif
16655
16656         pkg = open_file(res->filepath, &pkg_size);
16657         if (!pkg)
16658                 return;
16659
16660 #ifdef RTE_LIBRTE_I40E_PMD
16661         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16662                                 (uint8_t *)&info, sizeof(info),
16663                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16664         if (!ret) {
16665                 printf("Global Track id:       0x%x\n", info.track_id);
16666                 printf("Global Version:        %d.%d.%d.%d\n",
16667                         info.version.major,
16668                         info.version.minor,
16669                         info.version.update,
16670                         info.version.draft);
16671                 printf("Global Package name:   %s\n\n", info.name);
16672         }
16673
16674         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16675                                 (uint8_t *)&info, sizeof(info),
16676                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16677         if (!ret) {
16678                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16679                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16680                         info.version.major,
16681                         info.version.minor,
16682                         info.version.update,
16683                         info.version.draft);
16684                 printf("i40e Profile name:     %s\n\n", info.name);
16685         }
16686
16687         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16688                                 (uint8_t *)&buff_size, sizeof(buff_size),
16689                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16690         if (!ret && buff_size) {
16691                 buff = (uint8_t *)malloc(buff_size);
16692                 if (buff) {
16693                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16694                                                 buff, buff_size,
16695                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16696                         if (!ret)
16697                                 printf("Package Notes:\n%s\n\n", buff);
16698                         free(buff);
16699                 }
16700         }
16701
16702         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16703                                 (uint8_t *)&dev_num, sizeof(dev_num),
16704                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16705         if (!ret && dev_num) {
16706                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16707                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16708                 if (devs) {
16709                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16710                                                 (uint8_t *)devs, buff_size,
16711                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16712                         if (!ret) {
16713                                 printf("List of supported devices:\n");
16714                                 for (i = 0; i < dev_num; i++) {
16715                                         printf("  %04X:%04X %04X:%04X\n",
16716                                                 devs[i].vendor_dev_id >> 16,
16717                                                 devs[i].vendor_dev_id & 0xFFFF,
16718                                                 devs[i].sub_vendor_dev_id >> 16,
16719                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16720                                 }
16721                                 printf("\n");
16722                         }
16723                         free(devs);
16724                 }
16725         }
16726
16727         /* get information about protocols and packet types */
16728         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16729                 (uint8_t *)&proto_num, sizeof(proto_num),
16730                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16731         if (ret || !proto_num)
16732                 goto no_print_return;
16733
16734         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16735         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16736         if (!proto)
16737                 goto no_print_return;
16738
16739         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16740                                         buff_size,
16741                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16742         if (!ret) {
16743                 printf("List of used protocols:\n");
16744                 for (i = 0; i < proto_num; i++)
16745                         printf("  %2u: %s\n", proto[i].proto_id,
16746                                proto[i].name);
16747                 printf("\n");
16748         }
16749         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16750                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16751                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16752         if (ret || !pctype_num)
16753                 goto no_print_pctypes;
16754
16755         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16756         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16757         if (!pctype)
16758                 goto no_print_pctypes;
16759
16760         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16761                                         buff_size,
16762                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16763         if (ret) {
16764                 free(pctype);
16765                 goto no_print_pctypes;
16766         }
16767
16768         printf("List of defined packet classification types:\n");
16769         for (i = 0; i < pctype_num; i++) {
16770                 printf("  %2u:", pctype[i].ptype_id);
16771                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16772                         proto_id = pctype[i].protocols[j];
16773                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16774                                 for (n = 0; n < proto_num; n++) {
16775                                         if (proto[n].proto_id == proto_id) {
16776                                                 printf(" %s", proto[n].name);
16777                                                 break;
16778                                         }
16779                                 }
16780                         }
16781                 }
16782                 printf("\n");
16783         }
16784         printf("\n");
16785         free(pctype);
16786
16787 no_print_pctypes:
16788
16789         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16790                                         sizeof(ptype_num),
16791                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16792         if (ret || !ptype_num)
16793                 goto no_print_return;
16794
16795         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16796         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16797         if (!ptype)
16798                 goto no_print_return;
16799
16800         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16801                                         buff_size,
16802                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16803         if (ret) {
16804                 free(ptype);
16805                 goto no_print_return;
16806         }
16807         printf("List of defined packet types:\n");
16808         for (i = 0; i < ptype_num; i++) {
16809                 printf("  %2u:", ptype[i].ptype_id);
16810                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16811                         proto_id = ptype[i].protocols[j];
16812                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16813                                 for (n = 0; n < proto_num; n++) {
16814                                         if (proto[n].proto_id == proto_id) {
16815                                                 printf(" %s", proto[n].name);
16816                                                 break;
16817                                         }
16818                                 }
16819                         }
16820                 }
16821                 printf("\n");
16822         }
16823         free(ptype);
16824         printf("\n");
16825
16826         ret = 0;
16827 no_print_return:
16828         if (proto)
16829                 free(proto);
16830 #endif
16831         if (ret == -ENOTSUP)
16832                 printf("Function not supported in PMD driver\n");
16833         close_file(pkg);
16834 }
16835
16836 cmdline_parse_inst_t cmd_ddp_get_info = {
16837         .f = cmd_ddp_info_parsed,
16838         .data = NULL,
16839         .help_str = "ddp get info <profile_path>",
16840         .tokens = {
16841                 (void *)&cmd_ddp_info_ddp,
16842                 (void *)&cmd_ddp_info_get,
16843                 (void *)&cmd_ddp_info_info,
16844                 (void *)&cmd_ddp_info_filepath,
16845                 NULL,
16846         },
16847 };
16848
16849 /* Get dynamic device personalization profile info list*/
16850 #define PROFILE_INFO_SIZE 48
16851 #define MAX_PROFILE_NUM 16
16852
16853 struct cmd_ddp_get_list_result {
16854         cmdline_fixed_string_t ddp;
16855         cmdline_fixed_string_t get;
16856         cmdline_fixed_string_t list;
16857         portid_t port_id;
16858 };
16859
16860 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16861         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16862 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16863         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16864 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16865         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16866 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16867         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16868
16869 static void
16870 cmd_ddp_get_list_parsed(
16871         __rte_unused void *parsed_result,
16872         __rte_unused struct cmdline *cl,
16873         __rte_unused void *data)
16874 {
16875 #ifdef RTE_LIBRTE_I40E_PMD
16876         struct cmd_ddp_get_list_result *res = parsed_result;
16877         struct rte_pmd_i40e_profile_list *p_list;
16878         struct rte_pmd_i40e_profile_info *p_info;
16879         uint32_t p_num;
16880         uint32_t size;
16881         uint32_t i;
16882 #endif
16883         int ret = -ENOTSUP;
16884
16885 #ifdef RTE_LIBRTE_I40E_PMD
16886         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16887         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16888         if (!p_list)
16889                 printf("%s: Failed to malloc buffer\n", __func__);
16890
16891         if (ret == -ENOTSUP)
16892                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16893                                                 (uint8_t *)p_list, size);
16894
16895         if (!ret) {
16896                 p_num = p_list->p_count;
16897                 printf("Profile number is: %d\n\n", p_num);
16898
16899                 for (i = 0; i < p_num; i++) {
16900                         p_info = &p_list->p_info[i];
16901                         printf("Profile %d:\n", i);
16902                         printf("Track id:     0x%x\n", p_info->track_id);
16903                         printf("Version:      %d.%d.%d.%d\n",
16904                                p_info->version.major,
16905                                p_info->version.minor,
16906                                p_info->version.update,
16907                                p_info->version.draft);
16908                         printf("Profile name: %s\n\n", p_info->name);
16909                 }
16910         }
16911
16912         free(p_list);
16913 #endif
16914
16915         if (ret < 0)
16916                 printf("Failed to get ddp list\n");
16917 }
16918
16919 cmdline_parse_inst_t cmd_ddp_get_list = {
16920         .f = cmd_ddp_get_list_parsed,
16921         .data = NULL,
16922         .help_str = "ddp get list <port_id>",
16923         .tokens = {
16924                 (void *)&cmd_ddp_get_list_ddp,
16925                 (void *)&cmd_ddp_get_list_get,
16926                 (void *)&cmd_ddp_get_list_list,
16927                 (void *)&cmd_ddp_get_list_port_id,
16928                 NULL,
16929         },
16930 };
16931
16932 /* Configure input set */
16933 struct cmd_cfg_input_set_result {
16934         cmdline_fixed_string_t port;
16935         cmdline_fixed_string_t cfg;
16936         portid_t port_id;
16937         cmdline_fixed_string_t pctype;
16938         uint8_t pctype_id;
16939         cmdline_fixed_string_t inset_type;
16940         cmdline_fixed_string_t opt;
16941         cmdline_fixed_string_t field;
16942         uint8_t field_idx;
16943 };
16944
16945 static void
16946 cmd_cfg_input_set_parsed(
16947         __rte_unused void *parsed_result,
16948         __rte_unused struct cmdline *cl,
16949         __rte_unused void *data)
16950 {
16951 #ifdef RTE_LIBRTE_I40E_PMD
16952         struct cmd_cfg_input_set_result *res = parsed_result;
16953         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16954         struct rte_pmd_i40e_inset inset;
16955 #endif
16956         int ret = -ENOTSUP;
16957
16958         if (!all_ports_stopped()) {
16959                 printf("Please stop all ports first\n");
16960                 return;
16961         }
16962
16963 #ifdef RTE_LIBRTE_I40E_PMD
16964         if (!strcmp(res->inset_type, "hash_inset"))
16965                 inset_type = INSET_HASH;
16966         else if (!strcmp(res->inset_type, "fdir_inset"))
16967                 inset_type = INSET_FDIR;
16968         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16969                 inset_type = INSET_FDIR_FLX;
16970         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16971                                      &inset, inset_type);
16972         if (ret) {
16973                 printf("Failed to get input set.\n");
16974                 return;
16975         }
16976
16977         if (!strcmp(res->opt, "get")) {
16978                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16979                                                    res->field_idx);
16980                 if (ret)
16981                         printf("Field index %d is enabled.\n", res->field_idx);
16982                 else
16983                         printf("Field index %d is disabled.\n", res->field_idx);
16984                 return;
16985         } else if (!strcmp(res->opt, "set"))
16986                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16987                                                    res->field_idx);
16988         else if (!strcmp(res->opt, "clear"))
16989                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16990                                                      res->field_idx);
16991         if (ret) {
16992                 printf("Failed to configure input set field.\n");
16993                 return;
16994         }
16995
16996         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16997                                      &inset, inset_type);
16998         if (ret) {
16999                 printf("Failed to set input set.\n");
17000                 return;
17001         }
17002 #endif
17003
17004         if (ret == -ENOTSUP)
17005                 printf("Function not supported\n");
17006 }
17007
17008 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17009         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17010                                  port, "port");
17011 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17012         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17013                                  cfg, "config");
17014 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17015         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17016                               port_id, UINT16);
17017 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17018         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17019                                  pctype, "pctype");
17020 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17021         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17022                               pctype_id, UINT8);
17023 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17024         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17025                                  inset_type,
17026                                  "hash_inset#fdir_inset#fdir_flx_inset");
17027 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17028         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17029                                  opt, "get#set#clear");
17030 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17031         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17032                                  field, "field");
17033 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17034         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17035                               field_idx, UINT8);
17036
17037 cmdline_parse_inst_t cmd_cfg_input_set = {
17038         .f = cmd_cfg_input_set_parsed,
17039         .data = NULL,
17040         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17041                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17042         .tokens = {
17043                 (void *)&cmd_cfg_input_set_port,
17044                 (void *)&cmd_cfg_input_set_cfg,
17045                 (void *)&cmd_cfg_input_set_port_id,
17046                 (void *)&cmd_cfg_input_set_pctype,
17047                 (void *)&cmd_cfg_input_set_pctype_id,
17048                 (void *)&cmd_cfg_input_set_inset_type,
17049                 (void *)&cmd_cfg_input_set_opt,
17050                 (void *)&cmd_cfg_input_set_field,
17051                 (void *)&cmd_cfg_input_set_field_idx,
17052                 NULL,
17053         },
17054 };
17055
17056 /* Clear input set */
17057 struct cmd_clear_input_set_result {
17058         cmdline_fixed_string_t port;
17059         cmdline_fixed_string_t cfg;
17060         portid_t port_id;
17061         cmdline_fixed_string_t pctype;
17062         uint8_t pctype_id;
17063         cmdline_fixed_string_t inset_type;
17064         cmdline_fixed_string_t clear;
17065         cmdline_fixed_string_t all;
17066 };
17067
17068 static void
17069 cmd_clear_input_set_parsed(
17070         __rte_unused void *parsed_result,
17071         __rte_unused struct cmdline *cl,
17072         __rte_unused void *data)
17073 {
17074 #ifdef RTE_LIBRTE_I40E_PMD
17075         struct cmd_clear_input_set_result *res = parsed_result;
17076         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17077         struct rte_pmd_i40e_inset inset;
17078 #endif
17079         int ret = -ENOTSUP;
17080
17081         if (!all_ports_stopped()) {
17082                 printf("Please stop all ports first\n");
17083                 return;
17084         }
17085
17086 #ifdef RTE_LIBRTE_I40E_PMD
17087         if (!strcmp(res->inset_type, "hash_inset"))
17088                 inset_type = INSET_HASH;
17089         else if (!strcmp(res->inset_type, "fdir_inset"))
17090                 inset_type = INSET_FDIR;
17091         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17092                 inset_type = INSET_FDIR_FLX;
17093
17094         memset(&inset, 0, sizeof(inset));
17095
17096         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17097                                      &inset, inset_type);
17098         if (ret) {
17099                 printf("Failed to clear input set.\n");
17100                 return;
17101         }
17102
17103 #endif
17104
17105         if (ret == -ENOTSUP)
17106                 printf("Function not supported\n");
17107 }
17108
17109 cmdline_parse_token_string_t cmd_clear_input_set_port =
17110         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17111                                  port, "port");
17112 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17113         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17114                                  cfg, "config");
17115 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17116         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17117                               port_id, UINT16);
17118 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17119         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17120                                  pctype, "pctype");
17121 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17122         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17123                               pctype_id, UINT8);
17124 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17125         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17126                                  inset_type,
17127                                  "hash_inset#fdir_inset#fdir_flx_inset");
17128 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17129         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17130                                  clear, "clear");
17131 cmdline_parse_token_string_t cmd_clear_input_set_all =
17132         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17133                                  all, "all");
17134
17135 cmdline_parse_inst_t cmd_clear_input_set = {
17136         .f = cmd_clear_input_set_parsed,
17137         .data = NULL,
17138         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17139                     "fdir_inset|fdir_flx_inset clear all",
17140         .tokens = {
17141                 (void *)&cmd_clear_input_set_port,
17142                 (void *)&cmd_clear_input_set_cfg,
17143                 (void *)&cmd_clear_input_set_port_id,
17144                 (void *)&cmd_clear_input_set_pctype,
17145                 (void *)&cmd_clear_input_set_pctype_id,
17146                 (void *)&cmd_clear_input_set_inset_type,
17147                 (void *)&cmd_clear_input_set_clear,
17148                 (void *)&cmd_clear_input_set_all,
17149                 NULL,
17150         },
17151 };
17152
17153 /* show vf stats */
17154
17155 /* Common result structure for show vf stats */
17156 struct cmd_show_vf_stats_result {
17157         cmdline_fixed_string_t show;
17158         cmdline_fixed_string_t vf;
17159         cmdline_fixed_string_t stats;
17160         portid_t port_id;
17161         uint16_t vf_id;
17162 };
17163
17164 /* Common CLI fields show vf stats*/
17165 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17166         TOKEN_STRING_INITIALIZER
17167                 (struct cmd_show_vf_stats_result,
17168                  show, "show");
17169 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17170         TOKEN_STRING_INITIALIZER
17171                 (struct cmd_show_vf_stats_result,
17172                  vf, "vf");
17173 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17174         TOKEN_STRING_INITIALIZER
17175                 (struct cmd_show_vf_stats_result,
17176                  stats, "stats");
17177 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17178         TOKEN_NUM_INITIALIZER
17179                 (struct cmd_show_vf_stats_result,
17180                  port_id, UINT16);
17181 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17182         TOKEN_NUM_INITIALIZER
17183                 (struct cmd_show_vf_stats_result,
17184                  vf_id, UINT16);
17185
17186 static void
17187 cmd_show_vf_stats_parsed(
17188         void *parsed_result,
17189         __rte_unused struct cmdline *cl,
17190         __rte_unused void *data)
17191 {
17192         struct cmd_show_vf_stats_result *res = parsed_result;
17193         struct rte_eth_stats stats;
17194         int ret = -ENOTSUP;
17195         static const char *nic_stats_border = "########################";
17196
17197         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17198                 return;
17199
17200         memset(&stats, 0, sizeof(stats));
17201
17202 #ifdef RTE_LIBRTE_I40E_PMD
17203         if (ret == -ENOTSUP)
17204                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17205                                                 res->vf_id,
17206                                                 &stats);
17207 #endif
17208 #ifdef RTE_LIBRTE_BNXT_PMD
17209         if (ret == -ENOTSUP)
17210                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17211                                                 res->vf_id,
17212                                                 &stats);
17213 #endif
17214
17215         switch (ret) {
17216         case 0:
17217                 break;
17218         case -EINVAL:
17219                 printf("invalid vf_id %d\n", res->vf_id);
17220                 break;
17221         case -ENODEV:
17222                 printf("invalid port_id %d\n", res->port_id);
17223                 break;
17224         case -ENOTSUP:
17225                 printf("function not implemented\n");
17226                 break;
17227         default:
17228                 printf("programming error: (%s)\n", strerror(-ret));
17229         }
17230
17231         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17232                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17233
17234         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17235                "%-"PRIu64"\n",
17236                stats.ipackets, stats.imissed, stats.ibytes);
17237         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17238         printf("  RX-nombuf:  %-10"PRIu64"\n",
17239                stats.rx_nombuf);
17240         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17241                "%-"PRIu64"\n",
17242                stats.opackets, stats.oerrors, stats.obytes);
17243
17244         printf("  %s############################%s\n",
17245                                nic_stats_border, nic_stats_border);
17246 }
17247
17248 cmdline_parse_inst_t cmd_show_vf_stats = {
17249         .f = cmd_show_vf_stats_parsed,
17250         .data = NULL,
17251         .help_str = "show vf stats <port_id> <vf_id>",
17252         .tokens = {
17253                 (void *)&cmd_show_vf_stats_show,
17254                 (void *)&cmd_show_vf_stats_vf,
17255                 (void *)&cmd_show_vf_stats_stats,
17256                 (void *)&cmd_show_vf_stats_port_id,
17257                 (void *)&cmd_show_vf_stats_vf_id,
17258                 NULL,
17259         },
17260 };
17261
17262 /* clear vf stats */
17263
17264 /* Common result structure for clear vf stats */
17265 struct cmd_clear_vf_stats_result {
17266         cmdline_fixed_string_t clear;
17267         cmdline_fixed_string_t vf;
17268         cmdline_fixed_string_t stats;
17269         portid_t port_id;
17270         uint16_t vf_id;
17271 };
17272
17273 /* Common CLI fields clear vf stats*/
17274 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17275         TOKEN_STRING_INITIALIZER
17276                 (struct cmd_clear_vf_stats_result,
17277                  clear, "clear");
17278 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17279         TOKEN_STRING_INITIALIZER
17280                 (struct cmd_clear_vf_stats_result,
17281                  vf, "vf");
17282 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17283         TOKEN_STRING_INITIALIZER
17284                 (struct cmd_clear_vf_stats_result,
17285                  stats, "stats");
17286 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17287         TOKEN_NUM_INITIALIZER
17288                 (struct cmd_clear_vf_stats_result,
17289                  port_id, UINT16);
17290 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17291         TOKEN_NUM_INITIALIZER
17292                 (struct cmd_clear_vf_stats_result,
17293                  vf_id, UINT16);
17294
17295 static void
17296 cmd_clear_vf_stats_parsed(
17297         void *parsed_result,
17298         __rte_unused struct cmdline *cl,
17299         __rte_unused void *data)
17300 {
17301         struct cmd_clear_vf_stats_result *res = parsed_result;
17302         int ret = -ENOTSUP;
17303
17304         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17305                 return;
17306
17307 #ifdef RTE_LIBRTE_I40E_PMD
17308         if (ret == -ENOTSUP)
17309                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17310                                                   res->vf_id);
17311 #endif
17312 #ifdef RTE_LIBRTE_BNXT_PMD
17313         if (ret == -ENOTSUP)
17314                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17315                                                   res->vf_id);
17316 #endif
17317
17318         switch (ret) {
17319         case 0:
17320                 break;
17321         case -EINVAL:
17322                 printf("invalid vf_id %d\n", res->vf_id);
17323                 break;
17324         case -ENODEV:
17325                 printf("invalid port_id %d\n", res->port_id);
17326                 break;
17327         case -ENOTSUP:
17328                 printf("function not implemented\n");
17329                 break;
17330         default:
17331                 printf("programming error: (%s)\n", strerror(-ret));
17332         }
17333 }
17334
17335 cmdline_parse_inst_t cmd_clear_vf_stats = {
17336         .f = cmd_clear_vf_stats_parsed,
17337         .data = NULL,
17338         .help_str = "clear vf stats <port_id> <vf_id>",
17339         .tokens = {
17340                 (void *)&cmd_clear_vf_stats_clear,
17341                 (void *)&cmd_clear_vf_stats_vf,
17342                 (void *)&cmd_clear_vf_stats_stats,
17343                 (void *)&cmd_clear_vf_stats_port_id,
17344                 (void *)&cmd_clear_vf_stats_vf_id,
17345                 NULL,
17346         },
17347 };
17348
17349 /* port config pctype mapping reset */
17350
17351 /* Common result structure for port config pctype mapping reset */
17352 struct cmd_pctype_mapping_reset_result {
17353         cmdline_fixed_string_t port;
17354         cmdline_fixed_string_t config;
17355         portid_t port_id;
17356         cmdline_fixed_string_t pctype;
17357         cmdline_fixed_string_t mapping;
17358         cmdline_fixed_string_t reset;
17359 };
17360
17361 /* Common CLI fields for port config pctype mapping reset*/
17362 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17363         TOKEN_STRING_INITIALIZER
17364                 (struct cmd_pctype_mapping_reset_result,
17365                  port, "port");
17366 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17367         TOKEN_STRING_INITIALIZER
17368                 (struct cmd_pctype_mapping_reset_result,
17369                  config, "config");
17370 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17371         TOKEN_NUM_INITIALIZER
17372                 (struct cmd_pctype_mapping_reset_result,
17373                  port_id, UINT16);
17374 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17375         TOKEN_STRING_INITIALIZER
17376                 (struct cmd_pctype_mapping_reset_result,
17377                  pctype, "pctype");
17378 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17379         TOKEN_STRING_INITIALIZER
17380                 (struct cmd_pctype_mapping_reset_result,
17381                  mapping, "mapping");
17382 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17383         TOKEN_STRING_INITIALIZER
17384                 (struct cmd_pctype_mapping_reset_result,
17385                  reset, "reset");
17386
17387 static void
17388 cmd_pctype_mapping_reset_parsed(
17389         void *parsed_result,
17390         __rte_unused struct cmdline *cl,
17391         __rte_unused void *data)
17392 {
17393         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17394         int ret = -ENOTSUP;
17395
17396         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17397                 return;
17398
17399 #ifdef RTE_LIBRTE_I40E_PMD
17400         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17401 #endif
17402
17403         switch (ret) {
17404         case 0:
17405                 break;
17406         case -ENODEV:
17407                 printf("invalid port_id %d\n", res->port_id);
17408                 break;
17409         case -ENOTSUP:
17410                 printf("function not implemented\n");
17411                 break;
17412         default:
17413                 printf("programming error: (%s)\n", strerror(-ret));
17414         }
17415 }
17416
17417 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17418         .f = cmd_pctype_mapping_reset_parsed,
17419         .data = NULL,
17420         .help_str = "port config <port_id> pctype mapping reset",
17421         .tokens = {
17422                 (void *)&cmd_pctype_mapping_reset_port,
17423                 (void *)&cmd_pctype_mapping_reset_config,
17424                 (void *)&cmd_pctype_mapping_reset_port_id,
17425                 (void *)&cmd_pctype_mapping_reset_pctype,
17426                 (void *)&cmd_pctype_mapping_reset_mapping,
17427                 (void *)&cmd_pctype_mapping_reset_reset,
17428                 NULL,
17429         },
17430 };
17431
17432 /* show port pctype mapping */
17433
17434 /* Common result structure for show port pctype mapping */
17435 struct cmd_pctype_mapping_get_result {
17436         cmdline_fixed_string_t show;
17437         cmdline_fixed_string_t port;
17438         portid_t port_id;
17439         cmdline_fixed_string_t pctype;
17440         cmdline_fixed_string_t mapping;
17441 };
17442
17443 /* Common CLI fields for pctype mapping get */
17444 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17445         TOKEN_STRING_INITIALIZER
17446                 (struct cmd_pctype_mapping_get_result,
17447                  show, "show");
17448 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17449         TOKEN_STRING_INITIALIZER
17450                 (struct cmd_pctype_mapping_get_result,
17451                  port, "port");
17452 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17453         TOKEN_NUM_INITIALIZER
17454                 (struct cmd_pctype_mapping_get_result,
17455                  port_id, UINT16);
17456 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17457         TOKEN_STRING_INITIALIZER
17458                 (struct cmd_pctype_mapping_get_result,
17459                  pctype, "pctype");
17460 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17461         TOKEN_STRING_INITIALIZER
17462                 (struct cmd_pctype_mapping_get_result,
17463                  mapping, "mapping");
17464
17465 static void
17466 cmd_pctype_mapping_get_parsed(
17467         void *parsed_result,
17468         __rte_unused struct cmdline *cl,
17469         __rte_unused void *data)
17470 {
17471         struct cmd_pctype_mapping_get_result *res = parsed_result;
17472         int ret = -ENOTSUP;
17473 #ifdef RTE_LIBRTE_I40E_PMD
17474         struct rte_pmd_i40e_flow_type_mapping
17475                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17476         int i, j, first_pctype;
17477 #endif
17478
17479         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17480                 return;
17481
17482 #ifdef RTE_LIBRTE_I40E_PMD
17483         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17484 #endif
17485
17486         switch (ret) {
17487         case 0:
17488                 break;
17489         case -ENODEV:
17490                 printf("invalid port_id %d\n", res->port_id);
17491                 return;
17492         case -ENOTSUP:
17493                 printf("function not implemented\n");
17494                 return;
17495         default:
17496                 printf("programming error: (%s)\n", strerror(-ret));
17497                 return;
17498         }
17499
17500 #ifdef RTE_LIBRTE_I40E_PMD
17501         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17502                 if (mapping[i].pctype != 0ULL) {
17503                         first_pctype = 1;
17504
17505                         printf("pctype: ");
17506                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17507                                 if (mapping[i].pctype & (1ULL << j)) {
17508                                         printf(first_pctype ?
17509                                                "%02d" : ",%02d", j);
17510                                         first_pctype = 0;
17511                                 }
17512                         }
17513                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17514                 }
17515         }
17516 #endif
17517 }
17518
17519 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17520         .f = cmd_pctype_mapping_get_parsed,
17521         .data = NULL,
17522         .help_str = "show port <port_id> pctype mapping",
17523         .tokens = {
17524                 (void *)&cmd_pctype_mapping_get_show,
17525                 (void *)&cmd_pctype_mapping_get_port,
17526                 (void *)&cmd_pctype_mapping_get_port_id,
17527                 (void *)&cmd_pctype_mapping_get_pctype,
17528                 (void *)&cmd_pctype_mapping_get_mapping,
17529                 NULL,
17530         },
17531 };
17532
17533 /* port config pctype mapping update */
17534
17535 /* Common result structure for port config pctype mapping update */
17536 struct cmd_pctype_mapping_update_result {
17537         cmdline_fixed_string_t port;
17538         cmdline_fixed_string_t config;
17539         portid_t port_id;
17540         cmdline_fixed_string_t pctype;
17541         cmdline_fixed_string_t mapping;
17542         cmdline_fixed_string_t update;
17543         cmdline_fixed_string_t pctype_list;
17544         uint16_t flow_type;
17545 };
17546
17547 /* Common CLI fields for pctype mapping update*/
17548 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17549         TOKEN_STRING_INITIALIZER
17550                 (struct cmd_pctype_mapping_update_result,
17551                  port, "port");
17552 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17553         TOKEN_STRING_INITIALIZER
17554                 (struct cmd_pctype_mapping_update_result,
17555                  config, "config");
17556 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17557         TOKEN_NUM_INITIALIZER
17558                 (struct cmd_pctype_mapping_update_result,
17559                  port_id, UINT16);
17560 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17561         TOKEN_STRING_INITIALIZER
17562                 (struct cmd_pctype_mapping_update_result,
17563                  pctype, "pctype");
17564 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17565         TOKEN_STRING_INITIALIZER
17566                 (struct cmd_pctype_mapping_update_result,
17567                  mapping, "mapping");
17568 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17569         TOKEN_STRING_INITIALIZER
17570                 (struct cmd_pctype_mapping_update_result,
17571                  update, "update");
17572 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17573         TOKEN_STRING_INITIALIZER
17574                 (struct cmd_pctype_mapping_update_result,
17575                  pctype_list, NULL);
17576 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17577         TOKEN_NUM_INITIALIZER
17578                 (struct cmd_pctype_mapping_update_result,
17579                  flow_type, UINT16);
17580
17581 static void
17582 cmd_pctype_mapping_update_parsed(
17583         void *parsed_result,
17584         __rte_unused struct cmdline *cl,
17585         __rte_unused void *data)
17586 {
17587         struct cmd_pctype_mapping_update_result *res = parsed_result;
17588         int ret = -ENOTSUP;
17589 #ifdef RTE_LIBRTE_I40E_PMD
17590         struct rte_pmd_i40e_flow_type_mapping mapping;
17591         unsigned int i;
17592         unsigned int nb_item;
17593         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17594 #endif
17595
17596         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17597                 return;
17598
17599 #ifdef RTE_LIBRTE_I40E_PMD
17600         nb_item = parse_item_list(res->pctype_list, "pctypes",
17601                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17602         mapping.flow_type = res->flow_type;
17603         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17604                 mapping.pctype |= (1ULL << pctype_list[i]);
17605         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17606                                                 &mapping,
17607                                                 1,
17608                                                 0);
17609 #endif
17610
17611         switch (ret) {
17612         case 0:
17613                 break;
17614         case -EINVAL:
17615                 printf("invalid pctype or flow type\n");
17616                 break;
17617         case -ENODEV:
17618                 printf("invalid port_id %d\n", res->port_id);
17619                 break;
17620         case -ENOTSUP:
17621                 printf("function not implemented\n");
17622                 break;
17623         default:
17624                 printf("programming error: (%s)\n", strerror(-ret));
17625         }
17626 }
17627
17628 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17629         .f = cmd_pctype_mapping_update_parsed,
17630         .data = NULL,
17631         .help_str = "port config <port_id> pctype mapping update"
17632         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17633         .tokens = {
17634                 (void *)&cmd_pctype_mapping_update_port,
17635                 (void *)&cmd_pctype_mapping_update_config,
17636                 (void *)&cmd_pctype_mapping_update_port_id,
17637                 (void *)&cmd_pctype_mapping_update_pctype,
17638                 (void *)&cmd_pctype_mapping_update_mapping,
17639                 (void *)&cmd_pctype_mapping_update_update,
17640                 (void *)&cmd_pctype_mapping_update_pc_type,
17641                 (void *)&cmd_pctype_mapping_update_flow_type,
17642                 NULL,
17643         },
17644 };
17645
17646 /* ptype mapping get */
17647
17648 /* Common result structure for ptype mapping get */
17649 struct cmd_ptype_mapping_get_result {
17650         cmdline_fixed_string_t ptype;
17651         cmdline_fixed_string_t mapping;
17652         cmdline_fixed_string_t get;
17653         portid_t port_id;
17654         uint8_t valid_only;
17655 };
17656
17657 /* Common CLI fields for ptype mapping get */
17658 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17659         TOKEN_STRING_INITIALIZER
17660                 (struct cmd_ptype_mapping_get_result,
17661                  ptype, "ptype");
17662 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17663         TOKEN_STRING_INITIALIZER
17664                 (struct cmd_ptype_mapping_get_result,
17665                  mapping, "mapping");
17666 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17667         TOKEN_STRING_INITIALIZER
17668                 (struct cmd_ptype_mapping_get_result,
17669                  get, "get");
17670 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17671         TOKEN_NUM_INITIALIZER
17672                 (struct cmd_ptype_mapping_get_result,
17673                  port_id, UINT16);
17674 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17675         TOKEN_NUM_INITIALIZER
17676                 (struct cmd_ptype_mapping_get_result,
17677                  valid_only, UINT8);
17678
17679 static void
17680 cmd_ptype_mapping_get_parsed(
17681         void *parsed_result,
17682         __rte_unused struct cmdline *cl,
17683         __rte_unused void *data)
17684 {
17685         struct cmd_ptype_mapping_get_result *res = parsed_result;
17686         int ret = -ENOTSUP;
17687 #ifdef RTE_LIBRTE_I40E_PMD
17688         int max_ptype_num = 256;
17689         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17690         uint16_t count;
17691         int i;
17692 #endif
17693
17694         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17695                 return;
17696
17697 #ifdef RTE_LIBRTE_I40E_PMD
17698         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17699                                         mapping,
17700                                         max_ptype_num,
17701                                         &count,
17702                                         res->valid_only);
17703 #endif
17704
17705         switch (ret) {
17706         case 0:
17707                 break;
17708         case -ENODEV:
17709                 printf("invalid port_id %d\n", res->port_id);
17710                 break;
17711         case -ENOTSUP:
17712                 printf("function not implemented\n");
17713                 break;
17714         default:
17715                 printf("programming error: (%s)\n", strerror(-ret));
17716         }
17717
17718 #ifdef RTE_LIBRTE_I40E_PMD
17719         if (!ret) {
17720                 for (i = 0; i < count; i++)
17721                         printf("%3d\t0x%08x\n",
17722                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17723         }
17724 #endif
17725 }
17726
17727 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17728         .f = cmd_ptype_mapping_get_parsed,
17729         .data = NULL,
17730         .help_str = "ptype mapping get <port_id> <valid_only>",
17731         .tokens = {
17732                 (void *)&cmd_ptype_mapping_get_ptype,
17733                 (void *)&cmd_ptype_mapping_get_mapping,
17734                 (void *)&cmd_ptype_mapping_get_get,
17735                 (void *)&cmd_ptype_mapping_get_port_id,
17736                 (void *)&cmd_ptype_mapping_get_valid_only,
17737                 NULL,
17738         },
17739 };
17740
17741 /* ptype mapping replace */
17742
17743 /* Common result structure for ptype mapping replace */
17744 struct cmd_ptype_mapping_replace_result {
17745         cmdline_fixed_string_t ptype;
17746         cmdline_fixed_string_t mapping;
17747         cmdline_fixed_string_t replace;
17748         portid_t port_id;
17749         uint32_t target;
17750         uint8_t mask;
17751         uint32_t pkt_type;
17752 };
17753
17754 /* Common CLI fields for ptype mapping replace */
17755 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17756         TOKEN_STRING_INITIALIZER
17757                 (struct cmd_ptype_mapping_replace_result,
17758                  ptype, "ptype");
17759 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17760         TOKEN_STRING_INITIALIZER
17761                 (struct cmd_ptype_mapping_replace_result,
17762                  mapping, "mapping");
17763 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17764         TOKEN_STRING_INITIALIZER
17765                 (struct cmd_ptype_mapping_replace_result,
17766                  replace, "replace");
17767 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17768         TOKEN_NUM_INITIALIZER
17769                 (struct cmd_ptype_mapping_replace_result,
17770                  port_id, UINT16);
17771 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17772         TOKEN_NUM_INITIALIZER
17773                 (struct cmd_ptype_mapping_replace_result,
17774                  target, UINT32);
17775 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17776         TOKEN_NUM_INITIALIZER
17777                 (struct cmd_ptype_mapping_replace_result,
17778                  mask, UINT8);
17779 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17780         TOKEN_NUM_INITIALIZER
17781                 (struct cmd_ptype_mapping_replace_result,
17782                  pkt_type, UINT32);
17783
17784 static void
17785 cmd_ptype_mapping_replace_parsed(
17786         void *parsed_result,
17787         __rte_unused struct cmdline *cl,
17788         __rte_unused void *data)
17789 {
17790         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17791         int ret = -ENOTSUP;
17792
17793         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17794                 return;
17795
17796 #ifdef RTE_LIBRTE_I40E_PMD
17797         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17798                                         res->target,
17799                                         res->mask,
17800                                         res->pkt_type);
17801 #endif
17802
17803         switch (ret) {
17804         case 0:
17805                 break;
17806         case -EINVAL:
17807                 printf("invalid ptype 0x%8x or 0x%8x\n",
17808                                 res->target, res->pkt_type);
17809                 break;
17810         case -ENODEV:
17811                 printf("invalid port_id %d\n", res->port_id);
17812                 break;
17813         case -ENOTSUP:
17814                 printf("function not implemented\n");
17815                 break;
17816         default:
17817                 printf("programming error: (%s)\n", strerror(-ret));
17818         }
17819 }
17820
17821 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17822         .f = cmd_ptype_mapping_replace_parsed,
17823         .data = NULL,
17824         .help_str =
17825                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17826         .tokens = {
17827                 (void *)&cmd_ptype_mapping_replace_ptype,
17828                 (void *)&cmd_ptype_mapping_replace_mapping,
17829                 (void *)&cmd_ptype_mapping_replace_replace,
17830                 (void *)&cmd_ptype_mapping_replace_port_id,
17831                 (void *)&cmd_ptype_mapping_replace_target,
17832                 (void *)&cmd_ptype_mapping_replace_mask,
17833                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17834                 NULL,
17835         },
17836 };
17837
17838 /* ptype mapping reset */
17839
17840 /* Common result structure for ptype mapping reset */
17841 struct cmd_ptype_mapping_reset_result {
17842         cmdline_fixed_string_t ptype;
17843         cmdline_fixed_string_t mapping;
17844         cmdline_fixed_string_t reset;
17845         portid_t port_id;
17846 };
17847
17848 /* Common CLI fields for ptype mapping reset*/
17849 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17850         TOKEN_STRING_INITIALIZER
17851                 (struct cmd_ptype_mapping_reset_result,
17852                  ptype, "ptype");
17853 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17854         TOKEN_STRING_INITIALIZER
17855                 (struct cmd_ptype_mapping_reset_result,
17856                  mapping, "mapping");
17857 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17858         TOKEN_STRING_INITIALIZER
17859                 (struct cmd_ptype_mapping_reset_result,
17860                  reset, "reset");
17861 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17862         TOKEN_NUM_INITIALIZER
17863                 (struct cmd_ptype_mapping_reset_result,
17864                  port_id, UINT16);
17865
17866 static void
17867 cmd_ptype_mapping_reset_parsed(
17868         void *parsed_result,
17869         __rte_unused struct cmdline *cl,
17870         __rte_unused void *data)
17871 {
17872         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17873         int ret = -ENOTSUP;
17874
17875         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17876                 return;
17877
17878 #ifdef RTE_LIBRTE_I40E_PMD
17879         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17880 #endif
17881
17882         switch (ret) {
17883         case 0:
17884                 break;
17885         case -ENODEV:
17886                 printf("invalid port_id %d\n", res->port_id);
17887                 break;
17888         case -ENOTSUP:
17889                 printf("function not implemented\n");
17890                 break;
17891         default:
17892                 printf("programming error: (%s)\n", strerror(-ret));
17893         }
17894 }
17895
17896 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17897         .f = cmd_ptype_mapping_reset_parsed,
17898         .data = NULL,
17899         .help_str = "ptype mapping reset <port_id>",
17900         .tokens = {
17901                 (void *)&cmd_ptype_mapping_reset_ptype,
17902                 (void *)&cmd_ptype_mapping_reset_mapping,
17903                 (void *)&cmd_ptype_mapping_reset_reset,
17904                 (void *)&cmd_ptype_mapping_reset_port_id,
17905                 NULL,
17906         },
17907 };
17908
17909 /* ptype mapping update */
17910
17911 /* Common result structure for ptype mapping update */
17912 struct cmd_ptype_mapping_update_result {
17913         cmdline_fixed_string_t ptype;
17914         cmdline_fixed_string_t mapping;
17915         cmdline_fixed_string_t reset;
17916         portid_t port_id;
17917         uint8_t hw_ptype;
17918         uint32_t sw_ptype;
17919 };
17920
17921 /* Common CLI fields for ptype mapping update*/
17922 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17923         TOKEN_STRING_INITIALIZER
17924                 (struct cmd_ptype_mapping_update_result,
17925                  ptype, "ptype");
17926 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17927         TOKEN_STRING_INITIALIZER
17928                 (struct cmd_ptype_mapping_update_result,
17929                  mapping, "mapping");
17930 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17931         TOKEN_STRING_INITIALIZER
17932                 (struct cmd_ptype_mapping_update_result,
17933                  reset, "update");
17934 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17935         TOKEN_NUM_INITIALIZER
17936                 (struct cmd_ptype_mapping_update_result,
17937                  port_id, UINT16);
17938 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17939         TOKEN_NUM_INITIALIZER
17940                 (struct cmd_ptype_mapping_update_result,
17941                  hw_ptype, UINT8);
17942 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17943         TOKEN_NUM_INITIALIZER
17944                 (struct cmd_ptype_mapping_update_result,
17945                  sw_ptype, UINT32);
17946
17947 static void
17948 cmd_ptype_mapping_update_parsed(
17949         void *parsed_result,
17950         __rte_unused struct cmdline *cl,
17951         __rte_unused void *data)
17952 {
17953         struct cmd_ptype_mapping_update_result *res = parsed_result;
17954         int ret = -ENOTSUP;
17955 #ifdef RTE_LIBRTE_I40E_PMD
17956         struct rte_pmd_i40e_ptype_mapping mapping;
17957 #endif
17958         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17959                 return;
17960
17961 #ifdef RTE_LIBRTE_I40E_PMD
17962         mapping.hw_ptype = res->hw_ptype;
17963         mapping.sw_ptype = res->sw_ptype;
17964         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17965                                                 &mapping,
17966                                                 1,
17967                                                 0);
17968 #endif
17969
17970         switch (ret) {
17971         case 0:
17972                 break;
17973         case -EINVAL:
17974                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17975                 break;
17976         case -ENODEV:
17977                 printf("invalid port_id %d\n", res->port_id);
17978                 break;
17979         case -ENOTSUP:
17980                 printf("function not implemented\n");
17981                 break;
17982         default:
17983                 printf("programming error: (%s)\n", strerror(-ret));
17984         }
17985 }
17986
17987 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17988         .f = cmd_ptype_mapping_update_parsed,
17989         .data = NULL,
17990         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17991         .tokens = {
17992                 (void *)&cmd_ptype_mapping_update_ptype,
17993                 (void *)&cmd_ptype_mapping_update_mapping,
17994                 (void *)&cmd_ptype_mapping_update_update,
17995                 (void *)&cmd_ptype_mapping_update_port_id,
17996                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17997                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17998                 NULL,
17999         },
18000 };
18001
18002 /* Common result structure for file commands */
18003 struct cmd_cmdfile_result {
18004         cmdline_fixed_string_t load;
18005         cmdline_fixed_string_t filename;
18006 };
18007
18008 /* Common CLI fields for file commands */
18009 cmdline_parse_token_string_t cmd_load_cmdfile =
18010         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18011 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18012         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18013
18014 static void
18015 cmd_load_from_file_parsed(
18016         void *parsed_result,
18017         __rte_unused struct cmdline *cl,
18018         __rte_unused void *data)
18019 {
18020         struct cmd_cmdfile_result *res = parsed_result;
18021
18022         cmdline_read_from_file(res->filename);
18023 }
18024
18025 cmdline_parse_inst_t cmd_load_from_file = {
18026         .f = cmd_load_from_file_parsed,
18027         .data = NULL,
18028         .help_str = "load <filename>",
18029         .tokens = {
18030                 (void *)&cmd_load_cmdfile,
18031                 (void *)&cmd_load_cmdfile_filename,
18032                 NULL,
18033         },
18034 };
18035
18036 /* Get Rx offloads capabilities */
18037 struct cmd_rx_offload_get_capa_result {
18038         cmdline_fixed_string_t show;
18039         cmdline_fixed_string_t port;
18040         portid_t port_id;
18041         cmdline_fixed_string_t rx_offload;
18042         cmdline_fixed_string_t capabilities;
18043 };
18044
18045 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18046         TOKEN_STRING_INITIALIZER
18047                 (struct cmd_rx_offload_get_capa_result,
18048                  show, "show");
18049 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18050         TOKEN_STRING_INITIALIZER
18051                 (struct cmd_rx_offload_get_capa_result,
18052                  port, "port");
18053 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18054         TOKEN_NUM_INITIALIZER
18055                 (struct cmd_rx_offload_get_capa_result,
18056                  port_id, UINT16);
18057 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18058         TOKEN_STRING_INITIALIZER
18059                 (struct cmd_rx_offload_get_capa_result,
18060                  rx_offload, "rx_offload");
18061 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18062         TOKEN_STRING_INITIALIZER
18063                 (struct cmd_rx_offload_get_capa_result,
18064                  capabilities, "capabilities");
18065
18066 static void
18067 print_rx_offloads(uint64_t offloads)
18068 {
18069         uint64_t single_offload;
18070         int begin;
18071         int end;
18072         int bit;
18073
18074         if (offloads == 0)
18075                 return;
18076
18077         begin = __builtin_ctzll(offloads);
18078         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18079
18080         single_offload = 1ULL << begin;
18081         for (bit = begin; bit < end; bit++) {
18082                 if (offloads & single_offload)
18083                         printf(" %s",
18084                                rte_eth_dev_rx_offload_name(single_offload));
18085                 single_offload <<= 1;
18086         }
18087 }
18088
18089 static void
18090 cmd_rx_offload_get_capa_parsed(
18091         void *parsed_result,
18092         __rte_unused struct cmdline *cl,
18093         __rte_unused void *data)
18094 {
18095         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18096         struct rte_eth_dev_info dev_info;
18097         portid_t port_id = res->port_id;
18098         uint64_t queue_offloads;
18099         uint64_t port_offloads;
18100         int ret;
18101
18102         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18103         if (ret != 0)
18104                 return;
18105
18106         queue_offloads = dev_info.rx_queue_offload_capa;
18107         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18108
18109         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18110         printf("  Per Queue :");
18111         print_rx_offloads(queue_offloads);
18112
18113         printf("\n");
18114         printf("  Per Port  :");
18115         print_rx_offloads(port_offloads);
18116         printf("\n\n");
18117 }
18118
18119 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18120         .f = cmd_rx_offload_get_capa_parsed,
18121         .data = NULL,
18122         .help_str = "show port <port_id> rx_offload capabilities",
18123         .tokens = {
18124                 (void *)&cmd_rx_offload_get_capa_show,
18125                 (void *)&cmd_rx_offload_get_capa_port,
18126                 (void *)&cmd_rx_offload_get_capa_port_id,
18127                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18128                 (void *)&cmd_rx_offload_get_capa_capabilities,
18129                 NULL,
18130         }
18131 };
18132
18133 /* Get Rx offloads configuration */
18134 struct cmd_rx_offload_get_configuration_result {
18135         cmdline_fixed_string_t show;
18136         cmdline_fixed_string_t port;
18137         portid_t port_id;
18138         cmdline_fixed_string_t rx_offload;
18139         cmdline_fixed_string_t configuration;
18140 };
18141
18142 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18143         TOKEN_STRING_INITIALIZER
18144                 (struct cmd_rx_offload_get_configuration_result,
18145                  show, "show");
18146 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18147         TOKEN_STRING_INITIALIZER
18148                 (struct cmd_rx_offload_get_configuration_result,
18149                  port, "port");
18150 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18151         TOKEN_NUM_INITIALIZER
18152                 (struct cmd_rx_offload_get_configuration_result,
18153                  port_id, UINT16);
18154 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18155         TOKEN_STRING_INITIALIZER
18156                 (struct cmd_rx_offload_get_configuration_result,
18157                  rx_offload, "rx_offload");
18158 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18159         TOKEN_STRING_INITIALIZER
18160                 (struct cmd_rx_offload_get_configuration_result,
18161                  configuration, "configuration");
18162
18163 static void
18164 cmd_rx_offload_get_configuration_parsed(
18165         void *parsed_result,
18166         __rte_unused struct cmdline *cl,
18167         __rte_unused void *data)
18168 {
18169         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18170         struct rte_eth_dev_info dev_info;
18171         portid_t port_id = res->port_id;
18172         struct rte_port *port = &ports[port_id];
18173         uint64_t port_offloads;
18174         uint64_t queue_offloads;
18175         uint16_t nb_rx_queues;
18176         int q;
18177         int ret;
18178
18179         printf("Rx Offloading Configuration of port %d :\n", port_id);
18180
18181         port_offloads = port->dev_conf.rxmode.offloads;
18182         printf("  Port :");
18183         print_rx_offloads(port_offloads);
18184         printf("\n");
18185
18186         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18187         if (ret != 0)
18188                 return;
18189
18190         nb_rx_queues = dev_info.nb_rx_queues;
18191         for (q = 0; q < nb_rx_queues; q++) {
18192                 queue_offloads = port->rx_conf[q].offloads;
18193                 printf("  Queue[%2d] :", q);
18194                 print_rx_offloads(queue_offloads);
18195                 printf("\n");
18196         }
18197         printf("\n");
18198 }
18199
18200 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18201         .f = cmd_rx_offload_get_configuration_parsed,
18202         .data = NULL,
18203         .help_str = "show port <port_id> rx_offload configuration",
18204         .tokens = {
18205                 (void *)&cmd_rx_offload_get_configuration_show,
18206                 (void *)&cmd_rx_offload_get_configuration_port,
18207                 (void *)&cmd_rx_offload_get_configuration_port_id,
18208                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18209                 (void *)&cmd_rx_offload_get_configuration_configuration,
18210                 NULL,
18211         }
18212 };
18213
18214 /* Enable/Disable a per port offloading */
18215 struct cmd_config_per_port_rx_offload_result {
18216         cmdline_fixed_string_t port;
18217         cmdline_fixed_string_t config;
18218         portid_t port_id;
18219         cmdline_fixed_string_t rx_offload;
18220         cmdline_fixed_string_t offload;
18221         cmdline_fixed_string_t on_off;
18222 };
18223
18224 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18225         TOKEN_STRING_INITIALIZER
18226                 (struct cmd_config_per_port_rx_offload_result,
18227                  port, "port");
18228 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18229         TOKEN_STRING_INITIALIZER
18230                 (struct cmd_config_per_port_rx_offload_result,
18231                  config, "config");
18232 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18233         TOKEN_NUM_INITIALIZER
18234                 (struct cmd_config_per_port_rx_offload_result,
18235                  port_id, UINT16);
18236 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18237         TOKEN_STRING_INITIALIZER
18238                 (struct cmd_config_per_port_rx_offload_result,
18239                  rx_offload, "rx_offload");
18240 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18241         TOKEN_STRING_INITIALIZER
18242                 (struct cmd_config_per_port_rx_offload_result,
18243                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18244                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18245                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18246                            "scatter#timestamp#security#keep_crc#rss_hash");
18247 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18248         TOKEN_STRING_INITIALIZER
18249                 (struct cmd_config_per_port_rx_offload_result,
18250                  on_off, "on#off");
18251
18252 static uint64_t
18253 search_rx_offload(const char *name)
18254 {
18255         uint64_t single_offload;
18256         const char *single_name;
18257         int found = 0;
18258         unsigned int bit;
18259
18260         single_offload = 1;
18261         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18262                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18263                 if (!strcasecmp(single_name, name)) {
18264                         found = 1;
18265                         break;
18266                 }
18267                 single_offload <<= 1;
18268         }
18269
18270         if (found)
18271                 return single_offload;
18272
18273         return 0;
18274 }
18275
18276 static void
18277 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18278                                 __rte_unused struct cmdline *cl,
18279                                 __rte_unused void *data)
18280 {
18281         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18282         portid_t port_id = res->port_id;
18283         struct rte_eth_dev_info dev_info;
18284         struct rte_port *port = &ports[port_id];
18285         uint64_t single_offload;
18286         uint16_t nb_rx_queues;
18287         int q;
18288         int ret;
18289
18290         if (port->port_status != RTE_PORT_STOPPED) {
18291                 printf("Error: Can't config offload when Port %d "
18292                        "is not stopped\n", port_id);
18293                 return;
18294         }
18295
18296         single_offload = search_rx_offload(res->offload);
18297         if (single_offload == 0) {
18298                 printf("Unknown offload name: %s\n", res->offload);
18299                 return;
18300         }
18301
18302         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18303         if (ret != 0)
18304                 return;
18305
18306         nb_rx_queues = dev_info.nb_rx_queues;
18307         if (!strcmp(res->on_off, "on")) {
18308                 port->dev_conf.rxmode.offloads |= single_offload;
18309                 for (q = 0; q < nb_rx_queues; q++)
18310                         port->rx_conf[q].offloads |= single_offload;
18311         } else {
18312                 port->dev_conf.rxmode.offloads &= ~single_offload;
18313                 for (q = 0; q < nb_rx_queues; q++)
18314                         port->rx_conf[q].offloads &= ~single_offload;
18315         }
18316
18317         cmd_reconfig_device_queue(port_id, 1, 1);
18318 }
18319
18320 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18321         .f = cmd_config_per_port_rx_offload_parsed,
18322         .data = NULL,
18323         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18324                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18325                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18326                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18327                     "on|off",
18328         .tokens = {
18329                 (void *)&cmd_config_per_port_rx_offload_result_port,
18330                 (void *)&cmd_config_per_port_rx_offload_result_config,
18331                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18332                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18333                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18334                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18335                 NULL,
18336         }
18337 };
18338
18339 /* Enable/Disable a per queue offloading */
18340 struct cmd_config_per_queue_rx_offload_result {
18341         cmdline_fixed_string_t port;
18342         portid_t port_id;
18343         cmdline_fixed_string_t rxq;
18344         uint16_t queue_id;
18345         cmdline_fixed_string_t rx_offload;
18346         cmdline_fixed_string_t offload;
18347         cmdline_fixed_string_t on_off;
18348 };
18349
18350 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18351         TOKEN_STRING_INITIALIZER
18352                 (struct cmd_config_per_queue_rx_offload_result,
18353                  port, "port");
18354 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18355         TOKEN_NUM_INITIALIZER
18356                 (struct cmd_config_per_queue_rx_offload_result,
18357                  port_id, UINT16);
18358 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18359         TOKEN_STRING_INITIALIZER
18360                 (struct cmd_config_per_queue_rx_offload_result,
18361                  rxq, "rxq");
18362 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18363         TOKEN_NUM_INITIALIZER
18364                 (struct cmd_config_per_queue_rx_offload_result,
18365                  queue_id, UINT16);
18366 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18367         TOKEN_STRING_INITIALIZER
18368                 (struct cmd_config_per_queue_rx_offload_result,
18369                  rx_offload, "rx_offload");
18370 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18371         TOKEN_STRING_INITIALIZER
18372                 (struct cmd_config_per_queue_rx_offload_result,
18373                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18374                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18375                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18376                            "scatter#timestamp#security#keep_crc");
18377 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18378         TOKEN_STRING_INITIALIZER
18379                 (struct cmd_config_per_queue_rx_offload_result,
18380                  on_off, "on#off");
18381
18382 static void
18383 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18384                                 __rte_unused struct cmdline *cl,
18385                                 __rte_unused void *data)
18386 {
18387         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18388         struct rte_eth_dev_info dev_info;
18389         portid_t port_id = res->port_id;
18390         uint16_t queue_id = res->queue_id;
18391         struct rte_port *port = &ports[port_id];
18392         uint64_t single_offload;
18393         int ret;
18394
18395         if (port->port_status != RTE_PORT_STOPPED) {
18396                 printf("Error: Can't config offload when Port %d "
18397                        "is not stopped\n", port_id);
18398                 return;
18399         }
18400
18401         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18402         if (ret != 0)
18403                 return;
18404
18405         if (queue_id >= dev_info.nb_rx_queues) {
18406                 printf("Error: input queue_id should be 0 ... "
18407                        "%d\n", dev_info.nb_rx_queues - 1);
18408                 return;
18409         }
18410
18411         single_offload = search_rx_offload(res->offload);
18412         if (single_offload == 0) {
18413                 printf("Unknown offload name: %s\n", res->offload);
18414                 return;
18415         }
18416
18417         if (!strcmp(res->on_off, "on"))
18418                 port->rx_conf[queue_id].offloads |= single_offload;
18419         else
18420                 port->rx_conf[queue_id].offloads &= ~single_offload;
18421
18422         cmd_reconfig_device_queue(port_id, 1, 1);
18423 }
18424
18425 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18426         .f = cmd_config_per_queue_rx_offload_parsed,
18427         .data = NULL,
18428         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18429                     "vlan_strip|ipv4_cksum|"
18430                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18431                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18432                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18433                     "on|off",
18434         .tokens = {
18435                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18436                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18437                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18438                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18439                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18440                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18441                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18442                 NULL,
18443         }
18444 };
18445
18446 /* Get Tx offloads capabilities */
18447 struct cmd_tx_offload_get_capa_result {
18448         cmdline_fixed_string_t show;
18449         cmdline_fixed_string_t port;
18450         portid_t port_id;
18451         cmdline_fixed_string_t tx_offload;
18452         cmdline_fixed_string_t capabilities;
18453 };
18454
18455 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18456         TOKEN_STRING_INITIALIZER
18457                 (struct cmd_tx_offload_get_capa_result,
18458                  show, "show");
18459 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18460         TOKEN_STRING_INITIALIZER
18461                 (struct cmd_tx_offload_get_capa_result,
18462                  port, "port");
18463 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18464         TOKEN_NUM_INITIALIZER
18465                 (struct cmd_tx_offload_get_capa_result,
18466                  port_id, UINT16);
18467 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18468         TOKEN_STRING_INITIALIZER
18469                 (struct cmd_tx_offload_get_capa_result,
18470                  tx_offload, "tx_offload");
18471 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18472         TOKEN_STRING_INITIALIZER
18473                 (struct cmd_tx_offload_get_capa_result,
18474                  capabilities, "capabilities");
18475
18476 static void
18477 print_tx_offloads(uint64_t offloads)
18478 {
18479         uint64_t single_offload;
18480         int begin;
18481         int end;
18482         int bit;
18483
18484         if (offloads == 0)
18485                 return;
18486
18487         begin = __builtin_ctzll(offloads);
18488         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18489
18490         single_offload = 1ULL << begin;
18491         for (bit = begin; bit < end; bit++) {
18492                 if (offloads & single_offload)
18493                         printf(" %s",
18494                                rte_eth_dev_tx_offload_name(single_offload));
18495                 single_offload <<= 1;
18496         }
18497 }
18498
18499 static void
18500 cmd_tx_offload_get_capa_parsed(
18501         void *parsed_result,
18502         __rte_unused struct cmdline *cl,
18503         __rte_unused void *data)
18504 {
18505         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18506         struct rte_eth_dev_info dev_info;
18507         portid_t port_id = res->port_id;
18508         uint64_t queue_offloads;
18509         uint64_t port_offloads;
18510         int ret;
18511
18512         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18513         if (ret != 0)
18514                 return;
18515
18516         queue_offloads = dev_info.tx_queue_offload_capa;
18517         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18518
18519         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18520         printf("  Per Queue :");
18521         print_tx_offloads(queue_offloads);
18522
18523         printf("\n");
18524         printf("  Per Port  :");
18525         print_tx_offloads(port_offloads);
18526         printf("\n\n");
18527 }
18528
18529 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18530         .f = cmd_tx_offload_get_capa_parsed,
18531         .data = NULL,
18532         .help_str = "show port <port_id> tx_offload capabilities",
18533         .tokens = {
18534                 (void *)&cmd_tx_offload_get_capa_show,
18535                 (void *)&cmd_tx_offload_get_capa_port,
18536                 (void *)&cmd_tx_offload_get_capa_port_id,
18537                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18538                 (void *)&cmd_tx_offload_get_capa_capabilities,
18539                 NULL,
18540         }
18541 };
18542
18543 /* Get Tx offloads configuration */
18544 struct cmd_tx_offload_get_configuration_result {
18545         cmdline_fixed_string_t show;
18546         cmdline_fixed_string_t port;
18547         portid_t port_id;
18548         cmdline_fixed_string_t tx_offload;
18549         cmdline_fixed_string_t configuration;
18550 };
18551
18552 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18553         TOKEN_STRING_INITIALIZER
18554                 (struct cmd_tx_offload_get_configuration_result,
18555                  show, "show");
18556 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18557         TOKEN_STRING_INITIALIZER
18558                 (struct cmd_tx_offload_get_configuration_result,
18559                  port, "port");
18560 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18561         TOKEN_NUM_INITIALIZER
18562                 (struct cmd_tx_offload_get_configuration_result,
18563                  port_id, UINT16);
18564 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18565         TOKEN_STRING_INITIALIZER
18566                 (struct cmd_tx_offload_get_configuration_result,
18567                  tx_offload, "tx_offload");
18568 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18569         TOKEN_STRING_INITIALIZER
18570                 (struct cmd_tx_offload_get_configuration_result,
18571                  configuration, "configuration");
18572
18573 static void
18574 cmd_tx_offload_get_configuration_parsed(
18575         void *parsed_result,
18576         __rte_unused struct cmdline *cl,
18577         __rte_unused void *data)
18578 {
18579         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18580         struct rte_eth_dev_info dev_info;
18581         portid_t port_id = res->port_id;
18582         struct rte_port *port = &ports[port_id];
18583         uint64_t port_offloads;
18584         uint64_t queue_offloads;
18585         uint16_t nb_tx_queues;
18586         int q;
18587         int ret;
18588
18589         printf("Tx Offloading Configuration of port %d :\n", port_id);
18590
18591         port_offloads = port->dev_conf.txmode.offloads;
18592         printf("  Port :");
18593         print_tx_offloads(port_offloads);
18594         printf("\n");
18595
18596         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18597         if (ret != 0)
18598                 return;
18599
18600         nb_tx_queues = dev_info.nb_tx_queues;
18601         for (q = 0; q < nb_tx_queues; q++) {
18602                 queue_offloads = port->tx_conf[q].offloads;
18603                 printf("  Queue[%2d] :", q);
18604                 print_tx_offloads(queue_offloads);
18605                 printf("\n");
18606         }
18607         printf("\n");
18608 }
18609
18610 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18611         .f = cmd_tx_offload_get_configuration_parsed,
18612         .data = NULL,
18613         .help_str = "show port <port_id> tx_offload configuration",
18614         .tokens = {
18615                 (void *)&cmd_tx_offload_get_configuration_show,
18616                 (void *)&cmd_tx_offload_get_configuration_port,
18617                 (void *)&cmd_tx_offload_get_configuration_port_id,
18618                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18619                 (void *)&cmd_tx_offload_get_configuration_configuration,
18620                 NULL,
18621         }
18622 };
18623
18624 /* Enable/Disable a per port offloading */
18625 struct cmd_config_per_port_tx_offload_result {
18626         cmdline_fixed_string_t port;
18627         cmdline_fixed_string_t config;
18628         portid_t port_id;
18629         cmdline_fixed_string_t tx_offload;
18630         cmdline_fixed_string_t offload;
18631         cmdline_fixed_string_t on_off;
18632 };
18633
18634 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18635         TOKEN_STRING_INITIALIZER
18636                 (struct cmd_config_per_port_tx_offload_result,
18637                  port, "port");
18638 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18639         TOKEN_STRING_INITIALIZER
18640                 (struct cmd_config_per_port_tx_offload_result,
18641                  config, "config");
18642 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18643         TOKEN_NUM_INITIALIZER
18644                 (struct cmd_config_per_port_tx_offload_result,
18645                  port_id, UINT16);
18646 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18647         TOKEN_STRING_INITIALIZER
18648                 (struct cmd_config_per_port_tx_offload_result,
18649                  tx_offload, "tx_offload");
18650 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18651         TOKEN_STRING_INITIALIZER
18652                 (struct cmd_config_per_port_tx_offload_result,
18653                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18654                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18655                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18656                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18657                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18658 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18659         TOKEN_STRING_INITIALIZER
18660                 (struct cmd_config_per_port_tx_offload_result,
18661                  on_off, "on#off");
18662
18663 static uint64_t
18664 search_tx_offload(const char *name)
18665 {
18666         uint64_t single_offload;
18667         const char *single_name;
18668         int found = 0;
18669         unsigned int bit;
18670
18671         single_offload = 1;
18672         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18673                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18674                 if (single_name == NULL)
18675                         break;
18676                 if (!strcasecmp(single_name, name)) {
18677                         found = 1;
18678                         break;
18679                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18680                         break;
18681                 single_offload <<= 1;
18682         }
18683
18684         if (found)
18685                 return single_offload;
18686
18687         return 0;
18688 }
18689
18690 static void
18691 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18692                                 __rte_unused struct cmdline *cl,
18693                                 __rte_unused void *data)
18694 {
18695         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18696         portid_t port_id = res->port_id;
18697         struct rte_eth_dev_info dev_info;
18698         struct rte_port *port = &ports[port_id];
18699         uint64_t single_offload;
18700         uint16_t nb_tx_queues;
18701         int q;
18702         int ret;
18703
18704         if (port->port_status != RTE_PORT_STOPPED) {
18705                 printf("Error: Can't config offload when Port %d "
18706                        "is not stopped\n", port_id);
18707                 return;
18708         }
18709
18710         single_offload = search_tx_offload(res->offload);
18711         if (single_offload == 0) {
18712                 printf("Unknown offload name: %s\n", res->offload);
18713                 return;
18714         }
18715
18716         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18717         if (ret != 0)
18718                 return;
18719
18720         nb_tx_queues = dev_info.nb_tx_queues;
18721         if (!strcmp(res->on_off, "on")) {
18722                 port->dev_conf.txmode.offloads |= single_offload;
18723                 for (q = 0; q < nb_tx_queues; q++)
18724                         port->tx_conf[q].offloads |= single_offload;
18725         } else {
18726                 port->dev_conf.txmode.offloads &= ~single_offload;
18727                 for (q = 0; q < nb_tx_queues; q++)
18728                         port->tx_conf[q].offloads &= ~single_offload;
18729         }
18730
18731         cmd_reconfig_device_queue(port_id, 1, 1);
18732 }
18733
18734 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18735         .f = cmd_config_per_port_tx_offload_parsed,
18736         .data = NULL,
18737         .help_str = "port config <port_id> tx_offload "
18738                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18739                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18740                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18741                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18742                     "mt_lockfree|multi_segs|mbuf_fast_free|security on|off",
18743         .tokens = {
18744                 (void *)&cmd_config_per_port_tx_offload_result_port,
18745                 (void *)&cmd_config_per_port_tx_offload_result_config,
18746                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18747                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18748                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18749                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18750                 NULL,
18751         }
18752 };
18753
18754 /* Enable/Disable a per queue offloading */
18755 struct cmd_config_per_queue_tx_offload_result {
18756         cmdline_fixed_string_t port;
18757         portid_t port_id;
18758         cmdline_fixed_string_t txq;
18759         uint16_t queue_id;
18760         cmdline_fixed_string_t tx_offload;
18761         cmdline_fixed_string_t offload;
18762         cmdline_fixed_string_t on_off;
18763 };
18764
18765 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18766         TOKEN_STRING_INITIALIZER
18767                 (struct cmd_config_per_queue_tx_offload_result,
18768                  port, "port");
18769 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18770         TOKEN_NUM_INITIALIZER
18771                 (struct cmd_config_per_queue_tx_offload_result,
18772                  port_id, UINT16);
18773 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18774         TOKEN_STRING_INITIALIZER
18775                 (struct cmd_config_per_queue_tx_offload_result,
18776                  txq, "txq");
18777 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18778         TOKEN_NUM_INITIALIZER
18779                 (struct cmd_config_per_queue_tx_offload_result,
18780                  queue_id, UINT16);
18781 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18782         TOKEN_STRING_INITIALIZER
18783                 (struct cmd_config_per_queue_tx_offload_result,
18784                  tx_offload, "tx_offload");
18785 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18786         TOKEN_STRING_INITIALIZER
18787                 (struct cmd_config_per_queue_tx_offload_result,
18788                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18789                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18790                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18791                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18792                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18793 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18794         TOKEN_STRING_INITIALIZER
18795                 (struct cmd_config_per_queue_tx_offload_result,
18796                  on_off, "on#off");
18797
18798 static void
18799 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18800                                 __rte_unused struct cmdline *cl,
18801                                 __rte_unused void *data)
18802 {
18803         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18804         struct rte_eth_dev_info dev_info;
18805         portid_t port_id = res->port_id;
18806         uint16_t queue_id = res->queue_id;
18807         struct rte_port *port = &ports[port_id];
18808         uint64_t single_offload;
18809         int ret;
18810
18811         if (port->port_status != RTE_PORT_STOPPED) {
18812                 printf("Error: Can't config offload when Port %d "
18813                        "is not stopped\n", port_id);
18814                 return;
18815         }
18816
18817         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18818         if (ret != 0)
18819                 return;
18820
18821         if (queue_id >= dev_info.nb_tx_queues) {
18822                 printf("Error: input queue_id should be 0 ... "
18823                        "%d\n", dev_info.nb_tx_queues - 1);
18824                 return;
18825         }
18826
18827         single_offload = search_tx_offload(res->offload);
18828         if (single_offload == 0) {
18829                 printf("Unknown offload name: %s\n", res->offload);
18830                 return;
18831         }
18832
18833         if (!strcmp(res->on_off, "on"))
18834                 port->tx_conf[queue_id].offloads |= single_offload;
18835         else
18836                 port->tx_conf[queue_id].offloads &= ~single_offload;
18837
18838         cmd_reconfig_device_queue(port_id, 1, 1);
18839 }
18840
18841 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18842         .f = cmd_config_per_queue_tx_offload_parsed,
18843         .data = NULL,
18844         .help_str = "port <port_id> txq <queue_id> tx_offload "
18845                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18846                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18847                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18848                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18849                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18850                     "on|off",
18851         .tokens = {
18852                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18853                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18854                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18855                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18856                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18857                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18858                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18859                 NULL,
18860         }
18861 };
18862
18863 /* *** configure tx_metadata for specific port *** */
18864 struct cmd_config_tx_metadata_specific_result {
18865         cmdline_fixed_string_t port;
18866         cmdline_fixed_string_t keyword;
18867         uint16_t port_id;
18868         cmdline_fixed_string_t item;
18869         uint32_t value;
18870 };
18871
18872 static void
18873 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18874                                 __rte_unused struct cmdline *cl,
18875                                 __rte_unused void *data)
18876 {
18877         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18878
18879         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18880                 return;
18881         ports[res->port_id].tx_metadata = res->value;
18882         /* Add/remove callback to insert valid metadata in every Tx packet. */
18883         if (ports[res->port_id].tx_metadata)
18884                 add_tx_md_callback(res->port_id);
18885         else
18886                 remove_tx_md_callback(res->port_id);
18887         rte_flow_dynf_metadata_register();
18888 }
18889
18890 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18891         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18892                         port, "port");
18893 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18894         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18895                         keyword, "config");
18896 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18897         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18898                         port_id, UINT16);
18899 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18900         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18901                         item, "tx_metadata");
18902 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18903         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18904                         value, UINT32);
18905
18906 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18907         .f = cmd_config_tx_metadata_specific_parsed,
18908         .data = NULL,
18909         .help_str = "port config <port_id> tx_metadata <value>",
18910         .tokens = {
18911                 (void *)&cmd_config_tx_metadata_specific_port,
18912                 (void *)&cmd_config_tx_metadata_specific_keyword,
18913                 (void *)&cmd_config_tx_metadata_specific_id,
18914                 (void *)&cmd_config_tx_metadata_specific_item,
18915                 (void *)&cmd_config_tx_metadata_specific_value,
18916                 NULL,
18917         },
18918 };
18919
18920 /* *** set dynf *** */
18921 struct cmd_config_tx_dynf_specific_result {
18922         cmdline_fixed_string_t port;
18923         cmdline_fixed_string_t keyword;
18924         uint16_t port_id;
18925         cmdline_fixed_string_t item;
18926         cmdline_fixed_string_t name;
18927         cmdline_fixed_string_t value;
18928 };
18929
18930 static void
18931 cmd_config_dynf_specific_parsed(void *parsed_result,
18932                                 __rte_unused struct cmdline *cl,
18933                                 __rte_unused void *data)
18934 {
18935         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18936         struct rte_mbuf_dynflag desc_flag;
18937         int flag;
18938         uint64_t old_port_flags;
18939
18940         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18941                 return;
18942         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18943         if (flag <= 0) {
18944                 if (strlcpy(desc_flag.name, res->name,
18945                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18946                         printf("Flag name too long\n");
18947                         return;
18948                 }
18949                 desc_flag.flags = 0;
18950                 flag = rte_mbuf_dynflag_register(&desc_flag);
18951                 if (flag < 0) {
18952                         printf("Can't register flag\n");
18953                         return;
18954                 }
18955                 strcpy(dynf_names[flag], desc_flag.name);
18956         }
18957         old_port_flags = ports[res->port_id].mbuf_dynf;
18958         if (!strcmp(res->value, "set")) {
18959                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
18960                 if (old_port_flags == 0)
18961                         add_tx_dynf_callback(res->port_id);
18962         } else {
18963                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18964                 if (ports[res->port_id].mbuf_dynf == 0)
18965                         remove_tx_dynf_callback(res->port_id);
18966         }
18967 }
18968
18969 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18970         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18971                         keyword, "port");
18972 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18973         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18974                         keyword, "config");
18975 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18976         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18977                         port_id, UINT16);
18978 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18979         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18980                         item, "dynf");
18981 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18982         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18983                         name, NULL);
18984 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
18985         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18986                         value, "set#clear");
18987
18988 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
18989         .f = cmd_config_dynf_specific_parsed,
18990         .data = NULL,
18991         .help_str = "port config <port id> dynf <name> set|clear",
18992         .tokens = {
18993                 (void *)&cmd_config_tx_dynf_specific_port,
18994                 (void *)&cmd_config_tx_dynf_specific_keyword,
18995                 (void *)&cmd_config_tx_dynf_specific_port_id,
18996                 (void *)&cmd_config_tx_dynf_specific_item,
18997                 (void *)&cmd_config_tx_dynf_specific_name,
18998                 (void *)&cmd_config_tx_dynf_specific_value,
18999                 NULL,
19000         },
19001 };
19002
19003 /* *** display tx_metadata per port configuration *** */
19004 struct cmd_show_tx_metadata_result {
19005         cmdline_fixed_string_t cmd_show;
19006         cmdline_fixed_string_t cmd_port;
19007         cmdline_fixed_string_t cmd_keyword;
19008         portid_t cmd_pid;
19009 };
19010
19011 static void
19012 cmd_show_tx_metadata_parsed(void *parsed_result,
19013                 __rte_unused struct cmdline *cl,
19014                 __rte_unused void *data)
19015 {
19016         struct cmd_show_tx_metadata_result *res = parsed_result;
19017
19018         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19019                 printf("invalid port id %u\n", res->cmd_pid);
19020                 return;
19021         }
19022         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19023                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19024                        ports[res->cmd_pid].tx_metadata);
19025         }
19026 }
19027
19028 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19029         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19030                         cmd_show, "show");
19031 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19032         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19033                         cmd_port, "port");
19034 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19035         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19036                         cmd_pid, UINT16);
19037 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19038         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19039                         cmd_keyword, "tx_metadata");
19040
19041 cmdline_parse_inst_t cmd_show_tx_metadata = {
19042         .f = cmd_show_tx_metadata_parsed,
19043         .data = NULL,
19044         .help_str = "show port <port_id> tx_metadata",
19045         .tokens = {
19046                 (void *)&cmd_show_tx_metadata_show,
19047                 (void *)&cmd_show_tx_metadata_port,
19048                 (void *)&cmd_show_tx_metadata_pid,
19049                 (void *)&cmd_show_tx_metadata_keyword,
19050                 NULL,
19051         },
19052 };
19053
19054 /* show port supported ptypes */
19055
19056 /* Common result structure for show port ptypes */
19057 struct cmd_show_port_supported_ptypes_result {
19058         cmdline_fixed_string_t show;
19059         cmdline_fixed_string_t port;
19060         portid_t port_id;
19061         cmdline_fixed_string_t ptypes;
19062 };
19063
19064 /* Common CLI fields for show port ptypes */
19065 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19066         TOKEN_STRING_INITIALIZER
19067                 (struct cmd_show_port_supported_ptypes_result,
19068                  show, "show");
19069 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19070         TOKEN_STRING_INITIALIZER
19071                 (struct cmd_show_port_supported_ptypes_result,
19072                  port, "port");
19073 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19074         TOKEN_NUM_INITIALIZER
19075                 (struct cmd_show_port_supported_ptypes_result,
19076                  port_id, UINT16);
19077 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19078         TOKEN_STRING_INITIALIZER
19079                 (struct cmd_show_port_supported_ptypes_result,
19080                  ptypes, "ptypes");
19081
19082 static void
19083 cmd_show_port_supported_ptypes_parsed(
19084         void *parsed_result,
19085         __rte_unused struct cmdline *cl,
19086         __rte_unused void *data)
19087 {
19088 #define RSVD_PTYPE_MASK       0xf0000000
19089 #define MAX_PTYPES_PER_LAYER  16
19090 #define LTYPE_NAMESIZE        32
19091 #define PTYPE_NAMESIZE        256
19092         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19093         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19094         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19095         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19096         uint16_t port_id = res->port_id;
19097         int ret, i;
19098
19099         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19100         if (ret < 0)
19101                 return;
19102
19103         while (ptype_mask != RSVD_PTYPE_MASK) {
19104
19105                 switch (ptype_mask) {
19106                 case RTE_PTYPE_L2_MASK:
19107                         strlcpy(ltype, "L2", sizeof(ltype));
19108                         break;
19109                 case RTE_PTYPE_L3_MASK:
19110                         strlcpy(ltype, "L3", sizeof(ltype));
19111                         break;
19112                 case RTE_PTYPE_L4_MASK:
19113                         strlcpy(ltype, "L4", sizeof(ltype));
19114                         break;
19115                 case RTE_PTYPE_TUNNEL_MASK:
19116                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19117                         break;
19118                 case RTE_PTYPE_INNER_L2_MASK:
19119                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19120                         break;
19121                 case RTE_PTYPE_INNER_L3_MASK:
19122                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19123                         break;
19124                 case RTE_PTYPE_INNER_L4_MASK:
19125                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19126                         break;
19127                 default:
19128                         return;
19129                 }
19130
19131                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19132                                                        ptype_mask, ptypes,
19133                                                        MAX_PTYPES_PER_LAYER);
19134
19135                 if (ret > 0)
19136                         printf("Supported %s ptypes:\n", ltype);
19137                 else
19138                         printf("%s ptypes unsupported\n", ltype);
19139
19140                 for (i = 0; i < ret; ++i) {
19141                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19142                         printf("%s\n", buf);
19143                 }
19144
19145                 ptype_mask <<= 4;
19146         }
19147 }
19148
19149 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19150         .f = cmd_show_port_supported_ptypes_parsed,
19151         .data = NULL,
19152         .help_str = "show port <port_id> ptypes",
19153         .tokens = {
19154                 (void *)&cmd_show_port_supported_ptypes_show,
19155                 (void *)&cmd_show_port_supported_ptypes_port,
19156                 (void *)&cmd_show_port_supported_ptypes_port_id,
19157                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19158                 NULL,
19159         },
19160 };
19161
19162 /* *** display rx/tx descriptor status *** */
19163 struct cmd_show_rx_tx_desc_status_result {
19164         cmdline_fixed_string_t cmd_show;
19165         cmdline_fixed_string_t cmd_port;
19166         cmdline_fixed_string_t cmd_keyword;
19167         cmdline_fixed_string_t cmd_desc;
19168         cmdline_fixed_string_t cmd_status;
19169         portid_t cmd_pid;
19170         portid_t cmd_qid;
19171         portid_t cmd_did;
19172 };
19173
19174 static void
19175 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19176                 __rte_unused struct cmdline *cl,
19177                 __rte_unused void *data)
19178 {
19179         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19180         int rc;
19181
19182         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19183                 printf("invalid port id %u\n", res->cmd_pid);
19184                 return;
19185         }
19186
19187         if (!strcmp(res->cmd_keyword, "rxq")) {
19188                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19189                                              res->cmd_did);
19190                 if (rc < 0) {
19191                         printf("Invalid queueid = %d\n", res->cmd_qid);
19192                         return;
19193                 }
19194                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19195                         printf("Desc status = AVAILABLE\n");
19196                 else if (rc == RTE_ETH_RX_DESC_DONE)
19197                         printf("Desc status = DONE\n");
19198                 else
19199                         printf("Desc status = UNAVAILABLE\n");
19200         } else if (!strcmp(res->cmd_keyword, "txq")) {
19201                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19202                                              res->cmd_did);
19203                 if (rc < 0) {
19204                         printf("Invalid queueid = %d\n", res->cmd_qid);
19205                         return;
19206                 }
19207                 if (rc == RTE_ETH_TX_DESC_FULL)
19208                         printf("Desc status = FULL\n");
19209                 else if (rc == RTE_ETH_TX_DESC_DONE)
19210                         printf("Desc status = DONE\n");
19211                 else
19212                         printf("Desc status = UNAVAILABLE\n");
19213         }
19214 }
19215
19216 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19217         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19218                         cmd_show, "show");
19219 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19220         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19221                         cmd_port, "port");
19222 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19223         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19224                         cmd_pid, UINT16);
19225 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19226         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19227                         cmd_keyword, "rxq#txq");
19228 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19229         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19230                         cmd_qid, UINT16);
19231 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19232         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19233                         cmd_desc, "desc");
19234 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19235         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19236                         cmd_did, UINT16);
19237 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19238         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19239                         cmd_status, "status");
19240 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19241         .f = cmd_show_rx_tx_desc_status_parsed,
19242         .data = NULL,
19243         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19244                 "status",
19245         .tokens = {
19246                 (void *)&cmd_show_rx_tx_desc_status_show,
19247                 (void *)&cmd_show_rx_tx_desc_status_port,
19248                 (void *)&cmd_show_rx_tx_desc_status_pid,
19249                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19250                 (void *)&cmd_show_rx_tx_desc_status_qid,
19251                 (void *)&cmd_show_rx_tx_desc_status_desc,
19252                 (void *)&cmd_show_rx_tx_desc_status_did,
19253                 (void *)&cmd_show_rx_tx_desc_status_status,
19254                 NULL,
19255         },
19256 };
19257
19258 /* Common result structure for set port ptypes */
19259 struct cmd_set_port_ptypes_result {
19260         cmdline_fixed_string_t set;
19261         cmdline_fixed_string_t port;
19262         portid_t port_id;
19263         cmdline_fixed_string_t ptype_mask;
19264         uint32_t mask;
19265 };
19266
19267 /* Common CLI fields for set port ptypes */
19268 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19269         TOKEN_STRING_INITIALIZER
19270                 (struct cmd_set_port_ptypes_result,
19271                  set, "set");
19272 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19273         TOKEN_STRING_INITIALIZER
19274                 (struct cmd_set_port_ptypes_result,
19275                  port, "port");
19276 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19277         TOKEN_NUM_INITIALIZER
19278                 (struct cmd_set_port_ptypes_result,
19279                  port_id, UINT16);
19280 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19281         TOKEN_STRING_INITIALIZER
19282                 (struct cmd_set_port_ptypes_result,
19283                  ptype_mask, "ptype_mask");
19284 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19285         TOKEN_NUM_INITIALIZER
19286                 (struct cmd_set_port_ptypes_result,
19287                  mask, UINT32);
19288
19289 static void
19290 cmd_set_port_ptypes_parsed(
19291         void *parsed_result,
19292         __rte_unused struct cmdline *cl,
19293         __rte_unused void *data)
19294 {
19295         struct cmd_set_port_ptypes_result *res = parsed_result;
19296 #define PTYPE_NAMESIZE        256
19297         char ptype_name[PTYPE_NAMESIZE];
19298         uint16_t port_id = res->port_id;
19299         uint32_t ptype_mask = res->mask;
19300         int ret, i;
19301
19302         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19303                                                NULL, 0);
19304         if (ret <= 0) {
19305                 printf("Port %d doesn't support any ptypes.\n", port_id);
19306                 return;
19307         }
19308
19309         uint32_t ptypes[ret];
19310
19311         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19312         if (ret < 0) {
19313                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19314                 return;
19315         }
19316
19317         printf("Successfully set following ptypes for Port %d\n", port_id);
19318         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19319                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19320                 printf("%s\n", ptype_name);
19321         }
19322
19323         clear_ptypes = false;
19324 }
19325
19326 cmdline_parse_inst_t cmd_set_port_ptypes = {
19327         .f = cmd_set_port_ptypes_parsed,
19328         .data = NULL,
19329         .help_str = "set port <port_id> ptype_mask <mask>",
19330         .tokens = {
19331                 (void *)&cmd_set_port_ptypes_set,
19332                 (void *)&cmd_set_port_ptypes_port,
19333                 (void *)&cmd_set_port_ptypes_port_id,
19334                 (void *)&cmd_set_port_ptypes_mask_str,
19335                 (void *)&cmd_set_port_ptypes_mask_u32,
19336                 NULL,
19337         },
19338 };
19339
19340 /* *** display mac addresses added to a port *** */
19341 struct cmd_showport_macs_result {
19342         cmdline_fixed_string_t cmd_show;
19343         cmdline_fixed_string_t cmd_port;
19344         cmdline_fixed_string_t cmd_keyword;
19345         portid_t cmd_pid;
19346 };
19347
19348 static void
19349 cmd_showport_macs_parsed(void *parsed_result,
19350                 __rte_unused struct cmdline *cl,
19351                 __rte_unused void *data)
19352 {
19353         struct cmd_showport_macs_result *res = parsed_result;
19354
19355         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19356                 return;
19357
19358         if (!strcmp(res->cmd_keyword, "macs"))
19359                 show_macs(res->cmd_pid);
19360         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19361                 show_mcast_macs(res->cmd_pid);
19362 }
19363
19364 cmdline_parse_token_string_t cmd_showport_macs_show =
19365         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19366                         cmd_show, "show");
19367 cmdline_parse_token_string_t cmd_showport_macs_port =
19368         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19369                         cmd_port, "port");
19370 cmdline_parse_token_num_t cmd_showport_macs_pid =
19371         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19372                         cmd_pid, UINT16);
19373 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19374         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19375                         cmd_keyword, "macs#mcast_macs");
19376
19377 cmdline_parse_inst_t cmd_showport_macs = {
19378         .f = cmd_showport_macs_parsed,
19379         .data = NULL,
19380         .help_str = "show port <port_id> macs|mcast_macs",
19381         .tokens = {
19382                 (void *)&cmd_showport_macs_show,
19383                 (void *)&cmd_showport_macs_port,
19384                 (void *)&cmd_showport_macs_pid,
19385                 (void *)&cmd_showport_macs_keyword,
19386                 NULL,
19387         },
19388 };
19389
19390 /* ******************************************************************************** */
19391
19392 /* list of instructions */
19393 cmdline_parse_ctx_t main_ctx[] = {
19394         (cmdline_parse_inst_t *)&cmd_help_brief,
19395         (cmdline_parse_inst_t *)&cmd_help_long,
19396         (cmdline_parse_inst_t *)&cmd_quit,
19397         (cmdline_parse_inst_t *)&cmd_load_from_file,
19398         (cmdline_parse_inst_t *)&cmd_showport,
19399         (cmdline_parse_inst_t *)&cmd_showqueue,
19400         (cmdline_parse_inst_t *)&cmd_showportall,
19401         (cmdline_parse_inst_t *)&cmd_showdevice,
19402         (cmdline_parse_inst_t *)&cmd_showcfg,
19403         (cmdline_parse_inst_t *)&cmd_showfwdall,
19404         (cmdline_parse_inst_t *)&cmd_start,
19405         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19406         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19407         (cmdline_parse_inst_t *)&cmd_set_link_up,
19408         (cmdline_parse_inst_t *)&cmd_set_link_down,
19409         (cmdline_parse_inst_t *)&cmd_reset,
19410         (cmdline_parse_inst_t *)&cmd_set_numbers,
19411         (cmdline_parse_inst_t *)&cmd_set_log,
19412         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19413         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19414         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19415         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19416         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19417         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19418         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19419         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19420         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19421         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19422         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19423         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19424         (cmdline_parse_inst_t *)&cmd_set_link_check,
19425         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19426         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19427         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19428         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19429 #ifdef RTE_LIBRTE_PMD_BOND
19430         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19431         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19432         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19433         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19434         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19435         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19436         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19437         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19438         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19439         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19440         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19441 #endif
19442         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19443         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19444         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19445         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19446         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19447         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19448         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19449         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19450         (cmdline_parse_inst_t *)&cmd_csum_set,
19451         (cmdline_parse_inst_t *)&cmd_csum_show,
19452         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19453         (cmdline_parse_inst_t *)&cmd_tso_set,
19454         (cmdline_parse_inst_t *)&cmd_tso_show,
19455         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19456         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19457         (cmdline_parse_inst_t *)&cmd_gro_enable,
19458         (cmdline_parse_inst_t *)&cmd_gro_flush,
19459         (cmdline_parse_inst_t *)&cmd_gro_show,
19460         (cmdline_parse_inst_t *)&cmd_gso_enable,
19461         (cmdline_parse_inst_t *)&cmd_gso_size,
19462         (cmdline_parse_inst_t *)&cmd_gso_show,
19463         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19464         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19465         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19466         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19467         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19468         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19469         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19470         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19471         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19472         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19473         (cmdline_parse_inst_t *)&cmd_config_dcb,
19474         (cmdline_parse_inst_t *)&cmd_read_reg,
19475         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19476         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19477         (cmdline_parse_inst_t *)&cmd_write_reg,
19478         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19479         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19480         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19481         (cmdline_parse_inst_t *)&cmd_stop,
19482         (cmdline_parse_inst_t *)&cmd_mac_addr,
19483         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19484         (cmdline_parse_inst_t *)&cmd_set_qmap,
19485         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19486         (cmdline_parse_inst_t *)&cmd_operate_port,
19487         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19488         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19489         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19490         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19491         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19492         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19493         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19494         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19495         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19496         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19497         (cmdline_parse_inst_t *)&cmd_config_mtu,
19498         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19499         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19500         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19501         (cmdline_parse_inst_t *)&cmd_config_rss,
19502         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19503         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19504         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19505         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19506         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19507         (cmdline_parse_inst_t *)&cmd_showport_reta,
19508         (cmdline_parse_inst_t *)&cmd_showport_macs,
19509         (cmdline_parse_inst_t *)&cmd_config_burst,
19510         (cmdline_parse_inst_t *)&cmd_config_thresh,
19511         (cmdline_parse_inst_t *)&cmd_config_threshold,
19512         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19513         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19514         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19515         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19516         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19517         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19518         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19519         (cmdline_parse_inst_t *)&cmd_global_config,
19520         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19521         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19522         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19523         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19524         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19525         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19526         (cmdline_parse_inst_t *)&cmd_dump,
19527         (cmdline_parse_inst_t *)&cmd_dump_one,
19528         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19529         (cmdline_parse_inst_t *)&cmd_syn_filter,
19530         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19531         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19532         (cmdline_parse_inst_t *)&cmd_flex_filter,
19533         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19534         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19535         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19536         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19537         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19538         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19539         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19540         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19541         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19542         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19543         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19544         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19545         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19546         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19547         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19548         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19549         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19550         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19551         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19552         (cmdline_parse_inst_t *)&cmd_flow,
19553         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19554         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19555         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19556         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19557         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19558         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19559         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19560         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19561         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19562         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19563         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19564         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19565         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19566         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19567         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19568         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19569         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19570         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19571         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19572         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19573         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19574         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19575         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19576         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19577         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19578         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19579         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19580         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19581         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19582         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19583         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19584         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19585         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19586         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19587         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19588         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19589         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19590         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19591         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19592         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19593         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19594         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19595         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19596         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19597         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19598         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19599         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19600         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19601         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19602 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19603         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19604 #endif
19605         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19606         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19607         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19608         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19609         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19610         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19611         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19612         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19613         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19614         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19615         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19616         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19617         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19618         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19619         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19620         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19621         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19622         (cmdline_parse_inst_t *)&cmd_ddp_add,
19623         (cmdline_parse_inst_t *)&cmd_ddp_del,
19624         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19625         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19626         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19627         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19628         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19629         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19630         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19631         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19632         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19633         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19634         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19635         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19636
19637         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19638         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19639         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19640         (cmdline_parse_inst_t *)&cmd_queue_region,
19641         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19642         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19643         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19644         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19645         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19646         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19647         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19648         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19649         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19650         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19651         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19652         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19653         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19654         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19655         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19656         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19657         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19658         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19659         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19660         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19661         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19662         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19663         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19664         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19665         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19666         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19667         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19668         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19669         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19670         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19671         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19672         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19673         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19674         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19675         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19676 #ifdef RTE_LIBRTE_BPF
19677         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19678         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19679 #endif
19680         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19681         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19682         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19683         (cmdline_parse_inst_t *)&cmd_set_raw,
19684         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19685         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19686         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19687         NULL,
19688 };
19689
19690 /* read cmdline commands from file */
19691 void
19692 cmdline_read_from_file(const char *filename)
19693 {
19694         struct cmdline *cl;
19695
19696         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19697         if (cl == NULL) {
19698                 printf("Failed to create file based cmdline context: %s\n",
19699                        filename);
19700                 return;
19701         }
19702
19703         cmdline_interact(cl);
19704         cmdline_quit(cl);
19705
19706         cmdline_free(cl);
19707
19708         printf("Read CLI commands from %s\n", filename);
19709 }
19710
19711 /* prompt function, called from main on MASTER lcore */
19712 void
19713 prompt(void)
19714 {
19715         /* initialize non-constant commands */
19716         cmd_set_fwd_mode_init();
19717         cmd_set_fwd_retry_mode_init();
19718
19719         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19720         if (testpmd_cl == NULL)
19721                 return;
19722         cmdline_interact(testpmd_cl);
19723         cmdline_stdin_exit(testpmd_cl);
19724 }
19725
19726 void
19727 prompt_exit(void)
19728 {
19729         if (testpmd_cl != NULL)
19730                 cmdline_quit(testpmd_cl);
19731 }
19732
19733 static void
19734 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19735 {
19736         if (id == (portid_t)RTE_PORT_ALL) {
19737                 portid_t pid;
19738
19739                 RTE_ETH_FOREACH_DEV(pid) {
19740                         /* check if need_reconfig has been set to 1 */
19741                         if (ports[pid].need_reconfig == 0)
19742                                 ports[pid].need_reconfig = dev;
19743                         /* check if need_reconfig_queues has been set to 1 */
19744                         if (ports[pid].need_reconfig_queues == 0)
19745                                 ports[pid].need_reconfig_queues = queue;
19746                 }
19747         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19748                 /* check if need_reconfig has been set to 1 */
19749                 if (ports[id].need_reconfig == 0)
19750                         ports[id].need_reconfig = dev;
19751                 /* check if need_reconfig_queues has been set to 1 */
19752                 if (ports[id].need_reconfig_queues == 0)
19753                         ports[id].need_reconfig_queues = queue;
19754         }
19755 }